diff --git a/app/gegl/gimp-gegl-utils.c b/app/gegl/gimp-gegl-utils.c index 30e9afa680..dc2ecfdd9b 100644 --- a/app/gegl/gimp-gegl-utils.c +++ b/app/gegl/gimp-gegl-utils.c @@ -25,6 +25,8 @@ #include #include +#include "libgimpmath/gimpmath.h" + #include "gimp-gegl-types.h" #include "core/gimpprogress.h" @@ -154,3 +156,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 7903532f38..918b71bdf2 100644 --- a/app/gegl/gimp-gegl-utils.h +++ b/app/gegl/gimp-gegl-utils.h @@ -22,22 +22,26 @@ #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, - const Babl *space); +GeglColor * gimp_gegl_color_new (const GimpRGB *rgb, + const Babl *space); -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__ */