[gnome-photos/wip/rishi/edit-preview: 3/3] base-item: Add photos_base_item_create_preview



commit 56dd269021ad4af093ec05352d7ea00bb038b7d9
Author: Debarshi Ray <debarshir gnome org>
Date:   Mon Nov 23 20:57:51 2015 +0100

    base-item: Add photos_base_item_create_preview

 src/photos-base-item.c |   37 +++++++++++++++++++++++++++++++++++++
 src/photos-base-item.h |    5 +++++
 2 files changed, 42 insertions(+), 0 deletions(-)
---
diff --git a/src/photos-base-item.c b/src/photos-base-item.c
index 7ee60ad..831f518 100644
--- a/src/photos-base-item.c
+++ b/src/photos-base-item.c
@@ -1380,6 +1380,43 @@ photos_base_item_can_trash (PhotosBaseItem *self)
 }
 
 
+cairo_surface_t *
+photos_base_item_create_preview (PhotosBaseItem *self, gint size, gint scale, const gchar *operation)
+{
+  PhotosBaseItemPrivate *priv = self->priv;
+  GeglBuffer *buffer = NULL;
+  GeglOperation *operation;
+  GeglRectangle bbox;
+  const Babl *format;
+  const gchar *name;
+  gdouble zoom;
+  gint level;
+  gint min_dimension;
+
+  g_return_val_if_fail (priv->buffer_source != NULL, NULL);
+  g_return_val_if_fail (priv->edit_graph != NULL, NULL);
+  g_return_val_if_fail (priv->load_graph != NULL, NULL);
+
+  operation = gegl_node_get_gegl_operation (priv->buffer_source);
+  g_return_val_if_fail (operation != NULL, NULL);
+
+  name = gegl_operation_get_name (operation);
+  g_return_val_if_fail (g_strcmp0 (name, "gegl:buffer-source") == 0, NULL);
+
+  bbox = gegl_node_get_bounding_box (priv->buffer_source);
+  min_dimension = bbox.height < bbox.width ? bbox.height : bbox.width;
+  zoom = (gdouble) (size * scale) / (gdouble) min_dimension;
+  level = photos_utils_get_level_from_zoom (zoom);
+
+  format = gegl_operation_get_format (operation, "output");
+  buffer = gegl_buffer_new (NULL, format);
+
+  gegl_node_blit_buffer (priv->buffer_source, buffer, &bbox, level, GEGL_ABYSS_NONE);
+
+  g_object_unref (buffer);
+}
+
+
 void
 photos_base_item_destroy (PhotosBaseItem *self)
 {
diff --git a/src/photos-base-item.h b/src/photos-base-item.h
index 884e925..571a82f 100644
--- a/src/photos-base-item.h
+++ b/src/photos-base-item.h
@@ -91,6 +91,11 @@ GType               photos_base_item_get_type                (void) G_GNUC_CONST
 
 gboolean            photos_base_item_can_trash               (PhotosBaseItem *self);
 
+cairo_surface_t    *photos_base_item_create_preview          (PhotosBaseItem *self,
+                                                              gint size,
+                                                              gint scale,
+                                                              const gchar *operation);
+
 void                photos_base_item_destroy                 (PhotosBaseItem *self);
 
 gchar              *photos_base_item_download                (PhotosBaseItem *self,


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