[gtk/wip/otte/color-profiles: 105/111] Check profiles match memory formats




commit fa01190d332c923f36a648a83bb98a45b6c4a713
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Sep 29 14:52:15 2021 -0400

    Check profiles match memory formats
    
    When creating a GdkMemoryTexture, the caller provides
    a memory format and a color profile, both of which
    encode expectations about the color components of
    the pixel data. Check that they match.

 gdk/gdkcolorprofile.c        | 14 ++++++++++++++
 gdk/gdkcolorprofileprivate.h |  3 +++
 gdk/gdkmemorytexture.c       |  3 ++-
 3 files changed, 19 insertions(+), 1 deletion(-)
---
diff --git a/gdk/gdkcolorprofile.c b/gdk/gdkcolorprofile.c
index 6d7a98b3c0..6c398f7811 100644
--- a/gdk/gdkcolorprofile.c
+++ b/gdk/gdkcolorprofile.c
@@ -346,6 +346,7 @@ gdk_color_profile_get_lcms_profile (GdkColorProfile *self)
  * @profile: a `GdkColorProfile`
  *
  * Checks if the given profile is linear.
+ *
  * GTK tries to do compositing in a linear profile.
  *
  * Some profiles may be linear, but it is not possible to
@@ -470,3 +471,16 @@ gdk_color_profile_lookup_transform (GdkColorProfile *source,
   
   return transform;
 }
+
+/* Check if the color profile and the memory format have the
+ * same color components.
+ */
+gboolean
+gdk_color_profile_supports_memory_format (GdkColorProfile *profile,
+                                          GdkMemoryFormat  format)
+{
+  /* Currently, all our memory formats are RGB (with or without alpha).
+   * Update this when that changes.
+   */
+  return cmsGetColorSpace (profile->lcms_profile) == cmsSigRgbData;
+}
diff --git a/gdk/gdkcolorprofileprivate.h b/gdk/gdkcolorprofileprivate.h
index 41dd99c457..419ecdc1af 100644
--- a/gdk/gdkcolorprofileprivate.h
+++ b/gdk/gdkcolorprofileprivate.h
@@ -2,6 +2,7 @@
 #define __GDK_COLOR_PROFILE_PRIVATE_H__
 
 #include "gdkcolorprofile.h"
+#include "gdkmemorytexture.h"
 
 #include <lcms2.h>
 
@@ -18,6 +19,8 @@ cmsHTRANSFORM *              gdk_color_profile_lookup_transform           (GdkCo
                                                                            guint                 source_type,
                                                                            GdkColorProfile      *dest,
                                                                            guint                 dest_type);
+gboolean                     gdk_color_profile_supports_memory_format     (GdkColorProfile      *profile,
+                                                                           GdkMemoryFormat       format);
 
 G_END_DECLS
 
diff --git a/gdk/gdkmemorytexture.c b/gdk/gdkmemorytexture.c
index 2391784d03..4a5474bfe9 100644
--- a/gdk/gdkmemorytexture.c
+++ b/gdk/gdkmemorytexture.c
@@ -21,7 +21,7 @@
 
 #include "gdkmemorytextureprivate.h"
 
-#include "gdkcolorprofile.h"
+#include "gdkcolorprofileprivate.h"
 #include "gdkmemoryformatprivate.h"
 #include "gsk/ngl/fp16private.h"
 
@@ -220,6 +220,7 @@ gdk_memory_texture_new_with_color_profile (int              width,
   g_return_val_if_fail (GDK_IS_COLOR_PROFILE (color_profile), NULL);
   g_return_val_if_fail (bytes != NULL, NULL);
   g_return_val_if_fail (stride >= width * gdk_memory_format_bytes_per_pixel (format), NULL);
+  g_return_val_if_fail (gdk_color_profile_supports_memory_format (color_profile, format), NULL);
 
   bytes = gdk_memory_sanitize (bytes, width, height, format, stride, &stride);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]