[gegl] buffer: add gegl_buffer_set_format:
- From: Ãyvind KolÃs <ok src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] buffer: add gegl_buffer_set_format:
- Date: Mon, 26 Mar 2012 02:46:41 +0000 (UTC)
commit fec1a8dc1c576b1211eb651acfeae4bff43542d7
Author: Ãyvind KolÃs <pippin gimp org>
Date: Mon Mar 26 03:44:21 2012 +0100
buffer: add gegl_buffer_set_format:
Set the babl format of the buffer, setting the babl format of the buffer
requires the new format to have exactly the same bytes per pixel as the
original format. If NULL is passed in the format of the buffer is reset to the
original format.
Returns: the new babl format or NULL if it the passed in buffer was
incompatible (then the original format is still used).
gegl/buffer/gegl-buffer-access.c | 46 ++++++++++++------------
gegl/buffer/gegl-buffer-cl-cache.c | 12 +++---
gegl/buffer/gegl-buffer-cl-iterator.c | 20 +++++-----
gegl/buffer/gegl-buffer-iterator.c | 6 ++--
gegl/buffer/gegl-buffer-linear.c | 4 +-
gegl/buffer/gegl-buffer-private.h | 2 +
gegl/buffer/gegl-buffer.c | 62 ++++++++++++++++++++++++++++----
gegl/buffer/gegl-buffer.h | 22 +++++++++++-
8 files changed, 121 insertions(+), 53 deletions(-)
---
diff --git a/gegl/buffer/gegl-buffer-access.c b/gegl/buffer/gegl-buffer-access.c
index fa30d4c..3646e14 100644
--- a/gegl/buffer/gegl-buffer-access.c
+++ b/gegl/buffer/gegl-buffer-access.c
@@ -62,9 +62,9 @@ gegl_buffer_pixel_set (GeglBuffer *buffer,
gint buffer_abyss_x = buffer->abyss.x;
gint buffer_abyss_y = buffer->abyss.y;
- if (format != buffer->format)
+ if (format != buffer->soft_format)
{
- fish = babl_fish (buffer->format, format);
+ fish = babl_fish (buffer->soft_format, format);
}
if (!(buffer_y + y >= buffer_abyss_y &&
@@ -142,11 +142,11 @@ gegl_buffer_set_pixel (GeglBuffer *buffer,
gint buffer_shift_x = buffer->shift_x;
gint buffer_shift_y = buffer->shift_y;
- gint px_size = babl_format_get_bytes_per_pixel (buffer->format);
+ gint px_size = babl_format_get_bytes_per_pixel (buffer->soft_format);
- if (format != buffer->format)
+ if (format != buffer->soft_format)
{
- fish = babl_fish ((gpointer) buffer->format,
+ fish = babl_fish ((gpointer) buffer->soft_format,
(gpointer) format);
}
@@ -219,11 +219,11 @@ gegl_buffer_get_pixel (GeglBuffer *buffer,
gint buffer_shift_x = buffer->shift_x;
gint buffer_shift_y = buffer->shift_y;
- gint px_size = babl_format_get_bytes_per_pixel (buffer->format);
+ gint px_size = babl_format_get_bytes_per_pixel (buffer->soft_format);
- if (format != buffer->format)
+ if (format != buffer->soft_format)
{
- fish = babl_fish ((gpointer) buffer->format,
+ fish = babl_fish ((gpointer) buffer->soft_format,
(gpointer) format);
}
@@ -321,7 +321,7 @@ gegl_buffer_iterate (GeglBuffer *buffer,
{
gint tile_width = buffer->tile_storage->tile_width;
gint tile_height = buffer->tile_storage->tile_height;
- gint px_size = babl_format_get_bytes_per_pixel (buffer->format);
+ gint px_size = babl_format_get_bytes_per_pixel (buffer->soft_format);
gint bpx_size = babl_format_get_bytes_per_pixel (format);
gint tile_stride = px_size * tile_width;
gint buf_stride;
@@ -364,7 +364,7 @@ gegl_buffer_iterate (GeglBuffer *buffer,
if (rowstride != GEGL_AUTO_ROWSTRIDE)
buf_stride = rowstride;
- if (format == buffer->format)
+ if (format == buffer->soft_format)
{
fish = NULL;
}
@@ -373,11 +373,11 @@ gegl_buffer_iterate (GeglBuffer *buffer,
if (write)
{
fish = babl_fish ((gpointer) format,
- (gpointer) buffer->format);
+ (gpointer) buffer->soft_format);
}
else
{
- fish = babl_fish ((gpointer) buffer->format,
+ fish = babl_fish ((gpointer) buffer->soft_format,
(gpointer) format);
}
}
@@ -578,7 +578,7 @@ gegl_buffer_set_unlocked (GeglBuffer *buffer,
gint rowstride)
{
if (format == NULL)
- format = buffer->format;
+ format = buffer->soft_format;
#if 0 /* XXX: not thread safe */
if (rect && rect->width == 1 && rect->height == 1) /* fast path */
@@ -935,7 +935,7 @@ gegl_buffer_get_unlocked (GeglBuffer *buffer,
{
if (format == NULL)
- format = buffer->format;
+ format = buffer->soft_format;
#if 0
/* not thread-safe */
@@ -1162,7 +1162,7 @@ gegl_buffer_copy (GeglBuffer *src,
dst_rect = src_rect;
}
- fish = babl_fish (src->format, dst->format);
+ fish = babl_fish (src->soft_format, dst->soft_format);
{
GeglRectangle dest_rect_r = *dst_rect;
@@ -1172,8 +1172,8 @@ gegl_buffer_copy (GeglBuffer *src,
dest_rect_r.width = src_rect->width;
dest_rect_r.height = src_rect->height;
- i = gegl_buffer_iterator_new (dst, &dest_rect_r, dst->format, GEGL_BUFFER_WRITE, 0); /* XXX: is level 0 right? */
- read = gegl_buffer_iterator_add (i, src, src_rect, src->format, GEGL_BUFFER_READ);
+ i = gegl_buffer_iterator_new (dst, &dest_rect_r, dst->soft_format, GEGL_BUFFER_WRITE, 0); /* XXX: is level 0 right? */
+ read = gegl_buffer_iterator_add (i, src, src_rect, src->soft_format, GEGL_BUFFER_READ);
while (gegl_buffer_iterator_next (i))
babl_process (fish, i->data[read], i->data[0], i->length);
}
@@ -1196,7 +1196,7 @@ gegl_buffer_clear (GeglBuffer *dst,
dst_rect->height == 0)
return;
- pxsize = babl_format_get_bytes_per_pixel (dst->format);
+ pxsize = babl_format_get_bytes_per_pixel (dst->soft_format);
if (gegl_cl_is_accelerated ())
gegl_buffer_cl_cache_invalidate (dst, dst_rect);
@@ -1204,7 +1204,7 @@ gegl_buffer_clear (GeglBuffer *dst,
/* FIXME: this can be even further optimized by special casing it so
* that fully voided tiles are dropped.
*/
- i = gegl_buffer_iterator_new (dst, dst_rect, dst->format, GEGL_BUFFER_WRITE, 0); /* XXX: should level be settable */
+ i = gegl_buffer_iterator_new (dst, dst_rect, dst->soft_format, GEGL_BUFFER_WRITE, 0); /* XXX: should level be settable */
while (gegl_buffer_iterator_next (i))
{
memset (((guchar*)(i->data[0])), 0, i->length * pxsize);
@@ -1264,7 +1264,7 @@ void gegl_buffer_set_color (GeglBuffer *dst,
g_return_if_fail (GEGL_IS_BUFFER (dst));
g_return_if_fail (color);
- gegl_color_get_pixel (color, dst->format, buf);
+ gegl_color_get_pixel (color, dst->soft_format, buf);
if (!dst_rect)
{
@@ -1274,12 +1274,12 @@ void gegl_buffer_set_color (GeglBuffer *dst,
dst_rect->height == 0)
return;
- pxsize = babl_format_get_bytes_per_pixel (dst->format);
+ pxsize = babl_format_get_bytes_per_pixel (dst->soft_format);
/* FIXME: this can be even further optimized by special casing it so
* that fully filled tiles are shared.
*/
- i = gegl_buffer_iterator_new (dst, dst_rect, dst->format, GEGL_BUFFER_WRITE, 0);
+ i = gegl_buffer_iterator_new (dst, dst_rect, dst->soft_format, GEGL_BUFFER_WRITE, 0);
while (gegl_buffer_iterator_next (i))
{
int j;
@@ -1295,7 +1295,7 @@ gegl_buffer_dup (GeglBuffer *buffer)
g_return_val_if_fail (GEGL_IS_BUFFER (buffer), NULL);
- new_buffer = gegl_buffer_new (gegl_buffer_get_extent (buffer), buffer->format);
+ new_buffer = gegl_buffer_new (gegl_buffer_get_extent (buffer), buffer->soft_format);
gegl_buffer_copy (buffer, gegl_buffer_get_extent (buffer),
new_buffer, gegl_buffer_get_extent (buffer));
return new_buffer;
diff --git a/gegl/buffer/gegl-buffer-cl-cache.c b/gegl/buffer/gegl-buffer-cl-cache.c
index 7172b90..07b5d52 100644
--- a/gegl/buffer/gegl-buffer-cl-cache.c
+++ b/gegl/buffer/gegl-buffer-cl-cache.c
@@ -86,7 +86,7 @@ gegl_buffer_cl_cache_merge (GeglBuffer *buffer,
if (!roi)
roi = &buffer->extent;
- gegl_cl_color_babl (buffer->format, &size);
+ gegl_cl_color_babl (buffer->soft_format, &size);
for (elem=cache_entries; elem; elem=elem->next)
{
@@ -103,7 +103,7 @@ gegl_buffer_cl_cache_merge (GeglBuffer *buffer,
if (cl_err != CL_SUCCESS) CL_ERROR;
/* tile-ize */
- gegl_buffer_set (entry->buffer, &entry->roi, 0, entry->buffer->format, data, GEGL_AUTO_ROWSTRIDE);
+ gegl_buffer_set (entry->buffer, &entry->roi, 0, entry->buffer->soft_format, data, GEGL_AUTO_ROWSTRIDE);
cl_err = gegl_clEnqueueUnmapMemObject (gegl_cl_get_command_queue(), entry->tex, data,
0, NULL, NULL);
@@ -235,8 +235,8 @@ gegl_buffer_cl_cache_from (GeglBuffer *buffer,
cl_mem tex_dest = NULL;
GList *elem_cache, *elem_buffer;
- gegl_cl_color_op conv = gegl_cl_color_supported (buffer->format, format);
- gegl_cl_color_babl (buffer->format, &buf_size);
+ gegl_cl_color_op conv = gegl_cl_color_supported (buffer->soft_format, format);
+ gegl_cl_color_babl (buffer->soft_format, &buf_size);
gegl_cl_color_babl (format, &dest_size);
for (elem_cache=cache_entries; elem_cache; elem_cache=elem_cache->next)
@@ -268,7 +268,7 @@ gegl_buffer_cl_cache_from (GeglBuffer *buffer,
CacheBuffer *cb = elem_buffer->data;
if (cb->valid && cb->buffer &&
cb->buffer_origin == buffer &&
- cb->buffer->format == format &&
+ cb->buffer->soft_format == format &&
gegl_rectangle_contains (&cb->roi, roi))
{
gegl_buffer_get (cb->buffer,
@@ -303,7 +303,7 @@ gegl_buffer_cl_cache_from (GeglBuffer *buffer,
NULL, &cl_err);
if (cl_err != CL_SUCCESS) CL_ERROR;
- cl_err = gegl_cl_color_conv (entry->tex, tex_dest, entry->roi.width * entry->roi.height, buffer->format, format);
+ cl_err = gegl_cl_color_conv (entry->tex, tex_dest, entry->roi.width * entry->roi.height, buffer->soft_format, format);
if (cl_err == FALSE) CL_ERROR;
data = gegl_clEnqueueMapBuffer(gegl_cl_get_command_queue(), tex_dest, CL_TRUE,
diff --git a/gegl/buffer/gegl-buffer-cl-iterator.c b/gegl/buffer/gegl-buffer-cl-iterator.c
index 6296fb4..a34b5a4 100644
--- a/gegl/buffer/gegl-buffer-cl-iterator.c
+++ b/gegl/buffer/gegl-buffer-cl-iterator.c
@@ -47,7 +47,7 @@ typedef struct GeglBufferClIterators
const Babl *format [GEGL_CL_BUFFER_MAX_ITERATORS]; /* The format required for the data */
GeglBuffer *buffer [GEGL_CL_BUFFER_MAX_ITERATORS];
- /* buffer->format */
+ /* buffer->soft_format */
size_t buf_cl_format_size [GEGL_CL_BUFFER_MAX_ITERATORS];
/* format */
size_t op_cl_format_size [GEGL_CL_BUFFER_MAX_ITERATORS];
@@ -101,15 +101,15 @@ gegl_buffer_cl_iterator_add_2 (GeglBufferClIterator *iterator,
if (format)
i->format[self]=format;
else
- i->format[self]=buffer->format;
+ i->format[self]=buffer->soft_format;
if (flags == GEGL_CL_BUFFER_WRITE)
- i->conv[self] = gegl_cl_color_supported (format, buffer->format);
+ i->conv[self] = gegl_cl_color_supported (format, buffer->soft_format);
else
- i->conv[self] = gegl_cl_color_supported (buffer->format, format);
+ i->conv[self] = gegl_cl_color_supported (buffer->soft_format, format);
- gegl_cl_color_babl (buffer->format, &i->buf_cl_format_size[self]);
- gegl_cl_color_babl (format, &i->op_cl_format_size [self]);
+ gegl_cl_color_babl (buffer->soft_format, &i->buf_cl_format_size[self]);
+ gegl_cl_color_babl (format, &i->op_cl_format_size [self]);
}
else /* GEGL_CL_BUFFER_AUX */
{
@@ -229,7 +229,7 @@ gegl_buffer_cl_iterator_next (GeglBufferClIterator *iterator, gboolean *err)
for (j=0; j < i->n; j++)
{
cl_err = gegl_cl_color_conv (i->tex_op[no][j], i->tex_buf[no][j], i->size[no][j],
- i->format[no], i->buffer[no]->format);
+ i->format[no], i->buffer[no]->soft_format);
if (cl_err == FALSE) CL_ERROR;
}
@@ -384,7 +384,7 @@ gegl_buffer_cl_iterator_next (GeglBufferClIterator *iterator, gboolean *err)
if (cl_err != CL_SUCCESS) CL_ERROR;
/* color conversion will be performed in the GPU later */
- gegl_buffer_get (i->buffer[no], &i->roi[no][j], 1.0, i->buffer[no]->format, data, GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
+ gegl_buffer_get (i->buffer[no], &i->roi[no][j], 1.0, i->buffer[no]->soft_format, data, GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
cl_err = gegl_clEnqueueUnmapMemObject (gegl_cl_get_command_queue(), i->tex_buf[no][j], data,
0, NULL, NULL);
@@ -420,7 +420,7 @@ gegl_buffer_cl_iterator_next (GeglBufferClIterator *iterator, gboolean *err)
if (cl_err != CL_SUCCESS) CL_ERROR;
/* color conversion will be performed in the GPU later */
- gegl_buffer_get (i->buffer[no], &i->roi[no][j], 1.0, i->buffer[no]->format, data, GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
+ gegl_buffer_get (i->buffer[no], &i->roi[no][j], 1.0, i->buffer[no]->soft_format, data, GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
cl_err = gegl_clEnqueueUnmapMemObject (gegl_cl_get_command_queue(), i->tex_buf[no][j], data,
0, NULL, NULL);
@@ -437,7 +437,7 @@ gegl_buffer_cl_iterator_next (GeglBufferClIterator *iterator, gboolean *err)
/* color conversion in the GPU (input) */
g_assert (i->tex_buf[no][j] && i->tex_op[no][j]);
cl_err = gegl_cl_color_conv (i->tex_buf[no][j], i->tex_op[no][j], i->size[no][j],
- i->buffer[no]->format, i->format[no]);
+ i->buffer[no]->soft_format, i->format[no]);
if (cl_err == FALSE) CL_ERROR;
i->tex[no][j] = i->tex_op[no][j];
diff --git a/gegl/buffer/gegl-buffer-iterator.c b/gegl/buffer/gegl-buffer-iterator.c
index bb8a58b..866e3bf 100644
--- a/gegl/buffer/gegl-buffer-iterator.c
+++ b/gegl/buffer/gegl-buffer-iterator.c
@@ -199,7 +199,7 @@ gulp:
i->data = gegl_tile_get_data (i->tile);
{
- gint bpp = babl_format_get_bytes_per_pixel (i->buffer->format);
+ gint bpp = babl_format_get_bytes_per_pixel (i->buffer->soft_format);
i->rowstride = bpp * tile_width;
i->sub_data = (guchar*)(i->data) + bpp * (i->subrect.y * tile_width + i->subrect.x);
}
@@ -279,7 +279,7 @@ gegl_buffer_iterator_add (GeglBufferIterator *iterator,
if (format)
i->format[self]=format;
else
- i->format[self]=buffer->format;
+ i->format[self]=buffer->soft_format;
i->flags[self]=flags;
if (self==0) /* The first buffer which is always scan aligned */
@@ -303,7 +303,7 @@ gegl_buffer_iterator_add (GeglBufferIterator *iterator,
i->buf[self] = NULL;
- if (i->format[self] == i->buffer[self]->format)
+ if (i->format[self] == i->buffer[self]->soft_format)
{
i->flags[self] |= GEGL_BUFFER_FORMAT_COMPATIBLE;
}
diff --git a/gegl/buffer/gegl-buffer-linear.c b/gegl/buffer/gegl-buffer-linear.c
index 2505a6a..a4cd108 100644
--- a/gegl/buffer/gegl-buffer-linear.c
+++ b/gegl/buffer/gegl-buffer-linear.c
@@ -125,7 +125,7 @@ gegl_buffer_linear_open (GeglBuffer *buffer,
const Babl *format) /* if NULL, from buf */
{
if (!format)
- format = buffer->format;
+ format = buffer->soft_format;
if (extent == NULL)
extent=&buffer->extent;
@@ -136,7 +136,7 @@ gegl_buffer_linear_open (GeglBuffer *buffer,
extent->y == buffer->extent.y &&
extent->width == buffer->tile_width &&
extent->height <= buffer->tile_height &&
- buffer->format == format)
+ buffer->soft_format == format)
{
GeglTile *tile;
diff --git a/gegl/buffer/gegl-buffer-private.h b/gegl/buffer/gegl-buffer-private.h
index 802af0b..398f7b5 100644
--- a/gegl/buffer/gegl-buffer-private.h
+++ b/gegl/buffer/gegl-buffer-private.h
@@ -40,6 +40,8 @@ struct _GeglBuffer
const Babl *format; /* the pixel format used for pixels in this
buffer */
+ const Babl *soft_format; /* the format the buffer pretends to be, might
+ be different from format */
gint shift_x; /* The relative offset of origins compared with */
gint shift_y; /* anchestral tile_storage buffer, during */
diff --git a/gegl/buffer/gegl-buffer.c b/gegl/buffer/gegl-buffer.c
index 339c846..82fd96b 100644
--- a/gegl/buffer/gegl-buffer.c
+++ b/gegl/buffer/gegl-buffer.c
@@ -190,10 +190,17 @@ gegl_buffer_get_property (GObject *gobject,
* since it will never change.
*/
- if (buffer->format == NULL)
- buffer->format = gegl_buffer_internal_get_format (buffer);
+ {
+ const Babl *format;
+
+ format = buffer->soft_format;
+ if (format == NULL)
+ format = buffer->format;
+ if (format == NULL)
+ format = gegl_buffer_internal_get_format (buffer);
- g_value_set_pointer (value, (void*)buffer->format); /* Eeeek? */
+ g_value_set_pointer (value, (void*)format);
+ }
break;
case PROP_BACKEND:
@@ -292,7 +299,21 @@ gegl_buffer_set_property (GObject *gobject,
* for a gpointer paramspec
*/
if (g_value_get_pointer (value))
- buffer->format = g_value_get_pointer (value);
+ {
+ const Babl *format = g_value_get_pointer (value);
+ /* XXX: need to check if the internal format matches, should
+ * perhaps do different things here depending on whether
+ * we are during construction or not
+ */
+ if (buffer->soft_format)
+ {
+ gegl_buffer_set_format (buffer, format);
+ }
+ else
+ {
+ buffer->format = format;
+ }
+ }
break;
case PROP_BACKEND:
if (g_value_get_pointer (value))
@@ -603,7 +624,7 @@ gegl_buffer_constructor (GType type,
g_warning ("not enough data to have a tile source for our buffer");
}
/* we reset the size if it seems to have been set to 0 during a on
- * disk buffer creation, nasty but it seems to do the job.
+ * disk buffer creation, nasty but it does the job.
*/
if (buffer->extent.width == 0)
@@ -709,6 +730,11 @@ gegl_buffer_constructor (GType type,
buffer->tile_storage = gegl_buffer_tile_storage (buffer);
+ /* intialize the soft format to be equivalent to the actual
+ * format
+ */
+ buffer->soft_format = buffer->format;
+
return object;
}
@@ -942,6 +968,7 @@ gegl_buffer_init (GeglBuffer *buffer)
buffer->abyss.width = 0;
buffer->abyss.height = 0;
buffer->format = NULL;
+ buffer->soft_format = NULL;
buffer->hot_tile = NULL;
buffer->path = NULL;
@@ -1240,7 +1267,6 @@ gegl_buffer_new_from_format (const void *babl_fmt,
return buffer;
}
-
static const void *gegl_buffer_internal_get_format (GeglBuffer *buffer)
{
g_assert (buffer);
@@ -1249,9 +1275,29 @@ static const void *gegl_buffer_internal_get_format (GeglBuffer *buffer)
return gegl_tile_backend_get_format (gegl_buffer_backend (buffer));
}
-const Babl *gegl_buffer_get_format (GeglBuffer *buffer)
+const Babl *
+gegl_buffer_get_format (GeglBuffer *buffer)
+{
+ return buffer?buffer->format:NULL;
+}
+
+const Babl *
+gegl_buffer_set_format (GeglBuffer *buffer,
+ const Babl *format)
{
- return buffer?buffer->format:0;
+ if (format == NULL)
+ {
+ buffer->soft_format = buffer->format;
+ return buffer->soft_format;
+ }
+ if (babl_format_get_bytes_per_pixel (format) ==
+ babl_format_get_bytes_per_pixel (buffer->format))
+ {
+ buffer->soft_format = format;
+ return buffer->soft_format;
+ }
+ g_warning ("tried to set format of different bpp on buffer\n");
+ return NULL;
}
gboolean gegl_buffer_is_shared (GeglBuffer *buffer)
diff --git a/gegl/buffer/gegl-buffer.h b/gegl/buffer/gegl-buffer.h
index a1d909b..2eb6f96 100644
--- a/gegl/buffer/gegl-buffer.h
+++ b/gegl/buffer/gegl-buffer.h
@@ -300,13 +300,33 @@ void gegl_buffer_set_pattern (GeglBuffer *buffer,
* gegl_buffer_get_format:
* @buffer: a #GeglBuffer
*
- * Get the native babl format of the buffer.
+ * Get the babl format of the buffer, this might not be the format the buffer
+ * was originally created with, you need to use gegl_buffer_set_format (buf,
+ * NULL); to retireve the original format (potentially having save away the
+ * original format of the buffer to re-set it.)
*
* Returns: the babl format used for storing pixels in the buffer.
*
*/
const Babl * gegl_buffer_get_format (GeglBuffer *buffer);
+
+/**
+ * gegl_buffer_set_format:
+ * @buffer: a #GeglBuffer
+ * @format: the new babl format, must have same bpp as original format.
+ *
+ * Set the babl format of the buffer, setting the babl format of the buffer
+ * requires the new format to have exactly the same bytes per pixel as the
+ * original format. If NULL is passed in the format of the buffer is reset to
+ * the original format.
+ *
+ * Returns: the new babl format or NULL if it the passed in buffer was
+ * incompatible (then the original format is still used).
+ */
+const Babl * gegl_buffer_set_format (GeglBuffer *buffer,
+ const Babl *format);
+
/**
* gegl_buffer_clear:
* @buffer: a #GeglBuffer
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]