gimp r25354 - in trunk: . app/pdb tools/pdbgen/pdb



Author: neo
Date: Fri Apr  4 07:57:42 2008
New Revision: 25354
URL: http://svn.gnome.org/viewvc/gimp?rev=25354&view=rev

Log:
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.



Modified:
   trunk/ChangeLog
   trunk/app/pdb/convert_cmds.c
   trunk/app/pdb/gimppdb-utils.c
   trunk/app/pdb/gimppdb-utils.h
   trunk/tools/pdbgen/pdb/convert.pdb

Modified: trunk/app/pdb/convert_cmds.c
==============================================================================
--- trunk/app/pdb/convert_cmds.c	(original)
+++ trunk/app/pdb/convert_cmds.c	Fri Apr  4 07:57:42 2008
@@ -53,12 +53,16 @@
 
   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 @@
 
   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 @@
 
   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 @@
               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 @@
         success = gimp_image_convert (image, GIMP_INDEXED,
                                       num_cols, dither_type,
                                       alpha_dither, remove_unused,
-                                      palette_type, palette,
+                                      palette_type, pal,
                                       NULL, error);
     }
 

Modified: trunk/app/pdb/gimppdb-utils.c
==============================================================================
--- trunk/app/pdb/gimppdb-utils.c	(original)
+++ trunk/app/pdb/gimppdb-utils.c	Fri Apr  4 07:57:42 2008
@@ -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 @@
   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,

Modified: trunk/app/pdb/gimppdb-utils.h
==============================================================================
--- trunk/app/pdb/gimppdb-utils.h	(original)
+++ trunk/app/pdb/gimppdb-utils.h	Fri Apr  4 07:57:42 2008
@@ -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);
-
-gboolean        gimp_pdb_item_is_attached    (GimpItem      *item,
-                                              GError       **error);
-gboolean        gimp_pdb_layer_is_text_layer (GimpLayer     *layer,
-                                              GError       **error);
-
-GimpStroke    * gimp_pdb_get_vectors_stroke  (GimpVectors   *vectors,
-                                              gint           stroke_ID,
-                                              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_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);
 
 
 #endif /* __GIMP_PDB_UTILS_H__ */

Modified: trunk/tools/pdbgen/pdb/convert.pdb
==============================================================================
--- trunk/tools/pdbgen/pdb/convert.pdb	(original)
+++ trunk/tools/pdbgen/pdb/convert.pdb	Fri Apr  4 07:57:42 2008
@@ -36,12 +36,16 @@
     %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 @@
     %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 @@
     %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 @@
 	  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 @@
     success = gimp_image_convert (image, GIMP_INDEXED,
                                   num_cols, dither_type,
                                   alpha_dither, remove_unused,
-				  palette_type, palette,
+				  palette_type, pal,
                                   NULL, error);
 }
 CODE



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]