File: operation_reference.c

package info (click to toggle)
gegl 0.0.18-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 6,784 kB
  • ctags: 4,389
  • sloc: ansic: 45,496; sh: 9,223; ruby: 1,361; makefile: 740; cpp: 509; xml: 256
file content (360 lines) | stat: -rw-r--r-- 11,158 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
#include "config.h"

#include <gegl-plugin.h>  /* needed to do full introspection */
#include <stdio.h>
#include <string.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif

static GList *
gegl_operations_build (GList *list, GType type)
{
  GeglOperationClass *klass;
  GType *ops;
  guint  children;
  gint   no;

  if (!type)
    return list;

  klass = g_type_class_ref (type);
  if (klass->name != NULL)
    list = g_list_prepend (list, klass);

  ops = g_type_children (type, &children);

  for (no=0; no<children; no++)
    {
      list = gegl_operations_build (list, ops[no]);
    }
  if (ops)
    g_free (ops);
  return list;
}

static gint compare_operation_names (gconstpointer a,
                                     gconstpointer b)
{
  const GeglOperationClass *klassA, *klassB;

  klassA = a;
  klassB = b;

  return strcmp (klassA->name, klassB->name);
}

static GList *gegl_operations (void)
{
  static GList *operations = NULL;
  if (!operations)
    {
      operations = gegl_operations_build (NULL, GEGL_TYPE_OPERATION);
      operations = g_list_sort (operations, compare_operation_names);
    }
  return operations;
}

GeglColor *
gegl_param_spec_color_get_default (GParamSpec *self);


static void
list_properties (GType    type,
                 gint     indent,
                 gboolean html)
{
  GParamSpec **self;
  GParamSpec **parent;
  guint n_self;
  guint n_parent;
  gint prop_no;

  if (!type)
    return;

  self = g_object_class_list_properties (
            G_OBJECT_CLASS (g_type_class_ref (type)),
            &n_self);
  parent = g_object_class_list_properties (
            /*G_OBJECT_CLASS (g_type_class_peek_parent (g_type_class_ref (type))),*/
            G_OBJECT_CLASS (g_type_class_ref (GEGL_TYPE_OPERATION)),
            &n_parent);

  for (prop_no=0;prop_no<n_self;prop_no++)
    {
      gint parent_no;
      gboolean found=FALSE;
      for (parent_no=0;parent_no<n_parent;parent_no++)
        if (self[prop_no]==parent[parent_no])
          found=TRUE;
      /* only print properties if we are an addition compared to
       * GeglOperation
       */
      if (!found)
        {
          const gchar *type_name = g_type_name (G_OBJECT_TYPE (self[prop_no]));

          type_name = strstr (type_name, "Param");
          type_name+=5;

          g_print("<tr><td colspan='1'>&nbsp;&nbsp;</td><td colspan='1' class='prop_type' valign='top'>%s<br/><span style='font-style:normal;text-align:right;float:right;padding-right:1em;'>", type_name);

          if (g_type_is_a (G_PARAM_SPEC_VALUE_TYPE (self[prop_no]), G_TYPE_DOUBLE))
            {

            g_print ("%2.2f", G_PARAM_SPEC_DOUBLE (self[prop_no])->default_value);

            {
            gdouble min = G_PARAM_SPEC_DOUBLE (self[prop_no])->minimum;
            gdouble max = G_PARAM_SPEC_DOUBLE (self[prop_no])->maximum;
            g_print ("<br/>");
            if (min<-10000000)
              g_print ("-inf ");
            else
              g_print ("%2.2f", min);
            
            g_print ("-");

            if (max>10000000)
              g_print (" +inf");
            else
              g_print ("%2.2f", max);
            }

            }
          else if (g_type_is_a (G_PARAM_SPEC_VALUE_TYPE (self[prop_no]), G_TYPE_INT))
            {
              g_print ("%i", G_PARAM_SPEC_INT (self[prop_no])->default_value);

            {
            gint min = G_PARAM_SPEC_INT (self[prop_no])->minimum;
            gint max = G_PARAM_SPEC_INT (self[prop_no])->maximum;
            g_print ("<br/>");
            if (min<-10000000)
              g_print ("-inf ");
            else
              g_print ("%i", min);
            
            g_print ("-");

            if (max>10000000)
              g_print (" +inf");
            else
              g_print ("%i", max);
            }

            }
          else if (g_type_is_a (G_PARAM_SPEC_VALUE_TYPE (self[prop_no]), G_TYPE_FLOAT))
            {
              g_print ("%2.2f", G_PARAM_SPEC_FLOAT (self[prop_no])->default_value);
            }
          else if (g_type_is_a (G_PARAM_SPEC_VALUE_TYPE (self[prop_no]), G_TYPE_BOOLEAN))
            {
              g_print ("%s", G_PARAM_SPEC_BOOLEAN (self[prop_no])->default_value?"True":"False");
            }
          else if (g_type_is_a (G_PARAM_SPEC_VALUE_TYPE (self[prop_no]), G_TYPE_STRING))
            {
              const gchar *string = G_PARAM_SPEC_STRING (self[prop_no])->default_value;

              if (strlen (string) > 8)
                {
                  gchar copy[16];
                  g_snprintf (copy, 12, "%s..", string);
                  g_print (copy);
                }
              else
                g_print ("%s", string);
            }
          else if (g_type_is_a (G_PARAM_SPEC_VALUE_TYPE (self[prop_no]), GEGL_TYPE_COLOR))
            {
              GeglColor *color = gegl_param_spec_color_get_default (self[prop_no]);
              if (color)
                {
                  gchar *string;
                  g_object_get (color, "string", &string, NULL);
                  g_print ("%s", string);
                  g_free (string);
                }
              g_object_unref (color);
            }
          else 
            {
              g_print ("\n");
            }
          g_print ("</span></td>");

          g_print("<td class='prop_name' valign='top'>%s</td>\n",
            g_param_spec_get_name (self[prop_no]));

          if (g_param_spec_get_blurb (self[prop_no])[0]!='\0')
            g_print ("<td colspan='1' valign='top' class='prop_blurb'>%s</td>\n",
            g_param_spec_get_blurb (self[prop_no]));
          else
            g_print ("<td><em>not documented</em></td>\n\n");

          g_print ("</tr>\n");

        }
    }
  if (self)
    g_free (self);
  if (parent)
    g_free (parent);
}


