[gimp/goat-invasion] app: add a GimpPrecision enum that for now contains GIMP_PRECISION_U8
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/goat-invasion] app: add a GimpPrecision enum that for now contains GIMP_PRECISION_U8
- Date: Sun, 22 Apr 2012 15:09:05 +0000 (UTC)
commit 5270e11be2a679bd3fe6e532c644574e1bd5ee6e
Author: Michael Natterer <mitch gimp org>
Date: Sun Apr 22 17:07:35 2012 +0200
app: add a GimpPrecision enum that for now contains GIMP_PRECISION_U8
Add gimp_image_get_precision(), and a "precision" argument to
gimp_babl_format(). Change code accordingly and do some more format
related cleanups.
app/core/core-enums.c | 27 +++++++++++++++++++++++
app/core/core-enums.h | 10 ++++++++
app/core/gimpgrouplayer.c | 6 +++-
app/core/gimpimage-private.h | 1 +
app/core/gimpimage.c | 28 ++++++++++++++++++------
app/core/gimpimage.h | 1 +
app/file/file-open.c | 14 ++++++++---
app/gegl/gimp-babl.c | 48 +++++++++++++++++++++++++++++++++++-------
app/gegl/gimp-babl.h | 2 +
app/paint/gimpbrushcore.c | 9 +++++--
app/widgets/gimpcolorframe.c | 6 ++--
11 files changed, 125 insertions(+), 27 deletions(-)
---
diff --git a/app/core/core-enums.c b/app/core/core-enums.c
index 136b0cc..a32e7a7 100644
--- a/app/core/core-enums.c
+++ b/app/core/core-enums.c
@@ -714,6 +714,33 @@ gimp_orientation_type_get_type (void)
}
GType
+gimp_precision_get_type (void)
+{
+ static const GEnumValue values[] =
+ {
+ { GIMP_PRECISION_U8, "GIMP_PRECISION_U8", "u8" },
+ { 0, NULL, NULL }
+ };
+
+ static const GimpEnumDesc descs[] =
+ {
+ { GIMP_PRECISION_U8, NC_("precision", "8-Bit unsigned integer"), NULL },
+ { 0, NULL, NULL }
+ };
+
+ static GType type = 0;
+
+ if (G_UNLIKELY (! type))
+ {
+ type = g_enum_register_static ("GimpPrecision", values);
+ gimp_type_set_translation_context (type, "precision");
+ gimp_enum_set_value_descriptions (type, descs);
+ }
+
+ return type;
+}
+
+GType
gimp_item_set_get_type (void)
{
static const GEnumValue values[] =
diff --git a/app/core/core-enums.h b/app/core/core-enums.h
index 28f5bf9..900c945 100644
--- a/app/core/core-enums.h
+++ b/app/core/core-enums.h
@@ -324,6 +324,16 @@ typedef enum
} GimpOrientationType;
+#define GIMP_PRECISION_GET_TYPE (gimp_precision_get_type ())
+
+GType gimp_precision_get_type (void) G_GNUC_CONST;
+
+typedef enum /*< pdb-skip >*/
+{
+ GIMP_PRECISION_U8 /*< desc="8-Bit unsigned integer" >*/
+} GimpPrecision;
+
+
#define GIMP_TYPE_ITEM_SET (gimp_item_set_get_type ())
GType gimp_item_set_get_type (void) G_GNUC_CONST;
diff --git a/app/core/gimpgrouplayer.c b/app/core/gimpgrouplayer.c
index 8a3ec37..3769754 100644
--- a/app/core/gimpgrouplayer.c
+++ b/app/core/gimpgrouplayer.c
@@ -826,14 +826,16 @@ static const Babl *
get_projection_format (GimpProjectable *projectable,
GimpImageBaseType base_type)
{
+ GimpImage *image = gimp_item_get_image (GIMP_ITEM (projectable));
+
switch (base_type)
{
case GIMP_RGB:
case GIMP_INDEXED:
- return babl_format ("R'G'B'A u8");
+ return gimp_image_get_format (image, GIMP_RGB, TRUE);
case GIMP_GRAY:
- return babl_format ("Y'A u8");
+ return gimp_image_get_format (image, GIMP_GRAY, TRUE);
}
g_assert_not_reached ();
diff --git a/app/core/gimpimage-private.h b/app/core/gimpimage-private.h
index 2146f8b..dd3e611 100644
--- a/app/core/gimpimage-private.h
+++ b/app/core/gimpimage-private.h
@@ -46,6 +46,7 @@ struct _GimpImagePrivate
gdouble yresolution; /* image y-res, in dpi */
GimpUnit resolution_unit; /* resolution unit */
GimpImageBaseType base_type; /* base gimp_image type */
+ GimpPrecision precision; /* image's precision */
guchar *colormap; /* colormap (for indexed) */
gint n_colors; /* # of colors (for indexed) */
diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c
index 1ec8804..c3a2dd6 100644
--- a/app/core/gimpimage.c
+++ b/app/core/gimpimage.c
@@ -633,6 +633,7 @@ gimp_image_init (GimpImage *image)
private->yresolution = 1.0;
private->resolution_unit = GIMP_UNIT_INCH;
private->base_type = GIMP_RGB;
+ private->precision = GIMP_PRECISION_U8;
private->colormap = NULL;
private->n_colors = 0;
@@ -1180,11 +1181,13 @@ gimp_image_real_colormap_changed (GimpImage *image,
if (private->colormap)
{
babl_palette_set_palette (private->babl_palette_rgb,
- babl_format ("R'G'B' u8"),
+ gimp_babl_format (GIMP_RGB,
+ private->precision, FALSE),
private->colormap,
private->n_colors);
babl_palette_set_palette (private->babl_palette_rgba,
- babl_format ("R'G'B' u8"),
+ gimp_babl_format (GIMP_RGB,
+ private->precision, FALSE),
private->colormap,
private->n_colors);
}
@@ -1267,16 +1270,17 @@ gimp_image_get_image (GimpProjectable *projectable)
static const Babl *
gimp_image_get_proj_format (GimpProjectable *projectable)
{
- GimpImagePrivate *private = GIMP_IMAGE_GET_PRIVATE (projectable);
+ GimpImage *image = GIMP_IMAGE (projectable);
+ GimpImagePrivate *private = GIMP_IMAGE_GET_PRIVATE (image);
switch (private->base_type)
{
case GIMP_RGB:
case GIMP_INDEXED:
- return babl_format ("R'G'B'A u8");
+ return gimp_image_get_format (image, GIMP_RGB, TRUE);
case GIMP_GRAY:
- return babl_format ("Y'A u8");
+ return gimp_image_get_format (image, GIMP_GRAY, TRUE);
}
g_assert_not_reached ();
@@ -1467,6 +1471,14 @@ gimp_image_base_type (const GimpImage *image)
return GIMP_IMAGE_GET_PRIVATE (image)->base_type;
}
+GimpPrecision
+gimp_image_get_precision (const GimpImage *image)
+{
+ g_return_val_if_fail (GIMP_IS_IMAGE (image), -1);
+
+ return GIMP_IMAGE_GET_PRIVATE (image)->precision;
+}
+
CombinationMode
gimp_image_get_combination_mode (GimpImageType dest_type,
gint src_bytes)
@@ -1485,7 +1497,9 @@ gimp_image_get_format (const GimpImage *image,
{
case GIMP_RGB:
case GIMP_GRAY:
- return gimp_babl_format (base_type, with_alpha);
+ return gimp_babl_format (base_type,
+ gimp_image_get_precision (image),
+ with_alpha);
case GIMP_INDEXED:
if (with_alpha)
@@ -1513,7 +1527,7 @@ gimp_image_get_channel_format (const GimpImage *image)
{
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
- return babl_format ("Y' u8");
+ return gimp_image_get_format (image, GIMP_GRAY, FALSE);
}
const Babl *
diff --git a/app/core/gimpimage.h b/app/core/gimpimage.h
index c8a250f..73b28d6 100644
--- a/app/core/gimpimage.h
+++ b/app/core/gimpimage.h
@@ -109,6 +109,7 @@ GimpImage * gimp_image_new (Gimp *gimp,
GimpImageBaseType base_type);
GimpImageBaseType gimp_image_base_type (const GimpImage *image);
+GimpPrecision gimp_image_get_precision (const GimpImage *image);
CombinationMode gimp_image_get_combination_mode (GimpImageType dest_type,
gint src_bytes);
diff --git a/app/file/file-open.c b/app/file/file-open.c
index 37d042d..7688519 100644
--- a/app/file/file-open.c
+++ b/app/file/file-open.c
@@ -47,6 +47,8 @@
#include "config/gimpcoreconfig.h"
+#include "gegl/gimp-babl.h"
+
#include "core/gimp.h"
#include "core/gimpcontext.h"
#include "core/gimpdocumentlist.h"
@@ -323,19 +325,23 @@ file_open_thumbnail (Gimp *gimp,
switch (value)
{
case GIMP_RGB_IMAGE:
- *format = babl_format ("R'G'B' u8");
+ *format = gimp_babl_format (GIMP_RGB, GIMP_PRECISION_U8,
+ FALSE);
break;
case GIMP_RGBA_IMAGE:
- *format = babl_format ("R'G'B'A u8");
+ *format = gimp_babl_format (GIMP_RGB, GIMP_PRECISION_U8,
+ TRUE);
break;
case GIMP_GRAY_IMAGE:
- *format = babl_format ("Y' u8");
+ *format = gimp_babl_format (GIMP_GRAY, GIMP_PRECISION_U8,
+ FALSE);
break;
case GIMP_GRAYA_IMAGE:
- *format = babl_format ("Y'A u8");
+ *format = gimp_babl_format (GIMP_GRAY, GIMP_PRECISION_U8,
+ TRUE);
break;
case GIMP_INDEXED_IMAGE:
diff --git a/app/gegl/gimp-babl.c b/app/gegl/gimp-babl.c
index 9968ffc..8fa3e7b 100644
--- a/app/gegl/gimp-babl.c
+++ b/app/gegl/gimp-babl.c
@@ -147,23 +147,55 @@ gimp_babl_format_get_base_type (const Babl *format)
g_return_val_if_reached (-1);
}
+GimpPrecision
+gimp_babl_format_get_precision (const Babl *format)
+{
+ const Babl *type;
+
+ g_return_val_if_fail (format != NULL, -1);
+
+ type = babl_format_get_type (format, 0);
+
+ if (type == babl_type ("u8"))
+ return GIMP_PRECISION_U8;
+
+ g_return_val_if_reached (-1);
+}
+
const Babl *
gimp_babl_format (GimpImageBaseType base_type,
+ GimpPrecision precision,
gboolean with_alpha)
{
switch (base_type)
{
case GIMP_RGB:
- if (with_alpha)
- return babl_format ("R'G'B'A u8");
- else
- return babl_format ("R'G'B' u8");
+ switch (precision)
+ {
+ case GIMP_PRECISION_U8:
+ if (with_alpha)
+ return babl_format ("R'G'B'A u8");
+ else
+ return babl_format ("R'G'B' u8");
+
+ default:
+ break;
+ }
+ break;
case GIMP_GRAY:
- if (with_alpha)
- return babl_format ("Y'A u8");
- else
- return babl_format ("Y' u8");
+ switch (precision)
+ {
+ case GIMP_PRECISION_U8:
+ if (with_alpha)
+ return babl_format ("Y'A u8");
+ else
+ return babl_format ("Y' u8");
+
+ default:
+ break;
+ }
+ break;
case GIMP_INDEXED:
/* need to use the image's api for this */
diff --git a/app/gegl/gimp-babl.h b/app/gegl/gimp-babl.h
index 704f611..1a50b1d 100644
--- a/app/gegl/gimp-babl.h
+++ b/app/gegl/gimp-babl.h
@@ -27,8 +27,10 @@ void gimp_babl_init (void);
const gchar * gimp_babl_get_description (const Babl *babl);
GimpImageBaseType gimp_babl_format_get_base_type (const Babl *format);
+GimpPrecision gimp_babl_format_get_precision (const Babl *format);
const Babl * gimp_babl_format (GimpImageBaseType base_type,
+ GimpPrecision precision,
gboolean with_alpha);
diff --git a/app/paint/gimpbrushcore.c b/app/paint/gimpbrushcore.c
index 7d75d46..a42ca0e 100644
--- a/app/paint/gimpbrushcore.c
+++ b/app/paint/gimpbrushcore.c
@@ -1127,7 +1127,7 @@ gimp_brush_core_subsample_mask (GimpBrushCore *core,
dest = gimp_temp_buf_new (mask->width + 2,
mask->height + 2,
- babl_format ("Y u8"));
+ mask->format);
gimp_temp_buf_data_clear (dest);
/* Allocate and initialize the accum buffer */
@@ -1208,7 +1208,7 @@ gimp_brush_core_pressurize_mask (GimpBrushCore *core,
core->pressure_brush = gimp_temp_buf_new (brush_mask->width + 2,
brush_mask->height + 2,
- babl_format ("Y u8"));
+ brush_mask->format);
gimp_temp_buf_data_clear (core->pressure_brush);
#ifdef FANCY_PRESSURE
@@ -1621,6 +1621,7 @@ gimp_brush_core_paint_line_pixmap_mask (GimpDrawable *drawable,
GimpBrushApplicationMode mode)
{
GimpImageBaseType pixmap_base_type;
+ GimpPrecision pixmap_precision;
gint pixmap_bytes;
guchar *b;
@@ -1631,6 +1632,7 @@ gimp_brush_core_paint_line_pixmap_mask (GimpDrawable *drawable,
y += pixmap_mask->height;
pixmap_base_type = gimp_babl_format_get_base_type (pixmap_mask->format);
+ pixmap_precision = gimp_babl_format_get_precision (pixmap_mask->format);
pixmap_bytes = babl_format_get_bytes_per_pixel (pixmap_mask->format);
/* Point to the approriate scanline */
@@ -1646,7 +1648,8 @@ gimp_brush_core_paint_line_pixmap_mask (GimpDrawable *drawable,
guchar *l = line_buf;
gint i;
- fish = babl_fish (gimp_babl_format (pixmap_base_type, TRUE),
+ fish = babl_fish (gimp_babl_format (pixmap_base_type, pixmap_precision,
+ TRUE),
gimp_drawable_get_format_with_alpha (drawable));
/* put the source pixmap's pixels, plus the mask's alpha, into
diff --git a/app/widgets/gimpcolorframe.c b/app/widgets/gimpcolorframe.c
index 337454b..a435cf7 100644
--- a/app/widgets/gimpcolorframe.c
+++ b/app/widgets/gimpcolorframe.c
@@ -26,6 +26,8 @@
#include "widgets-types.h"
+#include "gegl/gimp-babl.h"
+
#include "core/gimpimage.h"
#include "gimpcolorframe.h"
@@ -504,9 +506,7 @@ gimp_color_frame_update (GimpColorFrame *frame)
switch (frame->frame_mode)
{
case GIMP_COLOR_FRAME_MODE_PIXEL:
- if (frame->sample_format == babl_format ("Y u8") ||
- frame->sample_format == babl_format ("Y' u8") ||
- frame->sample_format == babl_format ("Y'A u8"))
+ if (gimp_babl_format_get_base_type (frame->sample_format) == GIMP_GRAY)
{
names[0] = _("Value:");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]