[gtk/matthiasc/color-profile-rebased: 10/46] memoryformat: Take a color profile when converting
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/matthiasc/color-profile-rebased: 10/46] memoryformat: Take a color profile when converting
- Date: Tue, 10 May 2022 13:15:49 +0000 (UTC)
commit 15cce98a31356d76596803e30dfe7d30a7256447
Author: Matthias Clasen <mclasen redhat com>
Date: Sun May 8 07:59:50 2022 -0400
memoryformat: Take a color profile when converting
gdk/gdkgltexture.c | 8 +++++---
gdk/gdkmemoryformat.c | 41 +++++++++++++++++++++++++++++++++++++----
gdk/gdkmemoryformatprivate.h | 3 +++
gdk/gdkmemorytexture.c | 2 ++
gsk/gl/gskglglyphlibrary.c | 2 ++
gsk/gl/gskgliconlibrary.c | 5 ++++-
6 files changed, 53 insertions(+), 8 deletions(-)
---
diff --git a/gdk/gdkgltexture.c b/gdk/gdkgltexture.c
index 94d877e8a2..27acc486ed 100644
--- a/gdk/gdkgltexture.c
+++ b/gdk/gdkgltexture.c
@@ -157,7 +157,7 @@ gdk_gl_texture_do_download (gpointer texture_,
expected_stride = texture->width * gdk_memory_format_bytes_per_pixel (download->format);
if (download->stride == expected_stride &&
- !gdk_gl_context_get_use_es (self->context) &&
+ !gdk_gl_context_get_use_es (self->context) &&
gdk_memory_format_gl_format (download->format, TRUE, &gl_internal_format, &gl_format, &gl_type))
{
glGetTexImage (GL_TEXTURE_2D,
@@ -193,7 +193,7 @@ gdk_gl_texture_do_download (gpointer texture_,
(download->stride == expected_stride))
{
glReadPixels (0, 0,
- texture->width, texture->height,
+ texture->width, texture->height,
gl_read_format,
gl_read_type,
download->data);
@@ -204,7 +204,7 @@ gdk_gl_texture_do_download (gpointer texture_,
guchar *pixels = g_malloc_n (texture->width * actual_bpp, texture->height);
glReadPixels (0, 0,
- texture->width, texture->height,
+ texture->width, texture->height,
gl_read_format,
gl_read_type,
pixels);
@@ -212,9 +212,11 @@ gdk_gl_texture_do_download (gpointer texture_,
gdk_memory_convert (download->data,
download->stride,
download->format,
+ gdk_color_profile_get_srgb (),
pixels,
texture->width * actual_bpp,
actual_format,
+ gdk_color_profile_get_srgb (),
texture->width,
texture->height);
diff --git a/gdk/gdkmemoryformat.c b/gdk/gdkmemoryformat.c
index 5bd7b228d4..27eedd4bc7 100644
--- a/gdk/gdkmemoryformat.c
+++ b/gdk/gdkmemoryformat.c
@@ -21,6 +21,7 @@
#include "gdkmemoryformatprivate.h"
+#include "gdkcolorprofileprivate.h"
#include "gsk/gl/fp16private.h"
#include <epoxy/gl.h>
@@ -513,14 +514,17 @@ void
gdk_memory_convert (guchar *dest_data,
gsize dest_stride,
GdkMemoryFormat dest_format,
+ GdkColorProfile *dest_profile,
const guchar *src_data,
gsize src_stride,
GdkMemoryFormat src_format,
+ GdkColorProfile *src_profile,
gsize width,
gsize height)
{
const GdkMemoryFormatDescription *dest_desc = &memory_formats[dest_format];
const GdkMemoryFormatDescription *src_desc = &memory_formats[src_format];
+ cmsHTRANSFORM transform;
float *tmp;
gsize y;
void (*func) (guchar *, const guchar *, gsize) = NULL;
@@ -578,17 +582,46 @@ gdk_memory_convert (guchar *dest_data,
tmp = g_new (float, width * 4);
+ if (gdk_color_profile_equal (src_profile, dest_profile))
+ {
+ transform = NULL;
+ }
+ else
+ {
+ transform = cmsCreateTransform (gdk_color_profile_get_lcms_profile (src_profile),
+ TYPE_RGBA_FLT,
+ gdk_color_profile_get_lcms_profile (dest_profile),
+ TYPE_RGBA_FLT,
+ INTENT_PERCEPTUAL,
+ cmsFLAGS_COPY_ALPHA);
+ }
+
for (y = 0; y < height; y++)
{
src_desc->to_float (tmp, src_data, width);
- if (src_desc->alpha == GDK_MEMORY_ALPHA_PREMULTIPLIED && dest_desc->alpha == GDK_MEMORY_ALPHA_STRAIGHT)
- unpremultiply (tmp, width);
- else if (src_desc->alpha == GDK_MEMORY_ALPHA_STRAIGHT && dest_desc->alpha != GDK_MEMORY_ALPHA_STRAIGHT)
- premultiply (tmp, width);
+ if (transform)
+ {
+ if (src_desc->alpha == GDK_MEMORY_ALPHA_PREMULTIPLIED)
+ unpremultiply (tmp, width);
+ cmsDoTransform (transform,
+ tmp,
+ tmp,
+ width);
+ if (dest_desc->alpha != GDK_MEMORY_ALPHA_STRAIGHT)
+ premultiply (tmp, width);
+ }
+ else
+ {
+ if (src_desc->alpha == GDK_MEMORY_ALPHA_PREMULTIPLIED && dest_desc->alpha ==
GDK_MEMORY_ALPHA_STRAIGHT)
+ unpremultiply (tmp, width);
+ else if (src_desc->alpha == GDK_MEMORY_ALPHA_STRAIGHT && dest_desc->alpha !=
GDK_MEMORY_ALPHA_STRAIGHT)
+ premultiply (tmp, width);
+ }
dest_desc->from_float (dest_data, tmp, width);
src_data += src_stride;
dest_data += dest_stride;
}
g_free (tmp);
+ g_clear_pointer (&transform, cmsDeleteTransform);
}
diff --git a/gdk/gdkmemoryformatprivate.h b/gdk/gdkmemoryformatprivate.h
index 3618852f02..46c9575f8e 100644
--- a/gdk/gdkmemoryformatprivate.h
+++ b/gdk/gdkmemoryformatprivate.h
@@ -21,6 +21,7 @@
#define __GDK_MEMORY_CONVERT_PRIVATE_H__
#include "gdkenums.h"
+#include "gdkcolorprofile.h"
G_BEGIN_DECLS
@@ -43,9 +44,11 @@ gboolean gdk_memory_format_gl_format (GdkMemoryFormat
void gdk_memory_convert (guchar *dest_data,
gsize dest_stride,
GdkMemoryFormat dest_format,
+ GdkColorProfile *dest_profile,
const guchar *src_data,
gsize src_stride,
GdkMemoryFormat src_format,
+ GdkColorProfile *src_profile,
gsize width,
gsize height);
diff --git a/gdk/gdkmemorytexture.c b/gdk/gdkmemorytexture.c
index 2bf9fb3a27..61f72a53e0 100644
--- a/gdk/gdkmemorytexture.c
+++ b/gdk/gdkmemorytexture.c
@@ -66,9 +66,11 @@ gdk_memory_texture_download (GdkTexture *texture,
gdk_memory_convert (data, stride,
format,
+ gdk_color_profile_get_srgb (),
(guchar *) g_bytes_get_data (self->bytes, NULL),
self->stride,
texture->format,
+ gdk_texture_get_color_profile (texture),
gdk_texture_get_width (texture),
gdk_texture_get_height (texture));
}
diff --git a/gsk/gl/gskglglyphlibrary.c b/gsk/gl/gskglglyphlibrary.c
index 58e34bc938..ae36915323 100644
--- a/gsk/gl/gskglglyphlibrary.c
+++ b/gsk/gl/gskglglyphlibrary.c
@@ -284,9 +284,11 @@ gsk_gl_glyph_library_upload_glyph (GskGLGlyphLibrary *self,
gdk_memory_convert (pixel_data,
width * 4,
GDK_MEMORY_R8G8B8A8_PREMULTIPLIED,
+ gdk_color_profile_get_srgb (),
cairo_image_surface_get_data (surface),
width * 4,
GDK_MEMORY_DEFAULT,
+ gdk_color_profile_get_srgb (),
width, height);
gl_format = GL_RGBA;
gl_type = GL_UNSIGNED_BYTE;
diff --git a/gsk/gl/gskgliconlibrary.c b/gsk/gl/gskgliconlibrary.c
index f4686fd877..ffc934de76 100644
--- a/gsk/gl/gskgliconlibrary.c
+++ b/gsk/gl/gskgliconlibrary.c
@@ -116,8 +116,11 @@ gsk_gl_icon_library_add (GskGLIconLibrary *self,
pixel_data = free_data = g_malloc (width * height * 4);
gdk_memory_convert (pixel_data, width * 4,
GDK_MEMORY_R8G8B8A8_PREMULTIPLIED,
+ gdk_color_profile_get_srgb (),
surface_data, cairo_image_surface_get_stride (surface),
- GDK_MEMORY_DEFAULT, width, height);
+ GDK_MEMORY_DEFAULT,
+ gdk_color_profile_get_srgb (),
+ width, height);
gl_format = GL_RGBA;
gl_type = GL_UNSIGNED_BYTE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]