




已阅读5页,还剩3页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
How to write a GIMP plug-in编写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插件基础知识,并介绍了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. 新的开发人员往往被GIMP的规模和声誉所吓倒。他们认为,编写一个插件将是一项艰巨的任务。这些文章的目标是降低这种感觉,通过展示如何轻易可以做出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. 在本部分中,我将介绍一个插件的基本元素。我们将看到如何安装插件以及如何从一个图像和直接操纵获得数据。Architecture体系结构体系结构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脚本接口是集中在程序上的数据库(PDB)。在启动时,GIMP看起来成一组预定义的脚本和插件的地方,并要求每一个新的脚本,以确定本身。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. 该插件声称自己当时的程序的数据库,并通过信息的位置,希望得到的菜单层次结构,输入参数和输出参数。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. 当一个脚本或插件要使用我们的插件,它就会通过程序的数据库,管理以透明的方式在一个方向和其他通信参数。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. 内部功能,希望得到接触插件都是包装在核心,将它们登记程序中的数据库,其次在libgimp将允许函数被称为一个正常人。This was the introduction - now, we will look closer at our first plug-in, a Hello, world!.这是介绍现在,我们将更详细地介绍我们的第一个插件,一个“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. 能够编译简单的插件GIMP,需要libgimp 头文件,以及相关的实用程序名为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. 与该实用程序,可以安装一个插件,无论是在一个私有目录( / .gimp - 2.0 /插件),或在全部的插件目录。Syntax is 语法是 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. 这个实用工具,与其他选项,也可以用来安装脚本,或者卸载插件。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. 一个GIMP插件通常能表现的三种不同的方式。它可以把图像数据,修改它并发回修改后的图像,像边缘检测。它可以生成一个图像,并把它送回去,就像一些script-fus或文件读取插件等。或者它可以得到一个图像,并处理不修改其数据,如文件保护插件。Essentials概要 #include This header makes all basic plug-in elements available to us. 这个头文件将提供给我们所有基本插件的元素。 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. 这个结构,必须有一名。它包含四个函数指针,这支名为在固定时间插件的生命。init和quit是可选的,因此可以容纳NULL值,但是最后两个函数,query和run,是强制性的。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. 每次启动GIMP时init()函数被调用。这个函数通常不使用。一些插件使用它来做一个二级搜索,不是由核心。这个函数没有使用任何标准GIMP插件,但可能是有用的插件,例如想注册一些过程有条件地存在某些文件。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()函数用的范围比较少。它被称为当GIMP即将被关闭,以使其自由的一些资源。它是用在script插件。The query() function is called the first time the plug-in is present, and then each time the plug-in changes. 被称为query()函数的插件是目前的第一次,然后每一次的插件在变化。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()函数是插件的核心。当插件被要求运行时它被访问。它获取插件名称(作为一个插件可以注册多个程序),输入参数,以及一个指向输出参数的指针,然后决定是否启动互动的方式或由一个脚本,完成所有的插件处理。它的原型是 void run (const gchar *name, gint nparams, const GimpParam *param, gint *nreturn_vals, GimpParam *return_vals); MAIN () 主函数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是一个C的宏,拥有一点黑暗魔法初始化参数。它还调用适当的PLUG_IN_INFO函数取决于时机。你的插件需要它。The query() function 查询函数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()处理程序注册和输入参数定义。这些信息是保存到加速启动时间,只有当插件被修改时刷新。 For our Hello, world! plug-in, the query function will look like this: 我们的“Hello, world!“插件,查询功能将如下: 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包含三个方面参数类型、它的名称、和一个字符串描述参数。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声明过程名称,一些描述和帮助字符串、插件应该插入的菜单路径、由插件处理的图像类型,并在结束时,输入和输出参数的数量,以及参数描述。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*”声明了图像处理类型。它可以是RGB,INDEXED或GRAY,有或没有Alpha。所以“RGB *,GRAY*”描述了RGB,RGBA、GRAY或GRAY图像类型。GIMP_PLUGIN declares this procedure to be external, and not to be executed in The GIMP core. GIMP_PLUGIN声明此过程为外部,而不是要执行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. 通过添加一个存根现在run函数,我们可以检查我们的插件有所有必要的元素,并测试它,它注册自身PDB与“Xtns - 插件的详细资料”插件。/*/ Plug-in details(插件的详细资料) Our plug-in is in the menus (我们编写的插件在菜单中)The run() function run()函数The other required function for PLUG_IN_INFO is run. The core of the plug-in stands there. 运行的为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原型)必须至少有一个相关联的值插件状态。通常,该参数将举行“GIMP_PDB_SUCCESS”。Run-modes 运行模式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. 运行一个插件有几种不同的方式,它可以运行于一个GIMP菜单如果GIMP是交互式地运行,或从脚本或批处理,或从最后的“捷径”过滤器 - 重复运行。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”输入参数可以保存这些值:“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”通常是唯一的情况下,创建一个选项对话框。否则,直接从输入参数值或从内存调用处理。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: 对于我们的测试插件,我们将简单地显示一个对话框包含一个“世界,你好!“消息。谢天谢地,这是真的很容易使用GTK +。我们的run函数可以: static void run (const gchar *na
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年事业单位工勤技能-湖南-湖南兽医防治员一级(高级技师)历年参考题库含答案解析
- 2025年事业单位工勤技能-湖南-湖南中式烹调师五级(初级工)历年参考题库典型考点含答案解析
- 2025年事业单位工勤技能-湖北-湖北医技工二级(技师)历年参考题库典型考点含答案解析
- 2025年事业单位工勤技能-湖北-湖北保安员二级(技师)历年参考题库含答案解析
- 汽车与交通设备行业:汽车安全带技术发展趋势报告
- 2025年事业单位工勤技能-浙江-浙江工程测量工四级(中级工)历年参考题库含答案解析(5套)
- 2025年生态修复工程中生态系统服务功能评估与生态修复工程技术创新
- 2025年事业单位工勤技能-河南-河南地质勘查员二级(技师)历年参考题库典型考点含答案解析
- 2025年事业单位工勤技能-河北-河北造林管护工二级(技师)历年参考题库含答案解析
- 2025年事业单位工勤技能-江苏-江苏地图绘制员五级(初级工)历年参考题库含答案解析
- 2025广东广州市从化区社区专职人员招聘33人笔试参考题库附答案解析
- 2025年内河船员考试(主推进动力装置2103·一类三管轮)历年参考题库含答案详解(5套)
- 感染性腹主动脉瘤护理
- 公司不交社保合作协议书
- 城市轨道交通工程监测技术
- 港口无人驾驶行业深度报告:奇点已至蓝海启航
- 骨灰管理员职业技能鉴定经典试题含答案
- 火锅店股东协议合同范本
- 托管老师岗前培训
- (正式版)HGT 6313-2024 化工园区智慧化评价导则
- 高尔夫基础培训ppt课件
评论
0/150
提交评论