[gimp] libgimp: add gimp_drawable_get_format()



commit 79464eefcea649661cc312a113fc197c37c5a269
Author: Michael Natterer <mitch gimp org>
Date:   Mon Apr 2 20:43:38 2012 +0200

    libgimp: add gimp_drawable_get_format()

 libgimp/gimp.def       |    3 +-
 libgimp/gimpdrawable.c |   53 ++++++++++++++++++++++++++++++++++++++++++++++-
 libgimp/gimpdrawable.h |    2 +
 3 files changed, 55 insertions(+), 3 deletions(-)
---
diff --git a/libgimp/gimp.def b/libgimp/gimp.def
index 6cc2416..efc0244 100644
--- a/libgimp/gimp.def
+++ b/libgimp/gimp.def
@@ -177,12 +177,13 @@ EXPORTS
 	gimp_drawable_free_shadow
 	gimp_drawable_get
 	gimp_drawable_get_buffer
-	gimp_drawable_get_shadow_buffer
 	gimp_drawable_get_color_uchar
+	gimp_drawable_get_format
 	gimp_drawable_get_image
 	gimp_drawable_get_linked
 	gimp_drawable_get_name
 	gimp_drawable_get_pixel
+	gimp_drawable_get_shadow_buffer
 	gimp_drawable_get_sub_thumbnail
 	gimp_drawable_get_sub_thumbnail_data
 	gimp_drawable_get_tattoo
diff --git a/libgimp/gimpdrawable.c b/libgimp/gimpdrawable.c
index bddfd0c..e6c7965 100644
--- a/libgimp/gimpdrawable.c
+++ b/libgimp/gimpdrawable.c
@@ -650,7 +650,7 @@ gimp_drawable_attach_new_parasite (gint32          drawable_ID,
 
 /**
  * gimp_drawable_get_buffer:
- * @drawable_ID: the ID of the #GimpDrawableto  get the buffer for.
+ * @drawable_ID: the ID of the #GimpDrawable to get the buffer for.
  *
  * Returns a #GeglBuffer of a specified drawable. The buffer can be used
  * like any other GEGL buffer. Its data will we synced back with the core
@@ -687,7 +687,7 @@ gimp_drawable_get_buffer (gint32 drawable_ID)
 
 /**
  * gimp_drawable_get_shadow_buffer:
- * @drawable_ID: the ID of the #GimpDrawableto get the buffer for.
+ * @drawable_ID: the ID of the #GimpDrawable to get the buffer for.
  *
  * Returns a #GeglBuffer of a specified drawable's shadow tiles. The
  * buffer can be used like any other GEGL buffer. Its data will we
@@ -721,3 +721,52 @@ gimp_drawable_get_shadow_buffer (gint32 drawable_ID)
 
   return NULL;
 }
+
+/**
+ * gimp_drawable_get_format:
+ * @drawable_ID: the ID of the #GimpDrawable to get the format for.
+ *
+ * Returns the #Babl format of the drawable.
+ *
+ * Return value: The #Babl format.
+ *
+ * Since: GIMP 2.10
+ */
+const Babl *
+gimp_drawable_get_format (gint32 drawable_ID)
+{
+  switch (gimp_drawable_type (drawable_ID))
+    {
+    case GIMP_RGB_IMAGE:   return babl_format ("R'G'B' u8");
+    case GIMP_RGBA_IMAGE:  return babl_format ("R'G'B'A u8");
+    case GIMP_GRAY_IMAGE:  return babl_format ("Y' u8");
+    case GIMP_GRAYA_IMAGE: return babl_format ("Y'A u8");
+    case GIMP_INDEXED_IMAGE:
+    case GIMP_INDEXEDA_IMAGE:
+      {
+        gint32      image_ID = gimp_item_get_image (drawable_ID);
+        const Babl *pala;
+        const Babl *pal;
+        guchar     *cmap;
+        gint        n_cols;
+
+        cmap = gimp_image_get_colormap (image_ID, &n_cols);
+
+        babl_new_palette (NULL, &pal, &pala);
+        babl_palette_set_palette (pal, babl_format ("R'G'B' u8"),
+                                  cmap, n_cols);
+
+        g_free (cmap);
+
+        if (gimp_drawable_type (drawable_ID) == GIMP_INDEXEDA_IMAGE)
+          return pala;
+
+        return pal;
+      }
+
+    default:
+      g_warn_if_reached ();
+    }
+
+  return NULL;
+}
diff --git a/libgimp/gimpdrawable.h b/libgimp/gimpdrawable.h
index 3df1fc2..2bd03bb 100644
--- a/libgimp/gimpdrawable.h
+++ b/libgimp/gimpdrawable.h
@@ -45,6 +45,8 @@ struct _GimpDrawable
 GeglBuffer   * gimp_drawable_get_buffer             (gint32         drawable_ID);
 GeglBuffer   * gimp_drawable_get_shadow_buffer      (gint32         drawable_ID);
 
+const Babl   * gimp_drawable_get_format             (gint32         drawable_ID);
+
 GimpDrawable * gimp_drawable_get                    (gint32         drawable_ID);
 void           gimp_drawable_detach                 (GimpDrawable  *drawable);
 void           gimp_drawable_flush                  (GimpDrawable  *drawable);



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