Perfectly Clear SDK Documentation  9.0.0.295
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,
202 };
203 
205 public enum PFCNR_STATUS
206 {
215 };
216 
218 public enum PFCCORE_STATUS
219 {
227 };
228 
230 public enum PFCFB_STATUS
231 {
243 };
244 
246 public enum PFCRE_STATUS
247 {
257 };
258 
260 public enum PFCAPPLYSTATUS
261 {
262  APPLY_SUCCESS = 0,
265  APPLY_CANCELLED = -3,
266  APPLY_NOSOURCE = -4,
267  APPLY_BADFORMAT = -5,
269 };
270 
272 public enum TINTCORRECTION
273 {
278 };
279 
281 public enum AGGRESSIVENESS
282 {
283  CONSERVATIVE,
284  MODERATE,
285  AGGRESSIVE,
286 };
287 
289 public enum DCFMODE
290 {
293 };
294 
296 public enum CONTRASTMODE
297 {
298  HIGH_CONTRAST,
300 };
301 
303 public enum BIASMODE
304 {
305  BIAS_NONE,
309 };
310 
312 public enum ADPTRRETURNCODE
313 {
314  SUCCESS,
315  WARNING,
316  INTERNALERROR,
317  WRONG_FORMAT
318 };
319 
321 public enum SKINMODE
322 {
323  SKINMODE_FACE = 1,
325 };
326 
328 public enum SKINSMOOTHTYPE
329 {
333 };
334 
336 public enum SKINTONINGTYPE
337 {
343 };
344 
346 public enum LIPSHARPENTYPE
347 {
348  LIPSHARPENTYPE_FINE = 1,
351 };
352 
354 public struct PFCCOREPARAM
355 {
356  public bool bEnabled;
357  public bool bAbnormalTintRemoval;
359  public float fTintScale;
360  public int iBlackEnhancement;
361  public bool bVibrancy;
362  public int iVibrancy;
363  public int iStrength;
364  public bool bContrast;
366  public int iContrast;
368  public float fBiasScale;
371  public bool bSharpen;
372  public float fSharpenScale;
374  public bool bUseFAE;
376  public int iMaxStrength;
377  public bool bInfrared;
378  public float fInfrared;
379  public bool bLightDiffusion;
380  public float fLightDiffusion;
381  public bool bDynamicRange;
382  public bool bDCF;
383  public DCFMODE eDCFMode;
384  public float fDCF;
385 };
386 
388 public struct PFCFBPARAM
389 {
390  public bool bEnabled;
391  public bool bSmooth;
392  public int iSmoothLevel;
395  public bool bEnlarge;
396  public int iEnlargeLevel;
397  public bool bEnhance;
398  public int iEnhanceLevel;
399  public bool bEyeCirc;
400  public int iEyeCirc;
401  public bool bTeeth;
402  public int iTeethLevel;
403  public bool bBlemish;
404  public int iBlemish;
405  public bool bSlim;
406  public int iSlim;
407  public bool bDeFlash;
408  public int iDeFlash;
409  public bool bCatchLight;
410  public int iCatchLight;
411  public int iCatchLightMode;
412  public bool bSkinToning;
419  public int iSkinToning;
422  public bool bLipSharpen;
423  public int iLipSharpen;
425  public bool bBlush;
426  public int iBlush;
427 };
428 
430 public unsafe struct PFCNRPARAM
431 {
432  public bool bEnabled;
433  public int iPreset;
434  public int iStrengthOffset;
442  public int iDetailOffset;
443 };
444 
446 public struct PFCREPARAM
447 
448 {
449  public bool bEnabled;
450 };
451 
452 // V3 additions
453 public enum PFCCORE_MASK_TYPE
454 {
455  PFCCORE_MASK_NONE, // 0.0 everywhere, don't apply
456  PFCCORE_MASK_ALL, // 1.0 everywhere (background)
457  PFCCORE_MASK_RADIAL, // ellipse
458  PFCCORE_MASK_TOP, // linear from 1.0 on top
459  PFCCORE_MASK_BOTTOM, // linear from 1.0 on bottom
460  PFCCORE_MASK_ROUNDRECT // rounded rect
461 };
462 
463 /* Description of mask for grad filter, all coordinates are relative (Y/height, X/width) in final crop-rotated image */
467 public unsafe struct PFCCOREMask
468 {
469  public PFCCORE_MASK_TYPE type;
470  public float centerX;
471  public float centerY;
472  public float width;
473  public float height;
474  public float radius;
475  public float feather;
476  public float angle;
477  public float transparency;
478  public bool invert;
479 };
480 
481 [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
483 public struct PFC3DLutInfo
484 {
485  [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 33)]
486  public string guid;
487 
488  public byte strength; // C++ unsigned char
489 }
490 
492 public unsafe struct PFCV3PARAM
493 {
494  // Image Ambulance
495  public bool bPreprocessEV;
496  public int iPreprocessEV;
497  // built-in 3D luts
498  public int iNeutralDensity;
499  public int iColorVibrancy;
504  // custom output 3D Lut
506  // Finishing
507  public int iFinishTemp;
508  public int iFinishTint;
509  public int iFinishExposure;
510  public int iFinishBlacks;
511  public int iFinishShadows;
512  public int iFinishHighlights;
513  public int iFinishWhites;
514  public int iFinishSaturation;
515  public int iFinishVibrancy;
516  public int iFinishContrast;
517 };
518 
519 [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
521 public struct PFCPARAM
522 {
524  public PFCFBPARAM fb;
525  public PFCNRPARAM nr;
526  public PFCREPARAM re;
527  public PFCV3PARAM v3;
534 };
535 
537 public struct PFCSTATUS
538 {
539  public PFCCORE_STATUS CORE_Status;
540  public PFCNR_STATUS NR_Status;
541  public PFCFB_STATUS FB_Status;
542  public PFCRE_STATUS RE_Status;
543  public int Status;
544 }
545 
552  public unsafe class PerfectlyClear : IDisposable
553  {
555  protected unsafe struct PFCENGINE
556  {
557  void* pEngine;
558  public uint status;
559  };
561  protected unsafe struct PerfectlyClearImageTransfer
562  {
563  public int width;
564  public int height;
565  public int rowBytes;
566  public int columnBytes;
567  public int data1;
568  public int data2;
569  public int data3;
570  };
571 
573  protected unsafe struct PFCIMAGEPROFILE
574  {
575  void* pPfcParam;
576  void* pNoiseParam;
577  void* pRedEyeParam;
578  void* pSFBParam;
579  void* pInternal;
580 
585 
586  public int Status;
587  };
594 
596  protected unsafe struct PFCIMAGE
597  {
598  public int width;
599  public int height;
600  public int stride;
602  public void* data;
603  };
604 
605 
606  protected PFCENGINE* m_pEngine;
607  protected PFCIMAGEPROFILE* m_pProfile;
608  public PFCPARAM m_Param;
609  public PFCSTATUS LastStatus;
610  private bool releaseProtection = false;
611 
645  public static int SetProtectionPath(string path, string licenseCode)
646  {
647 #if PROTECTION_ENABLED
648  try
649  {
650  byte* pLicpath = null;
651  if (!String.IsNullOrEmpty(path))
652  {
653  pLicpath = GetCharBuffer(path);
654  }
655 
656  byte* pLicenseCode = null;
657  if (!String.IsNullOrEmpty(licenseCode)) {
658  pLicenseCode = GetCharBuffer(licenseCode);
659  }
660 
661  int status = PFC_SetProtectionPath(pLicpath, pLicenseCode);
662 
663  FreeCharBuffer(pLicpath);
664  FreeCharBuffer(pLicenseCode);
665  //Trace.WriteLine("status " + status.ToString());
666 
667  return status;
668  }
669  catch (Exception ex)
670  {
671  Trace.WriteLine(ex.Message);
672  return 100;
673  }
674 #endif
675  return 0;
676  }
677 
678 
684  public static void ReleaseProtectionPath()
685  {
686  PFC_ReleaseProtectionPath();
687  }
688 
695  public PerfectlyClear()
696  {
697  m_pEngine = null;
698  m_pProfile = null;
699 
700  try
701  {
702  m_pEngine = PFC_CreateEngine();
703  if (m_pEngine != null)
704  {
705  LastStatus.Status = (int)(*m_pEngine).status;
706  }
707  }
708  catch (Exception ex)
709  {
710  Trace.WriteLine(ex.Message);
711  }
712 
713  PFC_SetParam(ref m_Param, PFCPRESETID.PRESET_IAUTO_2019);
714  }
715 
725  public PerfectlyClear(string path, string licenseCode = "")
726  {
727  m_pEngine = null;
728  m_pProfile = null;
729 
730 #if PROTECTION_ENABLED
731  try
732  {
733  byte* pLicpath = null;
734  if (!String.IsNullOrEmpty(path))
735  {
736  pLicpath = GetCharBuffer(path);
737  }
738 
739  byte* pLicenseCode = null;
740  if (!String.IsNullOrEmpty(licenseCode)) {
741  pLicenseCode = GetCharBuffer(licenseCode);
742  }
743 
744  int status = PFC_SetProtectionPath(pLicpath, pLicenseCode);
745  releaseProtection = true;
746 
747  FreeCharBuffer(pLicpath);
748  FreeCharBuffer(pLicenseCode);
749  //Trace.WriteLine("status " + status.ToString());
750  }
751  catch (Exception ex)
752  {
753  Trace.WriteLine(ex.Message);
754  }
755 #endif
756  try
757  {
758  m_pEngine = PFC_CreateEngine();
759  if (m_pEngine != null)
760  {
761  LastStatus.Status = (int)(*m_pEngine).status;
762  }
763  }
764  catch (Exception ex)
765  {
766  Trace.WriteLine(ex.Message);
767  }
768 
769  PFC_SetParam(ref m_Param, PFCPRESETID.PRESET_IAUTO_2019);
770  }
771 
772  ~PerfectlyClear()
773  {
774 #if PROTECTION_ENABLED
775  if(releaseProtection) {
777  }
778 #endif
779  Dispose(false);
780  }
781 
787  public unsafe ADPTRRETURNCODE Calc(ref Bitmap bm)
788  {
789  return Calc(ref bm, PFCFEATURE.CALC_ALL, -1, null);
790  }
791 
797  public unsafe ADPTRRETURNCODE Calc(ref PFCImageFile imgfile)
798  {
799  return Calc(ref imgfile, PFCFEATURE.CALC_ALL, -1, null);
800  }
801 
808  public unsafe ADPTRRETURNCODE Calc(ref Bitmap bm, ref Bitmap bmds)
809  {
810  return Calc(ref bm, ref bmds, PFCFEATURE.CALC_ALL, -1, null);
811  }
812 
819  public unsafe ADPTRRETURNCODE Calc(ref PFCImageFile imgfile, PFCFEATURE feature)
820  {
821  return Calc(ref imgfile, feature, -1, null);
822  }
823 
830  public unsafe ADPTRRETURNCODE Calc(ref Bitmap bm, PFCFEATURE feature)
831  {
832  return Calc(ref bm, feature, -1, null);
833  }
834 
842  public unsafe ADPTRRETURNCODE Calc(ref Bitmap bm, ref Bitmap bmds, PFCFEATURE feature)
843  {
844  return Calc(ref bm, ref bmds, feature, -1, null);
845  }
846 
855  public unsafe ADPTRRETURNCODE Calc(ref Bitmap bm, PFCFEATURE feature, int ISO, string CameraModel)
856  {
857  BitmapData bd = null;
858  Byte* pBase = null;
859  bd = LockBitmapData(ref bm);
860  if (bd.PixelFormat != PixelFormat.Format24bppRgb &&
861  bd.PixelFormat != PixelFormat.Format32bppArgb &&
862  bd.PixelFormat != PixelFormat.Format48bppRgb &&
863  bd.PixelFormat != PixelFormat.Format64bppArgb)
864  {
865  ReleaseBitmapData(ref bm, ref bd);
866  return ADPTRRETURNCODE.WRONG_FORMAT;
867  }
868  pBase = (Byte*)bd.Scan0.ToPointer();
869 
870  PFCIMAGE im;
871  im.width = bd.Width;
872  im.height = bd.Height;
873  im.stride = bd.Stride;
874  switch (bd.PixelFormat)
875  {
876  default:
877  case PixelFormat.Format24bppRgb: im.format = PFCPIXELFORMAT.PFC_PixelFormat24bppRGB; break;
878  case PixelFormat.Format32bppArgb: im.format = PFCPIXELFORMAT.PFC_PixelFormat32bppARGB; break;
879  case PixelFormat.Format48bppRgb: im.format = PFCPIXELFORMAT.PFC_PixelFormat48bppRGB; break;
880  case PixelFormat.Format64bppArgb: im.format = PFCPIXELFORMAT.PFC_PixelFormat64bppARGB; break;
881  }
882  im.data = (void*)pBase;
883 
884  if (m_pProfile != null)
885  PFC_ReleaseProfile(m_pProfile);
886 
887  byte* pModel = null;
888  if (CameraModel != null)
889  {
890  pModel = GetCharBuffer(CameraModel);
891  }
892  m_pProfile = PFC_Calc(&im, null, m_pEngine, feature, ISO, pModel, null, null, 1);
893 
894  FreeCharBuffer(pModel);
895 
896  ReleaseBitmapData(ref bm, ref bd);
897 
898  LastStatus.NR_Status = (*m_pProfile).NR_Status;
899  LastStatus.CORE_Status = (*m_pProfile).CORE_Status;
900  LastStatus.FB_Status = (*m_pProfile).FB_Status;
901  LastStatus.RE_Status = (*m_pProfile).RE_Status;
902  LastStatus.Status = (*m_pProfile).Status;
903 
904  return (LastStatus.Status == 0) ? ADPTRRETURNCODE.SUCCESS : ADPTRRETURNCODE.WARNING;
905  }
906 
915  public unsafe ADPTRRETURNCODE Calc(ref PFCImageFile imgfile, PFCFEATURE feature, int ISO, string CameraModel)
916  {
917  PFCIMAGE im;
918  im.width = imgfile.width();
919  im.height = imgfile.height();
920  im.stride = imgfile.stride();
921  im.format = (PFCPIXELFORMAT)imgfile.pfcImageFormat();
922  im.data = (void*)imgfile.raw_image();
923 
924  if (m_pProfile != null)
925  PFC_ReleaseProfile(m_pProfile);
926 
927  byte* pModel = null;
928  if (CameraModel != null)
929  {
930  pModel = GetCharBuffer(CameraModel);
931  }
932  m_pProfile = PFC_Calc(&im, null, m_pEngine, feature, ISO, pModel, null, null, 1);
933 
934  FreeCharBuffer(pModel);
935 
936  LastStatus.NR_Status = (*m_pProfile).NR_Status;
937  LastStatus.CORE_Status = (*m_pProfile).CORE_Status;
938  LastStatus.FB_Status = (*m_pProfile).FB_Status;
939  LastStatus.RE_Status = (*m_pProfile).RE_Status;
940  LastStatus.Status = (*m_pProfile).Status;
941 
942  return (LastStatus.Status == 0) ? ADPTRRETURNCODE.SUCCESS : ADPTRRETURNCODE.WARNING;
943  }
944 
954  public unsafe ADPTRRETURNCODE Calc(ref Bitmap bm, ref Bitmap bmds, PFCFEATURE feature, int ISO, string CameraModel)
955  {
956  BitmapData bd = null;
957  Byte* pBase = null;
958  bd = LockBitmapData(ref bm);
959  if (bd.PixelFormat != PixelFormat.Format24bppRgb &&
960  bd.PixelFormat != PixelFormat.Format32bppArgb &&
961  bd.PixelFormat != PixelFormat.Format48bppRgb &&
962  bd.PixelFormat != PixelFormat.Format64bppArgb)
963  {
964  ReleaseBitmapData(ref bm, ref bd);
965  return ADPTRRETURNCODE.WRONG_FORMAT;
966  }
967  pBase = (Byte*)bd.Scan0.ToPointer();
968 
969  PFCIMAGE im;
970  im.width = bd.Width;
971  im.height = bd.Height;
972  im.stride = bd.Stride;
973  switch (bd.PixelFormat)
974  {
975  default:
976  case PixelFormat.Format24bppRgb: im.format = PFCPIXELFORMAT.PFC_PixelFormat24bppRGB; break;
977  case PixelFormat.Format32bppArgb: im.format = PFCPIXELFORMAT.PFC_PixelFormat32bppARGB; break;
978  case PixelFormat.Format48bppRgb: im.format = PFCPIXELFORMAT.PFC_PixelFormat48bppRGB; break;
979  case PixelFormat.Format64bppArgb: im.format = PFCPIXELFORMAT.PFC_PixelFormat64bppARGB; break;
980  }
981  im.data = (void*)pBase;
982 
983  BitmapData bdds = null;
984  bdds = LockBitmapData(ref bmds);
985  if (bdds.PixelFormat != PixelFormat.Format24bppRgb &&
986  bdds.PixelFormat != PixelFormat.Format32bppArgb &&
987  bdds.PixelFormat != PixelFormat.Format48bppRgb &&
988  bdds.PixelFormat != PixelFormat.Format64bppArgb)
989  {
990  ReleaseBitmapData(ref bmds, ref bdds);
991  return ADPTRRETURNCODE.WRONG_FORMAT;
992  }
993  pBase = (Byte*)bdds.Scan0.ToPointer();
994 
995  PFCIMAGE imds;
996  imds.width = bdds.Width;
997  imds.height = bdds.Height;
998  imds.stride = bdds.Stride;
999  switch (bdds.PixelFormat)
1000  {
1001  default:
1002  case PixelFormat.Format24bppRgb: imds.format = PFCPIXELFORMAT.PFC_PixelFormat24bppRGB; break;
1003  case PixelFormat.Format32bppArgb: imds.format = PFCPIXELFORMAT.PFC_PixelFormat32bppARGB; break;
1004  case PixelFormat.Format48bppRgb: imds.format = PFCPIXELFORMAT.PFC_PixelFormat48bppRGB; break;
1005  case PixelFormat.Format64bppArgb: imds.format = PFCPIXELFORMAT.PFC_PixelFormat64bppARGB; break;
1006  }
1007  imds.data = (void*)pBase;
1008 
1009  if (m_pProfile != null)
1010  PFC_ReleaseProfile(m_pProfile);
1011 
1012  byte* pModel = null;
1013  if (CameraModel != null)
1014  {
1015  pModel = GetCharBuffer(CameraModel);
1016  }
1017  m_pProfile = PFC_Calc(&im, &imds, m_pEngine, feature, ISO, pModel, null, null, 1);
1018 
1019  FreeCharBuffer(pModel);
1020 
1021  ReleaseBitmapData(ref bm, ref bd);
1022  ReleaseBitmapData(ref bmds, ref bdds);
1023 
1024  LastStatus.NR_Status = (*m_pProfile).NR_Status;
1025  LastStatus.CORE_Status = (*m_pProfile).CORE_Status;
1026  LastStatus.FB_Status = (*m_pProfile).FB_Status;
1027  LastStatus.RE_Status = (*m_pProfile).RE_Status;
1028  LastStatus.Status = (*m_pProfile).Status;
1029 
1030  return (LastStatus.Status == 0) ? ADPTRRETURNCODE.SUCCESS : ADPTRRETURNCODE.WARNING;
1031  }
1032 
1039  public unsafe PFCAPPLYSTATUS Apply(ref Bitmap bm)
1040  {
1041  return Apply(ref bm, 100);
1042  }
1043 
1049  public unsafe PFCAPPLYSTATUS Apply(ref PFCImageFile imgfile)
1050  {
1051  return Apply(ref imgfile, 100);
1052  }
1053 
1060  public unsafe PFCAPPLYSTATUS Apply(ref Bitmap bm, int iOpacity)
1061  {
1062  if (m_pProfile == null)
1063  {
1064  return PFCAPPLYSTATUS.APPLY_ERROR_PROFILE_MISSING;
1065  }
1066 
1067  BitmapData bd = null;
1068  Byte* pBase = null;
1069  bd = LockBitmapData(ref bm);
1070  if (bd.PixelFormat != PixelFormat.Format24bppRgb &&
1071  bd.PixelFormat != PixelFormat.Format32bppArgb &&
1072  bd.PixelFormat != PixelFormat.Format48bppRgb &&
1073  bd.PixelFormat != PixelFormat.Format64bppArgb)
1074  {
1075  ReleaseBitmapData(ref bm, ref bd);
1076  return PFCAPPLYSTATUS.APPLY_BADFORMAT;
1077  }
1078  pBase = (Byte*)bd.Scan0.ToPointer();
1079 
1080  PFCIMAGE im;
1081  im.width = bd.Width;
1082  im.height = bd.Height;
1083  im.stride = bd.Stride;
1084  switch (bd.PixelFormat)
1085  {
1086  default:
1087  case PixelFormat.Format24bppRgb: im.format = PFCPIXELFORMAT.PFC_PixelFormat24bppRGB; break;
1088  case PixelFormat.Format32bppArgb: im.format = PFCPIXELFORMAT.PFC_PixelFormat32bppARGB; break;
1089  case PixelFormat.Format48bppRgb: im.format = PFCPIXELFORMAT.PFC_PixelFormat48bppRGB; break;
1090  case PixelFormat.Format64bppArgb: im.format = PFCPIXELFORMAT.PFC_PixelFormat64bppARGB; break;
1091  }
1092  im.data = (void*)pBase;
1093 
1094  PFCAPPLYSTATUS ret = PFC_Apply(&im, m_pEngine, m_pProfile, ref m_Param, null, iOpacity, null);
1095 
1096  if (ret > 0)
1097  {
1098  int code = (int)ret;
1099  // Get individual return codes
1100  LastStatus.NR_Status = (PFCNR_STATUS)(code & 0x000000FF);
1101  LastStatus.CORE_Status = (PFCCORE_STATUS)((code >> 8) & 0x000000FF);
1102  LastStatus.FB_Status = (PFCFB_STATUS)((code >> 16) & 0x000000FF);
1103  LastStatus.RE_Status = (PFCRE_STATUS)((code >> 24) & 0x000000FF);
1104  LastStatus.Status = code;
1105  }
1106 
1107  ReleaseBitmapData(ref bm, ref bd);
1108  return ret;
1109  }
1110 
1117  public unsafe PFCAPPLYSTATUS Apply(ref PFCImageFile imgfile, int iOpacity)
1118  {
1119  if (m_pProfile == null)
1120  {
1121  return PFCAPPLYSTATUS.APPLY_ERROR_PROFILE_MISSING;
1122  }
1123 
1124  PFCIMAGE im;
1125  im.width = imgfile.width();
1126  im.height = imgfile.height();
1127  im.stride = imgfile.stride();
1128  im.format = (PFCPIXELFORMAT)imgfile.pfcImageFormat();
1129  im.data = (void*)imgfile.raw_image();
1130 
1131  PFCAPPLYSTATUS ret = PFC_Apply(&im, m_pEngine, m_pProfile, ref m_Param, null, iOpacity, null);
1132 
1133  if (ret > 0)
1134  {
1135  int code = (int)ret;
1136  // Get individual return codes
1137  LastStatus.NR_Status = (PFCNR_STATUS)(code & 0x000000FF);
1138  LastStatus.CORE_Status = (PFCCORE_STATUS)((code >> 8) & 0x000000FF);
1139  LastStatus.FB_Status = (PFCFB_STATUS)((code >> 16) & 0x000000FF);
1140  LastStatus.RE_Status = (PFCRE_STATUS)((code >> 24) & 0x000000FF);
1141  LastStatus.Status = code;
1142  }
1143 
1144  return ret;
1145  }
1146 
1147  public unsafe PFCAPPLYSTATUS ApplyLocal(ref Bitmap bm, int xOffset, int yOffset, int widthOrig, int heightOrig)
1148  {
1149  return ApplyLocal(ref bm, xOffset, yOffset, widthOrig, heightOrig, 100);
1150  }
1151 
1152  public unsafe PFCAPPLYSTATUS ApplyLocal(ref Bitmap bm, int xOffset, int yOffset, int widthOrig, int heightOrig, int iOpacity)
1153  {
1154  BitmapData bd = null;
1155  Byte* pBase = null;
1156  bd = LockBitmapData(ref bm);
1157  if (bd.PixelFormat != PixelFormat.Format24bppRgb &&
1158  bd.PixelFormat != PixelFormat.Format32bppArgb &&
1159  bd.PixelFormat != PixelFormat.Format48bppRgb &&
1160  bd.PixelFormat != PixelFormat.Format64bppArgb)
1161  {
1162  ReleaseBitmapData(ref bm, ref bd);
1163  return PFCAPPLYSTATUS.APPLY_BADFORMAT;
1164  }
1165  pBase = (Byte*)bd.Scan0.ToPointer();
1166 
1167  PFCIMAGE im;
1168  im.width = bd.Width;
1169  im.height = bd.Height;
1170  im.stride = bd.Stride;
1171  switch (bd.PixelFormat)
1172  {
1173  default:
1174  case PixelFormat.Format24bppRgb: im.format = PFCPIXELFORMAT.PFC_PixelFormat24bppRGB; break;
1175  case PixelFormat.Format32bppArgb: im.format = PFCPIXELFORMAT.PFC_PixelFormat32bppARGB; break;
1176  case PixelFormat.Format48bppRgb: im.format = PFCPIXELFORMAT.PFC_PixelFormat48bppRGB; break;
1177  case PixelFormat.Format64bppArgb: im.format = PFCPIXELFORMAT.PFC_PixelFormat64bppARGB; break;
1178  }
1179  im.data = (void*)pBase;
1180 
1181  PFCAPPLYSTATUS ret = PFC_ApplyLocal(&im, xOffset, yOffset, widthOrig, heightOrig, m_pEngine, m_pProfile, ref m_Param, iOpacity);
1182 
1183  ReleaseBitmapData(ref bm, ref bd);
1184  return ret;
1185  }
1186 
1187  public unsafe PFCAPPLYSTATUS ApplyLocal(ref PFCImageFile imgfile, int xOffset, int yOffset, int widthOrig, int heightOrig, int iOpacity)
1188  {
1189  PFCIMAGE im;
1190  im.width = imgfile.width();
1191  im.height = imgfile.height();
1192  im.stride = imgfile.stride();
1193  im.format = (PFCPIXELFORMAT)imgfile.pfcImageFormat();
1194  im.data = (void*)imgfile.raw_image();
1195 
1196  PFCAPPLYSTATUS ret = PFC_ApplyLocal(&im, xOffset, yOffset, widthOrig, heightOrig, m_pEngine, m_pProfile, ref m_Param, iOpacity);
1197 
1198  return ret;
1199  }
1200 
1231  public int AutoCorrect(ref Bitmap bm)
1232  {
1233  return AutoCorrect(ref bm, -1, null, false);
1234  }
1235 
1241  public int AutoCorrect(ref PFCImageFile imgfile)
1242  {
1243  return AutoCorrect(ref imgfile, -1, null, false);
1244  }
1245 
1253  public int AutoCorrect(ref Bitmap bm, ref Bitmap bmds)
1254  {
1255  return AutoCorrect(ref bm, ref bmds, -1, null, false);
1256  }
1257 
1266  public int AutoCorrect(ref Bitmap bm, int ISO, string CameraModel, bool bFastFAE)
1267  {
1268  PFCFEATURE feature = 0;
1269  if (m_Param.nr.bEnabled)
1270  feature |= PFCFEATURE.CALC_NR;
1271  if (m_Param.core.bEnabled)
1272  feature |= PFCFEATURE.CALC_CORE;
1273  if (m_Param.fb.bEnabled)
1274  feature |= PFCFEATURE.CALC_FB;
1275  if (m_Param.re.bEnabled)
1276  feature |= PFCFEATURE.CALC_RE;
1277  if (!m_Param.core.bAbnormalTintRemoval)
1278  feature |= PFCFEATURE.CALC_NOTINTCALC;
1279  // Any FAE optimization
1280  if (m_Param.core.bUseFAE)
1281  {
1282  if (bFastFAE)
1283  feature |= PFCFEATURE.CALC_FAEHISPEED;
1284  }
1285  else
1286  {
1287  feature |= PFCFEATURE.CALC_NOFAE;
1288  }
1289 
1290  ADPTRRETURNCODE ret = Calc(ref bm, feature, ISO, CameraModel);
1291 
1292  if (ret != ADPTRRETURNCODE.SUCCESS)
1293  {
1294  PFCNR_STATUS retNR = LastStatus.NR_Status;
1295  if (retNR == PFCNR_STATUS.PFC_NR_NOTFOUND || retNR == PFCNR_STATUS.PFC_NR_NOTENABLED)
1296  retNR = PFCNR_STATUS.PFC_NR_SUCCESS;
1297 
1298  PFCCORE_STATUS retCORE = LastStatus.CORE_Status;
1299  if (retCORE == PFCCORE_STATUS.PFC_CORE_NOTENABLED)
1300  retCORE = PFCCORE_STATUS.PFC_CORE_SUCCESS;
1301 
1302  PFCFB_STATUS retFB = LastStatus.FB_Status;
1303  if (retFB == PFCFB_STATUS.PFC_FB_NOTENABLED || retFB == PFCFB_STATUS.PFC_FB_WARNING)
1304  retFB = PFCFB_STATUS.PFC_FB_SUCCESS;
1305 
1306  PFCRE_STATUS retRE = LastStatus.RE_Status;
1307  if (retRE == PFCRE_STATUS.PFC_RE_NOTENABLED || retRE == PFCRE_STATUS.PFC_RE_NOT_FOUND)
1308  retRE = PFCRE_STATUS.PFC_RE_SUCCESS;
1309 
1310  int retInt = (((((((int)retRE << 8) | (int)retFB) << 8) | (int)retCORE) << 8) | (int)retNR);
1311  return retInt;
1312  }
1313  else
1314  {
1315  PFCAPPLYSTATUS aret = Apply(ref bm);
1316  return (int)aret;
1317  }
1318  }
1319 
1328  public int AutoCorrect(ref PFCImageFile imgfile, int ISO, string CameraModel, bool bFastFAE)
1329  {
1330  PFCFEATURE feature = 0;
1331  if (m_Param.nr.bEnabled)
1332  feature |= PFCFEATURE.CALC_NR;
1333  if (m_Param.core.bEnabled)
1334  feature |= PFCFEATURE.CALC_CORE;
1335  if (m_Param.fb.bEnabled)
1336  feature |= PFCFEATURE.CALC_FB;
1337  if (m_Param.re.bEnabled)
1338  feature |= PFCFEATURE.CALC_RE;
1339  if (!m_Param.core.bAbnormalTintRemoval)
1340  feature |= PFCFEATURE.CALC_NOTINTCALC;
1341  // Any FAE optimization
1342  if (m_Param.core.bUseFAE)
1343  {
1344  if (bFastFAE)
1345  feature |= PFCFEATURE.CALC_FAEHISPEED;
1346  }
1347  else
1348  {
1349  feature |= PFCFEATURE.CALC_NOFAE;
1350  }
1351 
1352  ADPTRRETURNCODE ret = Calc(ref imgfile, feature, ISO, CameraModel);
1353 
1354  if (ret != ADPTRRETURNCODE.SUCCESS)
1355  {
1356  PFCNR_STATUS retNR = LastStatus.NR_Status;
1357  if (retNR == PFCNR_STATUS.PFC_NR_NOTFOUND || retNR == PFCNR_STATUS.PFC_NR_NOTENABLED)
1358  retNR = PFCNR_STATUS.PFC_NR_SUCCESS;
1359 
1360  PFCCORE_STATUS retCORE = LastStatus.CORE_Status;
1361  if (retCORE == PFCCORE_STATUS.PFC_CORE_NOTENABLED)
1362  retCORE = PFCCORE_STATUS.PFC_CORE_SUCCESS;
1363 
1364  PFCFB_STATUS retFB = LastStatus.FB_Status;
1365  if (retFB == PFCFB_STATUS.PFC_FB_NOTENABLED || retFB == PFCFB_STATUS.PFC_FB_WARNING)
1366  retFB = PFCFB_STATUS.PFC_FB_SUCCESS;
1367 
1368  PFCRE_STATUS retRE = LastStatus.RE_Status;
1369  if (retRE == PFCRE_STATUS.PFC_RE_NOTENABLED || retRE == PFCRE_STATUS.PFC_RE_NOT_FOUND)
1370  retRE = PFCRE_STATUS.PFC_RE_SUCCESS;
1371 
1372  int retInt = (((((((int)retRE << 8) | (int)retFB) << 8) | (int)retCORE) << 8) | (int)retNR);
1373  return retInt;
1374  }
1375  else
1376  {
1377  PFCAPPLYSTATUS aret = Apply(ref imgfile);
1378  return (int)aret;
1379  }
1380  }
1381 
1391  public int AutoCorrect(ref Bitmap bm, ref Bitmap bmds, int ISO, string CameraModel, bool bFastFAE)
1392  {
1393  PFCFEATURE feature = 0;
1394  if (m_Param.nr.bEnabled)
1395  feature |= PFCFEATURE.CALC_NR;
1396  if (m_Param.core.bEnabled)
1397  feature |= PFCFEATURE.CALC_CORE;
1398  if (m_Param.fb.bEnabled)
1399  feature |= PFCFEATURE.CALC_FB;
1400  if (m_Param.re.bEnabled)
1401  feature |= PFCFEATURE.CALC_RE;
1402  if (!m_Param.core.bAbnormalTintRemoval)
1403  feature |= PFCFEATURE.CALC_NOTINTCALC;
1404  // Any FAE optimization
1405  if (m_Param.core.bUseFAE)
1406  {
1407  if (bFastFAE)
1408  feature |= PFCFEATURE.CALC_FAEHISPEED;
1409  }
1410  else
1411  {
1412  feature |= PFCFEATURE.CALC_NOFAE;
1413  }
1414 
1415  ADPTRRETURNCODE ret = Calc(ref bm, ref bmds, feature, ISO, CameraModel);
1416 
1417  if (ret != ADPTRRETURNCODE.SUCCESS)
1418  {
1419  PFCNR_STATUS retNR = LastStatus.NR_Status;
1420  if (retNR == PFCNR_STATUS.PFC_NR_NOTFOUND || retNR == PFCNR_STATUS.PFC_NR_NOTENABLED)
1421  retNR = PFCNR_STATUS.PFC_NR_SUCCESS;
1422 
1423  PFCCORE_STATUS retCORE = LastStatus.CORE_Status;
1424  if (retCORE == PFCCORE_STATUS.PFC_CORE_NOTENABLED)
1425  retCORE = PFCCORE_STATUS.PFC_CORE_SUCCESS;
1426 
1427  PFCFB_STATUS retFB = LastStatus.FB_Status;
1428  if (retFB == PFCFB_STATUS.PFC_FB_NOTENABLED || retFB == PFCFB_STATUS.PFC_FB_WARNING)
1429  retFB = PFCFB_STATUS.PFC_FB_SUCCESS;
1430 
1431  PFCRE_STATUS retRE = LastStatus.RE_Status;
1432  if (retRE == PFCRE_STATUS.PFC_RE_NOTENABLED || retRE == PFCRE_STATUS.PFC_RE_NOT_FOUND)
1433  retRE = PFCRE_STATUS.PFC_RE_SUCCESS;
1434 
1435  int retInt = (((((((int)retRE << 8) | (int)retFB) << 8) | (int)retCORE) << 8) | (int)retNR);
1436  return retInt;
1437  }
1438  else
1439  {
1440  PFCAPPLYSTATUS aret = Apply(ref bm);
1441  return (int)aret;
1442  }
1443  }
1444 
1451  public int AutoCorrect(ref Bitmap bm, string pathPreset)
1452  {
1453  int retCode = ReadPresets(pathPreset);
1454  if (retCode == 0)
1455  {
1456  return AutoCorrect(ref bm, -1, null, false);
1457  }
1458  return retCode-1000;
1459  }
1460 
1467  public int AutoCorrect(ref PFCImageFile imgfile, string pathPreset)
1468  {
1469  int retCode = ReadPresets(pathPreset);
1470  if (retCode == 0)
1471  {
1472  return AutoCorrect(ref imgfile, -1, null, false);
1473  }
1474  return retCode - 1000;
1475  }
1476 
1484  public int AutoCorrect(ref Bitmap bm, ref Bitmap bmds, string pathPreset)
1485  {
1486  int retCode = ReadPresets(pathPreset);
1487  if (retCode == 0)
1488  {
1489  return AutoCorrect(ref bm, ref bmds, -1, null, false);
1490  }
1491  return retCode - 1000;
1492  }
1493 
1503  public int AutoCorrect(ref Bitmap bm, string pathPreset, int ISO, string CameraModel, bool bFastFAE)
1504  {
1505  int retCode = ReadPresets(pathPreset);
1506  if (retCode == 0)
1507  {
1508  return AutoCorrect(ref bm, ISO, CameraModel, bFastFAE);
1509  }
1510  return retCode - 1000;
1511  }
1512 
1522  public int AutoCorrect(ref PFCImageFile imgfile, string pathPreset, int ISO, string CameraModel, bool bFastFAE)
1523  {
1524  int retCode = ReadPresets(pathPreset);
1525  if (retCode == 0)
1526  {
1527  return AutoCorrect(ref imgfile, ISO, CameraModel, bFastFAE);
1528  }
1529  return retCode - 1000;
1530  }
1531 
1542  public int AutoCorrect(ref Bitmap bm, ref Bitmap bmds, string pathPreset, int ISO, string CameraModel, bool bFastFAE)
1543  {
1544  int retCode = ReadPresets(pathPreset);
1545  if (retCode == 0)
1546  {
1547  return AutoCorrect(ref bm, ref bmds, ISO, CameraModel, bFastFAE);
1548  }
1549  return retCode - 1000;
1550  }
1551 
1556  public void SetParam(PFCPRESETID id)
1557  {
1558  PFC_SetParam(ref m_Param, id);
1559  }
1560 
1578  public int ReadPresets(string path)
1579  {
1580  try
1581  {
1582  byte* presetpath = null;
1583  if (path != null)
1584  {
1585  presetpath = GetCharBuffer(path);
1586  }
1587 
1588  int status = PFC_ReadPresets(ref m_Param, presetpath);
1589  //Trace.WriteLine("status " + status.ToString());
1590  return status;
1591  }
1592  catch (Exception ex)
1593  {
1594  Trace.WriteLine(ex.Message);
1595  }
1596  return -8;
1597  }
1598 
1611  public int ReadPresetsFromStream(FileStream fs)
1612  {
1613  try
1614  {
1615  long len = fs.Length;
1616  byte[] buffer = new byte[len + 1];
1617  int size = (int)len;
1618  fs.Read(buffer, 0, size);
1619  buffer[size] = 0;
1620  byte* b = GetCharBuffer(buffer);
1621  // PFC_ReadPresetsFromStream return codes
1622  // 0 - success
1623  // -3 - Stream read error.
1624  // -4 - Parse error.
1625  int status = PFC_ReadPresetsFromStream(ref m_Param, b);
1626  FreeCharBuffer(b);
1627  return status;
1628  }
1629  catch (Exception ex)
1630  {
1631  Trace.WriteLine(ex.Message);
1632  }
1633  return -8;
1634  }
1635 
1641  {
1642  return PFC_HasFaceBeautification(m_pEngine);
1643  }
1644 
1650  public int FBFaceCount()
1651  {
1652  return PFC_FBFaceCount(m_pProfile);
1653  }
1654 
1663  public bool GetFaceInfo(ref PFCFBFACEINFO info, int index)
1664  {
1665  PFCFBFACEINFO1 fi;
1666  bool ret = PFC_GetFaceInfo(m_pProfile, &fi, index);
1667  info.face.left = fi.face.left;
1668  info.face.top = fi.face.top;
1669  info.face.width = fi.face.width;
1670  info.face.height = fi.face.height;
1671  info.leftEye.x = fi.leftEye.x;
1672  info.leftEye.y = fi.leftEye.y;
1673  info.rightEye.x = fi.rightEye.x;
1674  info.rightEye.y = fi.rightEye.y;
1675  return ret;
1676  }
1677 
1683  public bool AbnormalTintDetected(TINTCORRECTION eTintMethod)
1684  {
1685  return PFC_AbnormalTintDetected(m_pProfile, eTintMethod);
1686  }
1687 
1693  public void ApplyStrengthToParam(int strength)
1694  {
1695  PFC_ApplyStrengthToParam(ref m_Param, strength);
1696  }
1697 
1698  protected BitmapData LockBitmapData(ref Bitmap bm)
1699  {
1700  GraphicsUnit unit = GraphicsUnit.Pixel;
1701  RectangleF boundsF = bm.GetBounds(ref unit);
1702  Rectangle bounds = new Rectangle((int)boundsF.X,
1703  (int)boundsF.Y,
1704  (int)boundsF.Width,
1705  (int)boundsF.Height);
1706 
1707  BitmapData bitmapData =
1708  bm.LockBits(bounds, ImageLockMode.ReadWrite, bm.PixelFormat);
1709  return bitmapData;
1710  }
1711 
1712  protected void ReleaseBitmapData(ref Bitmap bm, ref BitmapData bitmapData)
1713  {
1714  bm.UnlockBits(bitmapData);
1715  }
1716 
1717  protected Bitmap DupBitmap(ref Bitmap bm)
1718  {
1719  PerfectlyClearImageTransfer tr, tr1;
1720  Byte* pBase = null;
1721  GraphicsUnit unit = GraphicsUnit.Pixel;
1722  RectangleF boundsF = bm.GetBounds(ref unit);
1723  Rectangle bounds = new Rectangle((int)boundsF.X,
1724  (int)boundsF.Y,
1725  (int)boundsF.Width,
1726  (int)boundsF.Height);
1727  BitmapData bd = bm.LockBits(bounds, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
1728  Bitmap bm1 = new Bitmap(bd.Width, bd.Height, PixelFormat.Format24bppRgb);
1729  BitmapData bd1 = LockBitmapData(ref bm1);
1730  pBase = (Byte*)bd.Scan0.ToPointer();
1731  tr.columnBytes = (bd.PixelFormat == PixelFormat.Format24bppRgb) ? 3 : 4;
1732  tr.rowBytes = bd.Stride;
1733  tr.height = bd.Height;
1734  tr.width = bd.Width;
1735  tr.data1 = (int)(pBase + 2);
1736  tr.data2 = (int)(pBase + 1);
1737  tr.data3 = (int)pBase;
1738  pBase = (Byte*)bd1.Scan0.ToPointer();
1739  tr1.columnBytes = (bd1.PixelFormat == PixelFormat.Format24bppRgb) ? 3 : 4;
1740  tr1.rowBytes = bd1.Stride;
1741  tr1.height = bd1.Height;
1742  tr1.width = bd1.Width;
1743  tr1.data1 = (int)(pBase + 2);
1744  tr1.data2 = (int)(pBase + 1);
1745  tr1.data3 = (int)pBase;
1746  for (int i = 0; i < tr.height; i++)
1747  {
1748  for (int j = 0; j < tr.width; j++)
1749  {
1750  ((Byte*)tr1.data1)[j * tr1.columnBytes] = ((Byte*)tr.data1)[j * tr.columnBytes];
1751  ((Byte*)tr1.data2)[j * tr1.columnBytes] = ((Byte*)tr.data2)[j * tr.columnBytes];
1752  ((Byte*)tr1.data3)[j * tr1.columnBytes] = ((Byte*)tr.data3)[j * tr.columnBytes];
1753  }
1754  tr.data1 += (int)tr.rowBytes;
1755  tr.data2 += (int)tr.rowBytes;
1756  tr.data3 += (int)tr.rowBytes;
1757  tr1.data1 += (int)tr1.rowBytes;
1758  tr1.data2 += (int)tr1.rowBytes;
1759  tr1.data3 += (int)tr1.rowBytes;
1760  }
1761  ReleaseBitmapData(ref bm1, ref bd1);
1762  ReleaseBitmapData(ref bm, ref bd);
1763  return bm1;
1764  }
1765 
1766  protected Bitmap BW2RGB(ref Bitmap bm)
1767  {
1768  Byte* pBase = null;
1769  Byte* pBase1 = null;
1770  GraphicsUnit unit = GraphicsUnit.Pixel;
1771  RectangleF boundsF = bm.GetBounds(ref unit);
1772  Rectangle bounds = new Rectangle((int)boundsF.X,
1773  (int)boundsF.Y,
1774  (int)boundsF.Width,
1775  (int)boundsF.Height);
1776  BitmapData bd = bm.LockBits(bounds, ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);
1777  Bitmap bm1 = new Bitmap(bd.Width, bd.Height, PixelFormat.Format24bppRgb);
1778  BitmapData bd1 = LockBitmapData(ref bm1);
1779  pBase = (Byte*)bd.Scan0.ToPointer();
1780  pBase1 = (Byte*)bd1.Scan0.ToPointer();
1781  for (int i = 0; i < bd.Height; i++)
1782  {
1783  for (int j = 0; j < bd.Width; j++)
1784  {
1785  pBase1[j * 3] = pBase[j];
1786  pBase1[j * 3 + 1] = pBase[j];
1787  pBase1[j * 3 + 2] = pBase[j];
1788  }
1789  pBase += bd.Stride;
1790  pBase1 += bd1.Stride;
1791  }
1792  ReleaseBitmapData(ref bm1, ref bd1);
1793  ReleaseBitmapData(ref bm, ref bd);
1794  return bm1;
1795  }
1796 
1804  public Bitmap ReadImage(string filename)
1805  {
1806  Bitmap bm = null;
1807  Bitmap myBitmap = new Bitmap(filename);
1808  if ((myBitmap.Flags & (int)ImageFlags.ColorSpaceYcck) != 0)
1809  {
1810  bm = DupBitmap(ref myBitmap);
1811  myBitmap.Dispose();
1812  }
1813  else
1814  {
1815  if (myBitmap.PixelFormat == PixelFormat.Format8bppIndexed)
1816  {
1817  bm = BW2RGB(ref myBitmap);
1818  myBitmap.Dispose();
1819  }
1820  else
1821  {
1822  bm = myBitmap;
1823  }
1824  }
1825  return bm;
1826  }
1827 
1828  protected Bitmap GetStatImage(ref Bitmap bm, int iMaxDimension)
1829  {
1830  // Build max dim reference image
1831  bool bNeedResize = true;
1832  int w, h, w1, h1;
1833  w = bm.Width;
1834  h = bm.Height;
1835  // Calculate size of reference image. One dimension is 1024.
1836  if (w > h)
1837  {
1838  if (w <= iMaxDimension)
1839  bNeedResize = false;
1840  w1 = iMaxDimension;
1841  h1 = w1 * h / w;
1842  }
1843  else
1844  {
1845  if (h <= iMaxDimension)
1846  bNeedResize = false;
1847  h1 = iMaxDimension;
1848  w1 = h1 * w / h;
1849  }
1850 
1851  if (bNeedResize)
1852  {
1853  //
1854  // Step 2.
1855  // Create temporary bitmap to assist red eye analysis.
1856  //
1857  Bitmap bmds = new Bitmap(w1, h1, bm.PixelFormat);
1858  {
1859  using (Graphics gr = Graphics.FromImage(bmds))
1860  {
1861  gr.SmoothingMode = SmoothingMode.HighQuality;
1862  gr.InterpolationMode = InterpolationMode.HighQualityBicubic;
1863  gr.PixelOffsetMode = PixelOffsetMode.HighQuality;
1864  gr.DrawImage(bm, new Rectangle(0, 0, w1, h1));
1865  }
1866  }
1867 
1868  return bmds;
1869  }
1870  else
1871  {
1872  Bitmap bmds = (Bitmap)bm.Clone();
1873  return bmds;
1874  }
1875  }
1876 
1877  public void Dispose()
1878  {
1879  Dispose(true);
1880  GC.SuppressFinalize(this);
1881  }
1882 
1883  protected virtual void Dispose(bool disposing)
1884  {
1885  if (disposing)
1886  {
1887  }
1888 
1889  if (m_pProfile != null)
1890  {
1891  PFC_ReleaseProfile(m_pProfile);
1892  m_pProfile = null;
1893  }
1894 
1895  if (m_pEngine != null)
1896  {
1897  PFC_DestroyEngine(m_pEngine);
1898  m_pEngine = null;
1899  }
1900  }
1901 
1902  static protected byte* GetCharBuffer(byte[] s)
1903  {
1904  int i, iCount = s.Length;
1905  IntPtr _memory = IntPtr.Zero;
1906  _memory = Marshal.AllocHGlobal(iCount + 1);
1907  byte* p = (byte*)_memory;
1908  for (i = 0; i < iCount; i++)
1909  {
1910  p[i] = (byte)s[i];
1911  }
1912  p[iCount] = 0;
1913 
1914  return (byte*)p;
1915  }
1916 
1917  static protected byte* GetCharBuffer(string s)
1918  {
1919  int i, iCount = s.Length;
1920  IntPtr _memory = IntPtr.Zero;
1921  _memory = Marshal.AllocHGlobal(iCount + 1);
1922  byte* p = (byte*)_memory;
1923  for (i = 0; i < iCount; i++)
1924  {
1925  p[i] = (byte)s[i];
1926  }
1927  p[iCount] = 0;
1928 
1929  return (byte*)p;
1930  }
1931 
1932  static protected void FreeCharBuffer(byte* p)
1933  {
1934  IntPtr _memory = (IntPtr)p;
1935  Marshal.FreeHGlobal(_memory);
1936  }
1937 
1938 #if ADAPTER64BIT
1939  [DllImport("PerfectlyClearPro")]
1940  static extern int PFC_SetProtectionPath(byte* path, byte* licenseCode);
1941 
1942  [DllImport("PerfectlyClearPro")]
1943  static extern void PFC_ReleaseProtectionPath();
1944 
1945  [DllImport("PerfectlyClearPro")]
1946  static extern PFCENGINE* PFC_CreateEngine();
1947 
1948  [DllImport("PerfectlyClearPro")]
1949  static extern void PFC_DestroyEngine(PFCENGINE* p);
1950 
1951  [DllImport("PerfectlyClearPro")]
1952  static extern void PFC_SetParam(ref PFCPARAM param, PFCPRESETID id);
1953 
1954  [DllImport("PerfectlyClearPro")]
1955  static extern int PFC_ReadPresets(ref PFCPARAM param, byte* filename);
1956 
1957  [DllImport("PerfectlyClearPro")]
1958  static extern int PFC_ReadPresetsFromStream(ref PFCPARAM param, byte* s);
1959 
1960  [DllImport("PerfectlyClearPro")]
1961  static extern PFCIMAGEPROFILE* PFC_Calc(PFCIMAGE* pImage, PFCIMAGE* pImageds, PFCENGINE* pEngine, PFCFEATURE feature, int iISO, byte* pCameraModel, void* pImageProfile, void* progfn, int bRejectMonolith);
1962 
1963  [DllImport("PerfectlyClearPro")]
1964  static extern void PFC_ReleaseProfile(void* pProfile);
1965 
1966  [DllImport("PerfectlyClearPro")]
1967  static extern PFCAPPLYSTATUS PFC_Apply(PFCIMAGE* pImage, PFCENGINE* pEngine, void* pImageProfile, ref PFCPARAM param, void* progfn, int iOpacity, void* pBGProfile);
1968 
1969  [DllImport("PerfectlyClearPro")]
1970  static extern PFCAPPLYSTATUS PFC_ApplyLocal(PFCIMAGE* pImage, int xOffset, int yOffset, int widthOrig, int heightOrig, PFCENGINE* pEngine, PFCIMAGEPROFILE* pImageProfile, ref PFCPARAM param, int iOpacity);
1971 
1972  [DllImport("PerfectlyClearPro")]
1973  static extern bool PFC_HasFaceBeautification(PFCENGINE* pEngine);
1974 
1975  [DllImport("PerfectlyClearPro")]
1976  static extern int PFC_FBFaceCount(void* pImageProfile);
1977 
1978  [DllImport("PerfectlyClearPro")]
1979  static extern bool PFC_GetFaceInfo(void* pImageProfile, PFCFBFACEINFO1* pFace, int index);
1980 
1981  [DllImport("PerfectlyClearPro")]
1982  static extern bool PFC_AbnormalTintDetected(void* pImageProfile, TINTCORRECTION eTintMethod);
1983 
1984  [DllImport("PerfectlyClearPro")]
1985  static extern void PFC_ApplyStrengthToParam(ref PFCPARAM param, int strength);
1986 #endif
1987 
1988 #if ADAPTER32BIT
1989  [DllImport("PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
1990  static extern int PFC_SetProtectionPath(byte* path, byte* licenseCode);
1991 
1992  [DllImport("PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
1993  static extern void PFC_ReleaseProtectionPath();
1994 
1995  [DllImport("PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
1996  static extern PFCENGINE* PFC_CreateEngine();
1997 
1998  [DllImport("PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
1999  static extern void PFC_DestroyEngine(PFCENGINE* p);
2000 
2001  [DllImport("PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2002  static extern void PFC_SetParam(ref PFCPARAM param, PFCPRESETID id);
2003 
2004  [DllImport("PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2005  static extern int PFC_ReadPresets(ref PFCPARAM param, byte* filename);
2006 
2007  [DllImport("PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2008  static extern int PFC_ReadPresetsFromStream(ref PFCPARAM param, byte* s);
2009 
2010  [DllImport("PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2011  static extern PFCIMAGEPROFILE* PFC_Calc(PFCIMAGE* pImage, PFCIMAGE* pImageds, PFCENGINE* pEngine, PFCFEATURE feature, int iISO, byte* pCameraModel, void* pImageProfile, void* progfn, int bRejectMonolith);
2012 
2013  [DllImport("PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2014  static extern void PFC_ReleaseProfile(void* pProfile);
2015 
2016  [DllImport("PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2017  static extern PFCAPPLYSTATUS PFC_Apply(PFCIMAGE* pImage, PFCENGINE* pEngine, void* pImageProfile, ref PFCPARAM param, void* progfn, int iOpacity, void* pBGProfile);
2018 
2019  [DllImport("PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2020  static extern PFCAPPLYSTATUS PFC_ApplyLocal(PFCIMAGE* pImage, int xOffset, int yOffset, int widthOrig, int heightOrig, PFCENGINE* pEngine, PFCIMAGEPROFILE* pImageProfile, ref PFCPARAM param, int iOpacity);
2021 
2022  [DllImport("PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2023  static extern bool PFC_HasFaceBeautification(PFCENGINE* pEngine);
2024 
2025  [DllImport("PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2026  static extern int PFC_FBFaceCount(void* pImageProfile);
2027 
2028  [DllImport("PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2029  static extern bool PFC_GetFaceInfo(void* pImageProfile, PFCFBFACEINFO1* pFace, int index);
2030 
2031  [DllImport("PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2032  static extern bool PFC_AbnormalTintDetected(void* pImageProfile, TINTCORRECTION eTintMethod);
2033 
2034  [DllImport("PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2035  static extern void PFC_ApplyStrengthToParam(ref PFCPARAM param, int strength);
2036 #endif
2037  }
2038 
2039 
2075  public unsafe class PFCImageFile : IDisposable
2076  {
2077  private IntPtr m_pNativeObject;
2078 
2080  public PFCImageFile()
2081  {
2082  m_pNativeObject = create_PFCImageFile();
2083  }
2084 
2085  public void Dispose()
2086  {
2087  Dispose(true);
2088  }
2089 
2090  protected virtual void Dispose(bool bDisposing)
2091  {
2092  if (this.m_pNativeObject != IntPtr.Zero)
2093  {
2094  delete_PFCImageFile(m_pNativeObject);
2095  m_pNativeObject = IntPtr.Zero;
2096  }
2097 
2098  if (bDisposing)
2099  {
2100  // No need to call the finalizer since we've now cleaned
2101  // up the unmanaged memory
2102  GC.SuppressFinalize(this);
2103  }
2104  }
2105 
2106  ~PFCImageFile()
2107  {
2108  Dispose(false);
2109  }
2110 
2113  {
2114  LOAD_OK,
2115  LOAD_ERROR,
2118  };
2119 
2121  public enum PFC_FILETYPE
2122  {
2123  PFC_JPEG = 1,
2124  PFC_PNG = 2
2125  };
2126 
2134  public PFC_FILE_LOAD_STATUS LoadImage(string filename, bool bConvertToSRGB = false, string iccFolderPath = null)
2135  {
2136  if (filename == null)
2137  {
2138  return PFC_FILE_LOAD_STATUS.LOAD_ERROR;
2139  }
2140 
2141  byte* pFilename = GetCharBuffer(filename);
2142 
2143  byte* pIccFolderPath = null;
2144  if (iccFolderPath != null)
2145  {
2146  pIccFolderPath = GetCharBuffer(iccFolderPath);
2147  }
2148 
2149  int result = PFCImageFile_LoadImageFile(m_pNativeObject, pFilename, bConvertToSRGB, pIccFolderPath);
2150 
2151  FreeCharBuffer(pFilename);
2152  FreeCharBuffer(pIccFolderPath);
2153 
2154  return (PFC_FILE_LOAD_STATUS)result;
2155  }
2156 
2165  public PFC_FILE_LOAD_STATUS LoadImage(string filename, PFC_FILETYPE type, bool bConvertToSRGB = true, string iccFolderPath = null)
2166  {
2167  if (filename == null)
2168  {
2169  return PFC_FILE_LOAD_STATUS.LOAD_ERROR;
2170  }
2171 
2172  byte* pFilename = GetCharBuffer(filename);
2173 
2174  byte* pIccFolderPath = null;
2175  if (iccFolderPath != null)
2176  {
2177  pIccFolderPath = GetCharBuffer(iccFolderPath);
2178  }
2179 
2180  int result = PFCImageFile_LoadImageFileType(m_pNativeObject, pFilename, (int)type, bConvertToSRGB, pIccFolderPath);
2181 
2182  FreeCharBuffer(pFilename);
2183  FreeCharBuffer(pIccFolderPath);
2184 
2185  return (PFC_FILE_LOAD_STATUS)result;
2186  }
2187 
2195  public bool SaveImageFile(string filename, int jpegQuality = 92, bool bConvertToOriginalColorSpace= true, bool bEmbedOriginalMetadata = true)
2196  {
2197  if (filename == null)
2198  {
2199  return false;
2200  }
2201 
2202  byte* pFilename = GetCharBuffer(filename);
2203 
2204  bool result = PFCImageFile_SaveImageFile(m_pNativeObject, pFilename, jpegQuality, bConvertToOriginalColorSpace, bEmbedOriginalMetadata);
2205 
2206  FreeCharBuffer(pFilename);
2207 
2208  return result;
2209  }
2210 
2219  public bool SaveImageFile(string filename, PFC_FILETYPE type, int jpegQuality = 92, bool bConvertToOriginalColorSpace = true, bool bEmbedOriginalMetadata = true)
2220  {
2221  if (filename == null)
2222  {
2223  return false;
2224  }
2225 
2226  byte* pFilename = GetCharBuffer(filename);
2227 
2228  bool result = PFCImageFile_SaveImageFileType(m_pNativeObject, pFilename, (int)type, jpegQuality, bConvertToOriginalColorSpace, bEmbedOriginalMetadata);
2229 
2230  FreeCharBuffer(pFilename);
2231 
2232  return result;
2233  }
2234 
2235  public void AllocBuffer(int width, int height, int bytes_per_pixel, int stride)
2236  {
2237  PFCImageFile_AllocBuffer(m_pNativeObject, width, height, bytes_per_pixel, stride);
2238  }
2239 
2240  public int pfcImageFormat()
2241  {
2242  return PFCImageFile_pfcImageFormat(m_pNativeObject);
2243  }
2244 
2245  public int exifOrientation()
2246  {
2247  return PFCImageFile_exifOrientation(m_pNativeObject);
2248  }
2249 
2250  public byte* raw_image()
2251  {
2252  return PFCImageFile_get_raw_image(m_pNativeObject);
2253  }
2254 
2255  public int width()
2256  {
2257  return PFCImageFile_get_width(m_pNativeObject);
2258  }
2259 
2260  public int height()
2261  {
2262  return PFCImageFile_get_height(m_pNativeObject);
2263  }
2264 
2265  public int bytes_per_pixel()
2266  {
2267  return PFCImageFile_get_bytes_per_pixel(m_pNativeObject);
2268  }
2269 
2270  public int stride()
2271  {
2272  return PFCImageFile_get_stride(m_pNativeObject);
2273  }
2274 
2275  public bool sourceSRGB()
2276  {
2277  return PFCImageFile_get_sourceSRGB(m_pNativeObject);
2278  }
2279 
2288  public PFC_FILE_LOAD_STATUS ExpandImageBuffer(MemoryStream inStream, PFC_FILETYPE type, bool bConvertToSRGB = true, string iccFolderPath = null)
2289  {
2290  byte* buffer = GetByteBuffer(inStream.ToArray());
2291  byte* pIccFolderPath = null;
2292  if (iccFolderPath != null)
2293  {
2294  pIccFolderPath = GetCharBuffer(iccFolderPath);
2295  }
2296  int result = PFCImageFile_ExpandImageBuffer(m_pNativeObject, buffer, inStream.Length, (int)type, bConvertToSRGB, pIccFolderPath);
2297  FreeCharBuffer(pIccFolderPath);
2298  FreeByteBuffer(buffer);
2299 
2300  return (PFC_FILE_LOAD_STATUS)result;
2301  }
2302 
2311  public MemoryStream CompressImageBuffer(PFC_FILETYPE type, int jpegQuality = 92, bool bConvertToOriginalColorSpace = true, bool bEmbedOriginalMetadata = true)
2312  {
2313  byte* compressedBuffer = null;
2314  int length = PFCImageFile_CompressImageBuffer(m_pNativeObject, &compressedBuffer, (int)type, jpegQuality, bConvertToOriginalColorSpace, bEmbedOriginalMetadata);
2315  if (length > 0 && compressedBuffer != null)
2316  {
2317  byte[] result = new byte[length];
2318  Marshal.Copy((IntPtr)(compressedBuffer), result, 0, length);
2319  deleteBuffer(compressedBuffer);
2320 
2321  // let the stream be resizable
2322  MemoryStream stream = new MemoryStream();
2323  stream.Write(result, 0, result.Length);
2324  return stream;
2325  }
2326  return new MemoryStream();
2327  }
2328 
2329  private static byte* GetCharBuffer(string s)
2330  {
2331  UTF8Encoding utf8 = new UTF8Encoding();
2332  Byte[] encodedBytes = utf8.GetBytes(s);
2333 
2334  int i, iCount = encodedBytes.Length;
2335  IntPtr _memory = IntPtr.Zero;
2336  _memory = Marshal.AllocHGlobal(iCount + 1);
2337  byte* p = (byte*)_memory;
2338  for (i = 0; i < iCount; i++)
2339  {
2340  p[i] = encodedBytes[i];
2341  }
2342  p[iCount] = 0;
2343 
2344  return (byte*)p;
2345  }
2346 
2347  private static void FreeCharBuffer(byte* p)
2348  {
2349  IntPtr _memory = (IntPtr)p;
2350  Marshal.FreeHGlobal(_memory);
2351  }
2352 
2353  private static byte* GetByteBuffer(byte[] bytes)
2354  {
2355  int length = bytes.Length;
2356  IntPtr p = Marshal.AllocHGlobal(length);
2357  Marshal.Copy(bytes, 0, p, length);
2358  return (byte*)p;
2359  }
2360 
2361  private static void FreeByteBuffer(byte* p)
2362  {
2363  IntPtr _memory = (IntPtr)p;
2364  Marshal.FreeHGlobal(_memory);
2365  }
2366 
2367 #if ADAPTER64BIT
2368  [DllImport("PFCImageFile")]
2369  static private extern unsafe IntPtr create_PFCImageFile();
2370 
2371  [DllImport("PFCImageFile")]
2372  static private extern void delete_PFCImageFile(IntPtr o);
2373 
2374  [DllImport("PFCImageFile")]
2375  static private extern unsafe int PFCImageFile_LoadImageFile(IntPtr o, byte* filename, bool bConvertToSRGB, byte* iccFolderPath);
2376 
2377  [DllImport("PFCImageFile")]
2378  static private extern unsafe int PFCImageFile_LoadImageFileType(IntPtr o, byte* filename, int type, bool bConvertToSRGB, byte* iccFolderPath);
2379 
2380  [DllImport("PFCImageFile")]
2381  static private extern unsafe bool PFCImageFile_SaveImageFile(IntPtr ptr, byte* filename, int jpegQuality, bool bConvertToOriginalColorSpace, bool bEmbedOriginalMetadata);
2382 
2383  [DllImport("PFCImageFile")]
2384  static private extern unsafe bool PFCImageFile_SaveImageFileType(IntPtr ptr, byte* filename, int type, int jpegQuality, bool bConvertToOriginalColorSpace, bool bEmbedOriginalMetadata);
2385 
2386  [DllImport("PFCImageFile")]
2387  static private extern unsafe void PFCImageFile_AllocBuffer(IntPtr ptr, int width, int height, int bytes_per_pixel, int stride);
2388 
2389  [DllImport("PFCImageFile")]
2390  static private extern unsafe int PFCImageFile_pfcImageFormat(IntPtr ptr);
2391 
2392  [DllImport("PFCImageFile")]
2393  static private extern unsafe int PFCImageFile_exifOrientation(IntPtr ptr);
2394 
2395  [DllImport("PFCImageFile")]
2396  static private extern unsafe byte* PFCImageFile_get_raw_image(IntPtr ptr);
2397 
2398  [DllImport("PFCImageFile")]
2399  static private extern unsafe int PFCImageFile_get_width(IntPtr ptr);
2400 
2401  [DllImport("PFCImageFile")]
2402  static private extern unsafe int PFCImageFile_get_height(IntPtr ptr);
2403 
2404  [DllImport("PFCImageFile")]
2405  static private extern unsafe int PFCImageFile_get_bytes_per_pixel(IntPtr ptr);
2406 
2407  [DllImport("PFCImageFile")]
2408  static private extern unsafe int PFCImageFile_get_stride(IntPtr ptr);
2409 
2410  [DllImport("PFCImageFile")]
2411  static private extern unsafe bool PFCImageFile_get_sourceSRGB(IntPtr ptr);
2412 
2413  [DllImport("PFCImageFile")]
2414  static private extern unsafe int PFCImageFile_ExpandImageBuffer(IntPtr ptr, byte* buffer, long size, int type, bool bConvertToSRGB, byte* iccFolderPath);
2415 
2416  [DllImport("PFCImageFile")]
2417  static private extern unsafe int PFCImageFile_CompressImageBuffer(IntPtr ptr, byte** destination, int type, int jpegQuality, bool bConvertToOriginalColorSpace, bool bEmbedOriginalMetadata);
2418 
2419  [DllImport("PFCImageFile")]
2420  static private extern unsafe int deleteBuffer(byte* buffer);
2421 #endif
2422 
2423 #if ADAPTER32BIT
2424  [DllImport("PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2425  static private extern unsafe IntPtr create_PFCImageFile();
2426 
2427  [DllImport("PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2428  static private extern void delete_PFCImageFile(IntPtr o);
2429 
2430  [DllImport("PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2431  static private extern unsafe int PFCImageFile_LoadImageFile(IntPtr o, byte* filename, bool bConvertToSRGB, byte* iccFolderPath);
2432 
2433  [DllImport("PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2434  static private extern unsafe int PFCImageFile_LoadImageFileType(IntPtr o, byte* filename, int type, bool bConvertToSRGB, byte* iccFolderPath);
2435 
2436  [DllImport("PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2437  static private extern unsafe bool PFCImageFile_SaveImageFile(IntPtr ptr, byte* filename, int jpegQuality, bool bConvertToOriginalColorSpace, bool bEmbedOriginalMetadata);
2438 
2439  [DllImport("PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2440  static private extern unsafe bool PFCImageFile_SaveImageFileType(IntPtr ptr, byte* filename, int type, int jpegQuality, bool bConvertToOriginalColorSpace, bool bEmbedOriginalMetadata);
2441 
2442  [DllImport("PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2443  static private extern unsafe void PFCImageFile_AllocBuffer(IntPtr ptr, int width, int height, int bytes_per_pixel, int stride);
2444 
2445  [DllImport("PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2446  static private extern unsafe int PFCImageFile_pfcImageFormat(IntPtr ptr);
2447 
2448  [DllImport("PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2449  static private extern unsafe int PFCImageFile_exifOrientation(IntPtr ptr);
2450 
2451  [DllImport("PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2452  static private extern unsafe byte* PFCImageFile_get_raw_image(IntPtr ptr);
2453 
2454  [DllImport("PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2455  static private extern unsafe int PFCImageFile_get_width(IntPtr ptr);
2456 
2457  [DllImport("PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2458  static private extern unsafe int PFCImageFile_get_height(IntPtr ptr);
2459 
2460  [DllImport("PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2461  static private extern unsafe int PFCImageFile_get_bytes_per_pixel(IntPtr ptr);
2462 
2463  [DllImport("PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2464  static private extern unsafe int PFCImageFile_get_stride(IntPtr ptr);
2465 
2466  [DllImport("PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2467  static private extern unsafe bool PFCImageFile_get_sourceSRGB(IntPtr ptr);
2468 
2469  [DllImport("PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2470  static private extern unsafe int PFCImageFile_ExpandImageBuffer(IntPtr ptr, byte* buffer, long size, int type, bool bConvertToSRGB, byte* iccFolderPath);
2471 
2472  [DllImport("PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2473  static private extern unsafe int PFCImageFile_CompressImageBuffer(IntPtr ptr, byte** destination, int type, int jpegQuality, bool bConvertToOriginalColorSpace, bool bEmbedOriginalMetadata);
2474 
2475  [DllImport("PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2476  static private extern unsafe int deleteBuffer(byte* buffer);
2477 #endif
2478  }
2479 }
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.
bool bDCF
Set to true to enable Digital Color Fidelity. Recommended value is FALSE.
Error reading image data.
Skip pre-calculations on Abnormal Tint Correction during Core pre-calculations.
int iTeethLevel
Teeth whitening level. Range 0 to 100.
Process aborted because of insufficient memory.
PFCPIXELFORMAT format
Defines byte order of input buffer.
int iFinishExposure
Exposure correction amount.
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.
Full res 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.
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.
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.
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
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.
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.
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.
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.
Warning. e.g. 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.
Same as iAuto 2019 but also with Red Eye Correction 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.
Full res image (pImage) is missing.
PFCNR_STATUS
Enumeration defining status of Noise Removal pre-calculation.
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.
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.
General error.
DCFMODE
Enumeration defining DCF analysis mode.
Fine tuned for Asian skin tone.
Operation cancelled by user.
unsafe ADPTRRETURNCODE Calc(ref Bitmap bm, ref Bitmap bmds, PFCFEATURE feature)
Overload method for precalc analysis.
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.
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.
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.
Pointer pEngine is NULL.
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.
Image side dimension smaller than 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.
Monolith source image.
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.
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...
Pointer pImage is NULL.
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.
Error in settings.
bool bLipSharpen
Set to TRUE to enable lip sharpening.
TINTCORRECTION
Enumeration defining different abnormal tint analysis mode.
unsafe ADPTRRETURNCODE Calc(ref Bitmap bm, PFCFEATURE feature, int ISO, string CameraModel)
Overload method for precalc analysis.
unsigned char * data
Pointer pointing to the first byte of image data buffer.
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.
Process cancelled.
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.
unsafe ADPTRRETURNCODE Calc(ref PFCImageFile imgfile, PFCFEATURE feature, int ISO, string CameraModel)
Overload method for precalc analysis.
float fSharpenScale
Sharpening intensity. This value controls how much sharpening to be applied. Range 0...
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.
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.
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.
Face beautification feature not available.
Structure encapsulating Red Eye Correction parameters.
PerfectlyClear(string path, string licenseCode="")
Class constructor.
Full res 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.
Full res 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.
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.
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.
New iAuto for even better image corrections - this is the default Preset and a great starting point f...
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.