[recipes] Simplify pixbuf loading api



commit e1b0074d9704129dfb280544f1cb0cd0b99b0585
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Feb 26 20:09:38 2017 -0500

    Simplify pixbuf loading api
    
    All callers were passing 0 for the angle, so drop the rotation
    functionality and simplify the api.

 src/gr-chef-dialog.c           |    2 +-
 src/gr-cooking-view.c          |    4 +-
 src/gr-edit-page.c             |    2 +-
 src/gr-image-page.c            |    2 +-
 src/gr-image-viewer.c          |    4 +-
 src/gr-recipe-importer.c       |    4 +-
 src/gr-recipe-printer.c        |    2 +-
 src/gr-shell-search-provider.c |    2 +-
 src/gr-utils.c                 |   49 ++++-----------------------------------
 src/gr-utils.h                 |    2 -
 10 files changed, 16 insertions(+), 57 deletions(-)
---
diff --git a/src/gr-chef-dialog.c b/src/gr-chef-dialog.c
index dec39a7..89ec414 100644
--- a/src/gr-chef-dialog.c
+++ b/src/gr-chef-dialog.c
@@ -75,7 +75,7 @@ update_image (GrChefDialog *self)
 {
         if (self->image_path != NULL && self->image_path[0] != '\0') {
                 g_autoptr(GdkPixbuf) pixbuf = NULL;
-                pixbuf = load_pixbuf_fit_size (self->image_path, 0, 64, 64, TRUE);
+                pixbuf = load_pixbuf_fit_size (self->image_path, 64, 64, TRUE);
                 gtk_image_set_from_pixbuf (GTK_IMAGE (self->image), pixbuf);
                 gtk_style_context_remove_class (gtk_widget_get_style_context (self->image), "dim-label");
         }
diff --git a/src/gr-cooking-view.c b/src/gr-cooking-view.c
index 6aca05a..8c11ba5 100644
--- a/src/gr-cooking-view.c
+++ b/src/gr-cooking-view.c
@@ -322,9 +322,9 @@ setup_step (GrCookingView *view)
                 gtk_widget_set_halign (view->text_box, GTK_ALIGN_START);
                 ri = &g_array_index (view->images, GrImage, s->image);
                 if (view->wide)
-                        pixbuf = load_pixbuf_fill_size (ri->path, 0, 640, 480);
+                        pixbuf = load_pixbuf_fill_size (ri->path, 640, 480);
                 else
-                        pixbuf = load_pixbuf_fill_size (ri->path, 0, 320, 240);
+                        pixbuf = load_pixbuf_fill_size (ri->path, 320, 240);
                 gtk_image_set_from_pixbuf (GTK_IMAGE (view->cooking_image), pixbuf);
                 gtk_stack_set_visible_child_name (GTK_STACK (view->cooking_stack), "image");
         }
diff --git a/src/gr-edit-page.c b/src/gr-edit-page.c
index 046a2df..566f065 100644
--- a/src/gr-edit-page.c
+++ b/src/gr-edit-page.c
@@ -166,7 +166,7 @@ populate_image_flowbox (GrEditPage *page)
 
         for (i = 0; i < images->len; i++) {
                 GrImage *ri = &g_array_index (images, GrImage, i);
-                g_autoptr(GdkPixbuf) pb = load_pixbuf_fill_size (ri->path, 0, 60, 40);
+                g_autoptr(GdkPixbuf) pb = load_pixbuf_fill_size (ri->path, 60, 40);
                 GtkWidget *image;
                 GtkWidget *child;
 
diff --git a/src/gr-image-page.c b/src/gr-image-page.c
index 7310b30..ffb0406 100644
--- a/src/gr-image-page.c
+++ b/src/gr-image-page.c
@@ -97,7 +97,7 @@ set_current_image (GrImagePage *page)
                 gdk_monitor_get_geometry (monitor, &geom);
 
                 ri = &g_array_index (page->images, GrImage, page->index);
-                pixbuf = load_pixbuf_fit_size (ri->path, 0, geom.width - 80, geom.height - 80, FALSE);
+                pixbuf = load_pixbuf_fit_size (ri->path, geom.width - 80, geom.height - 80, FALSE);
                 gtk_image_set_from_pixbuf (GTK_IMAGE (page->image), pixbuf);
         }
 }
