mirror of https://github.com/GNOME/gimp.git
added utility functions to check the image base type.
2008-04-04 Sven Neumann <sven@gimp.org> * app/pdb/gimppdb-utils.[ch]: added utility functions to check the image base type. * tools/pdbgen/pdb/convert.pdb: use it so that we get a proper error set on failure. * app/pdb/convert_cmds.c: regenerated. svn path=/trunk/; revision=25354
This commit is contained in:
parent
6f2e776871
commit
54e8c482d1
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
|||
2008-04-04 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* app/pdb/gimppdb-utils.[ch]: added utility functions to check the
|
||||
image base type.
|
||||
|
||||
* tools/pdbgen/pdb/convert.pdb: use it so that we get a proper
|
||||
error set on failure.
|
||||
|
||||
* app/pdb/convert_cmds.c: regenerated.
|
||||
|
||||
2008-04-04 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* app/core/gimpimage-convert.[ch]
|
||||
|
|
|
@ -53,12 +53,16 @@ image_convert_rgb_invoker (GimpProcedure *procedure,
|
|||
|
||||
if (success)
|
||||
{
|
||||
if (gimp_image_base_type (image) != GIMP_RGB)
|
||||
success = gimp_image_convert (image, GIMP_RGB,
|
||||
0, 0, FALSE, FALSE, 0, NULL,
|
||||
NULL, error);
|
||||
if (gimp_pdb_image_is_not_base_type (image, GIMP_RGB, error))
|
||||
{
|
||||
success = gimp_image_convert (image, GIMP_RGB,
|
||||
0, 0, FALSE, FALSE, 0, NULL,
|
||||
NULL, error);
|
||||
}
|
||||
else
|
||||
success = FALSE;
|
||||
{
|
||||
success = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return gimp_procedure_get_return_values (procedure, success);
|
||||
|
@ -79,12 +83,16 @@ image_convert_grayscale_invoker (GimpProcedure *procedure,
|
|||
|
||||
if (success)
|
||||
{
|
||||
if (gimp_image_base_type (image) != GIMP_GRAY)
|
||||
success = gimp_image_convert (image, GIMP_GRAY,
|
||||
0, 0, FALSE, FALSE, 0, NULL,
|
||||
NULL, error);
|
||||
if (gimp_pdb_image_is_not_base_type (image, GIMP_GRAY, error))
|
||||
{
|
||||
success = gimp_image_convert (image, GIMP_GRAY,
|
||||
0, 0, FALSE, FALSE, 0, NULL,
|
||||
NULL, error);
|
||||
}
|
||||
else
|
||||
success = FALSE;
|
||||
{
|
||||
success = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return gimp_procedure_get_return_values (procedure, success);
|
||||
|
@ -117,9 +125,9 @@ image_convert_indexed_invoker (GimpProcedure *procedure,
|
|||
|
||||
if (success)
|
||||
{
|
||||
GimpPalette *palette = NULL;
|
||||
GimpPalette *pal = NULL;
|
||||
|
||||
if (gimp_image_base_type (image) != GIMP_INDEXED)
|
||||
if (gimp_pdb_image_is_not_base_type (image, GIMP_INDEXED, error))
|
||||
{
|
||||
switch (palette_type)
|
||||
{
|
||||
|
@ -129,12 +137,12 @@ image_convert_indexed_invoker (GimpProcedure *procedure,
|
|||
break;
|
||||
|
||||
case GIMP_CUSTOM_PALETTE:
|
||||
palette = gimp_pdb_get_palette (gimp, palette, FALSE, error);
|
||||
if (! palette)
|
||||
pal = gimp_pdb_get_palette (gimp, palette, FALSE, error);
|
||||
if (! pal)
|
||||
{
|
||||
success = FALSE;
|
||||
}
|
||||
else if (palette->n_colors > MAXNUMCOLORS)
|
||||
else if (pal->n_colors > MAXNUMCOLORS)
|
||||
{
|
||||
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_INVALID_ARGUMENT,
|
||||
_("Cannot convert to a palette "
|
||||
|
@ -156,7 +164,7 @@ image_convert_indexed_invoker (GimpProcedure *procedure,
|
|||
success = gimp_image_convert (image, GIMP_INDEXED,
|
||||
num_cols, dither_type,
|
||||
alpha_dither, remove_unused,
|
||||
palette_type, palette,
|
||||
palette_type, pal,
|
||||
NULL, error);
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include "core/gimpcontainer.h"
|
||||
#include "core/gimpdatafactory.h"
|
||||
#include "core/gimpdrawable.h"
|
||||
#include "core/gimpimage.h"
|
||||
#include "core/gimpitem.h"
|
||||
|
||||
#include "text/gimptextlayer.h"
|
||||
|
@ -333,6 +334,66 @@ gimp_pdb_layer_is_text_layer (GimpLayer *layer,
|
|||
return gimp_pdb_item_is_attached (GIMP_ITEM (layer), error);
|
||||
}
|
||||
|
||||
static const gchar *
|
||||
gimp_pdb_enum_value_get_nick (GType enum_type,
|
||||
gint value)
|
||||
{
|
||||
GEnumClass *enum_class;
|
||||
GEnumValue *enum_value;
|
||||
const gchar *nick;
|
||||
|
||||
enum_class = g_type_class_ref (enum_type);
|
||||
enum_value = g_enum_get_value (enum_class, value);
|
||||
|
||||
nick = enum_value->value_nick;
|
||||
|
||||
g_type_class_unref (enum_class);
|
||||
|
||||
return nick;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gimp_pdb_image_is_base_type (GimpImage *image,
|
||||
GimpImageBaseType type,
|
||||
GError **error)
|
||||
{
|
||||
g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
|
||||
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
||||
|
||||
if (gimp_image_base_type (image) == type)
|
||||
return TRUE;
|
||||
|
||||
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_INVALID_ARGUMENT,
|
||||
_("Image '%s' (%d) is of type %s, "
|
||||
"but an image of type %s is expected"),
|
||||
gimp_object_get_name (GIMP_OBJECT (image)),
|
||||
gimp_image_get_ID (image),
|
||||
gimp_pdb_enum_value_get_nick (GIMP_TYPE_IMAGE_BASE_TYPE,
|
||||
gimp_image_base_type (image)),
|
||||
gimp_pdb_enum_value_get_nick (GIMP_TYPE_IMAGE_BASE_TYPE, type));
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gimp_pdb_image_is_not_base_type (GimpImage *image,
|
||||
GimpImageBaseType type,
|
||||
GError **error)
|
||||
{
|
||||
g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
|
||||
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
||||
|
||||
if (gimp_image_base_type (image) != type)
|
||||
return TRUE;
|
||||
|
||||
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_INVALID_ARGUMENT,
|
||||
_("Image '%s' (%d) is already of type %s"),
|
||||
gimp_object_get_name (GIMP_OBJECT (image)),
|
||||
gimp_image_get_ID (image),
|
||||
gimp_pdb_enum_value_get_nick (GIMP_TYPE_IMAGE_BASE_TYPE, type));
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
GimpStroke *
|
||||
gimp_pdb_get_vectors_stroke (GimpVectors *vectors,
|
||||
|
|
|
@ -20,43 +20,49 @@
|
|||
#define __GIMP_PDB_UTILS_H__
|
||||
|
||||
|
||||
GimpBrush * gimp_pdb_get_brush (Gimp *gimp,
|
||||
const gchar *name,
|
||||
gboolean writable,
|
||||
GError **error);
|
||||
GimpBrush * gimp_pdb_get_generated_brush (Gimp *gimp,
|
||||
const gchar *name,
|
||||
gboolean writable,
|
||||
GError **error);
|
||||
GimpPattern * gimp_pdb_get_pattern (Gimp *gimp,
|
||||
const gchar *name,
|
||||
GError **error);
|
||||
GimpGradient * gimp_pdb_get_gradient (Gimp *gimp,
|
||||
const gchar *name,
|
||||
gboolean writable,
|
||||
GError **error);
|
||||
GimpPalette * gimp_pdb_get_palette (Gimp *gimp,
|
||||
const gchar *name,
|
||||
gboolean writable,
|
||||
GError **error);
|
||||
GimpFont * gimp_pdb_get_font (Gimp *gimp,
|
||||
const gchar *name,
|
||||
GError **error);
|
||||
GimpBuffer * gimp_pdb_get_buffer (Gimp *gimp,
|
||||
const gchar *name,
|
||||
GError **error);
|
||||
GimpPaintInfo * gimp_pdb_get_paint_info (Gimp *gimp,
|
||||
const gchar *name,
|
||||
GError **error);
|
||||
GimpBrush * gimp_pdb_get_brush (Gimp *gimp,
|
||||
const gchar *name,
|
||||
gboolean writable,
|
||||
GError **error);
|
||||
GimpBrush * gimp_pdb_get_generated_brush (Gimp *gimp,
|
||||
const gchar *name,
|
||||
gboolean writable,
|
||||
GError **error);
|
||||
GimpPattern * gimp_pdb_get_pattern (Gimp *gimp,
|
||||
const gchar *name,
|
||||
GError **error);
|
||||
GimpGradient * gimp_pdb_get_gradient (Gimp *gimp,
|
||||
const gchar *name,
|
||||
gboolean writable,
|
||||
GError **error);
|
||||
GimpPalette * gimp_pdb_get_palette (Gimp *gimp,
|
||||
const gchar *name,
|
||||
gboolean writable,
|
||||
GError **error);
|
||||
GimpFont * gimp_pdb_get_font (Gimp *gimp,
|
||||
const gchar *name,
|
||||
GError **error);
|
||||
GimpBuffer * gimp_pdb_get_buffer (Gimp *gimp,
|
||||
const gchar *name,
|
||||
GError **error);
|
||||
GimpPaintInfo * gimp_pdb_get_paint_info (Gimp *gimp,
|
||||
const gchar *name,
|
||||
GError **error);
|
||||
|
||||
gboolean gimp_pdb_item_is_attached (GimpItem *item,
|
||||
GError **error);
|
||||
gboolean gimp_pdb_layer_is_text_layer (GimpLayer *layer,
|
||||
GError **error);
|
||||
gboolean gimp_pdb_item_is_attached (GimpItem *item,
|
||||
GError **error);
|
||||
gboolean gimp_pdb_layer_is_text_layer (GimpLayer *layer,
|
||||
GError **error);
|
||||
gboolean gimp_pdb_image_is_base_type (GimpImage *image,
|
||||
GimpImageBaseType type,
|
||||
GError **error);
|
||||
gboolean gimp_pdb_image_is_not_base_type (GimpImage *image,
|
||||
GimpImageBaseType type,
|
||||
GError **error);
|
||||
|
||||
GimpStroke * gimp_pdb_get_vectors_stroke (GimpVectors *vectors,
|
||||
gint stroke_ID,
|
||||
GError **error);
|
||||
GimpStroke * gimp_pdb_get_vectors_stroke (GimpVectors *vectors,
|
||||
gint stroke_ID,
|
||||
GError **error);
|
||||
|
||||
|
||||
#endif /* __GIMP_PDB_UTILS_H__ */
|
||||
|
|
|
@ -36,12 +36,16 @@ HELP
|
|||
%invoke = (
|
||||
code => <<'CODE'
|
||||
{
|
||||
if (gimp_image_base_type (image) != GIMP_RGB)
|
||||
success = gimp_image_convert (image, GIMP_RGB,
|
||||
0, 0, FALSE, FALSE, 0, NULL,
|
||||
NULL, error);
|
||||
if (gimp_pdb_image_is_not_base_type (image, GIMP_RGB, error))
|
||||
{
|
||||
success = gimp_image_convert (image, GIMP_RGB,
|
||||
0, 0, FALSE, FALSE, 0, NULL,
|
||||
NULL, error);
|
||||
}
|
||||
else
|
||||
success = FALSE;
|
||||
{
|
||||
success = FALSE;
|
||||
}
|
||||
}
|
||||
CODE
|
||||
);
|
||||
|
@ -66,12 +70,16 @@ HELP
|
|||
%invoke = (
|
||||
code => <<'CODE'
|
||||
{
|
||||
if (gimp_image_base_type (image) != GIMP_GRAY)
|
||||
success = gimp_image_convert (image, GIMP_GRAY,
|
||||
0, 0, FALSE, FALSE, 0, NULL,
|
||||
NULL, error);
|
||||
if (gimp_pdb_image_is_not_base_type (image, GIMP_GRAY, error))
|
||||
{
|
||||
success = gimp_image_convert (image, GIMP_GRAY,
|
||||
0, 0, FALSE, FALSE, 0, NULL,
|
||||
NULL, error);
|
||||
}
|
||||
else
|
||||
success = FALSE;
|
||||
{
|
||||
success = FALSE;
|
||||
}
|
||||
}
|
||||
CODE
|
||||
);
|
||||
|
@ -121,9 +129,9 @@ HELP
|
|||
%invoke = (
|
||||
code => <<'CODE'
|
||||
{
|
||||
GimpPalette *palette = NULL;
|
||||
GimpPalette *pal = NULL;
|
||||
|
||||
if (gimp_image_base_type (image) != GIMP_INDEXED)
|
||||
if (gimp_pdb_image_is_not_base_type (image, GIMP_INDEXED, error))
|
||||
{
|
||||
switch (palette_type)
|
||||
{
|
||||
|
@ -133,12 +141,12 @@ HELP
|
|||
break;
|
||||
|
||||
case GIMP_CUSTOM_PALETTE:
|
||||
palette = gimp_pdb_get_palette (gimp, palette, FALSE, error);
|
||||
if (! palette)
|
||||
pal = gimp_pdb_get_palette (gimp, palette, FALSE, error);
|
||||
if (! pal)
|
||||
{
|
||||
success = FALSE;
|
||||
}
|
||||
else if (palette->n_colors > MAXNUMCOLORS)
|
||||
else if (pal->n_colors > MAXNUMCOLORS)
|
||||
{
|
||||
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_INVALID_ARGUMENT,
|
||||
_("Cannot convert to a palette "
|
||||
|
@ -160,7 +168,7 @@ HELP
|
|||
success = gimp_image_convert (image, GIMP_INDEXED,
|
||||
num_cols, dither_type,
|
||||
alpha_dither, remove_unused,
|
||||
palette_type, palette,
|
||||
palette_type, pal,
|
||||
NULL, error);
|
||||
}
|
||||
CODE
|
||||
|
|
Loading…
Reference in New Issue