[gimp/metadata-browser] app: remove "dest" parameter from temp_buf_copy() and always return a new copy



commit c78e7aeff0b0cacf7e9dc0ff8b48d7452834e981
Author: Michael Natterer <mitch gimp org>
Date:   Sun Apr 8 00:25:14 2012 +0200

    app: remove "dest" parameter from temp_buf_copy() and always return a new copy
    
    Also remove the color conversion functions in temp-buf.c

 app/base/temp-buf.c            |  136 ++-------------------------------------
 app/base/temp-buf.h            |    3 +-
 app/core/gimpbrush-transform.c |    8 +-
 app/core/gimpbrush.c           |    4 +-
 app/core/gimppattern.c         |    2 +-
 app/core/gimpundo.c            |    2 +-
 app/core/gimpviewable.c        |    2 +-
 7 files changed, 17 insertions(+), 140 deletions(-)
---
diff --git a/app/base/temp-buf.c b/app/base/temp-buf.c
index 7e2d0af..16ffbac 100644
--- a/app/base/temp-buf.c
+++ b/app/base/temp-buf.c
@@ -28,8 +28,6 @@
 #include <glib-object.h>
 #include <glib/gstdio.h>
 
-#include "libgimpcolor/gimpcolor.h"
-
 #include "base-types.h"
 
 #include "paint-funcs/paint-funcs.h"
@@ -38,12 +36,6 @@
 #include "temp-buf.h"
 
 
