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;
425 [StructLayout(LayoutKind.Sequential, Pack = 1)]
557 public enum PFCCORE_MASK_TYPE
564 PFCCORE_MASK_ROUNDRECT
582 [MarshalAsAttribute(UnmanagedType.I1)]
586 [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
590 [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 33)]
593 public byte strength;
597 [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
601 [MarshalAsAttribute(UnmanagedType.I1)]
640 [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
655 [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
683 [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
687 [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 250)]
690 public int profileUUID;
755 int m_loadedAiEngineFeatures;
760 private bool releaseProtection =
false;
797 #if PROTECTION_ENABLED
800 byte* pLicpath =
null;
801 if (!String.IsNullOrEmpty(path))
803 pLicpath = GetCharBuffer(path);
806 byte* pLicenseCode =
null;
807 if (!String.IsNullOrEmpty(licenseCode)) {
808 pLicenseCode = GetCharBuffer(licenseCode);
811 int status = PFC_SetProtectionPath(pLicpath, pLicenseCode);
813 FreeCharBuffer(pLicpath);
814 FreeCharBuffer(pLicenseCode);
821 Trace.WriteLine(ex.Message);
836 PFC_ReleaseProtectionPath();
850 m_loadedAiEngineFeatures = 0;
854 m_pEngine = PFC_CreateEngine();
855 if (m_pEngine !=
null)
857 LastStatus.Status = (int)(*m_pEngine).status;
860 m_pAiEngine = PFC_CreateEngine();
861 if (m_pAiEngine !=
null)
863 LastAiStatus.Status = (int)(*m_pAiEngine).status;
868 Trace.WriteLine(ex.Message);
871 PFC_SetParam(ref m_Param,
PFCPRESETID.PRESET_IAUTO_PEOPLE);
888 #if PROTECTION_ENABLED
891 byte* pLicpath =
null;
892 if (!String.IsNullOrEmpty(path))
894 pLicpath = GetCharBuffer(path);
897 byte* pLicenseCode =
null;
898 if (!String.IsNullOrEmpty(licenseCode)) {
899 pLicenseCode = GetCharBuffer(licenseCode);
902 int status = PFC_SetProtectionPath(pLicpath, pLicenseCode);
903 releaseProtection =
true;
905 FreeCharBuffer(pLicpath);
906 FreeCharBuffer(pLicenseCode);
911 Trace.WriteLine(ex.Message);
916 m_pEngine = PFC_CreateEngine();
917 if (m_pEngine !=
null)
919 LastStatus.Status = (int)(*m_pEngine).status;
922 m_pAiEngine = PFC_CreateEngine();
923 if (m_pAiEngine !=
null)
925 LastAiStatus.Status = (int)(*m_pAiEngine).status;
930 Trace.WriteLine(ex.Message);
933 PFC_SetParam(ref m_Param,
PFCPRESETID.PRESET_IAUTO_21);
938 #if PROTECTION_ENABLED
939 if(releaseProtection) {
985 return Calc(ref imgfile, feature, -1,
null);
996 return Calc(ref bm, feature, -1,
null);
1008 return Calc(ref bm, ref bmds, feature, -1,
null);
1022 BitmapData bd =
null;
1024 bd = LockBitmapData(ref bm);
1025 if (bd.PixelFormat != PixelFormat.Format24bppRgb &&
1026 bd.PixelFormat != PixelFormat.Format32bppArgb &&
1027 bd.PixelFormat != PixelFormat.Format48bppRgb &&
1028 bd.PixelFormat != PixelFormat.Format64bppArgb)
1030 ReleaseBitmapData(ref bm, ref bd);
1033 pBase = (Byte*)bd.Scan0.ToPointer();
1036 im.
width = bd.Width;
1039 switch (bd.PixelFormat)
1047 im.
data = (
void*)pBase;
1049 if (m_pProfile !=
null)
1050 PFC_ReleaseProfile(m_pProfile);
1052 byte* pModel =
null;
1053 if (CameraModel !=
null)
1055 pModel = GetCharBuffer(CameraModel);
1057 m_pProfile = PFC_Calc(&im,
null, m_pEngine, feature, ISO, pModel,
null,
null, (
int)rejectOption, m_pAiEngine);
1059 FreeCharBuffer(pModel);
1061 ReleaseBitmapData(ref bm, ref bd);
1063 LastStatus.NR_Status = (*m_pProfile).NR_Status;
1064 LastStatus.CORE_Status = (*m_pProfile).CORE_Status;
1065 LastStatus.FB_Status = (*m_pProfile).FB_Status;
1066 LastStatus.RE_Status = (*m_pProfile).RE_Status;
1067 LastStatus.Status = (*m_pProfile).Status;
1084 im.
width = imgfile.width();
1085 im.
height = imgfile.height();
1086 im.
stride = imgfile.stride();
1088 im.
data = (
void*)imgfile.raw_image();
1090 if (m_pProfile !=
null)
1091 PFC_ReleaseProfile(m_pProfile);
1093 byte* pModel =
null;
1094 if (CameraModel !=
null)
1096 pModel = GetCharBuffer(CameraModel);
1098 m_pProfile = PFC_Calc(&im,
null, m_pEngine, feature, ISO, pModel,
null,
null, (
int)rejectOption, m_pAiEngine);
1100 FreeCharBuffer(pModel);
1102 LastStatus.NR_Status = (*m_pProfile).NR_Status;
1103 LastStatus.CORE_Status = (*m_pProfile).CORE_Status;
1104 LastStatus.FB_Status = (*m_pProfile).FB_Status;
1105 LastStatus.RE_Status = (*m_pProfile).RE_Status;
1106 LastStatus.Status = (*m_pProfile).Status;
1122 BitmapData bd =
null;
1124 bd = LockBitmapData(ref bm);
1125 if (bd.PixelFormat != PixelFormat.Format24bppRgb &&
1126 bd.PixelFormat != PixelFormat.Format32bppArgb &&
1127 bd.PixelFormat != PixelFormat.Format48bppRgb &&
1128 bd.PixelFormat != PixelFormat.Format64bppArgb)
1130 ReleaseBitmapData(ref bm, ref bd);
1133 pBase = (Byte*)bd.Scan0.ToPointer();
1136 im.
width = bd.Width;
1139 switch (bd.PixelFormat)
1147 im.
data = (
void*)pBase;
1149 BitmapData bdds =
null;
1150 bdds = LockBitmapData(ref bmds);
1151 if (bdds.PixelFormat != PixelFormat.Format24bppRgb &&
1152 bdds.PixelFormat != PixelFormat.Format32bppArgb &&
1153 bdds.PixelFormat != PixelFormat.Format48bppRgb &&
1154 bdds.PixelFormat != PixelFormat.Format64bppArgb)
1156 ReleaseBitmapData(ref bmds, ref bdds);
1159 pBase = (Byte*)bdds.Scan0.ToPointer();
1162 imds.
width = bdds.Width;
1163 imds.
height = bdds.Height;
1164 imds.
stride = bdds.Stride;
1165 switch (bdds.PixelFormat)
1169 case PixelFormat.Format32bppArgb: imds.
format =
PFCPIXELFORMAT.PFC_PixelFormat32bppARGB;
break;
1171 case PixelFormat.Format64bppArgb: imds.
format =
PFCPIXELFORMAT.PFC_PixelFormat64bppARGB;
break;
1173 imds.
data = (
void*)pBase;
1175 if (m_pProfile !=
null)
1176 PFC_ReleaseProfile(m_pProfile);
1178 byte* pModel =
null;
1179 if (CameraModel !=
null)
1181 pModel = GetCharBuffer(CameraModel);
1183 m_pProfile = PFC_Calc(&im, &imds, m_pEngine, feature, ISO, pModel,
null,
null, 1, m_pAiEngine);
1185 FreeCharBuffer(pModel);
1187 ReleaseBitmapData(ref bm, ref bd);
1188 ReleaseBitmapData(ref bmds, ref bdds);
1190 LastStatus.NR_Status = (*m_pProfile).NR_Status;
1191 LastStatus.CORE_Status = (*m_pProfile).CORE_Status;
1192 LastStatus.FB_Status = (*m_pProfile).FB_Status;
1193 LastStatus.RE_Status = (*m_pProfile).RE_Status;
1194 LastStatus.Status = (*m_pProfile).Status;
1207 return Apply(ref bm, 100);
1217 return Apply(ref imgfile, 100);
1228 if (m_pProfile ==
null)
1233 BitmapData bd =
null;
1235 bd = LockBitmapData(ref bm);
1236 if (bd.PixelFormat != PixelFormat.Format24bppRgb &&
1237 bd.PixelFormat != PixelFormat.Format32bppArgb &&
1238 bd.PixelFormat != PixelFormat.Format48bppRgb &&
1239 bd.PixelFormat != PixelFormat.Format64bppArgb)
1241 ReleaseBitmapData(ref bm, ref bd);
1244 pBase = (Byte*)bd.Scan0.ToPointer();
1247 im.
width = bd.Width;
1250 switch (bd.PixelFormat)
1258 im.
data = (
void*)pBase;
1260 PFCAPPLYSTATUS ret = PFC_Apply(&im, m_pEngine, m_pProfile, ref m_Param,
null, iOpacity,
null);
1264 int code = (int)ret;
1266 LastStatus.NR_Status = (
PFCNR_STATUS)(code & 0x000000FF);
1267 LastStatus.CORE_Status = (
PFCCORE_STATUS)((code >> 8) & 0x000000FF);
1268 LastStatus.FB_Status = (
PFCFB_STATUS)((code >> 16) & 0x000000FF);
1269 LastStatus.RE_Status = (
PFCRE_STATUS)((code >> 24) & 0x000000FF);
1270 LastStatus.Status = code;
1273 ReleaseBitmapData(ref bm, ref bd);
1285 if (m_pProfile ==
null)
1291 im.
width = imgfile.width();
1292 im.
height = imgfile.height();
1293 im.
stride = imgfile.stride();
1295 im.
data = (
void*)imgfile.raw_image();
1297 PFCAPPLYSTATUS ret = PFC_Apply(&im, m_pEngine, m_pProfile, ref m_Param,
null, iOpacity,
null);
1301 int code = (int)ret;
1303 LastStatus.NR_Status = (
PFCNR_STATUS)(code & 0x000000FF);
1304 LastStatus.CORE_Status = (
PFCCORE_STATUS)((code >> 8) & 0x000000FF);
1305 LastStatus.FB_Status = (
PFCFB_STATUS)((code >> 16) & 0x000000FF);
1306 LastStatus.RE_Status = (
PFCRE_STATUS)((code >> 24) & 0x000000FF);
1307 LastStatus.Status = code;
1368 return AutoCorrect(ref bm, ref bmds, -1,
null,
false);
1379 public int AutoCorrect(ref Bitmap bm,
int ISO,
string CameraModel,
bool bFastFAE)
1385 int detectedCategory =
GetScene(&version);
1386 if (detectedCategory >= 0) {
1389 m_Param = categoryParam;
1445 int retInt = (((((((int)retRE << 8) | (int)retFB) << 8) | (
int)retCORE) << 8) | (int)retNR);
1469 int detectedCategory =
GetScene(&version);
1470 if (detectedCategory >= 0) {
1473 m_Param = categoryParam;
1529 int retInt = (((((((int)retRE << 8) | (int)retFB) << 8) | (
int)retCORE) << 8) | (int)retNR);
1548 public int AutoCorrect(ref Bitmap bm, ref Bitmap bmds,
int ISO,
string CameraModel,
bool bFastFAE)
1554 int detectedCategory =
GetScene(&version);
1555 if (detectedCategory >= 0) {
1558 m_Param = categoryParam;
1614 int retInt = (((((((int)retRE << 8) | (int)retFB) << 8) | (
int)retCORE) << 8) | (int)retNR);
1637 return retCode-1000;
1653 return retCode - 1000;
1663 public int AutoCorrect(ref Bitmap bm, ref Bitmap bmds,
string pathPreset)
1668 return AutoCorrect(ref bm, ref bmds, -1,
null,
false);
1670 return retCode - 1000;
1682 public int AutoCorrect(ref Bitmap bm,
string pathPreset,
int ISO,
string CameraModel,
bool bFastFAE)
1687 return AutoCorrect(ref bm, ISO, CameraModel, bFastFAE);
1689 return retCode - 1000;
1706 return AutoCorrect(ref imgfile, ISO, CameraModel, bFastFAE);
1708 return retCode - 1000;
1721 public int AutoCorrect(ref Bitmap bm, ref Bitmap bmds,
string pathPreset,
int ISO,
string CameraModel,
bool bFastFAE)
1726 return AutoCorrect(ref bm, ref bmds, ISO, CameraModel, bFastFAE);
1728 return retCode - 1000;
1737 PFC_SetParam(ref m_Param,
id);
1763 byte* presetpath =
null;
1766 presetpath = GetCharBuffer(path);
1769 int status = PFC_ReadPresets(ref m_Param, presetpath);
1773 catch (Exception ex)
1775 Trace.WriteLine(ex.Message);
1798 long len = fs.Length;
1799 byte[] buffer =
new byte[len + 1];
1800 int size = (int)len;
1801 fs.Read(buffer, 0, size);
1803 byte* b = GetCharBuffer(buffer);
1808 int status = PFC_ReadPresetsFromStream(ref m_Param, b);
1812 catch (Exception ex)
1814 Trace.WriteLine(ex.Message);
1825 return PFC_HasFaceBeautification(m_pEngine);
1835 return PFC_FBFaceCount(m_pProfile);
1849 bool ret = PFC_GetFaceInfo(m_pProfile, &fi, index);
1868 return PFC_AbnormalTintDetected(m_pProfile, eTintMethod);
1878 PFC_ApplyStrengthToParam(ref m_Param, strength);
1881 protected BitmapData LockBitmapData(ref Bitmap bm)
1883 GraphicsUnit unit = GraphicsUnit.Pixel;
1884 RectangleF boundsF = bm.GetBounds(ref unit);
1885 Rectangle bounds =
new Rectangle((
int)boundsF.X,
1888 (
int)boundsF.Height);
1890 BitmapData bitmapData =
1891 bm.LockBits(bounds, ImageLockMode.ReadWrite, bm.PixelFormat);
1895 protected void ReleaseBitmapData(ref Bitmap bm, ref BitmapData bitmapData)
1897 bm.UnlockBits(bitmapData);
1900 protected Bitmap DupBitmap(ref Bitmap bm)
1902 PerfectlyClearImageTransfer tr, tr1;
1904 GraphicsUnit unit = GraphicsUnit.Pixel;
1905 RectangleF boundsF = bm.GetBounds(ref unit);
1906 Rectangle bounds =
new Rectangle((
int)boundsF.X,
1909 (
int)boundsF.Height);
1910 BitmapData bd = bm.LockBits(bounds, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
1911 Bitmap bm1 =
new Bitmap(bd.Width, bd.Height, PixelFormat.Format24bppRgb);
1912 BitmapData bd1 = LockBitmapData(ref bm1);
1913 pBase = (Byte*)bd.Scan0.ToPointer();
1914 tr.columnBytes = (bd.PixelFormat == PixelFormat.Format24bppRgb) ? 3 : 4;
1915 tr.rowBytes = bd.Stride;
1916 tr.height = bd.Height;
1917 tr.width = bd.Width;
1918 tr.data1 = (int)(pBase + 2);
1919 tr.data2 = (int)(pBase + 1);
1920 tr.data3 = (int)pBase;
1921 pBase = (Byte*)bd1.Scan0.ToPointer();
1922 tr1.columnBytes = (bd1.PixelFormat == PixelFormat.Format24bppRgb) ? 3 : 4;
1923 tr1.rowBytes = bd1.Stride;
1924 tr1.height = bd1.Height;
1925 tr1.width = bd1.Width;
1926 tr1.data1 = (int)(pBase + 2);
1927 tr1.data2 = (int)(pBase + 1);
1928 tr1.data3 = (int)pBase;
1929 for (
int i = 0; i < tr.height; i++)
1931 for (
int j = 0; j < tr.width; j++)
1933 ((Byte*)tr1.data1)[j * tr1.columnBytes] = ((Byte*)tr.data1)[j * tr.columnBytes];
1934 ((Byte*)tr1.data2)[j * tr1.columnBytes] = ((Byte*)tr.data2)[j * tr.columnBytes];
1935 ((Byte*)tr1.data3)[j * tr1.columnBytes] = ((Byte*)tr.data3)[j * tr.columnBytes];
1937 tr.data1 += (int)tr.rowBytes;
1938 tr.data2 += (
int)tr.rowBytes;
1939 tr.data3 += (int)tr.rowBytes;
1940 tr1.data1 += (
int)tr1.rowBytes;
1941 tr1.data2 += (int)tr1.rowBytes;
1942 tr1.data3 += (
int)tr1.rowBytes;
1944 ReleaseBitmapData(ref bm1, ref bd1);
1945 ReleaseBitmapData(ref bm, ref bd);
1949 protected Bitmap BW2RGB(ref Bitmap bm)
1952 Byte* pBase1 =
null;
1953 GraphicsUnit unit = GraphicsUnit.Pixel;
1954 RectangleF boundsF = bm.GetBounds(ref unit);
1955 Rectangle bounds =
new Rectangle((
int)boundsF.X,
1958 (
int)boundsF.Height);
1959 BitmapData bd = bm.LockBits(bounds, ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);
1960 Bitmap bm1 =
new Bitmap(bd.Width, bd.Height, PixelFormat.Format24bppRgb);
1961 BitmapData bd1 = LockBitmapData(ref bm1);
1962 pBase = (Byte*)bd.Scan0.ToPointer();
1963 pBase1 = (Byte*)bd1.Scan0.ToPointer();
1964 for (
int i = 0; i < bd.Height; i++)
1966 for (
int j = 0; j < bd.Width; j++)
1968 pBase1[j * 3] = pBase[j];
1969 pBase1[j * 3 + 1] = pBase[j];
1970 pBase1[j * 3 + 2] = pBase[j];
1973 pBase1 += bd1.Stride;
1975 ReleaseBitmapData(ref bm1, ref bd1);
1976 ReleaseBitmapData(ref bm, ref bd);
1990 Bitmap myBitmap =
new Bitmap(filename);
1991 if ((myBitmap.Flags & (
int)ImageFlags.ColorSpaceYcck) != 0)
1993 bm = DupBitmap(ref myBitmap);
1998 if (myBitmap.PixelFormat == PixelFormat.Format8bppIndexed)
2000 bm = BW2RGB(ref myBitmap);
2011 protected Bitmap GetStatImage(ref Bitmap bm,
int iMaxDimension)
2014 bool bNeedResize =
true;
2021 if (w <= iMaxDimension)
2022 bNeedResize =
false;
2028 if (h <= iMaxDimension)
2029 bNeedResize =
false;
2040 Bitmap bmds =
new Bitmap(w1, h1, bm.PixelFormat);
2042 using (Graphics gr = Graphics.FromImage(bmds))
2044 gr.SmoothingMode = SmoothingMode.HighQuality;
2045 gr.InterpolationMode = InterpolationMode.HighQualityBicubic;
2046 gr.PixelOffsetMode = PixelOffsetMode.HighQuality;
2047 gr.DrawImage(bm,
new Rectangle(0, 0, w1, h1));
2055 Bitmap bmds = (Bitmap)bm.Clone();
2081 IntPtr wrapped = rect.pWrapped;
2082 IntPtr pRect = (IntPtr) PFC_EnumFAEFaceRect(m_pProfile, (
void*)wrapped);
2084 if (pRect != IntPtr.Zero) {
2087 rect.pWrapped = (IntPtr)pRect;
2091 rect.pWrapped = IntPtr.Zero;
2101 return PFC_FAEFaceCount(m_pProfile);
2113 if (binPath !=
null)
2115 path = GetCharBuffer(binPath);
2117 int result = PFC_LoadAIEngine(m_pAiEngine, aifeatures, path);
2118 m_loadedAiEngineFeatures = result;
2121 PFC_LoadAIEngine(m_pEngine,
PFCAIFEATURE.AI_CORRECTIONS, path);
2124 FreeCharBuffer(path);
2144 public unsafe
int LoadScenePresets(
string filePath,
int groupUUID = 0,
int* arrProfileUUID =
null,
int arrProfileUUIDLen = 0)
2147 if (filePath !=
null)
2149 path = GetCharBuffer(filePath);
2151 int result = PFC_LoadScenePresets(m_pAiEngine, path, groupUUID, arrProfileUUID, arrProfileUUIDLen);
2152 FreeCharBuffer(path);
2165 return PFC_ReadScenePreset(ref param, m_pAiEngine, scene);
2176 return PFC_GetScene(m_pProfile, version);
2189 return PFC_GetSceneDetectionEngineInfo(m_pAiEngine, groupUUID, arrProfileUUID, arrProfileUUIDLen);
2198 if (dirPath !=
null)
2200 path = GetCharBuffer(dirPath);
2202 PFC_SetAddonPath(path);
2203 FreeCharBuffer(path);
2224 bool result = PFC_GetSceneDescription(m_pAiEngine, index, ref sceneDescription);
2228 public void Dispose()
2231 GC.SuppressFinalize(
this);
2234 protected virtual void Dispose(
bool disposing)
2240 if (m_pProfile !=
null)
2242 PFC_ReleaseProfile(m_pProfile);
2246 if (m_pEngine !=
null)
2248 PFC_DestroyEngine(m_pEngine);
2252 if (m_pAiEngine !=
null)
2254 PFC_DestroyEngine(m_pAiEngine);
2259 static protected byte* GetCharBuffer(
byte[] s)
2261 int i, iCount = s.Length;
2262 IntPtr _memory = IntPtr.Zero;
2263 _memory = Marshal.AllocHGlobal(iCount + 1);
2264 byte* p = (
byte*)_memory;
2265 for (i = 0; i < iCount; i++)
2274 static protected byte* GetCharBuffer(
string s)
2276 int i, iCount = s.Length;
2277 IntPtr _memory = IntPtr.Zero;
2278 _memory = Marshal.AllocHGlobal(iCount + 1);
2279 byte* p = (
byte*)_memory;
2280 for (i = 0; i < iCount; i++)
2289 static protected void FreeCharBuffer(
byte* p)
2291 IntPtr _memory = (IntPtr)p;
2292 Marshal.FreeHGlobal(_memory);
2296 [DllImport(
"PerfectlyClearPro")]
2297 static extern int PFC_SetProtectionPath(
byte* path,
byte* licenseCode);
2299 [DllImport(
"PerfectlyClearPro")]
2300 static extern void PFC_ReleaseProtectionPath();
2302 [DllImport(
"PerfectlyClearPro")]
2303 static extern PFCENGINE* PFC_CreateEngine();
2305 [DllImport(
"PerfectlyClearPro")]
2306 static extern void PFC_DestroyEngine(
PFCENGINE* p);
2308 [DllImport(
"PerfectlyClearPro")]
2311 [DllImport(
"PerfectlyClearPro")]
2312 static extern int PFC_ReadPresets(ref
PFCPARAM param,
byte* filename);
2314 [DllImport(
"PerfectlyClearPro")]
2315 static extern int PFC_ReadPresetsFromStream(ref
PFCPARAM param,
byte* s);
2317 [DllImport(
"PerfectlyClearPro")]
2320 [DllImport(
"PerfectlyClearPro")]
2321 static extern void PFC_ReleaseProfile(
void* pProfile);
2323 [DllImport(
"PerfectlyClearPro")]
2326 [DllImport(
"PerfectlyClearPro")]
2327 static extern bool PFC_HasFaceBeautification(
PFCENGINE* pEngine);
2329 [DllImport(
"PerfectlyClearPro")]
2330 static extern int PFC_FBFaceCount(
void* pImageProfile);
2332 [DllImport(
"PerfectlyClearPro")]
2333 static extern bool PFC_GetFaceInfo(
void* pImageProfile, PFCFBFACEINFO1* pFace,
int index);
2335 [DllImport(
"PerfectlyClearPro")]
2336 static extern bool PFC_AbnormalTintDetected(
void* pImageProfile,
TINTCORRECTION eTintMethod);
2338 [DllImport(
"PerfectlyClearPro")]
2339 static extern void PFC_ApplyStrengthToParam(ref
PFCPARAM param,
int strength);
2341 [DllImport(
"PerfectlyClearPro")]
2342 static extern void* PFC_EnumFAEFaceRect(
void *pImageProfile,
void* p);
2344 [DllImport(
"PerfectlyClearPro")]
2345 static extern int PFC_FAEFaceCount(
void* pImageProfile);
2347 [DllImport(
"PerfectlyClearPro")]
2350 [DllImport(
"PerfectlyClearPro")]
2351 static extern int PFC_LoadScenePresets(
PFCENGINE* pEngine,
byte *filePath,
int groupUUID,
int *arrProfileUUID,
int arrProfileUUIDLen);
2353 [DllImport(
"PerfectlyClearPro")]
2354 static extern int PFC_ReadScenePreset(ref
PFCPARAM param,
PFCENGINE *pEngineAI,
int scene);
2356 [DllImport(
"PerfectlyClearPro")]
2357 static extern int PFC_GetScene(
void* precalc,
int *version);
2359 [DllImport(
"PerfectlyClearPro")]
2360 static extern bool PFC_GetSceneDetectionEngineInfo(
PFCENGINE* pEngine,
int* groupUUID,
int* arrProfileUUID,
int *arrProfileUUIDLen);
2362 [DllImport(
"PerfectlyClearPro")]
2363 static extern void PFC_SetAddonPath(
byte* path);
2365 [DllImport(
"PerfectlyClearPro")]
2371 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2372 static extern int PFC_SetProtectionPath(
byte* path,
byte* licenseCode);
2374 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2375 static extern void PFC_ReleaseProtectionPath();
2377 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2378 static extern PFCENGINE* PFC_CreateEngine();
2380 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2381 static extern void PFC_DestroyEngine(
PFCENGINE* p);
2383 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2386 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2387 static extern int PFC_ReadPresets(ref
PFCPARAM param,
byte* filename);
2389 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2390 static extern int PFC_ReadPresetsFromStream(ref
PFCPARAM param,
byte* s);
2392 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2395 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2396 static extern void PFC_ReleaseProfile(
void* pProfile);
2398 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2401 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2402 static extern bool PFC_HasFaceBeautification(
PFCENGINE* pEngine);
2404 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2405 static extern int PFC_FBFaceCount(
void* pImageProfile);
2407 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2408 static extern bool PFC_GetFaceInfo(
void* pImageProfile, PFCFBFACEINFO1* pFace,
int index);
2410 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2411 static extern bool PFC_AbnormalTintDetected(
void* pImageProfile,
TINTCORRECTION eTintMethod);
2413 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2414 static extern void PFC_ApplyStrengthToParam(ref
PFCPARAM param,
int strength);
2416 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2417 static extern void* PFC_EnumFAEFaceRect(
void *pImageProfile,
void* p);
2419 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2420 static extern int PFC_FAEFaceCount(
void* pImageProfile);
2422 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2425 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2426 static extern int PFC_LoadScenePresets(
PFCENGINE* pEngine,
byte *filePath,
int groupUUID,
int *arrProfileUUID,
int arrProfileUUIDLen);
2428 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2429 static extern int PFC_ReadScenePreset(ref
PFCPARAM param,
PFCENGINE *pEngineAI,
int scene);
2431 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2432 static extern int PFC_GetScene(
void* precalc,
int *version);
2434 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2435 static extern bool PFC_GetSceneDetectionEngineInfo(
PFCENGINE* pEngine,
int* groupUUID,
int* arrProfileUUID,
int* arrProfileUUIDLen);
2437 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2438 static extern void PFC_SetAddonPath(
byte* path);
2440 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2483 private IntPtr m_pNativeObject;
2488 m_pNativeObject = create_PFCImageFile();
2491 public void Dispose()
2496 protected virtual void Dispose(
bool bDisposing)
2498 if (this.m_pNativeObject != IntPtr.Zero)
2500 delete_PFCImageFile(m_pNativeObject);
2501 m_pNativeObject = IntPtr.Zero;
2508 GC.SuppressFinalize(
this);
2542 if (filename ==
null)
2547 byte* pFilename = GetCharBuffer(filename);
2549 byte* pIccFolderPath =
null;
2550 if (iccFolderPath !=
null)
2552 pIccFolderPath = GetCharBuffer(iccFolderPath);
2555 int result = PFCImageFile_LoadImageFile(m_pNativeObject, pFilename, bConvertToSRGB, pIccFolderPath);
2557 FreeCharBuffer(pFilename);
2558 FreeCharBuffer(pIccFolderPath);
2573 if (filename ==
null)
2578 byte* pFilename = GetCharBuffer(filename);
2580 byte* pIccFolderPath =
null;
2581 if (iccFolderPath !=
null)
2583 pIccFolderPath = GetCharBuffer(iccFolderPath);
2586 int result = PFCImageFile_LoadImageFileType(m_pNativeObject, pFilename, (
int)type, bConvertToSRGB, pIccFolderPath);
2588 FreeCharBuffer(pFilename);
2589 FreeCharBuffer(pIccFolderPath);
2601 public bool SaveImageFile(
string filename,
int jpegQuality = 92,
bool bConvertToOriginalColorSpace=
true,
bool bEmbedOriginalMetadata =
true)
2603 if (filename ==
null)
2608 byte* pFilename = GetCharBuffer(filename);
2610 bool result = PFCImageFile_SaveImageFile(m_pNativeObject, pFilename, jpegQuality, bConvertToOriginalColorSpace, bEmbedOriginalMetadata);
2612 FreeCharBuffer(pFilename);
2625 public bool SaveImageFile(
string filename,
PFC_FILETYPE type,
int jpegQuality = 92,
bool bConvertToOriginalColorSpace =
true,
bool bEmbedOriginalMetadata =
true)
2627 if (filename ==
null)
2632 byte* pFilename = GetCharBuffer(filename);
2634 bool result = PFCImageFile_SaveImageFileType(m_pNativeObject, pFilename, (
int)type, jpegQuality, bConvertToOriginalColorSpace, bEmbedOriginalMetadata);
2636 FreeCharBuffer(pFilename);
2641 public void AllocBuffer(
int width,
int height,
int bytes_per_pixel,
int stride)
2643 PFCImageFile_AllocBuffer(m_pNativeObject, width, height, bytes_per_pixel, stride);
2646 public int pfcImageFormat()
2648 return PFCImageFile_pfcImageFormat(m_pNativeObject);
2651 public int exifOrientation()
2653 return PFCImageFile_exifOrientation(m_pNativeObject);
2656 public byte* raw_image()
2658 return PFCImageFile_get_raw_image(m_pNativeObject);
2663 return PFCImageFile_get_width(m_pNativeObject);
2668 return PFCImageFile_get_height(m_pNativeObject);
2671 public int bytes_per_pixel()
2673 return PFCImageFile_get_bytes_per_pixel(m_pNativeObject);
2678 return PFCImageFile_get_stride(m_pNativeObject);
2681 public bool sourceSRGB()
2683 return PFCImageFile_get_sourceSRGB(m_pNativeObject);
2696 byte* buffer = GetByteBuffer(inStream.ToArray());
2697 byte* pIccFolderPath =
null;
2698 if (iccFolderPath !=
null)
2700 pIccFolderPath = GetCharBuffer(iccFolderPath);
2702 int result = PFCImageFile_ExpandImageBuffer(m_pNativeObject, buffer, inStream.Length, (
int)type, bConvertToSRGB, pIccFolderPath);
2703 FreeCharBuffer(pIccFolderPath);
2704 FreeByteBuffer(buffer);
2719 byte* compressedBuffer =
null;
2720 int length = PFCImageFile_CompressImageBuffer(m_pNativeObject, &compressedBuffer, (
int)type, jpegQuality, bConvertToOriginalColorSpace, bEmbedOriginalMetadata);
2721 if (length > 0 && compressedBuffer !=
null)
2723 byte[] result =
new byte[length];
2724 Marshal.Copy((IntPtr)(compressedBuffer), result, 0, length);
2725 deleteBuffer(compressedBuffer);
2728 MemoryStream stream =
new MemoryStream();
2729 stream.Write(result, 0, result.Length);
2732 return new MemoryStream();
2735 private static byte* GetCharBuffer(
string s)
2737 UTF8Encoding utf8 =
new UTF8Encoding();
2738 Byte[] encodedBytes = utf8.GetBytes(s);
2740 int i, iCount = encodedBytes.Length;
2741 IntPtr _memory = IntPtr.Zero;
2742 _memory = Marshal.AllocHGlobal(iCount + 1);
2743 byte* p = (
byte*)_memory;
2744 for (i = 0; i < iCount; i++)
2746 p[i] = encodedBytes[i];
2753 private static void FreeCharBuffer(
byte* p)
2755 IntPtr _memory = (IntPtr)p;
2756 Marshal.FreeHGlobal(_memory);
2759 private static byte* GetByteBuffer(
byte[] bytes)
2761 int length = bytes.Length;
2762 IntPtr p = Marshal.AllocHGlobal(length);
2763 Marshal.Copy(bytes, 0, p, length);
2767 private static void FreeByteBuffer(
byte* p)
2769 IntPtr _memory = (IntPtr)p;
2770 Marshal.FreeHGlobal(_memory);
2774 [DllImport(
"PFCImageFile")]
2775 static private extern unsafe IntPtr create_PFCImageFile();
2777 [DllImport(
"PFCImageFile")]
2778 static private extern void delete_PFCImageFile(IntPtr o);
2780 [DllImport(
"PFCImageFile")]
2781 static private extern unsafe
int PFCImageFile_LoadImageFile(IntPtr o,
byte* filename,
bool bConvertToSRGB,
byte* iccFolderPath);
2783 [DllImport(
"PFCImageFile")]
2784 static private extern unsafe
int PFCImageFile_LoadImageFileType(IntPtr o,
byte* filename,
int type,
bool bConvertToSRGB,
byte* iccFolderPath);
2786 [DllImport(
"PFCImageFile")]
2787 static private extern unsafe
bool PFCImageFile_SaveImageFile(IntPtr ptr,
byte* filename,
int jpegQuality,
bool bConvertToOriginalColorSpace,
bool bEmbedOriginalMetadata);
2789 [DllImport(
"PFCImageFile")]
2790 static private extern unsafe
bool PFCImageFile_SaveImageFileType(IntPtr ptr,
byte* filename,
int type,
int jpegQuality,
bool bConvertToOriginalColorSpace,
bool bEmbedOriginalMetadata);
2792 [DllImport(
"PFCImageFile")]
2793 static private extern unsafe
void PFCImageFile_AllocBuffer(IntPtr ptr,
int width,
int height,
int bytes_per_pixel,
int stride);
2795 [DllImport(
"PFCImageFile")]
2796 static private extern unsafe
int PFCImageFile_pfcImageFormat(IntPtr ptr);
2798 [DllImport(
"PFCImageFile")]
2799 static private extern unsafe
int PFCImageFile_exifOrientation(IntPtr ptr);
2801 [DllImport(
"PFCImageFile")]
2802 static private extern unsafe
byte* PFCImageFile_get_raw_image(IntPtr ptr);
2804 [DllImport(
"PFCImageFile")]
2805 static private extern unsafe
int PFCImageFile_get_width(IntPtr ptr);
2807 [DllImport(
"PFCImageFile")]
2808 static private extern unsafe
int PFCImageFile_get_height(IntPtr ptr);
2810 [DllImport(
"PFCImageFile")]
2811 static private extern unsafe
int PFCImageFile_get_bytes_per_pixel(IntPtr ptr);
2813 [DllImport(
"PFCImageFile")]
2814 static private extern unsafe
int PFCImageFile_get_stride(IntPtr ptr);
2816 [DllImport(
"PFCImageFile")]
2817 static private extern unsafe
bool PFCImageFile_get_sourceSRGB(IntPtr ptr);
2819 [DllImport(
"PFCImageFile")]
2820 static private extern unsafe
int PFCImageFile_ExpandImageBuffer(IntPtr ptr,
byte* buffer,
long size,
int type,
bool bConvertToSRGB,
byte* iccFolderPath);
2822 [DllImport(
"PFCImageFile")]
2823 static private extern unsafe
int PFCImageFile_CompressImageBuffer(IntPtr ptr,
byte** destination,
int type,
int jpegQuality,
bool bConvertToOriginalColorSpace,
bool bEmbedOriginalMetadata);
2825 [DllImport(
"PFCImageFile")]
2826 static private extern unsafe
int deleteBuffer(
byte* buffer);
2830 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2831 static private extern unsafe IntPtr create_PFCImageFile();
2833 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2834 static private extern void delete_PFCImageFile(IntPtr o);
2836 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2837 static private extern unsafe
int PFCImageFile_LoadImageFile(IntPtr o,
byte* filename,
bool bConvertToSRGB,
byte* iccFolderPath);
2839 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2840 static private extern unsafe
int PFCImageFile_LoadImageFileType(IntPtr o,
byte* filename,
int type,
bool bConvertToSRGB,
byte* iccFolderPath);
2842 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2843 static private extern unsafe
bool PFCImageFile_SaveImageFile(IntPtr ptr,
byte* filename,
int jpegQuality,
bool bConvertToOriginalColorSpace,
bool bEmbedOriginalMetadata);
2845 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2846 static private extern unsafe
bool PFCImageFile_SaveImageFileType(IntPtr ptr,
byte* filename,
int type,
int jpegQuality,
bool bConvertToOriginalColorSpace,
bool bEmbedOriginalMetadata);
2848 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2849 static private extern unsafe
void PFCImageFile_AllocBuffer(IntPtr ptr,
int width,
int height,
int bytes_per_pixel,
int stride);
2851 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2852 static private extern unsafe
int PFCImageFile_pfcImageFormat(IntPtr ptr);
2854 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2855 static private extern unsafe
int PFCImageFile_exifOrientation(IntPtr ptr);
2857 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2858 static private extern unsafe
byte* PFCImageFile_get_raw_image(IntPtr ptr);
2860 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2861 static private extern unsafe
int PFCImageFile_get_width(IntPtr ptr);
2863 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2864 static private extern unsafe
int PFCImageFile_get_height(IntPtr ptr);
2866 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2867 static private extern unsafe
int PFCImageFile_get_bytes_per_pixel(IntPtr ptr);
2869 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2870 static private extern unsafe
int PFCImageFile_get_stride(IntPtr ptr);
2872 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2873 static private extern unsafe
bool PFCImageFile_get_sourceSRGB(IntPtr ptr);
2875 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2876 static private extern unsafe
int PFCImageFile_ExpandImageBuffer(IntPtr ptr,
byte* buffer,
long size,
int type,
bool bConvertToSRGB,
byte* iccFolderPath);
2878 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2879 static private extern unsafe
int PFCImageFile_CompressImageBuffer(IntPtr ptr,
byte** destination,
int type,
int jpegQuality,
bool bConvertToOriginalColorSpace,
bool bEmbedOriginalMetadata);
2881 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2882 static private extern unsafe
int deleteBuffer(
byte* buffer);