[gimp/metadata-browser] app: turn the TempBuf's "bytes" into "format" and port everything to it



commit 8fab879e8ff8aff017fb70e72352aebb211bc58b
Author: Michael Natterer <mitch gimp org>
Date:   Sun Apr 8 18:47:49 2012 +0200

    app: turn the TempBuf's "bytes" into "format" and port everything to it

 app/base/Makefile.am                   |    3 +-
 app/base/pixel-region.c                |    5 ++-
 app/base/temp-buf.c                    |   35 ++++++++++++++++------------
 app/base/temp-buf.h                    |   14 +++++-----
 app/base/tile-manager-preview.c        |    8 ++++--
 app/core/gimp-edit.c                   |    2 +-
 app/core/gimpbrush-boundary.c          |    4 +--
 app/core/gimpbrush-load.c              |   12 +++++----
 app/core/gimpbrush-transform.c         |   15 +++++------
 app/core/gimpbrush.c                   |    7 +++--
 app/core/gimpbrushclipboard.c          |   13 ++++-----
 app/core/gimpbrushgenerated-load.c     |    2 +-
 app/core/gimpbrushgenerated-save.c     |    2 +-
 app/core/gimpbrushgenerated.c          |    5 ++-
 app/core/gimpbrushpipe-load.c          |    2 +-
 app/core/gimpbrushpipe.c               |    2 +-
 app/core/gimpbuffer.c                  |    4 +--
 app/core/gimpdrawable-preview.c        |    5 +++-
 app/core/gimpgradient.c                |    2 +-
 app/core/gimppalette.c                 |    2 +-
 app/core/gimppattern-load.c            |   38 +++++++++++++----------------
 app/core/gimppattern.c                 |   10 ++++----
 app/core/gimppatternclipboard.c        |    8 ++----
 app/core/gimppreviewcache.c            |   15 +++++++----
 app/core/gimpviewable.c                |    6 ++--
 app/gegl/gimp-gegl-utils.c             |   24 +++++-------------
 app/gegl/gimp-gegl-utils.h             |    1 -
 app/paint/gimpbrushcore.c              |   40 ++++++++++++++++----------------
 app/paint/gimpconvolve.c               |    7 +----
 app/paint/gimpheal.c                   |    3 +-
 app/paint/gimpink.c                    |    6 +---
 app/paint/gimpsmudge.c                 |    7 +----
 app/pdb/brush-cmds.c                   |   13 ++++-----
 app/pdb/drawable-cmds.c                |    8 +++---
 app/pdb/image-cmds.c                   |    4 +-
 app/pdb/pattern-cmds.c                 |    7 ++---
 app/pdb/patterns-cmds.c                |    5 +--
 app/text/gimpfont.c                    |    4 +-
 app/tools/gimpiscissorstool.c          |    2 +-
 app/vectors/gimpvectors-preview.c      |    2 +-
 app/widgets/gimppatternselect.c        |    2 +-
 app/widgets/gimpviewrenderer.c         |   12 +++++----
 app/widgets/gimpviewrendererbrush.c    |    1 +
 app/widgets/gimpviewrendererbuffer.c   |    1 +
 app/widgets/gimpviewrendererdrawable.c |    5 +++-
 tools/pdbgen/pdb/brush.pdb             |   13 ++++-----
 tools/pdbgen/pdb/drawable.pdb          |    8 +++---
 tools/pdbgen/pdb/image.pdb             |    4 +-
 tools/pdbgen/pdb/pattern.pdb           |    7 ++---
 tools/pdbgen/pdb/patterns.pdb          |    5 +--
 50 files changed, 200 insertions(+), 212 deletions(-)
---
diff --git a/app/base/Makefile.am b/app/base/Makefile.am
index 79b29fb..b4e788b 100644
--- a/app/base/Makefile.am
+++ b/app/base/Makefile.am
@@ -10,7 +10,8 @@ INCLUDES = \
 	-I$(top_srcdir)/app	\
 	$(BABL_CFLAGS)		\
 	$(CAIRO_CFLAGS)		\
-	$(GLIB_CFLAGS)		\
+	$(GEGL_CFLAGS)		\
+	$(GDK_PIXBUF_CFLAGS)	\
 	-I$(includedir)
 
 noinst_LIBRARIES = libappbase.a
diff --git a/app/base/pixel-region.c b/app/base/pixel-region.c
index de22f28..f581168 100644
--- a/app/base/pixel-region.c
+++ b/app/base/pixel-region.c
@@ -20,6 +20,7 @@
 #include <stdarg.h>
 #include <string.h>
 
+#include <babl/babl.h>
 #include <glib-object.h>
 
 #include "base-types.h"
