[gimp] Bug 792141 - Replace jasper with openjpeg.



commit 53a7c6c3a3b928f097353067e204a22bad742075
Author: Darshan kadu <darsh7807 gmail com>
Date:   Sun Mar 4 11:51:24 2018 +0530

    Bug 792141 - Replace jasper with openjpeg.
    
    Made plug-in support the RGB and grayscale with alpha.
    
    Comment by Jehan: this makes the original branch work finally usable on
    some JPEG 2000 images. Support of the format is not complete yet though
    but at least the port to OpenJPEG is now in usable test.

 plug-ins/common/file-jp2-load.c |   60 +++++++++++++++++++++++++++++++++++++--
 1 files changed, 57 insertions(+), 3 deletions(-)
---
diff --git a/plug-ins/common/file-jp2-load.c b/plug-ins/common/file-jp2-load.c
index 68af294..a6a3b1a 100644
--- a/plug-ins/common/file-jp2-load.c
+++ b/plug-ins/common/file-jp2-load.c
@@ -141,7 +141,7 @@ query (void)
                           load_args, load_return_vals);
 
   gimp_register_magic_load_handler (LOAD_PROC,
-                                    "jp2",
+                                    "jp2,jpc,jpx,j2k,jpf",
                                     "",
                                     "4,string,jP,0,string,\xff\x4f\xff\x51\x00");
 
@@ -913,16 +913,36 @@ load_image (const gchar  *filename,
         }
     }
 
+  if(image->color_space == OPJ_CLRSPC_GRAY)
+    {
+      base_type = GIMP_GRAY;
+      image_type = GIMP_GRAY_IMAGE;
+    }
+  else
+    {
+      base_type = GIMP_RGB;
+      image_type = GIMP_RGB_IMAGE;
+    }
+
   num_components = image->numcomps;
 
+  if(num_components == 2)
+    {
+      image_type = GIMP_GRAYA_IMAGE;
+    }
+  else if(num_components == 4)
+    {
+      image_type = GIMP_RGBA_IMAGE;
+    }
+
   /* FIXME */
-  base_type = GIMP_GRAY;
+/*  base_type = GIMP_GRAY;
   base_type = GIMP_RGB;
   image_type = GIMP_GRAYA_IMAGE;
   image_type = GIMP_GRAY_IMAGE;
   image_type = GIMP_RGBA_IMAGE;
   image_type = GIMP_RGB_IMAGE;
-
+*/
   width = image->comps[0].w;
   height = image->comps[0].h;
 
@@ -940,6 +960,40 @@ load_image (const gchar  *filename,
   buffer = gimp_drawable_get_buffer (layer_ID);
 
   pixels = malloc (width * num_components);
+
+  for (i = 0; i < height; i++)
+    {
+      for( j = 0; j < num_components; j++)
+        {
+          const int channel_prec = 8;
+
+          OPJ_UINT32 component_prec = image->comps[j].prec;
+
+          if(component_prec >= channel_prec)
+            {
+              int shift = component_prec - channel_prec;
+
+              for( k = 0; k < width; k++)
+                {
+                  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++)
+                {
+                  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);
+    }
+
 #if 0
   matrix = jas_matrix_create (1, width);
 


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