[gimp/goat-invasion: 127/526] app: add image API to get Babl formats based on GimpImageType



commit 1bb0ead0c676b3f8105c34233056286f24c3c16f
Author: Michael Natterer <mitch gimp org>
Date:   Sun Mar 18 17:08:33 2012 +0100

    app: add image API to get Babl formats based on GimpImageType
    
    because we often have only a type and an image, but no drawable
    (yet) to ask for its types.

 app/core/gimpdrawable.c       |   74 +++-------------------------------------
 app/core/gimpdrawable.h       |    2 +-
 app/core/gimpimage-colormap.c |    4 +-
 app/core/gimpimage-colormap.h |    4 +-
 app/core/gimpimage.c          |   63 ++++++++++++++++++++++++++++++++++
 app/core/gimpimage.h          |    7 ++++
 6 files changed, 81 insertions(+), 73 deletions(-)
---
diff --git a/app/core/gimpdrawable.c b/app/core/gimpdrawable.c
index f665d1f..13b82dc 100644
--- a/app/core/gimpdrawable.c
+++ b/app/core/gimpdrawable.c
@@ -1830,90 +1830,28 @@ gimp_drawable_fill_by_type (GimpDrawable *drawable,
 const Babl *
 gimp_drawable_get_format (const GimpDrawable *drawable)
 {
-  GimpImageType type;
-
   g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
 
-  type = gimp_drawable_type (drawable);
-
-  switch (type)
-    {
-    case GIMP_RGB_IMAGE:    return babl_format ("RGB u8");
-    case GIMP_RGBA_IMAGE:   return babl_format ("RGBA u8");
-    case GIMP_GRAY_IMAGE:   return babl_format ("Y u8");
-    case GIMP_GRAYA_IMAGE:  return babl_format ("YA u8");
-    case GIMP_INDEXED_IMAGE:
-    case GIMP_INDEXEDA_IMAGE:
-      {
-        GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
-
-        return (type == GIMP_INDEXED_IMAGE ?
-                gimp_image_colormap_get_rgb_format (image) :
-                gimp_image_colormap_get_rgba_format (image));
-      }
-    }
-
-  g_warn_if_reached ();
-
-  return NULL;
+  return gimp_image_get_format (gimp_item_get_image (GIMP_ITEM (drawable)),
+                                gimp_drawable_type (drawable));
 }
 
 const Babl *
 gimp_drawable_get_format_with_alpha (const GimpDrawable *drawable)
 {
-  GimpImageType type;
-
   g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
 
-  type = gimp_drawable_type (drawable);
-
-  switch (type)
-    {
-    case GIMP_RGB_IMAGE:
-    case GIMP_RGBA_IMAGE:   return babl_format ("RGBA u8");
-    case GIMP_GRAY_IMAGE:
-    case GIMP_GRAYA_IMAGE:  return babl_format ("YA u8");
-    case GIMP_INDEXED_IMAGE:
-    case GIMP_INDEXEDA_IMAGE:
-      {
-        GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
-
-        return gimp_image_colormap_get_rgba_format (image);
-      }
-    }
-
-  g_warn_if_reached ();
-
-  return NULL;
+  return gimp_image_get_format_with_alpha (gimp_item_get_image (GIMP_ITEM (drawable)),
+                                           gimp_drawable_type (drawable));
 }
 
 const Babl *
 gimp_drawable_get_format_without_alpha (const GimpDrawable *drawable)
 {
-  GimpImageType type;
-
   g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
 
-  type = gimp_drawable_type (drawable);
-
-  switch (type)
-    {
-    case GIMP_RGB_IMAGE:
-    case GIMP_RGBA_IMAGE:   return babl_format ("RGB u8");
-    case GIMP_GRAY_IMAGE:
-    case GIMP_GRAYA_IMAGE:  return babl_format ("Y u8");
-    case GIMP_INDEXED_IMAGE:
-    case GIMP_INDEXEDA_IMAGE:
-      {
-        GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
-
-        return gimp_image_colormap_get_rgb_format (image);
-      }
-    }
-
-  g_warn_if_reached ();
-
-  return NULL;
+  return gimp_image_get_format_without_alpha (gimp_item_get_image (GIMP_ITEM (drawable)),
+                                              gimp_drawable_type (drawable));
 }
 
 gboolean
diff --git a/app/core/gimpdrawable.h b/app/core/gimpdrawable.h
index 77f27b6..0b55f07 100644
--- a/app/core/gimpdrawable.h
+++ b/app/core/gimpdrawable.h
@@ -225,7 +225,7 @@ void            gimp_drawable_fill_by_type       (GimpDrawable       *drawable,
                                                   GimpContext        *context,
                                                   GimpFillType        fill_type);
 
-const Babl    * gimp_drawable_get_format        (const GimpDrawable *drawable);
+const Babl    * gimp_drawable_get_format         (const GimpDrawable *drawable);
 const Babl    * gimp_drawable_get_format_with_alpha
                                                  (const GimpDrawable *drawable);
 const Babl    * gimp_drawable_get_format_without_alpha
diff --git a/app/core/gimpimage-colormap.c b/app/core/gimpimage-colormap.c
index 1c5d9d4..fbcb887 100644
--- a/app/core/gimpimage-colormap.c
+++ b/app/core/gimpimage-colormap.c
@@ -129,7 +129,7 @@ gimp_image_colormap_free (GimpImage *image)
 }
 
 const Babl *
