[gimp/soc-2013-psd: 7/10] plug-ins: Preliminary 16, 32 bit color PSD proper loading support.



commit 6a25888de1f6e05e64dfa25ee7d1acd65aa44b8c
Author: Simon Lui <simonlui src gnome org>
Date:   Thu Sep 12 00:56:55 2013 -0400

    plug-ins: Preliminary 16, 32 bit color PSD proper loading support.

 plug-ins/file-psd/psd-image-res-load.c |    4 +-
 plug-ins/file-psd/psd-load.c           |  150 +++++++++++++++++++++++---------
 plug-ins/file-psd/psd.h                |   10 +--
 3 files changed, 114 insertions(+), 50 deletions(-)
---
diff --git a/plug-ins/file-psd/psd-image-res-load.c b/plug-ins/file-psd/psd-image-res-load.c
index 3c8acf6..846f79c 100644
--- a/plug-ins/file-psd/psd-image-res-load.c
+++ b/plug-ins/file-psd/psd-image-res-load.c
@@ -1080,6 +1080,7 @@ load_resource_1033 (const PSDimageres  *res_a,
 
   ThumbnailInfo         thumb_info;
   GeglBuffer           *buffer;
+  const Babl           *format;
   gint32                layer_id;
   guchar               *buf;
   guchar               *rgb_buf;
@@ -1161,6 +1162,7 @@ load_resource_1033 (const PSDimageres  *res_a,
                              cinfo.output_height,
                              GIMP_RGB_IMAGE, 100, GIMP_NORMAL_MODE);
   buffer = gimp_drawable_get_buffer (layer_id);
+  format = babl_format("R'G'B'A u8");
 
   /* Step 6: while (scan lines remain to be read) */
   /*           jpeg_read_scanlines(...); */
@@ -1187,7 +1189,7 @@ load_resource_1033 (const PSDimageres  *res_a,
             }
         }
       gegl_buffer_set (buffer, GEGL_RECTANGLE (0, 0, gegl_buffer_get_width (buffer), gegl_buffer_get_height 
(buffer)),
-                      0, NULL, rgb_buf ? rgb_buf : buf, GEGL_AUTO_ROWSTRIDE);
+                      0, format, rgb_buf ? rgb_buf : buf, GEGL_AUTO_ROWSTRIDE);
     }
 
   /* Step 7: Finish decompression */
diff --git a/plug-ins/file-psd/psd-load.c b/plug-ins/file-psd/psd-load.c
index 2c72a89..84da797 100644
--- a/plug-ins/file-psd/psd-load.c
+++ b/plug-ins/file-psd/psd-load.c
@@ -97,15 +97,13 @@ static gint             read_channel_data          (PSDchannel     *channel,
                                                     FILE           *f,
                                                     GError        **error);
 
-static void             convert_16_bit             (const gchar *src,
-                                                    gchar       *dst,
-                                                    guint32      len);
-
 static void             convert_1_bit              (const gchar *src,
                                                     gchar       *dst,
                                                     guint32      rows,
                                                     guint32      columns);
 
+static const Babl*      get_psd_pixel_format       (PSDimage    *img_a);
+
 
 /* Main file load function */
 gint32
