[gtk/matthiasc/color-profile-rebased: 9/47] jpeg: Add color space support
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/matthiasc/color-profile-rebased: 9/47] jpeg: Add color space support
- Date: Wed, 28 Sep 2022 19:07:14 +0000 (UTC)
commit b9b0ca14d3adb5e16fa50510e3be04f3500bfd9e
Author: Benjamin Otte <otte redhat com>
Date: Thu Sep 23 03:27:22 2021 +0200
jpeg: Add color space support
gdk/loaders/gdkjpeg.c | 44 +++++++++++++++++++++++++++++++++++++++-----
1 file changed, 39 insertions(+), 5 deletions(-)
---
diff --git a/gdk/loaders/gdkjpeg.c b/gdk/loaders/gdkjpeg.c
index ba6731ac11..0179baadf9 100644
--- a/gdk/loaders/gdkjpeg.c
+++ b/gdk/loaders/gdkjpeg.c
@@ -22,8 +22,9 @@
#include "gdkjpegprivate.h"
#include <glib/gi18n-lib.h>
-#include "gdktexture.h"
+#include "gdkcolorspace.h"
#include "gdkmemorytextureprivate.h"
+#include "gdktexture.h"
#include "gdkprofilerprivate.h"
@@ -143,9 +144,12 @@ gdk_load_jpeg (GBytes *input_bytes,
guint width, height, stride;
unsigned char *data;
unsigned char *row[1];
+ JOCTET *icc_data;
+ unsigned int icc_len;
GBytes *bytes;
GdkTexture *texture;
GdkMemoryFormat format;
+ GdkColorSpace *color_space;
G_GNUC_UNUSED guint64 before = GDK_PROFILER_CURRENT_TIME;
info.err = jpeg_std_error (&jerr.pub);
@@ -167,6 +171,9 @@ gdk_load_jpeg (GBytes *input_bytes,
g_bytes_get_data (input_bytes, NULL),
g_bytes_get_size (input_bytes));
+ /* save color space */
+ jpeg_save_markers (&info, JPEG_APP0 + 2, 0xFFFF);
+
jpeg_read_header (&info, TRUE);
jpeg_start_decompress (&info);
@@ -224,19 +231,34 @@ gdk_load_jpeg (GBytes *input_bytes,
g_assert_not_reached ();
}
+ if (jpeg_read_icc_profile (&info, &icc_data, &icc_len))
+ {
+ GBytes *icc_bytes = g_bytes_new_with_free_func (icc_data, icc_len, free, icc_data);
+ color_space = gdk_color_space_new_from_icc_profile (icc_bytes, error);
+ g_bytes_unref (icc_bytes);
+ }
+ else
+ color_space = g_object_ref (gdk_color_space_get_srgb ());
+
jpeg_finish_decompress (&info);
jpeg_destroy_decompress (&info);
bytes = g_bytes_new_take (data, stride * height);
- texture = gdk_memory_texture_new (width, height,
- format,
- bytes, stride);
+ if (color_space)
+ {
+ texture = gdk_memory_texture_new_with_color_space (width, height,
+ format,
+ color_space,
+ bytes, stride);
+ }
+ else
+ texture = NULL;
g_bytes_unref (bytes);
gdk_profiler_end_mark (before, "jpeg load", NULL);
-
+
return texture;
}
@@ -254,9 +276,12 @@ gdk_save_jpeg (GdkTexture *texture)
gsize texstride;
guchar *row;
int width, height;
+ GdkColorSpace *color_space;
+ GBytes *bytes;
width = gdk_texture_get_width (texture);
height = gdk_texture_get_height (texture);
+ color_space = gdk_texture_get_color_space (texture);
info.err = jpeg_std_error (&jerr.pub);
jerr.pub.error_exit = fatal_error_handler;
@@ -294,6 +319,15 @@ gdk_save_jpeg (GdkTexture *texture)
jpeg_start_compress (&info, TRUE);
+ bytes = gdk_color_space_save_to_icc_profile (color_space, NULL);
+ if (bytes)
+ {
+ jpeg_write_icc_profile (&info,
+ g_bytes_get_data (bytes, NULL),
+ g_bytes_get_size (bytes));
+ g_bytes_unref (bytes);
+ }
+
while (info.next_scanline < info.image_height)
{
row = (guchar *) texdata + info.next_scanline * texstride;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]