app: port GimpPaintCore's paste and replase APIs to GeglBuffer

This commit is contained in:
Michael Natterer 2012-04-03 23:58:56 +02:00
parent f07f01664e
commit 36fb008197
4 changed files with 128 additions and 65 deletions

View file

@ -935,7 +935,7 @@ gimp_brush_core_paste_canvas (GimpBrushCore *core,
if (brush_mask)
{
GimpPaintCore *paint_core = GIMP_PAINT_CORE (core);
PixelRegion brush_maskPR;
GeglBuffer *paint_mask;
gint x;
gint y;
gint off_x;
@ -947,15 +947,20 @@ gimp_brush_core_paste_canvas (GimpBrushCore *core,
off_x = (x < 0) ? -x : 0;
off_y = (y < 0) ? -y : 0;
pixel_region_init_temp_buf (&brush_maskPR, (TempBuf *) brush_mask,
off_x, off_y,
gegl_buffer_get_width (paint_core->paint_buffer),
gegl_buffer_get_height (paint_core->paint_buffer));
paint_mask = gimp_temp_buf_create_buffer ((TempBuf *) brush_mask,
babl_format ("Y u8"),
FALSE);
gimp_paint_core_paste (paint_core, &brush_maskPR, drawable,
gimp_paint_core_paste (paint_core, paint_mask,
GEGL_RECTANGLE (off_x, off_y,
gegl_buffer_get_width (paint_core->paint_buffer),
gegl_buffer_get_height (paint_core->paint_buffer)),
drawable,
brush_opacity,
image_opacity, paint_mode,
mode);
g_object_unref (paint_mask);
}
}
@ -981,7 +986,7 @@ gimp_brush_core_replace_canvas (GimpBrushCore *core,
if (brush_mask)
{
GimpPaintCore *paint_core = GIMP_PAINT_CORE (core);
PixelRegion brush_maskPR;
GeglBuffer *paint_mask;
gint x;
gint y;
gint off_x;
@ -993,12 +998,15 @@ gimp_brush_core_replace_canvas (GimpBrushCore *core,
off_x = (x < 0) ? -x : 0;
off_y = (y < 0) ? -y : 0;
pixel_region_init_temp_buf (&brush_maskPR, (TempBuf *) brush_mask,
off_x, off_y,
gegl_buffer_get_width (paint_core->paint_buffer),
gegl_buffer_get_height (paint_core->paint_buffer));
paint_mask = gimp_temp_buf_create_buffer ((TempBuf *) brush_mask,
babl_format ("Y u8"),
FALSE);
gimp_paint_core_replace (paint_core, &brush_maskPR, drawable,
gimp_paint_core_replace (paint_core, paint_mask,
GEGL_RECTANGLE (off_x, off_y,
gegl_buffer_get_width (paint_core->paint_buffer),
gegl_buffer_get_height (paint_core->paint_buffer)),
drawable,
brush_opacity,
image_opacity,
mode);

View file

@ -25,7 +25,6 @@
#include "paint-types.h"
#include "base/pixel-region.h"
#include "base/temp-buf.h"
#include "gegl/gimp-gegl-utils.h"
@ -272,7 +271,6 @@ gimp_ink_motion (GimpPaintCore *paint_core,
gint paint_buffer_y;
GimpRGB foreground;
GeglColor *color;
PixelRegion blob_maskPR;
if (! ink->last_blob)
{
@ -335,15 +333,13 @@ gimp_ink_motion (GimpPaintCore *paint_core,
blob_to_render);
/* draw the paint_area using the just rendered canvas_buffer as mask */
pixel_region_init (&blob_maskPR,
gimp_gegl_buffer_get_tiles (paint_core->canvas_buffer),
paint_core->paint_buffer_x,
paint_core->paint_buffer_y,
gegl_buffer_get_width (paint_core->paint_buffer),
gegl_buffer_get_height (paint_core->paint_buffer),
FALSE);
gimp_paint_core_paste (paint_core, &blob_maskPR, drawable,
gimp_paint_core_paste (paint_core,
paint_core->canvas_buffer,
GEGL_RECTANGLE (paint_core->paint_buffer_x,
paint_core->paint_buffer_y,
gegl_buffer_get_width (paint_core->paint_buffer),
gegl_buffer_get_height (paint_core->paint_buffer)),
drawable,
GIMP_OPACITY_OPAQUE,
gimp_context_get_opacity (context),
gimp_context_get_paint_mode (context),

View file

@ -106,13 +106,15 @@ static GimpUndo* gimp_paint_core_real_push_undo (GimpPaintCore *core,
GimpImage *image,
const gchar *undo_desc);
static void paint_mask_to_canvas_buffer (GimpPaintCore *core,
PixelRegion *paint_maskPR,
gdouble paint_opacity);
static void paint_mask_to_paint_area (GimpPaintCore *core,
PixelRegion *paint_maskPR,
gdouble paint_opacity);
static void canvas_buffer_to_paint_area (GimpPaintCore *core);
static void paint_mask_to_canvas_buffer (GimpPaintCore *core,
GeglBuffer *paint_mask,
const GeglRectangle *paint_mask_rect,
gdouble paint_opacity);
static void paint_mask_to_paint_area (GimpPaintCore *core,
GeglBuffer *paint_mask,
const GeglRectangle *paint_mask_rect,
gdouble paint_opacity);
static void canvas_buffer_to_paint_area (GimpPaintCore *core);
G_DEFINE_TYPE (GimpPaintCore, gimp_paint_core, GIMP_TYPE_OBJECT)
@ -710,7 +712,8 @@ gimp_paint_core_get_orig_proj (GimpPaintCore *core)
void
gimp_paint_core_paste (GimpPaintCore *core,
PixelRegion *paint_maskPR,
GeglBuffer *paint_mask,
const GeglRectangle *paint_mask_rect,
GimpDrawable *drawable,
gdouble paint_opacity,
gdouble image_opacity,
@ -728,10 +731,10 @@ gimp_paint_core_paste (GimpPaintCore *core,
/* Some tools (ink) paint the mask to paint_core->canvas_buffer
* directly. Don't need to copy it in this case.
*/
if (paint_maskPR->tiles !=
gimp_gegl_buffer_get_tiles (core->canvas_buffer))
if (paint_mask != core->canvas_buffer)
{
paint_mask_to_canvas_buffer (core, paint_maskPR, paint_opacity);
paint_mask_to_canvas_buffer (core, paint_mask, paint_mask_rect,
paint_opacity);
}
canvas_buffer_to_paint_area (core);
@ -743,7 +746,8 @@ gimp_paint_core_paste (GimpPaintCore *core,
*/
else
{
paint_mask_to_paint_area (core, paint_maskPR, paint_opacity);
paint_mask_to_paint_area (core, paint_mask, paint_mask_rect,
paint_opacity);
}
width = gegl_buffer_get_width (core->paint_buffer);
@ -785,17 +789,20 @@ gimp_paint_core_paste (GimpPaintCore *core,
*/
void
gimp_paint_core_replace (GimpPaintCore *core,
PixelRegion *paint_maskPR,
GeglBuffer *paint_mask,
const GeglRectangle *paint_mask_rect,
GimpDrawable *drawable,
gdouble paint_opacity,
gdouble image_opacity,
GimpPaintApplicationMode mode)
{
gint width, height;
PixelRegion paint_maskPR;
gint width, height;
if (! gimp_drawable_has_alpha (drawable))
{
gimp_paint_core_paste (core, paint_maskPR, drawable,
gimp_paint_core_paste (core, paint_mask, paint_mask_rect,
drawable,
paint_opacity,
image_opacity, GIMP_NORMAL_MODE,
mode);
@ -805,29 +812,35 @@ gimp_paint_core_replace (GimpPaintCore *core,
width = gegl_buffer_get_width (core->paint_buffer);
height = gegl_buffer_get_height (core->paint_buffer);
if (mode == GIMP_PAINT_CONSTANT)
{
if (mode == GIMP_PAINT_CONSTANT &&
/* Some tools (ink) paint the mask to paint_core->canvas_buffer
* directly. Don't need to copy it in this case.
*/
if (paint_maskPR->tiles !=
gimp_gegl_buffer_get_tiles (core->canvas_buffer))
{
/* combine the paint mask and the canvas buffer */
paint_mask_to_canvas_buffer (core, paint_maskPR, paint_opacity);
paint_mask != core->canvas_buffer)
{
/* combine the paint mask and the canvas buffer */
paint_mask_to_canvas_buffer (core, paint_mask, paint_mask_rect,
paint_opacity);
/* initialize the maskPR from the canvas buffer */
pixel_region_init (paint_maskPR,
gimp_gegl_buffer_get_tiles (core->canvas_buffer),
core->paint_buffer_x,
core->paint_buffer_y,
width, height,
FALSE);
}
/* initialize the maskPR from the canvas buffer */
pixel_region_init (&paint_maskPR,
gimp_gegl_buffer_get_tiles (core->canvas_buffer),
core->paint_buffer_x,
core->paint_buffer_y,
width, height,
FALSE);
}
else
{
/* The mask is just the paint_maskPR */
/* The mask is just the paint_mask */
pixel_region_init (&paint_maskPR,
gimp_gegl_buffer_get_tiles (paint_mask),
paint_mask_rect->x,
paint_mask_rect->y,
paint_mask_rect->width,
paint_mask_rect->height,
FALSE);
}
/* apply the paint area to the image */
@ -835,7 +848,7 @@ gimp_paint_core_replace (GimpPaintCore *core,
GEGL_RECTANGLE (0, 0, width, height),
FALSE, NULL,
image_opacity,
paint_maskPR,
&paint_maskPR,
core->paint_buffer_x,
core->paint_buffer_y);
@ -947,11 +960,13 @@ canvas_buffer_to_paint_area (GimpPaintCore *core)
}
static void
paint_mask_to_canvas_buffer (GimpPaintCore *core,
PixelRegion *paint_maskPR,
gdouble paint_opacity)
paint_mask_to_canvas_buffer (GimpPaintCore *core,
GeglBuffer *paint_mask,
const GeglRectangle *paint_mask_rect,
gdouble paint_opacity)
{
PixelRegion srcPR;
PixelRegion paint_maskPR;
/* combine the paint mask and the canvas buffer */
pixel_region_init (&srcPR,
@ -962,17 +977,39 @@ paint_mask_to_canvas_buffer (GimpPaintCore *core,
gegl_buffer_get_height (core->paint_buffer),
TRUE);
if (gimp_gegl_buffer_get_temp_buf (paint_mask))
{
pixel_region_init_temp_buf (&paint_maskPR,
gimp_gegl_buffer_get_temp_buf (paint_mask),
paint_mask_rect->x,
paint_mask_rect->y,
paint_mask_rect->width,
paint_mask_rect->height);
}
else
{
pixel_region_init (&paint_maskPR,
gimp_gegl_buffer_get_tiles (paint_mask),
paint_mask_rect->x,
paint_mask_rect->y,
paint_mask_rect->width,
paint_mask_rect->height,
FALSE);
}
/* combine the mask to the canvas tiles */
combine_mask_and_region (&srcPR, paint_maskPR,
combine_mask_and_region (&srcPR, &paint_maskPR,
paint_opacity * 255.999, GIMP_IS_AIRBRUSH (core));
}
static void
paint_mask_to_paint_area (GimpPaintCore *core,
PixelRegion *paint_maskPR,
gdouble paint_opacity)
paint_mask_to_paint_area (GimpPaintCore *core,
GeglBuffer *paint_mask,
const GeglRectangle *paint_mask_rect,
gdouble paint_opacity)
{
PixelRegion srcPR;
PixelRegion paint_maskPR;
/* combine the canvas buf and the paint mask to the canvas buf */
pixel_region_init_temp_buf (&srcPR,
@ -981,6 +1018,26 @@ paint_mask_to_paint_area (GimpPaintCore *core,
gegl_buffer_get_width (core->paint_buffer),
gegl_buffer_get_height (core->paint_buffer));
if (gimp_gegl_buffer_get_temp_buf (paint_mask))
{
pixel_region_init_temp_buf (&paint_maskPR,
gimp_gegl_buffer_get_temp_buf (paint_mask),
paint_mask_rect->x,
paint_mask_rect->y,
paint_mask_rect->width,
paint_mask_rect->height);
}
else
{
pixel_region_init (&paint_maskPR,
gimp_gegl_buffer_get_tiles (paint_mask),
paint_mask_rect->x,
paint_mask_rect->y,
paint_mask_rect->width,
paint_mask_rect->height,
FALSE);
}
/* apply the mask */
apply_mask_to_region (&srcPR, paint_maskPR, paint_opacity * 255.999);
apply_mask_to_region (&srcPR, &paint_maskPR, paint_opacity * 255.999);
}

View file

@ -166,14 +166,16 @@ GeglBuffer * gimp_paint_core_get_orig_image (GimpPaintCore *core);
GeglBuffer * gimp_paint_core_get_orig_proj (GimpPaintCore *core);
void gimp_paint_core_paste (GimpPaintCore *core,
PixelRegion *paint_maskPR,
GeglBuffer *paint_mask,
const GeglRectangle *paint_mask_rect,
GimpDrawable *drawable,
gdouble paint_opacity,
gdouble image_opacity,
GimpLayerModeEffects paint_mode,
GimpPaintApplicationMode mode);
void gimp_paint_core_replace (GimpPaintCore *core,
PixelRegion *paint_maskPR,
GeglBuffer *paint_mask,
const GeglRectangle *paint_mask_rect,
GimpDrawable *drawable,
gdouble paint_opacity,
gdouble image_opacity,