[gtk/wip/otte/colorspace: 14/19] memorytexture: Add colorspace argument to from_texture()




commit ca2e3edd549c85b86ca385d5cc47eaea9aa6ea94
Author: Benjamin Otte <otte redhat com>
Date:   Sun Oct 17 06:52:16 2021 +0200

    memorytexture: Add colorspace argument to from_texture()
    
    Make gdk_memory_texture_from_texture() take a colorspace instead of
    implicitly using sRGB.

 gdk/gdkgltexture.c            |  3 ++-
 gdk/gdkmemorytexture.c        | 16 +++++++++-------
 gdk/gdkmemorytextureprivate.h |  3 ++-
 gdk/gdkpixbuf-drawable.c      |  4 +++-
 gdk/loaders/gdkpng.c          |  4 ++--
 gdk/loaders/gdktiff.c         |  5 ++++-
 gsk/gl/gskglcommandqueue.c    |  2 +-
 gsk/gl/gskgldriver.c          | 13 ++++++-------
 8 files changed, 29 insertions(+), 21 deletions(-)
---
diff --git a/gdk/gdkgltexture.c b/gdk/gdkgltexture.c
index fd77cb9293..002b2bf906 100644
--- a/gdk/gdkgltexture.c
+++ b/gdk/gdkgltexture.c
@@ -293,7 +293,8 @@ gdk_gl_texture_release (GdkGLTexture *self)
 
   texture = GDK_TEXTURE (self);
   self->saved = GDK_TEXTURE (gdk_memory_texture_from_texture (texture,
-                                                              gdk_texture_get_format (texture)));
+                                                              gdk_texture_get_format (texture),
+                                                              gdk_texture_get_color_space (texture)));
 
   if (self->destroy)
     {
diff --git a/gdk/gdkmemorytexture.c b/gdk/gdkmemorytexture.c
index 0d4700886b..9b5e72eed1 100644
--- a/gdk/gdkmemorytexture.c
+++ b/gdk/gdkmemorytexture.c
@@ -250,7 +250,8 @@ gdk_memory_texture_new_subtexture (GdkMemoryTexture  *source,
 
 GdkMemoryTexture *
 gdk_memory_texture_from_texture (GdkTexture      *texture,
-                                 GdkMemoryFormat  format)
+                                 GdkMemoryFormat  format,
+                                 GdkColorSpace   *color_space)
 {
   GdkTexture *result;
   GBytes *bytes;
@@ -270,13 +271,14 @@ gdk_memory_texture_from_texture (GdkTexture      *texture,
   stride = texture->width * gdk_memory_format_bytes_per_pixel (format);
   data = g_malloc_n (stride, texture->height);
 
-  gdk_texture_do_download (texture, format, gdk_color_space_get_srgb (), data, stride);
+  gdk_texture_do_download (texture, format, color_space, data, stride);
   bytes = g_bytes_new_take (data, stride);
-  result = gdk_memory_texture_new (texture->width,
-                                   texture->height,
-                                   format,
-                                   bytes,
-                                   stride);
+  result = gdk_memory_texture_new_with_color_space (texture->width,
+                                                    texture->height,
+                                                    format,
+                                                    color_space,
+                                                    bytes,
+                                                    stride);
   g_bytes_unref (bytes);
 
   return GDK_MEMORY_TEXTURE (result);
diff --git a/gdk/gdkmemorytextureprivate.h b/gdk/gdkmemorytextureprivate.h
index 57dafd567b..e7175bf821 100644
--- a/gdk/gdkmemorytextureprivate.h
+++ b/gdk/gdkmemorytextureprivate.h
@@ -30,7 +30,8 @@ G_BEGIN_DECLS
 #define GDK_MEMORY_GDK_PIXBUF_ALPHA GDK_MEMORY_R8G8B8A8
 
 GdkMemoryTexture *      gdk_memory_texture_from_texture     (GdkTexture        *texture,
-                                                             GdkMemoryFormat    format);
+                                                             GdkMemoryFormat    format,
+                                                             GdkColorSpace     *color_space);
 GdkTexture *            gdk_memory_texture_new_subtexture   (GdkMemoryTexture  *texture,
                                                              int                x,
                                                              int                y,
diff --git a/gdk/gdkpixbuf-drawable.c b/gdk/gdkpixbuf-drawable.c
index 15b886357e..a079e20d3f 100644
--- a/gdk/gdkpixbuf-drawable.c
+++ b/gdk/gdkpixbuf-drawable.c
@@ -24,6 +24,7 @@
 
 #include "gdkpixbuf.h"
 
+#include "gdkcolorspace.h"
 #include "gdkmemoryformatprivate.h"
 #include "gdkmemorytextureprivate.h"
 #include "gdksurface.h"
@@ -245,7 +246,8 @@ gdk_pixbuf_get_from_texture (GdkTexture *texture)
 
   memtex = gdk_memory_texture_from_texture (texture,
                                             alpha ? GDK_MEMORY_GDK_PIXBUF_ALPHA
-                                                  : GDK_MEMORY_GDK_PIXBUF_OPAQUE);
+                                                  : GDK_MEMORY_GDK_PIXBUF_OPAQUE,
+                                            gdk_color_space_get_srgb ());
 
   return gdk_pixbuf_new_from_data (gdk_memory_texture_get_data (memtex),
                                    GDK_COLORSPACE_RGB,
diff --git a/gdk/loaders/gdkpng.c b/gdk/loaders/gdkpng.c
index 11ed7e4ef9..bd356418a0 100644
--- a/gdk/loaders/gdkpng.c
+++ b/gdk/loaders/gdkpng.c
@@ -19,13 +19,13 @@
 
 #include "gdkpngprivate.h"
 
+#include "gdkcolorspace.h"
 #include "gdkintl.h"
 #include "gdkmemoryformatprivate.h"
 #include "gdkmemorytextureprivate.h"
 #include "gdkprofilerprivate.h"
 #include "gdktexture.h"
 #include "gdktextureprivate.h"
-#include "gsk/gl/fp16private.h"
 #include <png.h>
 #include <stdio.h>
 
@@ -393,7 +393,7 @@ gdk_save_png (GdkTexture *texture)
       return NULL;
     }
 
-  memtex = gdk_memory_texture_from_texture (texture, format);
+  memtex = gdk_memory_texture_from_texture (texture, format, gdk_color_space_get_srgb ());
 
   png_set_write_fn (png, &io, png_write_func, png_flush_func);
 
diff --git a/gdk/loaders/gdktiff.c b/gdk/loaders/gdktiff.c
index ec68b7b8fa..a0e81246b6 100644
--- a/gdk/loaders/gdktiff.c
+++ b/gdk/loaders/gdktiff.c
@@ -19,6 +19,7 @@
 
 #include "gdktiffprivate.h"
 
+#include "gdkcolorspace.h"
 #include "gdkintl.h"
 #include "gdkmemoryformatprivate.h"
 #include "gdkmemorytextureprivate.h"
@@ -292,7 +293,9 @@ gdk_save_tiff (GdkTexture *texture)
   TIFFSetField (tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
   TIFFSetField (tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
 
-  memtex = gdk_memory_texture_from_texture (texture, fdata->format);
+  memtex = gdk_memory_texture_from_texture (texture,
+                                            fdata->format,
+                                            gdk_color_space_get_srgb ());
   data = gdk_memory_texture_get_data (memtex);
   stride = gdk_memory_texture_get_stride (memtex);
 
diff --git a/gsk/gl/gskglcommandqueue.c b/gsk/gl/gskglcommandqueue.c
index fa8ac1defb..17006767dd 100644
--- a/gsk/gl/gskglcommandqueue.c
+++ b/gsk/gl/gskglcommandqueue.c
@@ -1381,7 +1381,7 @@ gsk_gl_command_queue_do_upload_texture (GskGLCommandQueue *self,
         }
     }
 
-  memtex = gdk_memory_texture_from_texture (texture, data_format);
+  memtex = gdk_memory_texture_from_texture (texture, data_format, gdk_color_space_get_srgb ());
   data = gdk_memory_texture_get_data (memtex);
   stride = gdk_memory_texture_get_stride (memtex);
   bpp = gdk_memory_format_bytes_per_pixel (data_format);
diff --git a/gsk/gl/gskgldriver.c b/gsk/gl/gskgldriver.c
index 327dea93ff..8bbebb1376 100644
--- a/gsk/gl/gskgldriver.c
+++ b/gsk/gl/gskgldriver.c
@@ -774,10 +774,6 @@ gsk_gl_driver_load_texture (GskGLDriver *self,
           /* A GL texture from the same GL context is a simple task... */
           return gdk_gl_texture_get_id (gl_texture);
         }
-      else
-        {
-          downloaded_texture = gdk_memory_texture_from_texture (texture, gdk_texture_get_format (texture));
-        }
     }
   else
     {
@@ -786,10 +782,12 @@ gsk_gl_driver_load_texture (GskGLDriver *self,
           if (t->min_filter == min_filter && t->mag_filter == mag_filter)
             return t->texture_id;
         }
-
-      downloaded_texture = gdk_memory_texture_from_texture (texture, gdk_texture_get_format (texture));
     }
 
+  downloaded_texture = gdk_memory_texture_from_texture (texture,
+                                                        gdk_texture_get_format (texture),
+                                                        gdk_texture_get_color_space (texture));
+
   /* The download_texture() call may have switched the GL context. Make sure
    * the right context is at work again. */
   gdk_gl_context_make_current (context);
@@ -1251,7 +1249,8 @@ gsk_gl_driver_add_texture_slices (GskGLDriver        *self,
   n_slices = cols * rows;
   slices = g_new0 (GskGLTextureSlice, n_slices);
   memtex = gdk_memory_texture_from_texture (texture,
-                                            gdk_texture_get_format (texture));
+                                            gdk_texture_get_format (texture),
+                                            gdk_texture_get_color_space (texture));
 
   for (guint col = 0; col < cols; col ++)
     {


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