[gimp/metadata-browser] app: explicitly pass around the offsets of the view renderer's temp_bufs



commit f8cd2228677875902c2eac64f32d55d065375152
Author: Michael Natterer <mitch gimp org>
Date:   Tue Apr 10 15:50:36 2012 +0200

    app: explicitly pass around the offsets of the view renderer's temp_bufs
    
    and don't use temp_buf->x and ->y.

 app/widgets/gimpviewrenderer.c         |   33 ++++++++++++++++++++++---------
 app/widgets/gimpviewrenderer.h         |    2 +
 app/widgets/gimpviewrendererbrush.c    |   24 ++++++++++++++++------
 app/widgets/gimpviewrendererdrawable.c |   19 +++++++++++------
 app/widgets/gimpviewrendererimage.c    |    7 ++++-
 5 files changed, 59 insertions(+), 26 deletions(-)
---
diff --git a/app/widgets/gimpviewrenderer.c b/app/widgets/gimpviewrenderer.c
index f989bc4..92a2dda 100644
--- a/app/widgets/gimpviewrenderer.c
+++ b/app/widgets/gimpviewrenderer.c
@@ -76,6 +76,8 @@ static cairo_pattern_t *
 
 static void      gimp_view_render_temp_buf_to_surface (GimpViewRenderer   *renderer,
                                                        GimpTempBuf        *temp_buf,
+                                                       gint                temp_buf_x,
+                                                       gint                temp_buf_y,
                                                        gint                channel,
                                                        GimpViewBG          inside_bg,
                                                        GimpViewBG          outside_bg,
@@ -794,16 +796,21 @@ void
 gimp_view_renderer_render_temp_buf_simple (GimpViewRenderer *renderer,
                                            GimpTempBuf      *temp_buf)
 {
+  gint temp_buf_x = 0;
+  gint temp_buf_y = 0;
+
   g_return_if_fail (GIMP_IS_VIEW_RENDERER (renderer));
   g_return_if_fail (temp_buf != NULL);
 
   if (temp_buf->width < renderer->width)
-    temp_buf->x = (renderer->width - temp_buf->width)  / 2;
+    temp_buf_x = (renderer->width - temp_buf->width)  / 2;
 
   if (temp_buf->height < renderer->height)
-    temp_buf->y = (renderer->height - temp_buf->height) / 2;
+    temp_buf_y = (renderer->height - temp_buf->height) / 2;
 
-  gimp_view_renderer_render_temp_buf (renderer, temp_buf, -1,
+  gimp_view_renderer_render_temp_buf (renderer, temp_buf,
+                                      temp_buf_x, temp_buf_y,
+                                      -1,
                                       GIMP_VIEW_BG_CHECKS,
                                       GIMP_VIEW_BG_WHITE);
 }
@@ -811,6 +818,8 @@ gimp_view_renderer_render_temp_buf_simple (GimpViewRenderer *renderer,
 void
 gimp_view_renderer_render_temp_buf (GimpViewRenderer *renderer,
                                     GimpTempBuf      *temp_buf,
+                                    gint              temp_buf_x,
+                                    gint              temp_buf_y,
                                     gint              channel,
                                     GimpViewBG        inside_bg,
                                     GimpViewBG        outside_bg)
@@ -828,6 +837,8 @@ gimp_view_renderer_render_temp_buf (GimpViewRenderer *renderer,
 
   gimp_view_render_temp_buf_to_surface (renderer,
                                         temp_buf,
+                                        temp_buf_x,
+                                        temp_buf_y,
                                         channel,
                                         inside_bg,
                                         outside_bg,
@@ -921,6 +932,8 @@ gimp_view_renderer_render_stock (GimpViewRenderer *renderer,
 static void
 gimp_view_render_temp_buf_to_surface (GimpViewRenderer *renderer,
                                       GimpTempBuf      *temp_buf,
+                                      gint              temp_buf_x,
+                                      gint              temp_buf_y,
                                       gint              channel,
                                       GimpViewBG        inside_bg,
                                       GimpViewBG        outside_bg,
@@ -974,7 +987,7 @@ gimp_view_render_temp_buf_to_surface (GimpViewRenderer *renderer,
 
   if (! gimp_rectangle_intersect (0, 0,
                                   surface_width, surface_height,
-                                  temp_buf->x, temp_buf->y,
+                                  temp_buf_x, temp_buf_y,
                                   temp_buf->width, temp_buf->height,
                                   &x, &y,
                                   &width, &height))
@@ -1015,8 +1028,8 @@ gimp_view_render_temp_buf_to_surface (GimpViewRenderer *renderer,
       dest_buffer = gimp_cairo_image_surface_create_buffer (alpha_surface);
 
       gegl_buffer_copy (src_buffer,
-                        GEGL_RECTANGLE (x - temp_buf->x,
-                                        y - temp_buf->y,
+                        GEGL_RECTANGLE (x - temp_buf_x,
+                                        y - temp_buf_y,
                                         width, height),
                         dest_buffer,
                         GEGL_RECTANGLE (0, 0, 0, 0));
@@ -1044,8 +1057,8 @@ gimp_view_render_temp_buf_to_surface (GimpViewRenderer *renderer,
       dest_buffer = gimp_cairo_image_surface_create_buffer (surface);
 
       gegl_buffer_copy (src_buffer,
-                        GEGL_RECTANGLE (x - temp_buf->x,
-                                        y - temp_buf->y,
+                        GEGL_RECTANGLE (x - temp_buf_x,
+                                        y - temp_buf_y,
                                         width, height),
                         dest_buffer,
                         GEGL_RECTANGLE (x, y, 0, 0));
@@ -1070,8 +1083,8 @@ gimp_view_render_temp_buf_to_surface (GimpViewRenderer *renderer,
       bytes     = babl_format_get_bytes_per_pixel (temp_buf->format);
       rowstride = temp_buf->width * bytes;
 
-      src = gimp_temp_buf_get_data (temp_buf) + ((y - temp_buf->y) * rowstride +
-                                                 (x - temp_buf->x) * bytes);
+      src = gimp_temp_buf_get_data (temp_buf) + ((y - temp_buf_y) * rowstride +
+                                                 (x - temp_buf_x) * bytes);
 
       dest        = cairo_image_surface_get_data (surface);
       dest_stride = cairo_image_surface_get_stride (surface);
diff --git a/app/widgets/gimpviewrenderer.h b/app/widgets/gimpviewrenderer.h
index 1a52edc..711739f 100644
--- a/app/widgets/gimpviewrenderer.h
+++ b/app/widgets/gimpviewrenderer.h
@@ -144,6 +144,8 @@ void   gimp_view_renderer_render_temp_buf_simple (GimpViewRenderer *renderer,
                                                   GimpTempBuf      *temp_buf);
 void   gimp_view_renderer_render_temp_buf        (GimpViewRenderer *renderer,
                                                   GimpTempBuf      *temp_buf,
+                                                  gint              temp_buf_x,
+                                                  gint              temp_buf_y,
                                                   gint              channel,
                                                   GimpViewBG        inside_bg,
                                                   GimpViewBG        outside_bg);
diff --git a/app/widgets/gimpviewrendererbrush.c b/app/widgets/gimpviewrendererbrush.c
index 9f4e956..36f8046 100644
--- a/app/widgets/gimpviewrendererbrush.c
+++ b/app/widgets/gimpviewrendererbrush.c
@@ -89,6 +89,8 @@ gimp_view_renderer_brush_render (GimpViewRenderer *renderer,
 {
   GimpViewRendererBrush *renderbrush = GIMP_VIEW_RENDERER_BRUSH (renderer);
   GimpTempBuf           *temp_buf;
+  gint                   temp_buf_x = 0;
+  gint                   temp_buf_y = 0;
 
   if (renderbrush->pipe_timeout_id)
     {
@@ -102,14 +104,16 @@ gimp_view_renderer_brush_render (GimpViewRenderer *renderer,
                                             renderer->height);
 
   if (temp_buf->width < renderer->width)
-    temp_buf->x = (renderer->width - temp_buf->width) / 2;
+    temp_buf_x = (renderer->width - temp_buf->width) / 2;
 
   if (temp_buf->height < renderer->height)
-    temp_buf->y = (renderer->height - temp_buf->height) / 2;
+    temp_buf_y = (renderer->height - temp_buf->height) / 2;
 
   if (renderer->is_popup)
     {
-      gimp_view_renderer_render_temp_buf (renderer, temp_buf, -1,
+      gimp_view_renderer_render_temp_buf (renderer, temp_buf,
+                                          temp_buf_x, temp_buf_y,
+                                          -1,
                                           GIMP_VIEW_BG_WHITE,
                                           GIMP_VIEW_BG_WHITE);
 
@@ -126,7 +130,9 @@ gimp_view_renderer_brush_render (GimpViewRenderer *renderer,
       return;
     }
 
-  gimp_view_renderer_render_temp_buf (renderer, temp_buf, -1,
+  gimp_view_renderer_render_temp_buf (renderer, temp_buf,
+                                      temp_buf_x, temp_buf_y,
+                                      -1,
                                       GIMP_VIEW_BG_WHITE,
                                       GIMP_VIEW_BG_WHITE);
 
@@ -141,6 +147,8 @@ gimp_view_renderer_brush_render_timeout (gpointer data)
   GimpBrushPipe         *brush_pipe;
   GimpBrush             *brush;
   GimpTempBuf           *temp_buf;
+  gint                   temp_buf_x = 0;
+  gint                   temp_buf_y = 0;
 
   if (! renderer->viewable)
     {
@@ -166,12 +174,14 @@ gimp_view_renderer_brush_render_timeout (gpointer data)
                                             renderer->height);
 
   if (temp_buf->width < renderer->width)
-    temp_buf->x = (renderer->width - temp_buf->width) / 2;
+    temp_buf_x = (renderer->width - temp_buf->width) / 2;
 
   if (temp_buf->height < renderer->height)
-    temp_buf->y = (renderer->height - temp_buf->height) / 2;
+    temp_buf_y = (renderer->height - temp_buf->height) / 2;
 
-  gimp_view_renderer_render_temp_buf (renderer, temp_buf, -1,
+  gimp_view_renderer_render_temp_buf (renderer, temp_buf,
+                                      temp_buf_x, temp_buf_y,
+                                      -1,
                                       GIMP_VIEW_BG_WHITE,
                                       GIMP_VIEW_BG_WHITE);
 
diff --git a/app/widgets/gimpviewrendererdrawable.c b/app/widgets/gimpviewrendererdrawable.c
index f3e67b9..7ffd814 100644
--- a/app/widgets/gimpviewrendererdrawable.c
+++ b/app/widgets/gimpviewrendererdrawable.c
@@ -199,36 +199,41 @@ gimp_view_renderer_drawable_render (GimpViewRenderer *renderer,
 
   if (render_buf)
     {
+      gint render_buf_x = 0;
+      gint render_buf_y = 0;
+
       if (image && ! renderer->is_popup)
         {
           if (offset_x != 0)
-            render_buf->x =
+            render_buf_x =
               ROUND ((((gdouble) renderer->width /
                        (gdouble) gimp_image_get_width (image)) *
                       (gdouble) offset_x));
 
           if (offset_y != 0)
-            render_buf->y =
+            render_buf_y =
               ROUND ((((gdouble) renderer->height /
                        (gdouble) gimp_image_get_height (image)) *
                       (gdouble) offset_y));
 
           if (scaling_up)
             {
-              if (render_buf->x < 0) render_buf->x = 0;
-              if (render_buf->y < 0) render_buf->y = 0;
+              if (render_buf_x < 0) render_buf_x = 0;
+              if (render_buf_y < 0) render_buf_y = 0;
             }
         }
       else
         {
           if (view_width < width)
-            render_buf->x = (width - view_width) / 2;
+            render_buf_x = (width - view_width) / 2;
 
           if (view_height < height)
-            render_buf->y = (height - view_height) / 2;
+            render_buf_y = (height - view_height) / 2;
         }
 
-      gimp_view_renderer_render_temp_buf (renderer, render_buf, -1,
+      gimp_view_renderer_render_temp_buf (renderer, render_buf,
+                                          render_buf_x, render_buf_y,
+                                          -1,
                                           GIMP_VIEW_BG_CHECKS,
                                           GIMP_VIEW_BG_CHECKS);
       gimp_temp_buf_unref (render_buf);
diff --git a/app/widgets/gimpviewrendererimage.c b/app/widgets/gimpviewrendererimage.c
index 3b59b35..e5e289d 100644
--- a/app/widgets/gimpviewrendererimage.c
+++ b/app/widgets/gimpviewrendererimage.c
@@ -120,6 +120,8 @@ gimp_view_renderer_image_render (GimpViewRenderer *renderer,
 
       if (render_buf)
         {
+          gint render_buf_x    = 0;
+          gint render_buf_y    = 0;
           gint component_index = -1;
 
           /*  xresolution != yresolution */
@@ -134,16 +136,17 @@ gimp_view_renderer_image_render (GimpViewRenderer *renderer,
             }
 
           if (view_width  < renderer->width)
-            render_buf->x = (renderer->width  - view_width)  / 2;
+            render_buf_x = (renderer->width  - view_width)  / 2;
 
           if (view_height < renderer->height)
-            render_buf->y = (renderer->height - view_height) / 2;
+            render_buf_y = (renderer->height - view_height) / 2;
 
           if (rendererimage->channel != -1)
             component_index =
               gimp_image_get_component_index (image, rendererimage->channel);
 
           gimp_view_renderer_render_temp_buf (renderer, render_buf,
+                                              render_buf_x, render_buf_y,
                                               component_index,
                                               GIMP_VIEW_BG_CHECKS,
                                               GIMP_VIEW_BG_WHITE);



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