private static unsafe bool EnumPiMI(IntPtr hModule, IntPtr lpszType, IntPtr lpszName, IntPtr lParam) { GCHandle handle = GCHandle.FromIntPtr(lParam); QueryFilter query = (QueryFilter)handle.Target; IntPtr hRes = UnsafeNativeMethods.FindResourceW(hModule, lpszName, lpszType); if (hRes == IntPtr.Zero) { #if DEBUG System.Diagnostics.Debug.WriteLine(string.Format("FindResource failed for PiMI in {0}", query.fileName)); #endif return(true); } IntPtr loadRes = UnsafeNativeMethods.LoadResource(hModule, hRes); if (loadRes == IntPtr.Zero) { #if DEBUG System.Diagnostics.Debug.WriteLine(string.Format("LoadResource failed for PiMI in {0}", query.fileName)); #endif return(true); } IntPtr lockRes = UnsafeNativeMethods.LockResource(loadRes); if (lockRes == IntPtr.Zero) { #if DEBUG System.Diagnostics.Debug.WriteLine(string.Format("LockResource failed for PiMI in {0}", query.fileName)); #endif return(true); } int length = 0; byte *ptr = (byte *)lockRes.ToPointer() + 2L; string category = StringUtil.FromCString((IntPtr)ptr, out length); ptr += length; if (string.IsNullOrEmpty(category)) { category = PSFilterHostDll.Properties.Resources.PiMIDefaultCategoryName; } PlugInInfo *info = (PlugInInfo *)ptr; if (info->version > PSConstants.latestFilterVersion || (info->version == PSConstants.latestFilterVersion && info->subVersion > PSConstants.latestFilterSubVersion)) { #if DEBUG System.Diagnostics.Debug.WriteLine(string.Format("{0} requires newer filter interface version {1}.{2} and only version {3}.{4} is supported", new object[] { query.fileName, info->version, info->subVersion, PSConstants.latestFilterVersion, PSConstants.latestFilterSubVersion })); #endif return(true); } #if GDIPLUS // All GDI+ images are converted to 8-bit RGB(A) for processing. if ((info->supportsMode & PSConstants.supportsRGBColor) != PSConstants.supportsRGBColor) { return(true); } #else if ((info->supportsMode & PSConstants.supportsRGBColor) != PSConstants.supportsRGBColor && (info->supportsMode & PSConstants.supportsGrayScale) != PSConstants.supportsGrayScale) { #if DEBUG System.Diagnostics.Debug.WriteLine(string.Format("{0} does not support the plugInModeRGBColor or plugInModeGrayScale image modes.", query.fileName)); #endif return(true); } #endif // Add the supported modes to the plug-in data as it can be used later to disable filters that do not support the image type. ushort supportedModes = 0; if ((info->supportsMode & PSConstants.supportsGrayScale) == PSConstants.supportsGrayScale) { supportedModes |= PSConstants.flagSupportsGrayScale; } if ((info->supportsMode & PSConstants.supportsRGBColor) == PSConstants.supportsRGBColor) { supportedModes |= PSConstants.flagSupportsRGBColor; } if (info->requireHost != PSConstants.kPhotoshopSignature && info->requireHost != PSConstants.AnyHostSignature) { #if DEBUG System.Diagnostics.Debug.WriteLine(string.Format("{0} requires host '{1}'.", query.fileName, DebugUtils.PropToString(info->requireHost))); #endif return(true); } IntPtr filterRes = IntPtr.Zero; fixed(char *typePtr = "_8BFM") { // Load the _8BFM resource to get the filter title. filterRes = UnsafeNativeMethods.FindResourceW(hModule, lpszName, (IntPtr)typePtr); } if (filterRes == IntPtr.Zero) { #if DEBUG System.Diagnostics.Debug.WriteLine(string.Format("FindResource failed for _8BFM in {0}", query.fileName)); #endif return(true); } IntPtr filterLoad = UnsafeNativeMethods.LoadResource(hModule, filterRes); if (filterLoad == IntPtr.Zero) { #if DEBUG System.Diagnostics.Debug.WriteLine(string.Format("LoadResource failed for _8BFM in {0}", query.fileName)); #endif return(true); } IntPtr filterLock = UnsafeNativeMethods.LockResource(filterLoad); if (filterLock == IntPtr.Zero) { #if DEBUG System.Diagnostics.Debug.WriteLine(string.Format("LockResource failed for _8BFM in {0}", query.fileName)); #endif return(true); } IntPtr resPtr = new IntPtr(filterLock.ToInt64() + 2L); string title = StringUtil.FromCString(resPtr); // The entry point number is the same as the resource number. string entryPoint = "ENTRYPOINT" + lpszName.ToInt32().ToString(CultureInfo.InvariantCulture); PluginData pluginData = new PluginData(query.fileName, entryPoint, category, title, supportedModes); if (pluginData.IsValid()) { query.plugins.Add(pluginData); handle.Target = query; lParam = GCHandle.ToIntPtr(handle); } return(true); }
private static unsafe bool EnumPiMI(IntPtr hModule, IntPtr lpszType, IntPtr lpszName, IntPtr lParam) { GCHandle handle = GCHandle.FromIntPtr(lParam); QueryFilter query = (QueryFilter)handle.Target; IntPtr hRes = UnsafeNativeMethods.FindResourceW(hModule, lpszName, lpszType); if (hRes == IntPtr.Zero) { #if DEBUG System.Diagnostics.Debug.WriteLine(string.Format("FindResource failed for PiMI in {0}", query.fileName)); #endif return(true); } IntPtr loadRes = UnsafeNativeMethods.LoadResource(hModule, hRes); if (loadRes == IntPtr.Zero) { #if DEBUG System.Diagnostics.Debug.WriteLine(string.Format("LoadResource failed for PiMI in {0}", query.fileName)); #endif return(true); } IntPtr lockRes = UnsafeNativeMethods.LockResource(loadRes); if (lockRes == IntPtr.Zero) { #if DEBUG System.Diagnostics.Debug.WriteLine(string.Format("LockResource failed for PiMI in {0}", query.fileName)); #endif return(true); } byte *ptr = (byte *)lockRes.ToPointer() + 2; string category = StringUtil.FromCString(ptr, out uint length); ptr += length; if (string.IsNullOrEmpty(category)) { category = PSFilterPdn.Properties.Resources.PiMIDefaultCategoryName; } PlugInInfo *info = (PlugInInfo *)ptr; if (info->version > PSConstants.latestFilterVersion || (info->version == PSConstants.latestFilterVersion && info->subVersion > PSConstants.latestFilterSubVersion)) { #if DEBUG System.Diagnostics.Debug.WriteLine(string.Format("{0} requires newer filter interface version {1}.{2} and only version {3}.{4} is supported", new object[] { query.fileName, info->version, info->subVersion, PSConstants.latestFilterVersion, PSConstants.latestFilterSubVersion })); #endif return(true); } if ((info->supportsMode & PSConstants.supportsRGBColor) != PSConstants.supportsRGBColor) { #if DEBUG System.Diagnostics.Debug.WriteLine(string.Format("{0} does not support the plugInModeRGBColor image mode.", query.fileName)); #endif return(true); } if (info->requireHost != PSConstants.kPhotoshopSignature && info->requireHost != PSConstants.AnyHostSignature) { #if DEBUG System.Diagnostics.Debug.WriteLine(string.Format("{0} requires host '{1}'.", query.fileName, DebugUtils.PropToString(info->requireHost))); #endif return(true); } IntPtr filterRes = IntPtr.Zero; fixed(char *typePtr = "_8BFM") { // Load the _8BFM resource to get the filter title. filterRes = UnsafeNativeMethods.FindResourceW(hModule, lpszName, (IntPtr)typePtr); } if (filterRes == IntPtr.Zero) { #if DEBUG System.Diagnostics.Debug.WriteLine(string.Format("FindResource failed for _8BFM in {0}", query.fileName)); #endif return(true); } IntPtr filterLoad = UnsafeNativeMethods.LoadResource(hModule, filterRes); if (filterLoad == IntPtr.Zero) { #if DEBUG System.Diagnostics.Debug.WriteLine(string.Format("LoadResource failed for _8BFM in {0}", query.fileName)); #endif return(true); } IntPtr filterLock = UnsafeNativeMethods.LockResource(filterLoad); if (filterLock == IntPtr.Zero) { #if DEBUG System.Diagnostics.Debug.WriteLine(string.Format("LockResource failed for _8BFM in {0}", query.fileName)); #endif return(true); } IntPtr resPtr = new IntPtr(filterLock.ToInt64() + 2L); string title = StringUtil.FromCString(resPtr, StringUtil.StringTrimOption.WhiteSpaceAndNullTerminator); // The entry point number is the same as the resource number. string entryPoint = "ENTRYPOINT" + lpszName.ToInt32().ToString(CultureInfo.InvariantCulture); PluginData enumData = new PluginData(query.fileName, entryPoint, category, title); if (enumData.IsValid()) { query.plugins.Add(enumData); } return(true); }