[gimp/goat-invasion: 539/608] app: add gimp_babl_component_format() and use it in GimpImage
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/goat-invasion: 539/608] app: add gimp_babl_component_format() and use it in GimpImage
- Date: Fri, 27 Apr 2012 21:10:41 +0000 (UTC)
commit e47817f88a23a7ec59846b854344cec569200644
Author: Michael Natterer <mitch gimp org>
Date: Sun Apr 22 19:47:46 2012 +0200
app: add gimp_babl_component_format() and use it in GimpImage
app/core/gimpimage.c | 40 ++++++++++++++++++++++++++++++++------
app/gegl/gimp-babl.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++
app/gegl/gimp-babl.h | 3 ++
3 files changed, 87 insertions(+), 7 deletions(-)
---
diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c
index 9ef7bbf..868c04e 100644
--- a/app/core/gimpimage.c
+++ b/app/core/gimpimage.c
@@ -1551,7 +1551,12 @@ gimp_image_get_mask_format (const GimpImage *image)
{
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
- return babl_format ("Y u8");
+ switch (gimp_image_get_precision (image))
+ {
+ case GIMP_PRECISION_U8: return babl_format ("Y u8");
+ }
+
+ g_return_val_if_reached (NULL);
}
gint
@@ -2061,12 +2066,33 @@ gimp_image_get_component_format (const GimpImage *image,
switch (channel)
{
- case GIMP_RED_CHANNEL: return babl_format ("R' u8");
- case GIMP_GREEN_CHANNEL: return babl_format ("G' u8");
- case GIMP_BLUE_CHANNEL: return babl_format ("B' u8");
- case GIMP_GRAY_CHANNEL: return babl_format ("Y' u8");
- case GIMP_INDEXED_CHANNEL: return babl_format ("Y' u8"); /* XXX: seems wrong */
- case GIMP_ALPHA_CHANNEL: return babl_format ("A u8");
+ case GIMP_RED_CHANNEL:
+ return gimp_babl_component_format (GIMP_RGB,
+ gimp_image_get_precision (image),
+ RED);
+
+ case GIMP_GREEN_CHANNEL:
+ return gimp_babl_component_format (GIMP_RGB,
+ gimp_image_get_precision (image),
+ GREEN);
+
+ case GIMP_BLUE_CHANNEL:
+ return gimp_babl_component_format (GIMP_RGB,
+ gimp_image_get_precision (image),
+ BLUE);
+
+ case GIMP_ALPHA_CHANNEL:
+ return gimp_babl_component_format (GIMP_RGB,
+ gimp_image_get_precision (image),
+ ALPHA);
+
+ case GIMP_GRAY_CHANNEL:
+ return gimp_babl_component_format (GIMP_GRAY,
+ gimp_image_get_precision (image),
+ GRAY);
+
+ case GIMP_INDEXED_CHANNEL:
+ return babl_format ("Y' u8"); /* XXX: seems wrong */
}
return NULL;
diff --git a/app/gegl/gimp-babl.c b/app/gegl/gimp-babl.c
index f7d3b1f..78a0717 100644
--- a/app/gegl/gimp-babl.c
+++ b/app/gegl/gimp-babl.c
@@ -206,3 +206,54 @@ gimp_babl_format (GimpImageBaseType base_type,
g_return_val_if_reached (NULL);
}
+
+const Babl *
+gimp_babl_component_format (GimpImageBaseType base_type,
+ GimpPrecision precision,
+ gint index)
+{
+ switch (base_type)
+ {
+ case GIMP_RGB:
+ switch (precision)
+ {
+ case GIMP_PRECISION_U8:
+ switch (index)
+ {
+ case 0: return babl_format ("R' u8");
+ case 1: return babl_format ("G' u8");
+ case 2: return babl_format ("B' u8");
+ case 3: return babl_format ("A u8");
+ default:
+ break;
+ }
+
+ default:
+ break;
+ }
+ break;
+
+ case GIMP_GRAY:
+ switch (precision)
+ {
+ case GIMP_PRECISION_U8:
+ switch (index)
+ {
+ case 0: return babl_format ("Y' u8");
+ case 1: return babl_format ("A u8");
+ default:
+ break;
+ }
+
+ default:
+ break;
+ }
+ break;
+
+ case GIMP_INDEXED:
+ /* need to use the image's api for this */
+ break;
+ }
+
+ g_return_val_if_reached (NULL);
+}
diff --git a/app/gegl/gimp-babl.h b/app/gegl/gimp-babl.h
index 1a50b1d..efadeae 100644
--- a/app/gegl/gimp-babl.h
+++ b/app/gegl/gimp-babl.h
@@ -32,6 +32,9 @@ GimpPrecision gimp_babl_format_get_precision (const Babl *format);
const Babl * gimp_babl_format (GimpImageBaseType base_type,
GimpPrecision precision,
gboolean with_alpha);
+const Babl * gimp_babl_component_format (GimpImageBaseType base_type,
+ GimpPrecision precision,
+ gint index);
#endif /* __GIMP_BABL_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]