[gtk/texture-serialize-tiff] gsk: Serialize float textures as tiff




commit dd16d7c4c86a371246010c2c920b1762416c9af2
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue May 10 15:49:44 2022 -0400

    gsk: Serialize float textures as tiff
    
    Otherwise, we lose precision when converting them
    to 16bit integers.

 gsk/gskrendernodeparser.c | 41 ++++++++++++++++++++++++++++++++++++-----
 1 file changed, 36 insertions(+), 5 deletions(-)
---
diff --git a/gsk/gskrendernodeparser.c b/gsk/gskrendernodeparser.c
index 11d5e61d70..b5f703bd79 100644
--- a/gsk/gskrendernodeparser.c
+++ b/gsk/gskrendernodeparser.c
@@ -1102,7 +1102,7 @@ parse_conic_gradient_node (GtkCssParser *parser)
       g_array_append_val (stops, to);
     }
 
-  result = gsk_conic_gradient_node_new (&bounds, &center, rotation, 
+  result = gsk_conic_gradient_node_new (&bounds, &center, rotation,
                                         (GskColorStop *) stops->data, stops->len);
 
   g_array_free (stops, TRUE);
@@ -1388,7 +1388,7 @@ parse_cairo_node (GtkCssParser *parser)
   parse_declarations (parser, declarations, G_N_ELEMENTS(declarations));
 
   node = gsk_cairo_node_new (&bounds);
-  
+
   if (surface != NULL)
     {
       cairo_t *cr = gsk_cairo_node_get_draw_context (node);
@@ -2697,10 +2697,41 @@ render_node_print (Printer       *p,
         start_node (p, "texture");
         append_rect_param (p, "bounds", &node->bounds);
 
-        bytes = gdk_texture_save_to_png_bytes (texture);
-
         _indent (p);
-        g_string_append (p->str, "texture: url(\"data:image/png;base64,");
+
+        switch (gdk_texture_get_format (texture))
+          {
+          case GDK_MEMORY_B8G8R8A8_PREMULTIPLIED:
+          case GDK_MEMORY_A8R8G8B8_PREMULTIPLIED:
+          case GDK_MEMORY_R8G8B8A8_PREMULTIPLIED:
+          case GDK_MEMORY_B8G8R8A8:
+          case GDK_MEMORY_A8R8G8B8:
+          case GDK_MEMORY_R8G8B8A8:
+          case GDK_MEMORY_A8B8G8R8:
+          case GDK_MEMORY_R8G8B8:
+          case GDK_MEMORY_B8G8R8:
+          case GDK_MEMORY_R16G16B16:
+          case GDK_MEMORY_R16G16B16A16_PREMULTIPLIED:
+          case GDK_MEMORY_R16G16B16A16:
+            bytes = gdk_texture_save_to_png_bytes (texture);
+            g_string_append (p->str, "texture: url(\"data:image/png;base64,");
+            break;
+
+          case GDK_MEMORY_R16G16B16_FLOAT:
+          case GDK_MEMORY_R16G16B16A16_FLOAT_PREMULTIPLIED:
+          case GDK_MEMORY_R16G16B16A16_FLOAT:
+          case GDK_MEMORY_R32G32B32_FLOAT:
+          case GDK_MEMORY_R32G32B32A32_FLOAT_PREMULTIPLIED:
+          case GDK_MEMORY_R32G32B32A32_FLOAT:
+            bytes = gdk_texture_save_to_tiff_bytes (texture);
+            g_string_append (p->str, "texture: url(\"data:image/tiff;base64,");
+            break;
+
+          case GDK_MEMORY_N_FORMATS:
+          default:
+            g_assert_not_reached ();
+          }
+
         b64 = base64_encode_with_linebreaks (g_bytes_get_data (bytes, NULL),
                                              g_bytes_get_size (bytes));
         append_escaping_newlines (p->str, b64);


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