app: port gimp_brush_core_color_area_with_pixmap() to GeglBufferIterator

This can be simplified, needs revisiting.
This commit is contained in:
Michael Natterer
2012-04-14 08:41:08 +02:00
parent 774b6e3c16
commit 9a4d84e683
3 changed files with 30 additions and 40 deletions

View File

@ -25,8 +25,6 @@
#include "paint-types.h" #include "paint-types.h"
#include "base/pixel-region.h"
#include "gegl/gimp-gegl-utils.h" #include "gegl/gimp-gegl-utils.h"
#include "core/gimpbrush.h" #include "core/gimpbrush.h"
@ -119,14 +117,12 @@ static void gimp_brush_core_invalidate_cache (GimpBrush *brush,
GimpBrushCore *core); GimpBrushCore *core);
/* brush pipe utility functions */ /* brush pipe utility functions */
static void gimp_brush_core_paint_line_pixmap_mask (GimpImage *dest, static void gimp_brush_core_paint_line_pixmap_mask (GimpDrawable *drawable,
GimpDrawable *drawable,
const GimpTempBuf *pixmap_mask, const GimpTempBuf *pixmap_mask,
const GimpTempBuf *brush_mask, const GimpTempBuf *brush_mask,
guchar *d, guchar *d,
gint x, gint x,
gint y, gint y,
gint bytes,
gint width, gint width,
GimpBrushApplicationMode mode); GimpBrushApplicationMode mode);
@ -1546,28 +1542,24 @@ void
gimp_brush_core_color_area_with_pixmap (GimpBrushCore *core, gimp_brush_core_color_area_with_pixmap (GimpBrushCore *core,
GimpDrawable *drawable, GimpDrawable *drawable,
const GimpCoords *coords, const GimpCoords *coords,
GimpTempBuf *area, GeglBuffer *area,
gint area_x, gint area_x,
gint area_y, gint area_y,
GimpBrushApplicationMode mode) GimpBrushApplicationMode mode)
{ {
GimpImage *image; GeglBufferIterator *iter;
PixelRegion destPR; GeglRectangle *roi;
void *pr; gint bpp;
guchar *d; gint ulx;
gint ulx; gint uly;
gint uly; gint offsetx;
gint offsetx; gint offsety;
gint offsety; const GimpTempBuf *pixmap_mask;
gint y; const GimpTempBuf *brush_mask;
const GimpTempBuf *pixmap_mask;
const GimpTempBuf *brush_mask;
g_return_if_fail (GIMP_IS_BRUSH (core->brush)); g_return_if_fail (GIMP_IS_BRUSH (core->brush));
g_return_if_fail (core->brush->pixmap != NULL); g_return_if_fail (core->brush->pixmap != NULL);
image = gimp_item_get_image (GIMP_ITEM (drawable));
/* scale the brushes */ /* scale the brushes */
pixmap_mask = gimp_brush_core_transform_pixmap (core, core->brush); pixmap_mask = gimp_brush_core_transform_pixmap (core, core->brush);
@ -1579,11 +1571,6 @@ gimp_brush_core_color_area_with_pixmap (GimpBrushCore *core,
else else
brush_mask = NULL; brush_mask = NULL;
pixel_region_init_temp_buf (&destPR, area,
0, 0, area->width, area->height);
pr = pixel_regions_register (1, &destPR);
/* Calculate upper left corner of brush as in /* Calculate upper left corner of brush as in
* gimp_paint_core_get_paint_area. Ugly to have to do this here, too. * gimp_paint_core_get_paint_area. Ugly to have to do this here, too.
*/ */
@ -1593,38 +1580,43 @@ gimp_brush_core_color_area_with_pixmap (GimpBrushCore *core,
/* Not sure why this is necessary, but empirically the code does /* Not sure why this is necessary, but empirically the code does
* not work without it for even-sided brushes. See bug #166622. * not work without it for even-sided brushes. See bug #166622.
*/ */
if (pixmap_mask->width %2 == 0) if (pixmap_mask->width % 2 == 0)
ulx += ROUND (coords->x) - floor (coords->x); ulx += ROUND (coords->x) - floor (coords->x);
if (pixmap_mask->height %2 == 0) if (pixmap_mask->height % 2 == 0)
uly += ROUND (coords->y) - floor (coords->y); uly += ROUND (coords->y) - floor (coords->y);
offsetx = area_x - ulx; offsetx = area_x - ulx;
offsety = area_y - uly; offsety = area_y - uly;
for (; pr != NULL; pr = pixel_regions_process (pr)) bpp = babl_format_get_bytes_per_pixel (gegl_buffer_get_format (area));
{
d = destPR.data;
for (y = 0; y < destPR.h; y++) iter = gegl_buffer_iterator_new (area, NULL, 0, NULL,
GEGL_BUFFER_WRITE, GEGL_ABYSS_NONE);
roi = &iter->roi[0];
while (gegl_buffer_iterator_next (iter))
{
guchar *d = iter->data[0];
gint y;
for (y = 0; y < roi->height; y++)
{ {
gimp_brush_core_paint_line_pixmap_mask (image, drawable, gimp_brush_core_paint_line_pixmap_mask (drawable,
pixmap_mask, brush_mask, pixmap_mask, brush_mask,
d, offsetx, y + offsety, d, offsetx, y + offsety,
destPR.bytes, destPR.w, mode); roi->width, mode);
d += destPR.rowstride; d += roi->width * bpp;
} }
} }
} }
static void static void
gimp_brush_core_paint_line_pixmap_mask (GimpImage *dest, gimp_brush_core_paint_line_pixmap_mask (GimpDrawable *drawable,
GimpDrawable *drawable,
const GimpTempBuf *pixmap_mask, const GimpTempBuf *pixmap_mask,
const GimpTempBuf *brush_mask, const GimpTempBuf *brush_mask,
guchar *d, guchar *d,
gint x, gint x,
gint y, gint y,
gint bytes,
gint width, gint width,
GimpBrushApplicationMode mode) GimpBrushApplicationMode mode)
{ {

View File

@ -121,7 +121,7 @@ void gimp_brush_core_color_area_with_pixmap
(GimpBrushCore *core, (GimpBrushCore *core,
GimpDrawable *drawable, GimpDrawable *drawable,
const GimpCoords *coords, const GimpCoords *coords,
GimpTempBuf *area, GeglBuffer *area,
gint area_x, gint area_x,
gint area_y, gint area_y,
GimpBrushApplicationMode mode); GimpBrushApplicationMode mode);

View File

@ -181,11 +181,9 @@ _gimp_paintbrush_motion (GimpPaintCore *paint_core,
/* otherwise check if the brush has a pixmap and use that to /* otherwise check if the brush has a pixmap and use that to
* color the area * color the area
*/ */
GimpTempBuf *area = gimp_gegl_buffer_get_temp_buf (paint_buffer);
gimp_brush_core_color_area_with_pixmap (brush_core, drawable, gimp_brush_core_color_area_with_pixmap (brush_core, drawable,
coords, coords,
area, paint_buffer,
paint_buffer_x, paint_buffer_x,
paint_buffer_y, paint_buffer_y,
gimp_paint_options_get_brush_mode (paint_options)); gimp_paint_options_get_brush_mode (paint_options));