Blame tools/operation_reference.c

Packit bc1512
#include "config.h"
Packit bc1512
Packit bc1512
#include <gegl-plugin.h>  /* needed to do full introspection */
Packit bc1512
#include <stdio.h>
Packit bc1512
#include <string.h>
Packit bc1512
#ifdef HAVE_UNISTD_H
Packit bc1512
#include <unistd.h>
Packit bc1512
#endif
Packit bc1512
Packit bc1512
static GList *
Packit bc1512
gegl_operations_build (GList *list, GType type)
Packit bc1512
{
Packit bc1512
  GeglOperationClass *klass;
Packit bc1512
  GType *ops;
Packit bc1512
  guint  children;
Packit bc1512
  gint   no;
Packit bc1512
Packit bc1512
  if (!type)
Packit bc1512
    return list;
Packit bc1512
Packit bc1512
  klass = g_type_class_ref (type);
Packit bc1512
  if (klass->name != NULL)
Packit bc1512
    list = g_list_prepend (list, klass);
Packit bc1512
Packit bc1512
  ops = g_type_children (type, &children);
Packit bc1512
Packit bc1512
  for (no=0; no
Packit bc1512
    {
Packit bc1512
      list = gegl_operations_build (list, ops[no]);
Packit bc1512
    }
Packit bc1512
  if (ops)
Packit bc1512
    g_free (ops);
Packit bc1512
  return list;
Packit bc1512
}
Packit bc1512
Packit bc1512
static gint compare_operation_names (gconstpointer a,
Packit bc1512
                                     gconstpointer b)
Packit bc1512
{
Packit bc1512
  const GeglOperationClass *klassA, *klassB;
Packit bc1512
Packit bc1512
  klassA = a;
Packit bc1512
  klassB = b;
Packit bc1512
Packit bc1512
  return strcmp (klassA->name, klassB->name);
Packit bc1512
}
Packit bc1512
Packit bc1512
static GList *gegl_operations (void)
Packit bc1512
{
Packit bc1512
  static GList *operations = NULL;
Packit bc1512
  if (!operations)
Packit bc1512
    {
Packit bc1512
      operations = gegl_operations_build (NULL, GEGL_TYPE_OPERATION);
Packit bc1512
      operations = g_list_sort (operations, compare_operation_names);
Packit bc1512
    }
Packit bc1512
  return operations;
Packit bc1512
}
Packit bc1512
Packit bc1512
GeglColor *
Packit bc1512
gegl_param_spec_color_get_default (GParamSpec *self);
Packit bc1512
Packit bc1512
Packit bc1512
static void
Packit bc1512
list_properties (GType    type,
Packit bc1512
                 gint     indent,
Packit bc1512
                 gboolean html)
Packit bc1512
{
Packit bc1512
  GParamSpec **self;
Packit bc1512
  GParamSpec **parent;
Packit bc1512
  guint n_self;
Packit bc1512
  guint n_parent;
Packit bc1512
  gint prop_no;
Packit bc1512
Packit bc1512
  if (!type)
Packit bc1512
    return;
Packit bc1512
Packit bc1512
  self = g_object_class_list_properties (
Packit bc1512
            G_OBJECT_CLASS (g_type_class_ref (type)),
Packit bc1512
            &n_self);
Packit bc1512
  parent = g_object_class_list_properties (
Packit bc1512
            /*G_OBJECT_CLASS (g_type_class_peek_parent (g_type_class_ref (type))),*/
Packit bc1512
            G_OBJECT_CLASS (g_type_class_ref (GEGL_TYPE_OPERATION)),
Packit bc1512
            &n_parent);
Packit bc1512
Packit bc1512
  for (prop_no=0;prop_no
Packit bc1512
    {
Packit bc1512
      gint parent_no;
Packit bc1512
      gboolean found=FALSE;
Packit bc1512
      for (parent_no=0;parent_no
Packit bc1512
        if (self[prop_no]==parent[parent_no])
Packit bc1512
          found=TRUE;
Packit bc1512
      /* only print properties if we are an addition compared to
Packit bc1512
       * GeglOperation
Packit bc1512
       */
Packit bc1512
      if (!found)
Packit bc1512
        {
Packit bc1512
          const gchar *type_name = g_type_name (G_OBJECT_TYPE (self[prop_no]));
Packit bc1512
Packit bc1512
          type_name = strstr (type_name, "Param");
Packit bc1512
          type_name+=5;
Packit bc1512
Packit bc1512
          g_print("  %s
", type_name);
Packit bc1512
Packit bc1512
          if (g_type_is_a (G_PARAM_SPEC_VALUE_TYPE (self[prop_no]), G_TYPE_DOUBLE))
Packit bc1512
            {
Packit bc1512
              gdouble default_value = G_PARAM_SPEC_DOUBLE (self[prop_no])->default_value;
Packit bc1512
              gdouble min = G_PARAM_SPEC_DOUBLE (self[prop_no])->minimum;
Packit bc1512
              gdouble max = G_PARAM_SPEC_DOUBLE (self[prop_no])->maximum;
Packit bc1512
Packit bc1512
              if (default_value<-10000000)
Packit bc1512
                g_print ("-inf ");
Packit bc1512
              else if (default_value>10000000)
Packit bc1512
                g_print ("+inf");
Packit bc1512
              else
Packit bc1512
                g_print ("%2.2f", default_value);
Packit bc1512
Packit bc1512
              g_print ("
");
Packit bc1512
              if (min<-10000000)
Packit bc1512
                g_print ("-inf ");
Packit bc1512
              else
Packit bc1512
                g_print ("%2.2f", min);
Packit bc1512
Packit bc1512
              g_print ("-");
Packit bc1512
Packit bc1512
              if (max>10000000)
Packit bc1512
                g_print (" +inf");
Packit bc1512
              else
Packit bc1512
                g_print ("%2.2f", max);
Packit bc1512
            }
Packit bc1512
          else if (g_type_is_a (G_PARAM_SPEC_VALUE_TYPE (self[prop_no]), G_TYPE_INT))
Packit bc1512
            {
Packit bc1512
              gint default_value = G_PARAM_SPEC_INT (self[prop_no])->default_value;
Packit bc1512
              gint min = G_PARAM_SPEC_INT (self[prop_no])->minimum;
Packit bc1512
              gint max = G_PARAM_SPEC_INT (self[prop_no])->maximum;
Packit bc1512
Packit bc1512
              if (default_value<-10000000)
Packit bc1512
                g_print ("-inf ");
Packit bc1512
              else if (default_value>10000000)
Packit bc1512
                g_print ("+inf");
Packit bc1512
              else
Packit bc1512
                g_print ("%i", default_value);
Packit bc1512
Packit bc1512
              g_print ("
");
Packit bc1512
              if (min<-10000000)
Packit bc1512
                g_print ("-inf ");
Packit bc1512
              else
Packit bc1512
                g_print ("%i", min);
Packit bc1512
Packit bc1512
              g_print ("-");
Packit bc1512
Packit bc1512
              if (max>10000000)
Packit bc1512
                g_print (" +inf");
Packit bc1512
              else
Packit bc1512
                g_print ("%i", max);
Packit bc1512
            }
Packit bc1512
          else if (g_type_is_a (G_PARAM_SPEC_VALUE_TYPE (self[prop_no]), G_TYPE_FLOAT))
Packit bc1512
            {
Packit bc1512
              gfloat default_value = G_PARAM_SPEC_FLOAT (self[prop_no])->default_value;
Packit bc1512
              gfloat min = G_PARAM_SPEC_FLOAT (self[prop_no])->minimum;
Packit bc1512
              gfloat max = G_PARAM_SPEC_FLOAT (self[prop_no])->maximum;
Packit bc1512
Packit bc1512
              if (default_value<-10000000)
Packit bc1512
                g_print ("-inf ");
Packit bc1512
              else if (default_value>10000000)
Packit bc1512
                g_print ("+inf");
Packit bc1512
              else
Packit bc1512
                g_print ("%2.2f", default_value);
Packit bc1512
Packit bc1512
              g_print ("
");
Packit bc1512
              if (min<-10000000)
Packit bc1512
                g_print ("-inf ");
Packit bc1512
              else
Packit bc1512
                g_print ("%2.2f", min);
Packit bc1512
Packit bc1512
              g_print ("-");
Packit bc1512
Packit bc1512
              if (max>10000000)
Packit bc1512
                g_print (" +inf");
Packit bc1512
              else
Packit bc1512
                g_print ("%2.2f", max);
Packit bc1512
            }
Packit bc1512
          else if (g_type_is_a (G_PARAM_SPEC_VALUE_TYPE (self[prop_no]), G_TYPE_BOOLEAN))
Packit bc1512
            {
Packit bc1512
              g_print ("%s", G_PARAM_SPEC_BOOLEAN (self[prop_no])->default_value?"True":"False");
Packit bc1512
            }
Packit bc1512
          else if (g_type_is_a (G_PARAM_SPEC_VALUE_TYPE (self[prop_no]), G_TYPE_STRING))
Packit bc1512
            {
Packit bc1512
              const gchar *string = G_PARAM_SPEC_STRING (self[prop_no])->default_value;
Packit bc1512
Packit bc1512
              if (strlen (string) > 8)
Packit bc1512
                {
Packit bc1512
                  gchar copy[16];
Packit bc1512
                  g_snprintf (copy, 12, "%s..", string);
Packit bc1512
                  g_print ("%s", copy);
Packit bc1512
                }
Packit bc1512
              else
Packit bc1512
                g_print ("%s", string);
Packit bc1512
            }
Packit bc1512
          else if (g_type_is_a (G_PARAM_SPEC_VALUE_TYPE (self[prop_no]), GEGL_TYPE_COLOR))
Packit bc1512
            {
Packit bc1512
              GeglColor *color = gegl_param_spec_color_get_default (self[prop_no]);
Packit bc1512
              if (color)
Packit bc1512
                {
Packit bc1512
                  gchar *string;
Packit bc1512
Packit bc1512
                  g_object_get (color, "string", &string, NULL);
Packit bc1512
                  g_print ("%s", string);
Packit bc1512
                  g_free (string);
Packit bc1512
Packit bc1512
                  g_object_unref (color);
Packit bc1512
                }
Packit bc1512
            }
Packit bc1512
          else
Packit bc1512
            {
Packit bc1512
              g_print ("\n");
Packit bc1512
            }
Packit bc1512
          g_print ("");
Packit bc1512
Packit bc1512
          g_print("%s\n",
Packit bc1512
            g_param_spec_get_name (self[prop_no]));
Packit bc1512
Packit bc1512
          if (g_param_spec_get_blurb (self[prop_no]) &&
Packit bc1512
              g_param_spec_get_blurb (self[prop_no])[0]!='\0')
Packit bc1512
            g_print ("%s\n",
Packit bc1512
            g_param_spec_get_blurb (self[prop_no]));
Packit bc1512
          else
Packit bc1512
            g_print ("not documented\n\n");
Packit bc1512
Packit bc1512
          g_print ("\n");
Packit bc1512
Packit bc1512
        }
Packit bc1512
    }
Packit bc1512
  if (self)
Packit bc1512
    g_free (self);
Packit bc1512
  if (parent)
Packit bc1512
    g_free (parent);
Packit bc1512
}
Packit bc1512
Packit bc1512
Packit bc1512
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"
Packit bc1512
".category { margin-bottom: 2em; }\n"
Packit bc1512
".category a {\n  display: block;\n  width: 14em;\n  height: 1.2em;\n  float: left;\n  text-align: left;\n  font-size: 90%;\n}\n"
Packit bc1512
"</style>\n</head>\n\n<body>\n
\n
\n";
Packit bc1512
static gchar *html_bottom = "\n\n</body>\n</html>\n";
Packit bc1512
Packit bc1512
Packit bc1512
static void category_index (gpointer key,
Packit bc1512
                            gpointer value,
Packit bc1512
                            gpointer user_data)
Packit bc1512
{
Packit bc1512
  gchar    *category = key;
Packit bc1512
  GList    *operations = value;
Packit bc1512
  GList    *iter;
Packit bc1512
  gboolean  comma;
Packit bc1512
Packit bc1512
  if (!strcmp (category, "hidden"))
Packit bc1512
    return;
Packit bc1512
  g_print ("

%s

\n", category, category);
Packit bc1512
  g_print ("
\n");
Packit bc1512
Packit bc1512
  for (iter=operations, comma=FALSE;iter;iter = g_list_next (iter))
Packit bc1512
    {
Packit bc1512
      GeglOperationClass *klass = iter->data;
Packit bc1512
      const char *categories = gegl_operation_class_get_key (klass, "categories");
Packit bc1512
      if (strstr (categories, "hidden"))
Packit bc1512
        continue;
Packit bc1512
      g_print ("%s%s\n", comma?"":"", klass->name, klass->name);
Packit bc1512
      comma = TRUE;
Packit bc1512
    }
Packit bc1512
  g_print ("
\n");
Packit bc1512
}
Packit bc1512
Packit bc1512
static void category_menu_index (gpointer key,
Packit bc1512
                                 gpointer value,
Packit bc1512
                                 gpointer user_data)
Packit bc1512
{
Packit bc1512
  gchar    *category = key;
Packit bc1512
  GList    *operations = value;
Packit bc1512
  GList    *iter;
Packit bc1512
Packit bc1512
  if (!strcmp (category, "hidden"))
Packit bc1512
    return;
Packit bc1512
  for (iter=operations;iter;iter = g_list_next (iter))
Packit bc1512
    {
Packit bc1512
      GeglOperationClass *klass = iter->data;
Packit bc1512
      const char *categories = gegl_operation_class_get_key (klass, "categories");
Packit bc1512
      if (!categories || strstr (categories, "hidden"))
Packit bc1512
        continue;
Packit bc1512
      g_print ("
  • %s
  • \n", klass->name, klass->name);
    Packit bc1512
        }
    Packit bc1512
    }
    Packit bc1512
    Packit bc1512
    gint
    Packit bc1512
    main (gint    argc,
    Packit bc1512
          gchar **argv)
    Packit bc1512
    {
    Packit bc1512
      GList      *operations;
    Packit bc1512
      GList      *iter;
    Packit bc1512
      GHashTable *categories = NULL;
    Packit bc1512
    Packit bc1512
      gegl_init (&argc, &argv);
    Packit bc1512
    Packit bc1512
      operations = gegl_operations ();
    Packit bc1512
    Packit bc1512
      /* Collect categories */
    Packit bc1512
      categories = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
    Packit bc1512
      for (iter=operations;iter;iter = g_list_next (iter))
    Packit bc1512
        {
    Packit bc1512
          GeglOperationClass *klass = iter->data;
    Packit bc1512
          const char *categoris = gegl_operation_class_get_key (klass, "categories");
    Packit bc1512
          const gchar *ptr = categoris;
    Packit bc1512
          while (ptr && *ptr)
    Packit bc1512
            {
    Packit bc1512
              gchar category[64]="";
    Packit bc1512
              gint i=0;
    Packit bc1512
              while (*ptr && *ptr!=':' && i<63)
    Packit bc1512
                {
    Packit bc1512
                  category[i++]=*(ptr++);
    Packit bc1512
                  category[i]='\0';
    Packit bc1512
                }
    Packit bc1512
              if (*ptr==':')
    Packit bc1512
                ptr++;
    Packit bc1512
              {
    Packit bc1512
                GList *items = g_hash_table_lookup (categories, category);
    Packit bc1512
                g_hash_table_insert (categories, g_strdup (category), g_list_append (items, klass));
    Packit bc1512
              }
    Packit bc1512
            }
    Packit bc1512
        }
    Packit bc1512
    Packit bc1512
      g_print ("%s", html_top);
    Packit bc1512
    Packit bc1512
      g_print ("
    \n
      \n");
    Packit bc1512
      g_print ("
  • GEGL
  •  
  • \n");
    Packit bc1512
      g_print ("
  • Documentation
  • \n");
    Packit bc1512
      g_print ("
  •   Glossary
  • \n");
    Packit bc1512
      g_print ("
  •   Operations
  • \n");
    Packit bc1512
      g_print ("
  •   API reference
  • \n");
    Packit bc1512
      g_print ("
  •  
  • \n");
    Packit bc1512
      g_print ("
  • Categories
  • \n");
    Packit bc1512
      g_print ("
  •  
  • \n");
    Packit bc1512
      /*category_menu_item ("All", NULL, NULL);
    Packit bc1512
      g_hash_table_foreach (categories, category_menu_item, NULL);*/
    Packit bc1512
    Packit bc1512
          /*border: 0.1em dashed rgb(210,210,210);
    Packit bc1512
           */
    Packit bc1512
      category_menu_index("All", operations, NULL);
    Packit bc1512
    Packit bc1512
      g_print ("\n\n");
    Packit bc1512
    Packit bc1512
        g_print ("

    GEGL operation reference

    ");
    Packit bc1512
        g_print ("

    Image processing operations are shared objects (plug-ins) loaded when GEGL initializes. "

    Packit bc1512
                 "This page is generated from information registered by the plug-ins themselves.

    "
    Packit bc1512
                  "

    Categories

    A plug-in can "

    Packit bc1512
                 "belong in multiple categories. Below is indexes broken down into the various available categories.

    ");
    Packit bc1512
    Packit bc1512
      /*category_index ("All", operations, NULL);*/
    Packit bc1512
      /* create menus for each of the categories */
    Packit bc1512
    Packit bc1512
      g_hash_table_foreach (categories, category_index, NULL);
    Packit bc1512
    Packit bc1512
      /* list all operations */
    Packit bc1512
      g_print ("\n");
    Packit bc1512
      for (iter=operations;iter;iter = g_list_next (iter))
    Packit bc1512
        {
    Packit bc1512
          GeglOperationClass *klass = iter->data;
    Packit bc1512
          const char *categoris = gegl_operation_class_get_key (klass, "categories");
    Packit bc1512
          const char *description = gegl_operation_class_get_key (klass, "description");
    Packit bc1512
          if (categoris && strstr (categoris, "hidden"))
    Packit bc1512
            continue;
    Packit bc1512
    Packit bc1512
          g_print ("\n   \n  %s\n\n", klass->name, klass->name);
    Packit bc1512
          if (description)
    Packit bc1512
            g_print ("\n   \n  %s\n\n", description);
    Packit bc1512
          list_properties (G_OBJECT_CLASS_TYPE (klass), 2, TRUE);
    Packit bc1512
        }
    Packit bc1512
      g_print ("\n");
    Packit bc1512
    Packit bc1512
    Packit bc1512
      g_print ("%s", html_bottom);
    Packit bc1512
    Packit bc1512
      g_list_free (operations);
    Packit bc1512
      gegl_exit ();
    Packit bc1512
      return 0;
    Packit bc1512
    }