[gegl] bin: Add ppm output file format support



commit ba1cadb51982bd83c9ac239d4e66884af214b332
Author: Henrik Akesson <h m akesson gmail com>
Date:   Tue Apr 21 19:21:23 2009 +0200

    bin: Add ppm output file format support
    
    Add ppm output file format on the command-line application. It is done
    by parsing the filename extension of the --output parameter, which is
    used to choose the output node type created (png-save or ppm-save).
---
 ChangeLog          |   12 ++++++++++++
 bin/gegl-options.c |   30 ++++++++++++++++++++++++++++--
 bin/gegl-options.h |    1 +
 bin/gegl.c         |   11 +++++++++++
 4 files changed, 52 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 11b31bb..e5ed048 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 2009-04-21  Martin Nordholts  <martinn svn gnome org>
 
+	Add ppm output file format on the command-line application. It is done
+	by parsing the filename extension of the --output parameter, which is
+	used to choose the output node type created (png-save or ppm-save).
+
+	Patch from Henrik Akesson.
+
+	* bin/gegl.c
+	* bin/gegl-options.c
+	* bin/gegl-options.h
+
+2009-04-21  Martin Nordholts  <martinn svn gnome org>
+
 	Add a portable pixmap loader and saver that can read/write both
 	the ascii and the binary formats.
 
diff --git a/bin/gegl-options.c b/bin/gegl-options.c
index 2d11128..a396067 100644
--- a/bin/gegl-options.c
+++ b/bin/gegl-options.c
@@ -61,7 +61,8 @@ usage (char *application_name)
 "     --dot       output a graphviz graph description\n"
 ""
 "     --output    output generated image to named file\n"
-"     -o          (file is saved in PNG format)\n"
+"     -o          (file is saved in PNG or PPM format\n"
+"                  depending on the file ending.)\n"
 "\n"
 "     -p          (increment frame counters of various elements when\n"
 "                  processing is done.)\n"
@@ -246,8 +247,33 @@ parse_args (int    argc,
 
         else if (match ("--output") ||
                  match ("-o")) {
+            const char *trigramstart;
+            int   length;
+
             get_string_forced (o->output);
-            o->mode = GEGL_RUN_MODE_PNG;
+
+            length       = strlen (o->output);
+            trigramstart = o->output;
+
+            /* position the pointer at the start of the trigram or
+             * if the string is not long enough, at the end of the string
+             */
+            trigramstart += (length > 3 ? length - 3 : length);
+
+            if (strcmp (trigramstart, "png") == 0 ||
+                strcmp (trigramstart, "PNG") == 0 ) {
+
+                o->mode = GEGL_RUN_MODE_PNG;
+            } else if (strcmp (trigramstart, "ppm") == 0 ||
+                       strcmp (trigramstart, "PPM") == 0) {
+
+                o->mode = GEGL_RUN_MODE_PPM;
+            } else {
+                fprintf (stderr,
+                         "Output file extension not found (%s), using png\n",
+                         o->output);
+                o->mode = GEGL_RUN_MODE_PNG;
+            }
         }
 
         else if (match ("-X")) {
diff --git a/bin/gegl-options.h b/bin/gegl-options.h
index 8cd1a36..fdcd9fd 100644
--- a/bin/gegl-options.h
+++ b/bin/gegl-options.h
@@ -27,6 +27,7 @@ typedef enum
   GEGL_RUN_MODE_DOT,
   GEGL_RUN_MODE_EDITOR,
   GEGL_RUN_MODE_PNG,
+  GEGL_RUN_MODE_PPM,
   GEGL_RUN_MODE_XML
 } GeglRunMode;
 
diff --git a/bin/gegl.c b/bin/gegl.c
index 5753768..a5b117d 100644
--- a/bin/gegl.c
+++ b/bin/gegl.c
@@ -251,6 +251,17 @@ main (gint    argc,
           g_object_unref (output);
         }
         break;
+      case GEGL_RUN_MODE_PPM:
+        {
+          GeglNode *output = gegl_node_new_child (gegl,
+						  "operation", "gegl:ppm-save",
+						  "path", o->output,
+						  NULL);
+          gegl_node_connect_from (output, "input", gegl_node_get_output_proxy (gegl, "output"), "output");
+          gegl_node_process (output);
+          g_object_unref (output);
+        }
+        break;
       case GEGL_RUN_MODE_HELP:
         break;
       default:



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