[gimp/goat-invasion: 486/608] app: change gimp_image_get_format() to take a base_type and a with_alpha boolean
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/goat-invasion: 486/608] app: change gimp_image_get_format() to take a base_type and a with_alpha boolean
- Date: Fri, 27 Apr 2012 21:06:14 +0000 (UTC)
commit a6cd0f5e579fc00fbb5f36b881584fa7efe4a319
Author: Michael Natterer <mitch gimp org>
Date: Wed Apr 11 18:40:30 2012 +0200
app: change gimp_image_get_format() to take a base_type and a with_alpha boolean
which kills almost all remaining use of GimpImageType.
app/core/gimpdrawable-convert.c | 18 +++------
app/core/gimpdrawable.c | 10 +++--
app/core/gimpimage.c | 81 +++++++-------------------------------
app/core/gimpimage.h | 16 +++-----
app/core/gimplayer.c | 5 +-
app/paint/gimppaintbrush.c | 1 +
app/pdb/layer-cmds.c | 6 ++-
app/xcf/xcf-load.c | 7 +++-
tools/pdbgen/pdb/layer.pdb | 6 ++-
9 files changed, 52 insertions(+), 98 deletions(-)
---
diff --git a/app/core/gimpdrawable-convert.c b/app/core/gimpdrawable-convert.c
index c86e5c3..676ad87 100644
--- a/app/core/gimpdrawable-convert.c
+++ b/app/core/gimpdrawable-convert.c
@@ -42,10 +42,8 @@ gimp_drawable_convert_rgb (GimpDrawable *drawable,
g_return_if_fail (GIMP_IS_IMAGE (dest_image));
g_return_if_fail (! gimp_drawable_is_rgb (drawable));
- if (gimp_drawable_has_alpha (drawable))
- format = gimp_image_get_format (dest_image, GIMP_RGBA_IMAGE);
- else
- format = gimp_image_get_format (dest_image, GIMP_RGB_IMAGE);
+ format = gimp_image_get_format (dest_image, GIMP_RGB,
+ gimp_drawable_has_alpha (drawable));
dest_buffer =
gimp_gegl_buffer_new (GEGL_RECTANGLE (0, 0,
@@ -72,10 +70,8 @@ gimp_drawable_convert_grayscale (GimpDrawable *drawable,
g_return_if_fail (GIMP_IS_IMAGE (dest_image));
g_return_if_fail (! gimp_drawable_is_gray (drawable));
- if (gimp_drawable_has_alpha (drawable))
- format = gimp_image_get_format (dest_image, GIMP_GRAYA_IMAGE);
- else
- format = gimp_image_get_format (dest_image, GIMP_GRAY_IMAGE);
+ format = gimp_image_get_format (dest_image, GIMP_GRAY,
+ gimp_drawable_has_alpha (drawable));
dest_buffer =
gimp_gegl_buffer_new (GEGL_RECTANGLE (0, 0,
@@ -102,10 +98,8 @@ gimp_drawable_convert_indexed (GimpDrawable *drawable,
g_return_if_fail (GIMP_IS_IMAGE (dest_image));
g_return_if_fail (! gimp_drawable_is_indexed (drawable));
- if (gimp_drawable_has_alpha (drawable))
- format = gimp_image_get_format (dest_image, GIMP_INDEXEDA_IMAGE);
- else
- format = gimp_image_get_format (dest_image, GIMP_INDEXED_IMAGE);
+ format = gimp_image_get_format (dest_image, GIMP_INDEXED,
+ gimp_drawable_has_alpha (drawable));
dest_buffer =
gimp_gegl_buffer_new (GEGL_RECTANGLE (0, 0,
diff --git a/app/core/gimpdrawable.c b/app/core/gimpdrawable.c
index b5989c1..ea5a056 100644
--- a/app/core/gimpdrawable.c
+++ b/app/core/gimpdrawable.c
@@ -1598,8 +1598,9 @@ gimp_drawable_get_format_with_alpha (const GimpDrawable *drawable)
{
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
- return gimp_image_get_format_with_alpha (gimp_item_get_image (GIMP_ITEM (drawable)),
- gimp_drawable_type (drawable));
+ return gimp_image_get_format (gimp_item_get_image (GIMP_ITEM (drawable)),
+ gimp_drawable_get_base_type (drawable),
+ TRUE);
}
const Babl *
@@ -1607,8 +1608,9 @@ gimp_drawable_get_format_without_alpha (const GimpDrawable *drawable)
{
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
- return gimp_image_get_format_without_alpha (gimp_item_get_image (GIMP_ITEM (drawable)),
- gimp_drawable_type (drawable));
+ return gimp_image_get_format (gimp_item_get_image (GIMP_ITEM (drawable)),
+ gimp_drawable_get_base_type (drawable),
+ FALSE);
}
gboolean
diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c
index d8f0e0a..c49d0dc 100644
--- a/app/core/gimpimage.c
+++ b/app/core/gimpimage.c
@@ -1475,75 +1475,13 @@ gimp_image_get_combination_mode (GimpImageType dest_type,
}
const Babl *
-gimp_image_get_format (const GimpImage *image,
- GimpImageType type)
+gimp_image_get_format (const GimpImage *image,
+ GimpImageBaseType base_type,
+ gboolean with_alpha)
{
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
- switch (type)
- {
- 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: 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 ("R'G'B'A u8");
- case GIMP_GRAY_IMAGE:
- case GIMP_GRAYA_IMAGE: return babl_format ("Y'A 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 ("R'G'B' 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;
-}
-
-const Babl *
-gimp_image_get_layer_format (const GimpImage *image,
- gboolean with_alpha)
-{
- g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
-
- switch (GIMP_IMAGE_GET_PRIVATE (image)->base_type)
+ switch (base_type)
{
case GIMP_RGB:
if (with_alpha)
@@ -1568,6 +1506,17 @@ gimp_image_get_layer_format (const GimpImage *image,
}
const Babl *
+gimp_image_get_layer_format (const GimpImage *image,
+ gboolean with_alpha)
+{
+ g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
+
+ return gimp_image_get_format (image,
+ GIMP_IMAGE_GET_PRIVATE (image)->base_type,
+ with_alpha);
+}
+
+const Babl *
gimp_image_get_channel_format (const GimpImage *image)
{
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
diff --git a/app/core/gimpimage.h b/app/core/gimpimage.h
index f33215f..c8a250f 100644
--- a/app/core/gimpimage.h
+++ b/app/core/gimpimage.h
@@ -112,17 +112,13 @@ GimpImageBaseType gimp_image_base_type (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);
-
-const Babl * gimp_image_get_layer_format (const GimpImage *image,
+const Babl * gimp_image_get_format (const GimpImage *image,
+ GimpImageBaseType base_type,
gboolean with_alpha);
-const Babl * gimp_image_get_channel_format (const GimpImage *image);
-const Babl * gimp_image_get_mask_format (const GimpImage *image);
+const Babl * gimp_image_get_layer_format (const GimpImage *image,
+ gboolean with_alpha);
+const Babl * gimp_image_get_channel_format (const GimpImage *image);
+const Babl * gimp_image_get_mask_format (const GimpImage *image);
gint gimp_image_get_ID (const GimpImage *image);
GimpImage * gimp_image_get_by_ID (Gimp *gimp,
diff --git a/app/core/gimplayer.c b/app/core/gimplayer.c
index 34b9586..9d2b60e 100644
--- a/app/core/gimplayer.c
+++ b/app/core/gimplayer.c
@@ -1387,9 +1387,8 @@ gimp_layer_create_mask (const GimpLayer *layer,
if (! gimp_drawable_is_gray (drawable))
{
const Babl *copy_format =
- gimp_image_get_format (image,
- gimp_drawable_has_alpha (drawable) ?
- GIMP_GRAYA_IMAGE : GIMP_GRAY_IMAGE);
+ gimp_image_get_format (image, GIMP_GRAY,
+ gimp_drawable_has_alpha (drawable));
src_buffer =
gimp_gegl_buffer_new (GEGL_RECTANGLE (0, 0,
diff --git a/app/paint/gimppaintbrush.c b/app/paint/gimppaintbrush.c
index 636fc3b..86545be 100644
--- a/app/paint/gimppaintbrush.c
+++ b/app/paint/gimppaintbrush.c
@@ -35,6 +35,7 @@
#include "core/gimpdynamicsoutput.h"
#include "core/gimpgradient.h"
#include "core/gimpimage.h"
+#include "core/gimptempbuf.h"
#include "gimppaintbrush.h"
#include "gimppaintoptions.h"
diff --git a/app/pdb/layer-cmds.c b/app/pdb/layer-cmds.c
index bf98ce6..def2d69 100644
--- a/app/pdb/layer-cmds.c
+++ b/app/pdb/layer-cmds.c
@@ -75,8 +75,12 @@ layer_new_invoker (GimpProcedure *procedure,
if (success)
{
+ gboolean has_alpha = (type == GIMP_RGBA_IMAGE ||
+ type == GIMP_GRAYA_IMAGE ||
+ type == GIMP_INDEXEDA_IMAGE);
+
layer = gimp_layer_new (image, width, height,
- gimp_image_get_format (image, type),
+ gimp_image_get_layer_format (image, has_alpha),
name, opacity / 100.0, mode);
if (! layer)
diff --git a/app/xcf/xcf-load.c b/app/xcf/xcf-load.c
index 16b56a3..56901be 100644
--- a/app/xcf/xcf-load.c
+++ b/app/xcf/xcf-load.c
@@ -1089,6 +1089,7 @@ xcf_load_layer (XcfInfo *info,
gint width;
gint height;
gint type;
+ gboolean has_alpha;
gboolean is_fs_drawable;
gchar *name;
@@ -1103,9 +1104,13 @@ xcf_load_layer (XcfInfo *info,
info->cp += xcf_read_int32 (info->fp, (guint32 *) &type, 1);
info->cp += xcf_read_string (info->fp, &name, 1);
+ has_alpha = (type == GIMP_RGBA_IMAGE ||
+ type == GIMP_GRAYA_IMAGE ||
+ type == GIMP_INDEXEDA_IMAGE);
+
/* create a new layer */
layer = gimp_layer_new (image, width, height,
- gimp_image_get_format (image, type),
+ gimp_image_get_layer_format (image, has_alpha),
name, 255, GIMP_NORMAL_MODE);
g_free (name);
if (! layer)
diff --git a/tools/pdbgen/pdb/layer.pdb b/tools/pdbgen/pdb/layer.pdb
index 8aef442..eddbc9e 100644
--- a/tools/pdbgen/pdb/layer.pdb
+++ b/tools/pdbgen/pdb/layer.pdb
@@ -55,8 +55,12 @@ HELP
%invoke = (
code => <<'CODE'
{
+ gboolean has_alpha = (type == GIMP_RGBA_IMAGE ||
+ type == GIMP_GRAYA_IMAGE ||
+ type == GIMP_INDEXEDA_IMAGE);
+
layer = gimp_layer_new (image, width, height,
- gimp_image_get_format (image, type),
+ gimp_image_get_layer_format (image, has_alpha),
name, opacity / 100.0, mode);
if (! layer)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]