Commit 67825560 authored by Michael Natterer's avatar Michael Natterer 😴

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.
parent 5a4cac2a
......@@ -713,6 +713,33 @@ gimp_orientation_type_get_type (void)
return type;
}
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)
{
......
......@@ -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;
......
......@@ -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 ();
......
......@@ -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) */
......
......@@ -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 *
......
......@@ -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);
......
......@@ -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:
......
......@@ -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 */
......
......@@ -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);
......
......@@ -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
......
......@@ -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:");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment