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;
520 public enum PFCCORE_MASK_TYPE
527 PFCCORE_MASK_ROUNDRECT
545 [MarshalAsAttribute(UnmanagedType.I1)]
549 [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
553 [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 33)]
556 public byte strength;
560 [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
564 [MarshalAsAttribute(UnmanagedType.I1)]
599 [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
688 int m_loadedAiEngineFeatures;
693 private bool releaseProtection =
false;
730 #if PROTECTION_ENABLED
733 byte* pLicpath =
null;
734 if (!String.IsNullOrEmpty(path))
736 pLicpath = GetCharBuffer(path);
739 byte* pLicenseCode =
null;
740 if (!String.IsNullOrEmpty(licenseCode)) {
741 pLicenseCode = GetCharBuffer(licenseCode);
744 int status = PFC_SetProtectionPath(pLicpath, pLicenseCode);
746 FreeCharBuffer(pLicpath);
747 FreeCharBuffer(pLicenseCode);
754 Trace.WriteLine(ex.Message);
769 PFC_ReleaseProtectionPath();
783 m_loadedAiEngineFeatures = 0;
787 m_pEngine = PFC_CreateEngine();
788 if (m_pEngine !=
null)
790 LastStatus.Status = (int)(*m_pEngine).status;
793 m_pAiEngine = PFC_CreateEngine();
794 if (m_pAiEngine !=
null)
796 LastAiStatus.Status = (int)(*m_pAiEngine).status;
801 Trace.WriteLine(ex.Message);
804 PFC_SetParam(ref m_Param,
PFCPRESETID.PRESET_IAUTO_21);
821 #if PROTECTION_ENABLED
824 byte* pLicpath =
null;
825 if (!String.IsNullOrEmpty(path))
827 pLicpath = GetCharBuffer(path);
830 byte* pLicenseCode =
null;
831 if (!String.IsNullOrEmpty(licenseCode)) {
832 pLicenseCode = GetCharBuffer(licenseCode);
835 int status = PFC_SetProtectionPath(pLicpath, pLicenseCode);
836 releaseProtection =
true;
838 FreeCharBuffer(pLicpath);
839 FreeCharBuffer(pLicenseCode);
844 Trace.WriteLine(ex.Message);
849 m_pEngine = PFC_CreateEngine();
850 if (m_pEngine !=
null)
852 LastStatus.Status = (int)(*m_pEngine).status;
855 m_pAiEngine = PFC_CreateEngine();
856 if (m_pAiEngine !=
null)
858 LastAiStatus.Status = (int)(*m_pAiEngine).status;
863 Trace.WriteLine(ex.Message);
866 PFC_SetParam(ref m_Param,
PFCPRESETID.PRESET_IAUTO_21);
871 #if PROTECTION_ENABLED
872 if(releaseProtection) {
918 return Calc(ref imgfile, feature, -1,
null);
929 return Calc(ref bm, feature, -1,
null);
941 return Calc(ref bm, ref bmds, feature, -1,
null);
955 BitmapData bd =
null;
957 bd = LockBitmapData(ref bm);
958 if (bd.PixelFormat != PixelFormat.Format24bppRgb &&
959 bd.PixelFormat != PixelFormat.Format32bppArgb &&
960 bd.PixelFormat != PixelFormat.Format48bppRgb &&
961 bd.PixelFormat != PixelFormat.Format64bppArgb)
963 ReleaseBitmapData(ref bm, ref bd);
966 pBase = (Byte*)bd.Scan0.ToPointer();
972 switch (bd.PixelFormat)
980 im.
data = (
void*)pBase;
982 if (m_pProfile !=
null)
983 PFC_ReleaseProfile(m_pProfile);
986 if (CameraModel !=
null)
988 pModel = GetCharBuffer(CameraModel);
990 m_pProfile = PFC_Calc(&im,
null, m_pEngine, feature, ISO, pModel,
null,
null, (
int)rejectOption, m_pAiEngine);
992 FreeCharBuffer(pModel);
994 ReleaseBitmapData(ref bm, ref bd);
996 LastStatus.NR_Status = (*m_pProfile).NR_Status;
997 LastStatus.CORE_Status = (*m_pProfile).CORE_Status;
998 LastStatus.FB_Status = (*m_pProfile).FB_Status;
999 LastStatus.RE_Status = (*m_pProfile).RE_Status;
1000 LastStatus.Status = (*m_pProfile).Status;
1017 im.
width = imgfile.width();
1018 im.
height = imgfile.height();
1019 im.
stride = imgfile.stride();
1021 im.
data = (
void*)imgfile.raw_image();
1023 if (m_pProfile !=
null)
1024 PFC_ReleaseProfile(m_pProfile);
1026 byte* pModel =
null;
1027 if (CameraModel !=
null)
1029 pModel = GetCharBuffer(CameraModel);
1031 m_pProfile = PFC_Calc(&im,
null, m_pEngine, feature, ISO, pModel,
null,
null, (
int)rejectOption, m_pAiEngine);
1033 FreeCharBuffer(pModel);
1035 LastStatus.NR_Status = (*m_pProfile).NR_Status;
1036 LastStatus.CORE_Status = (*m_pProfile).CORE_Status;
1037 LastStatus.FB_Status = (*m_pProfile).FB_Status;
1038 LastStatus.RE_Status = (*m_pProfile).RE_Status;
1039 LastStatus.Status = (*m_pProfile).Status;
1055 BitmapData bd =
null;
1057 bd = LockBitmapData(ref bm);
1058 if (bd.PixelFormat != PixelFormat.Format24bppRgb &&
1059 bd.PixelFormat != PixelFormat.Format32bppArgb &&
1060 bd.PixelFormat != PixelFormat.Format48bppRgb &&
1061 bd.PixelFormat != PixelFormat.Format64bppArgb)
1063 ReleaseBitmapData(ref bm, ref bd);
1066 pBase = (Byte*)bd.Scan0.ToPointer();
1069 im.
width = bd.Width;
1072 switch (bd.PixelFormat)
1080 im.
data = (
void*)pBase;
1082 BitmapData bdds =
null;
1083 bdds = LockBitmapData(ref bmds);
1084 if (bdds.PixelFormat != PixelFormat.Format24bppRgb &&
1085 bdds.PixelFormat != PixelFormat.Format32bppArgb &&
1086 bdds.PixelFormat != PixelFormat.Format48bppRgb &&
1087 bdds.PixelFormat != PixelFormat.Format64bppArgb)
1089 ReleaseBitmapData(ref bmds, ref bdds);
1092 pBase = (Byte*)bdds.Scan0.ToPointer();
1095 imds.
width = bdds.Width;
1096 imds.
height = bdds.Height;
1097 imds.
stride = bdds.Stride;
1098 switch (bdds.PixelFormat)
1102 case PixelFormat.Format32bppArgb: imds.
format =
PFCPIXELFORMAT.PFC_PixelFormat32bppARGB;
break;
1104 case PixelFormat.Format64bppArgb: imds.
format =
PFCPIXELFORMAT.PFC_PixelFormat64bppARGB;
break;
1106 imds.
data = (
void*)pBase;
1108 if (m_pProfile !=
null)
1109 PFC_ReleaseProfile(m_pProfile);
1111 byte* pModel =
null;
1112 if (CameraModel !=
null)
1114 pModel = GetCharBuffer(CameraModel);
1116 m_pProfile = PFC_Calc(&im, &imds, m_pEngine, feature, ISO, pModel,
null,
null, 1, m_pAiEngine);
1118 FreeCharBuffer(pModel);
1120 ReleaseBitmapData(ref bm, ref bd);
1121 ReleaseBitmapData(ref bmds, ref bdds);
1123 LastStatus.NR_Status = (*m_pProfile).NR_Status;
1124 LastStatus.CORE_Status = (*m_pProfile).CORE_Status;
1125 LastStatus.FB_Status = (*m_pProfile).FB_Status;
1126 LastStatus.RE_Status = (*m_pProfile).RE_Status;
1127 LastStatus.Status = (*m_pProfile).Status;
1140 return Apply(ref bm, 100);
1150 return Apply(ref imgfile, 100);
1161 if (m_pProfile ==
null)
1166 BitmapData bd =
null;
1168 bd = LockBitmapData(ref bm);
1169 if (bd.PixelFormat != PixelFormat.Format24bppRgb &&
1170 bd.PixelFormat != PixelFormat.Format32bppArgb &&
1171 bd.PixelFormat != PixelFormat.Format48bppRgb &&
1172 bd.PixelFormat != PixelFormat.Format64bppArgb)
1174 ReleaseBitmapData(ref bm, ref bd);
1177 pBase = (Byte*)bd.Scan0.ToPointer();
1180 im.
width = bd.Width;
1183 switch (bd.PixelFormat)
1191 im.
data = (
void*)pBase;
1193 PFCAPPLYSTATUS ret = PFC_Apply(&im, m_pEngine, m_pProfile, ref m_Param,
null, iOpacity,
null);
1197 int code = (int)ret;
1199 LastStatus.NR_Status = (
PFCNR_STATUS)(code & 0x000000FF);
1200 LastStatus.CORE_Status = (
PFCCORE_STATUS)((code >> 8) & 0x000000FF);
1201 LastStatus.FB_Status = (
PFCFB_STATUS)((code >> 16) & 0x000000FF);
1202 LastStatus.RE_Status = (
PFCRE_STATUS)((code >> 24) & 0x000000FF);
1203 LastStatus.Status = code;
1206 ReleaseBitmapData(ref bm, ref bd);
1218 if (m_pProfile ==
null)
1224 im.
width = imgfile.width();
1225 im.
height = imgfile.height();
1226 im.
stride = imgfile.stride();
1228 im.
data = (
void*)imgfile.raw_image();
1230 PFCAPPLYSTATUS ret = PFC_Apply(&im, m_pEngine, m_pProfile, ref m_Param,
null, iOpacity,
null);
1234 int code = (int)ret;
1236 LastStatus.NR_Status = (
PFCNR_STATUS)(code & 0x000000FF);
1237 LastStatus.CORE_Status = (
PFCCORE_STATUS)((code >> 8) & 0x000000FF);
1238 LastStatus.FB_Status = (
PFCFB_STATUS)((code >> 16) & 0x000000FF);
1239 LastStatus.RE_Status = (
PFCRE_STATUS)((code >> 24) & 0x000000FF);
1240 LastStatus.Status = code;
1300 return AutoCorrect(ref bm, ref bmds, -1,
null,
false);
1311 public int AutoCorrect(ref Bitmap bm,
int ISO,
string CameraModel,
bool bFastFAE)
1317 int detectedCategory =
GetScene(&version);
1318 if (detectedCategory >= 0) {
1321 m_Param = categoryParam;
1369 int retInt = (((((((int)retRE << 8) | (int)retFB) << 8) | (
int)retCORE) << 8) | (int)retNR);
1393 int detectedCategory =
GetScene(&version);
1394 if (detectedCategory >= 0) {
1397 m_Param = categoryParam;
1445 int retInt = (((((((int)retRE << 8) | (int)retFB) << 8) | (
int)retCORE) << 8) | (int)retNR);
1464 public int AutoCorrect(ref Bitmap bm, ref Bitmap bmds,
int ISO,
string CameraModel,
bool bFastFAE)
1470 int detectedCategory =
GetScene(&version);
1471 if (detectedCategory >= 0) {
1474 m_Param = categoryParam;
1522 int retInt = (((((((int)retRE << 8) | (int)retFB) << 8) | (
int)retCORE) << 8) | (int)retNR);
1545 return retCode-1000;
1561 return retCode - 1000;
1571 public int AutoCorrect(ref Bitmap bm, ref Bitmap bmds,
string pathPreset)
1576 return AutoCorrect(ref bm, ref bmds, -1,
null,
false);
1578 return retCode - 1000;
1590 public int AutoCorrect(ref Bitmap bm,
string pathPreset,
int ISO,
string CameraModel,
bool bFastFAE)
1595 return AutoCorrect(ref bm, ISO, CameraModel, bFastFAE);
1597 return retCode - 1000;
1614 return AutoCorrect(ref imgfile, ISO, CameraModel, bFastFAE);
1616 return retCode - 1000;
1629 public int AutoCorrect(ref Bitmap bm, ref Bitmap bmds,
string pathPreset,
int ISO,
string CameraModel,
bool bFastFAE)
1634 return AutoCorrect(ref bm, ref bmds, ISO, CameraModel, bFastFAE);
1636 return retCode - 1000;
1645 PFC_SetParam(ref m_Param,
id);
1669 byte* presetpath =
null;
1672 presetpath = GetCharBuffer(path);
1675 int status = PFC_ReadPresets(ref m_Param, presetpath);
1679 catch (Exception ex)
1681 Trace.WriteLine(ex.Message);
1702 long len = fs.Length;
1703 byte[] buffer =
new byte[len + 1];
1704 int size = (int)len;
1705 fs.Read(buffer, 0, size);
1707 byte* b = GetCharBuffer(buffer);
1712 int status = PFC_ReadPresetsFromStream(ref m_Param, b);
1716 catch (Exception ex)
1718 Trace.WriteLine(ex.Message);
1729 return PFC_HasFaceBeautification(m_pEngine);
1739 return PFC_FBFaceCount(m_pProfile);
1753 bool ret = PFC_GetFaceInfo(m_pProfile, &fi, index);
1772 return PFC_AbnormalTintDetected(m_pProfile, eTintMethod);
1782 PFC_ApplyStrengthToParam(ref m_Param, strength);
1785 protected BitmapData LockBitmapData(ref Bitmap bm)
1787 GraphicsUnit unit = GraphicsUnit.Pixel;
1788 RectangleF boundsF = bm.GetBounds(ref unit);
1789 Rectangle bounds =
new Rectangle((
int)boundsF.X,
1792 (
int)boundsF.Height);
1794 BitmapData bitmapData =
1795 bm.LockBits(bounds, ImageLockMode.ReadWrite, bm.PixelFormat);
1799 protected void ReleaseBitmapData(ref Bitmap bm, ref BitmapData bitmapData)
1801 bm.UnlockBits(bitmapData);
1804 protected Bitmap DupBitmap(ref Bitmap bm)
1806 PerfectlyClearImageTransfer tr, tr1;
1808 GraphicsUnit unit = GraphicsUnit.Pixel;
1809 RectangleF boundsF = bm.GetBounds(ref unit);
1810 Rectangle bounds =
new Rectangle((
int)boundsF.X,
1813 (
int)boundsF.Height);
1814 BitmapData bd = bm.LockBits(bounds, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
1815 Bitmap bm1 =
new Bitmap(bd.Width, bd.Height, PixelFormat.Format24bppRgb);
1816 BitmapData bd1 = LockBitmapData(ref bm1);
1817 pBase = (Byte*)bd.Scan0.ToPointer();
1818 tr.columnBytes = (bd.PixelFormat == PixelFormat.Format24bppRgb) ? 3 : 4;
1819 tr.rowBytes = bd.Stride;
1820 tr.height = bd.Height;
1821 tr.width = bd.Width;
1822 tr.data1 = (int)(pBase + 2);
1823 tr.data2 = (int)(pBase + 1);
1824 tr.data3 = (int)pBase;
1825 pBase = (Byte*)bd1.Scan0.ToPointer();
1826 tr1.columnBytes = (bd1.PixelFormat == PixelFormat.Format24bppRgb) ? 3 : 4;
1827 tr1.rowBytes = bd1.Stride;
1828 tr1.height = bd1.Height;
1829 tr1.width = bd1.Width;
1830 tr1.data1 = (int)(pBase + 2);
1831 tr1.data2 = (int)(pBase + 1);
1832 tr1.data3 = (int)pBase;
1833 for (
int i = 0; i < tr.height; i++)
1835 for (
int j = 0; j < tr.width; j++)
1837 ((Byte*)tr1.data1)[j * tr1.columnBytes] = ((Byte*)tr.data1)[j * tr.columnBytes];
1838 ((Byte*)tr1.data2)[j * tr1.columnBytes] = ((Byte*)tr.data2)[j * tr.columnBytes];
1839 ((Byte*)tr1.data3)[j * tr1.columnBytes] = ((Byte*)tr.data3)[j * tr.columnBytes];
1841 tr.data1 += (int)tr.rowBytes;
1842 tr.data2 += (
int)tr.rowBytes;
1843 tr.data3 += (int)tr.rowBytes;
1844 tr1.data1 += (
int)tr1.rowBytes;
1845 tr1.data2 += (int)tr1.rowBytes;
1846 tr1.data3 += (
int)tr1.rowBytes;
1848 ReleaseBitmapData(ref bm1, ref bd1);
1849 ReleaseBitmapData(ref bm, ref bd);
1853 protected Bitmap BW2RGB(ref Bitmap bm)
1856 Byte* pBase1 =
null;
1857 GraphicsUnit unit = GraphicsUnit.Pixel;
1858 RectangleF boundsF = bm.GetBounds(ref unit);
1859 Rectangle bounds =
new Rectangle((
int)boundsF.X,
1862 (
int)boundsF.Height);
1863 BitmapData bd = bm.LockBits(bounds, ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);
1864 Bitmap bm1 =
new Bitmap(bd.Width, bd.Height, PixelFormat.Format24bppRgb);
1865 BitmapData bd1 = LockBitmapData(ref bm1);
1866 pBase = (Byte*)bd.Scan0.ToPointer();
1867 pBase1 = (Byte*)bd1.Scan0.ToPointer();
1868 for (
int i = 0; i < bd.Height; i++)
1870 for (
int j = 0; j < bd.Width; j++)
1872 pBase1[j * 3] = pBase[j];
1873 pBase1[j * 3 + 1] = pBase[j];
1874 pBase1[j * 3 + 2] = pBase[j];
1877 pBase1 += bd1.Stride;
1879 ReleaseBitmapData(ref bm1, ref bd1);
1880 ReleaseBitmapData(ref bm, ref bd);
1894 Bitmap myBitmap =
new Bitmap(filename);
1895 if ((myBitmap.Flags & (
int)ImageFlags.ColorSpaceYcck) != 0)
1897 bm = DupBitmap(ref myBitmap);
1902 if (myBitmap.PixelFormat == PixelFormat.Format8bppIndexed)
1904 bm = BW2RGB(ref myBitmap);
1915 protected Bitmap GetStatImage(ref Bitmap bm,
int iMaxDimension)
1918 bool bNeedResize =
true;
1925 if (w <= iMaxDimension)
1926 bNeedResize =
false;
1932 if (h <= iMaxDimension)
1933 bNeedResize =
false;
1944 Bitmap bmds =
new Bitmap(w1, h1, bm.PixelFormat);
1946 using (Graphics gr = Graphics.FromImage(bmds))
1948 gr.SmoothingMode = SmoothingMode.HighQuality;
1949 gr.InterpolationMode = InterpolationMode.HighQualityBicubic;
1950 gr.PixelOffsetMode = PixelOffsetMode.HighQuality;
1951 gr.DrawImage(bm,
new Rectangle(0, 0, w1, h1));
1959 Bitmap bmds = (Bitmap)bm.Clone();
1985 IntPtr wrapped = rect.pWrapped;
1986 IntPtr pRect = (IntPtr) PFC_EnumFAEFaceRect(m_pProfile, (
void*)wrapped);
1988 if (pRect != IntPtr.Zero) {
1991 rect.pWrapped = (IntPtr)pRect;
1995 rect.pWrapped = IntPtr.Zero;
2005 return PFC_FAEFaceCount(m_pProfile);
2017 if (binPath !=
null)
2019 path = GetCharBuffer(binPath);
2021 int result = PFC_LoadAIEngine(m_pAiEngine, aifeatures, path);
2022 m_loadedAiEngineFeatures = result;
2025 PFC_LoadAIEngine(m_pEngine,
PFCAIFEATURE.AI_CORRECTIONS, path);
2028 FreeCharBuffer(path);
2048 public unsafe
int LoadScenePresets(
string filePath,
int groupUUID = 0,
int* arrProfileUUID =
null,
int arrProfileUUIDLen = 0)
2051 if (filePath !=
null)
2053 path = GetCharBuffer(filePath);
2055 int result = PFC_LoadScenePresets(m_pAiEngine, path, groupUUID, arrProfileUUID, arrProfileUUIDLen);
2056 FreeCharBuffer(path);
2069 return PFC_ReadScenePreset(ref param, m_pAiEngine, scene);
2080 return PFC_GetScene(m_pProfile, version);
2093 return PFC_GetSceneDetectionEngineInfo(m_pAiEngine, groupUUID, arrProfileUUID, arrProfileUUIDLen);
2102 if (dirPath !=
null)
2104 path = GetCharBuffer(dirPath);
2106 PFC_SetAddonPath(path);
2107 FreeCharBuffer(path);
2110 public void Dispose()
2113 GC.SuppressFinalize(
this);
2116 protected virtual void Dispose(
bool disposing)
2122 if (m_pProfile !=
null)
2124 PFC_ReleaseProfile(m_pProfile);
2128 if (m_pEngine !=
null)
2130 PFC_DestroyEngine(m_pEngine);
2134 if (m_pAiEngine !=
null)
2136 PFC_DestroyEngine(m_pAiEngine);
2141 static protected byte* GetCharBuffer(
byte[] s)
2143 int i, iCount = s.Length;
2144 IntPtr _memory = IntPtr.Zero;
2145 _memory = Marshal.AllocHGlobal(iCount + 1);
2146 byte* p = (
byte*)_memory;
2147 for (i = 0; i < iCount; i++)
2156 static protected byte* GetCharBuffer(
string s)
2158 int i, iCount = s.Length;
2159 IntPtr _memory = IntPtr.Zero;
2160 _memory = Marshal.AllocHGlobal(iCount + 1);
2161 byte* p = (
byte*)_memory;
2162 for (i = 0; i < iCount; i++)
2171 static protected void FreeCharBuffer(
byte* p)
2173 IntPtr _memory = (IntPtr)p;
2174 Marshal.FreeHGlobal(_memory);
2178 [DllImport(
"PerfectlyClearPro")]
2179 static extern int PFC_SetProtectionPath(
byte* path,
byte* licenseCode);
2181 [DllImport(
"PerfectlyClearPro")]
2182 static extern void PFC_ReleaseProtectionPath();
2184 [DllImport(
"PerfectlyClearPro")]
2185 static extern PFCENGINE* PFC_CreateEngine();
2187 [DllImport(
"PerfectlyClearPro")]
2188 static extern void PFC_DestroyEngine(
PFCENGINE* p);
2190 [DllImport(
"PerfectlyClearPro")]
2193 [DllImport(
"PerfectlyClearPro")]
2194 static extern int PFC_ReadPresets(ref
PFCPARAM param,
byte* filename);
2196 [DllImport(
"PerfectlyClearPro")]
2197 static extern int PFC_ReadPresetsFromStream(ref
PFCPARAM param,
byte* s);
2199 [DllImport(
"PerfectlyClearPro")]
2202 [DllImport(
"PerfectlyClearPro")]
2203 static extern void PFC_ReleaseProfile(
void* pProfile);
2205 [DllImport(
"PerfectlyClearPro")]
2208 [DllImport(
"PerfectlyClearPro")]
2209 static extern bool PFC_HasFaceBeautification(
PFCENGINE* pEngine);
2211 [DllImport(
"PerfectlyClearPro")]
2212 static extern int PFC_FBFaceCount(
void* pImageProfile);
2214 [DllImport(
"PerfectlyClearPro")]
2215 static extern bool PFC_GetFaceInfo(
void* pImageProfile, PFCFBFACEINFO1* pFace,
int index);
2217 [DllImport(
"PerfectlyClearPro")]
2218 static extern bool PFC_AbnormalTintDetected(
void* pImageProfile,
TINTCORRECTION eTintMethod);
2220 [DllImport(
"PerfectlyClearPro")]
2221 static extern void PFC_ApplyStrengthToParam(ref
PFCPARAM param,
int strength);
2223 [DllImport(
"PerfectlyClearPro")]
2224 static extern void* PFC_EnumFAEFaceRect(
void *pImageProfile,
void* p);
2226 [DllImport(
"PerfectlyClearPro")]
2227 static extern int PFC_FAEFaceCount(
void* pImageProfile);
2229 [DllImport(
"PerfectlyClearPro")]
2232 [DllImport(
"PerfectlyClearPro")]
2233 static extern int PFC_LoadScenePresets(
PFCENGINE* pEngine,
byte *filePath,
int groupUUID,
int *arrProfileUUID,
int arrProfileUUIDLen);
2235 [DllImport(
"PerfectlyClearPro")]
2236 static extern int PFC_ReadScenePreset(ref
PFCPARAM param,
PFCENGINE *pEngineAI,
int scene);
2238 [DllImport(
"PerfectlyClearPro")]
2239 static extern int PFC_GetScene(
void* precalc,
int *version);
2241 [DllImport(
"PerfectlyClearPro")]
2242 static extern bool PFC_GetSceneDetectionEngineInfo(
PFCENGINE* pEngine,
int* groupUUID,
int* arrProfileUUID,
int *arrProfileUUIDLen);
2244 [DllImport(
"PerfectlyClearPro")]
2245 static extern void PFC_SetAddonPath(
byte* path);
2249 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2250 static extern int PFC_SetProtectionPath(
byte* path,
byte* licenseCode);
2252 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2253 static extern void PFC_ReleaseProtectionPath();
2255 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2256 static extern PFCENGINE* PFC_CreateEngine();
2258 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2259 static extern void PFC_DestroyEngine(
PFCENGINE* p);
2261 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2264 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2265 static extern int PFC_ReadPresets(ref
PFCPARAM param,
byte* filename);
2267 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2268 static extern int PFC_ReadPresetsFromStream(ref
PFCPARAM param,
byte* s);
2270 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2273 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2274 static extern void PFC_ReleaseProfile(
void* pProfile);
2276 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2279 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2280 static extern bool PFC_HasFaceBeautification(
PFCENGINE* pEngine);
2282 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2283 static extern int PFC_FBFaceCount(
void* pImageProfile);
2285 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2286 static extern bool PFC_GetFaceInfo(
void* pImageProfile, PFCFBFACEINFO1* pFace,
int index);
2288 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2289 static extern bool PFC_AbnormalTintDetected(
void* pImageProfile,
TINTCORRECTION eTintMethod);
2291 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2292 static extern void PFC_ApplyStrengthToParam(ref
PFCPARAM param,
int strength);
2294 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2295 static extern void* PFC_EnumFAEFaceRect(
void *pImageProfile,
void* p);
2297 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2298 static extern int PFC_FAEFaceCount(
void* pImageProfile);
2300 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2303 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2304 static extern int PFC_LoadScenePresets(
PFCENGINE* pEngine,
byte *filePath,
int groupUUID,
int *arrProfileUUID,
int arrProfileUUIDLen);
2306 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2307 static extern int PFC_ReadScenePreset(ref
PFCPARAM param,
PFCENGINE *pEngineAI,
int scene);
2309 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2310 static extern int PFC_GetScene(
void* precalc,
int *version);
2312 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2313 static extern bool PFC_GetSceneDetectionEngineInfo(
PFCENGINE* pEngine,
int* groupUUID,
int* arrProfileUUID,
int* arrProfileUUIDLen);
2315 [DllImport(
"PerfectlyClearPro", CallingConvention = CallingConvention.Cdecl)]
2316 static extern void PFC_SetAddonPath(
byte* path);
2358 private IntPtr m_pNativeObject;
2363 m_pNativeObject = create_PFCImageFile();
2366 public void Dispose()
2371 protected virtual void Dispose(
bool bDisposing)
2373 if (this.m_pNativeObject != IntPtr.Zero)
2375 delete_PFCImageFile(m_pNativeObject);
2376 m_pNativeObject = IntPtr.Zero;
2383 GC.SuppressFinalize(
this);
2417 if (filename ==
null)
2422 byte* pFilename = GetCharBuffer(filename);
2424 byte* pIccFolderPath =
null;
2425 if (iccFolderPath !=
null)
2427 pIccFolderPath = GetCharBuffer(iccFolderPath);
2430 int result = PFCImageFile_LoadImageFile(m_pNativeObject, pFilename, bConvertToSRGB, pIccFolderPath);
2432 FreeCharBuffer(pFilename);
2433 FreeCharBuffer(pIccFolderPath);
2448 if (filename ==
null)
2453 byte* pFilename = GetCharBuffer(filename);
2455 byte* pIccFolderPath =
null;
2456 if (iccFolderPath !=
null)
2458 pIccFolderPath = GetCharBuffer(iccFolderPath);
2461 int result = PFCImageFile_LoadImageFileType(m_pNativeObject, pFilename, (
int)type, bConvertToSRGB, pIccFolderPath);
2463 FreeCharBuffer(pFilename);
2464 FreeCharBuffer(pIccFolderPath);
2476 public bool SaveImageFile(
string filename,
int jpegQuality = 92,
bool bConvertToOriginalColorSpace=
true,
bool bEmbedOriginalMetadata =
true)
2478 if (filename ==
null)
2483 byte* pFilename = GetCharBuffer(filename);
2485 bool result = PFCImageFile_SaveImageFile(m_pNativeObject, pFilename, jpegQuality, bConvertToOriginalColorSpace, bEmbedOriginalMetadata);
2487 FreeCharBuffer(pFilename);
2500 public bool SaveImageFile(
string filename,
PFC_FILETYPE type,
int jpegQuality = 92,
bool bConvertToOriginalColorSpace =
true,
bool bEmbedOriginalMetadata =
true)
2502 if (filename ==
null)
2507 byte* pFilename = GetCharBuffer(filename);
2509 bool result = PFCImageFile_SaveImageFileType(m_pNativeObject, pFilename, (
int)type, jpegQuality, bConvertToOriginalColorSpace, bEmbedOriginalMetadata);
2511 FreeCharBuffer(pFilename);
2516 public void AllocBuffer(
int width,
int height,
int bytes_per_pixel,
int stride)
2518 PFCImageFile_AllocBuffer(m_pNativeObject, width, height, bytes_per_pixel, stride);
2521 public int pfcImageFormat()
2523 return PFCImageFile_pfcImageFormat(m_pNativeObject);
2526 public int exifOrientation()
2528 return PFCImageFile_exifOrientation(m_pNativeObject);
2531 public byte* raw_image()
2533 return PFCImageFile_get_raw_image(m_pNativeObject);
2538 return PFCImageFile_get_width(m_pNativeObject);
2543 return PFCImageFile_get_height(m_pNativeObject);
2546 public int bytes_per_pixel()
2548 return PFCImageFile_get_bytes_per_pixel(m_pNativeObject);
2553 return PFCImageFile_get_stride(m_pNativeObject);
2556 public bool sourceSRGB()
2558 return PFCImageFile_get_sourceSRGB(m_pNativeObject);
2571 byte* buffer = GetByteBuffer(inStream.ToArray());
2572 byte* pIccFolderPath =
null;
2573 if (iccFolderPath !=
null)
2575 pIccFolderPath = GetCharBuffer(iccFolderPath);
2577 int result = PFCImageFile_ExpandImageBuffer(m_pNativeObject, buffer, inStream.Length, (
int)type, bConvertToSRGB, pIccFolderPath);
2578 FreeCharBuffer(pIccFolderPath);
2579 FreeByteBuffer(buffer);
2594 byte* compressedBuffer =
null;
2595 int length = PFCImageFile_CompressImageBuffer(m_pNativeObject, &compressedBuffer, (
int)type, jpegQuality, bConvertToOriginalColorSpace, bEmbedOriginalMetadata);
2596 if (length > 0 && compressedBuffer !=
null)
2598 byte[] result =
new byte[length];
2599 Marshal.Copy((IntPtr)(compressedBuffer), result, 0, length);
2600 deleteBuffer(compressedBuffer);
2603 MemoryStream stream =
new MemoryStream();
2604 stream.Write(result, 0, result.Length);
2607 return new MemoryStream();
2610 private static byte* GetCharBuffer(
string s)
2612 UTF8Encoding utf8 =
new UTF8Encoding();
2613 Byte[] encodedBytes = utf8.GetBytes(s);
2615 int i, iCount = encodedBytes.Length;
2616 IntPtr _memory = IntPtr.Zero;
2617 _memory = Marshal.AllocHGlobal(iCount + 1);
2618 byte* p = (
byte*)_memory;
2619 for (i = 0; i < iCount; i++)
2621 p[i] = encodedBytes[i];
2628 private static void FreeCharBuffer(
byte* p)
2630 IntPtr _memory = (IntPtr)p;
2631 Marshal.FreeHGlobal(_memory);
2634 private static byte* GetByteBuffer(
byte[] bytes)
2636 int length = bytes.Length;
2637 IntPtr p = Marshal.AllocHGlobal(length);
2638 Marshal.Copy(bytes, 0, p, length);
2642 private static void FreeByteBuffer(
byte* p)
2644 IntPtr _memory = (IntPtr)p;
2645 Marshal.FreeHGlobal(_memory);
2649 [DllImport(
"PFCImageFile")]
2650 static private extern unsafe IntPtr create_PFCImageFile();
2652 [DllImport(
"PFCImageFile")]
2653 static private extern void delete_PFCImageFile(IntPtr o);
2655 [DllImport(
"PFCImageFile")]
2656 static private extern unsafe
int PFCImageFile_LoadImageFile(IntPtr o,
byte* filename,
bool bConvertToSRGB,
byte* iccFolderPath);
2658 [DllImport(
"PFCImageFile")]
2659 static private extern unsafe
int PFCImageFile_LoadImageFileType(IntPtr o,
byte* filename,
int type,
bool bConvertToSRGB,
byte* iccFolderPath);
2661 [DllImport(
"PFCImageFile")]
2662 static private extern unsafe
bool PFCImageFile_SaveImageFile(IntPtr ptr,
byte* filename,
int jpegQuality,
bool bConvertToOriginalColorSpace,
bool bEmbedOriginalMetadata);
2664 [DllImport(
"PFCImageFile")]
2665 static private extern unsafe
bool PFCImageFile_SaveImageFileType(IntPtr ptr,
byte* filename,
int type,
int jpegQuality,
bool bConvertToOriginalColorSpace,
bool bEmbedOriginalMetadata);
2667 [DllImport(
"PFCImageFile")]
2668 static private extern unsafe
void PFCImageFile_AllocBuffer(IntPtr ptr,
int width,
int height,
int bytes_per_pixel,
int stride);
2670 [DllImport(
"PFCImageFile")]
2671 static private extern unsafe
int PFCImageFile_pfcImageFormat(IntPtr ptr);
2673 [DllImport(
"PFCImageFile")]
2674 static private extern unsafe
int PFCImageFile_exifOrientation(IntPtr ptr);
2676 [DllImport(
"PFCImageFile")]
2677 static private extern unsafe
byte* PFCImageFile_get_raw_image(IntPtr ptr);
2679 [DllImport(
"PFCImageFile")]
2680 static private extern unsafe
int PFCImageFile_get_width(IntPtr ptr);
2682 [DllImport(
"PFCImageFile")]
2683 static private extern unsafe
int PFCImageFile_get_height(IntPtr ptr);
2685 [DllImport(
"PFCImageFile")]
2686 static private extern unsafe
int PFCImageFile_get_bytes_per_pixel(IntPtr ptr);
2688 [DllImport(
"PFCImageFile")]
2689 static private extern unsafe
int PFCImageFile_get_stride(IntPtr ptr);
2691 [DllImport(
"PFCImageFile")]
2692 static private extern unsafe
bool PFCImageFile_get_sourceSRGB(IntPtr ptr);
2694 [DllImport(
"PFCImageFile")]
2695 static private extern unsafe
int PFCImageFile_ExpandImageBuffer(IntPtr ptr,
byte* buffer,
long size,
int type,
bool bConvertToSRGB,
byte* iccFolderPath);
2697 [DllImport(
"PFCImageFile")]
2698 static private extern unsafe
int PFCImageFile_CompressImageBuffer(IntPtr ptr,
byte** destination,
int type,
int jpegQuality,
bool bConvertToOriginalColorSpace,
bool bEmbedOriginalMetadata);
2700 [DllImport(
"PFCImageFile")]
2701 static private extern unsafe
int deleteBuffer(
byte* buffer);
2705 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2706 static private extern unsafe IntPtr create_PFCImageFile();
2708 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2709 static private extern void delete_PFCImageFile(IntPtr o);
2711 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2712 static private extern unsafe
int PFCImageFile_LoadImageFile(IntPtr o,
byte* filename,
bool bConvertToSRGB,
byte* iccFolderPath);
2714 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2715 static private extern unsafe
int PFCImageFile_LoadImageFileType(IntPtr o,
byte* filename,
int type,
bool bConvertToSRGB,
byte* iccFolderPath);
2717 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2718 static private extern unsafe
bool PFCImageFile_SaveImageFile(IntPtr ptr,
byte* filename,
int jpegQuality,
bool bConvertToOriginalColorSpace,
bool bEmbedOriginalMetadata);
2720 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2721 static private extern unsafe
bool PFCImageFile_SaveImageFileType(IntPtr ptr,
byte* filename,
int type,
int jpegQuality,
bool bConvertToOriginalColorSpace,
bool bEmbedOriginalMetadata);
2723 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2724 static private extern unsafe
void PFCImageFile_AllocBuffer(IntPtr ptr,
int width,
int height,
int bytes_per_pixel,
int stride);
2726 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2727 static private extern unsafe
int PFCImageFile_pfcImageFormat(IntPtr ptr);
2729 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2730 static private extern unsafe
int PFCImageFile_exifOrientation(IntPtr ptr);
2732 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2733 static private extern unsafe
byte* PFCImageFile_get_raw_image(IntPtr ptr);
2735 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2736 static private extern unsafe
int PFCImageFile_get_width(IntPtr ptr);
2738 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2739 static private extern unsafe
int PFCImageFile_get_height(IntPtr ptr);
2741 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2742 static private extern unsafe
int PFCImageFile_get_bytes_per_pixel(IntPtr ptr);
2744 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2745 static private extern unsafe
int PFCImageFile_get_stride(IntPtr ptr);
2747 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2748 static private extern unsafe
bool PFCImageFile_get_sourceSRGB(IntPtr ptr);
2750 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2751 static private extern unsafe
int PFCImageFile_ExpandImageBuffer(IntPtr ptr,
byte* buffer,
long size,
int type,
bool bConvertToSRGB,
byte* iccFolderPath);
2753 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2754 static private extern unsafe
int PFCImageFile_CompressImageBuffer(IntPtr ptr,
byte** destination,
int type,
int jpegQuality,
bool bConvertToOriginalColorSpace,
bool bEmbedOriginalMetadata);
2756 [DllImport(
"PFCImageFile", CallingConvention = CallingConvention.Cdecl)]
2757 static private extern unsafe
int deleteBuffer(
byte* buffer);