[gnome-photos] base-item: Apply the embedded orientation



commit 48577fb5327145a4b432234268a461fbf7a7fb6a
Author: Debarshi Ray <debarshir gnome org>
Date:   Wed Nov 18 18:20:13 2015 +0100

    base-item: Apply the embedded orientation
    
    Read the nfo:orientation property from Tracker and use a GEGL
    operation to apply it when loading.
    
    Currently only 'bottom', 'left', 'right' and 'top' are implemented
    because I couldn't find test images for the others.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=734844

 src/photos-base-item.c     |   11 +++++++-
 src/photos-query-builder.c |    1 +
 src/photos-query.h         |    3 +-
 src/photos-utils.c         |   55 ++++++++++++++++++++++++++++++++++++++++++++
 src/photos-utils.h         |   14 +++++++++++
 5 files changed, 81 insertions(+), 3 deletions(-)
---
diff --git a/src/photos-base-item.c b/src/photos-base-item.c
index 3ffc373..7ee60ad 100644
--- a/src/photos-base-item.c
+++ b/src/photos-base-item.c
@@ -68,6 +68,7 @@ struct _PhotosBaseItemPrivate
   GMutex mutex;
   GQuark equipment;
   GQuark flash;
+  GQuark orientation;
   PhotosCollectionIconWatcher *watcher;
   PhotosPipeline *pipeline;
   PhotosSelectionController *sel_cntrlr;
