日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

怎样编写一个Photoshop滤镜(3)-- Scripting Plug-ins

發布時間:2025/3/15 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 怎样编写一个Photoshop滤镜(3)-- Scripting Plug-ins 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

????????????在第一篇文章中我們建立了一個沒有UI的基本濾鏡框架,并且引入PIPL資源使之能被PS加載到菜單。在第二篇文章中我們又引入了濾鏡參數和相應的對話框資源,并且講解了對話框在濾鏡調用流程中的顯示時機。這一篇文章我們將使濾鏡支持動作記錄和回放,也就是通過添加“術語資源”,使我們的濾鏡參數被PS的腳本系統所獲知(scripting-aware),并能夠記錄和回放。

????????????從Photoshop 4.0開始引入了一個新的面板以及相應的命令和回調函數:動作面板(浮動窗口),以及Descriptor 回調函數集。動作面板是Photoshop腳本系統用于和用戶交互的接口,也是其核心所在。Photoshop 5.0擴展了動作結構,使自動化插件能夠支持可描述的Photoshop命令。(《Photoshop API Guide》第11章)

????????????關于PS的 Scripting System,其來源是 PS 對蘋果系統的事件和腳本機制的繼承和支持,PS 的開發同時針對兩種操作系統平臺。這里我們介紹如何使我們的濾鏡被PS腳本系統接納。

?

????????????首先我們需要在 r文件中增加術語資源(terminology resource)。因此首先在 pipl 資源中增加一個 HasTerminology 結構,其定義如下:

?

//這個屬性指明濾鏡是否提供了?'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;

?

????????????這個結構將被增加到 r文件的 pipl資源內。下面我們在pipl資源后面添加了 aete 資源。

????????????在此前我們在一個通用的頭文件中添加一些aete資源需要的定義:

Code_CommonDefine.h
//定義?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"

?

????????????上面我們把我們的濾鏡,濾鏡的參數都定義為了鍵,關于鍵定義,需要符合以下原則:

????????????(a)它必須由4個字符組成。不夠4個字符可以結尾用空格補足。

????????????(b)用戶定義的鍵名應該以小寫字母開頭,同時至少含有一個大寫字母。(因為全大寫,全小寫鍵名屬于Apple定義)。

????????????濾鏡的唯一標識符采用VC工具生成的GUID即可。

????????????

????????????然后我們對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 文件,內容如下:

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,這樣我們在動作面板看到的參數值就和濾鏡的對話框上的參數值是一致的。否則我們看到的將是三個參數合成后的值。

?

??????????????????最后,是濾鏡的源代碼下載鏈接:

??????????????????http://files.cnblogs.com/hoodlum1980/FillRed.rar

?

??????????????????我的相關文章:

??????????????????《怎樣編寫一個Photoshop濾鏡(1)》

??????????????????《怎樣編寫一個Photoshop濾鏡(2)》

轉載于:https://www.cnblogs.com/hoodlum1980/archive/2009/05/16/1458092.html

總結

以上是生活随笔為你收集整理的怎样编写一个Photoshop滤镜(3)-- Scripting Plug-ins的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。