app: replace GimpSmudge's accum buffer by a TempBuf

This commit is contained in:
Michael Natterer
2012-04-01 19:02:22 +02:00
parent 2aa401e9db
commit 70c6885e7e
2 changed files with 35 additions and 57 deletions

View File

@ -106,9 +106,6 @@ gimp_smudge_class_init (GimpSmudgeClass *klass)
static void static void
gimp_smudge_init (GimpSmudge *smudge) gimp_smudge_init (GimpSmudge *smudge)
{ {
smudge->initialized = FALSE;
smudge->accum_data = NULL;
smudge->accum_size = 0;
} }
static void static void
@ -116,14 +113,12 @@ gimp_smudge_finalize (GObject *object)
{ {
GimpSmudge *smudge = GIMP_SMUDGE (object); GimpSmudge *smudge = GIMP_SMUDGE (object);
if (smudge->accum_data) if (smudge->accum_temp)
{ {
g_free (smudge->accum_data); temp_buf_free (smudge->accum_temp);
smudge->accum_data = NULL; smudge->accum_temp = NULL;
} }
smudge->accum_size = 0;
G_OBJECT_CLASS (parent_class)->finalize (object); G_OBJECT_CLASS (parent_class)->finalize (object);
} }
@ -150,10 +145,10 @@ gimp_smudge_paint (GimpPaintCore *paint_core,
break; break;
case GIMP_PAINT_STATE_FINISH: case GIMP_PAINT_STATE_FINISH:
if (smudge->accum_data) if (smudge->accum_temp)
{ {
g_free (smudge->accum_data); temp_buf_free (smudge->accum_temp);
smudge->accum_data = NULL; smudge->accum_temp = NULL;
} }
smudge->initialized = FALSE; smudge->initialized = FALSE;
break; break;
@ -174,7 +169,7 @@ gimp_smudge_start (GimpPaintCore *paint_core,
gint paint_buffer_x; gint paint_buffer_x;
gint paint_buffer_y; gint paint_buffer_y;
GeglBuffer *accum_buffer; GeglBuffer *accum_buffer;
gint bytes; gint accum_size;
gint x, y; gint x, y;
if (gimp_drawable_is_indexed (drawable)) if (gimp_drawable_is_indexed (drawable))
@ -187,33 +182,29 @@ gimp_smudge_start (GimpPaintCore *paint_core,
if (! paint_buffer) if (! paint_buffer)
return FALSE; return FALSE;
gimp_smudge_accumulator_size (paint_options, &smudge->accum_size); gimp_smudge_accumulator_size (paint_options, &accum_size);
/* Allocate the accumulation buffer */
smudge->accum_temp = temp_buf_new (accum_size, accum_size,
gimp_drawable_bytes (drawable),
0, 0, NULL);
accum_buffer =
gimp_temp_buf_create_buffer (smudge->accum_temp,
gimp_drawable_get_format (drawable));
/* adjust the x and y coordinates to the upper left corner of the /* adjust the x and y coordinates to the upper left corner of the
* accumulator * accumulator
*/ */
gimp_smudge_accumulator_coords (paint_core, coords, &x, &y); gimp_smudge_accumulator_coords (paint_core, coords, &x, &y);
/* Allocate the accumulation buffer */
bytes = gimp_drawable_bytes (drawable);
smudge->accum_data = g_malloc (SQR (smudge->accum_size) * bytes);
accum_buffer =
gegl_buffer_linear_new_from_data (smudge->accum_data,
gimp_drawable_get_format (drawable),
GIMP_GEGL_RECT (0, 0,
smudge->accum_size,
smudge->accum_size),
GEGL_AUTO_ROWSTRIDE,
NULL, NULL);
/* If clipped, prefill the smudge buffer with the color at the /* If clipped, prefill the smudge buffer with the color at the
* brush position. * brush position.
*/ */
if (x != paint_buffer_x || if (x != paint_buffer_x ||
y != paint_buffer_y || y != paint_buffer_y ||
smudge->accum_size != gegl_buffer_get_width (paint_buffer) || accum_size != gegl_buffer_get_width (paint_buffer) ||
smudge->accum_size != gegl_buffer_get_height (paint_buffer)) accum_size != gegl_buffer_get_height (paint_buffer))
{ {
GimpRGB pixel; GimpRGB pixel;
GeglColor *color; GeglColor *color;
@ -246,13 +237,6 @@ gimp_smudge_start (GimpPaintCore *paint_core,
g_object_unref (accum_buffer); g_object_unref (accum_buffer);
pixel_region_init_data (&smudge->accumPR, smudge->accum_data,
bytes, bytes * smudge->accum_size,
0,
0,
smudge->accum_size,
smudge->accum_size);
return TRUE; return TRUE;
} }
@ -321,13 +305,11 @@ gimp_smudge_motion (GimpPaintCore *paint_core,
rate = (options->rate / 100.0) * dynamic_rate; rate = (options->rate / 100.0) * dynamic_rate;
/* The tempPR will be the built up buffer (for smudge) */ /* The tempPR will be the built up buffer (for smudge) */
pixel_region_init_data (&tempPR, smudge->accum_data, pixel_region_init_temp_buf (&tempPR, smudge->accum_temp,
smudge->accumPR.bytes, area->x - x,
smudge->accumPR.rowstride, area->y - y,
area->x - x, area->width,
area->y - y, area->height);
area->width,
area->height);
/* The dest will be the paint area we got above (= paint_area) */ /* The dest will be the paint area we got above (= paint_area) */
pixel_region_init_temp_buf (&destPR, area, pixel_region_init_temp_buf (&destPR, area,
@ -344,13 +326,11 @@ gimp_smudge_motion (GimpPaintCore *paint_core,
blend_region (&srcPR, &tempPR, &tempPR, ROUND (rate * 255.0)); blend_region (&srcPR, &tempPR, &tempPR, ROUND (rate * 255.0));
/* re-init the tempPR */ /* re-init the tempPR */
pixel_region_init_data (&tempPR, smudge->accum_data, pixel_region_init_temp_buf (&tempPR, smudge->accum_temp,
smudge->accumPR.bytes, area->x - x,
smudge->accumPR.rowstride, area->y - y,
area->x - x, area->width,
area->y - y, area->height);
area->width,
area->height);
if (! gimp_drawable_has_alpha (drawable)) if (! gimp_drawable_has_alpha (drawable))
add_alpha_region (&tempPR, &destPR); add_alpha_region (&tempPR, &destPR);
@ -382,16 +362,16 @@ gimp_smudge_accumulator_coords (GimpPaintCore *paint_core,
{ {
GimpSmudge *smudge = GIMP_SMUDGE (paint_core); GimpSmudge *smudge = GIMP_SMUDGE (paint_core);
*x = (gint) coords->x - smudge->accum_size / 2; *x = (gint) coords->x - smudge->accum_temp->width / 2;
*y = (gint) coords->y - smudge->accum_size / 2; *y = (gint) coords->y - smudge->accum_temp->height / 2;
} }
static void static void
gimp_smudge_accumulator_size (GimpPaintOptions *paint_options, gimp_smudge_accumulator_size (GimpPaintOptions *paint_options,
gint *accumulator_size) gint *accumulator_size)
{ {
/* Note: the max brush mask size plus a border of 1 pixel and a
/* Note: the max brush mask size plus a border of 1 pixel and a little * little headroom
* headroom */ */
*accumulator_size = ceil (sqrt (2 * SQR (paint_options->brush_size + 1)) + 2); *accumulator_size = ceil (sqrt (2 * SQR (paint_options->brush_size + 1)) + 2);
} }

View File

@ -39,9 +39,7 @@ struct _GimpSmudge
GimpBrushCore parent_instance; GimpBrushCore parent_instance;
gboolean initialized; gboolean initialized;
PixelRegion accumPR; TempBuf *accum_temp;
guchar *accum_data;
gint accum_size;
}; };
struct _GimpSmudgeClass struct _GimpSmudgeClass