static gchar *html_top = "<html>\n<head>\n<title>GEGL operations</title>\n<link rel='shortcut icon' href='images/gegl.ico'/>\n<style type='text/css'>\n@import url(gegl.css);\ndiv#toc ul { font-size:70%; }\n"
".category { margin-bottom: 2em; }\n"
".category a {\n  display: block;\n  width: 10em;\n  height: 1.2em;\n  float: left;\n  text-align: left;\n  font-size: 90%;\n}\n"
"</style>\n</head>\n\n<body>\n<div class='paper'>\n<div class='content'>\n";
static gchar *html_bottom = "</div>\n</div>\n</body>\n</html>\n";

#if 0
static void category_menu_item (gpointer key,
                                gpointer value,
                                gpointer user_data)
{
  gchar    *category = key;
  if (!strcmp (category, "hidden"))
    return;
  g_print ("<li><a href='#cat_%s'>&nbsp;&nbsp;%s</a></li>\n", category, category);
}
#endif

static void category_index (gpointer key,
                            gpointer value,
                            gpointer user_data)
{
  gchar    *category = key;
  GList    *operations = value;
  GList    *iter;
  gboolean  comma;

  if (!strcmp (category, "hidden"))
    return;
  g_print ("<a name='cat_%s'></a><h3>%s</h3>\n", category, category);
  g_print ("<div class='category'>\n");

  for (iter=operations, comma=FALSE;iter;iter = g_list_next (iter))
    {
      GeglOperationClass *klass = iter->data;
      if (strstr (klass->categories, "hidden"))
        continue;
      g_print ("%s<a href='#op_%s'>%s</a>\n", comma?"":"", klass->name, klass->name);
      comma = TRUE;
    }
  g_print ("<div style='clear:both;'></div></div>\n");
}

