[gimp/goat-invasion: 526/608] app: remove bpp <-> format conversion stuff from gimp-gegl-utils.[ch]



commit 6f4cb313e464af2b4e06b04e184681938a3b820a
Author: Michael Natterer <mitch gimp org>
Date:   Sun Apr 22 00:42:00 2012 +0200

    app: remove bpp <-> format conversion stuff from gimp-gegl-utils.[ch]
    
    Fix stuff by picking formats as we get data from the "outside", like a
    GdkPixbuf, and pass around more proper formats from where we know them.

 app/base/tile-manager-preview.c |   19 ++++++---
 app/base/tile-manager-preview.h |    2 +
 app/core/gimpdrawable-preview.c |    1 +
 app/core/gimpimage-preview.c    |    5 ++-
 app/core/gimppattern-load.c     |   19 ++++++---
 app/gegl/gimp-gegl-utils.c      |   82 +++++++++------------------------------
 app/gegl/gimp-gegl-utils.h      |    4 +-
 app/paint/gimpbrushcore.c       |   14 ++++---
 8 files changed, 61 insertions(+), 85 deletions(-)
---
diff --git a/app/base/tile-manager-preview.c b/app/base/tile-manager-preview.c
index edf5915..2c914ec 100644
--- a/app/base/tile-manager-preview.c
+++ b/app/base/tile-manager-preview.c
@@ -23,8 +23,6 @@
 
 #include "paint-funcs/subsample-region.h"
 
-#include "gegl/gimp-gegl-utils.h"
-
 #include "core/gimptempbuf.h"
 
 #include "pixel-region.h"
