[gnome-photos/wip/rishi/buffer-convert] gegl, test-gegl: Split out the code to convert a GeglBuffer to a format
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/rishi/buffer-convert] gegl, test-gegl: Split out the code to convert a GeglBuffer to a format
- Date: Fri, 22 Feb 2019 09:18:28 +0000 (UTC)
commit 54b89044e6887e648ff08e244266b10ae22c6341
Author: Debarshi Ray <debarshir gnome org>
Date: Fri Feb 22 10:04:12 2019 +0100
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.
https://gitlab.gnome.org/GNOME/gnome-photos/issues/63
src/photos-gegl.c | 31 +++++++++++++++++++++++++++++++
src/photos-gegl.h | 2 ++
tests/unit/photos-test-gegl.c | 4 +---
3 files changed, 34 insertions(+), 3 deletions(-)
---
diff --git a/src/photos-gegl.c b/src/photos-gegl.c
index d6f6cedd..b793360b 100644
--- a/src/photos-gegl.c
+++ b/src/photos-gegl.c
@@ -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);
+
+ out:
+ return ret_val;
+}
+
+
GeglBuffer *
photos_gegl_buffer_new_from_pixbuf (GdkPixbuf *pixbuf)
{
diff --git a/src/photos-gegl.h b/src/photos-gegl.h
index 566b256a..cd533a97 100644
--- a/src/photos-gegl.h
+++ b/src/photos-gegl.h
@@ -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,
diff --git a/tests/unit/photos-test-gegl.c b/tests/unit/photos-test-gegl.c
index 2d0431cc..5cda0d59 100644
--- a/tests/unit/photos-test-gegl.c
+++ b/tests/unit/photos-test-gegl.c
@@ -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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]