Commit 54b89044 authored by Debarshi Ray's avatar Debarshi Ray

gegl, test-gegl: Split out the code to convert a GeglBuffer to a format

This code is necessary whenever the validity of a floating point
GeglBuffer has to be asserted because floating point colour component
values are inherently not reproducible. Minor errors can creep in due
to differences in computer architecture, varying Babl conversions or
other changes in code. These errors don't indicate a bug and will
cause spurious test failures. Therefore, it's better to convert such
GeglBuffers into integer values before checksumming. eg., this is
relevant when a buffer is zoomed by a GeglSampler because the result
is floating point premultiplied alpha.

Subsequent commits will add a new codec API for GeglBuffer similar to
those for GdkPixbuf, which is going to offer on-the-fly zooming while
decoding a bitstream. Therefore, this will be useful for testing those
code paths.

parent b4c1075b
Pipeline #61701 passed with stage
in 21 minutes and 33 seconds
......@@ -377,6 +377,37 @@ photos_gegl_buffer_apply_orientation (GeglBuffer *buffer_original, GQuark orient
GeglBuffer *
photos_gegl_buffer_convert (GeglBuffer *buffer_original, const Babl *format)
const Babl *format_original;
GeglBuffer *ret_val = NULL;
GeglRectangle bbox;
g_return_val_if_fail (GEGL_IS_BUFFER (buffer_original), NULL);
if (format == NULL)
ret_val = g_object_ref (buffer_original);
goto out;
format_original = gegl_buffer_get_format (buffer_original);
if (format == format_original)
ret_val = g_object_ref (buffer_original);
goto out;
bbox = *gegl_buffer_get_extent (buffer_original);
ret_val = gegl_buffer_new (&bbox, format);
gegl_buffer_copy (buffer_original, &bbox, GEGL_ABYSS_NONE, ret_val, &bbox);
return ret_val;
GeglBuffer *
photos_gegl_buffer_new_from_pixbuf (GdkPixbuf *pixbuf)
......@@ -29,6 +29,8 @@ G_BEGIN_DECLS
GeglBuffer *photos_gegl_buffer_apply_orientation (GeglBuffer *buffer_original, GQuark orientation);
GeglBuffer *photos_gegl_buffer_convert (GeglBuffer *buffer_original, const Babl *format);
GeglBuffer *photos_gegl_buffer_new_from_pixbuf (GdkPixbuf *pixbuf);
void photos_gegl_buffer_zoom_async (GeglBuffer *buffer,
......@@ -433,9 +433,7 @@ photos_test_gegl_buffer_check_zoom (PhotosTestGeglFixture *fixture,
g_assert_cmpint (bbox.y, ==, y);
format_zoomed_converted = babl_format ("R'G'B'A u8");
buffer_zoomed_converted = gegl_buffer_new (&bbox, format_zoomed_converted);
gegl_buffer_copy (buffer_zoomed, &bbox, GEGL_ABYSS_NONE, buffer_zoomed_converted, &bbox);
buffer_zoomed_converted = photos_gegl_buffer_convert (buffer_zoomed, format_zoomed_converted);
photos_test_gegl_buffer_save_to_file (buffer_zoomed_converted, fixture->destination_0);
checksum_zoomed_converted = photos_gegl_compute_checksum_for_buffer (G_CHECKSUM_SHA256, buffer_zoomed_converted);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment