[gimp/gimp-2-10] app: add gimp_gegl_rectangle_align_to_tile_grid()



commit 2b1435568991a632faa8ca8e96f08ef569a08e67
Author: Ell <ell_se yahoo com>
Date:   Sun Dec 2 02:30:55 2018 -0500

    app: add gimp_gegl_rectangle_align_to_tile_grid()
    
    ... which expands a GeglRectangle, such that it's aligned to the
    tile grid of a given GeglBuffer.
    
    (cherry picked from commit 69e5f783c57c8b18e5f009c13fbf802d2b2d6d89)

 app/gegl/gimp-gegl-utils.c | 36 ++++++++++++++++++++++++++++++++++++
 app/gegl/gimp-gegl-utils.h | 26 +++++++++++++++-----------
 2 files changed, 51 insertions(+), 11 deletions(-)
---
diff --git a/app/gegl/gimp-gegl-utils.c b/app/gegl/gimp-gegl-utils.c
index 96d3936776..f9bc64a4b6 100644
--- a/app/gegl/gimp-gegl-utils.c
+++ b/app/gegl/gimp-gegl-utils.c
@@ -25,6 +25,8 @@
 #include <gegl.h>
 #include <gegl-plugin.h>
 
+#include "libgimpmath/gimpmath.h"
+
 #include "gimp-gegl-types.h"
 
 #include "core/gimpprogress.h"
@@ -151,3 +153,37 @@ gimp_gegl_param_spec_has_key (GParamSpec  *pspec,
 
   return FALSE;
 }
+
+void
+gimp_gegl_rectangle_align_to_tile_grid (GeglRectangle       *dest,
+                                        const GeglRectangle *src,
+                                        GeglBuffer          *buffer)
+{
+  gint          shift_x;
+  gint          shift_y;
+  gint          tile_width;
+  gint          tile_height;
+  GeglRectangle rect;
+
+  g_return_if_fail (dest != NULL);
+  g_return_if_fail (src != NULL);
+  g_return_if_fail (GEGL_IS_BUFFER (buffer));
+
+  g_object_get (buffer,
+                "shift-x",     &shift_x,
+                "shift-y",     &shift_y,
+                "tile-width",  &tile_width,
+                "tile-height", &tile_height,
+                NULL);
+
+  rect.x      = (gint) floor ((gdouble) (src->x               + shift_x) /
+                              tile_width)  * tile_width;
+  rect.y      = (gint) floor ((gdouble) (src->y               + shift_y) /
+                              tile_height) * tile_height;
+  rect.width  = (gint) ceil  ((gdouble) (src->x + src->width  + shift_x) /
+                              tile_width)  * tile_width  - rect.x;
+  rect.height = (gint) ceil  ((gdouble) (src->y + src->height + shift_y) /
+                              tile_height) * tile_height - rect.y;
+
+  *dest = rect;
+}
diff --git a/app/gegl/gimp-gegl-utils.h b/app/gegl/gimp-gegl-utils.h
index cc25338aa4..cb76012b6e 100644
--- a/app/gegl/gimp-gegl-utils.h
+++ b/app/gegl/gimp-gegl-utils.h
@@ -22,21 +22,25 @@
 #define __GIMP_GEGL_UTILS_H__
 
 
-GType        gimp_gegl_get_op_enum_type   (const gchar   *operation,
-                                           const gchar   *property);
+GType        gimp_gegl_get_op_enum_type             (const gchar         *operation,
+                                                     const gchar         *property);
 
-GeglColor  * gimp_gegl_color_new          (const GimpRGB *rgb);
+GeglColor  * gimp_gegl_color_new                    (const GimpRGB       *rgb);
 
-void         gimp_gegl_progress_connect   (GeglNode      *node,
-                                           GimpProgress  *progress,
-                                           const gchar   *text);
+void         gimp_gegl_progress_connect             (GeglNode            *node,
+                                                     GimpProgress        *progress,
+                                                     const gchar         *text);
 
-const Babl * gimp_gegl_node_get_format    (GeglNode      *node,
-                                           const gchar   *pad_name);
+const Babl * gimp_gegl_node_get_format              (GeglNode            *node,
+                                                     const gchar         *pad_name);
 
-gboolean     gimp_gegl_param_spec_has_key (GParamSpec    *pspec,
-                                           const gchar   *key,
-                                           const gchar   *value);
+gboolean     gimp_gegl_param_spec_has_key           (GParamSpec          *pspec,
+                                                     const gchar         *key,
+                                                     const gchar         *value);
+
+void         gimp_gegl_rectangle_align_to_tile_grid (GeglRectangle       *dest,
+                                                     const GeglRectangle *src,
+                                                     GeglBuffer          *buffer);
 
 
 #endif /* __GIMP_GEGL_UTILS_H__ */


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