@@ -329,13 +327,12 @@ read_header_block (PSDimage  *img_a,
   /* Warnings for format conversions */
   switch (img_a->bps)
     {
+      case 32:
+        IFDBG(3) g_debug ("32 Bit Data");
+        break;
+
       case 16:
         IFDBG(3) g_debug ("16 Bit Data");
-        if (CONVERSION_WARNINGS)
-          g_message (_("Warning:\n"
-                       "The image you are loading has 16 bits per channel. GIMP "
-                       "can only handle 8 bit, so it will be converted for you. "
-                       "Information will be lost because of this conversion."));
         break;
 
       case 8:
@@ -1349,7 +1346,7 @@ add_layers (const gint32  image_id,
               gimp_layer_set_lock_alpha  (layer_id, lyr_a[lidx]->layer_flags.trans_prot);
              buffer = gimp_drawable_get_buffer (layer_id);
              gegl_buffer_set (buffer, GEGL_RECTANGLE (0, 0, gegl_buffer_get_width (buffer), 
gegl_buffer_get_height (buffer)),
-                              0, NULL, pixels, GEGL_AUTO_ROWSTRIDE);
+                              0, get_psd_pixel_format (img_a), pixels, GEGL_AUTO_ROWSTRIDE);
               gimp_item_set_visible (layer_id, lyr_a[lidx]->layer_flags.visible);
               if (lyr_a[lidx]->id)
                 gimp_item_set_tattoo (layer_id, lyr_a[lidx]->id);
@@ -1453,7 +1450,7 @@ add_layers (const gint32  image_id,
                   gimp_layer_add_mask (layer_id, mask_id);
                  buffer = gimp_drawable_get_buffer (mask_id);
                  gegl_buffer_set (buffer, GEGL_RECTANGLE (lm_x, lm_y, lm_w, lm_h), 0,
-                                 NULL, pixels, GEGL_AUTO_ROWSTRIDE);
+                                  get_psd_pixel_format (img_a), pixels, GEGL_AUTO_ROWSTRIDE);
                   g_object_unref (buffer);
                   gimp_layer_set_apply_mask (layer_id,
                     ! lyr_a[lidx]->layer_mask.mask_flags.disabled);
@@ -1630,7 +1627,7 @@ add_merged_image (const gint32  image_id,
       gimp_image_insert_layer (image_id, layer_id, -1, 0);
       buffer = gimp_drawable_get_buffer (layer_id);
       gegl_buffer_set (buffer, GEGL_RECTANGLE (0, 0, gegl_buffer_get_width (buffer), gegl_buffer_get_height 
(buffer)),
-                      0, NULL, pixels, GEGL_AUTO_ROWSTRIDE);
+                      0, get_psd_pixel_format (img_a), pixels, GEGL_AUTO_ROWSTRIDE);
       g_object_unref (buffer);
       g_free (pixels);
     }
@@ -1722,7 +1719,7 @@ add_merged_image (const gint32  image_id,
           gimp_item_set_visible (channel_id, alpha_visible);
          gegl_buffer_set (buffer,
                           GEGL_RECTANGLE (0, 0, gegl_buffer_get_width (buffer), gegl_buffer_get_height 
(buffer)),
-                          0, NULL, pixels, GEGL_AUTO_ROWSTRIDE);
+                          0, get_psd_pixel_format (img_a), pixels, GEGL_AUTO_ROWSTRIDE);
           g_object_unref (buffer);
           g_free (chn_a[cidx].data);
         }
