app: add "take_ownerspip" param to gimp_temp_buf_create_buffer()

and get rid of some more intermediate buffer creation/destruction, and
some redundant temp_buf_free() plus g_object_unref().
This commit is contained in:
Michael Natterer 2012-04-01 21:59:36 +02:00
parent 7b5252ac54
commit c5c555c834
14 changed files with 100 additions and 102 deletions

View File

@ -49,7 +49,8 @@ gimp_brush_transform_boundary_exact (GimpBrush *brush,
gint n_bound_segs;
buffer = gimp_temp_buf_create_buffer ((TempBuf *) mask,
babl_format ("Y u8"));
babl_format ("Y u8"),
FALSE);
bound_segs = gimp_boundary_find (buffer, NULL,
GIMP_BOUNDARY_WITHIN_BOUNDS,

View File

@ -210,7 +210,8 @@ gimp_brush_clipboard_buffer_changed (Gimp *gimp,
if (babl_format_has_alpha (format))
{
dest_buffer = gimp_temp_buf_create_buffer (brush->mask,
babl_format ("A u8"));
babl_format ("A u8"),
FALSE);
gegl_buffer_copy (buffer, NULL, dest_buffer, NULL);
@ -223,7 +224,7 @@ gimp_brush_clipboard_buffer_changed (Gimp *gimp,
}
/* copy the color channels into the brush's pixmap */
dest_buffer = gimp_temp_buf_create_buffer (brush->pixmap, NULL);
dest_buffer = gimp_temp_buf_create_buffer (brush->pixmap, NULL, FALSE);
gegl_buffer_copy (buffer, NULL, dest_buffer, NULL);

View File

@ -271,5 +271,5 @@ gimp_pattern_create_buffer (const GimpPattern *pattern)
{
g_return_val_if_fail (GIMP_IS_PATTERN (pattern), NULL);
return gimp_temp_buf_create_buffer (pattern->mask, NULL);
return gimp_temp_buf_create_buffer (pattern->mask, NULL, FALSE);
}

View File

@ -200,7 +200,8 @@ gimp_gegl_buffer_get_tiles (GeglBuffer *buffer)
GeglBuffer *
gimp_temp_buf_create_buffer (TempBuf *temp_buf,
const Babl *format)
const Babl *format,
gboolean take_ownership)
{
GeglBuffer *buffer;
gint width, height, bytes;
@ -217,11 +218,15 @@ gimp_temp_buf_create_buffer (TempBuf *temp_buf,
if (! format)
format = gimp_bpp_to_babl_format (bytes);
buffer = gegl_buffer_linear_new_from_data (temp_buf_get_data (temp_buf),
format,
GIMP_GEGL_RECT (0, 0, width, height),
width * bytes,
NULL, NULL);
buffer =
gegl_buffer_linear_new_from_data (temp_buf_get_data (temp_buf),
format,
GIMP_GEGL_RECT (0, 0, width, height),
width * bytes,
take_ownership ?
(GDestroyNotify) temp_buf_free : NULL,
take_ownership ?
temp_buf : NULL);
g_object_set_data (G_OBJECT (buffer), "gimp-temp-buf", temp_buf);

View File

@ -39,7 +39,8 @@ GeglBuffer * gimp_tile_manager_create_buffer (TileManager *tm,
TileManager * gimp_gegl_buffer_get_tiles (GeglBuffer *buffer);
GeglBuffer * gimp_temp_buf_create_buffer (TempBuf *temp_buf,
const Babl *format);
const Babl *format,
gboolean take_ownership);
TempBuf * gimp_gegl_buffer_get_temp_buf (GeglBuffer *buffer);
GeglBuffer * gimp_pixbuf_create_buffer (GdkPixbuf *pixbuf);

View File

@ -831,10 +831,10 @@ gimp_brush_core_get_paint_buffer (GimpPaintCore *paint_core,
{
const Babl *format = gimp_drawable_get_format_with_alpha (drawable);
gint bytes = babl_format_get_bytes_per_pixel (format);
TempBuf *temp_buf;
paint_core->paint_area = temp_buf_resize (paint_core->paint_area, bytes,
x1, y1,
(x2 - x1), (y2 - y1));
temp_buf = temp_buf_new ((x2 - x1), (y2 - y1), bytes,
0, 0, NULL);
*paint_buffer_x = x1;
*paint_buffer_y = y1;
@ -842,8 +842,8 @@ gimp_brush_core_get_paint_buffer (GimpPaintCore *paint_core,
if (paint_core->paint_buffer)
g_object_unref (paint_core->paint_buffer);
paint_core->paint_buffer =
gimp_temp_buf_create_buffer (paint_core->paint_area, format);
paint_core->paint_buffer = gimp_temp_buf_create_buffer (temp_buf, format,
TRUE);
return paint_core->paint_buffer;
}
@ -951,8 +951,8 @@ gimp_brush_core_paste_canvas (GimpBrushCore *core,
pixel_region_init_temp_buf (&brush_maskPR, (TempBuf *) brush_mask,
off_x, off_y,
paint_core->paint_area->width,
paint_core->paint_area->height);
gegl_buffer_get_width (paint_core->paint_buffer),
gegl_buffer_get_height (paint_core->paint_buffer));
gimp_paint_core_paste (paint_core, &brush_maskPR, drawable,
brush_opacity,
@ -997,8 +997,8 @@ gimp_brush_core_replace_canvas (GimpBrushCore *core,
pixel_region_init_temp_buf (&brush_maskPR, (TempBuf *) brush_mask,
off_x, off_y,
paint_core->paint_area->width,
paint_core->paint_area->height);
gegl_buffer_get_width (paint_core->paint_buffer),
gegl_buffer_get_height (paint_core->paint_buffer));
gimp_paint_core_replace (paint_core, &brush_maskPR, drawable,
brush_opacity,

View File

@ -193,7 +193,7 @@ gimp_convolve_motion (GimpPaintCore *paint_core,
babl_format_get_bytes_per_pixel (format),
0, 0, NULL);
convolve_buffer = gimp_temp_buf_create_buffer (convolve_temp, format);
convolve_buffer = gimp_temp_buf_create_buffer (convolve_temp, format, TRUE);
gegl_buffer_copy (gimp_drawable_get_buffer (drawable),
GIMP_GEGL_RECT (paint_buffer_x,
@ -203,8 +203,6 @@ gimp_convolve_motion (GimpPaintCore *paint_core,
convolve_buffer,
GIMP_GEGL_RECT (0, 0, 0, 0));
g_object_unref (convolve_buffer);
/* Convolve the region */
pixel_region_init_temp_buf (&tempPR, convolve_temp,
0, 0,
@ -221,7 +219,7 @@ gimp_convolve_motion (GimpPaintCore *paint_core,
convolve->matrix, 3, convolve->matrix_divisor,
GIMP_NORMAL_CONVOL, TRUE);
temp_buf_free (convolve_temp);
g_object_unref (convolve_buffer);
gimp_brush_core_replace_canvas (brush_core, drawable,
coords,

View File

@ -238,12 +238,12 @@ gimp_dodge_burn_motion (GimpPaintCore *paint_core,
babl_format_get_bytes_per_pixel (orig_format),
0, 0, NULL);
orig_buffer = gimp_temp_buf_create_buffer (orig_temp, orig_format);
orig_buffer = gimp_temp_buf_create_buffer (orig_temp, orig_format, TRUE);
gegl_buffer_copy (gimp_paint_core_get_orig_image (paint_core),
&orig_rect,
orig_buffer,
GIMP_GEGL_RECT (0, 0, 0, 0));
g_object_unref (orig_buffer);
pixel_region_init_temp_buf (&srcPR, orig_temp,
0, 0, orig_rect.width, orig_rect.height);
@ -252,6 +252,7 @@ gimp_dodge_burn_motion (GimpPaintCore *paint_core,
db_temp = temp_buf_new (orig_rect.width, orig_rect.height,
babl_format_get_bytes_per_pixel (orig_format),
0, 0, NULL);
db_buffer = gimp_temp_buf_create_buffer (db_temp, orig_format, TRUE);
pixel_region_init_temp_buf (&tempPR, db_temp,
0, 0, db_temp->width, db_temp->height);
@ -259,12 +260,11 @@ gimp_dodge_burn_motion (GimpPaintCore *paint_core,
/* DodgeBurn the region */
gimp_lut_process (dodgeburn->lut, &srcPR, &tempPR);
db_buffer = gimp_temp_buf_create_buffer (db_temp, orig_format);
g_object_unref (orig_buffer);
gegl_buffer_copy (db_buffer, NULL, paint_buffer, NULL);
g_object_unref (db_buffer);
temp_buf_free (db_temp);
hardness_output = gimp_dynamics_get_output (dynamics,
GIMP_DYNAMICS_OUTPUT_HARDNESS);

View File

@ -494,7 +494,8 @@ gimp_heal_motion (GimpSourceCore *source_core,
0, 0, NULL);
tmp = gimp_temp_buf_create_buffer (src_temp_buf,
gimp_drawable_get_format_with_alpha (drawable));
gimp_drawable_get_format_with_alpha (drawable),
FALSE);
gegl_buffer_copy (src_buffer, src_rect,
tmp, GIMP_GEGL_RECT (0, 0, 0, 0));
@ -508,7 +509,8 @@ gimp_heal_motion (GimpSourceCore *source_core,
dest_buffer =
gimp_temp_buf_create_buffer (dest_temp_buf,
gimp_drawable_get_format_with_alpha (drawable));
gimp_drawable_get_format_with_alpha (drawable),
TRUE);
gegl_buffer_copy (gimp_drawable_get_buffer (drawable),
GIMP_GEGL_RECT (paint_buffer_x, paint_buffer_y,
@ -526,7 +528,7 @@ gimp_heal_motion (GimpSourceCore *source_core,
don't do anything */
temp_buf_free (src_temp_buf);
temp_buf_free (dest_temp_buf);
g_object_unref (dest_buffer);
return;
}
@ -549,6 +551,8 @@ gimp_heal_motion (GimpSourceCore *source_core,
paint_area_width,
paint_area_height));
g_object_unref (dest_buffer);
/* replace the canvas with our healed data */
gimp_brush_core_replace_canvas (GIMP_BRUSH_CORE (paint_core), drawable,
coords,

View File

@ -222,10 +222,10 @@ gimp_ink_get_paint_buffer (GimpPaintCore *paint_core,
{
const Babl *format = gimp_drawable_get_format_with_alpha (drawable);
gint bytes = babl_format_get_bytes_per_pixel (format);
TempBuf *temp_buf;
paint_core->paint_area = temp_buf_resize (paint_core->paint_area, bytes,
x1, y1,
(x2 - x1), (y2 - y1));
temp_buf = temp_buf_new ((x2 - x1), (y2 - y1), bytes,
0, 0, NULL);
*paint_buffer_x = x1;
*paint_buffer_y = y1;
@ -233,8 +233,8 @@ gimp_ink_get_paint_buffer (GimpPaintCore *paint_core,
if (paint_core->paint_buffer)
g_object_unref (paint_core->paint_buffer);
paint_core->paint_buffer =
gimp_temp_buf_create_buffer (paint_core->paint_area, format);
paint_core->paint_buffer = gimp_temp_buf_create_buffer (temp_buf, format,
TRUE);
return paint_core->paint_buffer;
}
@ -328,10 +328,10 @@ gimp_ink_motion (GimpPaintCore *paint_core,
/* draw the blob directly to the canvas_buffer */
pixel_region_init (&blob_maskPR,
gimp_gegl_buffer_get_tiles (paint_core->canvas_buffer),
paint_core->paint_area->x,
paint_core->paint_area->y,
paint_core->paint_area->width,
paint_core->paint_area->height,
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),
TRUE);
render_blob (blob_to_render, &blob_maskPR);
@ -339,10 +339,10 @@ gimp_ink_motion (GimpPaintCore *paint_core,
/* 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_area->x,
paint_core->paint_area->y,
paint_core->paint_area->width,
paint_core->paint_area->height,
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,

View File

@ -553,12 +553,6 @@ gimp_paint_core_cleanup (GimpPaintCore *core)
core->canvas_buffer = NULL;
}
if (core->paint_area)
{
temp_buf_free (core->paint_area);
core->paint_area = NULL;
}
if (core->paint_buffer)
{
g_object_unref (core->paint_buffer);
@ -934,17 +928,18 @@ canvas_buffer_to_paint_area (GimpPaintCore *core)
PixelRegion maskPR;
/* combine the canvas buffer and the paint area */
pixel_region_init_temp_buf (&srcPR, core->paint_area,
pixel_region_init_temp_buf (&srcPR,
gimp_gegl_buffer_get_temp_buf (core->paint_buffer),
0, 0,
core->paint_area->width,
core->paint_area->height);
gegl_buffer_get_width (core->paint_buffer),
gegl_buffer_get_height (core->paint_buffer));
pixel_region_init (&maskPR,
gimp_gegl_buffer_get_tiles (core->canvas_buffer),
core->paint_area->x,
core->paint_area->y,
core->paint_area->width,
core->paint_area->height,
core->paint_buffer_x,
core->paint_buffer_y,
gegl_buffer_get_width (core->paint_buffer),
gegl_buffer_get_height (core->paint_buffer),
FALSE);
/* apply the canvas buffer to the paint area */
@ -961,10 +956,10 @@ paint_mask_to_canvas_buffer (GimpPaintCore *core,
/* combine the paint mask and the canvas buffer */
pixel_region_init (&srcPR,
gimp_gegl_buffer_get_tiles (core->canvas_buffer),
core->paint_area->x,
core->paint_area->y,
core->paint_area->width,
core->paint_area->height,
core->paint_buffer_x,
core->paint_buffer_y,
gegl_buffer_get_width (core->paint_buffer),
gegl_buffer_get_height (core->paint_buffer),
TRUE);
/* combine the mask to the canvas tiles */
@ -980,10 +975,11 @@ paint_mask_to_paint_area (GimpPaintCore *core,
PixelRegion srcPR;
/* combine the canvas buf and the paint mask to the canvas buf */
pixel_region_init_temp_buf (&srcPR, core->paint_area,
pixel_region_init_temp_buf (&srcPR,
gimp_gegl_buffer_get_temp_buf (core->paint_buffer),
0, 0,
core->paint_area->width,
core->paint_area->height);
gegl_buffer_get_width (core->paint_buffer),
gegl_buffer_get_height (core->paint_buffer));
/* apply the mask */
apply_mask_to_region (&srcPR, paint_maskPR, paint_opacity * 255.999);

View File

@ -59,8 +59,7 @@ struct _GimpPaintCore
GeglBuffer *saved_proj_buffer; /* proj tiles which have been modified */
GeglBuffer *canvas_buffer; /* the buffer to paint the mask to */
TempBuf *paint_area; /* the buffer to paint pixels to */
GeglBuffer *paint_buffer; /* for now proxies paint_area */
GeglBuffer *paint_buffer; /* the buffer to paint pixels to */
gint paint_buffer_x;
gint paint_buffer_y;

View File

@ -113,10 +113,10 @@ gimp_smudge_finalize (GObject *object)
{
GimpSmudge *smudge = GIMP_SMUDGE (object);
if (smudge->accum_temp)
if (smudge->accum_buffer)
{
temp_buf_free (smudge->accum_temp);
smudge->accum_temp = NULL;
g_object_unref (smudge->accum_buffer);
smudge->accum_buffer = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
@ -145,10 +145,10 @@ gimp_smudge_paint (GimpPaintCore *paint_core,
break;
case GIMP_PAINT_STATE_FINISH:
if (smudge->accum_temp)
if (smudge->accum_buffer)
{
temp_buf_free (smudge->accum_temp);
smudge->accum_temp = NULL;
g_object_unref (smudge->accum_buffer);
smudge->accum_buffer = NULL;
}
smudge->initialized = FALSE;
break;
@ -164,13 +164,13 @@ gimp_smudge_start (GimpPaintCore *paint_core,
GimpPaintOptions *paint_options,
const GimpCoords *coords)
{
GimpSmudge *smudge = GIMP_SMUDGE (paint_core);
GeglBuffer *paint_buffer;
gint paint_buffer_x;
gint paint_buffer_y;
GeglBuffer *accum_buffer;
gint accum_size;
gint x, y;
GimpSmudge *smudge = GIMP_SMUDGE (paint_core);
GeglBuffer *paint_buffer;
gint paint_buffer_x;
gint paint_buffer_y;
TempBuf *accum_temp;
gint accum_size;
gint x, y;
if (gimp_drawable_is_indexed (drawable))
return FALSE;
@ -185,13 +185,14 @@ gimp_smudge_start (GimpPaintCore *paint_core,
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_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));
smudge->accum_buffer =
gimp_temp_buf_create_buffer (accum_temp,
gimp_drawable_get_format (drawable),
TRUE);
/* adjust the x and y coordinates to the upper left corner of the
* accumulator
@ -219,7 +220,7 @@ gimp_smudge_start (GimpPaintCore *paint_core,
&pixel);
color = gimp_gegl_color_new (&pixel);
gegl_buffer_set_color (accum_buffer, NULL, color);
gegl_buffer_set_color (smudge->accum_buffer, NULL, color);
g_object_unref (color);
}
@ -229,13 +230,11 @@ gimp_smudge_start (GimpPaintCore *paint_core,
paint_buffer_y,
gegl_buffer_get_width (paint_buffer),
gegl_buffer_get_height (paint_buffer)),
accum_buffer,
smudge->accum_buffer,
GIMP_GEGL_RECT (paint_buffer_x - x,
paint_buffer_y - y,
0, 0));
g_object_unref (accum_buffer);
return TRUE;
}
@ -256,7 +255,6 @@ gimp_smudge_motion (GimpPaintCore *paint_core,
GeglBuffer *paint_buffer;
gint paint_buffer_x;
gint paint_buffer_y;
GeglBuffer *accum_buffer;
PixelRegion srcPR, tempPR;
gdouble fade_point;
gdouble opacity;
@ -312,7 +310,8 @@ gimp_smudge_motion (GimpPaintCore *paint_core,
rate = (options->rate / 100.0) * dynamic_rate;
/* The tempPR will be the built up buffer (for smudge) */
pixel_region_init_temp_buf (&tempPR, smudge->accum_temp,
pixel_region_init_temp_buf (&tempPR,
gimp_gegl_buffer_get_temp_buf (smudge->accum_buffer),
paint_buffer_x - x,
paint_buffer_y - y,
gegl_buffer_get_width (paint_buffer),
@ -328,11 +327,7 @@ gimp_smudge_motion (GimpPaintCore *paint_core,
blend_region (&srcPR, &tempPR, &tempPR, ROUND (rate * 255.0));
accum_buffer =
gimp_temp_buf_create_buffer (smudge->accum_temp,
gimp_drawable_get_format (drawable));
gegl_buffer_copy (accum_buffer,
gegl_buffer_copy (smudge->accum_buffer,
GIMP_GEGL_RECT (paint_buffer_x - x,
paint_buffer_y - y,
gegl_buffer_get_width (paint_buffer),
@ -340,8 +335,6 @@ gimp_smudge_motion (GimpPaintCore *paint_core,
paint_buffer,
GIMP_GEGL_RECT (0, 0, 0, 0));
g_object_unref (accum_buffer);
hardness_output = gimp_dynamics_get_output (dynamics,
GIMP_DYNAMICS_OUTPUT_HARDNESS);
@ -367,8 +360,8 @@ gimp_smudge_accumulator_coords (GimpPaintCore *paint_core,
{
GimpSmudge *smudge = GIMP_SMUDGE (paint_core);
*x = (gint) coords->x - smudge->accum_temp->width / 2;
*y = (gint) coords->y - smudge->accum_temp->height / 2;
*x = (gint) coords->x - gegl_buffer_get_width (smudge->accum_buffer) / 2;
*y = (gint) coords->y - gegl_buffer_get_height (smudge->accum_buffer) / 2;
}
static void

View File

@ -39,7 +39,7 @@ struct _GimpSmudge
GimpBrushCore parent_instance;
gboolean initialized;
TempBuf *accum_temp;
GeglBuffer *accum_buffer;
};
struct _GimpSmudgeClass