@@ -95,8 +96,8 @@ pixel_region_init_temp_buf (PixelRegion *PR,
   PR->curtile       = NULL;
   PR->offx          = 0;
   PR->offy          = 0;
-  PR->bytes         = temp_buf->bytes;
-  PR->rowstride     = temp_buf->width * temp_buf->bytes;
+  PR->bytes         = babl_format_get_bytes_per_pixel (temp_buf->format);
+  PR->rowstride     = temp_buf->width * PR->bytes;
   PR->x             = x;
   PR->y             = y;
   PR->w             = w;
diff --git a/app/base/temp-buf.c b/app/base/temp-buf.c
index 1309419..8f5802a 100644
--- a/app/base/temp-buf.c
+++ b/app/base/temp-buf.c
@@ -34,24 +34,26 @@
 
 
 TempBuf *
-temp_buf_new (gint          width,
-              gint          height,
-              gint          bytes)
+temp_buf_new (gint        width,
+              gint        height,
+              const Babl *format)
 {
   TempBuf *temp;
 
   g_return_val_if_fail (width > 0 && height > 0, NULL);
-  g_return_val_if_fail (bytes > 0, NULL);
+  g_return_val_if_fail (format != NULL, NULL);
 
   temp = g_slice_new (TempBuf);
 
-  temp->bytes   = bytes;
+  temp->format  = format;
   temp->width   = width;
   temp->height  = height;
   temp->x       = 0;
   temp->y       = 0;
 
-  temp->data = g_new (guchar, width * height * bytes);
+  temp->data = g_new (guchar,
+                      width * height *
+                      babl_format_get_bytes_per_pixel (format));
 
   return temp;
 }
@@ -63,7 +65,7 @@ temp_buf_copy (TempBuf *src)
 
   g_return_val_if_fail (src != NULL, NULL);
 
-  dest = temp_buf_new (src->width, src->height, src->bytes);
+  dest = temp_buf_new (src->width, src->height, src->format);
 
   if (! dest)
     return NULL;
@@ -85,6 +87,7 @@ temp_buf_scale (TempBuf *src,
   guchar       *dest_data;
   gdouble       x_ratio;
   gdouble       y_ratio;
+  gint          bytes;
   gint          loop1;
   gint          loop2;
 
@@ -93,7 +96,7 @@ temp_buf_scale (TempBuf *src,
 
   dest = temp_buf_new (new_width,
                        new_height,
-                       src->bytes);
+                       src->format);
 
   src_data  = temp_buf_get_data (src);
   dest_data = temp_buf_get_data (dest);
@@ -101,6 +104,8 @@ temp_buf_scale (TempBuf *src,
   x_ratio = (gdouble) src->width  / (gdouble) new_width;
   y_ratio = (gdouble) src->height / (gdouble) new_height;
 
+  bytes = babl_format_get_bytes_per_pixel (src->format);
+
   for (loop1 = 0 ; loop1 < new_height ; loop1++)
     {
       for (loop2 = 0 ; loop2 < new_width ; loop2++)
@@ -110,13 +115,13 @@ temp_buf_scale (TempBuf *src,
           gint          i;
 
           src_pixel = src_data +
-            (gint) (loop2 * x_ratio) * src->bytes +
-            (gint) (loop1 * y_ratio) * src->bytes * src->width;
+            (gint) (loop2 * x_ratio) * bytes +
+            (gint) (loop1 * y_ratio) * bytes * src->width;
 
           dest_pixel = dest_data +
-            (loop2 + loop1 * new_width) * src->bytes;
+            (loop2 + loop1 * new_width) * bytes;
 
-          for (i = 0 ; i < src->bytes; i++)
+          for (i = 0 ; i < bytes; i++)
             *dest_pixel++ = *src_pixel++;
         }
     }
@@ -138,7 +143,7 @@ temp_buf_demultiply (TempBuf *buf)
 
   g_return_if_fail (buf != NULL);
 
-  switch (buf->bytes)
+  switch (babl_format_get_bytes_per_pixel (buf->format))
     {
     case 1:
       break;
@@ -196,13 +201,13 @@ temp_buf_get_data (const TempBuf *buf)
 gsize
 temp_buf_get_data_size (TempBuf *buf)
 {
-  return buf->bytes * buf->width * buf->height;
+  return babl_format_get_bytes_per_pixel (buf->format) * buf->width * buf->height;
 }
 
 guchar *
 temp_buf_data_clear (TempBuf *buf)
 {
-  memset (buf->data, 0, buf->height * buf->width * buf->bytes);
+  memset (buf->data, 0, temp_buf_get_data_size (buf));
 
   return buf->data;
 }
diff --git a/app/base/temp-buf.h b/app/base/temp-buf.h
index 041aff1..a16c7cb 100644
--- a/app/base/temp-buf.h
+++ b/app/base/temp-buf.h
@@ -21,12 +21,12 @@
 
 struct _TempBuf
 {
-  gint      bytes;      /*  number of bytes per pixel (1,2,3 or 4)         */
-  gint      width;
-  gint      height;
-  gint      x, y;       /*  origin of data source                          */
-  guchar   *data;       /*  The data buffer. Do never access this field
-                            directly, use temp_buf_get_data() instead !!   */
+  const Babl *format;  /*  pixel format  */
+  gint        width;
+  gint        height;
+  gint        x, y;      /*  origin of data source                          */
+  guchar     *data;      /*  The data buffer. Do never access this field
+                           directly, use temp_buf_get_data() instead !!   */
 };
 
 
@@ -34,7 +34,7 @@ struct _TempBuf
 
 TempBuf * temp_buf_new           (gint           width,
                                   gint           height,
-                                  gint           bytes);
+                                  const Babl    *fomat);
 TempBuf * temp_buf_copy          (TempBuf       *src);
 TempBuf * temp_buf_scale         (TempBuf       *buf,
                                   gint           width,
diff --git a/app/base/tile-manager-preview.c b/app/base/tile-manager-preview.c
index ce60fc3..e699003 100644
--- a/app/base/tile-manager-preview.c
+++ b/app/base/tile-manager-preview.c
@@ -17,12 +17,14 @@
 
 #include "config.h"
 
-#include <glib-object.h>
+#include <gegl.h>
 
-#include "base-types.h"
+#include "core/core-types.h" /* eek, but this file is cruft anyway */
 
 #include "paint-funcs/subsample-region.h"
 
+#include "gegl/gimp-gegl-utils.h"
+
 #include "pixel-region.h"
 #include "temp-buf.h"
 #include "tile-manager.h"
@@ -97,7 +99,7 @@ tile_manager_create_preview (TileManager *tiles,
   gint         subsample = 1;
 
   preview = temp_buf_new (dest_width, dest_height,
-                          tile_manager_bpp (tiles));
+                          gimp_bpp_to_babl_format (tile_manager_bpp (tiles)));
 
   pixel_region_init (&srcPR, tiles, src_x, src_y, src_width, src_height, FALSE);
 
diff --git a/app/core/gimp-edit.c b/app/core/gimp-edit.c
index 0181f4f..b2769fd 100644
--- a/app/core/gimp-edit.c
+++ b/app/core/gimp-edit.c
@@ -469,7 +469,7 @@ gimp_edit_fill_full (GimpImage            *image,
     return TRUE;  /*  nothing to do, but the fill succeded  */
 
   if (pattern &&
-      (pattern->mask->bytes == 2 || pattern->mask->bytes == 4) &&
+      babl_format_has_alpha (pattern->mask->format) &&
       ! gimp_drawable_has_alpha (drawable))
     {
       format = gimp_drawable_get_format_with_alpha (drawable);
diff --git a/app/core/gimpbrush-boundary.c b/app/core/gimpbrush-boundary.c
index 34979be..af0d980 100644
--- a/app/core/gimpbrush-boundary.c
+++ b/app/core/gimpbrush-boundary.c
@@ -48,9 +48,7 @@ gimp_brush_transform_boundary_exact (GimpBrush *brush,
       GimpBoundSeg  *bound_segs;
       gint           n_bound_segs;
 
-      buffer = gimp_temp_buf_create_buffer ((TempBuf *) mask,
-                                            babl_format ("Y u8"),
-                                            FALSE);
+      buffer = gimp_temp_buf_create_buffer ((TempBuf *) mask, FALSE);
 
       bound_segs = gimp_boundary_find (buffer, NULL,
                                        GIMP_BOUNDARY_WITHIN_BOUNDS,
diff --git a/app/core/gimpbrush-load.c b/app/core/gimpbrush-load.c
index bfb7820..df5b33d 100644
--- a/app/core/gimpbrush-load.c
+++ b/app/core/gimpbrush-load.c
@@ -34,7 +34,7 @@
 #define _O_BINARY 0
 #endif
 
-#include <glib-object.h>
+#include <gegl.h>
 #include <glib/gstdio.h>
 
 #include "libgimpbase/gimpbase.h"
@@ -291,7 +291,8 @@ gimp_brush_load_brush (GimpContext  *context,
                         NULL);
   g_free (name);
 
-  brush->mask = temp_buf_new (header.width, header.height, 1);
+  brush->mask = temp_buf_new (header.width, header.height,
+                              babl_format ("Y u8"));
 
   mask = temp_buf_get_data (brush->mask);
   size = header.width * header.height * header.bytes;
@@ -345,7 +346,8 @@ gimp_brush_load_brush (GimpContext  *context,
       {
         guchar buf[8 * 1024];
 
-        brush->pixmap = temp_buf_new (header.width, header.height, 3);
+        brush->pixmap = temp_buf_new (header.width, header.height,
+                                      babl_format ("R'G'B' u8"));
         pixmap = temp_buf_get_data (brush->pixmap);
 
         for (i = 0; success && i < size;)
@@ -648,7 +650,7 @@ gimp_brush_load_abr_brush_v12 (FILE         *file,
         brush->x_axis.y = 0.0;
         brush->y_axis.x = 0.0;
         brush->y_axis.y = height / 2.0;
-        brush->mask     = temp_buf_new (width, height, 1);
+        brush->mask     = temp_buf_new (width, height, babl_format ("Y u8"));
 
         mask = temp_buf_get_data (brush->mask);
         size = width * height * bytes;
@@ -755,7 +757,7 @@ gimp_brush_load_abr_brush_v6 (FILE         *file,
   brush->x_axis.y = 0.0;
   brush->y_axis.x = 0.0;
   brush->y_axis.y = height / 2.0;
-  brush->mask     = temp_buf_new (width, height, 1);
+  brush->mask     = temp_buf_new (width, height, babl_format ("Y u8"));
 
   mask = temp_buf_get_data (brush->mask);
 
diff --git a/app/core/gimpbrush-transform.c b/app/core/gimpbrush-transform.c
index bcb014b..95843d5 100644
--- a/app/core/gimpbrush-transform.c
+++ b/app/core/gimpbrush-transform.c
@@ -190,7 +190,7 @@ gimp_brush_real_transform_mask (GimpBrush *brush,
   gimp_matrix3_translate (&matrix, -x, -y);
   gimp_matrix3_invert (&matrix);
 
-  result = temp_buf_new (dest_width, dest_height, 1);
+  result = temp_buf_new (dest_width, dest_height, babl_format ("Y u8"));
 
   dest = temp_buf_get_data (result);
   src  = temp_buf_get_data (source);
@@ -342,10 +342,9 @@ gimp_brush_real_transform_mask (GimpBrush *brush,
 
       blur_src = temp_buf_copy (result);
 
-      src_buffer  = gimp_temp_buf_create_buffer (blur_src, babl_format ("Y u8"),
-                                                 TRUE);
-      dest_buffer = gimp_temp_buf_create_buffer (blur_src, babl_format ("Y u8"),
-                                                 FALSE);
+      src_buffer  = gimp_temp_buf_create_buffer (blur_src, TRUE);
+      dest_buffer = gimp_temp_buf_create_buffer (blur_src, FALSE);
+
       gimp_gegl_convolve (src_buffer,
                           GEGL_RECTANGLE (0, 0,
                                           blur_src->width,
@@ -486,7 +485,7 @@ gimp_brush_real_transform_pixmap (GimpBrush *brush,
   gimp_matrix3_translate (&matrix, -x, -y);
   gimp_matrix3_invert (&matrix);
 
-  result = temp_buf_new (dest_width, dest_height, 3);
+  result = temp_buf_new (dest_width, dest_height, babl_format ("R'G'B' u8"));
 
   dest = temp_buf_get_data (result);
   src  = temp_buf_get_data (source);
@@ -643,8 +642,8 @@ gimp_brush_real_transform_pixmap (GimpBrush *brush,
 
       blur_src = temp_buf_copy (result);
 
-      src_buffer  = gimp_temp_buf_create_buffer (blur_src, NULL, TRUE);
-      dest_buffer = gimp_temp_buf_create_buffer (blur_src, NULL, FALSE);
+      src_buffer  = gimp_temp_buf_create_buffer (blur_src, TRUE);
+      dest_buffer = gimp_temp_buf_create_buffer (blur_src, FALSE);
 
       gimp_gegl_convolve (src_buffer,
                           GEGL_RECTANGLE (0, 0,
diff --git a/app/core/gimpbrush.c b/app/core/gimpbrush.c
index d969d81..3f1c992 100644
--- a/app/core/gimpbrush.c
+++ b/app/core/gimpbrush.c
@@ -17,8 +17,8 @@
 
 #include "config.h"
 
-#include <glib-object.h>
 #include <cairo.h>
+#include <gegl.h>
 
 #include "libgimpbase/gimpbase.h"
 #include "libgimpmath/gimpmath.h"
@@ -314,7 +314,7 @@ gimp_brush_get_new_preview (GimpViewable *viewable,
 
           if (! mask_buf)
             {
-              mask_buf = temp_buf_new (1, 1, 1);
+              mask_buf = temp_buf_new (1, 1, babl_format ("Y u8"));
               temp_buf_data_clear ((TempBuf *) mask_buf);
               free_mask = TRUE;
             }
@@ -330,7 +330,8 @@ gimp_brush_get_new_preview (GimpViewable *viewable,
         }
     }
 
-  return_buf = temp_buf_new (mask_width, mask_height, 4);
+  return_buf = temp_buf_new (mask_width, mask_height,
+                             babl_format ("R'G'B'A u8"));
   temp_buf_data_clear (return_buf);
 
   mask = temp_buf_get_data (mask_buf);
diff --git a/app/core/gimpbrushclipboard.c b/app/core/gimpbrushclipboard.c
index be772c1..a3ba62c 100644
--- a/app/core/gimpbrushclipboard.c
+++ b/app/core/gimpbrushclipboard.c
@@ -203,16 +203,15 @@ gimp_brush_clipboard_buffer_changed (Gimp      *gimp,
       width  = MIN (gimp_buffer_get_width  (gimp->global_buffer), 512);
       height = MIN (gimp_buffer_get_height (gimp->global_buffer), 512);
 
-      brush->mask   = temp_buf_new (width, height, 1);
-      brush->pixmap = temp_buf_new (width, height, 3);
+      brush->mask   = temp_buf_new (width, height, babl_format ("Y u8"));
+      brush->pixmap = temp_buf_new (width, height, babl_format ("R'G'B' u8"));
 
       /*  copy the alpha channel into the brush's mask  */
       if (babl_format_has_alpha (format))
         {
-          dest_buffer = gimp_temp_buf_create_buffer (brush->mask,
-                                                     babl_format ("A u8"),
-                                                     FALSE);
+          dest_buffer = gimp_temp_buf_create_buffer (brush->mask, FALSE);
 
+          gegl_buffer_set_format (dest_buffer, babl_format ("A u8"));
           gegl_buffer_copy (buffer, NULL, dest_buffer, NULL);
 
           g_object_unref (dest_buffer);
@@ -224,7 +223,7 @@ gimp_brush_clipboard_buffer_changed (Gimp      *gimp,
         }
 
       /*  copy the color channels into the brush's pixmap  */
-      dest_buffer = gimp_temp_buf_create_buffer (brush->pixmap, NULL, FALSE);
+      dest_buffer = gimp_temp_buf_create_buffer (brush->pixmap, FALSE);
 
       gegl_buffer_copy (buffer, NULL, dest_buffer, NULL);
 
@@ -235,7 +234,7 @@ gimp_brush_clipboard_buffer_changed (Gimp      *gimp,
       width  = 17;
       height = 17;
 
-      brush->mask = temp_buf_new (width, height, 1);
+      brush->mask = temp_buf_new (width, height, babl_format ("Y u8"));
       temp_buf_data_clear (brush->mask);
     }
 
diff --git a/app/core/gimpbrushgenerated-load.c b/app/core/gimpbrushgenerated-load.c
index 9b08f48..1c802a3 100644
--- a/app/core/gimpbrushgenerated-load.c
+++ b/app/core/gimpbrushgenerated-load.c
@@ -27,7 +27,7 @@
 #include <unistd.h>
 #endif
 
-#include <glib-object.h>
+#include <gegl.h>
 #include <glib/gstdio.h>
 
 #include "libgimpbase/gimpbase.h"
diff --git a/app/core/gimpbrushgenerated-save.c b/app/core/gimpbrushgenerated-save.c
index 6059784..569adbc 100644
--- a/app/core/gimpbrushgenerated-save.c
+++ b/app/core/gimpbrushgenerated-save.c
@@ -27,7 +27,7 @@
 #include <unistd.h>
 #endif
 
-#include <glib-object.h>
+#include <gegl.h>
 #include <glib/gstdio.h>
 
 #include "libgimpbase/gimpbase.h"
diff --git a/app/core/gimpbrushgenerated.c b/app/core/gimpbrushgenerated.c
index 8bc97e2..2dd3774 100644
--- a/app/core/gimpbrushgenerated.c
+++ b/app/core/gimpbrushgenerated.c
@@ -19,7 +19,7 @@
 
 #include "config.h"
 
-#include <glib-object.h>
+#include <gegl.h>
 
 #include "libgimpbase/gimpbase.h"
 #include "libgimpmath/gimpmath.h"
@@ -483,7 +483,8 @@ gimp_brush_generated_calc (GimpBrushGenerated      *brush,
                                       &s, &c, &x_axis, &y_axis);
 
   mask = temp_buf_new (half_width  * 2 + 1,
-                       half_height * 2 + 1, 1);
+                       half_height * 2 + 1,
+                       babl_format ("Y u8"));
 
   centerp = temp_buf_get_data (mask) + half_height * mask->width + half_width;
 
diff --git a/app/core/gimpbrushpipe-load.c b/app/core/gimpbrushpipe-load.c
index 56a3b6d..cfbe128 100644
--- a/app/core/gimpbrushpipe-load.c
+++ b/app/core/gimpbrushpipe-load.c
@@ -33,7 +33,7 @@
 #define _O_BINARY 0
 #endif
 
-#include <glib-object.h>
+#include <gegl.h>
 #include <glib/gstdio.h>
 
 #ifdef G_OS_WIN32
diff --git a/app/core/gimpbrushpipe.c b/app/core/gimpbrushpipe.c
index e0d5b40..655fc63 100644
--- a/app/core/gimpbrushpipe.c
+++ b/app/core/gimpbrushpipe.c
@@ -18,7 +18,7 @@
 
 #include "config.h"
 
-#include <glib-object.h>
+#include <gegl.h>
 
 #include "libgimpmath/gimpmath.h"
 
diff --git a/app/core/gimpbuffer.c b/app/core/gimpbuffer.c
index e164378..139476a 100644
--- a/app/core/gimpbuffer.c
+++ b/app/core/gimpbuffer.c
@@ -196,11 +196,9 @@ gimp_buffer_get_new_preview (GimpViewable *viewable,
                              gint          height)
 {
   GimpBuffer *buffer = GIMP_BUFFER (viewable);
-  const Babl *format = gimp_buffer_get_format (buffer);
   TempBuf    *preview;
 
-  preview = temp_buf_new (width, height,
-                          babl_format_get_bytes_per_pixel (format));
+  preview = temp_buf_new (width, height, gimp_buffer_get_format (buffer));
 
   gegl_buffer_get (buffer->buffer, NULL,
                    MIN ((gdouble) width  / (gdouble) gimp_buffer_get_width (buffer),
diff --git a/app/core/gimpdrawable-preview.c b/app/core/gimpdrawable-preview.c
index 06be6a8..b921874 100644
--- a/app/core/gimpdrawable-preview.c
+++ b/app/core/gimpdrawable-preview.c
@@ -33,6 +33,8 @@
 
 #include "config/gimpcoreconfig.h"
 
+#include "gegl/gimp-gegl-utils.h"
+
 #include "gimp.h"
 #include "gimpchannel.h"
 #include "gimpimage.h"
@@ -218,7 +220,8 @@ gimp_drawable_indexed_preview (GimpDrawable *drawable,
                      src_x, src_y, src_width, src_height,
                      FALSE);
 
-  preview_buf = temp_buf_new (dest_width, dest_height, bytes);
+  preview_buf = temp_buf_new (dest_width, dest_height,
+                              gimp_bpp_to_babl_format (bytes));
 
   pixel_region_init_temp_buf (&destPR, preview_buf,
                               0, 0, dest_width, dest_height);
diff --git a/app/core/gimpgradient.c b/app/core/gimpgradient.c
index 3174388..aabf95b 100644
--- a/app/core/gimpgradient.c
+++ b/app/core/gimpgradient.c
@@ -220,7 +220,7 @@ gimp_gradient_get_new_preview (GimpViewable *viewable,
       cur_x += dx;
     }
 
-  temp_buf = temp_buf_new (width, height, 4);
+  temp_buf = temp_buf_new (width, height, babl_format ("R'G'B'A u8"));
 
   buf = temp_buf_get_data (temp_buf);
 
diff --git a/app/core/gimppalette.c b/app/core/gimppalette.c
index 21357ea..e4901d9 100644
--- a/app/core/gimppalette.c
+++ b/app/core/gimppalette.c
@@ -211,7 +211,7 @@ gimp_palette_get_new_preview (GimpViewable *viewable,
   gint         cell_size;
   gint         x, y;
 
-  temp_buf = temp_buf_new (width, height, 3);
+  temp_buf = temp_buf_new (width, height, babl_format ("R'G'B' u8"));
   memset (temp_buf_get_data (temp_buf), 255, width * height * 3);
 
   if (palette->n_columns > 1)
diff --git a/app/core/gimppattern-load.c b/app/core/gimppattern-load.c
index 0ff399e..d272dd6 100644
--- a/app/core/gimppattern-load.c
+++ b/app/core/gimppattern-load.c
@@ -30,7 +30,7 @@
 
 #include <fcntl.h>
 
-#include <glib-object.h>
+#include <gegl.h>
 #include <glib/gstdio.h>
 
 #ifdef G_OS_WIN32
@@ -49,6 +49,8 @@
 
 #include "base/temp-buf.h"
 
+#include "gegl/gimp-gegl-utils.h"
+
 #include "gimppattern.h"
 #include "gimppattern-header.h"
 #include "gimppattern-load.h"
@@ -154,7 +156,9 @@ gimp_pattern_load (GimpContext  *context,
 
   g_free (name);
 
-  pattern->mask = temp_buf_new (header.width, header.height, header.bytes);
+  pattern->mask = temp_buf_new (header.width, header.height,
+                                gimp_bpp_to_babl_format (header.bytes));
+
   if (read (fd, temp_buf_get_data (pattern->mask),
             header.width * header.height * header.bytes) <
       header.width * header.height * header.bytes)
@@ -186,14 +190,9 @@ gimp_pattern_load_pixbuf (GimpContext  *context,
 {
   GimpPattern *pattern;
   GdkPixbuf   *pixbuf;
-  guchar      *pat_data;
-  guchar      *buf_data;
+  GeglBuffer  *src_buffer;
+  GeglBuffer  *dest_buffer;
   gchar       *name;
-  gint         width;
-  gint         height;
-  gint         bytes;
-  gint         rowstride;
-  gint         i;
 
   g_return_val_if_fail (filename != NULL, NULL);
   g_return_val_if_fail (g_path_is_absolute (filename), NULL);
@@ -218,21 +217,18 @@ gimp_pattern_load_pixbuf (GimpContext  *context,
                           NULL);
   g_free (name);
 
-  width     = gdk_pixbuf_get_width (pixbuf);
-  height    = gdk_pixbuf_get_height (pixbuf);
-  bytes     = gdk_pixbuf_get_n_channels (pixbuf);
-  rowstride = gdk_pixbuf_get_rowstride (pixbuf);
+  pattern->mask =
+    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 = temp_buf_new (width, height, bytes);
+  src_buffer  = gimp_pixbuf_create_buffer (pixbuf);
+  dest_buffer = gimp_temp_buf_create_buffer (pattern->mask, FALSE);
 
-  pat_data = gdk_pixbuf_get_pixels (pixbuf);
-  buf_data = temp_buf_get_data (pattern->mask);
+  gegl_buffer_copy (src_buffer, NULL, dest_buffer, NULL);
 
-  for (i = 0; i < height; i++)
-    {
-      memcpy (buf_data + i * width * bytes, pat_data, width * bytes);
-      pat_data += rowstride;
-    }
+  g_object_unref (src_buffer);
+  g_object_unref (dest_buffer);
 
   g_object_unref (pixbuf);
 
diff --git a/app/core/gimppattern.c b/app/core/gimppattern.c
index 2bf0992..d695951 100644
--- a/app/core/gimppattern.c
+++ b/app/core/gimppattern.c
@@ -155,10 +155,10 @@ gimp_pattern_get_new_preview (GimpViewable *viewable,
   copy_height = MIN (height, pattern->mask->height);
 
   temp_buf = temp_buf_new (copy_width, copy_height,
-                           pattern->mask->bytes);
+                           pattern->mask->format);
 
-  src_buffer  = gimp_temp_buf_create_buffer (pattern->mask, NULL, FALSE);
-  dest_buffer = gimp_temp_buf_create_buffer (temp_buf, NULL, FALSE);
+  src_buffer  = gimp_temp_buf_create_buffer (pattern->mask, FALSE);
+  dest_buffer = gimp_temp_buf_create_buffer (temp_buf, FALSE);
 
   gegl_buffer_copy (src_buffer,  GEGL_RECTANGLE (0, 0, copy_width, copy_height),
                     dest_buffer, GEGL_RECTANGLE (0, 0, 0, 0));
@@ -232,7 +232,7 @@ gimp_pattern_new (GimpContext *context,
                           "name", name,
                           NULL);
 
-  pattern->mask = temp_buf_new (32, 32, 3);
+  pattern->mask = temp_buf_new (32, 32, babl_format ("R'G'B' u8"));
 
   data = temp_buf_get_data (pattern->mask);
 
@@ -278,5 +278,5 @@ gimp_pattern_create_buffer (const GimpPattern *pattern)
 {
   g_return_val_if_fail (GIMP_IS_PATTERN (pattern), NULL);
 
-  return gimp_temp_buf_create_buffer (pattern->mask, NULL, FALSE);
+  return gimp_temp_buf_create_buffer (pattern->mask, FALSE);
 }
diff --git a/app/core/gimppatternclipboard.c b/app/core/gimppatternclipboard.c
index 2c65cf3..ada97a1 100644
--- a/app/core/gimppatternclipboard.c
+++ b/app/core/gimppatternclipboard.c
@@ -189,16 +189,14 @@ gimp_pattern_clipboard_buffer_changed (Gimp        *gimp,
   if (gimp->global_buffer)
     {
       GimpBuffer *buffer = gimp->global_buffer;
-      const Babl *format = gimp_buffer_get_format (buffer);
       gint        width;
       gint        height;
-      gint        bytes;
 
       width  = MIN (gimp_buffer_get_width  (buffer), 512);
       height = MIN (gimp_buffer_get_height (buffer), 512);
-      bytes  = babl_format_get_bytes_per_pixel (format);
 
-      pattern->mask = temp_buf_new (width, height, bytes);
+      pattern->mask = temp_buf_new (width, height,
+                                    gimp_buffer_get_format (buffer));
 
       gegl_buffer_get (gimp_buffer_get_buffer (buffer),
                        GEGL_RECTANGLE (0, 0, width, height), 1.0,
@@ -208,7 +206,7 @@ gimp_pattern_clipboard_buffer_changed (Gimp        *gimp,
     }
   else
     {
-      pattern->mask = temp_buf_new (16, 16, 3);
+      pattern->mask = temp_buf_new (16, 16, babl_format ("R'G'B' u8"));
       memset (temp_buf_get_data (pattern->mask), 255, 16 * 16 * 3);
     }
 
diff --git a/app/core/gimppreviewcache.c b/app/core/gimppreviewcache.c
index f3af22e..b493c74 100644
--- a/app/core/gimppreviewcache.c
+++ b/app/core/gimppreviewcache.c
@@ -17,7 +17,7 @@
 
 #include "config.h"
 
-#include <glib-object.h>
+#include <gegl.h>
 
 #include "core-types.h"
 
@@ -215,6 +215,7 @@ gimp_preview_cache_get (GSList **plist,
       gdouble  y_ratio;
       guchar  *src_data;
       guchar  *dest_data;
+      gint     bytes;
       gint     loop1;
       gint     loop2;
 
@@ -228,7 +229,7 @@ gimp_preview_cache_get (GSList **plist,
       pheight = pn.buf->height;
 
       /* Now get the real one and add to cache */
-      preview = temp_buf_new (width, height, pn.buf->bytes);
+      preview = temp_buf_new (width, height, pn.buf->format);
 
       /* preview from nearest bigger one */
       if (width)
@@ -244,6 +245,8 @@ gimp_preview_cache_get (GSList **plist,
       src_data  = temp_buf_get_data (pn.buf);
       dest_data = temp_buf_get_data (preview);
 
+      bytes = babl_format_get_bytes_per_pixel (preview->format);
+
       for (loop1 = 0 ; loop1 < height ; loop1++)
         for (loop2 = 0 ; loop2 < width ; loop2++)
           {
@@ -252,13 +255,13 @@ gimp_preview_cache_get (GSList **plist,
             guchar *dest_pixel;
 
             src_pixel = src_data +
-              ((gint) (loop2 * x_ratio)) * preview->bytes +
-              ((gint) (loop1 * y_ratio)) * pwidth * preview->bytes;
+              ((gint) (loop2 * x_ratio)) * bytes +
+              ((gint) (loop1 * y_ratio)) * pwidth * bytes;
 
             dest_pixel = dest_data +
-              (loop2 + loop1 * width) * preview->bytes;
+              (loop2 + loop1 * width) * bytes;
 
-            for (i = 0; i < preview->bytes; i++)
+            for (i = 0; i < bytes; i++)
               *dest_pixel++ = *src_pixel++;
           }
 
diff --git a/app/core/gimpviewable.c b/app/core/gimpviewable.c
index c53ca89..0f776c4 100644
--- a/app/core/gimpviewable.c
+++ b/app/core/gimpviewable.c
@@ -359,12 +359,12 @@ gimp_viewable_real_get_new_pixbuf (GimpViewable *viewable,
       GeglBuffer *dest_buffer;
 
       pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
-                               temp_buf->bytes == 4 || temp_buf->bytes == 2,
+                               babl_format_has_alpha (temp_buf->format),
                                8,
                                temp_buf->width,
                                temp_buf->height);
 
-      src_buffer  = gimp_temp_buf_create_buffer (temp_buf, NULL, FALSE);
+      src_buffer  = gimp_temp_buf_create_buffer (temp_buf, FALSE);
       dest_buffer = gimp_pixbuf_create_buffer (pixbuf);
 
       gegl_buffer_copy (src_buffer, NULL, dest_buffer, NULL);
@@ -812,7 +812,7 @@ gimp_viewable_get_dummy_preview (GimpViewable  *viewable,
 
   pixbuf = gimp_viewable_get_dummy_pixbuf (viewable, width, height, bpp);
 
-  buf = temp_buf_new (width, height, bpp);
+  buf = temp_buf_new (width, height, gimp_bpp_to_babl_format (bpp));
 
   src  = gdk_pixbuf_get_pixels (pixbuf);
   dest = temp_buf_get_data (buf);
diff --git a/app/gegl/gimp-gegl-utils.c b/app/gegl/gimp-gegl-utils.c
index 7995476..9d1f853 100644
--- a/app/gegl/gimp-gegl-utils.c
+++ b/app/gegl/gimp-gegl-utils.c
@@ -246,30 +246,20 @@ gimp_gegl_buffer_get_tiles (GeglBuffer *buffer)
 }
 
 GeglBuffer  *
-gimp_temp_buf_create_buffer (TempBuf    *temp_buf,
-                             const Babl *format,
-                             gboolean    take_ownership)
+gimp_temp_buf_create_buffer (TempBuf  *temp_buf,
+                             gboolean  take_ownership)
 {
   GeglBuffer *buffer;
-  gint        width, height, bytes;
 
   g_return_val_if_fail (temp_buf != NULL, NULL);
-  g_return_val_if_fail (format == NULL ||
-                        babl_format_get_bytes_per_pixel (format) ==
-                        temp_buf->bytes, NULL);
-
-  width  = temp_buf->width;
-  height = temp_buf->height;
-  bytes  = temp_buf->bytes;
-
-  if (! format)
-    format = gimp_bpp_to_babl_format (bytes);
 
   buffer =
     gegl_buffer_linear_new_from_data (temp_buf_get_data (temp_buf),
-                                      format,
-                                      GEGL_RECTANGLE (0, 0, width, height),
-                                      width * bytes,
+                                      temp_buf->format,
+                                      GEGL_RECTANGLE (0, 0,
+                                                      temp_buf->width,
+                                                      temp_buf->height),
+                                      GEGL_AUTO_ROWSTRIDE,
                                       take_ownership ?
                                       (GDestroyNotify) temp_buf_free : NULL,
                                       take_ownership ?
diff --git a/app/gegl/gimp-gegl-utils.h b/app/gegl/gimp-gegl-utils.h
index ec0ae23..f0707a3 100644
--- a/app/gegl/gimp-gegl-utils.h
+++ b/app/gegl/gimp-gegl-utils.h
@@ -42,7 +42,6 @@ GeglBuffer  * gimp_tile_manager_create_buffer    (TileManager           *tm,
 TileManager * gimp_gegl_buffer_get_tiles         (GeglBuffer            *buffer);
 
 GeglBuffer  * gimp_temp_buf_create_buffer        (TempBuf               *temp_buf,
-                                                  const Babl            *format,
                                                   gboolean               take_ownership);
 TempBuf     * gimp_gegl_buffer_get_temp_buf      (GeglBuffer            *buffer);
 
diff --git a/app/paint/gimpbrushcore.c b/app/paint/gimpbrushcore.c
index f23d602..5b11eea 100644
--- a/app/paint/gimpbrushcore.c
+++ b/app/paint/gimpbrushcore.c
@@ -828,10 +828,9 @@ gimp_brush_core_get_paint_buffer (GimpPaintCore    *paint_core,
   if ((x2 - x1) && (y2 - y1))
     {
       const Babl *format = gimp_drawable_get_format_with_alpha (drawable);
-      gint        bytes  = babl_format_get_bytes_per_pixel (format);
       TempBuf    *temp_buf;
 
-      temp_buf = temp_buf_new ((x2 - x1), (y2 - y1), bytes);
+      temp_buf = temp_buf_new ((x2 - x1), (y2 - y1), format);
 
       *paint_buffer_x = x1;
       *paint_buffer_y = y1;
@@ -839,8 +838,7 @@ gimp_brush_core_get_paint_buffer (GimpPaintCore    *paint_core,
       if (paint_core->paint_buffer)
         g_object_unref (paint_core->paint_buffer);
 
-      paint_core->paint_buffer = gimp_temp_buf_create_buffer (temp_buf, format,
-                                                              TRUE);
+      paint_core->paint_buffer = gimp_temp_buf_create_buffer (temp_buf, TRUE);
 
       return paint_core->paint_buffer;
     }
@@ -946,9 +944,7 @@ gimp_brush_core_paste_canvas (GimpBrushCore            *core,
       off_x = (x < 0) ? -x : 0;
       off_y = (y < 0) ? -y : 0;
 
-      paint_mask = gimp_temp_buf_create_buffer ((TempBuf *) brush_mask,
-                                                babl_format ("Y u8"),
-                                                FALSE);
+      paint_mask = gimp_temp_buf_create_buffer ((TempBuf *) brush_mask, FALSE);
 
       gimp_paint_core_paste (paint_core, paint_mask,
                              GEGL_RECTANGLE (off_x, off_y,
@@ -997,9 +993,7 @@ gimp_brush_core_replace_canvas (GimpBrushCore            *core,
       off_x = (x < 0) ? -x : 0;
       off_y = (y < 0) ? -y : 0;
 
-      paint_mask = gimp_temp_buf_create_buffer ((TempBuf *) brush_mask,
-                                                babl_format ("Y u8"),
-                                                FALSE);
+      paint_mask = gimp_temp_buf_create_buffer ((TempBuf *) brush_mask, FALSE);
 
       gimp_paint_core_replace (paint_core, paint_mask,
                                GEGL_RECTANGLE (off_x, off_y,
@@ -1127,7 +1121,8 @@ gimp_brush_core_subsample_mask (GimpBrushCore *core,
     }
 
   dest = temp_buf_new (mask->width  + 2,
-                       mask->height + 2, 1);
+                       mask->height + 2,
+                       babl_format ("Y u8"));
   temp_buf_data_clear (dest);
 
   /* Allocate and initialize the accum buffer */
@@ -1207,7 +1202,8 @@ gimp_brush_core_pressurize_mask (GimpBrushCore *core,
     temp_buf_free (core->pressure_brush);
 
   core->pressure_brush = temp_buf_new (brush_mask->width  + 2,
-                                       brush_mask->height + 2, 1);
+                                       brush_mask->height + 2,
+                                       babl_format ("Y u8"));
   temp_buf_data_clear (core->pressure_brush);
 
 #ifdef FANCY_PRESSURE
@@ -1347,7 +1343,8 @@ gimp_brush_core_solidify_mask (GimpBrushCore *core,
     }
 
   dest = temp_buf_new (brush_mask->width  + 2,
-                       brush_mask->height + 2, 1);
+                       brush_mask->height + 2,
+                       babl_format ("Y u8"));
   temp_buf_data_clear (dest);
 
   core->solid_brushes[dest_offset_y][dest_offset_x] = dest;
@@ -1622,6 +1619,7 @@ gimp_brush_core_paint_line_pixmap_mask (GimpImage                *dest,
                                         gint                      width,
                                         GimpBrushApplicationMode  mode)
 {
+  gint    pixmap_bytes;
   guchar *b;
 
   /*  Make sure x, y are positive  */
@@ -1630,20 +1628,22 @@ gimp_brush_core_paint_line_pixmap_mask (GimpImage                *dest,
   while (y < 0)
     y += pixmap_mask->height;
 
+  pixmap_bytes = babl_format_get_bytes_per_pixel (pixmap_mask->format);
+
   /* Point to the approriate scanline */
   b = (temp_buf_get_data (pixmap_mask) +
-       (y % pixmap_mask->height) * pixmap_mask->width * pixmap_mask->bytes);
+       (y % pixmap_mask->height) * pixmap_mask->width * pixmap_bytes);
 
   if (mode == GIMP_BRUSH_SOFT && brush_mask)
     {
       const Babl   *fish;
       const guchar *mask     = (temp_buf_get_data (brush_mask) +
                                 (y % brush_mask->height) * brush_mask->width);
-      guchar       *line_buf = g_alloca (width * (pixmap_mask->bytes + 1));
+      guchar       *line_buf = g_alloca (width * (pixmap_bytes + 1));
       guchar       *l        = line_buf;
       gint          i;
 
-      fish = babl_fish (gimp_bpp_to_babl_format_with_alpha (pixmap_mask->bytes),
+      fish = babl_fish (gimp_bpp_to_babl_format_with_alpha (pixmap_bytes),
                         gimp_drawable_get_format_with_alpha (drawable));
 
       /* put the source pixmap's pixels, plus the mask's alpha, into
@@ -1653,7 +1653,7 @@ gimp_brush_core_paint_line_pixmap_mask (GimpImage                *dest,
       for (i = 0; i < width; i++)
         {
           gint    x_index = ((i + x) % pixmap_mask->width);
-          gint    p_bytes = pixmap_mask->bytes;
+          gint    p_bytes = pixmap_bytes;
           guchar *p       = b + x_index * p_bytes;
 
           while (p_bytes--)
@@ -1667,11 +1667,11 @@ gimp_brush_core_paint_line_pixmap_mask (GimpImage                *dest,
   else
     {
       const Babl *fish;
-      guchar     *line_buf = g_alloca (width * (pixmap_mask->bytes));
+      guchar     *line_buf = g_alloca (width * (pixmap_bytes));
       guchar     *l        = line_buf;
       gint        i;
 
-      fish = babl_fish (gimp_bpp_to_babl_format (pixmap_mask->bytes),
+      fish = babl_fish (gimp_bpp_to_babl_format (pixmap_bytes),
                         gimp_drawable_get_format_with_alpha (drawable));
 
       /* put the source pixmap's pixels, into one line, so we can use
@@ -1680,7 +1680,7 @@ gimp_brush_core_paint_line_pixmap_mask (GimpImage                *dest,
       for (i = 0; i < width; i++)
         {
           gint    x_index = ((i + x) % pixmap_mask->width);
-          gint    p_bytes = pixmap_mask->bytes;
+          gint    p_bytes = pixmap_bytes;
           guchar *p       = b + x_index * p_bytes;
 
           while (p_bytes--)
diff --git a/app/paint/gimpconvolve.c b/app/paint/gimpconvolve.c
index 7c0cce5..43cfd98 100644
--- a/app/paint/gimpconvolve.c
+++ b/app/paint/gimpconvolve.c
@@ -136,7 +136,6 @@ gimp_convolve_motion (GimpPaintCore    *paint_core,
   GeglBuffer          *paint_buffer;
   gint                 paint_buffer_x;
   gint                 paint_buffer_y;
-  const Babl          *format;
   TempBuf             *convolve_temp;
   GeglBuffer          *convolve_buffer;
   gdouble              fade_point;
@@ -182,13 +181,11 @@ gimp_convolve_motion (GimpPaintCore    *paint_core,
                                   brush_core->brush->mask->height / 2,
                                   rate);
 
-  format = gegl_buffer_get_format (paint_buffer);
-
   convolve_temp = temp_buf_new (gegl_buffer_get_width  (paint_buffer),
                                 gegl_buffer_get_height (paint_buffer),
-                                babl_format_get_bytes_per_pixel (format));
+                                gegl_buffer_get_format (paint_buffer));
 
-  convolve_buffer = gimp_temp_buf_create_buffer (convolve_temp, format, TRUE);
+  convolve_buffer = gimp_temp_buf_create_buffer (convolve_temp, TRUE);
 
   gegl_buffer_copy (gimp_drawable_get_buffer (drawable),
                     GEGL_RECTANGLE (paint_buffer_x,
diff --git a/app/paint/gimpheal.c b/app/paint/gimpheal.c
index b01ad1a..f2c05ca 100644
--- a/app/paint/gimpheal.c
+++ b/app/paint/gimpheal.c
@@ -537,8 +537,7 @@ gimp_heal_motion (GimpSourceCore   *source_core,
                                     paint_area_width,
                                     paint_area_height));
 
-  mask_buffer = gimp_temp_buf_create_buffer ((TempBuf *) mask_buf,
-                                             NULL, FALSE);
+  mask_buffer = gimp_temp_buf_create_buffer ((TempBuf *) mask_buf, FALSE);
 
   gimp_heal (src_copy,
              GEGL_RECTANGLE (0, 0,
diff --git a/app/paint/gimpink.c b/app/paint/gimpink.c
index dd61198..bd24019 100644
--- a/app/paint/gimpink.c
+++ b/app/paint/gimpink.c
@@ -221,10 +221,9 @@ gimp_ink_get_paint_buffer (GimpPaintCore    *paint_core,
   if ((x2 - x1) && (y2 - y1))
     {
       const Babl *format = gimp_drawable_get_format_with_alpha (drawable);
-      gint        bytes  = babl_format_get_bytes_per_pixel (format);
       TempBuf    *temp_buf;
 
-      temp_buf = temp_buf_new ((x2 - x1), (y2 - y1), bytes);
+      temp_buf = temp_buf_new ((x2 - x1), (y2 - y1), format);
 
       *paint_buffer_x = x1;
       *paint_buffer_y = y1;
@@ -232,8 +231,7 @@ gimp_ink_get_paint_buffer (GimpPaintCore    *paint_core,
       if (paint_core->paint_buffer)
         g_object_unref (paint_core->paint_buffer);
 
-      paint_core->paint_buffer = gimp_temp_buf_create_buffer (temp_buf, format,
-                                                              TRUE);
+      paint_core->paint_buffer = gimp_temp_buf_create_buffer (temp_buf, TRUE);
 
       return paint_core->paint_buffer;
     }
diff --git a/app/paint/gimpsmudge.c b/app/paint/gimpsmudge.c
index 9959c91..b05368c 100644
--- a/app/paint/gimpsmudge.c
+++ b/app/paint/gimpsmudge.c
@@ -186,12 +186,9 @@ gimp_smudge_start (GimpPaintCore    *paint_core,
 
   /*  Allocate the accumulation buffer */
   accum_temp = temp_buf_new (accum_size, accum_size,
-                             gimp_drawable_bytes (drawable));
+                             gimp_drawable_get_format (drawable));
 
-  smudge->accum_buffer =
-    gimp_temp_buf_create_buffer (accum_temp,
-                                 gimp_drawable_get_format (drawable),
-                                 TRUE);
+  smudge->accum_buffer = gimp_temp_buf_create_buffer (accum_temp, TRUE);
 
   /*  adjust the x and y coordinates to the upper left corner of the
    *  accumulator
diff --git a/app/pdb/brush-cmds.c b/app/pdb/brush-cmds.c
index 6a28a61..4226eea 100644
--- a/app/pdb/brush-cmds.c
+++ b/app/pdb/brush-cmds.c
@@ -279,8 +279,8 @@ brush_get_info_invoker (GimpProcedure      *procedure,
         {
           width     = brush->mask->width;
           height    = brush->mask->height;
-          mask_bpp  = brush->mask->bytes;
-          color_bpp = brush->pixmap ? brush->pixmap->bytes : 0;
+          mask_bpp  = babl_format_get_bytes_per_pixel (brush->mask->format);
+          color_bpp = brush->pixmap ? babl_format_get_bytes_per_pixel (brush->pixmap->format) : 0;
         }
       else
         success = FALSE;
@@ -330,16 +330,15 @@ brush_get_pixels_invoker (GimpProcedure      *procedure,
         {
           width          = brush->mask->width;
           height         = brush->mask->height;
-          mask_bpp       = brush->mask->bytes;
-          num_mask_bytes = brush->mask->height * brush->mask->width *
-                           brush->mask->bytes;
+          mask_bpp       = babl_format_get_bytes_per_pixel (brush->mask->format);
+          num_mask_bytes = brush->mask->height * brush->mask->width * mask_bpp;
           mask_bytes     = g_memdup (temp_buf_get_data (brush->mask), num_mask_bytes);
 
           if (brush->pixmap)
             {
-              color_bpp       = brush->pixmap->bytes;
+              color_bpp       = babl_format_get_bytes_per_pixel (brush->pixmap->format);
               num_color_bytes = brush->pixmap->height * brush->pixmap->width *
-                                brush->pixmap->bytes;
+                                color_bpp;
               color_bytes     = g_memdup (temp_buf_get_data (brush->pixmap),
                                           num_color_bytes);
             }
diff --git a/app/pdb/drawable-cmds.c b/app/pdb/drawable-cmds.c
index 711ac49..c5af490 100644
--- a/app/pdb/drawable-cmds.c
+++ b/app/pdb/drawable-cmds.c
@@ -747,8 +747,8 @@ drawable_thumbnail_invoker (GimpProcedure      *procedure,
         {
           actual_width         = buf->width;
           actual_height        = buf->height;
-          bpp                  = buf->bytes;
-          thumbnail_data_count = actual_width * actual_height * bpp;
+          bpp                  = babl_format_get_bytes_per_pixel (buf->format);
+          thumbnail_data_count = temp_buf_get_data_size (buf);
           thumbnail_data       = g_memdup (temp_buf_get_data (buf),
                                            thumbnail_data_count);
 
@@ -827,8 +827,8 @@ drawable_sub_thumbnail_invoker (GimpProcedure      *procedure,
             {
               width                = buf->width;
               height               = buf->height;
-              bpp                  = buf->bytes;
-              thumbnail_data_count = buf->height * buf->width * buf->bytes;
+              bpp                  = babl_format_get_bytes_per_pixel (buf->format);
+              thumbnail_data_count = temp_buf_get_data_size (buf);
               thumbnail_data       = g_memdup (temp_buf_get_data (buf),
                                                thumbnail_data_count);
 
diff --git a/app/pdb/image-cmds.c b/app/pdb/image-cmds.c
index bc870be..5b91435 100644
--- a/app/pdb/image-cmds.c
+++ b/app/pdb/image-cmds.c
@@ -1714,8 +1714,8 @@ image_thumbnail_invoker (GimpProcedure      *procedure,
         {
           actual_width         = buf->width;
           actual_height        = buf->height;
-          bpp                  = buf->bytes;
-          thumbnail_data_count = actual_width * actual_height * bpp;
+          bpp                  = babl_format_get_bytes_per_pixel (buf->format);
+          thumbnail_data_count = temp_buf_get_data_size (buf);
           thumbnail_data       = g_memdup (temp_buf_get_data (buf),
                                            thumbnail_data_count);
 
diff --git a/app/pdb/pattern-cmds.c b/app/pdb/pattern-cmds.c
index c3d750b..c084ddb 100644
--- a/app/pdb/pattern-cmds.c
+++ b/app/pdb/pattern-cmds.c
@@ -62,7 +62,7 @@ pattern_get_info_invoker (GimpProcedure      *procedure,
         {
           width  = pattern->mask->width;
           height = pattern->mask->height;
-          bpp    = pattern->mask->bytes;
+          bpp    = babl_format_get_bytes_per_pixel (pattern->mask->format);
         }
       else
         success = FALSE;
@@ -108,9 +108,8 @@ pattern_get_pixels_invoker (GimpProcedure      *procedure,
         {
           width           = pattern->mask->width;
           height          = pattern->mask->height;
-          bpp             = pattern->mask->bytes;
-          num_color_bytes = pattern->mask->height * pattern->mask->width *
-                            pattern->mask->bytes;
+          bpp             = babl_format_get_bytes_per_pixel (pattern->mask->format);
+          num_color_bytes = temp_buf_get_data_size (pattern->mask);
           color_bytes     = g_memdup (temp_buf_get_data (pattern->mask),
                                       num_color_bytes);
         }
diff --git a/app/pdb/patterns-cmds.c b/app/pdb/patterns-cmds.c
index bd17a09..160e344 100644
--- a/app/pdb/patterns-cmds.c
+++ b/app/pdb/patterns-cmds.c
@@ -158,9 +158,8 @@ patterns_get_pattern_data_invoker (GimpProcedure      *procedure,
           actual_name = g_strdup (gimp_object_get_name (pattern));
           width       = pattern->mask->width;
           height      = pattern->mask->height;
-          mask_bpp    = pattern->mask->bytes;
-          length      = pattern->mask->height * pattern->mask->width *
-                        pattern->mask->bytes;
+          mask_bpp    = babl_format_get_bytes_per_pixel (pattern->mask->format);
+          length      = temp_buf_get_data_size (pattern->mask);
           mask_data   = g_memdup (temp_buf_get_data (pattern->mask), length);
         }
       else
diff --git a/app/text/gimpfont.c b/app/text/gimpfont.c
index 7944726..9ee002f 100644
--- a/app/text/gimpfont.c
+++ b/app/text/gimpfont.c
@@ -21,7 +21,7 @@
 
 #include "config.h"
 
-#include <glib-object.h>
+#include <gegl.h>
 
 #include <pango/pangocairo.h>
 
@@ -283,7 +283,7 @@ gimp_font_get_new_preview (GimpViewable *viewable,
 
   width = cairo_format_stride_for_width (CAIRO_FORMAT_A8, width);
 
-  temp_buf = temp_buf_new (width, height, 1);
+  temp_buf = temp_buf_new (width, height, babl_format ("Y' u8"));
   memset (temp_buf_get_data (temp_buf), 255, width * height);
 
   surface = cairo_image_surface_create_for_data (temp_buf_get_data (temp_buf),
diff --git a/app/tools/gimpiscissorstool.c b/app/tools/gimpiscissorstool.c
index 8670a3f..1a0c7f0 100644
--- a/app/tools/gimpiscissorstool.c
+++ b/app/tools/gimpiscissorstool.c
@@ -1338,7 +1338,7 @@ calculate_curve (GimpIscissorsTool *iscissors,
       if (iscissors->dp_buf)
         temp_buf_free (iscissors->dp_buf);
 
-      iscissors->dp_buf = temp_buf_new (width, height, 4);
+      iscissors->dp_buf = temp_buf_new (width, height, babl_format ("Y u32"));
 
       /*  find the optimal path of pixels from (x1, y1) to (x2, y2)  */
       find_optimal_path (iscissors->gradient_map, iscissors->dp_buf,
diff --git a/app/vectors/gimpvectors-preview.c b/app/vectors/gimpvectors-preview.c
index 7c4bfdb..259b3a0 100644
--- a/app/vectors/gimpvectors-preview.c
+++ b/app/vectors/gimpvectors-preview.c
@@ -55,7 +55,7 @@ gimp_vectors_get_new_preview (GimpViewable *viewable,
   xscale = ((gdouble) width)  / gimp_image_get_width  (gimp_item_get_image (item));
   yscale = ((gdouble) height) / gimp_image_get_height (gimp_item_get_image (item));
 
-  temp_buf = temp_buf_new (width, height, 1);
+  temp_buf = temp_buf_new (width, height, babl_format ("Y' u8"));
   data = temp_buf_get_data (temp_buf);
   memset (data, 255, width * height);
 
diff --git a/app/widgets/gimppatternselect.c b/app/widgets/gimppatternselect.c
index e500d0c..df579fa 100644
--- a/app/widgets/gimppatternselect.c
+++ b/app/widgets/gimppatternselect.c
@@ -119,7 +119,7 @@ gimp_pattern_select_run_callback (GimpPdbDialog  *dialog,
                                         G_TYPE_STRING,        gimp_object_get_name (object),
                                         GIMP_TYPE_INT32,      pattern->mask->width,
                                         GIMP_TYPE_INT32,      pattern->mask->height,
-                                        GIMP_TYPE_INT32,      pattern->mask->bytes,
+                                        GIMP_TYPE_INT32,      babl_format_get_bytes_per_pixel (pattern->mask->format),
                                         GIMP_TYPE_INT32,      array->length,
                                         GIMP_TYPE_INT8_ARRAY, array,
                                         GIMP_TYPE_INT32,      closing,
diff --git a/app/widgets/gimpviewrenderer.c b/app/widgets/gimpviewrenderer.c
index 6c57866..031f392 100644
--- a/app/widgets/gimpviewrenderer.c
+++ b/app/widgets/gimpviewrenderer.c
@@ -931,6 +931,7 @@ gimp_view_render_temp_buf_to_surface (TempBuf         *temp_buf,
   gint          i, j;
   gint          x1, y1;
   gint          x2, y2;
+  gint          bytes;
   gint          rowstride;
   gint          dest_stride;
   gboolean      color;
@@ -969,10 +970,11 @@ gimp_view_render_temp_buf_to_surface (TempBuf         *temp_buf,
    *  3)  If image is gray, then temp_buf should have bytes == {1, 2}
    */
 
-  color            = (temp_buf->bytes == 3 || temp_buf->bytes == 4);
-  has_alpha        = (temp_buf->bytes == 2 || temp_buf->bytes == 4);
+  bytes            = babl_format_get_bytes_per_pixel (temp_buf->format);
+  color            = (bytes == 3 || bytes == 4);
+  has_alpha        = babl_format_has_alpha (temp_buf->format);
   render_composite = (channel == -1);
-  rowstride        = temp_buf->width * temp_buf->bytes;
+  rowstride        = temp_buf->width * bytes;
 
   /*  render the checkerboard only if the temp_buf has alpha *and*
    *  we render a composite view
@@ -1015,7 +1017,7 @@ gimp_view_render_temp_buf_to_surface (TempBuf         *temp_buf,
   y2 = CLAMP (temp_buf->y + temp_buf->height, 0, dest_height);
 
   src = temp_buf_get_data (temp_buf) + ((y1 - temp_buf->y) * rowstride +
-                                    (x1 - temp_buf->x) * temp_buf->bytes);
+                                        (x1 - temp_buf->x) * bytes);
 
   for (i = 0; i < dest_height; i++)
     {
@@ -1048,7 +1050,7 @@ gimp_view_render_temp_buf_to_surface (TempBuf         *temp_buf,
             }
 
           /*  The stuff in the middle  */
-          for (j = x1; j < x2; j++, d += 4, s += temp_buf->bytes)
+          for (j = x1; j < x2; j++, d += 4, s += bytes)
             {
               if (has_alpha && render_composite)
                 {
diff --git a/app/widgets/gimpviewrendererbrush.c b/app/widgets/gimpviewrendererbrush.c
index ac0a363..27e5ef8 100644
--- a/app/widgets/gimpviewrendererbrush.c
+++ b/app/widgets/gimpviewrendererbrush.c
@@ -20,6 +20,7 @@
 
 #include "config.h"
 
+#include <gegl.h>
 #include <gtk/gtk.h>
 
 #include "widgets-types.h"
diff --git a/app/widgets/gimpviewrendererbuffer.c b/app/widgets/gimpviewrendererbuffer.c
index 2a783f5..961ccd7 100644
--- a/app/widgets/gimpviewrendererbuffer.c
+++ b/app/widgets/gimpviewrendererbuffer.c
@@ -20,6 +20,7 @@
 
 #include "config.h"
 
+#include <gegl.h>
 #include <gtk/gtk.h>
 
 #include "libgimpwidgets/gimpwidgets.h"
diff --git a/app/widgets/gimpviewrendererdrawable.c b/app/widgets/gimpviewrendererdrawable.c
index 01c5648..5d4423d 100644
--- a/app/widgets/gimpviewrendererdrawable.c
+++ b/app/widgets/gimpviewrendererdrawable.c
@@ -30,6 +30,8 @@
 
 #include "base/temp-buf.h"
 
+#include "gegl/gimp-gegl-utils.h"
+
 #include "core/gimpdrawable.h"
 #include "core/gimpdrawable-preview.h"
 #include "core/gimpimage.h"
@@ -166,7 +168,8 @@ gimp_view_renderer_drawable_render (GimpViewRenderer *renderer,
             {
               gint bytes = gimp_drawable_preview_bytes (drawable);
 
-              render_buf = temp_buf_new (1, 1, bytes);
+              render_buf = temp_buf_new (1, 1,
+                                         gimp_bpp_to_babl_format (bytes));
               temp_buf_data_clear (render_buf);
             }
         }
diff --git a/tools/pdbgen/pdb/brush.pdb b/tools/pdbgen/pdb/brush.pdb
index 561d827..798b0d8 100644
--- a/tools/pdbgen/pdb/brush.pdb
+++ b/tools/pdbgen/pdb/brush.pdb
@@ -243,8 +243,8 @@ HELP
     {
       width     = brush->mask->width;
       height    = brush->mask->height;
-      mask_bpp  = brush->mask->bytes;
-      color_bpp = brush->pixmap ? brush->pixmap->bytes : 0;
+      mask_bpp  = babl_format_get_bytes_per_pixel (brush->mask->format);
+      color_bpp = brush->pixmap ? babl_format_get_bytes_per_pixel (brush->pixmap->format) : 0;
     }
   else
     success = FALSE;
@@ -294,16 +294,15 @@ HELP
     {
       width          = brush->mask->width;
       height         = brush->mask->height;
-      mask_bpp       = brush->mask->bytes;
-      num_mask_bytes = brush->mask->height * brush->mask->width *
-                       brush->mask->bytes;
+      mask_bpp       = babl_format_get_bytes_per_pixel (brush->mask->format);
+      num_mask_bytes = brush->mask->height * brush->mask->width * mask_bpp;
       mask_bytes     = g_memdup (temp_buf_get_data (brush->mask), num_mask_bytes);
 
       if (brush->pixmap)
         {
-          color_bpp       = brush->pixmap->bytes;
+          color_bpp       = babl_format_get_bytes_per_pixel (brush->pixmap->format);
           num_color_bytes = brush->pixmap->height * brush->pixmap->width *
-                            brush->pixmap->bytes;
+                            color_bpp;
           color_bytes     = g_memdup (temp_buf_get_data (brush->pixmap),
                                       num_color_bytes);
         }
diff --git a/tools/pdbgen/pdb/drawable.pdb b/tools/pdbgen/pdb/drawable.pdb
index f52468c..984017d 100644
--- a/tools/pdbgen/pdb/drawable.pdb
+++ b/tools/pdbgen/pdb/drawable.pdb
@@ -731,8 +731,8 @@ HELP
     {
       actual_width         = buf->width;
       actual_height        = buf->height;
-      bpp                  = buf->bytes;
-      thumbnail_data_count = actual_width * actual_height * bpp;
+      bpp                  = babl_format_get_bytes_per_pixel (buf->format);
+      thumbnail_data_count = temp_buf_get_data_size (buf);
       thumbnail_data       = g_memdup (temp_buf_get_data (buf),
                                        thumbnail_data_count);
 
@@ -812,8 +812,8 @@ HELP
         {
           width                = buf->width;
           height               = buf->height;
-          bpp                  = buf->bytes;
-          thumbnail_data_count = buf->height * buf->width * buf->bytes;
+          bpp                  = babl_format_get_bytes_per_pixel (buf->format);
+          thumbnail_data_count = temp_buf_get_data_size (buf);
           thumbnail_data       = g_memdup (temp_buf_get_data (buf),
                                            thumbnail_data_count);
 
diff --git a/tools/pdbgen/pdb/image.pdb b/tools/pdbgen/pdb/image.pdb
index 6d10240..0b4fb7f 100644
--- a/tools/pdbgen/pdb/image.pdb
+++ b/tools/pdbgen/pdb/image.pdb
@@ -2862,8 +2862,8 @@ HELP
     {
       actual_width         = buf->width;
       actual_height        = buf->height;
-      bpp                  = buf->bytes;
-      thumbnail_data_count = actual_width * actual_height * bpp;
+      bpp                  = babl_format_get_bytes_per_pixel (buf->format);
+      thumbnail_data_count = temp_buf_get_data_size (buf);
       thumbnail_data       = g_memdup (temp_buf_get_data (buf),
                                        thumbnail_data_count);
 
diff --git a/tools/pdbgen/pdb/pattern.pdb b/tools/pdbgen/pdb/pattern.pdb
index a3b55fd..7b90524 100644
--- a/tools/pdbgen/pdb/pattern.pdb
+++ b/tools/pdbgen/pdb/pattern.pdb
@@ -49,7 +49,7 @@ HELP
     {
       width  = pattern->mask->width;
       height = pattern->mask->height;
-      bpp    = pattern->mask->bytes;
+      bpp    = babl_format_get_bytes_per_pixel (pattern->mask->format);
     }
   else
     success = FALSE;
@@ -97,9 +97,8 @@ HELP
     {
       width           = pattern->mask->width;
       height          = pattern->mask->height;
-      bpp             = pattern->mask->bytes;
-      num_color_bytes = pattern->mask->height * pattern->mask->width *
-	                pattern->mask->bytes;
+      bpp             = babl_format_get_bytes_per_pixel (pattern->mask->format);
+      num_color_bytes = temp_buf_get_data_size (pattern->mask);
       color_bytes     = g_memdup (temp_buf_get_data (pattern->mask),
                                   num_color_bytes);
     }
diff --git a/tools/pdbgen/pdb/patterns.pdb b/tools/pdbgen/pdb/patterns.pdb
index e341a1f..68cfe49 100644
--- a/tools/pdbgen/pdb/patterns.pdb
+++ b/tools/pdbgen/pdb/patterns.pdb
@@ -136,9 +136,8 @@ sub patterns_get_pattern_data {
       actual_name = g_strdup (gimp_object_get_name (pattern));
       width       = pattern->mask->width;
       height      = pattern->mask->height;
-      mask_bpp    = pattern->mask->bytes;
-      length      = pattern->mask->height * pattern->mask->width *
-	            pattern->mask->bytes;
+      mask_bpp    = babl_format_get_bytes_per_pixel (pattern->mask->format);
+      length      = temp_buf_get_data_size (pattern->mask);
       mask_data   = g_memdup (temp_buf_get_data (pattern->mask), length);
     }
   else



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