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);
2267 public void Dispose()
2270 GC.SuppressFinalize(
this);
2273 protected virtual void Dispose(
bool disposing)
2279 if (m_pProfile !=
null)
2281 PFC_ReleaseProfile(m_pProfile);
2285 if (m_pEngine !=
null)
2287 PFC_DestroyEngine(m_pEngine);
2291 if (m_pAiEngine !=
null)
2293 PFC_DestroyEngine(m_pAiEngine);
2298 static protected byte* GetCharBuffer(
byte[] s)
2300 int i, iCount = s.Length;
2301 IntPtr _memory = IntPtr.Zero;
2302 _memory = Marshal.AllocHGlobal(iCount + 1);
2303 byte* p = (
byte*)_memory;
2304 for (i = 0; i < iCount; i++)
2313 static protected byte* GetCharBuffer(
string 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 void FreeCharBuffer(
byte* p)
2330 IntPtr _memory = (IntPtr)p;
2331 Marshal.FreeHGlobal(_memory);
2335 [DllImport(
"PerfectlyClearPro")]
2336 static extern int PFC_SetProtectionPath(
byte* path,
byte* licenseCode);
2338 [DllImport(
"PerfectlyClearPro")]
2339 static extern void PFC_ReleaseProtectionPath();
2341 [DllImport(
"PerfectlyClearPro")]
2342 static extern PFCENGINE* PFC_CreateEngine();
2344 [DllImport(
"PerfectlyClearPro")]
2345 static extern void PFC_DestroyEngine(
PFCENGINE* p);
2347 [DllImport(
"PerfectlyClearPro")]
2350 [DllImport(
"PerfectlyClearPro")]
2351 static extern int PFC_ReadPresets(ref
PFCPARAM param,
byte* filename);
2353 [DllImport(
"PerfectlyClearPro")]
2354 static extern int PFC_ReadPresetsFromStream(ref
PFCPARAM param,
byte* s);
2356 [DllImport(
"PerfectlyClearPro")]
2359 [DllImport(
"PerfectlyClearPro")]
2360 static extern void PFC_ReleaseProfile(
void* pProfile);
2362 [DllImport(
"PerfectlyClearPro")]
2365 [DllImport(
"PerfectlyClearPro")]
2366 static extern bool PFC_HasFaceBeautification(
PFCENGINE* pEngine);
2368 [DllImport(
"PerfectlyClearPro")]
2369 static extern int PFC_FBFaceCount(
void* pImageProfile);
2371 [DllImport(
"PerfectlyClearPro")]
2372 static extern bool PFC_GetFaceInfo(
void* pImageProfile, PFCFBFACEINFO1* pFace,
int index);
2374 [DllImport(
"PerfectlyClearPro")]
2375 static extern bool PFC_AbnormalTintDetected(
void* pImageProfile,
TINTCORRECTION eTintMethod);
2377 [DllImport(
"PerfectlyClearPro")]
2378 static extern void PFC_ApplyStrengthToParam(ref
PFCPARAM param,
int strength);
2380 [DllImport(
"PerfectlyClearPro")]
2381 static extern void* PFC_EnumFAEFaceRect(
void *pImageProfile,
void* p);
2383 [DllImport(
"PerfectlyClearPro")]
2384 static extern int PFC_FAEFaceCount(
void* pImageProfile);
2386 [DllImport(
"PerfectlyClearPro")]
2389 [DllImport(
"PerfectlyClearPro")]
2390 static extern int PFC_LoadScenePresets(
PFCENGINE* pEngine,
byte *filePath,
int groupUUID,
int *arrProfileUUID,
int arrProfileUUIDLen);
2392 [DllImport(
"PerfectlyClearPro")]
2393 static extern int PFC_ReadScenePreset(ref
PFCPARAM param,
PFCENGINE *pEngineAI,
int scene);
2395 [DllImport(
"PerfectlyClearPro")]
2396 static extern int PFC_GetScene(
void* precalc,
int *version);
2398 [DllImport(
"PerfectlyClearPro")]
2399 static extern bool PFC_GetSceneDetectionEngineInfo(
PFCENGINE* pEngine,
int* groupUUID,
int* arrProfileUUID,
int *arrProfileUUIDLen);
2401 [DllImport(
"PerfectlyClearPro")]
2402 static extern void PFC_SetAddonPath(
byte* path);
2404 [DllImport(
"PerfectlyClearPro")]
2407 [DllImport(
"PerfectlyClearPro")]
2408 static extern int PFC_LoadScenePresetsFromStream(
PFCENGINE* pEngine,
byte *buf,
int lenBuf,
int groupUUID,
int *arrProfileUUID,
int arrProfileUUIDLen);
2412 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2413 static extern int PFC_SetProtectionPath(
byte* path,
byte* licenseCode);
2415 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2416 static extern void PFC_ReleaseProtectionPath();
2418 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2419 static extern PFCENGINE* PFC_CreateEngine();
2421 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2422 static extern void PFC_DestroyEngine(
PFCENGINE* p);
2424 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2427 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2428 static extern int PFC_ReadPresets(ref
PFCPARAM param,
byte* filename);
2430 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2431 static extern int PFC_ReadPresetsFromStream(ref
PFCPARAM param,
byte* s);
2433 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2436 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2437 static extern void PFC_ReleaseProfile(
void* pProfile);
2439 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2442 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2443 static extern bool PFC_HasFaceBeautification(
PFCENGINE* pEngine);
2445 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2446 static extern int PFC_FBFaceCount(
void* pImageProfile);
2448 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2449 static extern bool PFC_GetFaceInfo(
void* pImageProfile, PFCFBFACEINFO1* pFace,
int index);
2451 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2452 static extern bool PFC_AbnormalTintDetected(
void* pImageProfile,
TINTCORRECTION eTintMethod);
2454 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2455 static extern void PFC_ApplyStrengthToParam(ref
PFCPARAM param,
int strength);
2457 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2458 static extern void* PFC_EnumFAEFaceRect(
void *pImageProfile,
void* p);
2460 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2461 static extern int PFC_FAEFaceCount(
void* pImageProfile);
2463 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2466 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2467 static extern int PFC_LoadScenePresets(
PFCENGINE* pEngine,
byte *filePath,
int groupUUID,
int *arrProfileUUID,
int arrProfileUUIDLen);
2469 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2470 static extern int PFC_ReadScenePreset(ref
PFCPARAM param,
PFCENGINE *pEngineAI,
int scene);
2472 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2473 static extern int PFC_GetScene(
void* precalc,
int *version);
2475 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2476 static extern bool PFC_GetSceneDetectionEngineInfo(
PFCENGINE* pEngine,
int* groupUUID,
int* arrProfileUUID,
int* arrProfileUUIDLen);
2478 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2479 static extern void PFC_SetAddonPath(
byte* path);
2481 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2484 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2485 static extern int PFC_LoadScenePresetsFromStream(
PFCENGINE* pEngine,
byte *buf,
int lenBuf,
int groupUUID,
int *arrProfileUUID,
int arrProfileUUIDLen);
2527 private IntPtr m_pNativeObject;
2532 m_pNativeObject = create_PFCImageFile();
2535 public void Dispose()
2540 protected virtual void Dispose(
bool bDisposing)
2542 if (this.m_pNativeObject != IntPtr.Zero)
2544 delete_PFCImageFile(m_pNativeObject);
2545 m_pNativeObject = IntPtr.Zero;
2552 GC.SuppressFinalize(
this);
2586 if (filename ==
null)
2591 byte* pFilename = GetCharBuffer(filename);
2593 byte* pIccFolderPath =
null;
2594 if (iccFolderPath !=
null)
2596 pIccFolderPath = GetCharBuffer(iccFolderPath);
2599 int result = PFCImageFile_LoadImageFile(m_pNativeObject, pFilename, bConvertToSRGB, pIccFolderPath);
2601 FreeCharBuffer(pFilename);
2602 FreeCharBuffer(pIccFolderPath);
2617 if (filename ==
null)
2622 byte* pFilename = GetCharBuffer(filename);
2624 byte* pIccFolderPath =
null;
2625 if (iccFolderPath !=
null)
2627 pIccFolderPath = GetCharBuffer(iccFolderPath);
2630 int result = PFCImageFile_LoadImageFileType(m_pNativeObject, pFilename, (
int)type, bConvertToSRGB, pIccFolderPath);
2632 FreeCharBuffer(pFilename);
2633 FreeCharBuffer(pIccFolderPath);
2645 public bool SaveImageFile(
string filename,
int jpegQuality = 92,
bool bConvertToOriginalColorSpace=
true,
bool bEmbedOriginalMetadata =
true)
2647 if (filename ==
null)
2652 byte* pFilename = GetCharBuffer(filename);
2654 bool result = PFCImageFile_SaveImageFile(m_pNativeObject, pFilename, jpegQuality, bConvertToOriginalColorSpace, bEmbedOriginalMetadata);
2656 FreeCharBuffer(pFilename);
2669 public bool SaveImageFile(
string filename,
PFC_FILETYPE type,
int jpegQuality = 92,
bool bConvertToOriginalColorSpace =
true,
bool bEmbedOriginalMetadata =
true)
2671 if (filename ==
null)
2676 byte* pFilename = GetCharBuffer(filename);
2678 bool result = PFCImageFile_SaveImageFileType(m_pNativeObject, pFilename, (
int)type, jpegQuality, bConvertToOriginalColorSpace, bEmbedOriginalMetadata);
2680 FreeCharBuffer(pFilename);
2685 public void AllocBuffer(
int width,
int height,
int bytes_per_pixel,
int stride)
2687 PFCImageFile_AllocBuffer(m_pNativeObject, width, height, bytes_per_pixel, stride);
2690 public int pfcImageFormat()
2692 return PFCImageFile_pfcImageFormat(m_pNativeObject);
2695 public int exifOrientation()
2697 return PFCImageFile_exifOrientation(m_pNativeObject);
2700 public byte* raw_image()
2702 return PFCImageFile_get_raw_image(m_pNativeObject);
2707 return PFCImageFile_get_width(m_pNativeObject);
2712 return PFCImageFile_get_height(m_pNativeObject);
2715 public int bytes_per_pixel()
2717 return PFCImageFile_get_bytes_per_pixel(m_pNativeObject);
2722 return PFCImageFile_get_stride(m_pNativeObject);
2725 public bool sourceSRGB()
2727 return PFCImageFile_get_sourceSRGB(m_pNativeObject);
2740 byte* buffer = GetByteBuffer(inStream.ToArray());
2741 byte* pIccFolderPath =
null;
2742 if (iccFolderPath !=
null)
2744 pIccFolderPath = GetCharBuffer(iccFolderPath);
2746 int result = PFCImageFile_ExpandImageBuffer(m_pNativeObject, buffer, inStream.Length, (
int)type, bConvertToSRGB, pIccFolderPath);
2747 FreeCharBuffer(pIccFolderPath);
2748 FreeByteBuffer(buffer);
2763 byte* compressedBuffer =
null;
2764 int length = PFCImageFile_CompressImageBuffer(m_pNativeObject, &compressedBuffer, (
int)type, jpegQuality, bConvertToOriginalColorSpace, bEmbedOriginalMetadata);
2765 if (length > 0 && compressedBuffer !=
null)
2767 byte[] result =
new byte[length];
2768 Marshal.Copy((IntPtr)(compressedBuffer), result, 0, length);
2769 deleteBuffer(compressedBuffer);
2772 MemoryStream stream =
new MemoryStream();
2773 stream.Write(result, 0, result.Length);
2776 return new MemoryStream();
2779 private static byte* GetCharBuffer(
string s)
2781 UTF8Encoding utf8 =
new UTF8Encoding();
2782 Byte[] encodedBytes = utf8.GetBytes(s);
2784 int i, iCount = encodedBytes.Length;
2785 IntPtr _memory = IntPtr.Zero;
2786 _memory = Marshal.AllocHGlobal(iCount + 1);
2787 byte* p = (
byte*)_memory;
2788 for (i = 0; i < iCount; i++)
2790 p[i] = encodedBytes[i];
2797 private static void FreeCharBuffer(
byte* p)
2799 IntPtr _memory = (IntPtr)p;
2800 Marshal.FreeHGlobal(_memory);
2803 private static byte* GetByteBuffer(
byte[] bytes)
2805 int length = bytes.Length;
2806 IntPtr p = Marshal.AllocHGlobal(length);
2807 Marshal.Copy(bytes, 0, p, length);
2811 private static void FreeByteBuffer(
byte* p)
2813 IntPtr _memory = (IntPtr)p;
2814 Marshal.FreeHGlobal(_memory);
2818 [DllImport(
"PFCImageFile")]
2819 static private extern unsafe IntPtr create_PFCImageFile();
2821 [DllImport(
"PFCImageFile")]
2822 static private extern void delete_PFCImageFile(IntPtr o);
2824 [DllImport(
"PFCImageFile")]
2825 static private extern unsafe
int PFCImageFile_LoadImageFile(IntPtr o,
byte* filename,
bool bConvertToSRGB,
byte* iccFolderPath);
2827 [DllImport(
"PFCImageFile")]
2828 static private extern unsafe
int PFCImageFile_LoadImageFileType(IntPtr o,
byte* filename,
int type,
bool bConvertToSRGB,
byte* iccFolderPath);
2830 [DllImport(
"PFCImageFile")]
2831 static private extern unsafe
bool PFCImageFile_SaveImageFile(IntPtr ptr,
byte* filename,
int jpegQuality,
bool bConvertToOriginalColorSpace,
bool bEmbedOriginalMetadata);
2833 [DllImport(
"PFCImageFile")]
2834 static private extern unsafe
bool PFCImageFile_SaveImageFileType(IntPtr ptr,
byte* filename,
int type,
int jpegQuality,
bool bConvertToOriginalColorSpace,
bool bEmbedOriginalMetadata);
2836 [DllImport(
"PFCImageFile")]
2837 static private extern unsafe
void PFCImageFile_AllocBuffer(IntPtr ptr,
int width,
int height,
int bytes_per_pixel,
int stride);
2839 [DllImport(
"PFCImageFile")]
2840 static private extern unsafe
int PFCImageFile_pfcImageFormat(IntPtr ptr);
2842 [DllImport(
"PFCImageFile")]
2843 static private extern unsafe
int PFCImageFile_exifOrientation(IntPtr ptr);
2845 [DllImport(
"PFCImageFile")]
2846 static private extern unsafe
byte* PFCImageFile_get_raw_image(IntPtr ptr);
2848 [DllImport(
"PFCImageFile")]
2849 static private extern unsafe
int PFCImageFile_get_width(IntPtr ptr);
2851 [DllImport(
"PFCImageFile")]
2852 static private extern unsafe
int PFCImageFile_get_height(IntPtr ptr);
2854 [DllImport(
"PFCImageFile")]
2855 static private extern unsafe
int PFCImageFile_get_bytes_per_pixel(IntPtr ptr);
2857 [DllImport(
"PFCImageFile")]
2858 static private extern unsafe
int PFCImageFile_get_stride(IntPtr ptr);
2860 [DllImport(
"PFCImageFile")]
2861 static private extern unsafe
bool PFCImageFile_get_sourceSRGB(IntPtr ptr);
2863 [DllImport(
"PFCImageFile")]
2864 static private extern unsafe
int PFCImageFile_ExpandImageBuffer(IntPtr ptr,
byte* buffer,
long size,
int type,
bool bConvertToSRGB,
byte* iccFolderPath);
2866 [DllImport(
"PFCImageFile")]
2867 static private extern unsafe
int PFCImageFile_CompressImageBuffer(IntPtr ptr,
byte** destination,
int type,
int jpegQuality,
bool bConvertToOriginalColorSpace,
bool bEmbedOriginalMetadata);
2869 [DllImport(
"PFCImageFile")]
2870 static private extern unsafe
int deleteBuffer(
byte* buffer);
2874 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2875 static private extern unsafe IntPtr create_PFCImageFile();
2877 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2878 static private extern void delete_PFCImageFile(IntPtr o);
2880 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2881 static private extern unsafe
int PFCImageFile_LoadImageFile(IntPtr o,
byte* filename,
bool bConvertToSRGB,
byte* iccFolderPath);
2883 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2884 static private extern unsafe
int PFCImageFile_LoadImageFileType(IntPtr o,
byte* filename,
int type,
bool bConvertToSRGB,
byte* iccFolderPath);
2886 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2887 static private extern unsafe
bool PFCImageFile_SaveImageFile(IntPtr ptr,
byte* filename,
int jpegQuality,
bool bConvertToOriginalColorSpace,
bool bEmbedOriginalMetadata);
2889 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2890 static private extern unsafe
bool PFCImageFile_SaveImageFileType(IntPtr ptr,
byte* filename,
int type,
int jpegQuality,
bool bConvertToOriginalColorSpace,
bool bEmbedOriginalMetadata);
2892 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2893 static private extern unsafe
void PFCImageFile_AllocBuffer(IntPtr ptr,
int width,
int height,
int bytes_per_pixel,
int stride);
2895 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2896 static private extern unsafe
int PFCImageFile_pfcImageFormat(IntPtr ptr);
2898 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2899 static private extern unsafe
int PFCImageFile_exifOrientation(IntPtr ptr);
2901 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2902 static private extern unsafe
byte* PFCImageFile_get_raw_image(IntPtr ptr);
2904 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2905 static private extern unsafe
int PFCImageFile_get_width(IntPtr ptr);
2907 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2908 static private extern unsafe
int PFCImageFile_get_height(IntPtr ptr);
2910 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2911 static private extern unsafe
int PFCImageFile_get_bytes_per_pixel(IntPtr ptr);
2913 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2914 static private extern unsafe
int PFCImageFile_get_stride(IntPtr ptr);
2916 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2917 static private extern unsafe
bool PFCImageFile_get_sourceSRGB(IntPtr ptr);
2919 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2920 static private extern unsafe
int PFCImageFile_ExpandImageBuffer(IntPtr ptr,
byte* buffer,
long size,
int type,
bool bConvertToSRGB,
byte* iccFolderPath);
2922 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2923 static private extern unsafe
int PFCImageFile_CompressImageBuffer(IntPtr ptr,
byte** destination,
int type,
int jpegQuality,
bool bConvertToOriginalColorSpace,
bool bEmbedOriginalMetadata);
2925 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2926 static private extern unsafe
int deleteBuffer(
byte* buffer);