gegl r2816 - in trunk: . examples



Author: ok
Date: Sat Dec  6 13:34:58 2008
New Revision: 2816
URL: http://svn.gnome.org/viewvc/gegl?rev=2816&view=rev

Log:
* examples/gegl-slicer.c: (main): added a utility for slicing images
into subcomponents based on descriptions in a text file.


Added:
   trunk/examples/gegl-slicer.c
Modified:
   trunk/ChangeLog

Added: trunk/examples/gegl-slicer.c
==============================================================================
--- (empty file)
+++ trunk/examples/gegl-slicer.c	Sat Dec  6 13:34:58 2008
@@ -0,0 +1,99 @@
+#include <gegl.h>
+#include <string.h>
+
+gint
+main (gint    argc,
+      gchar **argv)
+{
+  gchar *rules;
+  GeglNode *gegl,
+           *load_file,
+           *crop,
+           *save_file;
+  GError *error = NULL;
+
+  gegl_init (&argc, &argv);
+
+  if (argv[1]==NULL ||
+      argv[2]==NULL)
+    {
+      g_print ("\nusage: %s <inputimage> <slicefile> [pathprefix]\n\n"
+ "  inputimage: the .png, .jpg, .svg or similar image to load\n"
+ "  slicefile: a text file with rule lines like (x,y widthxheight slice1.png)\n"
+ "  pathprefix: a string to preprend to the names of slices in theslicefile\n", strrchr (argv[0], '/')+1);
+      exit (-1);
+    }
+
+  gegl = gegl_node_new ();
+  load_file = gegl_node_new_child (gegl,
+                              "operation", "gegl:load",
+                              "path", argv[1],
+                              NULL);
+
+  crop = gegl_node_new_child (gegl,
+                              "operation", "gegl:crop",
+                              NULL);
+
+  save_file = gegl_node_new_child (gegl,
+                                   "operation", "gegl:png-save",
+                                   "compression", 9,
+                                   "bitdepth", 8,
+                                   NULL);
+  gegl_node_link_many (load_file, crop, save_file, NULL);
+
+  if (g_file_get_contents (argv[2], &rules, NULL, &error))
+    {
+      gchar *line;
+      gchar *next_line = NULL;
+      
+      for (line = rules;line; line = next_line)
+        {
+          gchar *next_new_line;
+          next_new_line = strchr (line, '\n');
+          if (next_new_line)
+            {
+              next_line = next_new_line + 1;
+              *next_new_line = '\0';
+            }
+          else
+            {
+              next_line = NULL;
+            }
+
+          while (*line == ' ')line++;
+
+          if (line[0]!='#' && line[0]!='\0')
+            {
+              gint x, y, width, height;
+              x = strtol (line, &line, 10);
+              while (*line == ' ' || *line == ',')line++;
+              y = strtol (line, &line, 10);
+              while (*line == ' ' || *line == ',')line++;
+              width = strtol (line, &line, 10);
+              while (*line == ' ' || *line == 'x')line++;
+              height = strtol (line, &line, 10);
+              while (*line == ' ')line++;
+
+              {
+                GString *str = g_string_new ("");
+                if (argv[3])
+                  {
+                    g_string_append (str, argv[3]);
+                  }
+                g_string_append (str, line);
+                gegl_node_set (save_file, "path", str->str, NULL);
+              gegl_node_set (crop, "x", x*1.0,
+                                   "y", y*1.0,
+                                   "width", width*1.0,
+                                   "height", height * 1.0,
+                                   NULL);
+              g_print ("%s (%i,%i %ix%i)\n", str->str, x, y, width, height);
+              g_string_free (str, TRUE);
+            }
+              gegl_node_process (save_file);
+            }
+        }
+      g_free (rules);
+    } 
+  return 0;
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]