-gimp_image_colormap_get_rgb_format  (GimpImage *image)
+gimp_image_colormap_get_rgb_format (const GimpImage *image)
 {
   g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
 
@@ -137,7 +137,7 @@ gimp_image_colormap_get_rgb_format  (GimpImage *image)
 }
 
 const Babl *
-gimp_image_colormap_get_rgba_format (GimpImage *image)
+gimp_image_colormap_get_rgba_format (const GimpImage *image)
 {
   g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
 
diff --git a/app/core/gimpimage-colormap.h b/app/core/gimpimage-colormap.h
index 9eb0694..b71e28b 100644
--- a/app/core/gimpimage-colormap.h
+++ b/app/core/gimpimage-colormap.h
@@ -26,8 +26,8 @@ void           gimp_image_colormap_init            (GimpImage       *image);
 void           gimp_image_colormap_dispose         (GimpImage       *image);
 void           gimp_image_colormap_free            (GimpImage       *image);
 
-const Babl   * gimp_image_colormap_get_rgb_format  (GimpImage       *image);
-const Babl   * gimp_image_colormap_get_rgba_format (GimpImage       *image);
+const Babl   * gimp_image_colormap_get_rgb_format  (const GimpImage *image);
+const Babl   * gimp_image_colormap_get_rgba_format (const GimpImage *image);
 
 GimpPalette  * gimp_image_get_colormap_palette     (GimpImage       *image);
 
diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c
index d2c5b3a..0a8d856 100644
--- a/app/core/gimpimage.c
+++ b/app/core/gimpimage.c
@@ -1495,6 +1495,69 @@ gimp_image_get_combination_mode (GimpImageType dest_type,
   return valid_combinations[dest_type][src_bytes];
 }
 
+const Babl *
+gimp_image_get_format (const GimpImage *image,
+                       GimpImageType    type)
+{
+  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
+
+  switch (type)
+    {
+    case GIMP_RGB_IMAGE:      return babl_format ("RGB u8");
+    case GIMP_RGBA_IMAGE:     return babl_format ("RGBA u8");
+    case GIMP_GRAY_IMAGE:     return babl_format ("Y u8");
+    case GIMP_GRAYA_IMAGE:    return babl_format ("YA u8");
+    case GIMP_INDEXED_IMAGE:  return gimp_image_colormap_get_rgb_format (image);
+    case GIMP_INDEXEDA_IMAGE: return gimp_image_colormap_get_rgba_format (image);
+    }
+
+  g_warn_if_reached ();
+
+  return NULL;
+}
+
+const Babl *
+gimp_image_get_format_with_alpha (const GimpImage *image,
+                                  GimpImageType    type)
+{
+  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
+
+  switch (type)
+    {
+    case GIMP_RGB_IMAGE:
+    case GIMP_RGBA_IMAGE:     return babl_format ("RGBA u8");
+    case GIMP_GRAY_IMAGE:
+    case GIMP_GRAYA_IMAGE:    return babl_format ("YA u8");
+    case GIMP_INDEXED_IMAGE:
+    case GIMP_INDEXEDA_IMAGE: return gimp_image_colormap_get_rgba_format (image);
+    }
+
+  g_warn_if_reached ();
+
+  return NULL;
+}
+
+const Babl *
+gimp_image_get_format_without_alpha (const GimpImage *image,
+                                     GimpImageType    type)
+{
+  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
+
+  switch (type)
+    {
+    case GIMP_RGB_IMAGE:
+    case GIMP_RGBA_IMAGE:     return babl_format ("RGB u8");
+    case GIMP_GRAY_IMAGE:
+    case GIMP_GRAYA_IMAGE:    return babl_format ("Y u8");
+    case GIMP_INDEXED_IMAGE:
+    case GIMP_INDEXEDA_IMAGE: return gimp_image_colormap_get_rgb_format (image);
+    }
+
+  g_warn_if_reached ();
+
+  return NULL;
+}
+
 gint
 gimp_image_get_ID (const GimpImage *image)
 {
diff --git a/app/core/gimpimage.h b/app/core/gimpimage.h
index 30f7e0e..d111cd75 100644
--- a/app/core/gimpimage.h
+++ b/app/core/gimpimage.h
@@ -170,6 +170,13 @@ GimpImageType      gimp_image_base_type_with_alpha (const GimpImage  *image);
 CombinationMode    gimp_image_get_combination_mode (GimpImageType     dest_type,
                                                     gint              src_bytes);
 
+const Babl * gimp_image_get_format               (const GimpImage    *image,
+                                                  GimpImageType       type);
+const Babl * gimp_image_get_format_with_alpha    (const GimpImage    *image,
+                                                  GimpImageType       type);
+const Babl * gimp_image_get_format_without_alpha (const GimpImage    *image,
+                                                  GimpImageType       type);
+
 gint            gimp_image_get_ID                (const GimpImage    *image);
 GimpImage     * gimp_image_get_by_ID             (Gimp               *gimp,
                                                   gint                id);



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