[gimp/metadata-browser] pdb/libgimp: export enum GimpPrecision and gimp-image-convert-precision
- From: Roman Joost <romanofski src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/metadata-browser] pdb/libgimp: export enum GimpPrecision and gimp-image-convert-precision
- Date: Wed, 12 Sep 2012 23:57:49 +0000 (UTC)
commit e49859447e0fbf46535bd6dbe37cf68e48a603a6
Author: Michael Natterer <mitch gimp org>
Date: Wed Apr 25 20:16:29 2012 +0200
pdb/libgimp: export enum GimpPrecision and gimp-image-convert-precision
app/core/core-enums.h | 2 +-
app/pdb/convert-cmds.c | 66 ++++++++++++++++++++++++++++++++++++++++-
app/pdb/gimppdb-utils.c | 28 +++++++++++++++--
app/pdb/gimppdb-utils.h | 5 ++-
app/pdb/internal-procs.c | 2 +-
libgimp/gimp.def | 2 +
libgimp/gimpconvert_pdb.c | 36 +++++++++++++++++++++++
libgimp/gimpconvert_pdb.h | 2 +
libgimp/gimpenums.c.tail | 2 +
libgimp/gimpenums.h | 12 +++++++
tools/pdbgen/enums.pl | 9 ++++++
tools/pdbgen/pdb/convert.pdb | 42 ++++++++++++++++++++++++--
12 files changed, 196 insertions(+), 12 deletions(-)
---
diff --git a/app/core/core-enums.h b/app/core/core-enums.h
index a49c8cc..a46608a 100644
--- a/app/core/core-enums.h
+++ b/app/core/core-enums.h
@@ -328,7 +328,7 @@ typedef enum
GType gimp_precision_get_type (void) G_GNUC_CONST;
-typedef enum /*< pdb-skip >*/
+typedef enum
{
GIMP_PRECISION_U8, /*< desc="8-bit unsigned integer" >*/
GIMP_PRECISION_U16, /*< desc="16-bit unsigned integer" >*/
diff --git a/app/pdb/convert-cmds.c b/app/pdb/convert-cmds.c
index ca63696..a2f7c4c 100644
--- a/app/pdb/convert-cmds.c
+++ b/app/pdb/convert-cmds.c
@@ -129,8 +129,8 @@ image_convert_indexed_invoker (GimpProcedure *procedure,
{
GimpPalette *pal = NULL;
- if (gimp_pdb_image_is_not_base_type (image, GIMP_INDEXED, error) &&
- gimp_pdb_image_has_precision (image, GIMP_PRECISION_U8, error) &&
+ if (gimp_pdb_image_is_not_base_type (image, GIMP_INDEXED, error) &&
+ gimp_pdb_image_is_precision (image, GIMP_PRECISION_U8, error) &&
gimp_item_stack_is_flat (GIMP_ITEM_STACK (gimp_image_get_layers (image))))
{
switch (palette_type)
@@ -216,6 +216,38 @@ image_convert_set_dither_matrix_invoker (GimpProcedure *procedure,
error ? *error : NULL);
}
+static GValueArray *
+image_convert_precision_invoker (GimpProcedure *procedure,
+ Gimp *gimp,
+ GimpContext *context,
+ GimpProgress *progress,
+ const GValueArray *args,
+ GError **error)
+{
+ gboolean success = TRUE;
+ GimpImage *image;
+ gint32 precision;
+
+ image = gimp_value_get_image (&args->values[0], gimp);
+ precision = g_value_get_enum (&args->values[1]);
+
+ if (success)
+ {
+ if (gimp_pdb_image_is_not_base_type (image, GIMP_INDEXED, error) &&
+ gimp_pdb_image_is_not_precision (image, precision, error))
+ {
+ gimp_image_convert_precision (image, precision, NULL);
+ }
+ else
+ {
+ success = FALSE;
+ }
+ }
+
+ return gimp_procedure_get_return_values (procedure, success,
+ error ? *error : NULL);
+}
+
void
register_convert_procs (GimpPDB *pdb)
{
@@ -368,4 +400,34 @@ register_convert_procs (GimpPDB *pdb)
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
+
+ /*
+ * gimp-image-convert-precision
+ */
+ procedure = gimp_procedure_new (image_convert_precision_invoker);
+ gimp_object_set_static_name (GIMP_OBJECT (procedure),
+ "gimp-image-convert-precision");
+ gimp_procedure_set_static_strings (procedure,
+ "gimp-image-convert-precision",
+ "Convert the image to the specified precision",
+ "This procedure converts the image to the specified precision. Note that indexed images cannot be converted and are always in GIMP_PRECISION_U8.",
+ "Michael Natterer <mitch gimp org>",
+ "Michael Natterer",
+ "2012",
+ NULL);
+ gimp_procedure_add_argument (procedure,
+ gimp_param_spec_image_id ("image",
+ "image",
+ "The image",
+ pdb->gimp, FALSE,
+ GIMP_PARAM_READWRITE));
+ gimp_procedure_add_argument (procedure,
+ g_param_spec_enum ("precision",
+ "precision",
+ "The new precision",
+ GIMP_TYPE_PRECISION,
+ GIMP_PRECISION_U8,
+ GIMP_PARAM_READWRITE));
+ gimp_pdb_register_procedure (pdb, procedure);
+ g_object_unref (procedure);
}
diff --git a/app/pdb/gimppdb-utils.c b/app/pdb/gimppdb-utils.c
index 245db60..4786d13 100644
--- a/app/pdb/gimppdb-utils.c
+++ b/app/pdb/gimppdb-utils.c
@@ -618,7 +618,7 @@ gimp_pdb_image_is_not_base_type (GimpImage *image,
return TRUE;
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
- _("Image '%s' (%d) is already of type '%s'"),
+ _("Image '%s' (%d) must not be of type '%s'"),
gimp_image_get_display_name (image),
gimp_image_get_ID (image),
gimp_pdb_enum_value_get_nick (GIMP_TYPE_IMAGE_BASE_TYPE, type));
@@ -627,9 +627,9 @@ gimp_pdb_image_is_not_base_type (GimpImage *image,
}
gboolean
-gimp_pdb_image_has_precision (GimpImage *image,
- GimpPrecision precision,
- GError **error)
+gimp_pdb_image_is_precision (GimpImage *image,
+ GimpPrecision precision,
+ GError **error)
{
g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
@@ -649,6 +649,26 @@ gimp_pdb_image_has_precision (GimpImage *image,
return FALSE;
}
+gboolean
+gimp_pdb_image_is_not_precision (GimpImage *image,
+ GimpPrecision precision,
+ 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_get_precision (image) != precision)
+ return TRUE;
+
+ g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
+ _("Image '%s' (%d) must not be of precision '%s'"),
+ gimp_image_get_display_name (image),
+ gimp_image_get_ID (image),
+ gimp_pdb_enum_value_get_nick (GIMP_TYPE_PRECISION, precision));
+
+ return FALSE;
+}
+
GimpStroke *
gimp_pdb_get_vectors_stroke (GimpVectors *vectors,
gint stroke_ID,
diff --git a/app/pdb/gimppdb-utils.h b/app/pdb/gimppdb-utils.h
index d7efe6f..426a634 100644
--- a/app/pdb/gimppdb-utils.h
+++ b/app/pdb/gimppdb-utils.h
@@ -88,7 +88,10 @@ gboolean gimp_pdb_image_is_not_base_type (GimpImage *image,
GimpImageBaseType type,
GError **error);
-gboolean gimp_pdb_image_has_precision (GimpImage *image,
+gboolean gimp_pdb_image_is_precision (GimpImage *image,
+ GimpPrecision precision,
+ GError **error);
+gboolean gimp_pdb_image_is_not_precision (GimpImage *image,
GimpPrecision precision,
GError **error);
diff --git a/app/pdb/internal-procs.c b/app/pdb/internal-procs.c
index 069cc9c..e820dff 100644
--- a/app/pdb/internal-procs.c
+++ b/app/pdb/internal-procs.c
@@ -28,7 +28,7 @@
#include "internal-procs.h"
-/* 670 procedures registered total */
+/* 671 procedures registered total */
void
internal_procs_init (GimpPDB *pdb)
diff --git a/libgimp/gimp.def b/libgimp/gimp.def
index f6c9fbf..6c5fd9e 100644
--- a/libgimp/gimp.def
+++ b/libgimp/gimp.def
@@ -366,6 +366,7 @@ EXPORTS
gimp_image_clean_all
gimp_image_convert_grayscale
gimp_image_convert_indexed
+ gimp_image_convert_precision
gimp_image_convert_rgb
gimp_image_convert_set_dither_matrix
gimp_image_crop
@@ -676,6 +677,7 @@ EXPORTS
gimp_plugin_precision_enabled
gimp_plugin_set_pdb_error_handler
gimp_posterize
+ gimp_precision_get_type
gimp_procedural_db_dump
gimp_procedural_db_get_data
gimp_procedural_db_get_data_size
diff --git a/libgimp/gimpconvert_pdb.c b/libgimp/gimpconvert_pdb.c
index 2f2ddf7..b529182 100644
--- a/libgimp/gimpconvert_pdb.c
+++ b/libgimp/gimpconvert_pdb.c
@@ -196,3 +196,39 @@ gimp_image_convert_set_dither_matrix (gint width,
return success;
}
+
+/**
+ * gimp_image_convert_precision:
+ * @image_ID: The image.
+ * @precision: The new precision.
+ *
+ * Convert the image to the specified precision
+ *
+ * This procedure converts the image to the specified precision. Note
+ * that indexed images cannot be converted and are always in
+ * GIMP_PRECISION_U8.
+ *
+ * Returns: TRUE on success.
+ *
+ * Since: GIMP 2.10
+ **/
+gboolean
+gimp_image_convert_precision (gint32 image_ID,
+ GimpPrecision precision)
+{
+ GimpParam *return_vals;
+ gint nreturn_vals;
+ gboolean success = TRUE;
+
+ return_vals = gimp_run_procedure ("gimp-image-convert-precision",
+ &nreturn_vals,
+ GIMP_PDB_IMAGE, image_ID,
+ GIMP_PDB_INT32, precision,
+ GIMP_PDB_END);
+
+ success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
+
+ gimp_destroy_params (return_vals, nreturn_vals);
+
+ return success;
+}
diff --git a/libgimp/gimpconvert_pdb.h b/libgimp/gimpconvert_pdb.h
index 1bf1eb4..a368004 100644
--- a/libgimp/gimpconvert_pdb.h
+++ b/libgimp/gimpconvert_pdb.h
@@ -45,6 +45,8 @@ gboolean gimp_image_convert_set_dither_matrix (gint width,
gint height,
gint matrix_length,
const guint8 *matrix);
+gboolean gimp_image_convert_precision (gint32 image_ID,
+ GimpPrecision precision);
G_END_DECLS
diff --git a/libgimp/gimpenums.c.tail b/libgimp/gimpenums.c.tail
index d5e0bac..d472342 100644
--- a/libgimp/gimpenums.c.tail
+++ b/libgimp/gimpenums.c.tail
@@ -41,6 +41,7 @@ static const GimpGetTypeFunc get_type_funcs[] =
gimp_pdb_proc_type_get_type,
gimp_pdb_status_type_get_type,
gimp_paint_application_mode_get_type,
+ gimp_precision_get_type,
gimp_progress_command_get_type,
gimp_repeat_mode_get_type,
gimp_rotation_type_get_type,
@@ -98,6 +99,7 @@ static const gchar * const type_names[] =
"GimpPDBProcType",
"GimpPDBStatusType",
"GimpPaintApplicationMode",
+ "GimpPrecision",
"GimpProgressCommand",
"GimpRepeatMode",
"GimpRotationType",
diff --git a/libgimp/gimpenums.h b/libgimp/gimpenums.h
index 70a6107..508cb6e 100644
--- a/libgimp/gimpenums.h
+++ b/libgimp/gimpenums.h
@@ -258,6 +258,18 @@ typedef enum
} GimpOrientationType;
+#define GIMP_TYPE_PRECISION (gimp_precision_get_type ())
+
+GType gimp_precision_get_type (void) G_GNUC_CONST;
+
+typedef enum
+{
+ GIMP_PRECISION_U8,
+ GIMP_PRECISION_U16,
+ GIMP_PRECISION_FLOAT
+} GimpPrecision;
+
+
#define GIMP_TYPE_ROTATION_TYPE (gimp_rotation_type_get_type ())
GType gimp_rotation_type_get_type (void) G_GNUC_CONST;
diff --git a/tools/pdbgen/enums.pl b/tools/pdbgen/enums.pl
index 63ff409..3f19a65 100644
--- a/tools/pdbgen/enums.pl
+++ b/tools/pdbgen/enums.pl
@@ -537,6 +537,15 @@ package Gimp::CodeGen::enums;
GIMP_ORIENTATION_VERTICAL => '1',
GIMP_ORIENTATION_UNKNOWN => '2' }
},
+ GimpPrecision =>
+ { contig => 1,
+ header => 'core/core-enums.h',
+ symbols => [ qw(GIMP_PRECISION_U8 GIMP_PRECISION_U16
+ GIMP_PRECISION_FLOAT) ],
+ mapping => { GIMP_PRECISION_U8 => '0',
+ GIMP_PRECISION_U16 => '1',
+ GIMP_PRECISION_FLOAT => '2' }
+ },
GimpRotationType =>
{ contig => 1,
header => 'core/core-enums.h',
diff --git a/tools/pdbgen/pdb/convert.pdb b/tools/pdbgen/pdb/convert.pdb
index d660ca9..419680e 100644
--- a/tools/pdbgen/pdb/convert.pdb
+++ b/tools/pdbgen/pdb/convert.pdb
@@ -130,8 +130,8 @@ HELP
{
GimpPalette *pal = NULL;
- if (gimp_pdb_image_is_not_base_type (image, GIMP_INDEXED, error) &&
- gimp_pdb_image_has_precision (image, GIMP_PRECISION_U8, error) &&
+ if (gimp_pdb_image_is_not_base_type (image, GIMP_INDEXED, error) &&
+ gimp_pdb_image_is_precision (image, GIMP_PRECISION_U8, error) &&
gimp_item_stack_is_flat (GIMP_ITEM_STACK (gimp_image_get_layers (image))))
{
switch (palette_type)
@@ -219,6 +219,41 @@ CODE
);
}
+sub image_convert_precision {
+ $blurb = 'Convert the image to the specified precision';
+
+ $help = <<'HELP';
+This procedure converts the image to the specified precision. Note
+that indexed images cannot be converted and are always in
+GIMP_PRECISION_U8.
+HELP
+
+ &mitch_pdb_misc('2012', '2.10');
+
+ @inargs = (
+ { name => 'image', type => 'image',
+ desc => 'The image' },
+ { name => 'precision', type => 'enum GimpPrecision',
+ desc => 'The new precision' }
+ );
+
+ %invoke = (
+ code => <<'CODE'
+{
+ if (gimp_pdb_image_is_not_base_type (image, GIMP_INDEXED, error) &&
+ gimp_pdb_image_is_not_precision (image, precision, error))
+ {
+ gimp_image_convert_precision (image, precision, NULL);
+ }
+ else
+ {
+ success = FALSE;
+ }
+}
+CODE
+ );
+}
+
@headers = qw("core/gimpimage.h"
"core/gimpimage-convert.h"
"core/gimpitemstack.h"
@@ -230,7 +265,8 @@ CODE
@procs = qw(image_convert_rgb
image_convert_grayscale
image_convert_indexed
- image_convert_set_dither_matrix);
+ image_convert_set_dither_matrix
+ image_convert_precision);
%exports = (app => [ procs], lib => [ procs]);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]