app: pattern-clone using gegl_buffer_set_pattern()
instead of tons and tons of legacy code.
This commit is contained in:
@ -69,15 +69,6 @@ static void gimp_clone_motion (GimpSourceCore *source_core,
|
|||||||
gint paint_area_width,
|
gint paint_area_width,
|
||||||
gint paint_area_height);
|
gint paint_area_height);
|
||||||
|
|
||||||
static void gimp_clone_line_pattern (GimpImage *dest_image,
|
|
||||||
const Babl *fish,
|
|
||||||
GimpPattern *pattern,
|
|
||||||
guchar *d,
|
|
||||||
gint x,
|
|
||||||
gint y,
|
|
||||||
gint dest_bytes,
|
|
||||||
gint width);
|
|
||||||
|
|
||||||
|
|
||||||
G_DEFINE_TYPE (GimpClone, gimp_clone, GIMP_TYPE_SOURCE_CORE)
|
G_DEFINE_TYPE (GimpClone, gimp_clone, GIMP_TYPE_SOURCE_CORE)
|
||||||
|
|
||||||
@ -163,15 +154,10 @@ gimp_clone_motion (GimpSourceCore *source_core,
|
|||||||
GimpContext *context = GIMP_CONTEXT (paint_options);
|
GimpContext *context = GIMP_CONTEXT (paint_options);
|
||||||
GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
|
GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
|
||||||
GimpDynamicsOutput *force_output;
|
GimpDynamicsOutput *force_output;
|
||||||
|
GeglBuffer *dest_buffer;
|
||||||
gdouble fade_point;
|
gdouble fade_point;
|
||||||
gdouble force;
|
gdouble force;
|
||||||
|
|
||||||
switch (options->clone_type)
|
|
||||||
{
|
|
||||||
case GIMP_IMAGE_CLONE:
|
|
||||||
{
|
|
||||||
GeglBuffer *dest_buffer;
|
|
||||||
|
|
||||||
dest_buffer =
|
dest_buffer =
|
||||||
gegl_buffer_linear_new_from_data (temp_buf_get_data (paint_area),
|
gegl_buffer_linear_new_from_data (temp_buf_get_data (paint_area),
|
||||||
gimp_drawable_get_format_with_alpha (drawable),
|
gimp_drawable_get_format_with_alpha (drawable),
|
||||||
@ -182,6 +168,10 @@ gimp_clone_motion (GimpSourceCore *source_core,
|
|||||||
paint_area->bytes,
|
paint_area->bytes,
|
||||||
NULL, NULL);
|
NULL, NULL);
|
||||||
|
|
||||||
|
switch (options->clone_type)
|
||||||
|
{
|
||||||
|
case GIMP_IMAGE_CLONE:
|
||||||
|
{
|
||||||
gegl_buffer_copy (src_buffer,
|
gegl_buffer_copy (src_buffer,
|
||||||
GIMP_GEGL_RECT (0, 0,
|
GIMP_GEGL_RECT (0, 0,
|
||||||
paint_area_width,
|
paint_area_width,
|
||||||
@ -190,47 +180,32 @@ gimp_clone_motion (GimpSourceCore *source_core,
|
|||||||
GIMP_GEGL_RECT (paint_area_offset_x,
|
GIMP_GEGL_RECT (paint_area_offset_x,
|
||||||
paint_area_offset_y,
|
paint_area_offset_y,
|
||||||
0, 0));
|
0, 0));
|
||||||
|
|
||||||
g_object_unref (dest_buffer);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GIMP_PATTERN_CLONE:
|
case GIMP_PATTERN_CLONE:
|
||||||
{
|
{
|
||||||
|
/* XXX: move this to INIT */
|
||||||
GimpPattern *pattern = gimp_context_get_pattern (context);
|
GimpPattern *pattern = gimp_context_get_pattern (context);
|
||||||
const Babl *fish;
|
GeglBuffer *src_buffer = gimp_pattern_create_buffer (pattern);
|
||||||
PixelRegion destPR;
|
|
||||||
gpointer pr;
|
|
||||||
|
|
||||||
fish = babl_fish (gimp_bpp_to_babl_format (pattern->mask->bytes),
|
gegl_buffer_set_pattern (dest_buffer,
|
||||||
gimp_drawable_get_format_with_alpha (drawable));
|
GIMP_GEGL_RECT (paint_area_offset_x,
|
||||||
|
paint_area_offset_y,
|
||||||
|
paint_area_width,
|
||||||
|
paint_area_height),
|
||||||
|
src_buffer,
|
||||||
|
- paint_area->x - src_offset_x,
|
||||||
|
- paint_area->y - src_offset_y);
|
||||||
|
|
||||||
pixel_region_init_temp_buf (&destPR, paint_area,
|
/* XXX: move this to FINISH */
|
||||||
0, 0,
|
g_object_unref (src_buffer);
|
||||||
paint_area->width, paint_area->height);
|
|
||||||
|
|
||||||
pr = pixel_regions_register (1, &destPR);
|
|
||||||
|
|
||||||
for (; pr != NULL; pr = pixel_regions_process (pr))
|
|
||||||
{
|
|
||||||
guchar *d = destPR.data;
|
|
||||||
gint y;
|
|
||||||
|
|
||||||
for (y = 0; y < destPR.h; y++)
|
|
||||||
{
|
|
||||||
gimp_clone_line_pattern (image, fish,
|
|
||||||
pattern, d,
|
|
||||||
paint_area->x + src_offset_x,
|
|
||||||
paint_area->y + y + src_offset_y,
|
|
||||||
destPR.bytes, destPR.w);
|
|
||||||
|
|
||||||
d += destPR.rowstride;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_object_unref (dest_buffer);
|
||||||
|
|
||||||
force_output = gimp_dynamics_get_output (GIMP_BRUSH_CORE (paint_core)->dynamics,
|
force_output = gimp_dynamics_get_output (GIMP_BRUSH_CORE (paint_core)->dynamics,
|
||||||
GIMP_DYNAMICS_OUTPUT_FORCE);
|
GIMP_DYNAMICS_OUTPUT_FORCE);
|
||||||
|
|
||||||
@ -260,37 +235,3 @@ gimp_clone_motion (GimpSourceCore *source_core,
|
|||||||
GIMP_SOURCE_ALIGN_FIXED ?
|
GIMP_SOURCE_ALIGN_FIXED ?
|
||||||
GIMP_PAINT_INCREMENTAL : GIMP_PAINT_CONSTANT);
|
GIMP_PAINT_INCREMENTAL : GIMP_PAINT_CONSTANT);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
gimp_clone_line_pattern (GimpImage *dest_image,
|
|
||||||
const Babl *fish,
|
|
||||||
GimpPattern *pattern,
|
|
||||||
guchar *d,
|
|
||||||
gint x,
|
|
||||||
gint y,
|
|
||||||
gint dest_bytes,
|
|
||||||
gint width)
|
|
||||||
{
|
|
||||||
guchar *pat, *p;
|
|
||||||
gint pat_bytes = pattern->mask->bytes;
|
|
||||||
gint i;
|
|
||||||
|
|
||||||
/* Make sure x, y are positive */
|
|
||||||
while (x < 0)
|
|
||||||
x += pattern->mask->width;
|
|
||||||
while (y < 0)
|
|
||||||
y += pattern->mask->height;
|
|
||||||
|
|
||||||
/* Get a pointer to the appropriate scanline of the pattern buffer */
|
|
||||||
pat = temp_buf_get_data (pattern->mask) +
|
|
||||||
(y % pattern->mask->height) * pattern->mask->width * pat_bytes;
|
|
||||||
|
|
||||||
for (i = 0; i < width; i++)
|
|
||||||
{
|
|
||||||
p = pat + ((i + x) % pattern->mask->width) * pat_bytes;
|
|
||||||
|
|
||||||
babl_process (fish, p, d, 1);
|
|
||||||
|
|
||||||
d += dest_bytes;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user