[gimp] plug-ins: space invade file-jpeg



commit 4c41f185e25076e4b7b9af262d3bda4c2f4821f2
Author: Michael Natterer <mitch gimp org>
Date:   Tue Jun 25 14:05:30 2019 +0200

    plug-ins: space invade file-jpeg
    
    Use the drawable's space for the load/save formats to avoid unwanted
    color conversions. Also cleaned up the loading code a bit, it was
    doing weird duplicated stuff for the preview and !preview cases.

 plug-ins/file-jpeg/jpeg-load.c | 77 ++++++++++++++++++++----------------------
 plug-ins/file-jpeg/jpeg-save.c |  3 ++
 2 files changed, 39 insertions(+), 41 deletions(-)
---
diff --git a/plug-ins/file-jpeg/jpeg-load.c b/plug-ins/file-jpeg/jpeg-load.c
index 69298a2e33..c3e16b7558 100644
--- a/plug-ins/file-jpeg/jpeg-load.c
+++ b/plug-ins/file-jpeg/jpeg-load.c
@@ -62,27 +62,28 @@ load_image (const gchar  *filename,
             gboolean     *resolution_loaded,
             GError      **error)
 {
-  gint32 volatile  image_ID;
-  gint32           layer_ID;
+  gint32 volatile    image_ID;
+  gint32             layer_ID;
   struct jpeg_decompress_struct cinfo;
   struct my_error_mgr           jerr;
   jpeg_saved_marker_ptr         marker;
-  FILE            *infile;
-  guchar          *buf;
-  guchar         **rowbuf;
-  GimpImageBaseType image_type;
-  GimpImageType    layer_type;
-  GeglBuffer      *buffer = NULL;
-  const Babl      *format;
-  gint             tile_height;
-  gint             i;
-  cmsHTRANSFORM    cmyk_transform = NULL;
+  FILE              *infile;
+  guchar            *buf;
+  guchar           **rowbuf;
+  GimpImageBaseType  image_type;
+  GimpImageType      layer_type;
+  GeglBuffer        *buffer = NULL;
+  const Babl        *format;
+  const gchar       *layer_name = NULL;
+  gint               tile_height;
+  gint               i;
+  cmsHTRANSFORM      cmyk_transform = NULL;
 
   /* We set up the normal JPEG error routines. */
   cinfo.err = jpeg_std_error (&jerr.pub);
   jerr.pub.error_exit = my_error_exit;
 
-  if (!preview)
+  if (! preview)
     {
       jerr.pub.output_message = my_output_message;
 
@@ -212,10 +213,18 @@ load_image (const gchar  *filename,
 
   if (preview)
     {
+      layer_name = _("JPEG preview");
+
       image_ID = preview_image_ID;
     }
   else
     {
+      GString *comment_buffer = NULL;
+      guint8  *icc_data       = NULL;
+      guint    icc_length     = 0;
+
+      layer_name = _("Background");
+
       image_ID = gimp_image_new_with_precision (cinfo.output_width,
                                                 cinfo.output_height,
                                                 image_type,
@@ -223,33 +232,6 @@ load_image (const gchar  *filename,
 
       gimp_image_undo_disable (image_ID);
       gimp_image_set_filename (image_ID, filename);
-    }
-
-  if (preview)
-    {
-      preview_layer_ID = gimp_layer_new (preview_image_ID, _("JPEG preview"),
-                                         cinfo.output_width,
-                                         cinfo.output_height,
-                                         layer_type,
-                                         100,
-                                         gimp_image_get_default_new_layer_mode (preview_image_ID));
-      layer_ID = preview_layer_ID;
-    }
-  else
-    {
-      layer_ID = gimp_layer_new (image_ID, _("Background"),
-                                 cinfo.output_width,
-                                 cinfo.output_height,
-                                 layer_type,
-                                 100,
-                                 gimp_image_get_default_new_layer_mode (image_ID));
-    }
-
-  if (! preview)
-    {
-      GString *comment_buffer = NULL;
-      guint8  *icc_data       = NULL;
-      guint    icc_length     = 0;
 
       /* Step 5.0: save the original JPEG settings in a parasite */
       jpeg_detect_original_settings (&cinfo, image_ID);
@@ -339,6 +321,16 @@ load_image (const gchar  *filename,
        */
     }
 
+  layer_ID = gimp_layer_new (image_ID, layer_name,
+                             cinfo.output_width,
+                             cinfo.output_height,
+                             layer_type,
+                             100,
+                             gimp_image_get_default_new_layer_mode (image_ID));
+
+  if (preview)
+    preview_layer_ID = layer_ID;
+
   /* Step 6: while (scan lines remain to be read) */
   /*           jpeg_read_scanlines(...); */
 
@@ -347,7 +339,10 @@ load_image (const gchar  *filename,
    */
 
   buffer = gimp_drawable_get_buffer (layer_ID);
-  format = babl_format (image_type == GIMP_RGB ? "R'G'B' u8" : "Y' u8");
+
+  format = babl_format_with_space (image_type == GIMP_RGB ?
+                                   "R'G'B' u8" : "Y' u8",
+                                   gimp_drawable_get_format (layer_ID));
 
   while (cinfo.output_scanline < cinfo.output_height)
     {
diff --git a/plug-ins/file-jpeg/jpeg-save.c b/plug-ins/file-jpeg/jpeg-save.c
index a0ca7a7503..a030c73404 100644
--- a/plug-ins/file-jpeg/jpeg-save.c
+++ b/plug-ins/file-jpeg/jpeg-save.c
@@ -429,6 +429,9 @@ save_image (const gchar  *filename,
       return FALSE;
     }
 
+  format = babl_format_with_space (babl_format_get_encoding (format),
+                                   gimp_drawable_get_format (drawable_ID));
+
   /* Step 3: set parameters for compression */
 
   /* First we supply a description of the input image.


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