@@ -800,11 +801,13 @@ photos_base_item_load_buffer_async (PhotosBaseItem *self,
 
   if (priv->load_graph == NULL)
     {
+      GeglNode *orientation;
+
       priv->load_graph = gegl_node_new ();
       priv->load = gegl_node_new_child (priv->load_graph, "operation", "gegl:load", NULL);
+      orientation = photos_utils_create_orientation_node (priv->load_graph, priv->orientation);
       priv->buffer_sink = gegl_node_new_child (priv->load_graph, "operation", "gegl:buffer-sink", NULL);
-      gegl_node_link (priv->load, priv->buffer_sink);
-
+      gegl_node_link_many (priv->load, orientation, priv->buffer_sink, NULL);
     }
 
   if (priv->edit_graph == NULL)
@@ -1081,6 +1084,7 @@ photos_base_item_populate_from_cursor (PhotosBaseItem *self, TrackerSparqlCursor
   const gchar *equipment;
   const gchar *flash;
   const gchar *mtime;
+  const gchar *orientation;
   const gchar *title;
   const gchar *uri;
 
@@ -1132,6 +1136,9 @@ photos_base_item_populate_from_cursor (PhotosBaseItem *self, TrackerSparqlCursor
   equipment = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_EQUIPMENT, NULL);
   priv->equipment = g_quark_from_string (equipment);
 
+  orientation = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_ORIENTATION, NULL);
+  priv->orientation = g_quark_from_string (orientation);
+
   priv->exposure_time = tracker_sparql_cursor_get_double (cursor, PHOTOS_QUERY_COLUMNS_EXPOSURE_TIME);
   priv->fnumber = tracker_sparql_cursor_get_double (cursor, PHOTOS_QUERY_COLUMNS_FNUMBER);
   priv->focal_length = tracker_sparql_cursor_get_double (cursor, PHOTOS_QUERY_COLUMNS_FOCAL_LENGTH);
diff --git a/src/photos-query-builder.c b/src/photos-query-builder.c
index 58325fb..e8d48b0 100644
--- a/src/photos-query-builder.c
+++ b/src/photos-query-builder.c
@@ -176,6 +176,7 @@ photos_query_builder_query (PhotosSearchContextState *state,
                         "nfo:width (?urn) "
                         "nfo:height (?urn) "
                         "nfo:equipment (?urn) "
+                        "nfo:orientation (?urn) "
                         "nmm:exposureTime (?urn) "
                         "nmm:fnumber (?urn) "
                         "nmm:focalLength (?urn) "
diff --git a/src/photos-query.h b/src/photos-query.h
index ea88201..a0e4bb2 100644
--- a/src/photos-query.h
+++ b/src/photos-query.h
@@ -1,6 +1,6 @@
 /*
  * Photos - access, organize and share your photos on GNOME
- * Copyright © 2012, 2013, 2014 Red Hat, Inc.
+ * Copyright © 2012, 2013, 2014, 2015 Red Hat, Inc.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -51,6 +51,7 @@ typedef enum
   PHOTOS_QUERY_COLUMNS_WIDTH,
   PHOTOS_QUERY_COLUMNS_HEIGHT,
   PHOTOS_QUERY_COLUMNS_EQUIPMENT,
+  PHOTOS_QUERY_COLUMNS_ORIENTATION,
   PHOTOS_QUERY_COLUMNS_EXPOSURE_TIME,
   PHOTOS_QUERY_COLUMNS_FNUMBER,
   PHOTOS_QUERY_COLUMNS_FOCAL_LENGTH,
diff --git a/src/photos-utils.c b/src/photos-utils.c
index 909ab67..1d1b785 100644
--- a/src/photos-utils.c
+++ b/src/photos-utils.c
@@ -243,6 +243,33 @@ photos_utils_create_collection_icon (gint base_size, GList *pixbufs)
 }
 
 
+GeglNode *
+photos_utils_create_orientation_node (GeglNode *parent, GQuark orientation)
+{
+  GeglNode *ret_val = NULL;
+  double degrees = 1.0;
+
+  if (orientation == PHOTOS_ORIENTATION_TOP)
+    goto out;
+
+  if (orientation == PHOTOS_ORIENTATION_BOTTOM)
+    degrees = -180.0;
+  else if (orientation == PHOTOS_ORIENTATION_LEFT)
+    degrees = -270.0;
+  else if (orientation == PHOTOS_ORIENTATION_RIGHT)
+    degrees = -90.0;
+
+  if (degrees < 0.0)
+    ret_val = gegl_node_new_child (parent, "operation", "gegl:rotate-on-center", "degrees", degrees, NULL);
+
+ out:
+  if (ret_val == NULL)
+    ret_val = gegl_node_new_child (parent, "operation", "gegl:nop", NULL);
+
+  return ret_val;
+}
+
+
 GdkPixbuf *
 photos_utils_create_pixbuf_from_node (GeglNode *node)
 {
@@ -933,6 +960,34 @@ photos_utils_icon_from_rdf_type (const gchar *type)
 }
 
 
+GQuark
+photos_utils_orientation_bottom_quark (void)
+{
+  return g_quark_from_static_string 
("http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#orientation-bottom";);
+}
+
+
+GQuark
+photos_utils_orientation_left_quark (void)
+{
+  return g_quark_from_static_string 
("http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#orientation-left";);
+}
+
+
+GQuark
+photos_utils_orientation_right_quark (void)
+{
+  return g_quark_from_static_string 
("http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#orientation-right";);
+}
+
+
+GQuark
+photos_utils_orientation_top_quark (void)
+{
+  return g_quark_from_static_string 
("http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#orientation-top";);
+}
+
+
 static void
 photos_utils_update_executed (GObject *source_object, GAsyncResult *res, gpointer user_data)
 {
diff --git a/src/photos-utils.h b/src/photos-utils.h
index 776e9f2..99302bd 100644
--- a/src/photos-utils.h
+++ b/src/photos-utils.h
@@ -44,6 +44,10 @@ G_BEGIN_DECLS
 #define PHOTOS_ERROR (photos_utils_error_quark ())
 #define PHOTOS_FLASH_OFF (photos_utils_flash_off_quark ())
 #define PHOTOS_FLASH_ON (photos_utils_flash_on_quark ())
+#define PHOTOS_ORIENTATION_BOTTOM (photos_utils_orientation_bottom_quark ())
+#define PHOTOS_ORIENTATION_LEFT (photos_utils_orientation_left_quark ())
+#define PHOTOS_ORIENTATION_RIGHT (photos_utils_orientation_right_quark ())
+#define PHOTOS_ORIENTATION_TOP (photos_utils_orientation_top_quark ())
 
 #define PHOTOS_BASE_ITEM_EXTENSION_POINT_NAME "photos-base-item"
 #define PHOTOS_TOOL_EXTENSION_POINT_NAME "photos-tool"
@@ -60,6 +64,8 @@ gchar           *photos_utils_convert_path_to_uri         (const gchar *path);
 
 GIcon           *photos_utils_create_collection_icon      (gint base_size, GList *pixbufs);
 
+GeglNode        *photos_utils_create_orientation_node     (GeglNode *parent, GQuark orientation);
+
 GdkPixbuf       *photos_utils_create_pixbuf_from_node     (GeglNode *node);
 
 GIcon           *photos_utils_create_symbolic_icon_for_scale (const gchar *name, gint base_size, gint scale);
@@ -122,6 +128,14 @@ GList           *photos_utils_get_urns_from_paths         (GList *paths, GtkTree
 
 GIcon           *photos_utils_icon_from_rdf_type          (const gchar *type);
 
+GQuark           photos_utils_orientation_bottom_quark    (void);
+
+GQuark           photos_utils_orientation_left_quark      (void);
+
+GQuark           photos_utils_orientation_right_quark     (void);
+
+GQuark           photos_utils_orientation_top_quark       (void);
+
 void             photos_utils_set_edited_name             (const gchar *urn, const gchar *title);
 
 void             photos_utils_set_favorite                (const gchar *urn, gboolean is_favorite);


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