Debian Codegraph @

tools/smooth/plugins/README

raw
1 README: how to write your plugins
2 =================================
3
4 1. Introduction
5 This readme file is aimed at helping you create new plugins for smooth.
6 You can use plugin_randomize.c as a base to get you started. Please
7 submit your plugins to [email protected] for inclusion in this
8 package.
9
10 2. Plugins
11 Plugins must have at least 4 special functions, one called
12 plugin_parse(), one called plugin_apply(), one called init_plugin()
13 and one called deinit_plugin() and must have in the "#include" one for
14 "../globals.h" (found in the source for smooth)
15
16 init_plugin() is called first and should be used to set a local
17 variable of type glob_statics with what is passed in its parameters
18 (which is the main's glob_statics struct).
19 The function plugin_parse will then be called by main and will be given as
20 parameter a string (that is a "char *") representing 1 (one) line from
21 the config file that is found in the section [your_plugin]. The return
22 value is an integer, which is < 0 when a problem occur (like a
23 mistyped string).
24 The function plugin_apply will be called with a 6 char string
25 containing the hex value for the colour being transformed from and
26 must return a 6 char string containing the hex valur for the colour
27 being transformed to as well as a copy of glob_variables which is a
28 structure holding all the global data that change a lot, like the
29 global_x and the global_y and the image_out SDL_Surface.
30 At unload time, the deinit_function will be automatically called. It
31 could be used for doing reporting for instance.
32
33 3. Inner workings
34 Whenever the config file parser see a strings starting with
35 [plugin_name], it will load the library "libsmooth_plugin_name.so",
36 call it's init_plugin() with the glob_statics as a parameter and
37 call its plugin_parse() function for each line of config read from now
38 on until the next [section]. It is then important that you use this
39 function to prepare your structures so that when plugin_apply is
40 called with a colour as a parameter, you will know what colour to
41 return. It might be possible that not preparation work is involved
42 depending on the type of plugin you are writing; in this case simply
43 return a value > 0. Note that this case should be very rare.
44 When the config file as been entirely parsed, the program will walk
45 across the map, pixel by pixel, retrieve the colour index for this
46 pixel, and use this index to get the head of the chained list holding
47 the address of the plugin_apply()s to apply against this pixel. The
48 result from the calls to plugin_apply()s is a colour which is then put
49 on the output image, even if the colour does not exist in the original
50 image. Eventually, when all is done, a new palette is created to
51 reflect the fact new colours might have been added to the image.
52 All in all, the only thing you have to worry about is:
53 * initialising your plugin's global variables
54 * parsing the config file line given in plugin_parse (see
55 plugin_randomize.c for getting ideas on how I did it)
56 * be prepared to return a hex colour when given a colour as a
57 parameter.
58
59 It seems that knowing what colour we want to transform from is not
60 enough. That's why you also have access to the coordinates for the
61 pixel being transformed. image_in, global_x and global_y are global
62 variables accessed through a structure passed to plugin_apply.
63
64 For instance, if your plugin requires knowing the colour value on the
65 direct left of the pixel being transformed, you could use
66 getpixel(g_vars.image_in,g_vars.global_x+1,g_vars.global_y). Of
67 course, you need to check if g_vars.global_x+1 is still in
68 the boundaries of the image and you need to write your own getpixel function.
69
70 Don't be afraid to look at plugin_randomize.c to get an idea on how to
71 start your plugin. In case you are really stomped, just email me at:
72 Artaxerxes2 at iname dot com
73
74 Written by Artaxerxes2 at iname dot com
75 =======================================