@@ -33,6 +31,7 @@
 
 
 static GimpTempBuf * tile_manager_create_preview (TileManager *tiles,
+                                                  const Babl  *format,
                                                   gint         src_x,
                                                   gint         src_y,
                                                   gint         src_width,
@@ -43,13 +42,17 @@ static GimpTempBuf * tile_manager_create_preview (TileManager *tiles,
 
 GimpTempBuf *
 tile_manager_get_preview (TileManager *tiles,
+                          const Babl  *format,
                           gint         width,
                           gint         height)
 {
   g_return_val_if_fail (tiles != NULL, NULL);
+  g_return_val_if_fail (format != NULL, NULL);
+  g_return_val_if_fail (babl_format_get_bytes_per_pixel (format) ==
+                        tile_manager_bpp (tiles), NULL);
   g_return_val_if_fail (width > 0 && height > 0, NULL);
 
-  return tile_manager_create_preview (tiles,
+  return tile_manager_create_preview (tiles, format,
                                       0, 0,
                                       tile_manager_width (tiles),
                                       tile_manager_height (tiles),
@@ -58,6 +61,7 @@ tile_manager_get_preview (TileManager *tiles,
 
 GimpTempBuf *
 tile_manager_get_sub_preview (TileManager *tiles,
+                              const Babl  *format,
                               gint         src_x,
                               gint         src_y,
                               gint         src_width,
@@ -66,6 +70,9 @@ tile_manager_get_sub_preview (TileManager *tiles,
                               gint         dest_height)
 {
   g_return_val_if_fail (tiles != NULL, NULL);
+  g_return_val_if_fail (format != NULL, NULL);
+  g_return_val_if_fail (babl_format_get_bytes_per_pixel (format) ==
+                        tile_manager_bpp (tiles), NULL);
 
   g_return_val_if_fail (src_x >= 0 &&
                         src_x < tile_manager_width (tiles), NULL);
@@ -80,13 +87,14 @@ tile_manager_get_sub_preview (TileManager *tiles,
 
   g_return_val_if_fail (dest_width > 0 && dest_height > 0, NULL);
 
-  return tile_manager_create_preview (tiles,
+  return tile_manager_create_preview (tiles, format,
                                       src_x, src_y, src_width, src_height,
                                       dest_width, dest_height);
 }
 
 static GimpTempBuf *
 tile_manager_create_preview (TileManager *tiles,
+                             const Babl  *format,
                              gint         src_x,
                              gint         src_y,
                              gint         src_width,
@@ -99,8 +107,7 @@ tile_manager_create_preview (TileManager *tiles,
   PixelRegion  destPR;
   gint         subsample = 1;
 
-  preview = gimp_temp_buf_new (dest_width, dest_height,
-                               gimp_bpp_to_babl_format (tile_manager_bpp (tiles)));
+  preview = gimp_temp_buf_new (dest_width, dest_height, format);
 
   pixel_region_init (&srcPR, tiles, src_x, src_y, src_width, src_height, FALSE);
 
diff --git a/app/base/tile-manager-preview.h b/app/base/tile-manager-preview.h
index 8d784cf..cb23e66 100644
--- a/app/base/tile-manager-preview.h
+++ b/app/base/tile-manager-preview.h
@@ -20,9 +20,11 @@
 
 
 GimpTempBuf * tile_manager_get_preview     (TileManager *tiles,
+                                            const Babl  *format,
                                             gint         width,
                                             gint         height);
 GimpTempBuf * tile_manager_get_sub_preview (TileManager *tiles,
+                                            const Babl  *format,
                                             gint         src_x,
                                             gint         src_y,
                                             gint         src_width,
diff --git a/app/core/gimpdrawable-preview.c b/app/core/gimpdrawable-preview.c
index 2e3a96d..82852e7 100644
--- a/app/core/gimpdrawable-preview.c
+++ b/app/core/gimpdrawable-preview.c
@@ -159,6 +159,7 @@ gimp_drawable_get_sub_preview (GimpDrawable *drawable,
                                           dest_width, dest_height);
 
   return tile_manager_get_sub_preview (gimp_drawable_get_tiles (drawable),
+                                       gimp_drawable_get_preview_format (drawable),
                                        src_x, src_y, src_width, src_height,
                                        dest_width, dest_height);
 }
diff --git a/app/core/gimpimage-preview.c b/app/core/gimpimage-preview.c
index 60789bf..b91d0c3 100644
--- a/app/core/gimpimage-preview.c
+++ b/app/core/gimpimage-preview.c
@@ -26,6 +26,7 @@
 #include "gimpimage.h"
 #include "gimpimage-preview.h"
 #include "gimpimage-private.h"
+#include "gimpprojectable.h"
 #include "gimpprojection.h"
 #include "gimptempbuf.h"
 
@@ -141,7 +142,9 @@ gimp_image_get_new_preview (GimpViewable *viewable,
   level = gimp_projection_get_level (projection, scale_x, scale_y);
   tiles = gimp_projection_get_tiles_at_level (projection, level, &is_premult);
 
-  buf = tile_manager_get_preview (tiles, width, height);
+  buf = tile_manager_get_preview (tiles,
+                                  gimp_projectable_get_format (GIMP_PROJECTABLE (image)),
+                                  width, height);
 
   if (is_premult)
     {
diff --git a/app/core/gimppattern-load.c b/app/core/gimppattern-load.c
index 2de2f75..e839e29 100644
--- a/app/core/gimppattern-load.c
+++ b/app/core/gimppattern-load.c
@@ -63,6 +63,7 @@ gimp_pattern_load (GimpContext  *context,
                    GError      **error)
 {
   GimpPattern   *pattern = NULL;
+  const Babl    *format  = NULL;
   gint           fd;
   PatternHeader  header;
   gint           bn_size;
@@ -155,8 +156,15 @@ gimp_pattern_load (GimpContext  *context,
 
   g_free (name);
 
-  pattern->mask = gimp_temp_buf_new (header.width, header.height,
-                                     gimp_bpp_to_babl_format (header.bytes));
+  switch (header.bytes)
+    {
+    case 1: format = babl_format ("Y' u8");      break;
+    case 2: format = babl_format ("Y'A u8");     break;
+    case 3: format = babl_format ("R'G'B' u8");  break;
+    case 4: format = babl_format ("R'G'B'A u8"); break;
+    }
+
+  pattern->mask = gimp_temp_buf_new (header.width, header.height, format);
 
   if (read (fd, gimp_temp_buf_get_data (pattern->mask),
             header.width * header.height * header.bytes) <
@@ -216,10 +224,9 @@ gimp_pattern_load_pixbuf (GimpContext  *context,
                           NULL);
   g_free (name);
 
-  pattern->mask =
-    gimp_temp_buf_new (gdk_pixbuf_get_width (pixbuf),
-                       gdk_pixbuf_get_height (pixbuf),
-                       gimp_bpp_to_babl_format (gdk_pixbuf_get_n_channels (pixbuf)));
+  pattern->mask = gimp_temp_buf_new (gdk_pixbuf_get_width (pixbuf),
+                                     gdk_pixbuf_get_height (pixbuf),
+                                     gimp_pixbuf_get_format (pixbuf));
 
   src_buffer  = gimp_pixbuf_create_buffer (pixbuf);
   dest_buffer = gimp_temp_buf_create_buffer (pattern->mask);
diff --git a/app/gegl/gimp-gegl-utils.c b/app/gegl/gimp-gegl-utils.c
index 6b56086..4500087 100644
--- a/app/gegl/gimp-gegl-utils.c
+++ b/app/gegl/gimp-gegl-utils.c
@@ -57,62 +57,6 @@ gimp_babl_format_get_image_type (const Babl *format)
   g_return_val_if_reached (-1);
 }
 
-/**
- * gimp_bpp_to_babl_format:
- * @bpp: bytes per pixel
- *
- * Return the Babl format to use for a given number of bytes per pixel.
- * This function assumes that the data is 8bit.
- *
- * Return value: the Babl format to use
- **/
-const Babl *
-gimp_bpp_to_babl_format (guint bpp)
-{
-  g_return_val_if_fail (bpp > 0 && bpp <= 4, NULL);
-
-  switch (bpp)
-    {
-    case 1:
-      return babl_format ("Y' u8");
-    case 2:
-      return babl_format ("Y'A u8");
-    case 3:
-      return babl_format ("R'G'B' u8");
-    case 4:
-      return babl_format ("R'G'B'A u8");
-    }
-
-  return NULL;
-}
-
-/**
- * gimp_bpp_to_babl_format_with_alpha:
- * @bpp: bytes per pixel
- *
- * Return the Babl format to use for a given number of bytes per pixel.
- * This function assumes that the data is 8bit.
- *
- * Return value: the Babl format to use
- **/
-const Babl *
-gimp_bpp_to_babl_format_with_alpha (guint bpp)
-{
-  g_return_val_if_fail (bpp > 0 && bpp <= 4, NULL);
-
-  switch (bpp)
-    {
-      case 1:
-      case 2:
-        return babl_format ("Y'A u8");
-      case 3:
-      case 4:
-        return babl_format ("R'G'B'A u8");
-    }
-
-  return NULL;
-}
-
 const gchar *
 gimp_interpolation_to_gegl_filter (GimpInterpolationType interpolation)
 {
@@ -129,24 +73,36 @@ gimp_interpolation_to_gegl_filter (GimpInterpolationType interpolation)
   return "nearest";
 }
 
+const Babl *
+gimp_pixbuf_get_format (GdkPixbuf *pixbuf)
+{
+  g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
+
+  switch (gdk_pixbuf_get_n_channels (pixbuf))
+    {
+    case 3: return babl_format ("R'G'B' u8");
+    case 4: return babl_format ("R'G'B'A u8");
+    }
+
+  g_return_val_if_reached (NULL);
+}
+
 GeglBuffer *
 gimp_pixbuf_create_buffer (GdkPixbuf *pixbuf)
 {
-  gint          width;
-  gint          height;
-  gint          rowstride;
-  gint          channels;
+  gint width;
+  gint height;
+  gint rowstride;
 
   g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
 
   width     = gdk_pixbuf_get_width (pixbuf);
   height    = gdk_pixbuf_get_height (pixbuf);
   rowstride = gdk_pixbuf_get_rowstride (pixbuf);
-  channels  = gdk_pixbuf_get_n_channels (pixbuf);
 
   return gegl_buffer_linear_new_from_data (gdk_pixbuf_get_pixels (pixbuf),
-                                           gimp_bpp_to_babl_format (channels),
-                                           GEGL_RECTANGLE (0,0,width,height),
+                                           gimp_pixbuf_get_format (pixbuf),
+                                           GEGL_RECTANGLE (0, 0, width, height),
                                            rowstride,
                                            (GDestroyNotify) g_object_unref,
                                            g_object_ref (pixbuf));
diff --git a/app/gegl/gimp-gegl-utils.h b/app/gegl/gimp-gegl-utils.h
index 072a313..f7dac68 100644
--- a/app/gegl/gimp-gegl-utils.h
+++ b/app/gegl/gimp-gegl-utils.h
@@ -27,9 +27,6 @@
 
 GimpImageType    gimp_babl_format_get_image_type (const Babl            *format);
 
-const Babl  * gimp_bpp_to_babl_format            (guint                  bpp) G_GNUC_CONST;
-const Babl  * gimp_bpp_to_babl_format_with_alpha (guint                  bpp) G_GNUC_CONST;
-
 const gchar * gimp_interpolation_to_gegl_filter  (GimpInterpolationType  interpolation) G_GNUC_CONST;
 
 GeglBuffer  * gimp_gegl_buffer_new               (const GeglRectangle   *rect,
@@ -40,6 +37,7 @@ GeglBuffer  * gimp_tile_manager_create_buffer    (TileManager           *tm,
                                                   const Babl            *format);
 TileManager * gimp_gegl_buffer_get_tiles         (GeglBuffer            *buffer);
 
+const Babl  * gimp_pixbuf_get_format             (GdkPixbuf             *pixbuf);
 GeglBuffer  * gimp_pixbuf_create_buffer          (GdkPixbuf             *pixbuf);
 
 void          gimp_gegl_buffer_refetch_tiles     (GeglBuffer            *buffer);
diff --git a/app/paint/gimpbrushcore.c b/app/paint/gimpbrushcore.c
index ddfabf1..7d75d46 100644
--- a/app/paint/gimpbrushcore.c
+++ b/app/paint/gimpbrushcore.c
@@ -25,7 +25,7 @@
 
 #include "paint-types.h"
 
-#include "gegl/gimp-gegl-utils.h"
+#include "gegl/gimp-babl.h"
 
 #include "core/gimpbrush.h"
 #include "core/gimpdrawable.h"
@@ -1620,8 +1620,9 @@ gimp_brush_core_paint_line_pixmap_mask (GimpDrawable             *drawable,
                                         gint                      width,
                                         GimpBrushApplicationMode  mode)
 {
-  gint    pixmap_bytes;
-  guchar *b;
+  GimpImageBaseType  pixmap_base_type;
+  gint               pixmap_bytes;
+  guchar            *b;
 
   /*  Make sure x, y are positive  */
   while (x < 0)
@@ -1629,7 +1630,8 @@ gimp_brush_core_paint_line_pixmap_mask (GimpDrawable             *drawable,
   while (y < 0)
     y += pixmap_mask->height;
 
-  pixmap_bytes = babl_format_get_bytes_per_pixel (pixmap_mask->format);
+  pixmap_base_type = gimp_babl_format_get_base_type (pixmap_mask->format);
+  pixmap_bytes     = babl_format_get_bytes_per_pixel (pixmap_mask->format);
 
   /* Point to the approriate scanline */
   b = (gimp_temp_buf_get_data (pixmap_mask) +
@@ -1644,7 +1646,7 @@ gimp_brush_core_paint_line_pixmap_mask (GimpDrawable             *drawable,
       guchar       *l        = line_buf;
       gint          i;
 
-      fish = babl_fish (gimp_bpp_to_babl_format_with_alpha (pixmap_bytes),
+      fish = babl_fish (gimp_babl_format (pixmap_base_type, TRUE),
                         gimp_drawable_get_format_with_alpha (drawable));
 
       /* put the source pixmap's pixels, plus the mask's alpha, into
@@ -1672,7 +1674,7 @@ gimp_brush_core_paint_line_pixmap_mask (GimpDrawable             *drawable,
       guchar     *l        = line_buf;
       gint        i;
 
-      fish = babl_fish (gimp_bpp_to_babl_format (pixmap_bytes),
+      fish = babl_fish (pixmap_mask->format,
                         gimp_drawable_get_format_with_alpha (drawable));
 
       /* put the source pixmap's pixels, into one line, so we can use



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