In the first article, we established a basic filter framework without UI, and introduced PIPL resources to be loaded to the menu by PS. In the second article, we introduced filter parameters and corresponding dialog box resources, and explained the display timing of the dialog box in the filter calling process. In this article, we will make the filter support action recording and playback, that is, by adding a "term resource", our filter parameters will be known to the PS scripting system (scripting-aware), and can be recorded and played back.
Starting from Photoshop 4.0, a new panel and corresponding commands and callback functions have been introduced: Action Panel (floating window), and Descriptor callback function set. The action panel is the interface used by the Photoshop scripting system to interact with users, and is also its core. Photoshop 5.0 extends the action structure to enable automation plug-ins to support descriptive Photoshop commands. (Chapter 11 of "Photoshop API Guide")
About PS's Scripting System, its source is PS's inheritance and support of the event and scripting mechanism of Apple system. PS is developed for both operating system platforms. Here we introduce how to make our filters accepted by the PS script system.
First we need to add terminology resource to the r file. Therefore, first add a HasTerminology structure to the pipl resource, which is defined as follows:
//这个属性指明滤镜是否提供了 'aete'资源。 typedef struct HasTerminology { int32 classID; // classID from 'aete' int32 eventID; // eventID from 'aete' or NULL if none int16 aeteResNum; // number of 'aete' resource CString uniqueID; // unique ID string (UUID or your own ™/©). If present, ignores AppleScript and keeps local to Photoshop. } HasTerminology;
This structure will be added to the pipl resource of the r file. Below we add the aete resource after the pipl resource.
Previously we added some definitions required for aete resources in a common header file:
//定义 Scripting Keys #define KEY_FILLCOLOR 'fiCo' #define KEY_OPACITY 'opcA' #define plugInSuiteID 'filR' #define plugInClassID 'filR' #define plugInEventID 'filR' #define plugInUniqueID "18EC4E8F-DB34-4aff-AF99-77C8013BD74F" #define plugInAETEComment "FillRed example filter By hoodlum1980" #define vendorName "hoodlum1980"
然后我们对r文件增加aete 资源,aete 资源模板如下:
resource 'aete' (0) { // aete version and language specifiers { /* suite descriptor */ { /* filter/selection/color picker descriptor */ { /* any parameters */ / * additional parameters */ } }, { /* import/export/format descriptors */ { /* properties. First property defines inheritance. */ /* any properties */ }, { /* elements. Not supported for plug-ins. */ }, /* class descriptions for other classes used as parameters or properties */ }, { /* comparison ops. Not currently supported. */ }, { /* any enumerations */ { /* additional values for enumeration */ }, /* any additional enumerations */ /* variant types are a special enumeration: */ { /* additional types for variant */ }, /* any additional variants */ /* class and reference types are a special enumeration: */ { }, /* any additional class or reference types */ } } }
请注意的是这是一个针对PS插件的aete资源模板,也就是说它不仅仅针对滤镜,也包括其他种类的PS插件。关于其具体含义这里我们不做详细讨论,可以参考相关PS SDK文档。
【注意】即使有的节不需要,也必须提供一个空的花括号占位,而不能有缺失。
下面我们给出添加了aete资源后的 FillRed.r 文件,内容如下:
// ADOBE SYSTEMS INCORPORATED // Copyright 1993 - 2002 Adobe Systems Incorporated // All Rights Reserved // // NOTICE: Adobe permits you to use, modify, and distribute this // file in accordance with the terms of the Adobe license agreement // accompanying it. If you have received this file from a source // other than Adobe, then your use, modification, or distribution // of it requires the prior written permission of Adobe. //------------------------------------------------------------------------------- #define plugInName "FillRed Filter" #define plugInCopyrightYear "2009" #define plugInDescription \ "FillRed Filter.\n\t - http:\\www.cnblogs.com\hoodlum1980" #include "E:\Codes\Adobe Photoshop CS2 SDK\samplecode\common\includes\PIDefines.h" #ifdef __PIMac__ #include "Types.r" #include "SysTypes.r" #include "PIGeneral.r" #include "PIUtilities.r" #include "DialogUtilities.r" #include "CommonDefine.h" /* 包含了术语定义 */ #elif defined(__PIWin__) #define Rez #include "PIGeneral.h" #include "E:\Codes\Adobe Photoshop CS2 SDK\samplecode\common\resources\PIUtilities.r" #include "E:\Codes\Adobe Photoshop CS2 SDK\samplecode\common\resources\WinDialogUtils.r" #include "CommonDefine.h" /* 包含了术语定义 */ #endif #include "PITerminology.h" #include "PIActions.h" /* 包含对 NO_REPLY 的定义 */ resource 'PiPL' ( 16000, "FillRed", purgeable ) { { Kind { Filter }, Name { plugInName }, Category { "Demo By hoodlum1980" }, Version { (latestFilterVersion << 16) | latestFilterSubVersion }, #ifdef __PIWin__ CodeWin32X86 { "PluginMain" }, #else CodeMachOPowerPC { 0, 0, "PluginMain" }, #endif SupportedModes { noBitmap, doesSupportGrayScale, noIndexedColor, doesSupportRGBColor, doesSupportCMYKColor, doesSupportHSLColor, doesSupportHSBColor, doesSupportMultichannel, doesSupportDuotone, doesSupportLABColor }, HasTerminology { plugInClassID, plugInEventID, 16000, /* int16 aeteResNum; number of 'aete' resource */ plugInUniqueID }, EnableInfo { "in (PSHOP_ImageMode, RGBMode," "CMYKMode, HSLMode, HSBMode, " "DuotoneMode, LabMode)" }, PlugInMaxSize { 2000000, 2000000 }, FilterCaseInfo { { /* array: 7 elements */ /* Flat data, no selection */ inStraightData, outStraightData, doNotWriteOutsideSelection, doesNotFilterLayerMasks, doesNotWorkWithBlankData, copySourceToDestination, /* Flat data with selection */ inStraightData, outStraightData, doNotWriteOutsideSelection, doesNotFilterLayerMasks, doesNotWorkWithBlankData, copySourceToDestination, /* Floating selection */ inStraightData, outStraightData, doNotWriteOutsideSelection, doesNotFilterLayerMasks, doesNotWorkWithBlankData, copySourceToDestination, /* Editable transparency, no selection */ inStraightData, outStraightData, doNotWriteOutsideSelection, doesNotFilterLayerMasks, doesNotWorkWithBlankData, copySourceToDestination, /* Editable transparency, with selection */ inStraightData, outStraightData, doNotWriteOutsideSelection, doesNotFilterLayerMasks, doesNotWorkWithBlankData, copySourceToDestination, /* Preserved transparency, no selection */ inStraightData, outStraightData, doNotWriteOutsideSelection, doesNotFilterLayerMasks, doesNotWorkWithBlankData, copySourceToDestination, /* Preserved transparency, with selection */ inStraightData, outStraightData, doNotWriteOutsideSelection, doesNotFilterLayerMasks, doesNotWorkWithBlankData, copySourceToDestination } } } }; resource 'aete' (16000, "FillRed dictionary", purgeable) { 1, 0, english, roman, /* aete version and language specifiers */ { vendorName, /* vendor suite name */ "FillRed Demo By hoodlum1980", /* optional description */ plugInSuiteID, /* suite ID */ 1, /* suite code, must be 1 */ 1, /* suite level, must be 1 */ { /* structure for filters */ plugInName, /* unique filter name */ plugInAETEComment, /* optional description */ plugInClassID, /* class ID, must be unique or Suite ID */ plugInEventID, /* event ID, must be unique to class ID */ NO_REPLY, /* never a reply */ IMAGE_DIRECT_PARAMETER, /* direct parameter, used by Photoshop */ { /* parameters here, if any */ "FillColor", /* parameter name */ KEY_FILLCOLOR, /* parameter key ID */ typeInteger, /* parameter type ID */ "Fill color in RGB", /* optional description */ flagsSingleParameter, /* parameter flags */ "Opacity", /* optional parameter */ KEY_OPACITY, /* key ID */ typeInteger, /* type */ "opacity in RGB", /* optional desc */ flagsSingleParameter /* parameter flags */ } }, { /* non-filter plug-in class here */ }, { /* comparison ops (not supported) */ }, { /* any enumerations */ } } };
在上面的文件中,我们可以看到我们的滤镜含有的两个主要参数:填充颜色 和 不透明度。位于 IMAGE_DIRECT_PARAMETER 结构中,typeInteger 指明它们是整数类型。flagsSingleParameter指明它们是基本类型(具有单一值)。此外,还可以把参数定义为枚举类型,同时把枚举的值域定义放在最后一节中,这里我们对此不做介绍了。
滤镜被重新编译后,我们在PS中对它录制一个动作,命名为“测试 FillRed”,录制完成后,可以看到在动作面板上的左侧,出现了对话框选项的CheckBox,我们可以设置播放时是否弹出对话框。我们把FillRed滤镜命令的下拉列表展开可以看到滤镜参数:
FillColor: 10
Opacity:90
请注意参数的名字就是来自于上面的aete资源中的定义的滤镜参数名字属性,这就是我们需要给它定义一个可读的参数名的原因。需要注意的是,由于我们把对话框上三个参数合成为了一个参数,这就使得上面的参数显示是三个参数的合成值(10进制)。因此这里为了看清楚,我就只设置了 R 和 O1,其他参数都为0,这样我们在动作面板看到的参数值就和滤镜的对话框上的参数值是一致的。否则我们看到的将是三个参数合成后的值。
更多怎样编写一个Photoshop滤镜-- Scripting Plug-ins相关文章请关注PHP中文网!

In Photoshop, the role of layer masks is to allow hidden or displayed portions of layers in a non-destructive manner. 1. The working principle of layer mask is to control the visibility of the layer through black, white and grayscale. 2. The basic usage includes image synthesis, such as synthesising the character image into a new background. 3. Advanced usage can be achieved by using gradient masks to achieve smooth image transition.

Photoshop's powerful features include smart objects and neural filters, while free alternatives such as GIMP, Krita and Photopea do well in specific fields such as GIMP's layer functionality, Krita's digital paintings and online editing of Photopea.

Color adjustment in Photoshop can be achieved through adjustment layers to make the image more professional. 1. Use color level, curve, hue/saturation and other tools to adjust the hue, saturation and brightness. 2. Apply LUT to create unique color effects. 3. Use adjustment layers to avoid image distortion and use the History panel to track adjustment steps.

Photoshop's applications in the real world include artistic creation, scientific research and commercial marketing. 1) In artistic creation, it is used for digital painting and illustration. 2) In scientific research, it is used for image processing and data visualization. 3) In commercial marketing, it is used for advertising design and brand image shaping. The versatility of this software makes it widely used in various fields.

Adobe Photoshop goes beyond simple editing and becomes a creative tool for artists and designers. 1) It provides a wealth of tools such as brushes, stamp tools, blend modes and layer styles, supporting adjustments from basic images to complex digital paintings and 3D designs. 2) These tools implement functions through pixel-level operations, allowing users to create unique visual effects.

