[gimp/goat-invasion] pdb/libgimp: export gimp-image-new-with-precision



commit 1780b0180b945b5e24b79ce119c8bc735391240e
Author: Michael Natterer <mitch gimp org>
Date:   Wed Apr 25 20:39:23 2012 +0200

    pdb/libgimp: export gimp-image-new-with-precision
    
    And switch on precision awareness of a plug-in in the core when
    possible, instead of in the libgimp wrappers.

 app/pdb/convert-cmds.c        |    6 +++
 app/pdb/drawable-cmds.c       |    3 +
 app/pdb/image-cmds.c          |   97 +++++++++++++++++++++++++++++++++++++++++
 app/pdb/internal-procs.c      |    2 +-
 libgimp/gimp.def              |    1 +
 libgimp/gimpdrawable.c        |    2 -
 libgimp/gimpimage_pdb.c       |   45 +++++++++++++++++++
 libgimp/gimpimage_pdb.h       |    4 ++
 tools/pdbgen/pdb/convert.pdb  |    8 +++-
 tools/pdbgen/pdb/drawable.pdb |    3 +
 tools/pdbgen/pdb/image.pdb    |   54 ++++++++++++++++++++++-
 11 files changed, 219 insertions(+), 6 deletions(-)
---
diff --git a/app/pdb/convert-cmds.c b/app/pdb/convert-cmds.c
index a2f7c4c..579bcf5 100644
--- a/app/pdb/convert-cmds.c
+++ b/app/pdb/convert-cmds.c
@@ -23,11 +23,14 @@
 
 #include "pdb-types.h"
 
+#include "core/gimp.h"
 #include "core/gimpimage-convert.h"
 #include "core/gimpimage.h"
 #include "core/gimpitemstack.h"
 #include "core/gimppalette.h"
 #include "core/gimpparamspecs.h"
+#include "plug-in/gimpplugin.h"
+#include "plug-in/gimppluginmanager.h"
 
 #include "gimppdb.h"
 #include "gimppdberror.h"
