private short PropertySetProc(uint signature, uint key, int index, IntPtr simpleProperty, Handle complexProperty) { #if DEBUG DebugUtils.Ping(DebugFlags.PropertySuite, string.Format("Sig: {0}, Key: {1}, Index: {2}", DebugUtils.PropToString(signature), DebugUtils.PropToString(key), index.ToString())); #endif if (signature != PSConstants.kPhotoshopSignature) { return(PSError.errPlugInPropertyUndefined); } switch (key) { case PSProperties.BigNudgeH: case PSProperties.BigNudgeV: case PSProperties.Caption: case PSProperties.Copyright: case PSProperties.EXIFData: case PSProperties.XMPData: case PSProperties.GridMajor: case PSProperties.GridMinor: case PSProperties.RulerOriginH: case PSProperties.RulerOriginV: case PSProperties.URL: case PSProperties.WatchSuspension: break; default: return(PSError.errPlugInPropertyUndefined); } return(PSError.noErr); }
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); }
private unsafe short PropertyGetProc(uint signature, uint key, int index, IntPtr *simpleProperty, Handle *complexProperty) { #if DEBUG DebugUtils.Ping(DebugFlags.PropertySuite, string.Format("Sig: {0}, Key: {1}, Index: {2}", DebugUtils.PropToString(signature), DebugUtils.PropToString(key), index.ToString())); #endif if (signature != PSConstants.kPhotoshopSignature) { return(PSError.errPlugInPropertyUndefined); } short error = PSError.noErr; byte[] bytes = null; switch (key) { case PSProperties.BigNudgeH: case PSProperties.BigNudgeV: error = GetSimpleProperty(simpleProperty, new Fixed16(PSConstants.Properties.BigNudgeDistance).Value); break; case PSProperties.Caption: if (complexProperty != null) { *complexProperty = HandleSuite.Instance.NewHandle(0); } break; case PSProperties.ChannelName: string name = string.Empty; switch (index) { case 0: name = Resources.RedChannelName; break; case 1: name = Resources.GreenChannelName; break; case 2: name = Resources.BlueChannelName; break; case 3: name = Resources.AlphaChannelName; break; default: return(PSError.errPlugInPropertyUndefined); } bytes = Encoding.ASCII.GetBytes(name); error = CreateComplexPropertyHandle(complexProperty, bytes); break; case PSProperties.Copyright: case PSProperties.Copyright2: error = GetSimpleProperty(simpleProperty, false); break; case PSProperties.EXIFData: case PSProperties.XMPData: if (complexProperty != null) { // If the complexProperty is not IntPtr.Zero we return a valid zero byte handle, otherwise some filters will crash with an access violation. *complexProperty = HandleSuite.Instance.NewHandle(0); } break; case PSProperties.GridMajor: error = GetSimpleProperty(simpleProperty, new Fixed16(PSConstants.Properties.GridMajor).Value); break; case PSProperties.GridMinor: error = GetSimpleProperty(simpleProperty, PSConstants.Properties.GridMinor); break; case PSProperties.ImageMode: error = GetSimpleProperty(simpleProperty, PSConstants.plugInModeRGBColor); break; case PSProperties.InterpolationMethod: error = GetSimpleProperty(simpleProperty, PSConstants.Properties.InterpolationMethod.NearestNeghbor); break; case PSProperties.NumberOfChannels: error = GetSimpleProperty(simpleProperty, numberOfChannels); break; case PSProperties.NumberOfPaths: error = GetSimpleProperty(simpleProperty, 0); break; case PSProperties.WorkPathIndex: case PSProperties.ClippingPathIndex: case PSProperties.TargetPathIndex: error = GetSimpleProperty(simpleProperty, PSConstants.Properties.NoPathIndex); break; case PSProperties.RulerUnits: error = GetSimpleProperty(simpleProperty, PSConstants.Properties.RulerUnits.Pixels); break; case PSProperties.RulerOriginH: case PSProperties.RulerOriginV: error = GetSimpleProperty(simpleProperty, new Fixed16(0).Value); break; case PSProperties.SerialString: bytes = Encoding.ASCII.GetBytes(HostSerial); error = CreateComplexPropertyHandle(complexProperty, bytes); break; case PSProperties.URL: if (complexProperty != null) { *complexProperty = HandleSuite.Instance.NewHandle(0); } break; case PSProperties.Title: case PSProperties.UnicodeTitle: string title = "temp.pdn"; // some filters just want a non empty string if (key == PSProperties.UnicodeTitle) { bytes = Encoding.Unicode.GetBytes(title); } else { bytes = Encoding.ASCII.GetBytes(title); } error = CreateComplexPropertyHandle(complexProperty, bytes); break; case PSProperties.WatchSuspension: error = GetSimpleProperty(simpleProperty, false); break; case PSProperties.DocumentWidth: error = GetSimpleProperty(simpleProperty, documentWidth); break; case PSProperties.DocumentHeight: error = GetSimpleProperty(simpleProperty, documentHeight); break; case PSProperties.ToolTips: error = GetSimpleProperty(simpleProperty, true); break; case PSProperties.HighDpi: error = GetSimpleProperty(simpleProperty, highDpi); break; default: return(PSError.errPlugInPropertyUndefined); } return(error); }
private static unsafe bool EnumPiPL(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 PiPL 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 PiPL 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 PiPL in {0}", query.fileName)); #endif return(true); } #if DEBUG short fb = Marshal.ReadInt16(lockRes); // PiPL Resources always start with 1, this seems to be Photoshop's signature #endif int version = Marshal.ReadInt32(lockRes, 2); if (version != PSConstants.LatestPiPLVersion) { #if DEBUG System.Diagnostics.Debug.WriteLine(string.Format("Invalid PiPL version in {0}: {1}, Expected version {2}", query.fileName, version, PSConstants.LatestPiPLVersion)); #endif return(true); } string entryPoint = null; string category = null; string title = null; FilterCaseInfoCollection filterInfo = null; AETEData aete = null; string enableInfo = null; int count = Marshal.ReadInt32(lockRes, 6); byte *propPtr = (byte *)lockRes.ToPointer() + 10; for (int i = 0; i < count; i++) { PIProperty *pipp = (PIProperty *)propPtr; if (pipp->vendorID != PSConstants.kPhotoshopSignature) { // The property data is padded to a 4 byte boundary. propPtr += PIProperty.SizeOf + ((pipp->propertyLength + 3) & ~3); continue; } uint propKey = pipp->propertyKey; int propertyLength = pipp->propertyLength; byte *dataPtr = propPtr + PIProperty.SizeOf; if (propKey == PIPropertyID.PIKindProperty) { if (*(uint *)dataPtr != PSConstants.FilterKind) { #if DEBUG System.Diagnostics.Debug.WriteLine(string.Format("{0} is not a valid Photoshop Filter.", query.fileName)); #endif return(true); } } else if (propKey == query.platformEntryPoint) { entryPoint = StringUtil.FromCString(dataPtr); } else if (propKey == PIPropertyID.PIVersionProperty) { int packedVersion = *(int *)dataPtr; int major = packedVersion >> 16; int minor = packedVersion & 0xffff; if (major > PSConstants.latestFilterVersion || major == PSConstants.latestFilterVersion && minor > 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, major, minor, PSConstants.latestFilterVersion, PSConstants.latestFilterSubVersion })); #endif return(true); } } else if (propKey == PIPropertyID.PIImageModesProperty) { if ((dataPtr[0] & PSConstants.flagSupportsRGBColor) != PSConstants.flagSupportsRGBColor) { #if DEBUG System.Diagnostics.Debug.WriteLine(string.Format("{0} does not support the plugInModeRGBColor image mode.", query.fileName)); #endif return(true); } } else if (propKey == PIPropertyID.PICategoryProperty) { category = StringUtil.FromPascalString(dataPtr); } else if (propKey == PIPropertyID.PINameProperty) { title = StringUtil.FromPascalString(dataPtr); } else if (propKey == PIPropertyID.PIFilterCaseInfoProperty) { FilterCaseInfoResult result = FilterCaseInfoParser.Parse(dataPtr, propertyLength); if (result != null) { filterInfo = result.filterCaseInfo; // The actual property length may be longer than the header specifies // if the FilterCaseInfo fields are incorrectly escaped. if (propertyLength != result.propertyLength) { propertyLength = result.propertyLength; } } } else if (propKey == PIPropertyID.PIHasTerminologyProperty) { PITerminology *term = (PITerminology *)dataPtr; if (term->version == PSConstants.LatestTerminologyVersion) { #if DEBUG string aeteName = StringUtil.FromCString(dataPtr + PITerminology.SizeOf); #endif aete = ParseAETEResource(hModule, term->terminologyID); } } else if (propKey == PIPropertyID.PIEnableInfoProperty) { enableInfo = StringUtil.FromCString(dataPtr); } else if (propKey == PIPropertyID.PIRequiredHostProperty) { uint host = *(uint *)dataPtr; if (host != PSConstants.kPhotoshopSignature && host != PSConstants.AnyHostSignature) { #if DEBUG System.Diagnostics.Debug.WriteLine(string.Format("{0} requires host '{1}'.", query.fileName, DebugUtils.PropToString(host))); #endif return(true); } } #if DEBUG else { DebugUtils.Ping(DebugFlags.PiPL, string.Format("Unsupported property '{0}' in {1}", DebugUtils.PropToString(propKey), query.fileName)); } #endif int propertyDataPaddedLength = (propertyLength + 3) & ~3; propPtr += PIProperty.SizeOf + propertyDataPaddedLength; } PluginData enumData = new PluginData(query.fileName, entryPoint, category, title, filterInfo, query.runWith32BitShim, aete, enableInfo); if (enumData.IsValid()) { query.plugins.Add(enumData); } return(true); }