app: port GimpPaintCore's paste and replase APIs to GeglBuffer
This commit is contained in:
@ -935,7 +935,7 @@ gimp_brush_core_paste_canvas (GimpBrushCore *core,
|
|||||||
if (brush_mask)
|
if (brush_mask)
|
||||||
{
|
{
|
||||||
GimpPaintCore *paint_core = GIMP_PAINT_CORE (core);
|
GimpPaintCore *paint_core = GIMP_PAINT_CORE (core);
|
||||||
PixelRegion brush_maskPR;
|
GeglBuffer *paint_mask;
|
||||||
gint x;
|
gint x;
|
||||||
gint y;
|
gint y;
|
||||||
gint off_x;
|
gint off_x;
|
||||||
@ -947,15 +947,20 @@ gimp_brush_core_paste_canvas (GimpBrushCore *core,
|
|||||||
off_x = (x < 0) ? -x : 0;
|
off_x = (x < 0) ? -x : 0;
|
||||||
off_y = (y < 0) ? -y : 0;
|
off_y = (y < 0) ? -y : 0;
|
||||||
|
|
||||||
pixel_region_init_temp_buf (&brush_maskPR, (TempBuf *) brush_mask,
|
paint_mask = gimp_temp_buf_create_buffer ((TempBuf *) brush_mask,
|
||||||
off_x, off_y,
|
babl_format ("Y u8"),
|
||||||
gegl_buffer_get_width (paint_core->paint_buffer),
|
FALSE);
|
||||||
gegl_buffer_get_height (paint_core->paint_buffer));
|
|
||||||
|
|
||||||
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,
|
brush_opacity,
|
||||||
image_opacity, paint_mode,
|
image_opacity, paint_mode,
|
||||||
mode);
|
mode);
|
||||||
|
|
||||||
|
g_object_unref (paint_mask);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -981,7 +986,7 @@ gimp_brush_core_replace_canvas (GimpBrushCore *core,
|
|||||||
if (brush_mask)
|
if (brush_mask)
|
||||||
{
|
{
|
||||||
GimpPaintCore *paint_core = GIMP_PAINT_CORE (core);
|
GimpPaintCore *paint_core = GIMP_PAINT_CORE (core);
|
||||||
PixelRegion brush_maskPR;
|
GeglBuffer *paint_mask;
|
||||||
gint x;
|
gint x;
|
||||||
gint y;
|
gint y;
|
||||||
gint off_x;
|
gint off_x;
|
||||||
@ -993,12 +998,15 @@ gimp_brush_core_replace_canvas (GimpBrushCore *core,
|
|||||||
off_x = (x < 0) ? -x : 0;
|
off_x = (x < 0) ? -x : 0;
|
||||||
off_y = (y < 0) ? -y : 0;
|
off_y = (y < 0) ? -y : 0;
|
||||||
|
|
||||||
pixel_region_init_temp_buf (&brush_maskPR, (TempBuf *) brush_mask,
|
paint_mask = gimp_temp_buf_create_buffer ((TempBuf *) brush_mask,
|
||||||
off_x, off_y,
|
babl_format ("Y u8"),
|
||||||
gegl_buffer_get_width (paint_core->paint_buffer),
|
FALSE);
|
||||||
gegl_buffer_get_height (paint_core->paint_buffer));
|
|
||||||
|
|
||||||
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,
|
brush_opacity,
|
||||||
image_opacity,
|
image_opacity,
|
||||||
mode);
|
mode);
|
||||||
|
@ -25,7 +25,6 @@
|
|||||||
|
|
||||||
#include "paint-types.h"
|
#include "paint-types.h"
|
||||||
|
|
||||||
#include "base/pixel-region.h"
|
|
||||||
#include "base/temp-buf.h"
|
#include "base/temp-buf.h"
|
||||||
|
|
||||||
#include "gegl/gimp-gegl-utils.h"
|
#include "gegl/gimp-gegl-utils.h"
|
||||||
@ -272,7 +271,6 @@ gimp_ink_motion (GimpPaintCore *paint_core,
|
|||||||
gint paint_buffer_y;
|
gint paint_buffer_y;
|
||||||
GimpRGB foreground;
|
GimpRGB foreground;
|
||||||
GeglColor *color;
|
GeglColor *color;
|
||||||
PixelRegion blob_maskPR;
|
|
||||||
|
|
||||||
if (! ink->last_blob)
|
if (! ink->last_blob)
|
||||||
{
|
{
|
||||||
@ -335,15 +333,13 @@ gimp_ink_motion (GimpPaintCore *paint_core,
|
|||||||
blob_to_render);
|
blob_to_render);
|
||||||
|
|
||||||
/* draw the paint_area using the just rendered canvas_buffer as mask */
|
/* draw the paint_area using the just rendered canvas_buffer as mask */
|
||||||
pixel_region_init (&blob_maskPR,
|
gimp_paint_core_paste (paint_core,
|
||||||
gimp_gegl_buffer_get_tiles (paint_core->canvas_buffer),
|
paint_core->canvas_buffer,
|
||||||
paint_core->paint_buffer_x,
|
GEGL_RECTANGLE (paint_core->paint_buffer_x,
|
||||||
paint_core->paint_buffer_y,
|
paint_core->paint_buffer_y,
|
||||||
gegl_buffer_get_width (paint_core->paint_buffer),
|
gegl_buffer_get_width (paint_core->paint_buffer),
|
||||||
gegl_buffer_get_height (paint_core->paint_buffer),
|
gegl_buffer_get_height (paint_core->paint_buffer)),
|
||||||
FALSE);
|
drawable,
|
||||||
|
|
||||||
gimp_paint_core_paste (paint_core, &blob_maskPR, drawable,
|
|
||||||
GIMP_OPACITY_OPAQUE,
|
GIMP_OPACITY_OPAQUE,
|
||||||
gimp_context_get_opacity (context),
|
gimp_context_get_opacity (context),
|
||||||
gimp_context_get_paint_mode (context),
|
gimp_context_get_paint_mode (context),
|
||||||
|
@ -106,13 +106,15 @@ static GimpUndo* gimp_paint_core_real_push_undo (GimpPaintCore *core,
|
|||||||
GimpImage *image,
|
GimpImage *image,
|
||||||
const gchar *undo_desc);
|
const gchar *undo_desc);
|
||||||
|
|
||||||
static void paint_mask_to_canvas_buffer (GimpPaintCore *core,
|
static void paint_mask_to_canvas_buffer (GimpPaintCore *core,
|
||||||
PixelRegion *paint_maskPR,
|
GeglBuffer *paint_mask,
|
||||||
gdouble paint_opacity);
|
const GeglRectangle *paint_mask_rect,
|
||||||
static void paint_mask_to_paint_area (GimpPaintCore *core,
|
gdouble paint_opacity);
|
||||||
PixelRegion *paint_maskPR,
|
static void paint_mask_to_paint_area (GimpPaintCore *core,
|
||||||
gdouble paint_opacity);
|
GeglBuffer *paint_mask,
|
||||||
static void canvas_buffer_to_paint_area (GimpPaintCore *core);
|
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)
|
G_DEFINE_TYPE (GimpPaintCore, gimp_paint_core, GIMP_TYPE_OBJECT)
|
||||||
@ -710,7 +712,8 @@ gimp_paint_core_get_orig_proj (GimpPaintCore *core)
|
|||||||
|
|
||||||
void
|
void
|
||||||
gimp_paint_core_paste (GimpPaintCore *core,
|
gimp_paint_core_paste (GimpPaintCore *core,
|
||||||
PixelRegion *paint_maskPR,
|
GeglBuffer *paint_mask,
|
||||||
|
const GeglRectangle *paint_mask_rect,
|
||||||
GimpDrawable *drawable,
|
GimpDrawable *drawable,
|
||||||
gdouble paint_opacity,
|
gdouble paint_opacity,
|
||||||
gdouble image_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
|
/* Some tools (ink) paint the mask to paint_core->canvas_buffer
|
||||||
* directly. Don't need to copy it in this case.
|
* directly. Don't need to copy it in this case.
|
||||||
*/
|
*/
|
||||||
if (paint_maskPR->tiles !=
|
if (paint_mask != core->canvas_buffer)
|
||||||
gimp_gegl_buffer_get_tiles (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);
|
canvas_buffer_to_paint_area (core);
|
||||||
@ -743,7 +746,8 @@ gimp_paint_core_paste (GimpPaintCore *core,
|
|||||||
*/
|
*/
|
||||||
else
|
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);
|
width = gegl_buffer_get_width (core->paint_buffer);
|
||||||
@ -785,17 +789,20 @@ gimp_paint_core_paste (GimpPaintCore *core,
|
|||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
gimp_paint_core_replace (GimpPaintCore *core,
|
gimp_paint_core_replace (GimpPaintCore *core,
|
||||||
PixelRegion *paint_maskPR,
|
GeglBuffer *paint_mask,
|
||||||
|
const GeglRectangle *paint_mask_rect,
|
||||||
GimpDrawable *drawable,
|
GimpDrawable *drawable,
|
||||||
gdouble paint_opacity,
|
gdouble paint_opacity,
|
||||||
gdouble image_opacity,
|
gdouble image_opacity,
|
||||||
GimpPaintApplicationMode mode)
|
GimpPaintApplicationMode mode)
|
||||||
{
|
{
|
||||||
gint width, height;
|
PixelRegion paint_maskPR;
|
||||||
|
gint width, height;
|
||||||
|
|
||||||
if (! gimp_drawable_has_alpha (drawable))
|
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,
|
paint_opacity,
|
||||||
image_opacity, GIMP_NORMAL_MODE,
|
image_opacity, GIMP_NORMAL_MODE,
|
||||||
mode);
|
mode);
|
||||||
@ -805,29 +812,35 @@ gimp_paint_core_replace (GimpPaintCore *core,
|
|||||||
width = gegl_buffer_get_width (core->paint_buffer);
|
width = gegl_buffer_get_width (core->paint_buffer);
|
||||||
height = gegl_buffer_get_height (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
|
/* Some tools (ink) paint the mask to paint_core->canvas_buffer
|
||||||
* directly. Don't need to copy it in this case.
|
* directly. Don't need to copy it in this case.
|
||||||
*/
|
*/
|
||||||
if (paint_maskPR->tiles !=
|
paint_mask != core->canvas_buffer)
|
||||||
gimp_gegl_buffer_get_tiles (core->canvas_buffer))
|
{
|
||||||
{
|
/* combine the paint mask and the canvas buffer */
|
||||||
/* combine the paint mask and the canvas buffer */
|
paint_mask_to_canvas_buffer (core, paint_mask, paint_mask_rect,
|
||||||
paint_mask_to_canvas_buffer (core, paint_maskPR, paint_opacity);
|
paint_opacity);
|
||||||
|
|
||||||
/* initialize the maskPR from the canvas buffer */
|
/* initialize the maskPR from the canvas buffer */
|
||||||
pixel_region_init (paint_maskPR,
|
pixel_region_init (&paint_maskPR,
|
||||||
gimp_gegl_buffer_get_tiles (core->canvas_buffer),
|
gimp_gegl_buffer_get_tiles (core->canvas_buffer),
|
||||||
core->paint_buffer_x,
|
core->paint_buffer_x,
|
||||||
core->paint_buffer_y,
|
core->paint_buffer_y,
|
||||||
width, height,
|
width, height,
|
||||||
FALSE);
|
FALSE);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
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 */
|
/* apply the paint area to the image */
|
||||||
@ -835,7 +848,7 @@ gimp_paint_core_replace (GimpPaintCore *core,
|
|||||||
GEGL_RECTANGLE (0, 0, width, height),
|
GEGL_RECTANGLE (0, 0, width, height),
|
||||||
FALSE, NULL,
|
FALSE, NULL,
|
||||||
image_opacity,
|
image_opacity,
|
||||||
paint_maskPR,
|
&paint_maskPR,
|
||||||
core->paint_buffer_x,
|
core->paint_buffer_x,
|
||||||
core->paint_buffer_y);
|
core->paint_buffer_y);
|
||||||
|
|
||||||
@ -947,11 +960,13 @@ canvas_buffer_to_paint_area (GimpPaintCore *core)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
paint_mask_to_canvas_buffer (GimpPaintCore *core,
|
paint_mask_to_canvas_buffer (GimpPaintCore *core,
|
||||||
PixelRegion *paint_maskPR,
|
GeglBuffer *paint_mask,
|
||||||
gdouble paint_opacity)
|
const GeglRectangle *paint_mask_rect,
|
||||||
|
gdouble paint_opacity)
|
||||||
{
|
{
|
||||||
PixelRegion srcPR;
|
PixelRegion srcPR;
|
||||||
|
PixelRegion paint_maskPR;
|
||||||
|
|
||||||
/* combine the paint mask and the canvas buffer */
|
/* combine the paint mask and the canvas buffer */
|
||||||
pixel_region_init (&srcPR,
|
pixel_region_init (&srcPR,
|
||||||
@ -962,17 +977,39 @@ paint_mask_to_canvas_buffer (GimpPaintCore *core,
|
|||||||
gegl_buffer_get_height (core->paint_buffer),
|
gegl_buffer_get_height (core->paint_buffer),
|
||||||
TRUE);
|
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 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));
|
paint_opacity * 255.999, GIMP_IS_AIRBRUSH (core));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
paint_mask_to_paint_area (GimpPaintCore *core,
|
paint_mask_to_paint_area (GimpPaintCore *core,
|
||||||
PixelRegion *paint_maskPR,
|
GeglBuffer *paint_mask,
|
||||||
gdouble paint_opacity)
|
const GeglRectangle *paint_mask_rect,
|
||||||
|
gdouble paint_opacity)
|
||||||
{
|
{
|
||||||
PixelRegion srcPR;
|
PixelRegion srcPR;
|
||||||
|
PixelRegion paint_maskPR;
|
||||||
|
|
||||||
/* combine the canvas buf and the paint mask to the canvas buf */
|
/* combine the canvas buf and the paint mask to the canvas buf */
|
||||||
pixel_region_init_temp_buf (&srcPR,
|
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_width (core->paint_buffer),
|
||||||
gegl_buffer_get_height (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 the mask */
|
||||||
apply_mask_to_region (&srcPR, paint_maskPR, paint_opacity * 255.999);
|
apply_mask_to_region (&srcPR, &paint_maskPR, paint_opacity * 255.999);
|
||||||
}
|
}
|
||||||
|
@ -166,14 +166,16 @@ GeglBuffer * gimp_paint_core_get_orig_image (GimpPaintCore *core);
|
|||||||
GeglBuffer * gimp_paint_core_get_orig_proj (GimpPaintCore *core);
|
GeglBuffer * gimp_paint_core_get_orig_proj (GimpPaintCore *core);
|
||||||
|
|
||||||
void gimp_paint_core_paste (GimpPaintCore *core,
|
void gimp_paint_core_paste (GimpPaintCore *core,
|
||||||
PixelRegion *paint_maskPR,
|
GeglBuffer *paint_mask,
|
||||||
|
const GeglRectangle *paint_mask_rect,
|
||||||
GimpDrawable *drawable,
|
GimpDrawable *drawable,
|
||||||
gdouble paint_opacity,
|
gdouble paint_opacity,
|
||||||
gdouble image_opacity,
|
gdouble image_opacity,
|
||||||
GimpLayerModeEffects paint_mode,
|
GimpLayerModeEffects paint_mode,
|
||||||
GimpPaintApplicationMode mode);
|
GimpPaintApplicationMode mode);
|
||||||
void gimp_paint_core_replace (GimpPaintCore *core,
|
void gimp_paint_core_replace (GimpPaintCore *core,
|
||||||
PixelRegion *paint_maskPR,
|
GeglBuffer *paint_mask,
|
||||||
|
const GeglRectangle *paint_mask_rect,
|
||||||
GimpDrawable *drawable,
|
GimpDrawable *drawable,
|
||||||
gdouble paint_opacity,
|
gdouble paint_opacity,
|
||||||
gdouble image_opacity,
|
gdouble image_opacity,
|
||||||
|
Reference in New Issue
Block a user