[gimp] Use more x,y,width,height instead of x1,y1,x2,y2



commit bdd8d8e3fbc05bbbbd7852b71af675c644e6518a
Author: Michael Natterer <mitch gimp org>
Date:   Wed Jun 17 20:46:28 2009 +0200

    Use more x,y,width,height instead of x1,y1,x2,y2
    
    (gimp_paint_core_get_orig_image)
    (gimp_paint_core_get_orig_proj): changed parameters to x,y,width,height.
    Update callers accordingly and use x,y,width,height there too except
    in gimpperspectiveclone.c which does better with a bounding box.

 app/paint/gimpdodgeburn.c        |   27 ++++++++++-------
 app/paint/gimppaintcore.c        |   62 ++++++++++++++++++-------------------
 app/paint/gimppaintcore.h        |   16 +++++-----
 app/paint/gimpperspectiveclone.c |    8 ++++-
 app/paint/gimpsourcecore.c       |   46 ++++++++++++++-------------
 5 files changed, 84 insertions(+), 75 deletions(-)
---
diff --git a/app/paint/gimpdodgeburn.c b/app/paint/gimpdodgeburn.c
index 1c23993..d797a98 100644
--- a/app/paint/gimpdodgeburn.c
+++ b/app/paint/gimpdodgeburn.c
@@ -195,21 +195,26 @@ gimp_dodge_burn_motion (GimpPaintCore    *paint_core,
    */
   {
     GimpItem *item = GIMP_ITEM (drawable);
-    gint      x1, y1, x2, y2;
-
-    x1 = CLAMP (area->x, 0, gimp_item_get_width  (item));
-    y1 = CLAMP (area->y, 0, gimp_item_get_height (item));
-    x2 = CLAMP (area->x + area->width,  0, gimp_item_get_width  (item));
-    y2 = CLAMP (area->y + area->height, 0, gimp_item_get_height (item));
-
-    if (!(x2 - x1) || !(y2 - y1))
-      return;
+    gint      x, y;
+    gint      width, height;
+
+    if (! gimp_rectangle_intersect (area->x, area->y,
+                                    area->width, area->height,
+                                    0, 0,
+                                    gimp_item_get_width  (item),
+                                    gimp_item_get_height (item),
+                                    &x, &y,
+                                    &width, &height))
+      {
+        return;
+      }
 
     /*  get the original untouched image  */
-    orig = gimp_paint_core_get_orig_image (paint_core, drawable, x1, y1, x2, y2);
+    orig = gimp_paint_core_get_orig_image (paint_core, drawable,
+                                           x, y, width, height);
 
     pixel_region_init_temp_buf (&srcPR, orig,
-                                0, 0, x2 - x1, y2 - y1);
+                                0, 0, width, height);
   }
 
   /* tempPR will hold the dodgeburned region */
