Commit d5d8e36d authored by Michael Natterer's avatar Michael Natterer 😴
Browse files

app: gimp_-namespace all GimpTempBuf functions

parent 42a5f01b
......@@ -90,7 +90,7 @@ pixel_region_init_temp_buf (PixelRegion *PR,
gint w,
gint h)
{
PR->data = temp_buf_get_data (temp_buf);
PR->data = gimp_temp_buf_get_data (temp_buf);
PR->tiles = NULL;
PR->curtile = NULL;
PR->offx = 0;
......
......@@ -33,9 +33,9 @@
GimpTempBuf *
temp_buf_new (gint width,
gint height,
const Babl *format)
gimp_temp_buf_new (gint width,
gint height,
const Babl *format)
{
GimpTempBuf *temp;
......@@ -58,28 +58,36 @@ temp_buf_new (gint width,
}
GimpTempBuf *
temp_buf_copy (GimpTempBuf *src)
gimp_temp_buf_copy (GimpTempBuf *src)
{
GimpTempBuf *dest;
g_return_val_if_fail (src != NULL, NULL);
dest = temp_buf_new (src->width, src->height, src->format);
dest = gimp_temp_buf_new (src->width, src->height, src->format);
if (! dest)
return NULL;
memcpy (temp_buf_get_data (dest),
temp_buf_get_data (src),
temp_buf_get_data_size (src));
memcpy (gimp_temp_buf_get_data (dest),
gimp_temp_buf_get_data (src),
gimp_temp_buf_get_data_size (src));
return dest;
}
void
gimp_temp_buf_free (GimpTempBuf *buf)
{
g_return_if_fail (buf != NULL);
if (buf->data)
g_free (buf->data);
g_slice_free (GimpTempBuf, buf);
}
GimpTempBuf *
temp_buf_scale (GimpTempBuf *src,
gint new_width,
gint new_height)
gimp_temp_buf_scale (GimpTempBuf *src,
gint new_width,
gint new_height)
{
GimpTempBuf *dest;
const guchar *src_data;
......@@ -93,12 +101,12 @@ temp_buf_scale (GimpTempBuf *src,
g_return_val_if_fail (src != NULL, NULL);
g_return_val_if_fail (new_width > 0 && new_height > 0, NULL);
dest = temp_buf_new (new_width,
new_height,
src->format);
dest = gimp_temp_buf_new (new_width,
new_height,
src->format);
src_data = temp_buf_get_data (src);
dest_data = temp_buf_get_data (dest);
src_data = gimp_temp_buf_get_data (src);
dest_data = gimp_temp_buf_get_data (dest);
x_ratio = (gdouble) src->width / (gdouble) new_width;
y_ratio = (gdouble) src->height / (gdouble) new_height;
......@@ -129,13 +137,13 @@ temp_buf_scale (GimpTempBuf *src,
}
/**
* temp_buf_demultiply:
* gimp_temp_buf_demultiply:
* @buf:
*
* Converts a GimpTempBuf with pre-multiplied alpha to a 'normal' GimpTempBuf.
*/
void
temp_buf_demultiply (GimpTempBuf *buf)
gimp_temp_buf_demultiply (GimpTempBuf *buf)
{
guchar *data;
gint pixels;
......@@ -148,7 +156,7 @@ temp_buf_demultiply (GimpTempBuf *buf)
break;
case 2:
data = temp_buf_get_data (buf);
data = gimp_temp_buf_get_data (buf);
pixels = buf->width * buf->height;
while (pixels--)
{
......@@ -162,7 +170,7 @@ temp_buf_demultiply (GimpTempBuf *buf)
break;
case 4:
data = temp_buf_get_data (buf);
data = gimp_temp_buf_get_data (buf);
pixels = buf->width * buf->height;
while (pixels--)
{
......@@ -180,70 +188,35 @@ temp_buf_demultiply (GimpTempBuf *buf)
}
}
void
temp_buf_free (GimpTempBuf *buf)
{
g_return_if_fail (buf != NULL);
if (buf->data)
g_free (buf->data);
g_slice_free (GimpTempBuf, buf);
}
guchar *
temp_buf_get_data (const GimpTempBuf *buf)
gimp_temp_buf_get_data (const GimpTempBuf *buf)
{
return buf->data;
}
gsize
temp_buf_get_data_size (GimpTempBuf *buf)
gimp_temp_buf_get_data_size (GimpTempBuf *buf)
{
return babl_format_get_bytes_per_pixel (buf->format) * buf->width * buf->height;
}
guchar *
temp_buf_data_clear (GimpTempBuf *buf)
gimp_temp_buf_data_clear (GimpTempBuf *buf)
{
memset (buf->data, 0, temp_buf_get_data_size (buf));
memset (buf->data, 0, gimp_temp_buf_get_data_size (buf));
return buf->data;
}
gsize
temp_buf_get_memsize (GimpTempBuf *buf)
gimp_temp_buf_get_memsize (GimpTempBuf *buf)
{
if (buf)
return (sizeof (GimpTempBuf) + temp_buf_get_data_size (buf));
return (sizeof (GimpTempBuf) + gimp_temp_buf_get_data_size (buf));
return 0;
}
/**
* temp_buf_dump:
* @buf:
* @file:
*
* Dumps a GimpTempBuf to a raw RGB image that is easy to analyze, for
* example with GIMP.
**/
void
temp_buf_dump (GimpTempBuf *buf,
const gchar *filename)
{
gint fd = g_open (filename, O_CREAT | O_TRUNC | O_WRONLY, 0666);
g_return_if_fail (fd != -1);
g_return_if_fail (buf != NULL);
g_return_if_fail (temp_buf_get_data (buf) != NULL);
write (fd, temp_buf_get_data (buf), temp_buf_get_data_size (buf));
close (fd);
}
GeglBuffer *
gimp_temp_buf_create_buffer (GimpTempBuf *temp_buf,
gboolean take_ownership)
......@@ -253,14 +226,14 @@ gimp_temp_buf_create_buffer (GimpTempBuf *temp_buf,
g_return_val_if_fail (temp_buf != NULL, NULL);
buffer =
gegl_buffer_linear_new_from_data (temp_buf_get_data (temp_buf),
gegl_buffer_linear_new_from_data (gimp_temp_buf_get_data (temp_buf),
temp_buf->format,
GEGL_RECTANGLE (0, 0,
temp_buf->width,
temp_buf->height),
GEGL_AUTO_ROWSTRIDE,
take_ownership ?
(GDestroyNotify) temp_buf_free : NULL,
(GDestroyNotify) gimp_temp_buf_free : NULL,
take_ownership ?
temp_buf : NULL);
......
......@@ -15,8 +15,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __TEMP_BUF_H__
#define __TEMP_BUF_H__
#ifndef __GIMP_TEMP_BUF_H__
#define __GIMP_TEMP_BUF_H__
struct _GimpTempBuf
......@@ -32,27 +32,26 @@ struct _GimpTempBuf
/* The temp buffer functions */
GimpTempBuf * temp_buf_new (gint width,
gint height,
const Babl *fomat);
GimpTempBuf * temp_buf_copy (GimpTempBuf *src);
GimpTempBuf * temp_buf_scale (GimpTempBuf *buf,
gint width,
gint height) G_GNUC_WARN_UNUSED_RESULT;
GimpTempBuf * gimp_temp_buf_new (gint width,
gint height,
const Babl *fomat) G_GNUC_WARN_UNUSED_RESULT;
GimpTempBuf * gimp_temp_buf_copy (GimpTempBuf *src) G_GNUC_WARN_UNUSED_RESULT;
void gimp_temp_buf_free (GimpTempBuf *buf);
void temp_buf_demultiply (GimpTempBuf *buf);
GimpTempBuf * gimp_temp_buf_scale (GimpTempBuf *buf,
gint width,
gint height) G_GNUC_WARN_UNUSED_RESULT;
void temp_buf_free (GimpTempBuf *buf);
guchar * temp_buf_get_data (const GimpTempBuf *buf);
gsize temp_buf_get_data_size (GimpTempBuf *buf);
guchar * temp_buf_data_clear (GimpTempBuf *buf);
void gimp_temp_buf_demultiply (GimpTempBuf *buf);
gsize temp_buf_get_memsize (GimpTempBuf *buf);
void temp_buf_dump (GimpTempBuf *buf,
const gchar *filename);
guchar * gimp_temp_buf_get_data (const GimpTempBuf *buf);
gsize gimp_temp_buf_get_data_size (GimpTempBuf *buf);
guchar * gimp_temp_buf_data_clear (GimpTempBuf *buf);
GeglBuffer * gimp_temp_buf_create_buffer (GimpTempBuf *temp_buf,
gboolean take_ownership);
gsize gimp_temp_buf_get_memsize (GimpTempBuf *buf);
GeglBuffer * gimp_temp_buf_create_buffer (GimpTempBuf *temp_buf,
gboolean take_ownership) G_GNUC_WARN_UNUSED_RESULT;
#endif /* __TEMP_BUF_H__ */
#endif /* __GIMP_TEMP_BUF_H__ */
......@@ -98,8 +98,8 @@ tile_manager_create_preview (TileManager *tiles,
PixelRegion destPR;
gint subsample = 1;
preview = temp_buf_new (dest_width, dest_height,
gimp_bpp_to_babl_format (tile_manager_bpp (tiles)));
preview = gimp_temp_buf_new (dest_width, dest_height,
gimp_bpp_to_babl_format (tile_manager_bpp (tiles)));
pixel_region_init (&srcPR, tiles, src_x, src_y, src_width, src_height, FALSE);
......
......@@ -291,10 +291,10 @@ gimp_brush_load_brush (GimpContext *context,
NULL);
g_free (name);
brush->mask = temp_buf_new (header.width, header.height,
babl_format ("Y u8"));
brush->mask = gimp_temp_buf_new (header.width, header.height,
babl_format ("Y u8"));
mask = temp_buf_get_data (brush->mask);
mask = gimp_temp_buf_get_data (brush->mask);
size = header.width * header.height * header.bytes;
switch (header.bytes)
......@@ -346,9 +346,9 @@ gimp_brush_load_brush (GimpContext *context,
{
guchar buf[8 * 1024];
brush->pixmap = temp_buf_new (header.width, header.height,
babl_format ("R'G'B' u8"));
pixmap = temp_buf_get_data (brush->pixmap);
brush->pixmap = gimp_temp_buf_new (header.width, header.height,
babl_format ("R'G'B' u8"));
pixmap = gimp_temp_buf_get_data (brush->pixmap);
for (i = 0; success && i < size;)
{
......@@ -650,9 +650,10 @@ gimp_brush_load_abr_brush_v12 (FILE *file,
brush->x_axis.y = 0.0;
brush->y_axis.x = 0.0;
brush->y_axis.y = height / 2.0;
brush->mask = temp_buf_new (width, height, babl_format ("Y u8"));
brush->mask = gimp_temp_buf_new (width, height,
babl_format ("Y u8"));
mask = temp_buf_get_data (brush->mask);
mask = gimp_temp_buf_get_data (brush->mask);
size = width * height * bytes;
compress = abr_read_char (file);
......@@ -757,9 +758,10 @@ gimp_brush_load_abr_brush_v6 (FILE *file,
brush->x_axis.y = 0.0;
brush->y_axis.x = 0.0;
brush->y_axis.y = height / 2.0;
brush->mask = temp_buf_new (width, height, babl_format ("Y u8"));
brush->mask = gimp_temp_buf_new (width, height,
babl_format ("Y u8"));
mask = temp_buf_get_data (brush->mask);
mask = gimp_temp_buf_get_data (brush->mask);
/* data decoding */
if (! compress)
......
......@@ -178,7 +178,7 @@ gimp_brush_real_transform_mask (GimpBrush *brush,
scale, aspect_ratio, angle, &matrix);
if (gimp_matrix3_is_identity (&matrix))
return temp_buf_copy (source);
return gimp_temp_buf_copy (source);
src_width = source->width;
src_height = source->height;
......@@ -190,10 +190,10 @@ gimp_brush_real_transform_mask (GimpBrush *brush,
gimp_matrix3_translate (&matrix, -x, -y);
gimp_matrix3_invert (&matrix);
result = temp_buf_new (dest_width, dest_height, babl_format ("Y u8"));
result = gimp_temp_buf_new (dest_width, dest_height, babl_format ("Y u8"));
dest = temp_buf_get_data (result);
src = temp_buf_get_data (source);
dest = gimp_temp_buf_get_data (result);
src = gimp_temp_buf_get_data (source);
/* prevent disappearance of 1x1 pixel brush at some rotations when
scaling < 1 */
......@@ -340,7 +340,7 @@ gimp_brush_real_transform_mask (GimpBrush *brush,
gimp_brush_transform_fill_blur_kernel (blur_kernel, kernel_len);
blur_src = temp_buf_copy (result);
blur_src = gimp_temp_buf_copy (result);
src_buffer = gimp_temp_buf_create_buffer (blur_src, TRUE);
dest_buffer = gimp_temp_buf_create_buffer (blur_src, FALSE);
......@@ -473,7 +473,7 @@ gimp_brush_real_transform_pixmap (GimpBrush *brush,
scale, aspect_ratio, angle, &matrix);
if (gimp_matrix3_is_identity (&matrix))
return temp_buf_copy (source);
return gimp_temp_buf_copy (source);
src_width = source->width;
src_height = source->height;
......@@ -485,10 +485,11 @@ gimp_brush_real_transform_pixmap (GimpBrush *brush,
gimp_matrix3_translate (&matrix, -x, -y);
gimp_matrix3_invert (&matrix);
result = temp_buf_new (dest_width, dest_height, babl_format ("R'G'B' u8"));
result = gimp_temp_buf_new (dest_width, dest_height,
babl_format ("R'G'B' u8"));
dest = temp_buf_get_data (result);
src = temp_buf_get_data (source);
dest = gimp_temp_buf_get_data (result);
src = gimp_temp_buf_get_data (source);
gimp_matrix3_transform_point (&matrix, 0, 0, &tlx, &tly);
gimp_matrix3_transform_point (&matrix, dest_width, 0, &trx, &try);
......@@ -640,7 +641,7 @@ gimp_brush_real_transform_pixmap (GimpBrush *brush,
gimp_brush_transform_fill_blur_kernel (blur_kernel, kernel_len);
blur_src = temp_buf_copy (result);
blur_src = gimp_temp_buf_copy (result);
src_buffer = gimp_temp_buf_create_buffer (blur_src, TRUE);
dest_buffer = gimp_temp_buf_create_buffer (blur_src, FALSE);
......
......@@ -177,13 +177,13 @@ gimp_brush_finalize (GObject *object)
if (brush->mask)
{
temp_buf_free (brush->mask);
gimp_temp_buf_free (brush->mask);
brush->mask = NULL;
}
if (brush->pixmap)
{
temp_buf_free (brush->pixmap);
gimp_temp_buf_free (brush->pixmap);
brush->pixmap = NULL;
}
......@@ -255,8 +255,8 @@ gimp_brush_get_memsize (GimpObject *object,
GimpBrush *brush = GIMP_BRUSH (object);
gint64 memsize = 0;
memsize += temp_buf_get_memsize (brush->mask);
memsize += temp_buf_get_memsize (brush->pixmap);
memsize += gimp_temp_buf_get_memsize (brush->mask);
memsize += gimp_temp_buf_get_memsize (brush->pixmap);
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
gui_size);
......@@ -314,8 +314,8 @@ gimp_brush_get_new_preview (GimpViewable *viewable,
if (! mask_buf)
{
mask_buf = temp_buf_new (1, 1, babl_format ("Y u8"));
temp_buf_data_clear ((GimpTempBuf *) mask_buf);
mask_buf = gimp_temp_buf_new (1, 1, babl_format ("Y u8"));
gimp_temp_buf_data_clear ((GimpTempBuf *) mask_buf);
free_mask = TRUE;
}
......@@ -330,16 +330,16 @@ gimp_brush_get_new_preview (GimpViewable *viewable,
}
}
return_buf = temp_buf_new (mask_width, mask_height,
babl_format ("R'G'B'A u8"));
temp_buf_data_clear (return_buf);
return_buf = gimp_temp_buf_new (mask_width, mask_height,
babl_format ("R'G'B'A u8"));
gimp_temp_buf_data_clear (return_buf);
mask = temp_buf_get_data (mask_buf);
buf = temp_buf_get_data (return_buf);
mask = gimp_temp_buf_get_data (mask_buf);
buf = gimp_temp_buf_get_data (return_buf);
if (pixmap_buf)
{
guchar *pixmap = temp_buf_get_data (pixmap_buf);
guchar *pixmap = gimp_temp_buf_get_data (pixmap_buf);
for (y = 0; y < mask_height; y++)
{
......@@ -369,7 +369,7 @@ gimp_brush_get_new_preview (GimpViewable *viewable,
if (scaled)
{
if (free_mask)
temp_buf_free ((GimpTempBuf *) mask_buf);
gimp_temp_buf_free ((GimpTempBuf *) mask_buf);
gimp_brush_end_use (brush);
}
......@@ -416,10 +416,10 @@ static void
gimp_brush_real_begin_use (GimpBrush *brush)
{
brush->mask_cache =
gimp_brush_cache_new ((GDestroyNotify) temp_buf_free, 'M', 'm');
gimp_brush_cache_new ((GDestroyNotify) gimp_temp_buf_free, 'M', 'm');
brush->pixmap_cache =
gimp_brush_cache_new ((GDestroyNotify) temp_buf_free, 'P', 'p');
gimp_brush_cache_new ((GDestroyNotify) gimp_temp_buf_free, 'P', 'p');
brush->boundary_cache =
gimp_brush_cache_new ((GDestroyNotify) gimp_bezier_desc_free, 'B', 'b');
......@@ -464,9 +464,11 @@ gimp_brush_get_checksum (GimpTagged *tagged)
{
GChecksum *checksum = g_checksum_new (G_CHECKSUM_MD5);
g_checksum_update (checksum, temp_buf_get_data (brush->mask), temp_buf_get_data_size (brush->mask));
g_checksum_update (checksum, gimp_temp_buf_get_data (brush->mask),
gimp_temp_buf_get_data_size (brush->mask));
if (brush->pixmap)
g_checksum_update (checksum, temp_buf_get_data (brush->pixmap), temp_buf_get_data_size (brush->pixmap));
g_checksum_update (checksum, gimp_temp_buf_get_data (brush->pixmap),
gimp_temp_buf_get_data_size (brush->pixmap));
g_checksum_update (checksum, (const guchar *) &brush->spacing, sizeof (brush->spacing));
g_checksum_update (checksum, (const guchar *) &brush->x_axis, sizeof (brush->x_axis));
g_checksum_update (checksum, (const guchar *) &brush->y_axis, sizeof (brush->y_axis));
......@@ -619,7 +621,7 @@ gimp_brush_transform_mask (GimpBrush *brush,
angle == 0.0 &&
hardness == 1.0)
{
mask = temp_buf_copy (brush->mask);
mask = gimp_temp_buf_copy (brush->mask);
}
else
{
......@@ -669,7 +671,7 @@ gimp_brush_transform_pixmap (GimpBrush *brush,
angle == 0.0 &&
hardness == 1.0)
{
pixmap = temp_buf_copy (brush->pixmap);
pixmap = gimp_temp_buf_copy (brush->pixmap);
}
else
{
......
......@@ -184,13 +184,13 @@ gimp_brush_clipboard_buffer_changed (Gimp *gimp,
if (brush->mask)
{
temp_buf_free (brush->mask);
gimp_temp_buf_free (brush->mask);
brush->mask = NULL;
}
if (brush->pixmap)
{
temp_buf_free (brush->pixmap);
gimp_temp_buf_free (brush->pixmap);
brush->pixmap = NULL;
}
......@@ -203,8 +203,10 @@ gimp_brush_clipboard_buffer_changed (Gimp *gimp,
width = MIN (gimp_buffer_get_width (gimp->global_buffer), 512);
height = MIN (gimp_buffer_get_height (gimp->global_buffer), 512);
brush->mask = temp_buf_new (width, height, babl_format ("Y u8"));
brush->pixmap = temp_buf_new (width, height, babl_format ("R'G'B' u8"));
brush->mask = gimp_temp_buf_new (width, height,
babl_format ("Y u8"));
brush->pixmap = gimp_temp_buf_new (width, height,
babl_format ("R'G'B' u8"));
/* copy the alpha channel into the brush's mask */
if (babl_format_has_alpha (format))
......@@ -218,7 +220,7 @@ gimp_brush_clipboard_buffer_changed (Gimp *gimp,
}
else
{
memset (temp_buf_get_data (brush->mask), OPAQUE_OPACITY,
memset (gimp_temp_buf_get_data (brush->mask), OPAQUE_OPACITY,
width * height);
}
......@@ -234,8 +236,8 @@ gimp_brush_clipboard_buffer_changed (Gimp *gimp,
width = 17;
height = 17;
brush->mask = temp_buf_new (width, height, babl_format ("Y u8"));
temp_buf_data_clear (brush->mask);
brush->mask = gimp_temp_buf_new (width, height, babl_format ("Y u8"));
gimp_temp_buf_data_clear (brush->mask);
}
brush->x_axis.x = width / 2;
......
......@@ -254,7 +254,7 @@ gimp_brush_generated_dirty (GimpData *data)
GimpBrush *gbrush = GIMP_BRUSH (brush);
if (gbrush->mask)
temp_buf_free (gbrush->mask);
gimp_temp_buf_free (gbrush->mask);
gbrush->mask = gimp_brush_generated_calc (brush,
brush->shape,
......@@ -482,11 +482,12 @@ gimp_brush_generated_calc (GimpBrushGenerated *brush,
&half_width, &half_height,
&s, &c, &x_axis, &y_axis);
mask = temp_buf_new (half_width * 2 + 1,
half_height * 2 + 1,
babl_format ("Y u8"));
mask = gimp_temp_buf_new (half_width * 2 + 1,
half_height * 2 + 1,
babl_format ("Y u8"));
centerp = temp_buf_get_data (mask) + half_height * mask->width + half_width;
centerp = gimp_temp_buf_get_data (mask) +
half_height * mask->width + half_width;
lookup = gimp_brush_generated_calc_lut (radius, hardness);
......
......@@ -198,13 +198,14 @@ gimp_buffer_get_new_preview (GimpViewable *viewable,
GimpBuffer *buffer = GIMP_BUFFER (viewable);
GimpTempBuf *preview;
preview = temp_buf_new (width, height, gimp_buffer_get_format (buffer));
preview = gimp_temp_buf_new (width, height,
gimp_buffer_get_format (buffer));
gegl_buffer_get (buffer->buffer, NULL,
MIN ((gdouble) width / (gdouble) gimp_buffer_get_width (buffer),
(gdouble) height / (gdouble) gimp_buffer_get_height (buffer)),
NULL,
temp_buf_get_data (preview),
gimp_temp_buf_get_data (preview),
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
return preview;
......
......@@ -220,8 +220,8 @@ gimp_drawable_indexed_preview (GimpDrawable *drawable,
src_x, src_y, src_width, src_height,
FALSE);
preview_buf = temp_buf_new (dest_width, dest_height,
gimp_bpp_to_babl_format (bytes));
preview_buf = gimp_temp_buf_new (dest_width, dest_height,