-static void  temp_buf_to_color (TempBuf *src_buf,
-                                TempBuf *dest_buf);
-static void  temp_buf_to_gray  (TempBuf *src_buf,
-                                TempBuf *dest_buf);
-
-
 TempBuf *
 temp_buf_new (gint          width,
               gint          height,
@@ -68,38 +60,20 @@ temp_buf_new (gint          width,
 }
 
 TempBuf *
-temp_buf_copy (TempBuf *src,
-               TempBuf *dest)
+temp_buf_copy (TempBuf *src)
 {
+  TempBuf *dest;
+
   g_return_val_if_fail (src != NULL, NULL);
-  g_return_val_if_fail (! dest || (dest->width  == src->width &&
-                                   dest->height == src->height), NULL);
 
-  if (! dest)
-    dest = temp_buf_new (src->width, src->height, src->bytes);
+  dest = temp_buf_new (src->width, src->height, src->bytes);
 
   if (! dest)
     return NULL;
 
-  if (src->bytes != dest->bytes)
-    {
-      if (src->bytes == 4 && dest->bytes == 2)       /* RGBA  -> GRAYA */
-        temp_buf_to_gray (src, dest);
-      else if (src->bytes == 3 && dest->bytes == 1)  /* RGB   -> GRAY  */
-        temp_buf_to_gray (src, dest);
-      else if (src->bytes == 2 && dest->bytes == 4)  /* GRAYA -> RGBA  */
-        temp_buf_to_color (src, dest);
-      else if (src->bytes == 1 && dest->bytes == 3)  /* GRAY  -> RGB   */
-        temp_buf_to_color (src, dest);
-      else
-        g_warning ("temp_buf_copy(): unimplemented color conversion");
-    }
-  else
-    {
-      memcpy (temp_buf_get_data (dest),
-              temp_buf_get_data (src),
-              temp_buf_get_data_size (src));
-    }
+  memcpy (temp_buf_get_data (dest),
+          temp_buf_get_data (src),
+          temp_buf_get_data_size (src));
 
   return dest;
 }
@@ -325,99 +299,3 @@ temp_buf_dump (TempBuf     *buf,
 
   close (fd);
 }
-
-
-/*  The conversion routines  */
-
-static void
-temp_buf_to_color (TempBuf *src_buf,
-                   TempBuf *dest_buf)
-{
-  guchar *src;
-  guchar *dest;
-  glong   num_pixels;
-
-  src  = temp_buf_get_data (src_buf);
-  dest = temp_buf_get_data (dest_buf);
-
-  num_pixels = src_buf->width * src_buf->height;
-
-  switch (dest_buf->bytes)
-    {
-    case 3:
-      g_return_if_fail (src_buf->bytes == 1);
-      while (num_pixels--)
-        {
-          guchar tmp;
-
-          *dest++ = tmp = *src++;
-          *dest++ = tmp;
-          *dest++ = tmp;
-        }
-      break;
-
-    case 4:
-      g_return_if_fail (src_buf->bytes == 2);
-      while (num_pixels--)
-        {
-          guchar tmp;
-
-          *dest++ = tmp = *src++;
-          *dest++ = tmp;
-          *dest++ = tmp;
-
-          *dest++ = *src++;  /* alpha channel */
-        }
-      break;
-
-    default:
-      g_return_if_reached ();
-      break;
-    }
-}
-
-static void
-temp_buf_to_gray (TempBuf *src_buf,
-                  TempBuf *dest_buf)
-{
-  const guchar *src;
-  guchar       *dest;
-  glong         num_pixels;
-
-  src  = temp_buf_get_data (src_buf);
-  dest = temp_buf_get_data (dest_buf);
-
-  num_pixels = src_buf->width * src_buf->height;
-
-  switch (dest_buf->bytes)
-    {
-    case 1:
-      g_return_if_fail (src_buf->bytes == 3);
-      while (num_pixels--)
-        {
-          gint lum = GIMP_RGB_LUMINANCE (src[0], src[1], src[2]) + 0.5;
-
-          *dest++ = (guchar) lum;
-
-          src += 3;
-        }
-      break;
-
-    case 2:
-      g_return_if_fail (src_buf->bytes == 4);
-      while (num_pixels--)
-        {
-          gint lum = GIMP_RGB_LUMINANCE (src[0], src[1], src[2]) + 0.5;
-
-          *dest++ = (guchar) lum;
-          *dest++ = src[3];  /* alpha channel */
-
-          src += 4;
-        }
-      break;
-
-    default:
-      g_return_if_reached ();
-      break;
-    }
-}
diff --git a/app/base/temp-buf.h b/app/base/temp-buf.h
index b12bae8..dd43a41 100644
--- a/app/base/temp-buf.h
+++ b/app/base/temp-buf.h
@@ -35,8 +35,7 @@ struct _TempBuf
 TempBuf * temp_buf_new           (gint           width,
                                   gint           height,
                                   gint           bytes);
-TempBuf * temp_buf_copy          (TempBuf       *src,
-                                  TempBuf       *dest);
+TempBuf * temp_buf_copy          (TempBuf       *src);
 TempBuf * temp_buf_scale         (TempBuf       *buf,
                                   gint           width,
                                   gint           height) G_GNUC_WARN_UNUSED_RESULT;
diff --git a/app/core/gimpbrush-transform.c b/app/core/gimpbrush-transform.c
index cf5778e..bcb014b 100644
--- a/app/core/gimpbrush-transform.c
+++ b/app/core/gimpbrush-transform.c
@@ -178,7 +178,7 @@ gimp_brush_real_transform_mask (GimpBrush *brush,
                                scale, aspect_ratio, angle, &matrix);
 
   if (gimp_matrix3_is_identity (&matrix))
-    return temp_buf_copy (source, NULL);
+    return temp_buf_copy (source);
 
   src_width  = source->width;
   src_height = source->height;
@@ -340,7 +340,7 @@ gimp_brush_real_transform_mask (GimpBrush *brush,
 
       gimp_brush_transform_fill_blur_kernel (blur_kernel, kernel_len);
 
-      blur_src = temp_buf_copy (result, NULL);
+      blur_src = temp_buf_copy (result);
 
       src_buffer  = gimp_temp_buf_create_buffer (blur_src, babl_format ("Y u8"),
                                                  TRUE);
@@ -474,7 +474,7 @@ gimp_brush_real_transform_pixmap (GimpBrush *brush,
                                scale, aspect_ratio, angle, &matrix);
 
   if (gimp_matrix3_is_identity (&matrix))
-    return temp_buf_copy (source, NULL);
+    return temp_buf_copy (source);
 
   src_width  = source->width;
   src_height = source->height;
@@ -641,7 +641,7 @@ gimp_brush_real_transform_pixmap (GimpBrush *brush,
 
       gimp_brush_transform_fill_blur_kernel (blur_kernel, kernel_len);
 
-      blur_src = temp_buf_copy (result, NULL);
+      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);
diff --git a/app/core/gimpbrush.c b/app/core/gimpbrush.c
index a156e5e..d969d81 100644
--- a/app/core/gimpbrush.c
+++ b/app/core/gimpbrush.c
@@ -618,7 +618,7 @@ gimp_brush_transform_mask (GimpBrush *brush,
           angle        == 0.0 &&
           hardness     == 1.0)
         {
-          mask = temp_buf_copy (brush->mask, NULL);
+          mask = temp_buf_copy (brush->mask);
         }
       else
         {
@@ -668,7 +668,7 @@ gimp_brush_transform_pixmap (GimpBrush *brush,
           angle        == 0.0 &&
           hardness     == 1.0)
         {
-          pixmap = temp_buf_copy (brush->pixmap, NULL);
+          pixmap = temp_buf_copy (brush->pixmap);
         }
       else
         {
diff --git a/app/core/gimppattern.c b/app/core/gimppattern.c
index 0772857..f5c6878 100644
--- a/app/core/gimppattern.c
+++ b/app/core/gimppattern.c
@@ -184,7 +184,7 @@ gimp_pattern_duplicate (GimpData *data)
 {
   GimpPattern *pattern = g_object_new (GIMP_TYPE_PATTERN, NULL);
 
-  pattern->mask = temp_buf_copy (GIMP_PATTERN (data)->mask, NULL);
+  pattern->mask = temp_buf_copy (GIMP_PATTERN (data)->mask);
 
   return GIMP_DATA (pattern);
 }
diff --git a/app/core/gimpundo.c b/app/core/gimpundo.c
index e4e7317..908b250 100644
--- a/app/core/gimpundo.c
+++ b/app/core/gimpundo.c
@@ -328,7 +328,7 @@ gimp_undo_get_new_preview (GimpViewable *viewable,
           return temp_buf_scale (undo->preview, preview_width, preview_height);
         }
 
-      return temp_buf_copy (undo->preview, NULL);
+      return temp_buf_copy (undo->preview);
     }
 
   return NULL;
diff --git a/app/core/gimpviewable.c b/app/core/gimpviewable.c
index 7eb2eb4..c53ca89 100644
--- a/app/core/gimpviewable.c
+++ b/app/core/gimpviewable.c
@@ -775,7 +775,7 @@ gimp_viewable_get_new_preview (GimpViewable *viewable,
                                             width, height);
 
   if (temp_buf)
-    return temp_buf_copy (temp_buf, NULL);
+    return temp_buf_copy (temp_buf);
 
   return NULL;
 }



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