diff --git a/app/paint/gimppaintcore.c b/app/paint/gimppaintcore.c
index 3f7a1de..f90b4de 100644
--- a/app/paint/gimppaintcore.c
+++ b/app/paint/gimppaintcore.c
@@ -690,10 +690,10 @@ gimp_paint_core_get_paint_area (GimpPaintCore    *core,
 TempBuf *
 gimp_paint_core_get_orig_image (GimpPaintCore *core,
                                 GimpDrawable  *drawable,
-                                gint           x1,
-                                gint           y1,
-                                gint           x2,
-                                gint           y2)
+                                gint           x,
+                                gint           y,
+                                gint           width,
+                                gint           height)
 {
   PixelRegion   srcPR;
   PixelRegion   destPR;
@@ -713,28 +713,27 @@ gimp_paint_core_get_orig_image (GimpPaintCore *core,
 
   core->orig_buf = temp_buf_resize (core->orig_buf,
                                     gimp_drawable_bytes (drawable),
-                                    x1, y1,
-                                    (x2 - x1), (y2 - y1));
+                                    x, y, width, height);
 
   drawable_width  = gimp_item_get_width  (GIMP_ITEM (drawable));
   drawable_height = gimp_item_get_height (GIMP_ITEM (drawable));
 
-  x1 = CLAMP (x1, 0, drawable_width);
-  y1 = CLAMP (y1, 0, drawable_height);
-  x2 = CLAMP (x2, 0, drawable_width);
-  y2 = CLAMP (y2, 0, drawable_height);
+  gimp_rectangle_intersect (x, y,
+                            width, height,
+                            0, 0,
+                            drawable_width, drawable_height,
+                            &x, &y,
+                            &width, &height);
 
   /*  configure the pixel regions  */
   pixel_region_init (&srcPR, gimp_drawable_get_tiles (drawable),
-                     x1, y1,
-                     (x2 - x1), (y2 - y1),
+                     x, y, width, height,
                      FALSE);
 
   pixel_region_init_temp_buf (&destPR, core->orig_buf,
-                              x1 - core->orig_buf->x,
-                              y1 - core->orig_buf->y,
-                              x2 - x1,
-                              y2 - y1);
+                              x - core->orig_buf->x,
+                              y - core->orig_buf->y,
+                              width, height);
 
   for (pr = pixel_regions_register (2, &srcPR, &destPR);
        pr != NULL;
@@ -784,10 +783,10 @@ gimp_paint_core_get_orig_image (GimpPaintCore *core,
 TempBuf *
 gimp_paint_core_get_orig_proj (GimpPaintCore *core,
                                GimpPickable  *pickable,
-                               gint           x1,
-                               gint           y1,
-                               gint           x2,
-                               gint           y2)
+                               gint           x,
+                               gint           y,
+                               gint           width,
+                               gint           height)
 {
   TileManager  *src_tiles;
   PixelRegion   srcPR;
@@ -808,30 +807,29 @@ gimp_paint_core_get_orig_proj (GimpPaintCore *core,
 
   core->orig_proj_buf = temp_buf_resize (core->orig_proj_buf,
                                          gimp_pickable_get_bytes (pickable),
-                                         x1, y1,
-                                         (x2 - x1), (y2 - y1));
+                                         x, y, width, height);
 
   src_tiles = gimp_pickable_get_tiles (pickable);
 
   pickable_width  = tile_manager_width  (src_tiles);
   pickable_height = tile_manager_height (src_tiles);
 
-  x1 = CLAMP (x1, 0, pickable_width);
-  y1 = CLAMP (y1, 0, pickable_height);
-  x2 = CLAMP (x2, 0, pickable_width);
-  y2 = CLAMP (y2, 0, pickable_height);
+  gimp_rectangle_intersect (x, y,
+                            width, height,
+                            0, 0,
+                            pickable_width, pickable_height,
+                            &x, &y,
+                            &width, &height);
 
   /*  configure the pixel regions  */
   pixel_region_init (&srcPR, src_tiles,
-                     x1, y1,
-                     (x2 - x1), (y2 - y1),
+                     x, y, width, height,
                      FALSE);
 
   pixel_region_init_temp_buf (&destPR, core->orig_proj_buf,
-                              x1 - core->orig_proj_buf->x,
-                              y1 - core->orig_proj_buf->y,
-                              x2 - x1,
-                              y2 - y1);
+                              x - core->orig_proj_buf->x,
+                              y - core->orig_proj_buf->y,
+                              width, height);
 
   for (pr = pixel_regions_register (2, &srcPR, &destPR);
        pr != NULL;
diff --git a/app/paint/gimppaintcore.h b/app/paint/gimppaintcore.h
index 3b19002..a42ac51 100644
--- a/app/paint/gimppaintcore.h
+++ b/app/paint/gimppaintcore.h
@@ -158,16 +158,16 @@ TempBuf * gimp_paint_core_get_paint_area            (GimpPaintCore    *core,
                                                      const GimpCoords *coords);
 TempBuf * gimp_paint_core_get_orig_image            (GimpPaintCore    *core,
                                                      GimpDrawable     *drawable,
-                                                     gint              x1,
-                                                     gint              y1,
-                                                     gint              x2,
-                                                     gint              y2);
+                                                     gint              x,
+                                                     gint              y,
+                                                     gint              width,
+                                                     gint              height);
 TempBuf * gimp_paint_core_get_orig_proj             (GimpPaintCore    *core,
                                                      GimpPickable     *pickable,
-                                                     gint              x1,
-                                                     gint              y1,
-                                                     gint              x2,
-                                                     gint              y2);
+                                                     gint              x,
+                                                     gint              y,
+                                                     gint              width,
+                                                     gint              height);
 
 void      gimp_paint_core_paste             (GimpPaintCore            *core,
                                              PixelRegion              *paint_maskPR,
diff --git a/app/paint/gimpperspectiveclone.c b/app/paint/gimpperspectiveclone.c
index 3288c21..0135698 100644
--- a/app/paint/gimpperspectiveclone.c
+++ b/app/paint/gimpperspectiveclone.c
@@ -360,11 +360,15 @@ gimp_perspective_clone_get_source (GimpSourceCore   *source_core,
       if (options->sample_merged)
         orig = gimp_paint_core_get_orig_proj (paint_core,
                                               src_pickable,
-                                              xmin, ymin, xmax, ymax);
+                                              xmin, ymin,
+                                              xmax - xmin,
+                                              ymax - ymin);
       else
         orig = gimp_paint_core_get_orig_image (paint_core,
                                                GIMP_DRAWABLE (src_pickable),
-                                               xmin, ymin, xmax, ymax);
+                                               xmin, ymin,
+                                               xmax - xmin,
+                                               ymax - ymin);
 
       pixel_region_init_temp_buf (&origPR, orig,
                                   0, 0, xmax - xmin, ymax - ymin);
