Perfectly Clear SDK Documentation  9.1.1.325
PerfectlyClearAdapter.cs
Go to the documentation of this file.
1 
6 using System;
7 using System.Text;
8 using System.Drawing;
9 using System.Drawing.Drawing2D;
10 using System.Diagnostics;
11 using System.Drawing.Imaging;
12 using System.IO;
13 using System.Runtime.InteropServices;
14 
16 {
18 public struct PFCPOINT
19 {
20  public int x;
21  public int y;
22 };
23 
25 public struct PFCRECT
26 {
27  public int left;
28  public int top;
29  public int width;
30  public int height;
31 };
32 
34 public struct PFCFBFACEINFO1
35 {
36  public PFCPOINT leftEye;
37  public PFCPOINT rightEye;
38  public PFCRECT face;
39 };
40 
42 public class PFCFBFACEINFO
43 {
44  public PFCPOINT leftEye;
45  public PFCPOINT rightEye;
46  public PFCRECT face;
47 
49  public PFCFBFACEINFO()
50  {
51  face.left = 0;
52  face.top = 0;
53  face.width = 0;
54  face.height = 0;
55  leftEye.x = 0;
56  leftEye.y = 0;
57  rightEye.x = 0;
58  rightEye.y = 0;
59  }
60 };
61 
63 public enum PFCFEATURE
64 {
65  CALC_CORE = 1,
66  CALC_NR = 2,
67  CALC_FB = 4,
68  CALC_RE = 8,
69  CALC_ALL = 15,
70  CALC_NOTINTCALC = 16,
71  CALC_NOFAE = 32,
72  CALC_FAEHISPEED = 64
73 };
74 
76 public enum PFCPIXELFORMAT
77 {
190 };
191 
193 public enum PFCPRESETID
194 {
198  PRESET_VIVID,
204 };
205 
207 public enum PFCNR_STATUS
208 {
217 };
218 
220 public enum PFCCORE_STATUS
221 {
230 };
231 
233 public enum PFCREJECTOPTION
234 {
235  PFC_REJECT_NONE = 0,
236  PFC_REJECT_MONOLITH = 1,
237  PFC_REJECT_CLIPART = 2
238 };
239 
241 public enum PFCFB_STATUS
242 {
254 };
255 
257 public enum PFCRE_STATUS
258 {
268 };
269 
271 public enum PFCAPPLYSTATUS
272 {
273  APPLY_SUCCESS = 0,
276  APPLY_CANCELLED = -3,
277  APPLY_NOSOURCE = -4,
278  APPLY_BADFORMAT = -5,
280 };
281 
283 public enum TINTCORRECTION
284 {
289 };
290 
292 public enum AGGRESSIVENESS
293 {
294  CONSERVATIVE,
295  MODERATE,
296  AGGRESSIVE,
297 };
298 
300 public enum DCFMODE
301 {
304 };
305 
307 public enum CONTRASTMODE
308 {
309  HIGH_CONTRAST,
311 };
312 
314 public enum BIASMODE
315 {
316  BIAS_NONE,
320 };
321 
323 public enum ADPTRRETURNCODE
324 {
325  SUCCESS,
326  WARNING,
327  INTERNALERROR,
328  WRONG_FORMAT
329 };
330 
332 public enum SKINMODE
333 {
334  SKINMODE_FACE = 1,
336 };
337 
339 public enum SKINSMOOTHTYPE
340 {
344 };
345 
347 public enum SKINTONINGTYPE
348 {
354 };
355 
357 public enum LIPSHARPENTYPE
358 {
359  LIPSHARPENTYPE_FINE = 1,
362 };
363 
365 public struct PFCCOREPARAM
366 {
367  public bool bEnabled;
368  public bool bAbnormalTintRemoval;
370  public float fTintScale;
371  public int iBlackEnhancement;
372  public bool bVibrancy;
373  public int iVibrancy;
374  public int iStrength;
375  public bool bContrast;
377  public int iContrast;
379  public float fBiasScale;
382  public bool bSharpen;
383  public float fSharpenScale;
385  public bool bUseFAE;
387  public int iMaxStrength;
388  public bool bInfrared;
389  public float fInfrared;
390  public bool bLightDiffusion;
391  public float fLightDiffusion;
392  public bool bDynamicRange;
393  public bool bDCF;
394  public DCFMODE eDCFMode;
395  public float fDCF;
396 };
397 
399 public struct PFCFBPARAM
400 {
401  public bool bEnabled;
402  public bool bSmooth;
403  public int iSmoothLevel;
406  public bool bEnlarge;
407  public int iEnlargeLevel;
408  public bool bEnhance;
409  public int iEnhanceLevel;
410  public bool bEyeCirc;
411  public int iEyeCirc;
412  public bool bTeeth;
413  public int iTeethLevel;
414  public bool bBlemish;
415  public int iBlemish;
416  public bool bSlim;
417  public int iSlim;
418  public bool bDeFlash;
419  public int iDeFlash;
420  public bool bCatchLight;
421  public int iCatchLight;
422  public int iCatchLightMode;
423  public bool bSkinToning;
430  public int iSkinToning;
433  public bool bLipSharpen;
434  public int iLipSharpen;
436  public bool bBlush;
437  public int iBlush;
438 };
439 
441 public unsafe struct PFCNRPARAM
442 {
443  public bool bEnabled;
444  public int iPreset;
445  public int iStrengthOffset;
453  public int iDetailOffset;
454 };
455 
457 public struct PFCREPARAM
458 
459 {
460  public bool bEnabled;
461 };
462 
463 // V3 additions
464 public enum PFCCORE_MASK_TYPE
465 {
466  PFCCORE_MASK_NONE, // 0.0 everywhere, don't apply
467  PFCCORE_MASK_ALL, // 1.0 everywhere (background)
468  PFCCORE_MASK_RADIAL, // ellipse
469  PFCCORE_MASK_TOP, // linear from 1.0 on top
470  PFCCORE_MASK_BOTTOM, // linear from 1.0 on bottom
471  PFCCORE_MASK_ROUNDRECT // rounded rect
472 };
473 
474 /* Description of mask for grad filter, all coordinates are relative (Y/height, X/width) in final crop-rotated image */
478 public unsafe struct PFCCOREMask
479 {
480  public PFCCORE_MASK_TYPE type;
481  public float centerX;
482  public float centerY;
483  public float width;
484  public float height;
485  public float radius;
486  public float feather;
487  public float angle;
488  public float transparency;
489  public bool invert;
490 };
491 
492 [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
494 public struct PFC3DLutInfo
495 {
496  [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 33)]
497  public string guid;
498 
499  public byte strength; // C++ unsigned char
500 }
501 
503 public unsafe struct PFCV3PARAM
504 {
505  // Image Ambulance
506  public bool bPreprocessEV;
507  public int iPreprocessEV;
508  // built-in 3D luts
509  public int iNeutralDensity;
510  public int iColorVibrancy;
515  // custom output 3D Lut
517  // Finishing
518  public int iFinishTemp;
519  public int iFinishTint;
520  public int iFinishExposure;
521  public int iFinishBlacks;
522  public int iFinishShadows;
523  public int iFinishHighlights;
524  public int iFinishWhites;
525  public int iFinishSaturation;
526  public int iFinishVibrancy;
527  public int iFinishContrast;
528 };
529 
530 [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
532 public struct PFCPARAM
533 {
535  public PFCFBPARAM fb;
536  public PFCNRPARAM nr;
537  public PFCREPARAM re;
538  public PFCV3PARAM v3;
545 };
546 
548 public struct PFCSTATUS
549 {
550  public PFCCORE_STATUS CORE_Status;
551  public PFCNR_STATUS NR_Status;
552  public PFCFB_STATUS FB_Status;
553  public PFCRE_STATUS RE_Status;
554  public int Status;
555 }
556 
563  public unsafe class PerfectlyClear : IDisposable
564  {
566  protected unsafe struct PFCENGINE
567  {
568  void* pEngine;
569  public uint status;
570  };
572  protected unsafe struct PerfectlyClearImageTransfer
573  {
574  public int width;
575  public int height;
576  public int rowBytes;
577  public int columnBytes;
578  public int data1;
579  public int data2;
580  public int data3;
581  };
582 
584  protected unsafe struct PFCIMAGEPROFILE
585  {
586  void* pPfcParam;
587  void* pNoiseParam;
588  void* pRedEyeParam;
589  void* pSFBParam;
590  void* pInternal;
591 
596 
597  public int Status;
598  };
605 
607  protected unsafe struct PFCIMAGE
608  {
609  public int width;
610  public int height;
611  public int stride;
613  public void* data;
614  };
615 
616 
617  protected PFCENGINE* m_pEngine;
618  protected PFCIMAGEPROFILE* m_pProfile;
619  public PFCPARAM m_Param;
620  public PFCSTATUS LastStatus;
621  private bool releaseProtection = false;
622 
656  public static int SetProtectionPath(string path, string licenseCode)
657  {
658 #if PROTECTION_ENABLED
659  try
660  {
661  byte* pLicpath = null;
662  if (!String.IsNullOrEmpty(path))
663  {
664  pLicpath = GetCharBuffer(path);
665  }
666 
667  byte* pLicenseCode = null;
668  if (!String.IsNullOrEmpty(licenseCode)) {
669  pLicenseCode = GetCharBuffer(licenseCode);
670  }
671 
672  int status = PFC_SetProtectionPath(pLicpath, pLicenseCode);
673 
674  FreeCharBuffer(pLicpath);
675  FreeCharBuffer(pLicenseCode);
676  //Trace.WriteLine("status " + status.ToString());
677 
678  return status;
679  }
680  catch (Exception ex)
681  {
682  Trace.WriteLine(ex.Message);
683  return 100;
684  }
685 #endif
686  return 0;
687  }
688 
689 
695  public static void ReleaseProtectionPath()
696  {
697  PFC_ReleaseProtectionPath();
698  }
699 
706  public PerfectlyClear()
707  {
708  m_pEngine = null;
709  m_pProfile = null;
710 
711  try
712  {
713  m_pEngine = PFC_CreateEngine();
714  if (m_pEngine != null)
715  {
716  LastStatus.Status = (int)(*m_pEngine).status;
717  }
718  }
719  catch (Exception ex)
720  {
721  Trace.WriteLine(ex.Message);
722  }
723 
724  PFC_SetParam(ref m_Param, PFCPRESETID.PRESET_IAUTO_21);
725  }
726 
736  public PerfectlyClear(string path, string licenseCode = "")
737  {
738  m_pEngine = null;
739  m_pProfile = null;
740 
741 #if PROTECTION_ENABLED
742  try
743  {
744  byte* pLicpath = null;
745  if (!String.IsNullOrEmpty(path))
746  {
747  pLicpath = GetCharBuffer(path);
748  }
749 
750  byte* pLicenseCode = null;
751  if (!String.IsNullOrEmpty(licenseCode)) {
752  pLicenseCode = GetCharBuffer(licenseCode);
753  }
754 
755  int status = PFC_SetProtectionPath(pLicpath, pLicenseCode);
756  releaseProtection = true;
757 
758  FreeCharBuffer(pLicpath);
759  FreeCharBuffer(pLicenseCode);
760  //Trace.WriteLine("status " + status.ToString());
761  }
762  catch (Exception ex)
763  {
764  Trace.WriteLine(ex.Message);
765  }
766 #endif
767  try
768  {
769  m_pEngine = PFC_CreateEngine();
770  if (m_pEngine != null)
771  {
772  LastStatus.Status = (int)(*m_pEngine).status;
773  }
774  }
775  catch (Exception ex)
776  {
777  Trace.WriteLine(ex.Message);
778  }
779 
780  PFC_SetParam(ref m_Param, PFCPRESETID.PRESET_IAUTO_21);
781  }
782 
783  ~PerfectlyClear()
784  {
785 #if PROTECTION_ENABLED
786  if(releaseProtection) {
788  }
789 #endif
790  Dispose(false);
791  }
792 
798  public unsafe ADPTRRETURNCODE Calc(ref Bitmap bm)
799  {
800  return Calc(ref bm, PFCFEATURE.CALC_ALL, -1, null);
801  }
802 
808  public unsafe ADPTRRETURNCODE Calc(ref PFCImageFile imgfile)
809  {
810  return Calc(ref imgfile, PFCFEATURE.CALC_ALL, -1, null);
811  }
812 
819  public unsafe ADPTRRETURNCODE Calc(ref Bitmap bm, ref Bitmap bmds)
820  {
821  return Calc(ref bm, ref bmds, PFCFEATURE.CALC_ALL, -1, null);
822  }
823 
830  public unsafe ADPTRRETURNCODE Calc(ref PFCImageFile imgfile, PFCFEATURE feature)
831  {
832  return Calc(ref imgfile, feature, -1, null);
833  }
834 
841  public unsafe ADPTRRETURNCODE Calc(ref Bitmap bm, PFCFEATURE feature)
842  {
843  return Calc(ref bm, feature, -1, null);
844  }
845 
853  public unsafe ADPTRRETURNCODE Calc(ref Bitmap bm, ref Bitmap bmds, PFCFEATURE feature)
854  {
855  return Calc(ref bm, ref bmds, feature, -1, null);
856  }
857 
867  public unsafe ADPTRRETURNCODE Calc(ref Bitmap bm, PFCFEATURE feature, int ISO, string CameraModel, PFCREJECTOPTION rejectOption = PFCREJECTOPTION.PFC_REJECT_CLIPART)
868  {
869  BitmapData bd = null;
870  Byte* pBase = null;
871  bd = LockBitmapData(ref bm);
872  if (bd.PixelFormat != PixelFormat.Format24bppRgb &&
873  bd.PixelFormat != PixelFormat.Format32bppArgb &&
874  bd.PixelFormat != PixelFormat.Format48bppRgb &&
875  bd.PixelFormat != PixelFormat.Format64bppArgb)
876  {
877  ReleaseBitmapData(ref bm, ref bd);
878  return ADPTRRETURNCODE.WRONG_FORMAT;
879  }
880  pBase = (Byte*)bd.Scan0.ToPointer();
881 
882  PFCIMAGE im;
883  im.width = bd.Width;
884  im.height = bd.Height;
885  im.stride = bd.Stride;
886  switch (bd.PixelFormat)
887  {
888  default:
889  case PixelFormat.Format24bppRgb: im.format = PFCPIXELFORMAT.PFC_PixelFormat24bppRGB; break;
890  case PixelFormat.Format32bppArgb: im.format = PFCPIXELFORMAT.PFC_PixelFormat32bppARGB; break;
891  case PixelFormat.Format48bppRgb: im.format = PFCPIXELFORMAT.PFC_PixelFormat48bppRGB; break;
892  case PixelFormat.Format64bppArgb: im.format = PFCPIXELFORMAT.PFC_PixelFormat64bppARGB; break;
893  }
894  im.data = (void*)pBase;
895 
896  if (m_pProfile != null)
897  PFC_ReleaseProfile(m_pProfile);
898 
899  byte* pModel = null;
900  if (CameraModel != null)
901  {
902  pModel = GetCharBuffer(CameraModel);
903  }
904  m_pProfile = PFC_Calc(&im, null, m_pEngine, feature, ISO, pModel, null, null, (int)rejectOption);
905 
906  FreeCharBuffer(pModel);
907 
908  ReleaseBitmapData(ref bm, ref bd);
909 
910  LastStatus.NR_Status = (*m_pProfile).NR_Status;
911  LastStatus.CORE_Status = (*m_pProfile).CORE_Status;
912  LastStatus.FB_Status = (*m_pProfile).FB_Status;
913  LastStatus.RE_Status = (*m_pProfile).RE_Status;
914  LastStatus.Status = (*m_pProfile).Status;
915 
916  return (LastStatus.Status == 0) ? ADPTRRETURNCODE.SUCCESS : ADPTRRETURNCODE.WARNING;
917  }
918 
928  public unsafe ADPTRRETURNCODE Calc(ref PFCImageFile imgfile, PFCFEATURE feature, int ISO, string CameraModel, PFCREJECTOPTION rejectOption = PFCREJECTOPTION.PFC_REJECT_CLIPART)
929  {
930  PFCIMAGE im;
931  im.width = imgfile.width();
932  im.height = imgfile.height();
933  im.stride = imgfile.stride();
934  im.format = (PFCPIXELFORMAT)imgfile.pfcImageFormat();
935  im.data = (void*)imgfile.raw_image();
936 
937  if (m_pProfile != null)
938  PFC_ReleaseProfile(m_pProfile);
939 
940  byte* pModel = null;
941  if (CameraModel != null)
942  {
943  pModel = GetCharBuffer(CameraModel);
944  }
945  m_pProfile = PFC_Calc(&im, null, m_pEngine, feature, ISO, pModel, null, null, (int)rejectOption);
946 
947  FreeCharBuffer(pModel);
948 
949  LastStatus.NR_Status = (*m_pProfile).NR_Status;
950  LastStatus.CORE_Status = (*m_pProfile).CORE_Status;
951  LastStatus.FB_Status = (*m_pProfile).FB_Status;
952  LastStatus.RE_Status = (*m_pProfile).RE_Status;
953  LastStatus.Status = (*m_pProfile).Status;
954 
955  return (LastStatus.Status == 0) ? ADPTRRETURNCODE.SUCCESS : ADPTRRETURNCODE.WARNING;
956  }
957 
967  public unsafe ADPTRRETURNCODE Calc(ref Bitmap bm, ref Bitmap bmds, PFCFEATURE feature, int ISO, string CameraModel)
968  {
969  BitmapData bd = null;
970  Byte* pBase = null;
971  bd = LockBitmapData(ref bm);
972  if (bd.PixelFormat != PixelFormat.Format24bppRgb &&
973  bd.PixelFormat != PixelFormat.Format32bppArgb &&
974  bd.PixelFormat != PixelFormat.Format48bppRgb &&
975  bd.PixelFormat != PixelFormat.Format64bppArgb)
976  {
977  ReleaseBitmapData(ref bm, ref bd);
978  return ADPTRRETURNCODE.WRONG_FORMAT;
979  }
980  pBase = (Byte*)bd.Scan0.ToPointer();
981 
982  PFCIMAGE im;
983  im.width = bd.Width;
984  im.height = bd.Height;
985  im.stride = bd.Stride;
986  switch (bd.PixelFormat)
987  {
988  default:
989  case PixelFormat.Format24bppRgb: im.format = PFCPIXELFORMAT.PFC_PixelFormat24bppRGB; break;
990  case PixelFormat.Format32bppArgb: im.format = PFCPIXELFORMAT.PFC_PixelFormat32bppARGB; break;
991  case PixelFormat.Format48bppRgb: im.format = PFCPIXELFORMAT.PFC_PixelFormat48bppRGB; break;
992  case PixelFormat.Format64bppArgb: im.format = PFCPIXELFORMAT.PFC_PixelFormat64bppARGB; break;
993  }
994  im.data = (void*)pBase;
995 
996  BitmapData bdds = null;
997  bdds = LockBitmapData(ref bmds);
998  if (bdds.PixelFormat != PixelFormat.Format24bppRgb &&
999  bdds.PixelFormat != PixelFormat.Format32bppArgb &&
1000  bdds.PixelFormat != PixelFormat.Format48bppRgb &&
1001  bdds.PixelFormat != PixelFormat.Format64bppArgb)
1002  {
1003  ReleaseBitmapData(ref bmds, ref bdds);
1004  return ADPTRRETURNCODE.WRONG_FORMAT;
1005  }
1006  pBase = (Byte*)bdds.Scan0.ToPointer();
1007 
1008  PFCIMAGE imds;
1009  imds.width = bdds.Width;
1010  imds.height = bdds.Height;
1011  imds.stride = bdds.Stride;
1012  switch (bdds.PixelFormat)
1013  {
1014  default:
1015  case PixelFormat.Format24bppRgb: imds.format = PFCPIXELFORMAT.PFC_PixelFormat24bppRGB; break;
1016  case PixelFormat.Format32bppArgb: imds.format = PFCPIXELFORMAT.PFC_PixelFormat32bppARGB; break;
1017  case PixelFormat.Format48bppRgb: imds.format = PFCPIXELFORMAT.PFC_PixelFormat48bppRGB; break;
1018  case PixelFormat.Format64bppArgb: imds.format = PFCPIXELFORMAT.PFC_PixelFormat64bppARGB; break;
1019  }
1020  imds.data = (void*)pBase;
1021 
1022  if (m_pProfile != null)
1023  PFC_ReleaseProfile(m_pProfile);
1024 
1025  byte* pModel = null;
1026  if (CameraModel != null)
1027  {
1028  pModel = GetCharBuffer(CameraModel);
1029  }
1030  m_pProfile = PFC_Calc(&im, &imds, m_pEngine, feature, ISO, pModel, null, null, 1);
1031 
1032  FreeCharBuffer(pModel);
1033 
1034  ReleaseBitmapData(ref bm, ref bd);
1035  ReleaseBitmapData(ref bmds, ref bdds);
1036 
1037  LastStatus.NR_Status = (*m_pProfile).NR_Status;
1038  LastStatus.CORE_Status = (*m_pProfile).CORE_Status;
1039  LastStatus.FB_Status = (*m_pProfile).FB_Status;
1040  LastStatus.RE_Status = (*m_pProfile).RE_Status;
1041  LastStatus.Status = (*m_pProfile).Status;
1042 
1043  return (LastStatus.Status == 0) ? ADPTRRETURNCODE.SUCCESS : ADPTRRETURNCODE.WARNING;
1044  }
1045 
1052  public unsafe PFCAPPLYSTATUS Apply(ref Bitmap bm)
1053  {
1054  return Apply(ref bm, 100);
1055  }
1056 
1062  public unsafe PFCAPPLYSTATUS Apply(ref PFCImageFile imgfile)
1063  {
1064  return Apply(ref imgfile, 100);
1065  }
1066 
1073  public unsafe PFCAPPLYSTATUS Apply(ref Bitmap bm, int iOpacity)
1074  {
1075  if (m_pProfile == null)
1076  {
1077  return PFCAPPLYSTATUS.APPLY_ERROR_PROFILE_MISSING;
1078  }
1079 
1080  BitmapData bd = null;
1081  Byte* pBase = null;
1082  bd = LockBitmapData(ref bm);
1083  if (bd.PixelFormat != PixelFormat.Format24bppRgb &&
1084  bd.PixelFormat != PixelFormat.Format32bppArgb &&
1085  bd.PixelFormat != PixelFormat.Format48bppRgb &&
1086  bd.PixelFormat != PixelFormat.Format64bppArgb)
1087  {
1088  ReleaseBitmapData(ref bm, ref bd);
1089  return PFCAPPLYSTATUS.APPLY_BADFORMAT;
1090  }
1091  pBase = (Byte*)bd.Scan0.ToPointer();
1092 
1093  PFCIMAGE im;
1094  im.width = bd.Width;
1095  im.height = bd.Height;
1096  im.stride = bd.Stride;
1097  switch (bd.PixelFormat)
1098  {
1099  default:
1100  case PixelFormat.Format24bppRgb: im.format = PFCPIXELFORMAT.PFC_PixelFormat24bppRGB; break;
1101  case PixelFormat.Format32bppArgb: im.format = PFCPIXELFORMAT.PFC_PixelFormat32bppARGB; break;
1102  case PixelFormat.Format48bppRgb: im.format = PFCPIXELFORMAT.PFC_PixelFormat48bppRGB; break;
1103  case PixelFormat.Format64bppArgb: im.format = PFCPIXELFORMAT.PFC_PixelFormat64bppARGB; break;
1104  }
1105  im.data = (void*)pBase;
1106 
1107  PFCAPPLYSTATUS ret = PFC_Apply(&im, m_pEngine, m_pProfile, ref m_Param, null, iOpacity, null);
1108 
1109  if (ret > 0)
1110  {
1111  int code = (int)ret;
1112  // Get individual return codes
1113  LastStatus.NR_Status = (PFCNR_STATUS)(code & 0x000000FF);
1114  LastStatus.CORE_Status = (PFCCORE_STATUS)((code >> 8) & 0x000000FF);
1115  LastStatus.FB_Status = (PFCFB_STATUS)((code >> 16) & 0x000000FF);
1116  LastStatus.RE_Status = (PFCRE_STATUS)((code >> 24) & 0x000000FF);
1117  LastStatus.Status = code;
1118  }
1119 
1120  ReleaseBitmapData(ref bm, ref bd);
1121  return ret;
1122  }
1123 
1130  public unsafe PFCAPPLYSTATUS Apply(ref PFCImageFile imgfile, int iOpacity)
1131  {
1132  if (m_pProfile == null)
1133  {
1134  return PFCAPPLYSTATUS.APPLY_ERROR_PROFILE_MISSING;
1135  }
1136 
1137  PFCIMAGE im;
1138  im.width = imgfile.width();
1139  im.height = imgfile.height();
1140  im.stride = imgfile.stride();
1141  im.format = (PFCPIXELFORMAT)imgfile.pfcImageFormat();
1142  im.data = (void*)imgfile.raw_image();
1143 
1144  PFCAPPLYSTATUS ret = PFC_Apply(&im, m_pEngine, m_pProfile, ref m_Param, null, iOpacity, null);
1145 
1146  if (ret > 0)
1147  {
1148  int code = (int)ret;
1149  // Get individual return codes
1150  LastStatus.NR_Status = (PFCNR_STATUS)(code & 0x000000FF);
1151  LastStatus.CORE_Status = (PFCCORE_STATUS)((code >> 8) & 0x000000FF);
1152  LastStatus.FB_Status = (PFCFB_STATUS)((code >> 16) & 0x000000FF);
1153  LastStatus.RE_Status = (PFCRE_STATUS)((code >> 24) & 0x000000FF);
1154  LastStatus.Status = code;
1155  }
1156 
1157  return ret;
1158  }
1159 
1160  public unsafe PFCAPPLYSTATUS ApplyLocal(ref Bitmap bm, int xOffset, int yOffset, int widthOrig, int heightOrig)
1161  {
1162  return ApplyLocal(ref bm, xOffset, yOffset, widthOrig, heightOrig, 100);
1163  }
1164 
1165  public unsafe PFCAPPLYSTATUS ApplyLocal(ref Bitmap bm, int xOffset, int yOffset, int widthOrig, int heightOrig, int iOpacity)
1166  {
1167  BitmapData bd = null;
1168  Byte* pBase = null;
1169  bd = LockBitmapData(ref bm);
1170  if (bd.PixelFormat != PixelFormat.Format24bppRgb &&
1171  bd.PixelFormat != PixelFormat.Format32bppArgb &&
1172  bd.PixelFormat != PixelFormat.Format48bppRgb &&
1173  bd.PixelFormat != PixelFormat.Format64bppArgb)
1174  {
1175  ReleaseBitmapData(ref bm, ref bd);
1176  return PFCAPPLYSTATUS.APPLY_BADFORMAT;
1177  }
1178  pBase = (Byte*)bd.Scan0.ToPointer();
1179 
1180  PFCIMAGE im;
1181  im.width = bd.Width;
1182  im.height = bd.Height;
1183  im.stride = bd.Stride;
1184  switch (bd.PixelFormat)
1185  {
1186  default:
1187  case PixelFormat.Format24bppRgb: im.format = PFCPIXELFORMAT.PFC_PixelFormat24bppRGB; break;
1188  case PixelFormat.Format32bppArgb: im.format = PFCPIXELFORMAT.PFC_PixelFormat32bppARGB; break;
1189  case PixelFormat.Format48bppRgb: im.format = PFCPIXELFORMAT.PFC_PixelFormat48bppRGB; break;
1190  case PixelFormat.Format64bppArgb: im.format = PFCPIXELFORMAT.PFC_PixelFormat64bppARGB; break;
1191  }
1192  im.data = (void*)pBase;
1193 
1194  PFCAPPLYSTATUS ret = PFC_ApplyLocal(&im, xOffset, yOffset, widthOrig, heightOrig, m_pEngine, m_pProfile, ref m_Param, iOpacity);
1195 
1196  ReleaseBitmapData(ref bm, ref bd);
1197  return ret;
1198  }
1199 
1200  public unsafe PFCAPPLYSTATUS ApplyLocal(ref PFCImageFile imgfile, int xOffset, int yOffset, int widthOrig, int heightOrig, int iOpacity)
1201  {
1202  PFCIMAGE im;
1203  im.width = imgfile.width();
1204  im.height = imgfile.height();
1205  im.stride = imgfile.stride();
1206  im.format = (PFCPIXELFORMAT)imgfile.pfcImageFormat();
1207  im.data = (void*)imgfile.raw_image();
1208 
1209  PFCAPPLYSTATUS ret = PFC_ApplyLocal(&im, xOffset, yOffset, widthOrig, heightOrig, m_pEngine, m_pProfile, ref m_Param, iOpacity);
1210 
1211  return ret;
1212  }
1213 
1244  public int AutoCorrect(ref Bitmap bm)
1245  {
1246  return AutoCorrect(ref bm, -1, null, false);
1247  }
1248 
1254  public int AutoCorrect(ref PFCImageFile imgfile)
1255  {
1256  return AutoCorrect(ref imgfile, -1, null, false);
1257  }
1258 
1266  public int AutoCorrect(ref Bitmap bm, ref Bitmap bmds)
1267  {
1268  return AutoCorrect(ref bm, ref bmds, -1, null, false);
1269  }
1270 
1279  public int AutoCorrect(ref Bitmap bm, int ISO, string CameraModel, bool bFastFAE)
1280  {
1281  PFCFEATURE feature = 0;
1282  if (m_Param.nr.bEnabled)
1283  feature |= PFCFEATURE.CALC_NR;
1284  if (m_Param.core.bEnabled)
1285  feature |= PFCFEATURE.CALC_CORE;
1286  if (m_Param.fb.bEnabled)
1287  feature |= PFCFEATURE.CALC_FB;
1288  if (m_Param.re.bEnabled)
1289  feature |= PFCFEATURE.CALC_RE;
1290  if (!m_Param.core.bAbnormalTintRemoval)
1291  feature |= PFCFEATURE.CALC_NOTINTCALC;
1292  // Any FAE optimization
1293  if (m_Param.core.bUseFAE)
1294  {
1295  if (bFastFAE)
1296  feature |= PFCFEATURE.CALC_FAEHISPEED;
1297  }
1298  else
1299  {
1300  feature |= PFCFEATURE.CALC_NOFAE;
1301  }
1302 
1303  ADPTRRETURNCODE ret = Calc(ref bm, feature, ISO, CameraModel);
1304 
1305  if (ret != ADPTRRETURNCODE.SUCCESS)
1306  {
1307  PFCNR_STATUS retNR = LastStatus.NR_Status;
1308  if (retNR == PFCNR_STATUS.PFC_NR_NOTFOUND || retNR == PFCNR_STATUS.PFC_NR_NOTENABLED)
1309  retNR = PFCNR_STATUS.PFC_NR_SUCCESS;
1310 
1311  PFCCORE_STATUS retCORE = LastStatus.CORE_Status;
1312  if (retCORE == PFCCORE_STATUS.PFC_CORE_NOTENABLED)
1313  retCORE = PFCCORE_STATUS.PFC_CORE_SUCCESS;
1314 
1315  PFCFB_STATUS retFB = LastStatus.FB_Status;
1316  if (retFB == PFCFB_STATUS.PFC_FB_NOTENABLED || retFB == PFCFB_STATUS.PFC_FB_WARNING)
1317  retFB = PFCFB_STATUS.PFC_FB_SUCCESS;
1318 
1319  PFCRE_STATUS retRE = LastStatus.RE_Status;
1320  if (retRE == PFCRE_STATUS.PFC_RE_NOTENABLED || retRE == PFCRE_STATUS.PFC_RE_NOT_FOUND)
1321  retRE = PFCRE_STATUS.PFC_RE_SUCCESS;
1322 
1323  int retInt = (((((((int)retRE << 8) | (int)retFB) << 8) | (int)retCORE) << 8) | (int)retNR);
1324  return retInt;
1325  }
1326  else
1327  {
1328  PFCAPPLYSTATUS aret = Apply(ref bm);
1329  return (int)aret;
1330  }
1331  }
1332 
1341  public int AutoCorrect(ref PFCImageFile imgfile, int ISO, string CameraModel, bool bFastFAE)
1342  {
1343  PFCFEATURE feature = 0;
1344  if (m_Param.nr.bEnabled)
1345  feature |= PFCFEATURE.CALC_NR;
1346  if (m_Param.core.bEnabled)
1347  feature |= PFCFEATURE.CALC_CORE;
1348  if (m_Param.fb.bEnabled)
1349  feature |= PFCFEATURE.CALC_FB;
1350  if (m_Param.re.bEnabled)
1351  feature |= PFCFEATURE.CALC_RE;
1352  if (!m_Param.core.bAbnormalTintRemoval)
1353  feature |= PFCFEATURE.CALC_NOTINTCALC;
1354  // Any FAE optimization
1355  if (m_Param.core.bUseFAE)
1356  {
1357  if (bFastFAE)
1358  feature |= PFCFEATURE.CALC_FAEHISPEED;
1359  }
1360  else
1361  {
1362  feature |= PFCFEATURE.CALC_NOFAE;
1363  }
1364 
1365  ADPTRRETURNCODE ret = Calc(ref imgfile, feature, ISO, CameraModel);
1366 
1367  if (ret != ADPTRRETURNCODE.SUCCESS)
1368  {
1369  PFCNR_STATUS retNR = LastStatus.NR_Status;
1370  if (retNR == PFCNR_STATUS.PFC_NR_NOTFOUND || retNR == PFCNR_STATUS.PFC_NR_NOTENABLED)
1371  retNR = PFCNR_STATUS.PFC_NR_SUCCESS;
1372 
1373  PFCCORE_STATUS retCORE = LastStatus.CORE_Status;
1374  if (retCORE == PFCCORE_STATUS.PFC_CORE_NOTENABLED)
1375  retCORE = PFCCORE_STATUS.PFC_CORE_SUCCESS;
1376 
1377  PFCFB_STATUS retFB = LastStatus.FB_Status;
1378  if (retFB == PFCFB_STATUS.PFC_FB_NOTENABLED || retFB == PFCFB_STATUS.PFC_FB_WARNING)
1379  retFB = PFCFB_STATUS.PFC_FB_SUCCESS;
1380 
1381  PFCRE_STATUS retRE = LastStatus.RE_Status;
1382  if (retRE == PFCRE_STATUS.PFC_RE_NOTENABLED || retRE == PFCRE_STATUS.PFC_RE_NOT_FOUND)
1383  retRE = PFCRE_STATUS.PFC_RE_SUCCESS;
1384 
1385  int retInt = (((((((int)retRE << 8) | (int)retFB) << 8) | (int)retCORE) << 8) | (int)retNR);
1386  return retInt;
1387  }
1388  else
1389  {
1390  PFCAPPLYSTATUS aret = Apply(ref imgfile);
1391  return (int)aret;
1392  }
1393  }
1394 
1404  public int AutoCorrect(ref Bitmap bm, ref Bitmap bmds, int ISO, string CameraModel, bool bFastFAE)
1405  {
1406  PFCFEATURE feature = 0;
1407  if (m_Param.nr.bEnabled)
1408  feature |= PFCFEATURE.CALC_NR;
1409  if (m_Param.core.bEnabled)
1410  feature |= PFCFEATURE.CALC_CORE;
1411  if (m_Param.fb.bEnabled)
1412  feature |= PFCFEATURE.CALC_FB;
1413  if (m_Param.re.bEnabled)
1414  feature |= PFCFEATURE.CALC_RE;
1415  if (!m_Param.core.bAbnormalTintRemoval)
1416  feature |= PFCFEATURE.CALC_NOTINTCALC;
1417  // Any FAE optimization
1418  if (m_Param.core.bUseFAE)
1419  {
1420  if (bFastFAE)
1421  feature |= PFCFEATURE.CALC_FAEHISPEED;
1422  }
1423  else
1424  {
1425  feature |= PFCFEATURE.CALC_NOFAE;
1426  }
1427 
1428  ADPTRRETURNCODE ret = Calc(ref bm, ref bmds, feature, ISO, CameraModel);
1429 
1430  if (ret != ADPTRRETURNCODE.SUCCESS)
1431  {
1432  PFCNR_STATUS retNR = LastStatus.NR_Status;
1433  if (retNR == PFCNR_STATUS.PFC_NR_NOTFOUND || retNR == PFCNR_STATUS.PFC_NR_NOTENABLED)
1434  retNR = PFCNR_STATUS.PFC_NR_SUCCESS;
1435 
1436  PFCCORE_STATUS retCORE = LastStatus.CORE_Status;
1437  if (retCORE == PFCCORE_STATUS.PFC_CORE_NOTENABLED)
1438  retCORE = PFCCORE_STATUS.PFC_CORE_SUCCESS;
1439 
1440  PFCFB_STATUS retFB = LastStatus.FB_Status;
1441  if (retFB == PFCFB_STATUS.PFC_FB_NOTENABLED || retFB == PFCFB_STATUS.PFC_FB_WARNING)
1442  retFB = PFCFB_STATUS.PFC_FB_SUCCESS;
1443 
1444  PFCRE_STATUS retRE = LastStatus.RE_Status;
1445  if (retRE == PFCRE_STATUS.PFC_RE_NOTENABLED || retRE == PFCRE_STATUS.PFC_RE_NOT_FOUND)
1446  retRE = PFCRE_STATUS.PFC_RE_SUCCESS;
1447 
1448  int retInt = (((((((int)retRE << 8) | (int)retFB) << 8) | (int)retCORE) << 8) | (int)retNR);
1449  return retInt;
1450  }
1451  else
1452  {
1453  PFCAPPLYSTATUS aret = Apply(ref bm);
1454  return (int)aret;
1455  }
1456  }
1457 
1464  public int AutoCorrect(ref Bitmap bm, string pathPreset)
1465  {
1466  int retCode = ReadPresets(pathPreset);
1467  if (retCode == 0)
1468  {
1469  return AutoCorrect(ref bm, -1, null, false);
1470  }
1471  return retCode-1000;
1472  }
1473 
1480  public int AutoCorrect(ref PFCImageFile imgfile, string pathPreset)
1481  {
1482  int retCode = ReadPresets(pathPreset);
1483  if (retCode == 0)
1484  {
1485  return AutoCorrect(ref imgfile, -1, null, false);
1486  }
1487  return retCode - 1000;
1488  }
1489 
1497  public int AutoCorrect(ref Bitmap bm, ref Bitmap bmds, string pathPreset)
1498  {
1499  int retCode = ReadPresets(pathPreset);
1500  if (retCode == 0)
1501  {
1502  return AutoCorrect(ref bm, ref bmds, -1, null, false);
1503  }
1504  return retCode - 1000;
1505  }
1506 
1516  public int AutoCorrect(ref Bitmap bm, string pathPreset, int ISO, string CameraModel, bool bFastFAE)
1517  {
1518  int retCode = ReadPresets(pathPreset);
1519  if (retCode == 0)
1520  {
1521  return AutoCorrect(ref bm, ISO, CameraModel, bFastFAE);
1522  }
1523  return retCode - 1000;
1524  }
1525 
1535  public int AutoCorrect(ref PFCImageFile imgfile, string pathPreset, int ISO, string CameraModel, bool bFastFAE)
1536  {
1537  int retCode = ReadPresets(pathPreset);
1538  if (retCode == 0)
1539  {
1540  return AutoCorrect(ref imgfile, ISO, CameraModel, bFastFAE);
1541  }
1542  return retCode - 1000;
1543  }
1544 
1555  public int AutoCorrect(ref Bitmap bm, ref Bitmap bmds, string pathPreset, int ISO, string CameraModel, bool bFastFAE)
1556  {
1557  int retCode = ReadPresets(pathPreset);
1558  if (retCode == 0)
1559  {
1560  return AutoCorrect(ref bm, ref bmds, ISO, CameraModel, bFastFAE);
1561  }
1562  return retCode - 1000;
1563  }
1564 
1569  public void SetParam(PFCPRESETID id)
1570  {
1571  PFC_SetParam(ref m_Param, id);
1572  }
1573 
1591  public int ReadPresets(string path)
1592  {
1593  try
1594  {
1595  byte* presetpath = null;
1596  if (path != null)
1597  {
1598  presetpath = GetCharBuffer(path);
1599  }
1600 
1601  int status = PFC_ReadPresets(ref m_Param, presetpath);
1602  //Trace.WriteLine("status " + status.ToString());
1603  return status;
1604  }
1605  catch (Exception ex)
1606  {
1607  Trace.WriteLine(ex.Message);
1608  }
1609  return -8;
1610  }
1611 
1624  public int ReadPresetsFromStream(FileStream fs)
1625  {
1626  try
1627  {
1628  long len = fs.Length;
1629  byte[] buffer = new byte[len + 1];
1630  int size = (int)len;
1631  fs.Read(buffer, 0, size);
1632  buffer[size] = 0;
1633  byte* b = GetCharBuffer(buffer);
1634  // PFC_ReadPresetsFromStream return codes
1635  // 0 - success
1636  // -3 - Stream read error.
1637  // -4 - Parse error.
1638  int status = PFC_ReadPresetsFromStream(ref m_Param, b);
1639  FreeCharBuffer(b);
1640  return status;
1641  }
1642  catch (Exception ex)
1643  {
1644  Trace.WriteLine(ex.Message);
1645  }
1646  return -8;
1647  }
1648 
1654  {
1655  return PFC_HasFaceBeautification(m_pEngine);
1656  }
1657 
1663  public int FBFaceCount()
1664  {
1665  return PFC_FBFaceCount(m_pProfile);
1666  }
1667 
1676  public bool GetFaceInfo(ref PFCFBFACEINFO info, int index)
1677  {
1678  PFCFBFACEINFO1 fi;
1679  bool ret = PFC_GetFaceInfo(m_pProfile, &fi, index);
1680  info.face.left = fi.face.left;
1681  info.face.top = fi.face.top;
1682  info.face.width = fi.face.width;
1683  info.face.height = fi.face.height;
1684  info.leftEye.x = fi.leftEye.x;
1685  info.leftEye.y = fi.leftEye.y;
1686  info.rightEye.x = fi.rightEye.x;
1687  info.rightEye.y = fi.rightEye.y;
1688  return ret;
1689  }
1690 
1696  public bool AbnormalTintDetected(TINTCORRECTION eTintMethod)
1697  {
1698  return PFC_AbnormalTintDetected(m_pProfile, eTintMethod);
1699  }
1700 
1706  public void ApplyStrengthToParam(int strength)
1707  {
1708  PFC_ApplyStrengthToParam(ref m_Param, strength);
1709  }
1710 
1711  protected BitmapData LockBitmapData(ref Bitmap bm)
1712  {
1713  GraphicsUnit unit = GraphicsUnit.Pixel;
1714  RectangleF boundsF = bm.GetBounds(ref unit);
1715  Rectangle bounds = new Rectangle((int)boundsF.X,
1716  (int)boundsF.Y,
1717  (int)boundsF.Width,
1718  (int)boundsF.Height);
1719 
1720  BitmapData bitmapData =
1721  bm.LockBits(bounds, ImageLockMode.ReadWrite, bm.PixelFormat);
1722  return bitmapData;
1723  }
1724 
1725  protected void ReleaseBitmapData(ref Bitmap bm, ref BitmapData bitmapData)
1726  {
1727  bm.UnlockBits(bitmapData);
1728  }
1729 
1730  protected Bitmap DupBitmap(ref Bitmap bm)
1731  {
1732  PerfectlyClearImageTransfer tr, tr1;
1733  Byte* pBase = null;
1734  GraphicsUnit unit = GraphicsUnit.Pixel;
1735  RectangleF boundsF = bm.GetBounds(ref unit);
1736  Rectangle bounds = new Rectangle((int)boundsF.X,
1737  (int)boundsF.Y,
1738  (int)boundsF.Width,
1739  (int)boundsF.Height);
1740  BitmapData bd = bm.LockBits(bounds, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
1741  Bitmap bm1 = new Bitmap(bd.Width, bd.Height, PixelFormat.Format24bppRgb);
1742  BitmapData bd1 = LockBitmapData(ref bm1);
1743  pBase = (Byte*)bd.Scan0.ToPointer();
1744  tr.columnBytes = (bd.PixelFormat == PixelFormat.Format24bppRgb) ? 3 : 4;
1745  tr.rowBytes = bd.Stride;
1746  tr.height = bd.Height;
1747  tr.width = bd.Width;
1748  tr.data1 = (int)(pBase + 2);
1749  tr.data2 = (int)(pBase + 1);
1750  tr.data3 = (int)pBase;
1751  pBase = (Byte*)bd1.Scan0.ToPointer();
1752  tr1.columnBytes = (bd1.PixelFormat == PixelFormat.Format24bppRgb) ? 3 : 4;
1753  tr1.rowBytes = bd1.Stride;
1754  tr1.height = bd1.Height;
1755  tr1.width = bd1.Width;
1756  tr1.data1 = (int)(pBase + 2);
1757  tr1.data2 = (int)(pBase + 1);
1758  tr1.data3 = (int)pBase;
1759  for (int i = 0; i < tr.height; i++)
1760  {
1761  for (int j = 0; j < tr.width; j++)
1762  {
1763  ((Byte*)tr1.data1)[j * tr1.columnBytes] = ((Byte*)tr.data1)[j * tr.columnBytes];
1764  ((Byte*)tr1.data2)[j * tr1.columnBytes] = ((Byte*)tr.data2)[j * tr.columnBytes];
1765  ((Byte*)tr1.data3)[j * tr1.columnBytes] = ((Byte*)tr.data3)[j * tr.columnBytes];
1766  }
1767  tr.data1 += (int)tr.rowBytes;
1768  tr.data2 += (int)tr.rowBytes;
1769  tr.data3 += (int)tr.rowBytes;
1770  tr1.data1 += (int)tr1.rowBytes;
1771  tr1.data2 += (int)tr1.rowBytes;
1772  tr1.data3 += (int)tr1.rowBytes;
1773  }
1774  ReleaseBitmapData(ref bm1, ref bd1);
1775  ReleaseBitmapData(ref bm, ref bd);
1776  return bm1;
1777  }
1778 
1779  protected Bitmap BW2RGB(ref Bitmap bm)
1780  {
1781  Byte* pBase = null;
1782  Byte* pBase1 = null;
1783  GraphicsUnit unit = GraphicsUnit.Pixel;
1784  RectangleF boundsF = bm.GetBounds(ref unit);
1785  Rectangle bounds = new Rectangle((int)boundsF.X,
1786  (int)boundsF.Y,
1787  (int)boundsF.Width,
1788  (int)boundsF.Height);
1789  BitmapData bd = bm.LockBits(bounds, ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);
1790  Bitmap bm1 = new Bitmap(bd.Width, bd.Height, PixelFormat.Format24bppRgb);
1791  BitmapData bd1 = LockBitmapData(ref bm1);
1792  pBase = (Byte*)bd.Scan0.ToPointer();
1793  pBase1 = (Byte*)bd1.Scan0.ToPointer();
1794  for (int i = 0; i < bd.Height; i++)
1795  {
1796  for (int j = 0; j < bd.Width; j++)
1797  {
1798  pBase1[j * 3] = pBase[j];
1799  pBase1[j * 3 + 1] = pBase[j];
1800  pBase1[j * 3 + 2] = pBase[j];
1801  }
1802  pBase += bd.Stride;
1803  pBase1 += bd1.Stride;
1804  }
1805  ReleaseBitmapData(ref bm1, ref bd1);
1806  ReleaseBitmapData(ref bm, ref bd);
1807  return bm1;
1808  }
1809 
1817  public Bitmap ReadImage(string filename)
1818  {
1819  Bitmap bm = null;
1820  Bitmap myBitmap = new Bitmap(filename);
1821  if ((myBitmap.Flags & (int)ImageFlags.ColorSpaceYcck) != 0)
1822  {
1823  bm = DupBitmap(ref myBitmap);
1824  myBitmap.Dispose();
1825  }
1826  else
1827  {
1828  if (myBitmap.PixelFormat == PixelFormat.Format8bppIndexed)
1829  {
1830  bm = BW2RGB(ref myBitmap);
1831  myBitmap.Dispose();
1832  }
1833  else
1834  {
1835  bm = myBitmap;
1836  }
1837  }
1838  return bm;
1839  }
1840 
1841  protected Bitmap GetStatImage(ref Bitmap bm, int iMaxDimension)
1842  {
1843  // Build max dim reference image
1844  bool bNeedResize = true;
1845  int w, h, w1, h1;
1846  w = bm.Width;
1847  h = bm.Height;
1848  // Calculate size of reference image. One dimension is 1024.
1849  if (w > h)
1850  {
1851  if (w <= iMaxDimension)
1852  bNeedResize = false;
1853  w1 = iMaxDimension;
1854  h1 = w1 * h / w;
1855  }
1856  else
1857  {
1858  if (h <= iMaxDimension)
1859  bNeedResize = false;
1860  h1 = iMaxDimension;
1861  w1 = h1 * w / h;
1862  }
1863 
1864  if (bNeedResize)
1865  {
1866  //
1867  // Step 2.
1868  // Create temporary bitmap to assist red eye analysis.
1869  //
1870  Bitmap bmds = new Bitmap(w1, h1, bm.PixelFormat);
1871  {
1872  using (Graphics gr = Graphics.FromImage(bmds))
1873  {
1874  gr.SmoothingMode = SmoothingMode.HighQuality;
1875  gr.InterpolationMode = InterpolationMode.HighQualityBicubic;
1876  gr.PixelOffsetMode = PixelOffsetMode.HighQuality;
1877  gr.DrawImage(bm, new Rectangle(0, 0, w1, h1));
1878  }
1879  }
1880 
1881  return bmds;
1882  }
1883  else
1884  {
1885  Bitmap bmds = (Bitmap)bm.Clone();
1886  return bmds;
1887  }
1888  }
1889 
1890  public void Dispose()
1891  {
1892  Dispose(true);
1893  GC.SuppressFinalize(this);
1894  }
1895 
1896  protected virtual void Dispose(bool disposing)
1897  {
1898  if (disposing)
1899  {
1900  }
1901 
1902  if (m_pProfile != null)
1903  {
1904  PFC_ReleaseProfile(m_pProfile);
1905  m_pProfile = null;
1906  }
1907 
1908  if (m_pEngine != null)
1909  {
1910  PFC_DestroyEngine(m_pEngine);
1911  m_pEngine = null;
1912  }
1913  }
1914 
1915  static protected byte* GetCharBuffer(byte[] s)
1916  {
1917  int i, iCount = s.Length;
1918  IntPtr _memory = IntPtr.Zero;
1919  _memory = Marshal.AllocHGlobal(iCount + 1);
1920  byte* p = (byte*)_memory;
1921  for (i = 0; i < iCount; i++)
1922  {
1923  p[i] = (byte)s[i];
1924  }
1925  p[iCount] = 0;
1926 
1927  return (byte*)p;
1928  }
1929 
1930  static protected byte* GetCharBuffer(string s)
1931  {
1932  int i, iCount = s.Length;
1933  IntPtr _memory = IntPtr.Zero;
1934  _memory = Marshal.AllocHGlobal(iCount + 1);
1935  byte* p = (byte*)_memory;
1936  for (i = 0; i < iCount; i++)
1937  {
1938  p[i] = (byte)s[i];
1939  }
1940  p[iCount] = 0;
1941 
1942  return (byte*)p;
1943  }
1944 
1945  static protected void FreeCharBuffer(byte* p)
1946  {
1947  IntPtr _memory = (IntPtr)p;
1948  Marshal.FreeHGlobal(_memory);
1949  }
1950 
1951 #if ADAPTER64BIT
1952  [DllImport("PerfectlyClearPro")]
1953  static extern int PFC_SetProtectionPath(byte* path, byte* licenseCode);
1954 
1955  [DllImport("PerfectlyClearPro")]
1956  static extern void PFC_ReleaseProtectionPath();
1957 
1958  [DllImport("PerfectlyClearPro")]
1959  static extern PFCENGINE* PFC_CreateEngine();
1960 
1961  [DllImport("PerfectlyClearPro")]
1962  static extern void PFC_DestroyEngine(PFCENGINE* p);
1963 
1964  [DllImport("PerfectlyClearPro")]
1965  static extern void PFC_SetParam(ref PFCPARAM param, PFCPRESETID id);
1966 
1967  [DllImport("PerfectlyClearPro")]
1968  static extern int PFC_ReadPresets(ref PFCPARAM param, byte* filename);
1969 
1970  [DllImport("PerfectlyClearPro")]
1971  static extern int PFC_ReadPresetsFromStream(ref PFCPARAM param, byte* s);
1972 
1973  [DllImport("PerfectlyClearPro")]
1974  static extern PFCIMAGEPROFILE* PFC_Calc(PFCIMAGE* pImage, PFCIMAGE* pImageds, PFCENGINE* pEngine, PFCFEATURE feature, int iISO, byte* pCameraModel, void* pImageProfile, void* progfn, int iRejectOption);
1975 
1976  [DllImport("PerfectlyClearPro")]
1977  static extern void PFC_ReleaseProfile(void* pProfile);
1978 
1979  [DllImport("PerfectlyClearPro")]
1980  static extern PFCAPPLYSTATUS PFC_Apply(PFCIMAGE* pImage, PFCENGINE* pEngine, void* pImageProfile, ref PFCPARAM param, void* progfn, int iOpacity, void* pBGProfile);
1981 
1982  [DllImport("PerfectlyClearPro")]
1983  static extern PFCAPPLYSTATUS PFC_ApplyLocal(PFCIMAGE* pImage, int xOffset, int yOffset, int widthOrig, int heightOrig, PFCENGINE* pEngine, PFCIMAGEPROFILE* pImageProfile, ref PFCPARAM param, int iOpacity);
1984 
1985  [DllImport("PerfectlyClearPro")]
1986  static extern bool PFC_HasFaceBeautification(PFCENGINE* pEngine);
1987 
1988  [DllImport("PerfectlyClearPro")]
1989  static extern int PFC_FBFaceCount(void* pImageProfile);
1990 
1991  [DllImport("PerfectlyClearPro")]
1992  static extern bool PFC_GetFaceInfo(void* pImageProfile, PFCFBFACEINFO1* pFace, int index);
1993 
1994  [DllImport("PerfectlyClearPro")]
1995  static extern bool PFC_AbnormalTintDetected(void* pImageProfile, TINTCORRECTION eTintMethod);
1996 
1997  [DllImport("PerfectlyClearPro")]
1998  static extern void PFC_ApplyStrengthToParam(ref PFCPARAM param, int strength);
1999 #endif
2000 
2001 #if ADAPTER32BIT
2002  [DllImport("PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2003  static extern int PFC_SetProtectionPath(byte* path, byte* licenseCode);
2004 
2005  [DllImport("PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2006  static extern void PFC_ReleaseProtectionPath();
2007 
2008  [DllImport("PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2009  static extern PFCENGINE* PFC_CreateEngine();
2010 
2011  [DllImport("PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2012  static extern void PFC_DestroyEngine(PFCENGINE* p);
2013 
2014  [DllImport("PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2015  static extern void PFC_SetParam(ref PFCPARAM param, PFCPRESETID id);
2016 
2017  [DllImport("PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2018  static extern int PFC_ReadPresets(ref PFCPARAM param, byte* filename);
2019 
2020  [DllImport("PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2021  static extern int PFC_ReadPresetsFromStream(ref PFCPARAM param, byte* s);
2022 
2023  [DllImport("PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2024  static extern PFCIMAGEPROFILE* PFC_Calc(PFCIMAGE* pImage, PFCIMAGE* pImageds, PFCENGINE* pEngine, PFCFEATURE feature, int iISO, byte* pCameraModel, void* pImageProfile, void* progfn, int iRejectOption);
2025 
2026  [DllImport("PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2027  static extern void PFC_ReleaseProfile(void* pProfile);
2028 
2029  [DllImport("PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2030  static extern PFCAPPLYSTATUS PFC_Apply(PFCIMAGE* pImage, PFCENGINE* pEngine, void* pImageProfile, ref PFCPARAM param, void* progfn, int iOpacity, void* pBGProfile);
2031 
2032  [DllImport("PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2033  static extern PFCAPPLYSTATUS PFC_ApplyLocal(PFCIMAGE* pImage, int xOffset, int yOffset, int widthOrig, int heightOrig, PFCENGINE* pEngine, PFCIMAGEPROFILE* pImageProfile, ref PFCPARAM param, int iOpacity);
2034 
2035  [DllImport("PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2036  static extern bool PFC_HasFaceBeautification(PFCENGINE* pEngine);
2037 
2038  [DllImport("PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2039  static extern int PFC_FBFaceCount(void* pImageProfile);
2040 
2041  [DllImport("PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2042  static extern bool PFC_GetFaceInfo(void* pImageProfile, PFCFBFACEINFO1* pFace, int index);
2043 
2044  [DllImport("PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2045  static extern bool PFC_AbnormalTintDetected(void* pImageProfile, TINTCORRECTION eTintMethod);
2046 
2047  [DllImport("PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2048  static extern void PFC_ApplyStrengthToParam(ref PFCPARAM param, int strength);
2049 #endif
2050  }
2051 
2052 
2088  public unsafe class PFCImageFile : IDisposable
2089  {
2090  private IntPtr m_pNativeObject;
2091 
2093  public PFCImageFile()
2094  {
2095  m_pNativeObject = create_PFCImageFile();
2096  }
2097 
2098  public void Dispose()
2099  {
2100  Dispose(true);
2101  }
2102 
2103  protected virtual void Dispose(bool bDisposing)
2104  {
2105  if (this.m_pNativeObject != IntPtr.Zero)
2106  {
2107  delete_PFCImageFile(m_pNativeObject);
2108  m_pNativeObject = IntPtr.Zero;
2109  }
2110 
2111  if (bDisposing)
2112  {
2113  // No need to call the finalizer since we've now cleaned
2114  // up the unmanaged memory
2115  GC.SuppressFinalize(this);
2116  }
2117  }
2118 
2119  ~PFCImageFile()
2120  {
2121  Dispose(false);
2122  }
2123 
2126  {
2127  LOAD_OK,
2128  LOAD_ERROR,
2131  };
2132 
2134  public enum PFC_FILETYPE
2135  {
2136  PFC_JPEG = 1,
2137  PFC_PNG = 2
2138  };
2139 
2147  public PFC_FILE_LOAD_STATUS LoadImage(string filename, bool bConvertToSRGB = false, string iccFolderPath = null)
2148  {
2149  if (filename == null)
2150  {
2151  return PFC_FILE_LOAD_STATUS.LOAD_ERROR;
2152  }
2153 
2154  byte* pFilename = GetCharBuffer(filename);
2155 
2156  byte* pIccFolderPath = null;
2157  if (iccFolderPath != null)
2158  {
2159  pIccFolderPath = GetCharBuffer(iccFolderPath);
2160  }
2161 
2162  int result = PFCImageFile_LoadImageFile(m_pNativeObject, pFilename, bConvertToSRGB, pIccFolderPath);
2163 
2164  FreeCharBuffer(pFilename);
2165  FreeCharBuffer(pIccFolderPath);
2166 
2167  return (PFC_FILE_LOAD_STATUS)result;
2168  }
2169 
2178  public PFC_FILE_LOAD_STATUS LoadImage(string filename, PFC_FILETYPE type, bool bConvertToSRGB = true, string iccFolderPath = null)
2179  {
2180  if (filename == null)
2181  {
2182  return PFC_FILE_LOAD_STATUS.LOAD_ERROR;
2183  }
2184 
2185  byte* pFilename = GetCharBuffer(filename);
2186 
2187  byte* pIccFolderPath = null;
2188  if (iccFolderPath != null)
2189  {
2190  pIccFolderPath = GetCharBuffer(iccFolderPath);
2191  }
2192 
2193  int result = PFCImageFile_LoadImageFileType(m_pNativeObject, pFilename, (int)type, bConvertToSRGB, pIccFolderPath);
2194 
2195  FreeCharBuffer(pFilename);
2196  FreeCharBuffer(pIccFolderPath);
2197 
2198  return (PFC_FILE_LOAD_STATUS)result;
2199  }
2200 
2208  public bool SaveImageFile(string filename, int jpegQuality = 92, bool bConvertToOriginalColorSpace= true, bool bEmbedOriginalMetadata = true)
2209  {
2210  if (filename == null)
2211  {
2212  return false;
2213  }
2214 
2215  byte* pFilename = GetCharBuffer(filename);
2216 
2217  bool result = PFCImageFile_SaveImageFile(m_pNativeObject, pFilename, jpegQuality, bConvertToOriginalColorSpace, bEmbedOriginalMetadata);
2218 
2219  FreeCharBuffer(pFilename);
2220 
2221  return result;
2222  }
2223 
2232  public bool SaveImageFile(string filename, PFC_FILETYPE type, int jpegQuality = 92, bool bConvertToOriginalColorSpace = true, bool bEmbedOriginalMetadata = true)
2233  {
2234  if (filename == null)
2235  {
2236  return false;
2237  }
2238 
2239  byte* pFilename = GetCharBuffer(filename);
2240 
2241  bool result = PFCImageFile_SaveImageFileType(m_pNativeObject, pFilename, (int)type, jpegQuality, bConvertToOriginalColorSpace, bEmbedOriginalMetadata);
2242 
2243  FreeCharBuffer(pFilename);
2244 
2245  return result;
2246  }
2247 
2248  public void AllocBuffer(int width, int height, int bytes_per_pixel, int stride)
2249  {
2250  PFCImageFile_AllocBuffer(m_pNativeObject, width, height, bytes_per_pixel, stride);
2251  }
2252 
2253  public int pfcImageFormat()
2254  {
2255  return PFCImageFile_pfcImageFormat(m_pNativeObject);
2256  }
2257 
2258  public int exifOrientation()
2259  {
2260  return PFCImageFile_exifOrientation(m_pNativeObject);
2261  }
2262 
2263  public byte* raw_image()
2264  {
2265  return PFCImageFile_get_raw_image(m_pNativeObject);
2266  }
2267 
2268  public int width()
2269  {
2270  return PFCImageFile_get_width(m_pNativeObject);
2271  }
2272 
2273  public int height()
2274  {
2275  return PFCImageFile_get_height(m_pNativeObject);
2276  }
2277 
2278  public int bytes_per_pixel()
2279  {
2280  return PFCImageFile_get_bytes_per_pixel(m_pNativeObject);
2281  }
2282 
2283  public int stride()
2284  {
2285  return PFCImageFile_get_stride(m_pNativeObject);
2286  }
2287 
2288  public bool sourceSRGB()
2289  {
2290  return PFCImageFile_get_sourceSRGB(m_pNativeObject);
2291  }
2292 
2301  public PFC_FILE_LOAD_STATUS ExpandImageBuffer(MemoryStream inStream, PFC_FILETYPE type, bool bConvertToSRGB = true, string iccFolderPath = null)
2302  {
2303  byte* buffer = GetByteBuffer(inStream.ToArray());
2304  byte* pIccFolderPath = null;
2305  if (iccFolderPath != null)
2306  {
2307  pIccFolderPath = GetCharBuffer(iccFolderPath);
2308  }
2309  int result = PFCImageFile_ExpandImageBuffer(m_pNativeObject, buffer, inStream.Length, (int)type, bConvertToSRGB, pIccFolderPath);
2310  FreeCharBuffer(pIccFolderPath);
2311  FreeByteBuffer(buffer);
2312 
2313  return (PFC_FILE_LOAD_STATUS)result;
2314  }
2315 
2324  public MemoryStream CompressImageBuffer(PFC_FILETYPE type, int jpegQuality = 92, bool bConvertToOriginalColorSpace = true, bool bEmbedOriginalMetadata = true)
2325  {
2326  byte* compressedBuffer = null;
2327  int length = PFCImageFile_CompressImageBuffer(m_pNativeObject, &compressedBuffer, (int)type, jpegQuality, bConvertToOriginalColorSpace, bEmbedOriginalMetadata);
2328  if (length > 0 && compressedBuffer != null)
2329  {
2330  byte[] result = new byte[length];
2331  Marshal.Copy((IntPtr)(compressedBuffer), result, 0, length);
2332  deleteBuffer(compressedBuffer);
2333 
2334  // let the stream be resizable
2335  MemoryStream stream = new MemoryStream();
2336  stream.Write(result, 0, result.Length);
2337  return stream;
2338  }
2339  return new MemoryStream();
2340  }
2341 
2342  private static byte* GetCharBuffer(string s)
2343  {
2344  UTF8Encoding utf8 = new UTF8Encoding();
2345  Byte[] encodedBytes = utf8.GetBytes(s);
2346 
2347  int i, iCount = encodedBytes.Length;
2348  IntPtr _memory = IntPtr.Zero;
2349  _memory = Marshal.AllocHGlobal(iCount + 1);
2350  byte* p = (byte*)_memory;
2351  for (i = 0; i < iCount; i++)
2352  {
2353  p[i] = encodedBytes[i];
2354  }
2355  p[iCount] = 0;
2356 
2357  return (byte*)p;
2358  }
2359 
2360  private static void FreeCharBuffer(byte* p)
2361  {
2362  IntPtr _memory = (IntPtr)p;
2363  Marshal.FreeHGlobal(_memory);
2364  }
2365 
2366  private static byte* GetByteBuffer(byte[] bytes)
2367  {
2368  int length = bytes.Length;
2369  IntPtr p = Marshal.AllocHGlobal(length);
2370  Marshal.Copy(bytes, 0, p, length);
2371  return (byte*)p;
2372  }
2373 
2374  private static void FreeByteBuffer(byte* p)
2375  {
2376  IntPtr _memory = (IntPtr)p;
2377  Marshal.FreeHGlobal(_memory);
2378  }
2379 
2380 #if ADAPTER64BIT
2381  [DllImport("PFCImageFile")]
2382  static private extern unsafe IntPtr create_PFCImageFile();
2383 
2384  [DllImport("PFCImageFile")]
2385  static private extern void delete_PFCImageFile(IntPtr o);
2386 
2387  [DllImport("PFCImageFile")]
2388  static private extern unsafe int PFCImageFile_LoadImageFile(IntPtr o, byte* filename, bool bConvertToSRGB, byte* iccFolderPath);
2389 
2390  [DllImport("PFCImageFile")]
2391  static private extern unsafe int PFCImageFile_LoadImageFileType(IntPtr o, byte* filename, int type, bool bConvertToSRGB, byte* iccFolderPath);
2392 
2393  [DllImport("PFCImageFile")]
2394  static private extern unsafe bool PFCImageFile_SaveImageFile(IntPtr ptr, byte* filename, int jpegQuality, bool bConvertToOriginalColorSpace, bool bEmbedOriginalMetadata);
2395 
2396  [DllImport("PFCImageFile")]
2397  static private extern unsafe bool PFCImageFile_SaveImageFileType(IntPtr ptr, byte* filename, int type, int jpegQuality, bool bConvertToOriginalColorSpace, bool bEmbedOriginalMetadata);
2398 
2399  [DllImport("PFCImageFile")]
2400  static private extern unsafe void PFCImageFile_AllocBuffer(IntPtr ptr, int width, int height, int bytes_per_pixel, int stride);
2401 
2402  [DllImport("PFCImageFile")]
2403  static private extern unsafe int PFCImageFile_pfcImageFormat(IntPtr ptr);
2404 
2405  [DllImport("PFCImageFile")]
2406  static private extern unsafe int PFCImageFile_exifOrientation(IntPtr ptr);
2407 
2408  [DllImport("PFCImageFile")]
2409  static private extern unsafe byte* PFCImageFile_get_raw_image(IntPtr ptr);
2410 
2411  [DllImport("PFCImageFile")]
2412  static private extern unsafe int PFCImageFile_get_width(IntPtr ptr);
2413 
2414  [DllImport("PFCImageFile")]
2415  static private extern unsafe int PFCImageFile_get_height(IntPtr ptr);
2416 
2417  [DllImport("PFCImageFile")]
2418  static private extern unsafe int PFCImageFile_get_bytes_per_pixel(IntPtr ptr);
2419 
2420  [DllImport("PFCImageFile")]
2421  static private extern unsafe int PFCImageFile_get_stride(IntPtr ptr);
2422 
2423  [DllImport("PFCImageFile")]
2424  static private extern unsafe bool PFCImageFile_get_sourceSRGB(IntPtr ptr);
2425 
2426  [DllImport("PFCImageFile")]
2427  static private extern unsafe int PFCImageFile_ExpandImageBuffer(IntPtr ptr, byte* buffer, long size, int type, bool bConvertToSRGB, byte* iccFolderPath);
2428 
2429  [DllImport("PFCImageFile")]
2430  static private extern unsafe int PFCImageFile_CompressImageBuffer(IntPtr ptr, byte** destination, int type, int jpegQuality, bool bConvertToOriginalColorSpace, bool bEmbedOriginalMetadata);
2431 
2432  [DllImport("PFCImageFile")]
2433  static private extern unsafe int deleteBuffer(byte* buffer);
2434 #endif
2435 
2436 #if ADAPTER32BIT
2437  [DllImport("PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2438  static private extern unsafe IntPtr create_PFCImageFile();
2439 
2440  [DllImport("PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2441  static private extern void delete_PFCImageFile(IntPtr o);
2442 
2443  [DllImport("PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2444  static private extern unsafe int PFCImageFile_LoadImageFile(IntPtr o, byte* filename, bool bConvertToSRGB, byte* iccFolderPath);
2445 
2446  [DllImport("PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2447  static private extern unsafe int PFCImageFile_LoadImageFileType(IntPtr o, byte* filename, int type, bool bConvertToSRGB, byte* iccFolderPath);
2448 
2449  [DllImport("PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2450  static private extern unsafe bool PFCImageFile_SaveImageFile(IntPtr ptr, byte* filename, int jpegQuality, bool bConvertToOriginalColorSpace, bool bEmbedOriginalMetadata);
2451 
2452  [DllImport("PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2453  static private extern unsafe bool PFCImageFile_SaveImageFileType(IntPtr ptr, byte* filename, int type, int jpegQuality, bool bConvertToOriginalColorSpace, bool bEmbedOriginalMetadata);
2454 
2455  [DllImport("PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2456  static private extern unsafe void PFCImageFile_AllocBuffer(IntPtr ptr, int width, int height, int bytes_per_pixel, int stride);
2457 
2458  [DllImport("PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2459  static private extern unsafe int PFCImageFile_pfcImageFormat(IntPtr ptr);
2460 
2461  [DllImport("PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2462  static private extern unsafe int PFCImageFile_exifOrientation(IntPtr ptr);
2463 
2464  [DllImport("PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2465  static private extern unsafe byte* PFCImageFile_get_raw_image(IntPtr ptr);
2466 
2467  [DllImport("PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2468  static private extern unsafe int PFCImageFile_get_width(IntPtr ptr);
2469 
2470  [DllImport("PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2471  static private extern unsafe int PFCImageFile_get_height(IntPtr ptr);
2472 
2473  [DllImport("PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2474  static private extern unsafe int PFCImageFile_get_bytes_per_pixel(IntPtr ptr);
2475 
2476  [DllImport("PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2477  static private extern unsafe int PFCImageFile_get_stride(IntPtr ptr);
2478 
2479  [DllImport("PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2480  static private extern unsafe bool PFCImageFile_get_sourceSRGB(IntPtr ptr);
2481 
2482  [DllImport("PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2483  static private extern unsafe int PFCImageFile_ExpandImageBuffer(IntPtr ptr, byte* buffer, long size, int type, bool bConvertToSRGB, byte* iccFolderPath);
2484 
2485  [DllImport("PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2486  static private extern unsafe int PFCImageFile_CompressImageBuffer(IntPtr ptr, byte** destination, int type, int jpegQuality, bool bConvertToOriginalColorSpace, bool bEmbedOriginalMetadata);
2487 
2488  [DllImport("PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2489  static private extern unsafe int deleteBuffer(byte* buffer);
2490 #endif
2491  }
2492 }
unsafe ADPTRRETURNCODE Calc(ref PFCImageFile imgfile, PFCFEATURE feature, int ISO, string CameraModel, PFCREJECTOPTION rejectOption=PFCREJECTOPTION.PFC_REJECT_CLIPART)
Overload method for precalc analysis.
PFCPIXELFORMAT
defines the format of the image data
Legacy structure defining face area detected from the SFB library.
Adjust skin to user defined foundation color.
PFCRE_STATUS
Enumeration defining status of Red Eye pre-calculation.
Reject images classified as clipart, used by default.
bool bDCF
Set to true to enable Digital Color Fidelity. Recommended value is FALSE.
4 Error reading image data
Skip pre-calculations on Abnormal Tint Correction during Core pre-calculations.
6 General error
int iTeethLevel
Teeth whitening level. Range 0 to 100.
4 Process aborted because of insufficient memory
PFCPIXELFORMAT format
Defines byte order of input buffer.
int iFinishExposure
Exposure correction amount.
-6 Invalid License or validation failed
int AutoCorrect(ref PFCImageFile imgfile, string pathPreset, int ISO, string CameraModel, bool bFastFAE)
Overload method for auto correction.
int iEnhanceLevel
Eye enhancement level. Range 0 to 100.
PFCAPPLYSTATUS
Enumeration defining return code from the Apply() function.
PFCV3PARAM v3
V3 Corrections.
2 Source image (pImage) is missing
void * pEngine
Pointer to binary definition of the processing engine.
PFCCORE_STATUS CORE_Status
Status code for CORE pre-calc analysis.
Structure encapsulating Noise Removal parameters.
AGGRESSIVENESS eAggressiveness
The desired level of lighting for Automatic Strength Selection to target at the Exposure Correction...
MemoryStream CompressImageBuffer(PFC_FILETYPE type, int jpegQuality=92, bool bConvertToOriginalColorSpace=true, bool bEmbedOriginalMetadata=true)
Write image data to MemoryStream.
int AutoCorrect(ref Bitmap bm, ref Bitmap bmds)
Overload method for auto correction.
7 Process cancelled
PFCRECT face
Bounding rectangle of detected face.
This type of correction provides a more uniform appearance to the complexion. It combines the natural...
PFCREPARAM re
Red Eye Removal.
TINTCORRECTION
Enumeration defining different abnormal tint analysis mode.
5 Invalid parameter
TINTCORRECTION eTintMode
ENUM value defined in TINTCORRECTION. It sets the aggressiveness of Tint Removal. ...
Struct describing 3D Lut information.
void ApplyStrengthToParam(int strength)
Apply overall strength to parameters, same as Strength in Perfecly Clear products Adjusts the paramet...
int iSkinToning
Skin Toning level. Range 0 to 100.
PFCPOINT leftEye
Point of left eye in detected face.
8 No correction occur during process
Less aggressive in exposure correction.
unsafe ADPTRRETURNCODE Calc(ref PFCImageFile imgfile, PFCFEATURE feature)
Overload method for precalc analysis.
PFC_FILE_LOAD_STATUS ExpandImageBuffer(MemoryStream inStream, PFC_FILETYPE type, bool bConvertToSRGB=true, string iccFolderPath=null)
Load JPEG from MemoryStream.
int iFinishTint
Tint correction amount.
PFCV3PARAM layer2
params on layers 2 - fiinishing
1 Feature not enabled
PFCCOREMask mask0
masks for layer 0
int stride
Byte width of each scanline.
int iBlemish
Blemish removal level. Range 0 to 100.
int iBlush
Blush level. Range 0 to 100.
-5 Pixel format not supported
bool bEyeCirc
Set to TRUE to enable eye circle removal.
float fTintScale
Scalar value of how much tint correction should be applied. Range 0.0 to 1.0.
1 Feature not enabled
int iFinishHighlights
Highlights correction amount.
bool bUseFAE
Set to true (recommended) to enable Face Aware Exposure selection. Recommended exposure will be calcu...
bool bEnabled
Set to TRUE to enable noise removal.
bool GetFaceInfo(ref PFCFBFACEINFO info, int index)
Get face information.
Structure encapsulating Face Beautification parameters.
7 Noise not found
bool SaveImageFile(string filename, int jpegQuality=92, bool bConvertToOriginalColorSpace=true, bool bEmbedOriginalMetadata=true)
Write image data to file*.
int ReadPresetsFromStream(FileStream fs)
Read a preset from a file stream.
2 Warning: face not detected
For average usage, corresponds to "Normal" in PfC Products.
bool bLightDiffusion
Set to true to enable light diffusion during DCF correction.
Struct PFCSTATUS Process status of all sub sectors.
int AutoCorrect(ref Bitmap bm)
Overload method for auto correction.
This is a more aggressive and effective correction where the appearance of the entire skin (including...
int height
Pixel height of image.
Struct PFCPARAM the master structure of all processing parameters.
int AutoCorrect(ref Bitmap bm, ref Bitmap bmds, string pathPreset, int ISO, string CameraModel, bool bFastFAE)
Overload method for auto correction.
float height
radial/rounded: h of bounding rect, linear: dist from centerY where grad becomes 1.0.
SKINMODE
Enumeration defining modes in Perfect Smooth analysis.
PFCImageFile()
Constructs empty PFCImageFile, to be filled with LoadImageFile()
PFC_FILE_LOAD_STATUS LoadImage(string filename, bool bConvertToSRGB=false, string iccFolderPath=null)
Load JPEG from file on disk.
int ReadPresets(string path)
Read a preset from .preset file.
iAuto 2019 with Red Eye correciton enabled
PFCPIXELFORMAT
defines the format of the image data
Highest sensitivity level of tint detection.
Apply correction ONLY on skin regions included in faces.
Beautify Plus provides stronger beautification corrections. This is in the &#39;Perfectly Clear Essential...
int iNeutralDensity
Neutral density filter amout.
Struct defining an PFC engine instance.
Moderate level of tint detection.
PFCPOINT rightEye
Point of right eye in detected face.
Structure encapsulating the CORE processing parameters.
2 Source image (pImage) is missing
PFCNR_STATUS
Enumeration defining status of Noise Removal pre-calculation.
1 Feature not enabled
uint status
Status of engine defined in PFCENGINESTATUS. For NO-SFB version the status will always be ENGINESTATU...
LIPSHARPENTYPE eLipSharpenType
See definition of LIPSHARPENTYPE.
bool AbnormalTintDetected(TINTCORRECTION eTintMethod)
Query if Abnormal Tint detected.
unsafe ADPTRRETURNCODE Calc(ref Bitmap bm, PFCFEATURE feature, int ISO, string CameraModel, PFCREJECTOPTION rejectOption=PFCREJECTOPTION.PFC_REJECT_CLIPART)
Overload method for precalc analysis.
Struct defining a rectangle.
Struct PFCPARAM the master structure of all processing parameters.
void * data
Pointer pointing to the first byte of image data buffer.
Whitens (bleaches) face. Recommended mainly for darker skin.
4 General error
DCFMODE
Enumeration defining DCF analysis mode.
7 Image skipped due AI Clipart detection
Fine tuned for Asian skin tone.
-3 Operation cancelled
unsafe ADPTRRETURNCODE Calc(ref Bitmap bm, ref Bitmap bmds, PFCFEATURE feature)
Overload method for precalc analysis.
5 Unable to locate function in the SFBEngine library
PFCFEATURE
ENUM controlling types of calculations at the pre-calculation stage.
int iPreprocessEV
EV correction amount (Image Ambulace)
Struct defining an PFC engine instance.
Use Fast mode of Face Aware Exposure pre-calculations.
Error: failed to convert to sRGB.
Definition: PFCImageFile.h:23
Calculates for all of the above.
int iDetailOffset
Offset to recommended level of preservation of details. Range -30 to 30.
PFCPOINT rightEye
Point of right eye in detected face.
Bitmap ReadImage(string filename)
Utility function for reading image file into Bitmap.
unsafe PFCAPPLYSTATUS Apply(ref Bitmap bm)
Apply correction.
PerfectlyClear()
Special class constructor for multithreading.
4 Process cancelled
bool bHighlightPreservation
Set to true to enable Highlight Preservation.
unsafe ADPTRRETURNCODE Calc(ref Bitmap bm, ref Bitmap bmds, PFCFEATURE feature, int ISO, string CameraModel)
Overload method for precalc analysis.
bool bSkinToning
Set to TRUE to enable skin toning.
Error: unsupported file.
Definition: PFCImageFile.h:22
Moderate level of exposure correction.
int width
Pixel width of image.
int x
x coordinate of this point.
Apply correction on most skin regions regardless they are linked with a face or not.
int iFinishTemp
Temp correction amount.
bool bTeeth
Set to TRUE to enable teeth whitening.
PFC_FILETYPE
ENUM to set the filetype of files / buffers.
Struct defining an image to be used in PFC library.
PFCREJECTOPTION
Enumeration defining reject options.
Average usage with brighter tone, corresponds to "Bright" in PfC Products.
Optimized to bring out more details in the shadows, more details in the highlights, and more pleasing skin tones.
bool bVibrancy
Set to true (recommended default) to enable Color Vibrancy in the library.
-2 Pointer pEngine is NULL
7 The face analysis did not complete successfully
PFCPRESETID
ENUM for presets support by this SDK.
Error.
Definition: PFCImageFile.h:21
static int SetProtectionPath(string path, string licenseCode)
Set path to location of SDK License files This enables license protection and allows activation using...
PFCFBPARAM fb
Face Beautification corrections.
float radius
only for MASK_ROUNDRECT - corner radius, relative to image w.
bool bContrast
Set to TRUE to also apply Athentech&#39;s patented Medical Imaging contrast technology.
PFCCOREMask mask2
masks for layer 2
int iFinishSaturation
Saturation correction amount.
int iContrast
Intensity of contrast or depth. Range 0 to 100.
SKINMODE eSmoothMode
Use SKINMODE_FACE to apply correction ONLY on skin regions included in faces. Use SKINMODE_BODY to ap...
AGGRESSIVENESS
Enumeration defining different Auto Exposure calculation modes.
6 Image skipped, too small ( < 32 pixels )
bool bPreprocessEV
Enable EV correction (Image Ambulance)
float feather
relative length of gradient, from where it starts (1.0) to where it is 0.0,
int iColorVibrancy
Color Vibrancy amount.
int left
x in point coordinate of this rect.
int iSlim
Face slimming level. Range 0 to 100.
int AutoCorrect(ref PFCImageFile imgfile)
Overload method for auto correction.
float width
radial/rounded: w of bounding rect, linear: ignored.
Stronger sharpening. Details are more pronounced.
Priority on minimum false positive detection.
Struct defining an image profile as calculated from PFC_Calc() function.
5 Image skipped due to legacy clipart detection method
Struct defining an image to be used in PFC library.
PFCFEATURE
ENUM controlling types of calculations at the pre-calculation stage.
float transparency
overall transparency applied to the whole mask (strength 100 means transparency 0.0, 0 -> 1.0).
int iEnlargeLevel
Eye enlargement level. Range 0 to 100.
1 Feature not enabled
PFCImageFile Class to encapsulate file handling.
Definition: PFCImageFile.h:59
PFCRE_STATUS RE_Status
Status code for Red Eye pre-calc analysis.
PFC3DLutInfo lutInputSky
LUT data to apply.
unsafe PFCAPPLYSTATUS Apply(ref PFCImageFile imgfile, int iOpacity)
Apply correction.
PFC3DLutInfo lutOutput
LUT data to apply.
int iStrengthOffset
Offset to recommended level of noise removal strength. Range -5 to 5.
int iDeFlash
Deflash level. Range 0 to 100.
Intelligent Auto - this has been superceded by iAuto 2019 and is here for backwards compatability...
bool bDynamicRange
Set to TRUE to enable dynamic range correction.
bool bEnlarge
Set to TRUE to enable eye enlargement.
bool bSmooth
Set to TRUE to enable face smoothing.
int iCatchLight
Catchlight level. Range 0 to 100.
bool bUseAutomaticStrengthSelection
Set to TRUE (recommended default) to enable Automatic Strength Selection. Perfectly Clear will determ...
bool invert
invert mask (x = 1.0 - x). NOTE: UI meaning of invert is: if one mask layer set invert = true...
Vivid - good for landscapes and other general photography. This is in the &#39;Perfectly Clear Essentials...
-4 Pointer pImage is NULL, source image missing
PFC3DLutInfo lutInputFoliageBrown
LUT data to apply.
int height
height of this rect.
int iVibrancy
Degree of color vibrancy. This value will only be use when bVibrancy is TRUE. Very large values can p...
CONTRASTMODE eContrastMode
Select contrast mode.
bool bEnhance
Set to TRUE to enable eye enhancement.
SKINSMOOTHTYPE eSmoothType
See enum definition of SKINSMOOTHTYPE.
unsafe ADPTRRETURNCODE Calc(ref Bitmap bm, ref Bitmap bmds)
Overload method for precalc analysis.
Darkens skin, makes it look naturally tanned.
PFCFB_STATUS FB_Status
Status code for Face Beautification pre-calc analysis.
iAuto Details - legacy preset for backwards compability. This is in the &#39;Athentech Legacy&#39; group in E...
Warms skin tone.
int AutoCorrect(ref Bitmap bm, ref Bitmap bmds, int ISO, string CameraModel, bool bFastFAE)
Overload method for auto correction.
unsafe ADPTRRETURNCODE Calc(ref PFCImageFile imgfile)
Overload method for precalc analysis.
float fBiasScale
Scalar value of how much BIAS correction should be applied. Range 0.0 to 1.0.
5 Invalid parameter
bool bLipSharpen
Set to TRUE to enable lip sharpening.
TINTCORRECTION
Enumeration defining different abnormal tint analysis mode.
Disable image rejection.
unsigned char * data
Pointer pointing to the first byte of image data buffer.
3 Process cancelled
Makes skin look lighter and more pale.
int AutoCorrect(ref Bitmap bm, int ISO, string CameraModel, bool bFastFAE)
Performs auto correction.
SKINTONINGTYPE
Enumeration defining type of Skin Toning correction.
int AutoCorrect(ref Bitmap bm, string pathPreset, int ISO, string CameraModel, bool bFastFAE)
Overload method for auto correction.
2 Process cancelled
-1 Pointer pProfile is NULL
float fLightDiffusion
Scale value to control intensity of light diffusion correction.
int iLipSharpen
Lip sharpening level. Range 0 to 100.
int iFinishShadows
Shadows correction amount.
float fSharpenScale
Sharpening intensity. This value controls how much sharpening to be applied. Range 0...
6 Unable to create SFB Engine object for processing
int y
y coordinate of this point.
bool bAbnormalTintRemoval
Set to true to enable Abnormal Tint Removal. Recommended default is FALSE.
Calculates for Perfectly Clear Core correction.
DCFMODE eDCFMode
Select different class of DCF.
bool SaveImageFile(string filename, PFC_FILETYPE type, int jpegQuality=92, bool bConvertToOriginalColorSpace=true, bool bEmbedOriginalMetadata=true)
Write image data to file*.
int AutoCorrect(ref Bitmap bm, ref Bitmap bmds, string pathPreset)
Overload method for auto correction.
int iSmoothLevel
Face smoothing level. Range 0 to 100.
bool bDeFlash
Set to TRUE to enable deflash.
3 Red eye not found
float fDCF
Scale value to control intensity of Digital Color Fidelity correction. Range 0.0 to 1...
LIPSHARPENTYPE
Enumeration defining Lip Sharpening mode.
int iEyeCirc
Eye circle removal level. Range 0 to 100.
bool bInfrared
Set to true (recommended default) to enable infrared correction. It&#39;s a good idea to turn Infrared Co...
SKINTONINGTYPE eSkinToningType
See enum definition of SKINTONINGTYPE.
int iStrength
Set the strength of exposure correction. If Automatic Strength Selection is enabled, the recommended value is put in this variable upon function return. Range 0 to 150.
PFCCOREMask mask1
masks for layer 1
PFCPIXELFORMAT format
Defines byte order of input buffer.
int iFinishWhites
Whites correction amount.
int top
y in point corrdinate of this rect.
Image source in format not supported by this version of API.
PFCCORE_MASK_TYPE type
Mask type.
PFCNR_STATUS NR_Status
Status code for Noise Removal pre-calc analysis.
Calculates for Perfectly Clear Noise Removal.
int iFinishBlacks
Blacks correction amount.
PFC3DLutInfo lutInputFoliageGreen
LUT data to apply.
PFCFB_STATUS
Enumeration defining status of Face Beautification pre-calculation.
unsafe PFCAPPLYSTATUS Apply(ref Bitmap bm, int iOpacity)
Apply correction.
Struct describing V3 parameters.
PFC3DLutInfo lutInputCorrective
LUT data to apply.
SKINMODE eSkinToningMode
Use SKINMODE_FACE to apply correction ONLY on skin regions included in faces. Use SKINMODE_BODY to ap...
Beautify - provides a good default set of corrections for portratis and other photos of people...
unsafe ADPTRRETURNCODE Calc(ref Bitmap bm)
Performs precalc analysis.
Based on iAuto 21, but with brighter Skin & Depth Bias for truer skin tone.
PFCAPPLYSTATUS
Enumeration defining return code from the Apply() function.
unsafe ADPTRRETURNCODE Calc(ref Bitmap bm, PFCFEATURE feature)
Overload method for precalc analysis.
int iFinishVibrancy
Vibrancy correction amount.
bool bSharpen
Set to true to enable sharpening.
PFCPRESETID
ENUM for presets support by this SDK.
PFCV3PARAM layer0
params on layers 0 - top/inside
bool HasFaceBeautification()
Query if Face Beautification feature is available.
Skip Face Aware Exposure pre-calculations during Core pre-calculations.
Class defining face area detected from the SFB library.
The subtle correction removes the wrinkles and spots alone while it keeps the texture of the face unc...
PFCRECT face
Bounding rectangle of detected face.
PFCV3PARAM layer1
params on layers 1 - bottom/outside, 2 - fiinishing
unsafe PFCAPPLYSTATUS Apply(ref PFCImageFile imgfile)
Apply correction.
PFCCOREPARAM core
Core corrections to apply.
int iBlackEnhancement
Set luminance threshold for Noise Management. Range 0 to 25.
10 Face beautification feature not available
Structure encapsulating Red Eye Correction parameters.
PerfectlyClear(string path, string licenseCode="")
Class constructor.
3 Source image (pImage) is missing
BIASMODE
Enumeration defining BIAS analysis mode.
More aggressive in exposure correction.
bool bEnabled
Set to true to enable the entire Core correction.
PFC_FILE_LOAD_STATUS
Return status after loading a file with PFCImageFile.
3 Source image (pImage) is missing
bool bBlemish
Set to TRUE to enable blemish removal.
Calculates for Red Eye Removal.
void SetParam(PFCPRESETID id)
Set process parameters in current instance.
The iAuto you love plus newly tuned settings for sharper images, accurate skin correction, and more depth. Read more here: https://eyeq.photos/business/iauto-2021.
PFCImageFile Class to encapsulate file handling.
int iHighlightPreservation
Amount of Highlight Preservation to apply. Range 0 to 100.
Fine touch of sharpening.
int AutoCorrect(ref PFCImageFile imgfile, string pathPreset)
Overload method for auto correction.
Reject simple images that don&#39;t benefit from correction, like solid colors. This was the default befo...
6 Insufficient memory
CONTRASTMODE
Enumeration defining contrast mode.
Turn off bias correction.
bool bBlush
Set to TRUE to add blush.
Lip details are coarsely pronounced.
ADPTRRETURNCODE
General return code.
Struct defining an image profile as calculated from PFC_Calc() function.
int AutoCorrect(ref Bitmap bm, string pathPreset)
Overload method for auto correction.
float fInfrared
Scale value to control intensity of infrared correction. Range 0.0 to 1.0.
int AutoCorrect(ref PFCImageFile imgfile, int ISO, string CameraModel, bool bFastFAE)
Performs auto correction.
Optimized to bring higher contrast to the image.
bool bEnabled
Set to TRUE to enable red eye removal.
iAuto for even better image corrections
PFCCORE_STATUS
Enumeration defining status of Core pre-calculation.
Some warnings during processing.
bool bSlim
Set to TRUE to enable face slimming.
BIASMODE eBiasMode
Skin and depth bias control. Recommended value is BIAS_AVERAGE_PREFERENCE, unless you are printing to...
int iMaxStrength
Use this value to limit the maximum Exposure to be applied on the Automatic Exposure Strength Selecti...
static void ReleaseProtectionPath()
Releases resources from SetProtectionPath.
bool bCatchLight
Set to TRUE to enable catchlight removal.
int iFinishContrast
Contrast correction amount.
bool bEnabled
Set to TRUE to enable entire face beautification.
Success.
Definition: PFCImageFile.h:20
Aggressive detection of tint.
PFCPOINT leftEye
Point of left eye in detected face.
PFCNRPARAM nr
Noise reduction corrections.
Calculates for Face Beautification.
SKINSMOOTHTYPE
Enumeration defining types of Skin Smoothing correction.
PFC_FILE_LOAD_STATUS LoadImage(string filename, PFC_FILETYPE type, bool bConvertToSRGB=true, string iccFolderPath=null)
Load JPEG from file on disk.