diff --git a/src/gr-image-viewer.c b/src/gr-image-viewer.c
index 2b6f8ac..b74b74b 100644
--- a/src/gr-image-viewer.c
+++ b/src/gr-image-viewer.c
@@ -141,7 +141,7 @@ set_current_image (GrImageViewer *viewer)
                 const char *vis;
 
                 ri = &g_array_index (viewer->images, GrImage, viewer->index);
-                pixbuf = load_pixbuf_fill_size (ri->path, 0, 360, 240);
+                pixbuf = load_pixbuf_fill_size (ri->path, 360, 240);
 
                 vis = gtk_stack_get_visible_child_name (GTK_STACK (viewer->stack));
                 if (strcmp (vis, "image1") == 0) {
@@ -170,7 +170,7 @@ populate_preview (GrImageViewer *viewer)
 
         for (i = 0; i < viewer->images->len; i++) {
                 GrImage *ri = &g_array_index (viewer->images, GrImage, i);
-                g_autoptr(GdkPixbuf) pb = load_pixbuf_fill_size (ri->path, 0, 60, 40);
+                g_autoptr(GdkPixbuf) pb = load_pixbuf_fill_size (ri->path, 60, 40);
                 GtkWidget *image;
 
                 image = gtk_image_new_from_pixbuf (pb);
diff --git a/src/gr-recipe-importer.c b/src/gr-recipe-importer.c
index b89d91d..2e4176e 100644
--- a/src/gr-recipe-importer.c
+++ b/src/gr-recipe-importer.c
@@ -673,7 +673,7 @@ show_chef_conflict_dialog (GrRecipeImporter *importer,
         gtk_text_buffer_set_text (buffer, gr_chef_get_description (chef), -1);
         if (gr_chef_get_image (chef) != NULL) {
                 g_autoptr(GdkPixbuf) pixbuf = NULL;
-                pixbuf = load_pixbuf_fit_size (gr_chef_get_image (chef), 0, 64, 64, TRUE);
+                pixbuf = load_pixbuf_fit_size (gr_chef_get_image (chef), 64, 64, TRUE);
                 gtk_image_set_from_pixbuf (GTK_IMAGE (old_chef_picture), pixbuf);
         }
 
@@ -689,7 +689,7 @@ show_chef_conflict_dialog (GrRecipeImporter *importer,
                 g_autoptr(GdkPixbuf) pixbuf = NULL;
                 g_autofree char *path = NULL;
                 path = g_build_filename (importer->dir, importer->chef_image_path, NULL);
-                pixbuf = load_pixbuf_fit_size (path, 0, 64, 64, TRUE);
+                pixbuf = load_pixbuf_fit_size (path, 64, 64, TRUE);
                 gtk_image_set_from_pixbuf (GTK_IMAGE (new_chef_picture), pixbuf);
         }
 
diff --git a/src/gr-recipe-printer.c b/src/gr-recipe-printer.c
index da8f000..b243846 100644
--- a/src/gr-recipe-printer.c
+++ b/src/gr-recipe-printer.c
@@ -184,7 +184,7 @@ begin_print (GtkPrintOperation *operation,
         g_object_get (printer->recipe, "images", &images, NULL);
         if (images && images->len > 0) {
                 ri = &g_array_index (images, GrImage, 0);
-                printer->image = load_pixbuf_fit_size (ri->path, 0, width / 2, height / 4, FALSE);
+                printer->image = load_pixbuf_fit_size (ri->path, width / 2, height / 4, FALSE);
         }
 
         title_font = pango_font_description_from_string ("Cantarell Bold 18");
diff --git a/src/gr-shell-search-provider.c b/src/gr-shell-search-provider.c
index ad629ac..5df50a4 100644
--- a/src/gr-shell-search-provider.c
+++ b/src/gr-shell-search-provider.c
@@ -174,7 +174,7 @@ gr_recipe_get_pixbuf (GrRecipe *recipe)
                 GrImage *ri = &g_array_index (images, GrImage, 0);
                 GdkPixbuf *pixbuf;
 
-                pixbuf = load_pixbuf_fill_size (ri->path, 0, 64, 64);
+                pixbuf = load_pixbuf_fill_size (ri->path, 64, 64);
                 return pixbuf;
         }
 
diff --git a/src/gr-utils.c b/src/gr-utils.c
index c8c020c..07383fa 100644
--- a/src/gr-utils.c
+++ b/src/gr-utils.c
@@ -39,12 +39,11 @@
 #include "gr-utils.h"
 #include "gr-app.h"
 
-/* load image rotated by angle to fit in width x height while preserving
+/* load image to fit in width x height while preserving
  * aspect ratio, filling seams with transparency
  */
 GdkPixbuf *
 load_pixbuf_fit_size (const char *path,
-                      int         angle,
                       int         width,
                       int         height,
                       gboolean    pad)
@@ -53,30 +52,14 @@ load_pixbuf_fit_size (const char *path,
         GdkPixbuf *pixbuf;
         int dest_x, dest_y, dest_width, dest_height;
 
-        int load_width, load_height;
-
-        if (angle == 90 || angle == 270) {
-                load_width = height;
-                load_height = width;
-        }
-        else {
-                load_width = width;
-                load_height = height;
-        }
-
         pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, width, height);
         gdk_pixbuf_fill (pixbuf, 0x00000000);
 
-        original = gdk_pixbuf_new_from_file_at_size (path, load_width, load_height, NULL);
+        original = gdk_pixbuf_new_from_file_at_size (path, width, height, NULL);
         if (!original) {
                 g_warning ("Failed to load image %s", path);
                 return pixbuf;
         }
-        if (angle != 0) {
-                g_autoptr(GdkPixbuf) pb = NULL;
-                pb = gdk_pixbuf_rotate_simple (original, angle);
-                g_set_object (&original, pb);
-        }
 
         if (pad) {
                 dest_width = gdk_pixbuf_get_width (original);
@@ -95,29 +78,18 @@ load_pixbuf_fit_size (const char *path,
         return pixbuf;
 }
 
-/* load image rotated by angle to fill width x height while preserving
+/* load image to fill width x height while preserving
  * aspect ratio, cutting off overshoots
  */
 GdkPixbuf *
 load_pixbuf_fill_size (const char *path,
-                       int         angle,
                        int         width,
                        int         height)
 {
         g_autoptr(GdkPixbuf) original = NULL;
         int x, y;
-        int load_width, load_height;
 
-        if (angle == 90 || angle == 270) {
-                load_width = height;
-                load_height = width;
-        }
-        else {
-                load_width = width;
-                load_height = height;
-        }
-
-        original = gdk_pixbuf_new_from_file_at_scale (path, -1, load_height, TRUE, NULL);
+        original = gdk_pixbuf_new_from_file_at_scale (path, -1, height, TRUE, NULL);
         if (!original) {
                 GdkPixbuf *pixbuf;
                 g_warning ("Failed to load image %s", path);
@@ -126,21 +98,10 @@ load_pixbuf_fill_size (const char *path,
                 return pixbuf;
         }
 
-        if (angle != 0) {
-                g_autoptr(GdkPixbuf) pb = NULL;
-                pb = gdk_pixbuf_rotate_simple (original, angle);
-                g_set_object (&original, pb);
-        }
-
         if (gdk_pixbuf_get_width (original) < width) {
                 g_autoptr(GdkPixbuf) pb1 = NULL;
-                pb1 = gdk_pixbuf_new_from_file_at_scale (path, load_width, -1, TRUE, NULL);
+                pb1 = gdk_pixbuf_new_from_file_at_scale (path, width, -1, TRUE, NULL);
                 g_set_object (&original, pb1);
-                if (angle != 0) {
-                        g_autoptr(GdkPixbuf) pb = NULL;
-                        pb = gdk_pixbuf_rotate_simple (original, angle);
-                        g_set_object (&original, pb);
-                }
         }
 
         g_assert (gdk_pixbuf_get_width (original) >= width &&
diff --git a/src/gr-utils.h b/src/gr-utils.h
index d077726..eea9ac2 100644
--- a/src/gr-utils.h
+++ b/src/gr-utils.h
@@ -25,12 +25,10 @@
 G_BEGIN_DECLS
 
 GdkPixbuf *load_pixbuf_fit_size  (const char *path,
-                                  int         angle,
                                   int         width,
                                   int         height,
                                   gboolean    pad);
 GdkPixbuf *load_pixbuf_fill_size (const char *path,
-                                  int         angle,
                                   int         width,
                                   int         height);
 


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