[gegl/mrg_ui] ui: de-rotate image files on load



commit 370877f534e735ccc1091c8ad500d10098745403
Author: Oyvind Kolas <pippin gimp org>
Date:   Mon Aug 3 23:29:33 2015 +0200

    ui: de-rotate image files on load
    
    perhaps it would be better if the jpeg filer loader and some others did this itself with some fast-op - 
instead of using the generic resampling op.

 bin/mrg-ui.c |   59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 59 insertions(+), 0 deletions(-)
---
diff --git a/bin/mrg-ui.c b/bin/mrg-ui.c
index 891b276..cd807d0 100644
--- a/bin/mrg-ui.c
+++ b/bin/mrg-ui.c
@@ -111,6 +111,7 @@ static char *suffix = "-gegl";
 
 void   gegl_meta_set (const char *path, const char *meta_data);
 char * gegl_meta_get (const char *path);
+GExiv2Orientation path_get_orientation (const char *path);
 
 static char *suffix_path (const char *path);
 static char *unsuffix_path (const char *path);
@@ -1300,6 +1301,49 @@ static void load_into_buffer (State *o, const char *path)
   gegl_node_process (sink);
   g_object_unref (gegl);
 
+  {
+    GExiv2Orientation orientation = path_get_orientation (path);
+    gboolean hflip = FALSE;
+    gboolean vflip = FALSE;
+    double degrees = 0.0;
+    switch (orientation)
+    {
+      case GEXIV2_ORIENTATION_UNSPECIFIED:
+      case GEXIV2_ORIENTATION_NORMAL:
+        break;
+      case GEXIV2_ORIENTATION_HFLIP: hflip=TRUE; break;
+      case GEXIV2_ORIENTATION_VFLIP: vflip=TRUE; break;
+      case GEXIV2_ORIENTATION_ROT_90: degrees = 90.0; break;
+      case GEXIV2_ORIENTATION_ROT_90_HFLIP: degrees = 90.0; hflip=TRUE; break;
+      case GEXIV2_ORIENTATION_ROT_90_VFLIP: degrees = 90.0; vflip=TRUE; break;
+      case GEXIV2_ORIENTATION_ROT_180: degrees = 180.0; break;
+      case GEXIV2_ORIENTATION_ROT_270: degrees = 270.0; break;
+    }
+
+    if (degrees != 0.0 || vflip || hflip)
+     {
+       /* XXX: deal with vflip/hflip */
+       GeglBuffer *new_buffer = NULL;
+       GeglNode *rotate;
+       gegl = gegl_node_new ();
+       load = gegl_node_new_child (gegl, "operation", "gegl:buffer-source",
+                                   "buffer", o->buffer,
+                                   NULL);
+       sink = gegl_node_new_child (gegl, "operation", "gegl:buffer-sink",
+                                   "buffer", &(new_buffer),
+                                   NULL);
+       rotate = gegl_node_new_child (gegl, "operation", "gegl:rotate",
+                                   "degrees", -degrees,
+                                   
+                                   NULL);
+       gegl_node_link_many (load, rotate, sink, NULL);
+       gegl_node_process (sink);
+       g_object_unref (gegl);
+       g_object_unref (o->buffer);
+       o->buffer = new_buffer;
+     }
+  }
+
 #if 0 /* hack to see if having the data in some formats already is faster */
   {
   GeglBuffer *tempbuf;
@@ -1712,4 +1756,19 @@ gegl_meta_get (const char *path)
   return ret;
 }
 
+GExiv2Orientation path_get_orientation (const char *path)
+{
+  GExiv2Orientation ret = 0;
+  GError *error = NULL;
+  GExiv2Metadata *e2m = gexiv2_metadata_new ();
+  gexiv2_metadata_open_path (e2m, path, &error);
+  if (!error)
+    ret = gexiv2_metadata_get_orientation (e2m);
+  /*else
+    g_warning ("%s", error->message);*/
+  gexiv2_metadata_free (e2m);
+  return ret;
+}
+
+
 #endif



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