[gimp/goat-invasion: 297/418] app: don't use gimp_image_get_color() in gimp_palette_import_extract()



commit 002d3af7ceb5518f897f73004856428c7b75c725
Author: Michael Natterer <mitch gimp org>
Date:   Wed Mar 28 23:13:37 2012 +0200

    app: don't use gimp_image_get_color() in gimp_palette_import_extract()
    
    GEGL can deliver the image data as RGBA right away.

 app/core/gimppalette-import.c |   34 +++++++++++++---------------------
 1 files changed, 13 insertions(+), 21 deletions(-)
---
diff --git a/app/core/gimppalette-import.c b/app/core/gimppalette-import.c
index 647b271..5e45af2 100644
--- a/app/core/gimppalette-import.c
+++ b/app/core/gimppalette-import.c
@@ -278,16 +278,13 @@ gimp_palette_import_extract (GimpImage     *image,
   GeglRectangle      *roi;
   GeglRectangle      *mask_roi = NULL;
   GeglRectangle       rect     = { x, y, width, height };
-  GimpImageType       type;
   GHashTable         *colors   = NULL;
   const Babl         *format;
   gint                bpp;
   gint                mask_bpp = 0;
 
   buffer = gimp_pickable_get_buffer (pickable);
-  type = gimp_pickable_get_image_type (pickable);
-
-  format = gimp_pickable_get_format (pickable);
+  format = babl_format ("R'G'B'A u8");
 
   iter = gegl_buffer_iterator_new (buffer, &rect, 0, format,
                                    GEGL_BUFFER_READ, GEGL_ABYSS_NONE);
@@ -329,27 +326,22 @@ gimp_palette_import_extract (GimpImage     *image,
 
           for (j = 0; j < roi->width; j++)
             {
-              if (! mdata || *mdata)
+              /*  ignore unselected, and completely transparent pixels  */
+              if ((! mdata || *mdata) && idata[ALPHA])
                 {
-                  guchar rgba[MAX_CHANNELS];
-
-                  gimp_image_get_color (image, type, idata, rgba);
-
-                  /*  ignore completely transparent pixels  */
-                  if (rgba[ALPHA])
-                    {
-                      guchar rgb_real[MAX_CHANNELS];
+                  guchar rgba[MAX_CHANNELS]     = { 0, };
+                  guchar rgb_real[MAX_CHANNELS] = { 0, };
 
-                      memcpy (rgb_real, rgba, MAX_CHANNELS);
+                  memcpy (rgba, idata, 4);
+                  memcpy (rgb_real, rgba, 4);
 
-                      rgba[0] = (rgba[0] / threshold) * threshold;
-                      rgba[1] = (rgba[1] / threshold) * threshold;
-                      rgba[2] = (rgba[2] / threshold) * threshold;
+                  rgba[0] = (rgba[0] / threshold) * threshold;
+                  rgba[1] = (rgba[1] / threshold) * threshold;
+                  rgba[2] = (rgba[2] / threshold) * threshold;
 
-                      colors = gimp_palette_import_store_colors (colors,
-                                                                 rgba, rgb_real,
-                                                                 n_colors);
-                    }
+                  colors = gimp_palette_import_store_colors (colors,
+                                                             rgba, rgb_real,
+                                                             n_colors);
                 }
 
               idata += bpp;



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