@@ -1906,20 +1903,15 @@ read_channel_data (PSDchannel     *channel,
   /* Convert channel data to GIMP format */
   switch (bps)
     {
-      case 16:
+      case 1:
         channel->data = (gchar *) g_malloc (channel->rows * channel->columns);
-        convert_16_bit (raw_data, channel->data, (channel->rows * channel->columns) << 1);
+        convert_1_bit (raw_data, channel->data, channel->rows, channel->columns);
         break;
 
-      case 8:
-        channel->data = (gchar *) g_malloc (channel->rows * channel->columns);
+      default:
+       channel->data = (gchar *) g_malloc (channel->rows * channel->columns);
         memcpy (channel->data, raw_data, (channel->rows * channel->columns));
         break;
-
-      case 1:
-        channel->data = (gchar *) g_malloc (channel->rows * channel->columns);
-        convert_1_bit (raw_data, channel->data, channel->rows, channel->columns);
-        break;
     }
 
   g_free (raw_data);
@@ -1928,27 +1920,6 @@ read_channel_data (PSDchannel     *channel,
 }
 
 static void
-convert_16_bit (const gchar *src,
-                gchar       *dst,
-                guint32     len)
-{
-/* Convert 16 bit to 8 bit dropping low byte
-*/
-  gint      i;
-
-  IFDBG(3)  g_debug ("Start 16 bit conversion");
-
-  for (i = 0; i < len >> 1; ++i)
-    {
-      *dst = *src;
-      dst++;
-      src += 2;
-    }
-
-  IFDBG(3)  g_debug ("End 16 bit conversion");
-}
-
-static void
 convert_1_bit (const gchar *src,
                gchar       *dst,
                guint32      rows,
@@ -1980,3 +1951,96 @@ convert_1_bit (const gchar *src,
     }
   IFDBG(3)  g_debug ("End 1 bit conversion");
 }
+
+static const Babl*
+get_psd_pixel_format(PSDimage *img_a)
+{
+  const Babl *format;
+
+  switch (get_gimp_image_type (img_a->base_type, img_a->transparency))
+    {
+    case GIMP_GRAY_IMAGE:
+      switch (img_a->bps)
+       {
+        case 32:
+         format = babl_format ("Y' float");
+         break;
+        case 16:
+          format = babl_format ("Y' u16");
+         break;
+        case 8:
+        case 1:
+          format = babl_format ("Y' u8");
+         break;
+        default:
+         return NULL;
+         break;
+       }
+      break;
+
+    case GIMP_GRAYA_IMAGE:
+      switch (img_a->bps)
+       {
+        case 32:
+         format = babl_format ("Y'A float");
+          break;
+        case 16:
+          format = babl_format ("Y'A u16");
+          break;
+        case 8:
+        case 1:
+          format = babl_format ("Y'A u8");
+          break;
+        default:
+         return NULL;
+         break;
+       }
+      break;
+
+    case GIMP_RGB_IMAGE:
+    case GIMP_INDEXED_IMAGE:
+      switch (img_a->bps)
+       {
+        case 32:
+         format = babl_format ("R'G'B' float");
+          break;
+        case 16:
+          format = babl_format ("R'G'B' u16");
+          break;
+        case 8:
+        case 1:
+          format = babl_format ("R'G'B' u8");
+          break;
+        default:
+         return NULL;
+         break;
+       }
+      break;
+
+    case GIMP_RGBA_IMAGE:
+    case GIMP_INDEXEDA_IMAGE:
+      switch (img_a->bps)
+       {
+        case 32:
+         format = babl_format ("R'G'B'A float");
+          break;
+        case 16:
+          format = babl_format ("R'G'B'A u16");
+          break;
+        case 8:
+        case 1:
+          format = babl_format ("R'G'B'A u8");
+          break;
+        default:
+         return NULL;
+         break;
+       }
+      break;
+
+    default:
+      return NULL;
+      break;
+    }
+
+  return format;
+}
diff --git a/plug-ins/file-psd/psd.h b/plug-ins/file-psd/psd.h
index cdbc575..794c742 100644
--- a/plug-ins/file-psd/psd.h
+++ b/plug-ins/file-psd/psd.h
@@ -144,8 +144,6 @@
 #define PSD_LFX_INNER_GLW       "iglw"          /* Effects layer - inner glow (PS5) */
 #define PSD_LFX_BEVEL           "bevl"          /* Effects layer - bevel (PS5) */
 
-/* New stuff temporarily until I can get them sorted out */
-
 /* Placed Layer */
 #define PSD_LPL_PLACE_LAYER     "plLd"          /* Placed layer (?) */
 #define PSD_LPL_PLACE_LAYER_NEW "SoLd"          /* Placed layer (PS10) */
@@ -367,7 +365,7 @@ typedef struct
   guint16       red;
   guint16       green;
   guint16       blue;
-}CMRGBColor;
+} CMRGBColor;
 
 /*  HSV Color Value
     A color value expressed in the HSV color space is composed of hue,
@@ -382,7 +380,7 @@ typedef struct
   guint16       hue;
   guint16       saturation;
   guint16       value;
-}CMHSVColor;
+} CMHSVColor;
 
 /* CMYK Color Value
   A color value expressed in the CMYK color space is composed of cyan, magenta,
@@ -397,7 +395,7 @@ typedef struct
   guint16       magenta;
   guint16       yellow;
   guint16       black;
-}CMCMYKColor;
+} CMCMYKColor;
 
 /* L*a*b* Color Value
    The first three values in the color data are, respectively, the colors
@@ -649,7 +647,7 @@ typedef struct
   gboolean              transparency;           /* Image has merged transparency alpha channel */
   guint32               rows;                   /* Number of rows: 1 - 30000 */
   guint32               columns;                /* Number of columns: 1 - 30000 */
-  guint16               bps;                    /* Bits per channel: 1, 8 or 16 */
+  guint16               bps;                    /* Bits per channel: 1, 8, 16, or 32 */
   guint16               color_mode;             /* Image color mode: {PSDColorMode} */
   GimpImageBaseType     base_type;              /* Image base color mode: (GIMP) */
   guint16               comp_mode;              /* Merged image compression mode */


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