[gimp] plug-ins: robuster tests for image types and minor syntax fixes.



commit 73fbb166b3a824caa2e4cf680cd6e03a36219772
Author: Jehan <jehan girinstud io>
Date:   Sun Mar 4 16:16:23 2018 +0100

    plug-ins: robuster tests for image types and minor syntax fixes.
    
    Rather than just assuming all non-gray images are RGB, do a bit more
    robust check and reject unknown formats. Indeed even though I see we
    took care of YUV, e-YCC and CMYK images above (and normally either
    converted them to RGB or already exited with an error), I can see that
    the OpenJPEG library could still return OPJ_CLRSPC_UNKNOWN or
    OPJ_CLRSPC_UNSPECIFIED. Let's be thorough and not assume we got a SRGB
    here.
    Also add the alpha-variant tests inside their parent image type
    respective test. This should not change anything by any logics, but
    let's not leave anything for chance to strike us.
    
    Finally minor coding style fixes:
    - Add a space before "if|for" and parenthese.
    - Remove some spaces after parentheses.
    - Get rid of 2 trailing whitespaces.
    - Align function call parameters, declarations, assignments…

 plug-ins/common/file-jp2-load.c |   45 ++++++++++++++++++++------------------
 1 files changed, 24 insertions(+), 21 deletions(-)
---
diff --git a/plug-ins/common/file-jp2-load.c b/plug-ins/common/file-jp2-load.c
index a6a3b1a..6bf172a 100644
--- a/plug-ins/common/file-jp2-load.c
+++ b/plug-ins/common/file-jp2-load.c
@@ -913,26 +913,30 @@ load_image (const gchar  *filename,
         }
     }
 
-  if(image->color_space == OPJ_CLRSPC_GRAY)
+  num_components = image->numcomps;
+
+  if (image->color_space == OPJ_CLRSPC_GRAY)
     {
-      base_type = GIMP_GRAY;
+      base_type  = GIMP_GRAY;
       image_type = GIMP_GRAY_IMAGE;
+
+      if (num_components == 2)
+        image_type = GIMP_GRAYA_IMAGE;
     }
-  else
+  else if (image->color_space == OPJ_CLRSPC_SRGB)
     {
-      base_type = GIMP_RGB;
+      base_type  = GIMP_RGB;
       image_type = GIMP_RGB_IMAGE;
-    }
 
-  num_components = image->numcomps;
-
-  if(num_components == 2)
-    {
-      image_type = GIMP_GRAYA_IMAGE;
+      if (num_components == 4)
+        image_type = GIMP_RGBA_IMAGE;
     }
-  else if(num_components == 4)
+  else
     {
-      image_type = GIMP_RGBA_IMAGE;
+      g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+                   _("Couldn't decode JP2 image in '%s'."),
+                   gimp_filename_to_utf8 (filename));
+      goto out;
     }
 
   /* FIXME */
@@ -963,35 +967,34 @@ load_image (const gchar  *filename,
 
   for (i = 0; i < height; i++)
     {
-      for( j = 0; j < num_components; j++)
+      for (j = 0; j < num_components; j++)
         {
-          const int channel_prec = 8;
-
+          const int  channel_prec   = 8;
           OPJ_UINT32 component_prec = image->comps[j].prec;
 
-          if(component_prec >= channel_prec)
+          if (component_prec >= channel_prec)
             {
               int shift = component_prec - channel_prec;
 
-              for( k = 0; k < width; k++)
+              for (k = 0; k < width; k++)
                 {
-                  pixels[k * num_components + j] = image->comps[j].data[i * width + k] >> shift; 
+                  pixels[k * num_components + j] = image->comps[j].data[i * width + k] >> shift;
                 }
             }
           else
             {
               int mult = 1 << (channel_prec - component_prec);
 
-              for( k = 0; k < width; k++)
+              for (k = 0; k < width; k++)
                 {
-                  pixels[k* num_components + j] = image->comps[j].data[i * width + k ] * mult; 
+                  pixels[k * num_components + j] = image->comps[j].data[i * width + k ] * mult;
                 }
 
             }
         }
 
         gegl_buffer_set (buffer, GEGL_RECTANGLE (0, i, width, 1), 0,
-                       NULL, pixels, GEGL_AUTO_ROWSTRIDE);
+                         NULL, pixels, GEGL_AUTO_ROWSTRIDE);
     }
 
 #if 0


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