diff --git a/app/paint/gimpsourcecore.c b/app/paint/gimpsourcecore.c
index c6f6d04..6dedb5f 100644
--- a/app/paint/gimpsourcecore.c
+++ b/app/paint/gimpsourcecore.c
@@ -450,20 +450,21 @@ gimp_source_core_real_get_source (GimpSourceCore   *source_core,
   GimpImage         *image     = gimp_item_get_image (GIMP_ITEM (drawable));
   GimpImage         *src_image = gimp_pickable_get_image (src_pickable);
   TileManager       *src_tiles = gimp_pickable_get_tiles (src_pickable);
-  gint               x1, y1;
-  gint               x2, y2;
-
-  x1 = CLAMP (paint_area->x + src_offset_x,
-              0, tile_manager_width  (src_tiles));
-  y1 = CLAMP (paint_area->y + src_offset_y,
-              0, tile_manager_height (src_tiles));
-  x2 = CLAMP (paint_area->x + src_offset_x + paint_area->width,
-              0, tile_manager_width  (src_tiles));
-  y2 = CLAMP (paint_area->y + src_offset_y + paint_area->height,
-              0, tile_manager_height (src_tiles));
-
-  if (!(x2 - x1) || !(y2 - y1))
-    return FALSE;
+  gint               x, y;
+  gint               width, height;
+
+  if (! gimp_rectangle_intersect (paint_area->x + src_offset_x,
+                                  paint_area->y + src_offset_y,
+                                  paint_area->width,
+                                  paint_area->height,
+                                  0, 0,
+                                  tile_manager_width  (src_tiles),
+                                  tile_manager_height (src_tiles),
+                                  &x, &y,
+                                  &width, &height))
+    {
+      return FALSE;
+    }
 
   /*  If the source image is different from the destination,
    *  then we should copy straight from the source image
@@ -475,7 +476,8 @@ gimp_source_core_real_get_source (GimpSourceCore   *source_core,
       (! options->sample_merged && (source_core->src_drawable != drawable)))
     {
       pixel_region_init (srcPR, src_tiles,
-                         x1, y1, x2 - x1, y2 - y1, FALSE);
+                         x, y, width, height,
+                         FALSE);
     }
   else
     {
@@ -485,20 +487,20 @@ gimp_source_core_real_get_source (GimpSourceCore   *source_core,
       if (options->sample_merged)
         orig = gimp_paint_core_get_orig_proj (GIMP_PAINT_CORE (source_core),
                                               src_pickable,
-                                              x1, y1, x2, y2);
+                                              x, y, width, height);
       else
         orig = gimp_paint_core_get_orig_image (GIMP_PAINT_CORE (source_core),
                                                GIMP_DRAWABLE (src_pickable),
-                                               x1, y1, x2, y2);
+                                               x, y, width, height);
 
       pixel_region_init_temp_buf (srcPR, orig,
-                                  0, 0, x2 - x1, y2 - y1);
+                                  0, 0, width, height);
     }
 
-  *paint_area_offset_x = x1 - (paint_area->x + src_offset_x);
-  *paint_area_offset_y = y1 - (paint_area->y + src_offset_y);
-  *paint_area_width    = x2 - x1;
-  *paint_area_height   = y2 - y1;
+  *paint_area_offset_x = x - (paint_area->x + src_offset_x);
+  *paint_area_offset_y = y - (paint_area->y + src_offset_y);
+  *paint_area_width    = width;
+  *paint_area_height   = height;
 
   return TRUE;
 }



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