[gthumb] jpeg reader: use the sRGB profile if the ColorSpace tag is set to sRGB



commit 0eaed6989fb0e3159ab67fb07e14dcd5064dca71
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Tue Jun 27 16:54:01 2017 +0200

    jpeg reader: use the sRGB profile if the ColorSpace tag is set to sRGB

 extensions/cairo_io/cairo-image-surface-jpeg.c |   21 +++++++++++++++----
 gthumb/gth-icc-profile.c                       |   25 ++++++++++++++++++++++++
 gthumb/gth-icc-profile.h                       |    1 +
 3 files changed, 42 insertions(+), 5 deletions(-)
---
diff --git a/extensions/cairo_io/cairo-image-surface-jpeg.c b/extensions/cairo_io/cairo-image-surface-jpeg.c
index a500adb..f61d5e0 100644
--- a/extensions/cairo_io/cairo-image-surface-jpeg.c
+++ b/extensions/cairo_io/cairo-image-surface-jpeg.c
@@ -200,7 +200,7 @@ _cairo_image_surface_create_from_jpeg (GInputStream  *istream,
        _jpeg_info_data_init (&jpeg_info);
        info_flags = _JPEG_INFO_EXIF_ORIENTATION;
 #if HAVE_LCMS2
-       info_flags |= _JPEG_INFO_ICC_PROFILE;
+       info_flags |= _JPEG_INFO_EXIF_COLOR_SPACE | _JPEG_INFO_ICC_PROFILE;
 #endif
        _jpeg_info_get_from_buffer (in_buffer, in_buffer_size, info_flags, &jpeg_info);
        if (jpeg_info.valid & _JPEG_INFO_EXIF_ORIENTATION)
@@ -208,10 +208,21 @@ _cairo_image_surface_create_from_jpeg (GInputStream  *istream,
        else
                orientation = GTH_TRANSFORM_NONE;
 #if HAVE_LCMS2
-       if (jpeg_info.valid & _JPEG_INFO_ICC_PROFILE) {
-               GthICCProfile *profile = gth_icc_profile_new (GTH_ICC_PROFILE_ID_UNKNOWN, 
cmsOpenProfileFromMem (jpeg_info.icc_data, jpeg_info.icc_data_size));
-               gth_image_set_icc_profile (image, profile);
-               g_object_unref (profile);
+       {
+               GthICCProfile *profile = NULL;
+
+               if (jpeg_info.valid & _JPEG_INFO_ICC_PROFILE) {
+                       profile = gth_icc_profile_new (GTH_ICC_PROFILE_ID_UNKNOWN, cmsOpenProfileFromMem 
(jpeg_info.icc_data, jpeg_info.icc_data_size));
+               }
+               else if (jpeg_info.valid & _JPEG_INFO_EXIF_COLOR_SPACE) {
+                       if (jpeg_info.color_space == GTH_COLOR_SPACE_SRGB)
+                               profile = gth_icc_profile_new_srgb ();
+               }
+
+               if (profile != NULL) {
+                       gth_image_set_icc_profile (image, profile);
+                       g_object_unref (profile);
+               }
        }
 #endif
        _jpeg_info_data_dispose (&jpeg_info);
diff --git a/gthumb/gth-icc-profile.c b/gthumb/gth-icc-profile.c
index 637e041..13323e2 100644
--- a/gthumb/gth-icc-profile.c
+++ b/gthumb/gth-icc-profile.c
@@ -169,6 +169,31 @@ gth_icc_profile_new (const char    *id,
 }
 
 
+GthICCProfile *
+gth_icc_profile_new_srgb (void)
+{
+#ifdef HAVE_LCMS2
+
+       char          *id;
+       GthCMSProfile  cmd_profile;
+       GthICCProfile *icc_profile;
+
+       id = g_strdup ("standard://srgb");
+       cmd_profile = (GthCMSProfile) cmsCreate_sRGBProfile ();
+       icc_profile = gth_icc_profile_new (id, cmd_profile);
+
+       g_free (id);
+
+       return icc_profile;
+
+#else
+
+       return NULL;
+
+#endif
+}
+
+
 const char *
 gth_icc_profile_get_id (GthICCProfile *self)
 {
diff --git a/gthumb/gth-icc-profile.h b/gthumb/gth-icc-profile.h
index d7e759f..430ff09 100644
--- a/gthumb/gth-icc-profile.h
+++ b/gthumb/gth-icc-profile.h
@@ -79,6 +79,7 @@ void                  gth_cms_transform_free          (GthCMSTransform  transform);
 GType                  gth_icc_profile_get_type        (void);
 GthICCProfile *                gth_icc_profile_new             (const char      *id,
                                                         GthCMSProfile    profile);
+GthICCProfile *                gth_icc_profile_new_srgb        (void);
 const char *           gth_icc_profile_get_id          (GthICCProfile   *icc_profile);
 gboolean                gth_icc_profile_id_is_unknown   (const char      *id);
 GthCMSProfile          gth_icc_profile_get_profile     (GthICCProfile   *icc_profile);


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