9 using System.Drawing.Drawing2D;
10 using System.Diagnostics;
11 using System.Drawing.Imaging;
13 using System.Runtime.InteropServices;
18 [StructLayout(LayoutKind.Sequential, Pack = 1)]
26 [StructLayout(LayoutKind.Sequential, Pack = 1)]
65 [StructLayout(LayoutKind.Sequential, Pack = 1)]
87 public IntPtr pWrapped;
91 pWrapped = IntPtr.Zero;
426 [StructLayout(LayoutKind.Sequential, Pack = 1)]
558 public enum PFCCORE_MASK_TYPE
565 PFCCORE_MASK_ROUNDRECT
583 [MarshalAsAttribute(UnmanagedType.I1)]
587 [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
591 [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 33)]
594 public byte strength;
598 [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
602 [MarshalAsAttribute(UnmanagedType.I1)]
641 [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
656 [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
684 [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
688 [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 250)]
691 public int profileUUID;
756 int m_loadedAiEngineFeatures;
761 private bool releaseProtection =
false;
798 #if PROTECTION_ENABLED
801 byte* pLicpath =
null;
802 if (!String.IsNullOrEmpty(path))
804 pLicpath = GetCharBuffer(path);
807 byte* pLicenseCode =
null;
808 if (!String.IsNullOrEmpty(licenseCode)) {
809 pLicenseCode = GetCharBuffer(licenseCode);
812 int status = PFC_SetProtectionPath(pLicpath, pLicenseCode);
814 FreeCharBuffer(pLicpath);
815 FreeCharBuffer(pLicenseCode);
822 Trace.WriteLine(ex.Message);
837 PFC_ReleaseProtectionPath();
851 m_loadedAiEngineFeatures = 0;
855 m_pEngine = PFC_CreateEngine();
856 if (m_pEngine !=
null)
858 LastStatus.Status = (int)(*m_pEngine).status;
861 m_pAiEngine = PFC_CreateEngine();
862 if (m_pAiEngine !=
null)
864 LastAiStatus.Status = (int)(*m_pAiEngine).status;
869 Trace.WriteLine(ex.Message);
872 PFC_SetParam(ref m_Param,
PFCPRESETID.PRESET_IAUTO_PEOPLE);
889 #if PROTECTION_ENABLED
892 byte* pLicpath =
null;
893 if (!String.IsNullOrEmpty(path))
895 pLicpath = GetCharBuffer(path);
898 byte* pLicenseCode =
null;
899 if (!String.IsNullOrEmpty(licenseCode)) {
900 pLicenseCode = GetCharBuffer(licenseCode);
903 int status = PFC_SetProtectionPath(pLicpath, pLicenseCode);
904 releaseProtection =
true;
906 FreeCharBuffer(pLicpath);
907 FreeCharBuffer(pLicenseCode);
912 Trace.WriteLine(ex.Message);
917 m_pEngine = PFC_CreateEngine();
918 if (m_pEngine !=
null)
920 LastStatus.Status = (int)(*m_pEngine).status;
923 m_pAiEngine = PFC_CreateEngine();
924 if (m_pAiEngine !=
null)
926 LastAiStatus.Status = (int)(*m_pAiEngine).status;
931 Trace.WriteLine(ex.Message);
934 PFC_SetParam(ref m_Param,
PFCPRESETID.PRESET_IAUTO_21);
939 #if PROTECTION_ENABLED
940 if(releaseProtection) {
986 return Calc(ref imgfile, feature, -1,
null);
997 return Calc(ref bm, feature, -1,
null);
1009 return Calc(ref bm, ref bmds, feature, -1,
null);
1023 BitmapData bd =
null;
1025 bd = LockBitmapData(ref bm);
1026 if (bd.PixelFormat != PixelFormat.Format24bppRgb &&
1027 bd.PixelFormat != PixelFormat.Format32bppArgb &&
1028 bd.PixelFormat != PixelFormat.Format48bppRgb &&
1029 bd.PixelFormat != PixelFormat.Format64bppArgb)
1031 ReleaseBitmapData(ref bm, ref bd);
1034 pBase = (Byte*)bd.Scan0.ToPointer();
1037 im.
width = bd.Width;
1040 switch (bd.PixelFormat)
1048 im.
data = (
void*)pBase;
1050 if (m_pProfile !=
null)
1051 PFC_ReleaseProfile(m_pProfile);
1053 byte* pModel =
null;
1054 if (CameraModel !=
null)
1056 pModel = GetCharBuffer(CameraModel);
1058 m_pProfile = PFC_Calc(&im,
null, m_pEngine, feature, ISO, pModel,
null,
null, (
int)rejectOption, m_pAiEngine);
1060 FreeCharBuffer(pModel);
1062 ReleaseBitmapData(ref bm, ref bd);
1064 LastStatus.NR_Status = (*m_pProfile).NR_Status;
1065 LastStatus.CORE_Status = (*m_pProfile).CORE_Status;
1066 LastStatus.FB_Status = (*m_pProfile).FB_Status;
1067 LastStatus.RE_Status = (*m_pProfile).RE_Status;
1068 LastStatus.Status = (*m_pProfile).Status;
1085 im.
width = imgfile.width();
1086 im.
height = imgfile.height();
1087 im.
stride = imgfile.stride();
1089 im.
data = (
void*)imgfile.raw_image();
1091 if (m_pProfile !=
null)
1092 PFC_ReleaseProfile(m_pProfile);
1094 byte* pModel =
null;
1095 if (CameraModel !=
null)
1097 pModel = GetCharBuffer(CameraModel);
1099 m_pProfile = PFC_Calc(&im,
null, m_pEngine, feature, ISO, pModel,
null,
null, (
int)rejectOption, m_pAiEngine);
1101 FreeCharBuffer(pModel);
1103 LastStatus.NR_Status = (*m_pProfile).NR_Status;
1104 LastStatus.CORE_Status = (*m_pProfile).CORE_Status;
1105 LastStatus.FB_Status = (*m_pProfile).FB_Status;
1106 LastStatus.RE_Status = (*m_pProfile).RE_Status;
1107 LastStatus.Status = (*m_pProfile).Status;
1123 BitmapData bd =
null;
1125 bd = LockBitmapData(ref bm);
1126 if (bd.PixelFormat != PixelFormat.Format24bppRgb &&
1127 bd.PixelFormat != PixelFormat.Format32bppArgb &&
1128 bd.PixelFormat != PixelFormat.Format48bppRgb &&
1129 bd.PixelFormat != PixelFormat.Format64bppArgb)
1131 ReleaseBitmapData(ref bm, ref bd);
1134 pBase = (Byte*)bd.Scan0.ToPointer();
1137 im.
width = bd.Width;
1140 switch (bd.PixelFormat)
1148 im.
data = (
void*)pBase;
1150 BitmapData bdds =
null;
1151 bdds = LockBitmapData(ref bmds);
1152 if (bdds.PixelFormat != PixelFormat.Format24bppRgb &&
1153 bdds.PixelFormat != PixelFormat.Format32bppArgb &&
1154 bdds.PixelFormat != PixelFormat.Format48bppRgb &&
1155 bdds.PixelFormat != PixelFormat.Format64bppArgb)
1157 ReleaseBitmapData(ref bmds, ref bdds);
1160 pBase = (Byte*)bdds.Scan0.ToPointer();
1163 imds.
width = bdds.Width;
1164 imds.
height = bdds.Height;
1165 imds.
stride = bdds.Stride;
1166 switch (bdds.PixelFormat)
1170 case PixelFormat.Format32bppArgb: imds.
format =
PFCPIXELFORMAT.PFC_PixelFormat32bppARGB;
break;
1172 case PixelFormat.Format64bppArgb: imds.
format =
PFCPIXELFORMAT.PFC_PixelFormat64bppARGB;
break;
1174 imds.
data = (
void*)pBase;
1176 if (m_pProfile !=
null)
1177 PFC_ReleaseProfile(m_pProfile);
1179 byte* pModel =
null;
1180 if (CameraModel !=
null)
1182 pModel = GetCharBuffer(CameraModel);
1184 m_pProfile = PFC_Calc(&im, &imds, m_pEngine, feature, ISO, pModel,
null,
null, 1, m_pAiEngine);
1186 FreeCharBuffer(pModel);
1188 ReleaseBitmapData(ref bm, ref bd);
1189 ReleaseBitmapData(ref bmds, ref bdds);
1191 LastStatus.NR_Status = (*m_pProfile).NR_Status;
1192 LastStatus.CORE_Status = (*m_pProfile).CORE_Status;
1193 LastStatus.FB_Status = (*m_pProfile).FB_Status;
1194 LastStatus.RE_Status = (*m_pProfile).RE_Status;
1195 LastStatus.Status = (*m_pProfile).Status;
1208 return Apply(ref bm, 100);
1218 return Apply(ref imgfile, 100);
1229 if (m_pProfile ==
null)
1234 BitmapData bd =
null;
1236 bd = LockBitmapData(ref bm);
1237 if (bd.PixelFormat != PixelFormat.Format24bppRgb &&
1238 bd.PixelFormat != PixelFormat.Format32bppArgb &&
1239 bd.PixelFormat != PixelFormat.Format48bppRgb &&
1240 bd.PixelFormat != PixelFormat.Format64bppArgb)
1242 ReleaseBitmapData(ref bm, ref bd);
1245 pBase = (Byte*)bd.Scan0.ToPointer();
1248 im.
width = bd.Width;
1251 switch (bd.PixelFormat)
1259 im.
data = (
void*)pBase;
1261 PFCAPPLYSTATUS ret = PFC_Apply(&im, m_pEngine, m_pProfile, ref m_Param,
null, iOpacity,
null);
1265 int code = (int)ret;
1267 LastStatus.NR_Status = (
PFCNR_STATUS)(code & 0x000000FF);
1268 LastStatus.CORE_Status = (
PFCCORE_STATUS)((code >> 8) & 0x000000FF);
1269 LastStatus.FB_Status = (
PFCFB_STATUS)((code >> 16) & 0x000000FF);
1270 LastStatus.RE_Status = (
PFCRE_STATUS)((code >> 24) & 0x000000FF);
1271 LastStatus.Status = code;
1274 ReleaseBitmapData(ref bm, ref bd);
1286 if (m_pProfile ==
null)
1292 im.
width = imgfile.width();
1293 im.
height = imgfile.height();
1294 im.
stride = imgfile.stride();
1296 im.
data = (
void*)imgfile.raw_image();
1298 PFCAPPLYSTATUS ret = PFC_Apply(&im, m_pEngine, m_pProfile, ref m_Param,
null, iOpacity,
null);
1302 int code = (int)ret;
1304 LastStatus.NR_Status = (
PFCNR_STATUS)(code & 0x000000FF);
1305 LastStatus.CORE_Status = (
PFCCORE_STATUS)((code >> 8) & 0x000000FF);
1306 LastStatus.FB_Status = (
PFCFB_STATUS)((code >> 16) & 0x000000FF);
1307 LastStatus.RE_Status = (
PFCRE_STATUS)((code >> 24) & 0x000000FF);
1308 LastStatus.Status = code;
1369 return AutoCorrect(ref bm, ref bmds, -1,
null,
false);
1380 public int AutoCorrect(ref Bitmap bm,
int ISO,
string CameraModel,
bool bFastFAE)
1386 int detectedCategory =
GetScene(&version);
1387 if (detectedCategory >= 0) {
1390 m_Param = categoryParam;
1446 int retInt = (((((((int)retRE << 8) | (int)retFB) << 8) | (
int)retCORE) << 8) | (int)retNR);
1470 int detectedCategory =
GetScene(&version);
1471 if (detectedCategory >= 0) {
1474 m_Param = categoryParam;
1530 int retInt = (((((((int)retRE << 8) | (int)retFB) << 8) | (
int)retCORE) << 8) | (int)retNR);
1549 public int AutoCorrect(ref Bitmap bm, ref Bitmap bmds,
int ISO,
string CameraModel,
bool bFastFAE)
1555 int detectedCategory =
GetScene(&version);
1556 if (detectedCategory >= 0) {
1559 m_Param = categoryParam;
1615 int retInt = (((((((int)retRE << 8) | (int)retFB) << 8) | (
int)retCORE) << 8) | (int)retNR);
1638 return retCode-1000;
1654 return retCode - 1000;
1664 public int AutoCorrect(ref Bitmap bm, ref Bitmap bmds,
string pathPreset)
1669 return AutoCorrect(ref bm, ref bmds, -1,
null,
false);
1671 return retCode - 1000;
1683 public int AutoCorrect(ref Bitmap bm,
string pathPreset,
int ISO,
string CameraModel,
bool bFastFAE)
1688 return AutoCorrect(ref bm, ISO, CameraModel, bFastFAE);
1690 return retCode - 1000;
1707 return AutoCorrect(ref imgfile, ISO, CameraModel, bFastFAE);
1709 return retCode - 1000;
1722 public int AutoCorrect(ref Bitmap bm, ref Bitmap bmds,
string pathPreset,
int ISO,
string CameraModel,
bool bFastFAE)
1727 return AutoCorrect(ref bm, ref bmds, ISO, CameraModel, bFastFAE);
1729 return retCode - 1000;
1738 PFC_SetParam(ref m_Param,
id);
1764 byte* presetpath =
null;
1767 presetpath = GetCharBuffer(path);
1770 int status = PFC_ReadPresets(ref m_Param, presetpath);
1774 catch (Exception ex)
1776 Trace.WriteLine(ex.Message);
1799 long len = fs.Length;
1800 byte[] buffer =
new byte[len + 1];
1801 int size = (int)len;
1802 fs.Read(buffer, 0, size);
1804 byte* b = GetCharBuffer(buffer);
1809 int status = PFC_ReadPresetsFromStream(ref m_Param, b);
1813 catch (Exception ex)
1815 Trace.WriteLine(ex.Message);
1841 long len = fs.Length;
1842 byte[] buffer =
new byte[len + 1];
1843 int size = (int)len;
1844 fs.Read(buffer, 0, size);
1846 byte* b = GetCharBuffer(buffer);
1847 int status = PFC_LoadScenePresetsFromStream(m_pAiEngine, b, size, groupUUID, arrProfileUUID, arrProfileUUIDLen);
1851 catch (Exception ex)
1853 Trace.WriteLine(ex.Message);
1864 return PFC_HasFaceBeautification(m_pEngine);
1874 return PFC_FBFaceCount(m_pProfile);
1888 bool ret = PFC_GetFaceInfo(m_pProfile, &fi, index);
1907 return PFC_AbnormalTintDetected(m_pProfile, eTintMethod);
1917 PFC_ApplyStrengthToParam(ref m_Param, strength);
1920 protected BitmapData LockBitmapData(ref Bitmap bm)
1922 GraphicsUnit unit = GraphicsUnit.Pixel;
1923 RectangleF boundsF = bm.GetBounds(ref unit);
1924 Rectangle bounds =
new Rectangle((
int)boundsF.X,
1927 (
int)boundsF.Height);
1929 BitmapData bitmapData =
1930 bm.LockBits(bounds, ImageLockMode.ReadWrite, bm.PixelFormat);
1934 protected void ReleaseBitmapData(ref Bitmap bm, ref BitmapData bitmapData)
1936 bm.UnlockBits(bitmapData);
1939 protected Bitmap DupBitmap(ref Bitmap bm)
1941 PerfectlyClearImageTransfer tr, tr1;
1943 GraphicsUnit unit = GraphicsUnit.Pixel;
1944 RectangleF boundsF = bm.GetBounds(ref unit);
1945 Rectangle bounds =
new Rectangle((
int)boundsF.X,
1948 (
int)boundsF.Height);
1949 BitmapData bd = bm.LockBits(bounds, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
1950 Bitmap bm1 =
new Bitmap(bd.Width, bd.Height, PixelFormat.Format24bppRgb);
1951 BitmapData bd1 = LockBitmapData(ref bm1);
1952 pBase = (Byte*)bd.Scan0.ToPointer();
1953 tr.columnBytes = (bd.PixelFormat == PixelFormat.Format24bppRgb) ? 3 : 4;
1954 tr.rowBytes = bd.Stride;
1955 tr.height = bd.Height;
1956 tr.width = bd.Width;
1957 tr.data1 = (int)(pBase + 2);
1958 tr.data2 = (int)(pBase + 1);
1959 tr.data3 = (int)pBase;
1960 pBase = (Byte*)bd1.Scan0.ToPointer();
1961 tr1.columnBytes = (bd1.PixelFormat == PixelFormat.Format24bppRgb) ? 3 : 4;
1962 tr1.rowBytes = bd1.Stride;
1963 tr1.height = bd1.Height;
1964 tr1.width = bd1.Width;
1965 tr1.data1 = (int)(pBase + 2);
1966 tr1.data2 = (int)(pBase + 1);
1967 tr1.data3 = (int)pBase;
1968 for (
int i = 0; i < tr.height; i++)
1970 for (
int j = 0; j < tr.width; j++)
1972 ((Byte*)tr1.data1)[j * tr1.columnBytes] = ((Byte*)tr.data1)[j * tr.columnBytes];
1973 ((Byte*)tr1.data2)[j * tr1.columnBytes] = ((Byte*)tr.data2)[j * tr.columnBytes];
1974 ((Byte*)tr1.data3)[j * tr1.columnBytes] = ((Byte*)tr.data3)[j * tr.columnBytes];
1976 tr.data1 += (int)tr.rowBytes;
1977 tr.data2 += (
int)tr.rowBytes;
1978 tr.data3 += (int)tr.rowBytes;
1979 tr1.data1 += (
int)tr1.rowBytes;
1980 tr1.data2 += (int)tr1.rowBytes;
1981 tr1.data3 += (
int)tr1.rowBytes;
1983 ReleaseBitmapData(ref bm1, ref bd1);
1984 ReleaseBitmapData(ref bm, ref bd);
1988 protected Bitmap BW2RGB(ref Bitmap bm)
1991 Byte* pBase1 =
null;
1992 GraphicsUnit unit = GraphicsUnit.Pixel;
1993 RectangleF boundsF = bm.GetBounds(ref unit);
1994 Rectangle bounds =
new Rectangle((
int)boundsF.X,
1997 (
int)boundsF.Height);
1998 BitmapData bd = bm.LockBits(bounds, ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);
1999 Bitmap bm1 =
new Bitmap(bd.Width, bd.Height, PixelFormat.Format24bppRgb);
2000 BitmapData bd1 = LockBitmapData(ref bm1);
2001 pBase = (Byte*)bd.Scan0.ToPointer();
2002 pBase1 = (Byte*)bd1.Scan0.ToPointer();
2003 for (
int i = 0; i < bd.Height; i++)
2005 for (
int j = 0; j < bd.Width; j++)
2007 pBase1[j * 3] = pBase[j];
2008 pBase1[j * 3 + 1] = pBase[j];
2009 pBase1[j * 3 + 2] = pBase[j];
2012 pBase1 += bd1.Stride;
2014 ReleaseBitmapData(ref bm1, ref bd1);
2015 ReleaseBitmapData(ref bm, ref bd);
2029 Bitmap myBitmap =
new Bitmap(filename);
2030 if ((myBitmap.Flags & (
int)ImageFlags.ColorSpaceYcck) != 0)
2032 bm = DupBitmap(ref myBitmap);
2037 if (myBitmap.PixelFormat == PixelFormat.Format8bppIndexed)
2039 bm = BW2RGB(ref myBitmap);
2050 protected Bitmap GetStatImage(ref Bitmap bm,
int iMaxDimension)
2053 bool bNeedResize =
true;
2060 if (w <= iMaxDimension)
2061 bNeedResize =
false;
2067 if (h <= iMaxDimension)
2068 bNeedResize =
false;
2079 Bitmap bmds =
new Bitmap(w1, h1, bm.PixelFormat);
2081 using (Graphics gr = Graphics.FromImage(bmds))
2083 gr.SmoothingMode = SmoothingMode.HighQuality;
2084 gr.InterpolationMode = InterpolationMode.HighQualityBicubic;
2085 gr.PixelOffsetMode = PixelOffsetMode.HighQuality;
2086 gr.DrawImage(bm,
new Rectangle(0, 0, w1, h1));
2094 Bitmap bmds = (Bitmap)bm.Clone();
2120 IntPtr wrapped = rect.pWrapped;
2121 IntPtr pRect = (IntPtr) PFC_EnumFAEFaceRect(m_pProfile, (
void*)wrapped);
2123 if (pRect != IntPtr.Zero) {
2126 rect.pWrapped = (IntPtr)pRect;
2130 rect.pWrapped = IntPtr.Zero;
2140 return PFC_FAEFaceCount(m_pProfile);
2152 if (binPath !=
null)
2154 path = GetCharBuffer(binPath);
2156 int result = PFC_LoadAIEngine(m_pAiEngine, aifeatures, path);
2157 m_loadedAiEngineFeatures = result;
2160 PFC_LoadAIEngine(m_pEngine,
PFCAIFEATURE.AI_CORRECTIONS, path);
2163 FreeCharBuffer(path);
2183 public unsafe
int LoadScenePresets(
string filePath,
int groupUUID = 0,
int* arrProfileUUID =
null,
int arrProfileUUIDLen = 0)
2186 if (filePath !=
null)
2188 path = GetCharBuffer(filePath);
2190 int result = PFC_LoadScenePresets(m_pAiEngine, path, groupUUID, arrProfileUUID, arrProfileUUIDLen);
2191 FreeCharBuffer(path);
2204 return PFC_ReadScenePreset(ref param, m_pAiEngine, scene);
2215 return PFC_GetScene(m_pProfile, version);
2228 return PFC_GetSceneDetectionEngineInfo(m_pAiEngine, groupUUID, arrProfileUUID, arrProfileUUIDLen);
2237 if (dirPath !=
null)
2239 path = GetCharBuffer(dirPath);
2241 PFC_SetAddonPath(path);
2242 FreeCharBuffer(path);
2263 bool result = PFC_GetSceneDescription(m_pAiEngine, index, ref sceneDescription);
2276 if (m_pEngine ==
null)
2279 return PFC_SetSingleThreadedEngine(m_pEngine, bSingleThreaded);
2282 public void Dispose()
2285 GC.SuppressFinalize(
this);
2288 protected virtual void Dispose(
bool disposing)
2294 if (m_pProfile !=
null)
2296 PFC_ReleaseProfile(m_pProfile);
2300 if (m_pEngine !=
null)
2302 PFC_DestroyEngine(m_pEngine);
2306 if (m_pAiEngine !=
null)
2308 PFC_DestroyEngine(m_pAiEngine);
2313 static protected byte* GetCharBuffer(
byte[] s)
2315 int i, iCount = s.Length;
2316 IntPtr _memory = IntPtr.Zero;
2317 _memory = Marshal.AllocHGlobal(iCount + 1);
2318 byte* p = (
byte*)_memory;
2319 for (i = 0; i < iCount; i++)
2328 static protected byte* GetCharBuffer(
string s)
2330 int i, iCount = s.Length;
2331 IntPtr _memory = IntPtr.Zero;
2332 _memory = Marshal.AllocHGlobal(iCount + 1);
2333 byte* p = (
byte*)_memory;
2334 for (i = 0; i < iCount; i++)
2343 static protected void FreeCharBuffer(
byte* p)
2345 IntPtr _memory = (IntPtr)p;
2346 Marshal.FreeHGlobal(_memory);
2350 [DllImport(
"PerfectlyClearPro")]
2351 static extern int PFC_SetProtectionPath(
byte* path,
byte* licenseCode);
2353 [DllImport(
"PerfectlyClearPro")]
2354 static extern void PFC_ReleaseProtectionPath();
2356 [DllImport(
"PerfectlyClearPro")]
2357 static extern PFCENGINE* PFC_CreateEngine();
2359 [DllImport(
"PerfectlyClearPro")]
2360 static extern void PFC_DestroyEngine(
PFCENGINE* p);
2362 [DllImport(
"PerfectlyClearPro")]
2365 [DllImport(
"PerfectlyClearPro")]
2366 static extern int PFC_ReadPresets(ref
PFCPARAM param,
byte* filename);
2368 [DllImport(
"PerfectlyClearPro")]
2369 static extern int PFC_ReadPresetsFromStream(ref
PFCPARAM param,
byte* s);
2371 [DllImport(
"PerfectlyClearPro")]
2374 [DllImport(
"PerfectlyClearPro")]
2375 static extern void PFC_ReleaseProfile(
void* pProfile);
2377 [DllImport(
"PerfectlyClearPro")]
2380 [DllImport(
"PerfectlyClearPro")]
2381 static extern bool PFC_HasFaceBeautification(
PFCENGINE* pEngine);
2383 [DllImport(
"PerfectlyClearPro")]
2384 static extern int PFC_FBFaceCount(
void* pImageProfile);
2386 [DllImport(
"PerfectlyClearPro")]
2387 static extern bool PFC_GetFaceInfo(
void* pImageProfile, PFCFBFACEINFO1* pFace,
int index);
2389 [DllImport(
"PerfectlyClearPro")]
2390 static extern bool PFC_AbnormalTintDetected(
void* pImageProfile,
TINTCORRECTION eTintMethod);
2392 [DllImport(
"PerfectlyClearPro")]
2393 static extern void PFC_ApplyStrengthToParam(ref
PFCPARAM param,
int strength);
2395 [DllImport(
"PerfectlyClearPro")]
2396 static extern void* PFC_EnumFAEFaceRect(
void *pImageProfile,
void* p);
2398 [DllImport(
"PerfectlyClearPro")]
2399 static extern int PFC_FAEFaceCount(
void* pImageProfile);
2401 [DllImport(
"PerfectlyClearPro")]
2404 [DllImport(
"PerfectlyClearPro")]
2405 static extern int PFC_LoadScenePresets(
PFCENGINE* pEngine,
byte *filePath,
int groupUUID,
int *arrProfileUUID,
int arrProfileUUIDLen);
2407 [DllImport(
"PerfectlyClearPro")]
2408 static extern int PFC_ReadScenePreset(ref
PFCPARAM param,
PFCENGINE *pEngineAI,
int scene);
2410 [DllImport(
"PerfectlyClearPro")]
2411 static extern int PFC_GetScene(
void* precalc,
int *version);
2413 [DllImport(
"PerfectlyClearPro")]
2414 static extern bool PFC_GetSceneDetectionEngineInfo(
PFCENGINE* pEngine,
int* groupUUID,
int* arrProfileUUID,
int *arrProfileUUIDLen);
2416 [DllImport(
"PerfectlyClearPro")]
2417 static extern void PFC_SetAddonPath(
byte* path);
2419 [DllImport(
"PerfectlyClearPro")]
2422 [DllImport(
"PerfectlyClearPro")]
2423 static extern int PFC_LoadScenePresetsFromStream(
PFCENGINE* pEngine,
byte *buf,
int lenBuf,
int groupUUID,
int *arrProfileUUID,
int arrProfileUUIDLen);
2425 [DllImport(
"PerfectlyClearPro")]
2426 static extern bool PFC_SetSingleThreadedEngine(
PFCENGINE* pEngine,
bool bSingleThreaded);
2431 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2432 static extern int PFC_SetProtectionPath(
byte* path,
byte* licenseCode);
2434 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2435 static extern void PFC_ReleaseProtectionPath();
2437 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2438 static extern PFCENGINE* PFC_CreateEngine();
2440 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2441 static extern void PFC_DestroyEngine(
PFCENGINE* p);
2443 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2446 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2447 static extern int PFC_ReadPresets(ref
PFCPARAM param,
byte* filename);
2449 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2450 static extern int PFC_ReadPresetsFromStream(ref
PFCPARAM param,
byte* s);
2452 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2455 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2456 static extern void PFC_ReleaseProfile(
void* pProfile);
2458 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2461 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2462 static extern bool PFC_HasFaceBeautification(
PFCENGINE* pEngine);
2464 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2465 static extern int PFC_FBFaceCount(
void* pImageProfile);
2467 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2468 static extern bool PFC_GetFaceInfo(
void* pImageProfile, PFCFBFACEINFO1* pFace,
int index);
2470 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2471 static extern bool PFC_AbnormalTintDetected(
void* pImageProfile,
TINTCORRECTION eTintMethod);
2473 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2474 static extern void PFC_ApplyStrengthToParam(ref
PFCPARAM param,
int strength);
2476 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2477 static extern void* PFC_EnumFAEFaceRect(
void *pImageProfile,
void* p);
2479 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2480 static extern int PFC_FAEFaceCount(
void* pImageProfile);
2482 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2485 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2486 static extern int PFC_LoadScenePresets(
PFCENGINE* pEngine,
byte *filePath,
int groupUUID,
int *arrProfileUUID,
int arrProfileUUIDLen);
2488 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2489 static extern int PFC_ReadScenePreset(ref
PFCPARAM param,
PFCENGINE *pEngineAI,
int scene);
2491 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2492 static extern int PFC_GetScene(
void* precalc,
int *version);
2494 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2495 static extern bool PFC_GetSceneDetectionEngineInfo(
PFCENGINE* pEngine,
int* groupUUID,
int* arrProfileUUID,
int* arrProfileUUIDLen);
2497 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2498 static extern void PFC_SetAddonPath(
byte* path);
2500 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2503 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2504 static extern int PFC_LoadScenePresetsFromStream(
PFCENGINE* pEngine,
byte *buf,
int lenBuf,
int groupUUID,
int *arrProfileUUID,
int arrProfileUUIDLen);
2506 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2507 static extern bool PFC_SetSingleThreadedEngine(
PFCENGINE* pEngine,
bool bSingleThreaded);
2550 private IntPtr m_pNativeObject;
2555 m_pNativeObject = create_PFCImageFile();
2558 public void Dispose()
2563 protected virtual void Dispose(
bool bDisposing)
2565 if (this.m_pNativeObject != IntPtr.Zero)
2567 delete_PFCImageFile(m_pNativeObject);
2568 m_pNativeObject = IntPtr.Zero;
2575 GC.SuppressFinalize(
this);
2609 if (filename ==
null)
2614 byte* pFilename = GetCharBuffer(filename);
2616 byte* pIccFolderPath =
null;
2617 if (iccFolderPath !=
null)
2619 pIccFolderPath = GetCharBuffer(iccFolderPath);
2622 int result = PFCImageFile_LoadImageFile(m_pNativeObject, pFilename, bConvertToSRGB, pIccFolderPath);
2624 FreeCharBuffer(pFilename);
2625 FreeCharBuffer(pIccFolderPath);
2640 if (filename ==
null)
2645 byte* pFilename = GetCharBuffer(filename);
2647 byte* pIccFolderPath =
null;
2648 if (iccFolderPath !=
null)
2650 pIccFolderPath = GetCharBuffer(iccFolderPath);
2653 int result = PFCImageFile_LoadImageFileType(m_pNativeObject, pFilename, (
int)type, bConvertToSRGB, pIccFolderPath);
2655 FreeCharBuffer(pFilename);
2656 FreeCharBuffer(pIccFolderPath);
2668 public bool SaveImageFile(
string filename,
int jpegQuality = 92,
bool bConvertToOriginalColorSpace=
true,
bool bEmbedOriginalMetadata =
true)
2670 if (filename ==
null)
2675 byte* pFilename = GetCharBuffer(filename);
2677 bool result = PFCImageFile_SaveImageFile(m_pNativeObject, pFilename, jpegQuality, bConvertToOriginalColorSpace, bEmbedOriginalMetadata);
2679 FreeCharBuffer(pFilename);
2692 public bool SaveImageFile(
string filename,
PFC_FILETYPE type,
int jpegQuality = 92,
bool bConvertToOriginalColorSpace =
true,
bool bEmbedOriginalMetadata =
true)
2694 if (filename ==
null)
2699 byte* pFilename = GetCharBuffer(filename);
2701 bool result = PFCImageFile_SaveImageFileType(m_pNativeObject, pFilename, (
int)type, jpegQuality, bConvertToOriginalColorSpace, bEmbedOriginalMetadata);
2703 FreeCharBuffer(pFilename);
2708 public void AllocBuffer(
int width,
int height,
int bytes_per_pixel,
int stride)
2710 PFCImageFile_AllocBuffer(m_pNativeObject, width, height, bytes_per_pixel, stride);
2713 public int pfcImageFormat()
2715 return PFCImageFile_pfcImageFormat(m_pNativeObject);
2718 public int exifOrientation()
2720 return PFCImageFile_exifOrientation(m_pNativeObject);
2723 public byte* raw_image()
2725 return PFCImageFile_get_raw_image(m_pNativeObject);
2730 return PFCImageFile_get_width(m_pNativeObject);
2735 return PFCImageFile_get_height(m_pNativeObject);
2738 public int bytes_per_pixel()
2740 return PFCImageFile_get_bytes_per_pixel(m_pNativeObject);
2745 return PFCImageFile_get_stride(m_pNativeObject);
2748 public bool sourceSRGB()
2750 return PFCImageFile_get_sourceSRGB(m_pNativeObject);
2763 byte* buffer = GetByteBuffer(inStream.ToArray());
2764 byte* pIccFolderPath =
null;
2765 if (iccFolderPath !=
null)
2767 pIccFolderPath = GetCharBuffer(iccFolderPath);
2769 int result = PFCImageFile_ExpandImageBuffer(m_pNativeObject, buffer, inStream.Length, (
int)type, bConvertToSRGB, pIccFolderPath);
2770 FreeCharBuffer(pIccFolderPath);
2771 FreeByteBuffer(buffer);
2786 byte* compressedBuffer =
null;
2787 int length = PFCImageFile_CompressImageBuffer(m_pNativeObject, &compressedBuffer, (
int)type, jpegQuality, bConvertToOriginalColorSpace, bEmbedOriginalMetadata);
2788 if (length > 0 && compressedBuffer !=
null)
2790 byte[] result =
new byte[length];
2791 Marshal.Copy((IntPtr)(compressedBuffer), result, 0, length);
2792 deleteBuffer(compressedBuffer);
2795 MemoryStream stream =
new MemoryStream();
2796 stream.Write(result, 0, result.Length);
2799 return new MemoryStream();
2802 private static byte* GetCharBuffer(
string s)
2804 UTF8Encoding utf8 =
new UTF8Encoding();
2805 Byte[] encodedBytes = utf8.GetBytes(s);
2807 int i, iCount = encodedBytes.Length;
2808 IntPtr _memory = IntPtr.Zero;
2809 _memory = Marshal.AllocHGlobal(iCount + 1);
2810 byte* p = (
byte*)_memory;
2811 for (i = 0; i < iCount; i++)
2813 p[i] = encodedBytes[i];
2820 private static void FreeCharBuffer(
byte* p)
2822 IntPtr _memory = (IntPtr)p;
2823 Marshal.FreeHGlobal(_memory);
2826 private static byte* GetByteBuffer(
byte[] bytes)
2828 int length = bytes.Length;
2829 IntPtr p = Marshal.AllocHGlobal(length);
2830 Marshal.Copy(bytes, 0, p, length);
2834 private static void FreeByteBuffer(
byte* p)
2836 IntPtr _memory = (IntPtr)p;
2837 Marshal.FreeHGlobal(_memory);
2841 [DllImport(
"PFCImageFile")]
2842 static private extern unsafe IntPtr create_PFCImageFile();
2844 [DllImport(
"PFCImageFile")]
2845 static private extern void delete_PFCImageFile(IntPtr o);
2847 [DllImport(
"PFCImageFile")]
2848 static private extern unsafe
int PFCImageFile_LoadImageFile(IntPtr o,
byte* filename,
bool bConvertToSRGB,
byte* iccFolderPath);
2850 [DllImport(
"PFCImageFile")]
2851 static private extern unsafe
int PFCImageFile_LoadImageFileType(IntPtr o,
byte* filename,
int type,
bool bConvertToSRGB,
byte* iccFolderPath);
2853 [DllImport(
"PFCImageFile")]
2854 static private extern unsafe
bool PFCImageFile_SaveImageFile(IntPtr ptr,
byte* filename,
int jpegQuality,
bool bConvertToOriginalColorSpace,
bool bEmbedOriginalMetadata);
2856 [DllImport(
"PFCImageFile")]
2857 static private extern unsafe
bool PFCImageFile_SaveImageFileType(IntPtr ptr,
byte* filename,
int type,
int jpegQuality,
bool bConvertToOriginalColorSpace,
bool bEmbedOriginalMetadata);
2859 [DllImport(
"PFCImageFile")]
2860 static private extern unsafe
void PFCImageFile_AllocBuffer(IntPtr ptr,
int width,
int height,
int bytes_per_pixel,
int stride);
2862 [DllImport(
"PFCImageFile")]
2863 static private extern unsafe
int PFCImageFile_pfcImageFormat(IntPtr ptr);
2865 [DllImport(
"PFCImageFile")]
2866 static private extern unsafe
int PFCImageFile_exifOrientation(IntPtr ptr);
2868 [DllImport(
"PFCImageFile")]
2869 static private extern unsafe
byte* PFCImageFile_get_raw_image(IntPtr ptr);
2871 [DllImport(
"PFCImageFile")]
2872 static private extern unsafe
int PFCImageFile_get_width(IntPtr ptr);
2874 [DllImport(
"PFCImageFile")]
2875 static private extern unsafe
int PFCImageFile_get_height(IntPtr ptr);
2877 [DllImport(
"PFCImageFile")]
2878 static private extern unsafe
int PFCImageFile_get_bytes_per_pixel(IntPtr ptr);
2880 [DllImport(
"PFCImageFile")]
2881 static private extern unsafe
int PFCImageFile_get_stride(IntPtr ptr);
2883 [DllImport(
"PFCImageFile")]
2884 static private extern unsafe
bool PFCImageFile_get_sourceSRGB(IntPtr ptr);
2886 [DllImport(
"PFCImageFile")]
2887 static private extern unsafe
int PFCImageFile_ExpandImageBuffer(IntPtr ptr,
byte* buffer,
long size,
int type,
bool bConvertToSRGB,
byte* iccFolderPath);
2889 [DllImport(
"PFCImageFile")]
2890 static private extern unsafe
int PFCImageFile_CompressImageBuffer(IntPtr ptr,
byte** destination,
int type,
int jpegQuality,
bool bConvertToOriginalColorSpace,
bool bEmbedOriginalMetadata);
2892 [DllImport(
"PFCImageFile")]
2893 static private extern unsafe
int deleteBuffer(
byte* buffer);
2897 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2898 static private extern unsafe IntPtr create_PFCImageFile();
2900 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2901 static private extern void delete_PFCImageFile(IntPtr o);
2903 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2904 static private extern unsafe
int PFCImageFile_LoadImageFile(IntPtr o,
byte* filename,
bool bConvertToSRGB,
byte* iccFolderPath);
2906 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2907 static private extern unsafe
int PFCImageFile_LoadImageFileType(IntPtr o,
byte* filename,
int type,
bool bConvertToSRGB,
byte* iccFolderPath);
2909 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2910 static private extern unsafe
bool PFCImageFile_SaveImageFile(IntPtr ptr,
byte* filename,
int jpegQuality,
bool bConvertToOriginalColorSpace,
bool bEmbedOriginalMetadata);
2912 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2913 static private extern unsafe
bool PFCImageFile_SaveImageFileType(IntPtr ptr,
byte* filename,
int type,
int jpegQuality,
bool bConvertToOriginalColorSpace,
bool bEmbedOriginalMetadata);
2915 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2916 static private extern unsafe
void PFCImageFile_AllocBuffer(IntPtr ptr,
int width,
int height,
int bytes_per_pixel,
int stride);
2918 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2919 static private extern unsafe
int PFCImageFile_pfcImageFormat(IntPtr ptr);
2921 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2922 static private extern unsafe
int PFCImageFile_exifOrientation(IntPtr ptr);
2924 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2925 static private extern unsafe
byte* PFCImageFile_get_raw_image(IntPtr ptr);
2927 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2928 static private extern unsafe
int PFCImageFile_get_width(IntPtr ptr);
2930 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2931 static private extern unsafe
int PFCImageFile_get_height(IntPtr ptr);
2933 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2934 static private extern unsafe
int PFCImageFile_get_bytes_per_pixel(IntPtr ptr);
2936 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2937 static private extern unsafe
int PFCImageFile_get_stride(IntPtr ptr);
2939 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2940 static private extern unsafe
bool PFCImageFile_get_sourceSRGB(IntPtr ptr);
2942 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2943 static private extern unsafe
int PFCImageFile_ExpandImageBuffer(IntPtr ptr,
byte* buffer,
long size,
int type,
bool bConvertToSRGB,
byte* iccFolderPath);
2945 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2946 static private extern unsafe
int PFCImageFile_CompressImageBuffer(IntPtr ptr,
byte** destination,
int type,
int jpegQuality,
bool bConvertToOriginalColorSpace,
bool bEmbedOriginalMetadata);
2948 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2949 static private extern unsafe
int deleteBuffer(
byte* buffer);