@@ -233,6 +236,9 @@ image_convert_precision_invoker (GimpProcedure      *procedure,
 
   if (success)
     {
+      if (gimp->plug_in_manager->current_plug_in)
+        gimp_plug_in_enable_precision (gimp->plug_in_manager->current_plug_in);
+
       if (gimp_pdb_image_is_not_base_type (image, GIMP_INDEXED, error) &&
           gimp_pdb_image_is_not_precision (image, precision, error))
         {
diff --git a/app/pdb/drawable-cmds.c b/app/pdb/drawable-cmds.c
index cc047c6..8994e31 100644
--- a/app/pdb/drawable-cmds.c
+++ b/app/pdb/drawable-cmds.c
@@ -64,6 +64,9 @@ drawable_get_format_invoker (GimpProcedure      *procedure,
 
   if (success)
     {
+      if (gimp->plug_in_manager->current_plug_in)
+        gimp_plug_in_enable_precision (gimp->plug_in_manager->current_plug_in);
+
       format = g_strdup (babl_get_name (gimp_drawable_get_format (drawable)));
     }
 
diff --git a/app/pdb/image-cmds.c b/app/pdb/image-cmds.c
index a5eb078..ce3bb25 100644
--- a/app/pdb/image-cmds.c
+++ b/app/pdb/image-cmds.c
@@ -53,6 +53,8 @@
 #include "core/gimpselection.h"
 #include "core/gimptempbuf.h"
 #include "core/gimpunit.h"
+#include "plug-in/gimpplugin.h"
+#include "plug-in/gimppluginmanager.h"
 #include "vectors/gimpvectors.h"
 
 #include "gimppdb.h"
@@ -169,6 +171,52 @@ image_new_invoker (GimpProcedure      *procedure,
 }
 
 static GValueArray *
+image_new_with_precision_invoker (GimpProcedure      *procedure,
+                                  Gimp               *gimp,
+                                  GimpContext        *context,
+                                  GimpProgress       *progress,
+                                  const GValueArray  *args,
+                                  GError            **error)
+{
+  gboolean success = TRUE;
+  GValueArray *return_vals;
+  gint32 width;
+  gint32 height;
+  gint32 type;
+  gint32 precision;
+  GimpImage *image = NULL;
+
+  width = g_value_get_int (&args->values[0]);
+  height = g_value_get_int (&args->values[1]);
+  type = g_value_get_enum (&args->values[2]);
+  precision = g_value_get_enum (&args->values[3]);
+
+  if (success)
+    {
+      if (gimp->plug_in_manager->current_plug_in)
+        gimp_plug_in_enable_precision (gimp->plug_in_manager->current_plug_in);
+
+      if (type != GIMP_INDEXED || precision == GIMP_PRECISION_U8)
+        {
+          image = gimp_create_image (gimp, width, height, type,
+                                     precision, FALSE);
+          if (! image)
+            success = FALSE;
+        }
+      else
+        success = FALSE;
+    }
+
+  return_vals = gimp_procedure_get_return_values (procedure, success,
+                                                  error ? *error : NULL);
+
+  if (success)
+    gimp_value_set_image (&return_vals->values[1], image);
+
+  return return_vals;
+}
+
+static GValueArray *
 image_duplicate_invoker (GimpProcedure      *procedure,
                          Gimp               *gimp,
                          GimpContext        *context,
@@ -2884,6 +2932,55 @@ register_image_procs (GimpPDB *pdb)
   g_object_unref (procedure);
 
   /*
+   * gimp-image-new-with-precision
+   */
+  procedure = gimp_procedure_new (image_new_with_precision_invoker);
+  gimp_object_set_static_name (GIMP_OBJECT (procedure),
+                               "gimp-image-new-with-precision");
+  gimp_procedure_set_static_strings (procedure,
+                                     "gimp-image-new-with-precision",
+                                     "Creates a new image with the specified width, height, type and precision.",
+                                     "Creates a new image, undisplayed with the specified extents, type and precision. Indexed images can only be created at GIMP_PRECISION_U8 precision. See 'gimp-image-new' for further details.",
+                                     "Michael Natterer <mitch gimp org>",
+                                     "Michael Natterer",
+                                     "2012",
+                                     NULL);
+  gimp_procedure_add_argument (procedure,
+                               gimp_param_spec_int32 ("width",
+                                                      "width",
+                                                      "The width of the image",
+                                                      1, GIMP_MAX_IMAGE_SIZE, 1,
+                                                      GIMP_PARAM_READWRITE));
+  gimp_procedure_add_argument (procedure,
+                               gimp_param_spec_int32 ("height",
+                                                      "height",
+                                                      "The height of the image",
+                                                      1, GIMP_MAX_IMAGE_SIZE, 1,
+                                                      GIMP_PARAM_READWRITE));
+  gimp_procedure_add_argument (procedure,
+                               g_param_spec_enum ("type",
+                                                  "type",
+                                                  "The type of image",
+                                                  GIMP_TYPE_IMAGE_BASE_TYPE,
+                                                  GIMP_RGB,
+                                                  GIMP_PARAM_READWRITE));
+  gimp_procedure_add_argument (procedure,
+                               g_param_spec_enum ("precision",
+                                                  "precision",
+                                                  "The precision",
+                                                  GIMP_TYPE_PRECISION,
+                                                  GIMP_PRECISION_U8,
+                                                  GIMP_PARAM_READWRITE));
+  gimp_procedure_add_return_value (procedure,
+                                   gimp_param_spec_image_id ("image",
+                                                             "image",
+                                                             "The ID of the newly created image",
+                                                             pdb->gimp, FALSE,
+                                                             GIMP_PARAM_READWRITE));
+  gimp_pdb_register_procedure (pdb, procedure);
+  g_object_unref (procedure);
+
+  /*
    * gimp-image-duplicate
    */
   procedure = gimp_procedure_new (image_duplicate_invoker);
diff --git a/app/pdb/internal-procs.c b/app/pdb/internal-procs.c
index e820dff..f829424 100644
--- a/app/pdb/internal-procs.c
+++ b/app/pdb/internal-procs.c
@@ -28,7 +28,7 @@
 #include "internal-procs.h"
 
 
-/* 671 procedures registered total */
+/* 672 procedures registered total */
 
 void
 internal_procs_init (GimpPDB *pdb)
diff --git a/libgimp/gimp.def b/libgimp/gimp.def
index 6c5fd9e..30e2933 100644
--- a/libgimp/gimp.def
+++ b/libgimp/gimp.def
@@ -444,6 +444,7 @@ EXPORTS
 	gimp_image_merge_down
 	gimp_image_merge_visible_layers
 	gimp_image_new
+	gimp_image_new_with_precision
 	gimp_image_parasite_attach
 	gimp_image_parasite_detach
 	gimp_image_parasite_find
diff --git a/libgimp/gimpdrawable.c b/libgimp/gimpdrawable.c
index 9da4c24..18eeda2 100644
--- a/libgimp/gimpdrawable.c
+++ b/libgimp/gimpdrawable.c
@@ -744,8 +744,6 @@ gimp_drawable_get_format (gint32 drawable_ID)
 
   if (format_str)
     {
-      gimp_plugin_enable_precision ();
-
       if (gimp_drawable_is_indexed (drawable_ID))
         {
           gint32      image_ID = gimp_item_get_image (drawable_ID);
diff --git a/libgimp/gimpimage_pdb.c b/libgimp/gimpimage_pdb.c
index 6ee0c0f..ea7191e 100644
--- a/libgimp/gimpimage_pdb.c
+++ b/libgimp/gimpimage_pdb.c
@@ -152,6 +152,51 @@ gimp_image_new (gint              width,
 }
 
 /**
+ * gimp_image_new_with_precision:
+ * @width: The width of the image.
+ * @height: The height of the image.
+ * @type: The type of image.
+ * @precision: The precision.
+ *
+ * Creates a new image with the specified width, height, type and
+ * precision.
+ *
+ * Creates a new image, undisplayed with the specified extents, type
+ * and precision. Indexed images can only be created at
+ * GIMP_PRECISION_U8 precision. See gimp_image_new() for further
+ * details.
+ *
+ * Returns: The ID of the newly created image.
+ *
+ * Since: GIMP 2.10
+ **/
+gint32
+gimp_image_new_with_precision (gint              width,
+                               gint              height,
+                               GimpImageBaseType type,
+                               GimpPrecision     precision)
+{
+  GimpParam *return_vals;
+  gint nreturn_vals;
+  gint32 image_ID = -1;
+
+  return_vals = gimp_run_procedure ("gimp-image-new-with-precision",
+                                    &nreturn_vals,
+                                    GIMP_PDB_INT32, width,
+                                    GIMP_PDB_INT32, height,
+                                    GIMP_PDB_INT32, type,
+                                    GIMP_PDB_INT32, precision,
+                                    GIMP_PDB_END);
+
+  if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
+    image_ID = return_vals[1].data.d_image;
+
+  gimp_destroy_params (return_vals, nreturn_vals);
+
+  return image_ID;
+}
+
+/**
  * gimp_image_duplicate:
  * @image_ID: The image.
  *
diff --git a/libgimp/gimpimage_pdb.h b/libgimp/gimpimage_pdb.h
index 3f48a62..771e363 100644
--- a/libgimp/gimpimage_pdb.h
+++ b/libgimp/gimpimage_pdb.h
@@ -37,6 +37,10 @@ gint*                    gimp_image_list                     (gint
 gint32                   gimp_image_new                      (gint                    width,
                                                               gint                    height,
                                                               GimpImageBaseType       type);
+gint32                   gimp_image_new_with_precision       (gint                    width,
+                                                              gint                    height,
+                                                              GimpImageBaseType       type,
+                                                              GimpPrecision           precision);
 gint32                   gimp_image_duplicate                (gint32                  image_ID);
 gboolean                 gimp_image_delete                   (gint32                  image_ID);
 GimpImageBaseType        gimp_image_base_type                (gint32                  image_ID);
diff --git a/tools/pdbgen/pdb/convert.pdb b/tools/pdbgen/pdb/convert.pdb
index 419680e..30ba8ad 100644
--- a/tools/pdbgen/pdb/convert.pdb
+++ b/tools/pdbgen/pdb/convert.pdb
@@ -240,6 +240,9 @@ HELP
     %invoke = (
 	code => <<'CODE'
 {
+  if (gimp->plug_in_manager->current_plug_in)
+    gimp_plug_in_enable_precision (gimp->plug_in_manager->current_plug_in);
+
   if (gimp_pdb_image_is_not_base_type (image, GIMP_INDEXED, error) &&
       gimp_pdb_image_is_not_precision (image, precision, error))
     {
@@ -254,10 +257,13 @@ CODE
     );
 }
 
- headers = qw("core/gimpimage.h"
+ headers = qw("core/gimp.h"
+              "core/gimpimage.h"
               "core/gimpimage-convert.h"
               "core/gimpitemstack.h"
               "core/gimppalette.h"
+              "plug-in/gimpplugin.h"
+              "plug-in/gimppluginmanager.h"
               "gimppdberror.h"
               "gimppdb-utils.h"
               "gimp-intl.h");
diff --git a/tools/pdbgen/pdb/drawable.pdb b/tools/pdbgen/pdb/drawable.pdb
index 8e098e5..6648a43 100644
--- a/tools/pdbgen/pdb/drawable.pdb
+++ b/tools/pdbgen/pdb/drawable.pdb
@@ -283,6 +283,9 @@ sub drawable_get_format {
     %invoke = (
 	code => <<'CODE'
 {
+  if (gimp->plug_in_manager->current_plug_in)
+    gimp_plug_in_enable_precision (gimp->plug_in_manager->current_plug_in);
+
   format = g_strdup (babl_get_name (gimp_drawable_get_format (drawable)));
 }
 CODE
diff --git a/tools/pdbgen/pdb/image.pdb b/tools/pdbgen/pdb/image.pdb
index 84140bd..0f7ab4f 100644
--- a/tools/pdbgen/pdb/image.pdb
+++ b/tools/pdbgen/pdb/image.pdb
@@ -123,6 +123,53 @@ CODE
     );
 }
 
+sub image_new_with_precision {
+    $blurb = 'Creates a new image with the specified width, height, type and precision.';
+
+    $help = <<'HELP';
+Creates a new image, undisplayed with the specified extents, type
+and precision. Indexed images can only be created at GIMP_PRECISION_U8
+precision. See gimp_image_new() for further details.
+HELP
+
+    &mitch_pdb_misc('2012', '2.10');
+
+    @inargs = (
+        { name => 'width', type => '1 <= int32 <= GIMP_MAX_IMAGE_SIZE',
+          desc => 'The width of the image' },
+        { name => 'height', type => '1 <= int32 <= GIMP_MAX_IMAGE_SIZE',
+          desc => 'The height of the image' },
+        { name => 'type', type => 'enum GimpImageBaseType',
+          desc => 'The type of image' },
+        { name => 'precision', type => 'enum GimpPrecision',
+          desc => 'The precision' }
+    );
+
+    @outargs = (
+        { name => 'image', type => 'image',
+          desc => 'The ID of the newly created image' }
+    );
+
+    %invoke = (
+        code => <<'CODE'
+{
+  if (gimp->plug_in_manager->current_plug_in)
+    gimp_plug_in_enable_precision (gimp->plug_in_manager->current_plug_in);
+
+  if (type != GIMP_INDEXED || precision == GIMP_PRECISION_U8)
+    {
+      image = gimp_create_image (gimp, width, height, type,
+                                 precision, FALSE);
+      if (! image)
+        success = FALSE;
+    }
+  else
+    success = FALSE;
+}
+CODE
+    );
+}
+
 sub image_duplicate {
     $blurb = 'Duplicate the specified image';
 
@@ -2897,6 +2944,8 @@ CODE
               "core/gimpprogress.h"
               "core/gimptempbuf.h"
               "core/gimpunit.h"
+              "plug-in/gimpplugin.h"
+              "plug-in/gimppluginmanager.h"
               "gimppdbcontext.h"
               "gimppdberror.h"
               "gimppdb-utils.h"
@@ -2904,7 +2953,8 @@ CODE
 
 @procs = qw(image_is_valid
             image_list
-            image_new image_duplicate image_delete
+            image_new image_new_with_precision
+            image_duplicate image_delete
             image_base_type
             image_width image_height
             image_free_shadow
@@ -2961,7 +3011,7 @@ CODE
 # image_add_layer_mask and image_remove_layer_mask.
 # If adding or removing functions, make sure the range below is
 # updated correctly!
-%exports = (app => [ procs], lib => [ procs[0  42,45..83]]);
+%exports = (app => [ procs], lib => [ procs[0  43,46..84]]);
 
 $desc = 'Image';
 $doc_title = 'gimpimage';



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