[gtk/matthiasc/color-profile-rebased: 7/51] Add some colorspace tests
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/matthiasc/color-profile-rebased: 7/51] Add some colorspace tests
- Date: Sat, 1 Oct 2022 01:36:39 +0000 (UTC)
commit 9b824abddd8210968c119ec9c51644e403e4c833
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Sep 30 14:22:37 2022 -0400
Add some colorspace tests
This is very minimal, but it is enough to do
a very basic check of the gdk_color_space_equal
implementation.
testsuite/gdk/Rec709.icc | Bin 0 -> 22464 bytes
testsuite/gdk/colorspace.c | 97 +++++++++++++++++++++++++++++++++++++++++++++
testsuite/gdk/meson.build | 1 +
3 files changed, 98 insertions(+)
---
diff --git a/testsuite/gdk/Rec709.icc b/testsuite/gdk/Rec709.icc
new file mode 100644
index 0000000000..3f7f3d3758
Binary files /dev/null and b/testsuite/gdk/Rec709.icc differ
diff --git a/testsuite/gdk/colorspace.c b/testsuite/gdk/colorspace.c
new file mode 100644
index 0000000000..0fb4925ef4
--- /dev/null
+++ b/testsuite/gdk/colorspace.c
@@ -0,0 +1,97 @@
+#include <gdk/gdk.h>
+
+static GdkColorSpace *
+get_rec709 (void)
+{
+ const char *file;
+ char *data;
+ gsize size;
+ GError *error = NULL;
+ GBytes *bytes;
+ GdkColorSpace *cs;
+
+ file = g_test_get_filename (G_TEST_DIST, "Rec709.icc", NULL);
+
+ if (!g_file_get_contents (file, &data, &size, &error))
+ {
+ g_error ("%s", error->message);
+ return NULL;
+ }
+
+ bytes = g_bytes_new_take (data, size);
+
+ cs = gdk_color_space_new_from_icc_profile (bytes, &error);
+ if (!cs)
+ g_error ("%s", error->message);
+
+ g_bytes_unref (bytes);
+
+ return cs;
+}
+
+static void
+test_srgb (void)
+{
+ GdkColorSpace *cs;
+ GdkColorSpace *cs2;
+
+ cs = gdk_color_space_get_srgb ();
+
+ g_assert_false (gdk_color_space_is_linear (cs));
+ g_assert_cmpint (gdk_color_space_get_n_components (cs), ==, 3);
+ g_assert_true (gdk_color_space_supports_format (cs, GDK_MEMORY_B8G8R8A8_PREMULTIPLIED));
+ g_assert_true (gdk_color_space_supports_format (cs, GDK_MEMORY_R16G16B16_FLOAT));
+
+ cs2 = get_rec709 ();
+ g_assert_false (gdk_color_space_equal (cs, cs2));
+ g_object_unref (cs2);
+}
+
+static void
+test_icc_roundtrip (GdkColorSpace *cs)
+{
+ GdkColorSpace *cs2;
+ GBytes *icc_data;
+ GError *error = NULL;
+
+
+ icc_data = gdk_color_space_save_to_icc_profile (cs, &error);
+ g_assert_no_error (error);
+
+ cs2 = gdk_color_space_new_from_icc_profile (icc_data, &error);
+ g_assert_no_error (error);
+
+ g_assert_true (gdk_color_space_equal (cs, cs2));
+
+ g_bytes_unref (icc_data);
+
+ g_object_unref (cs2);
+}
+
+static void
+test_icc_roundtrip_srgb (void)
+{
+ test_icc_roundtrip (gdk_color_space_get_srgb ());
+}
+
+static void
+test_icc_roundtrip_rec709 (void)
+{
+ GdkColorSpace *cs;
+
+ cs = get_rec709 ();
+ test_icc_roundtrip (cs);
+ g_object_unref (cs);
+}
+
+int
+main (int argc, char *argv[])
+{
+ (g_test_init) (&argc, &argv, NULL);
+
+ g_test_add_func ("/colorspace/srgb", test_srgb);
+ g_test_add_func ("/colorspace/icc-roundtrip-srgb", test_icc_roundtrip_srgb);
+ g_test_add_func ("/colorspace/icc-roundtrip-rec709", test_icc_roundtrip_rec709);
+
+ return g_test_run ();
+}
diff --git a/testsuite/gdk/meson.build b/testsuite/gdk/meson.build
index 03528a3905..e8bc9c88f9 100644
--- a/testsuite/gdk/meson.build
+++ b/testsuite/gdk/meson.build
@@ -13,6 +13,7 @@ tests = [
{ 'name': 'array' },
{ 'name': 'cairo' },
{ 'name': 'clipboard', 'parallel': false, },
+ { 'name': 'colorspace' },
{ 'name': 'contentformats' },
{ 'name': 'contentserializer' },
{ 'name': 'cursor' },
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]