Photoshop offers two pricing models: single purchase and subscription service. 1. Single purchase: Pay $699 in one lump sum, permanent use, but no updates and cloud services. 2. Subscription service: $20.99 per month or $239.88 per year, and the latest version and cloud services are available. 3. Enterprise plan: $33.99 per user per month, including team management and additional cloud storage. 4. Educational Offer: Students and teachers are $19.99 per month, including multiple CreativeCloud applications.

The method to create a new layer in Photoshop is: 1. Click the "New Layer" button at the bottom of the layer panel; 2. Use the shortcut keys Ctrl Shift N (Windows) or Command Shift N (Mac). The layers are like transparent sheets on canvas, allowing design elements to be managed separately, non-destructive editing and experimenting, and improving design levels.

Photoshop is widely used in the fields of image processing and digital art, and is suitable for photo editing and digital art creation. 1. Photo editing: Adjust brightness and contrast Use the "Brightness/Contrast" tool. 2. Digital art: Use brush tools to create paintings. 3. Basic usage: Use the "Red Eye Tool" to remove red eyes. 4. Advanced usage: Use layers and masks for image synthesis. 5. Debug: Recover the lost layers by checking the layer panel. 6. Performance optimization: Adjust memory usage to improve running speed.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SublimeText3 Linux new version
SublimeText3 Linux latest version

Zend Studio 13.0.1
Powerful PHP integrated development environment
