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.
This commit is contained in:
Ell 2018-12-02 02:30:55 -05:00
parent f27b38808f
commit 69e5f783c5
2 changed files with 52 additions and 12 deletions

View File

@ -25,6 +25,8 @@
#include <gegl.h> #include <gegl.h>
#include <gegl-plugin.h> #include <gegl-plugin.h>
#include "libgimpmath/gimpmath.h"
#include "gimp-gegl-types.h" #include "gimp-gegl-types.h"
#include "core/gimpprogress.h" #include "core/gimpprogress.h"
@ -154,3 +156,37 @@ gimp_gegl_param_spec_has_key (GParamSpec *pspec,
return FALSE; 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;
}

View File

@ -22,22 +22,26 @@
#define __GIMP_GEGL_UTILS_H__ #define __GIMP_GEGL_UTILS_H__
GType gimp_gegl_get_op_enum_type (const gchar *operation, GType gimp_gegl_get_op_enum_type (const gchar *operation,
const gchar *property); const gchar *property);
GeglColor * gimp_gegl_color_new (const GimpRGB *rgb, GeglColor * gimp_gegl_color_new (const GimpRGB *rgb,
const Babl *space); const Babl *space);
void gimp_gegl_progress_connect (GeglNode *node, void gimp_gegl_progress_connect (GeglNode *node,
GimpProgress *progress, GimpProgress *progress,
const gchar *text); const gchar *text);
const Babl * gimp_gegl_node_get_format (GeglNode *node, const Babl * gimp_gegl_node_get_format (GeglNode *node,
const gchar *pad_name); const gchar *pad_name);
gboolean gimp_gegl_param_spec_has_key (GParamSpec *pspec, gboolean gimp_gegl_param_spec_has_key (GParamSpec *pspec,
const gchar *key, const gchar *key,
const gchar *value); const gchar *value);
void gimp_gegl_rectangle_align_to_tile_grid (GeglRectangle *dest,
const GeglRectangle *src,
GeglBuffer *buffer);
#endif /* __GIMP_GEGL_UTILS_H__ */ #endif /* __GIMP_GEGL_UTILS_H__ */