[gnome-photos/wip/baedert/gtkimageview: 241/248] Scale surface/buffer size by view_scale



commit 525f775cdf9c07d349afca7c7b9e0bcb25cd791c
Author: Timm Bäder <mail baedert org>
Date:   Fri Apr 15 15:49:21 2016 +0200

    Scale surface/buffer size by view_scale

 src/photos-gegl-image.c |   47 +++++++++++++++++++++++++++--------------------
 1 files changed, 27 insertions(+), 20 deletions(-)
---
diff --git a/src/photos-gegl-image.c b/src/photos-gegl-image.c
index 1c38699..cb3cab1 100644
--- a/src/photos-gegl-image.c
+++ b/src/photos-gegl-image.c
@@ -42,8 +42,8 @@ photos_gegl_image_render_surface (PhotosGeglImage *image)
     /*{*/
       image->surface = cairo_image_surface_create_for_data (image->buf,
                                                             CAIRO_FORMAT_ARGB32,
-                                                            image->width,
-                                                            image->height,
+                                                            image->width * image->view_scale,
+                                                            image->height * image->view_scale,
                                                             image->stride);
     /*}*/
 
@@ -51,18 +51,6 @@ photos_gegl_image_render_surface (PhotosGeglImage *image)
 }
 
 static void
-photos_gegl_image_draw (GtkAbstractImage *_image, cairo_t *ct)
-{
-  PhotosGeglImage *image = PHOTOS_GEGL_IMAGE (_image);
-
-  if (image->surface)
-    {
-      cairo_scale (ct, 1.0 / image->view_scale, 1.0 / image->view_scale);
-      cairo_set_source_surface (ct, image->surface, 0, 0);
-    }
-}
-
-static void
 photos_gegl_image_update_bbox (PhotosGeglImage *image)
 {
   GeglRectangle box;
@@ -84,21 +72,36 @@ photos_gegl_image_update_bbox (PhotosGeglImage *image)
       image->width  = box.width;
       image->height = box.height;
 
-      image->roi.x = box.x * image->view_scale;
-      image->roi.y = box.y * image->view_scale;
-      image->roi.width  = box.width  * image->scale_factor * image->view_scale;
-      image->roi.height = box.height * image->scale_factor * image->view_scale;
+      image->roi.x      = box.x;
+      image->roi.y      = box.y;
+      image->roi.width  = box.width  /* image->scale_factor */* image->view_scale;
+      image->roi.height = box.height /* image->scale_factor */* image->view_scale;
 
-      image->stride = cairo_format_stride_for_width (CAIRO_FORMAT_ARGB32, image->roi.width);
+
+
+      image->stride = cairo_format_stride_for_width (CAIRO_FORMAT_ARGB32,
+                                                     box.width * image->view_scale);
 
       g_clear_pointer (&image->buf, g_free);
       g_clear_pointer (&image->buf, cairo_surface_destroy);
 
-      image->buf = g_malloc (image->stride * image->roi.height * image->view_scale);
+      image->buf = g_malloc (image->stride * box.height); /* stride is already scaled */
     /*}*/
 }
 
 static void
+photos_gegl_image_draw (GtkAbstractImage *_image, cairo_t *ct)
+{
+  PhotosGeglImage *image = PHOTOS_GEGL_IMAGE (_image);
+
+  if (image->surface)
+    {
+      cairo_scale (ct, 1.0 / image->view_scale, 1.0 / image->view_scale);
+      cairo_set_source_surface (ct, image->surface, 0, 0);
+    }
+}
+
+static void
 photos_gegl_image_computed (PhotosGeglImage *image)
 {
   photos_gegl_image_update_bbox (image);
@@ -160,6 +163,10 @@ photos_gegl_image_class_init (PhotosGeglImageClass *klass)
 void
 photos_gegl_image_set_view_scale (PhotosGeglImage *image, double view_scale)
 {
+  if (view_scale == image->view_scale)
+    return;
+
   image->view_scale = view_scale;
+
   photos_gegl_image_render_surface (image);
 }


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