static void category_menu_index (gpointer key,
                                 gpointer value,
                                 gpointer user_data)
{
  gchar    *category = key;
  GList    *operations = value;
  GList    *iter;
  gboolean  comma;

  if (!strcmp (category, "hidden"))
    return;
  for (iter=operations, comma=FALSE;iter;iter = g_list_next (iter))
    {
      GeglOperationClass *klass = iter->data;
      if (strstr (klass->categories, "hidden"))
        continue;
      g_print ("<li><a href='#op_%s'>%s</a></li>\n", klass->name, klass->name);
      comma = TRUE;
    }
}

gint
main (gint    argc,
      gchar **argv)
{
  GList      *operations;
  GList      *iter;
  GHashTable *categories = NULL;
  gboolean    comma;

  gegl_init (&argc, &argv);

  operations = gegl_operations ();

  /* Collect categories */
  categories = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
  for (iter=operations, comma=FALSE;iter;iter = g_list_next (iter))
    {
      GeglOperationClass *klass = iter->data;
      const gchar *ptr = klass->categories;
      while (*ptr)
        {
          gchar category[64]="";
          gint i=0;
          while (*ptr && *ptr!=':' && i<63)
            {
              category[i++]=*(ptr++);
              category[i]='\0';
            }
          if (*ptr==':')
            ptr++;
          {
            GList *items = g_hash_table_lookup (categories, category);
            g_hash_table_insert (categories, g_strdup (category), g_list_append (items, klass));
          }
        }
    }

  g_print ("%s", html_top);

  g_print ("<div id='toc'>\n<ul>\n");
  g_print ("<li><a href='index.html'>GEGL</a></li><li>&nbsp;</li>\n");
  g_print ("<li><a href='index.html#Documentation'>Documentation</a></li>\n");
  g_print ("<li><a href='index.html#Glossary'>&nbsp;&nbsp;Glossary</a></li>\n");
  g_print ("<li><a href='operations.html#'>&nbsp;&nbsp;Operations</a></li>\n");
  g_print ("<li><a href='api.html'>&nbsp;&nbsp;API reference</a></li>\n");
  g_print ("<li><a href=''>&nbsp;</a></li>\n");
  g_print ("<li><a href='#Categories'>Categories</a></li>\n");
  g_print ("<li><a href=''>&nbsp;</a></li>\n");
  /*category_menu_item ("All", NULL, NULL);
  g_hash_table_foreach (categories, category_menu_item, NULL);*/

      /*border: 0.1em dashed rgb(210,210,210);
       */
  category_menu_index("All", operations, NULL);

  g_print ("</ul>\n</div>\n");

    g_print ("<h1>GEGL operation reference</h1>");
    g_print ("<p>Image processing operations are shared objects (plug-ins) loaded when GEGL initializes. "
             "This page is generated from information registered by the plug-ins themselves.</p>"
              "<a name='Categories'><h2>Categories</h2></a><p>A plug-in can "
             "belong in multiple categories. Below is indexes broken down into the various available categories.</p>");

  /*category_index ("All", operations, NULL);*/
  /* create menus for each of the categories */

  g_hash_table_foreach (categories, category_index, NULL);

  /* list all operations */
  g_print ("<table>\n");
  for (iter=operations;iter;iter = g_list_next (iter))
    {
      GeglOperationClass *klass = iter->data;
      if (strstr (klass->categories, "hidden"))
        continue;

      g_print ("<tr>\n  <td colspan='1'>&nbsp;</td>\n  <td class='op_name' colspan='4'><a name='op_%s'>%s</a></td>\n</tr>\n", klass->name, klass->name);
      if (klass->description)
        g_print ("<tr>\n  <td colspan='1'>&nbsp;</td>\n  <td class='op_description' colspan='4'>%s</td>\n</tr>\n", klass->description);
      list_properties (G_OBJECT_CLASS_TYPE (klass), 2, TRUE);
    }
  g_print ("</table>\n");


  g_print ("%s", html_bottom);

  g_list_free (operations);
  gegl_exit ();
  return 0;
}