[gegl] gegl-binary: add commandline option to scale output



commit c5a55b286f507f3c573925d4b861a6be782c5084
Author: Øyvind Kolås <pippin gimp org>
Date:   Wed Jul 2 23:49:42 2014 +0200

    gegl-binary: add commandline option to scale output

 bin/gegl-options.c |    8 ++++++++
 bin/gegl-options.h |    2 ++
 bin/gegl.c         |   36 ++++++++++++++++++++++++++++++++++--
 3 files changed, 44 insertions(+), 2 deletions(-)
---
diff --git a/bin/gegl-options.c b/bin/gegl-options.c
index 0153963..6558746 100644
--- a/bin/gegl-options.c
+++ b/bin/gegl-options.c
@@ -36,6 +36,7 @@ static GeglOptions *opts_new (void)
   o->files    = NULL;
   o->file     = NULL;
   o->rest     = NULL;
+  o->scale    = 1.0;
   return o;
 }
 
@@ -66,6 +67,8 @@ _("usage: %s [options] <file | -- [op [op] ..]>\n"
 "     -p              increment frame counters of various elements when\n"
 "                     processing is done.\n"
 "\n"
+"     -s scale, --scale scale  scale output dimensions by this factor.\n"
+"\n"
 "     -X              output the XML that was read in\n"
 "\n"
 "     -v, --verbose   print diagnostics while running\n"
@@ -312,6 +315,11 @@ parse_args (int    argc,
             o->mode = GEGL_RUN_MODE_OUTPUT;
         }
 
+        else if (match ("--scale") ||
+                 match ("-s")) {
+            get_float (o->scale);
+        }
+
         else if (match ("-X")) {
             o->mode = GEGL_RUN_MODE_XML;
         }
diff --git a/bin/gegl-options.h b/bin/gegl-options.h
index 073d62b..3b4d121 100644
--- a/bin/gegl-options.h
+++ b/bin/gegl-options.h
@@ -47,6 +47,8 @@ struct _GeglOptions
   gboolean     fatal_warnings;
 
   gboolean     play;
+
+  gdouble      scale;
 };
 
 GeglOptions *gegl_options_parse (gint    argc,
diff --git a/bin/gegl.c b/bin/gegl.c
index c98c295..e6455a6 100644
--- a/bin/gegl.c
+++ b/bin/gegl.c
@@ -232,8 +232,40 @@ main (gint    argc,
                                                   "operation", "gegl:save",
                                                   "path", o->output,
                                                   NULL);
-          gegl_node_connect_from (output, "input", gegl, "output");
-          gegl_node_process (output);
+
+          if (o->scale != 1.0){
+            GeglRectangle bounds = gegl_node_get_bounding_box (gegl);
+            GeglBuffer *tempb;
+            GeglNode *n0;
+
+            guchar *temp;
+            
+            bounds.x *= o->scale;
+            bounds.y *= o->scale;
+            bounds.width *= o->scale;
+            bounds.height *= o->scale;
+            temp = gegl_malloc (bounds.width * bounds.height * 4);
+            tempb = gegl_buffer_new (&bounds, babl_format("R'G'B'A u8"));
+            gegl_node_blit (gegl, o->scale, &bounds, babl_format("R'G'B'A u8"), temp, GEGL_AUTO_ROWSTRIDE,
+                            GEGL_BLIT_DEFAULT);
+
+            gegl_buffer_set (tempb, &bounds, 0.0, babl_format ("R'G'B'A u8"),
+                             temp, GEGL_AUTO_ROWSTRIDE);
+
+            n0 = gegl_node_new_child (gegl, "operation", "gegl:buffer-source",
+                                            "buffer", tempb,
+                                            NULL);
+            gegl_node_connect_from (output, "input", n0, "output");
+            gegl_node_process (output);
+            gegl_free (temp);
+            g_object_unref (tempb);
+          }
+          else
+          {
+            gegl_node_connect_from (output, "input", gegl, "output");
+            gegl_node_process (output);
+          }
+          
           g_object_unref (output);
         }
         break;


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