GIMP 添加插件.doc_第1頁(yè)
GIMP 添加插件.doc_第2頁(yè)
GIMP 添加插件.doc_第3頁(yè)
GIMP 添加插件.doc_第4頁(yè)
GIMP 添加插件.doc_第5頁(yè)
已閱讀5頁(yè),還剩3頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

How to write a GIMP plug-in編寫(xiě)gimp插件(一)Written By Dave Neary 作者:戴夫尼瑞In this article, I present GIMP plug-ins basics and introduce the libgimp API. I will also show how to use the PDB to make our plug-in available to other script authors. 在這篇文章中,我將介紹GIMP插件基礎(chǔ)知識(shí),并介紹了libgimp API。我還將展示如何使用PDB才能使插件可供其他腳本作者。Introduction介紹New developers are often intimidated by The GIMP size and its reputation. They think that writing a plug-in would be a difficult task. The goal of these articles is to dumb this feeling down, by showing how easily one can make a C plug-in. 新的開(kāi)發(fā)人員往往被GIMP的規(guī)模和聲譽(yù)所嚇倒。他們認(rèn)為,編寫(xiě)一個(gè)插件將是一項(xiàng)艱巨的任務(wù)。這些文章的目標(biāo)是降低這種感覺(jué),通過(guò)展示如何輕易可以做出C插件。In this part, I present a plug-ins basic elements. We will see how to install a plug-in and how to get data from an image and directly manipulate it. 在本部分中,我將介紹一個(gè)插件的基本元素。我們將看到如何安裝插件以及如何從一個(gè)圖像和直接操縱獲得數(shù)據(jù)。Architecture體系結(jié)構(gòu)體系結(jié)構(gòu)The GIMP script interface is centered on the Procedural database (PDB). At startup, The GIMP looks into a predefined set of places for scripts and plug-ins, and asks each new script to identify itself. GIMP腳本接口是集中在程序上的數(shù)據(jù)庫(kù)(PDB)。在啟動(dòng)時(shí),GIMP看起來(lái)成一組預(yù)定義的腳本和插件的地方,并要求每一個(gè)新的腳本,以確定本身。The plug-in declares itself to the PDB at that time, and passes informations like the position it wishes to get in the menu hierarchy, input parameters, and output parameters. 該插件聲稱(chēng)自己當(dāng)時(shí)的程序的數(shù)據(jù)庫(kù),并通過(guò)信息的位置,希望得到的菜單層次結(jié)構(gòu),輸入?yún)?shù)和輸出參數(shù)。When a script or a plug-in wants to use our plug-in, it gets through the PDB, which manages communicating parameters in one direction and the other in a transparent way. 當(dāng)一個(gè)腳本或插件要使用我們的插件,它就會(huì)通過(guò)程序的數(shù)據(jù)庫(kù),管理以透明的方式在一個(gè)方向和其他通信參數(shù)。Internal functions that wish to get exposed to plug-ins have to be packaged first in the core, that will register them in the PDB, and secondly in the libgimp that will allow the function to be called as a normal one. 內(nèi)部功能,希望得到接觸插件都是包裝在核心,將它們登記程序中的數(shù)據(jù)庫(kù),其次在libgimp將允許函數(shù)被稱(chēng)為一個(gè)正常人。This was the introduction - now, we will look closer at our first plug-in, a Hello, world!.這是介紹現(xiàn)在,我們將更詳細(xì)地介紹我們的第一個(gè)插件,一個(gè)“Hello, world!”。 Compiling the plug-in編譯插件To be able to compile simple plug-ins for The GIMP, one needs libgimp headers, as well as an associated utility named gimptool. 能夠編譯簡(jiǎn)單的插件GIMP,需要libgimp 頭文件,以及相關(guān)的實(shí)用程序名為gimptool。With that utility, one can install a plug-in either in a private directory (/.gimp-2.0/plug-ins), or in the global plug-in directory. 與該實(shí)用程序,可以安裝一個(gè)插件,無(wú)論是在一個(gè)私有目錄( / .gimp - 2.0 /插件),或在全部的插件目錄。Syntax is 語(yǔ)法是 gimptool-2.0 -install plugin.c or gimptool-2.0 -install-admin plugin.c This utility, with other options, can also be used to install scripts, or uninstall plug-ins. 這個(gè)實(shí)用工具,與其他選項(xiàng),也可以用來(lái)安裝腳本,或者卸載插件。Behaviour特性A GIMP plug-in can typically behave three different ways. It can take image data, modify it, and send back the modified image, like edge detection. It can generate an image and send it back, like some script-fus, or file reading plug-ins like jpeg. Or it can get an image, and process it without modifying its data, like a file saver plug-in. 一個(gè)GIMP插件通常能表現(xiàn)的三種不同的方式。它可以把圖像數(shù)據(jù),修改它并發(fā)回修改后的圖像,像邊緣檢測(cè)。它可以生成一個(gè)圖像,并把它送回去,就像一些script-fus或文件讀取插件等。或者它可以得到一個(gè)圖像,并處理不修改其數(shù)據(jù),如文件保護(hù)插件。Essentials概要 #include This header makes all basic plug-in elements available to us. 這個(gè)頭文件將提供給我們所有基本插件的元素。 GimpPlugInInfo PLUG_IN_INFO = init, quit, query, run ; This structure has to have that name. It contains four pointers to functions, which will be called at set times of the plug-in life. init and quit are optional, and thus can hold NULL values, but the last two functions, query and run, are mandatory. 這個(gè)結(jié)構(gòu),必須有一名。它包含四個(gè)函數(shù)指針,這支名為在固定時(shí)間插件的生命。init和quit是可選的,因此可以容納NULL值,但是最后兩個(gè)函數(shù),query和run,是強(qiáng)制性的。The init() function is called each time The GIMP starts up. This function is not typically used. Some plug-ins use it to make a secondary search that is not done by the core. This function is not used by any standard GIMP plug-in, but could be useful for example for a plug-in that would like to register some procedure conditionally on some files presence. 每次啟動(dòng)GIMP時(shí)init()函數(shù)被調(diào)用。這個(gè)函數(shù)通常不使用。一些插件使用它來(lái)做一個(gè)二級(jí)搜索,不是由核心。這個(gè)函數(shù)沒(méi)有使用任何標(biāo)準(zhǔn)GIMP插件,但可能是有用的插件,例如想注冊(cè)一些過(guò)程有條件地存在某些文件。The quit() function is not used much either. It is called when The GIMP is about to be closed, to allow it to free some resources. It is used in the script-fu plug-in. quit()函數(shù)用的范圍比較少。它被稱(chēng)為當(dāng)GIMP即將被關(guān)閉,以使其自由的一些資源。它是用在script插件。The query() function is called the first time the plug-in is present, and then each time the plug-in changes. 被稱(chēng)為query()函數(shù)的插件是目前的第一次,然后每一次的插件在變化。The run() function is the plug-ins centrepiece. It is called when the plug-in is asked to run. It gets the plug-in name (as a plug-in can register several procedures), input parameters, and a pointer to output parameters, then determines if it is launched in a interactive way or by a script, and does all the plug-in processing. Its prototype is run()函數(shù)是插件的核心。當(dāng)插件被要求運(yùn)行時(shí)它被訪問(wèn)。它獲取插件名稱(chēng)(作為一個(gè)插件可以注冊(cè)多個(gè)程序),輸入?yún)?shù),以及一個(gè)指向輸出參數(shù)的指針,然后決定是否啟動(dòng)互動(dòng)的方式或由一個(gè)腳本,完成所有的插件處理。它的原型是 void run (const gchar *name, gint nparams, const GimpParam *param, gint *nreturn_vals, GimpParam *return_vals); MAIN () 主函數(shù)MAIN is a C macro that holds a bit of dark magic to initialise arguments. It also calls the appropriate PLUG_IN_INFO function depending on the timing. Your plug-in needs it. MAIN是一個(gè)C的宏,擁有一點(diǎn)黑暗魔法初始化參數(shù)。它還調(diào)用適當(dāng)?shù)腜LUG_IN_INFO函數(shù)取決于時(shí)機(jī)。你的插件需要它。The query() function 查詢(xún)函數(shù)query() deals with the procedure registration and input arguments definition. These informations are saved to speed up startup time, and refreshed only when the plug-in is modified. Query()處理程序注冊(cè)和輸入?yún)?shù)定義。這些信息是保存到加速啟動(dòng)時(shí)間,只有當(dāng)插件被修改時(shí)刷新。 For our Hello, world! plug-in, the query function will look like this: 我們的“Hello, world!“插件,查詢(xún)功能將如下: static void query (void) static GimpParamDef args = GIMP_PDB_INT32, run-mode, Run mode , GIMP_PDB_IMAGE, image, Input image , GIMP_PDB_DRAWABLE, drawable, Input drawable ; gimp_install_procedure ( plug-in-hello, Hello, world!, Displays Hello, world! in a dialog, David Neary, Copyright David Neary, 2004, _Hello world., RGB*, GRAY*, GIMP_PLUGIN, G_N_ELEMENTS (args), 0, args, NULL); gimp_plugin_menu_register (plug-in-hello, /Filters/Misc); * GimpParamDef contains three things - the parameter type, its name, and a string describing the parameter. GimpParamDef包含三個(gè)方面參數(shù)類(lèi)型、它的名稱(chēng)、和一個(gè)字符串描述參數(shù)。gimp_install_procedure declares the procedure name, some description and help strings, menu path where the plug-in should sit, image types handled by the plug-in, and at the end, input and output parameters number, as well as the parameters descriptors. gimp_install_procedure聲明過(guò)程名稱(chēng),一些描述和幫助字符串、插件應(yīng)該插入的菜單路徑、由插件處理的圖像類(lèi)型,并在結(jié)束時(shí),輸入和輸出參數(shù)的數(shù)量,以及參數(shù)描述。RGB*, GRAY* declares the image types handled. It can be RGB, INDEXED or GRAY, with or without Alpha. So RGB*, GRAY* describes RGB, RGBA, GRAY or GRAY image type. “RGB *,GRAY*”聲明了圖像處理類(lèi)型。它可以是RGB,INDEXED或GRAY,有或沒(méi)有Alpha。所以“RGB *,GRAY*”描述了RGB,RGBA、GRAY或GRAY圖像類(lèi)型。GIMP_PLUGIN declares this procedure to be external, and not to be executed in The GIMP core. GIMP_PLUGIN聲明此過(guò)程為外部,而不是要執(zhí)行GIMP核心。By adding a stub run function now, we can check that our plug-in has all the essential elements, and test that it registers itself in the PDB with the Xtns-Plug-in Details plug-in. 通過(guò)添加一個(gè)存根現(xiàn)在run函數(shù),我們可以檢查我們的插件有所有必要的元素,并測(cè)試它,它注冊(cè)自身PDB與“Xtns - 插件的詳細(xì)資料”插件。/*/ Plug-in details(插件的詳細(xì)資料) Our plug-in is in the menus (我們編寫(xiě)的插件在菜單中)The run() function run()函數(shù)The other required function for PLUG_IN_INFO is run. The core of the plug-in stands there. 運(yùn)行的為PLUG_IN_INFO其他所需的功能。核心的插件,就在那里。Output values (return_vals in the prototype) must have at least one value associated - the plug-in status. Typically, this parameter will hold GIMP_PDB_SUCCESS. 輸出值(return_vals原型)必須至少有一個(gè)相關(guān)聯(lián)的值插件狀態(tài)。通常,該參數(shù)將舉行“GIMP_PDB_SUCCESS”。Run-modes 運(yùn)行模式One can run a plug-in in several different ways, it can be run from a GIMP menu if The GIMP is run interactively, or from a script or a batch, or from the Filters-Repeat Last shortcut. 運(yùn)行一個(gè)插件有幾種不同的方式,它可以運(yùn)行于一個(gè)GIMP菜單如果GIMP是交互式地運(yùn)行,或從腳本或批處理,或從最后的“捷徑”過(guò)濾器 - 重復(fù)運(yùn)行。The run_mode input parameter can hold one of these values: GIMP_RUN_INTERACTIVE, GIMP_RUN_NONINTERACTIVE or GIMP_RUN_WITH_LAST_VALS. “run_mode”輸入?yún)?shù)可以保存這些值:“GIMP_RUN_INTERACTIVE”、“GIMP_RUN_NONINTERACTIVE”或“GIMP_RUN_WITH_LAST_VALS”。GIMP_RUN_INTERACTIVE is typically the only case where one creates an options dialog. Otherwise, one directly calls the processing with values from input parameters or from memory. “GIMP_RUN_INTERACTIVE”通常是唯一的情況下,創(chuàng)建一個(gè)選項(xiàng)對(duì)話框。否則,直接從輸入?yún)?shù)值或從內(nèi)存調(diào)用處理。For our test plug-in, we will simply display a dialog containing a Hello, world! message. Thankfully, this is really easy with GTK+. Our run function could be: 對(duì)于我們的測(cè)試插件,我們將簡(jiǎn)單地顯示一個(gè)對(duì)話框包含一個(gè)“世界,你好!“消息。謝天謝地,這是真的很容易使用GTK +。我們的run函數(shù)可以: static void run (const gchar *na

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論