[gimp] pdb, app, libgimp: add gimp_image_convert_color_profile() PDB wrapper
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] pdb, app, libgimp: add gimp_image_convert_color_profile() PDB wrapper
- Date: Wed, 10 Jun 2015 00:05:56 +0000 (UTC)
commit c632ffad189adaf3722c1c665476bbfb1c536134
Author: Michael Natterer <mitch gimp org>
Date: Wed Jun 10 01:38:20 2015 +0200
pdb, app, libgimp: add gimp_image_convert_color_profile() PDB wrapper
This commit is more complex than a usual PDB procedure because it
needs to make the enums from libgimpconfig/gimpcolorconfig-enums.h
known to the PDB.
app/pdb/image-color-profile-cmds.c | 94 ++++++++++++++++++++++++++++++
app/pdb/internal-procs.c | 2 +-
libgimp/Makefile.am | 2 +-
libgimp/gimp.def | 1 +
libgimp/gimpenums.c.tail | 4 +
libgimp/gimpimagecolorprofile.c | 45 ++++++++++++++
libgimp/gimpimagecolorprofile.h | 13 +++-
libgimp/gimpimagecolorprofile_pdb.c | 45 ++++++++++++++
libgimp/gimpimagecolorprofile_pdb.h | 19 ++++--
tools/pdbgen/Makefile.am | 5 +-
tools/pdbgen/enums.pl | 22 +++++++
tools/pdbgen/pdb/image_color_profile.pdb | 53 ++++++++++++++++-
12 files changed, 289 insertions(+), 16 deletions(-)
---
diff --git a/app/pdb/image-color-profile-cmds.c b/app/pdb/image-color-profile-cmds.c
index f927430..ab6a6f1 100644
--- a/app/pdb/image-color-profile-cmds.c
+++ b/app/pdb/image-color-profile-cmds.c
@@ -172,6 +172,53 @@ image_get_effective_color_profile_invoker (GimpProcedure *procedure,
return return_vals;
}
+static GimpValueArray *
+image_convert_color_profile_invoker (GimpProcedure *procedure,
+ Gimp *gimp,
+ GimpContext *context,
+ GimpProgress *progress,
+ const GimpValueArray *args,
+ GError **error)
+{
+ gboolean success = TRUE;
+ GimpImage *image;
+ gint32 num_bytes;
+ const guint8 *color_profile;
+ gint32 intent;
+ gboolean bpc;
+
+ image = gimp_value_get_image (gimp_value_array_index (args, 0), gimp);
+ num_bytes = g_value_get_int (gimp_value_array_index (args, 1));
+ color_profile = gimp_value_get_int8array (gimp_value_array_index (args, 2));
+ intent = g_value_get_enum (gimp_value_array_index (args, 3));
+ bpc = g_value_get_boolean (gimp_value_array_index (args, 4));
+
+ if (success)
+ {
+ if (color_profile)
+ {
+ GimpColorProfile profile;
+
+ profile = gimp_color_profile_open_from_data (color_profile, num_bytes,
+ error);
+
+ if (profile)
+ {
+ success = gimp_image_convert_color_profile (image, profile,
+ intent, bpc,
+ progress, error);
+ }
+ else
+ success = FALSE;
+ }
+ else
+ success = FALSE;
+ }
+
+ return gimp_procedure_get_return_values (procedure, success,
+ error ? *error : NULL);
+}
+
void
register_image_color_profile_procs (GimpPDB *pdb)
{
@@ -278,4 +325,51 @@ register_image_color_profile_procs (GimpPDB *pdb)
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
+
+ /*
+ * gimp-image-convert-color-profile
+ */
+ procedure = gimp_procedure_new (image_convert_color_profile_invoker);
+ gimp_object_set_static_name (GIMP_OBJECT (procedure),
+ "gimp-image-convert-color-profile");
+ gimp_procedure_set_static_strings (procedure,
+ "gimp-image-convert-color-profile",
+ "Convert the image's layers to a color profile",
+ "This procedure converts from the image's color profile (or the default
RGB profile if none is set) to the given color profile. Only RGB color profiles are accepted.",
+ "Michael Natterer <mitch gimp org>",
+ "Michael Natterer",
+ "2015",
+ 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,
+ gimp_param_spec_int32 ("num-bytes",
+ "num bytes",
+ "Number of bytes in the color_profile array",
+ 0, G_MAXINT32, 0,
+ GIMP_PARAM_READWRITE));
+ gimp_procedure_add_argument (procedure,
+ gimp_param_spec_int8_array ("color-profile",
+ "color profile",
+ "The serialized color profile",
+ GIMP_PARAM_READWRITE));
+ gimp_procedure_add_argument (procedure,
+ g_param_spec_enum ("intent",
+ "intent",
+ "Rendering intent",
+ GIMP_TYPE_COLOR_RENDERING_INTENT,
+ GIMP_COLOR_RENDERING_INTENT_PERCEPTUAL,
+ GIMP_PARAM_READWRITE));
+ gimp_procedure_add_argument (procedure,
+ g_param_spec_boolean ("bpc",
+ "bpc",
+ "Black point compensation",
+ FALSE,
+ GIMP_PARAM_READWRITE));
+ gimp_pdb_register_procedure (pdb, procedure);
+ g_object_unref (procedure);
}
diff --git a/app/pdb/internal-procs.c b/app/pdb/internal-procs.c
index 25c8b3a..cada75b 100644
--- a/app/pdb/internal-procs.c
+++ b/app/pdb/internal-procs.c
@@ -28,7 +28,7 @@
#include "internal-procs.h"
-/* 760 procedures registered total */
+/* 761 procedures registered total */
void
internal_procs_init (GimpPDB *pdb)
diff --git a/libgimp/Makefile.am b/libgimp/Makefile.am
index bf52189..a4cd0fa 100644
--- a/libgimp/Makefile.am
+++ b/libgimp/Makefile.am
@@ -431,7 +431,7 @@ CLEANFILES = $(gen_sources)
gimpenums.c: $(srcdir)/gimpenums.h $(srcdir)/gimpenums.c.tail $(GIMP_MKENUMS)
$(GIMP_MKENUMS) \
- --fhead "#include \"config.h\"\n#include <gio/gio.h>\n#undef
GIMP_DISABLE_DEPRECATED\n#include \"libgimpbase/gimpbase.h\"\n#include \"gimpenums.h\"" \
+ --fhead "#include \"config.h\"\n#include <gio/gio.h>\n#undef
GIMP_DISABLE_DEPRECATED\n#include \"libgimpbase/gimpbase.h\"\n#include
\"libgimpconfig/gimpcolorconfig-enums.h\"\n#include \"gimpenums.h\"" \
--fprod "\n/* enumerations from \"@filename \" */" \
--vhead "GType\n enum_name@_get_type (void)\n{\n static const G Type@Value values[] =\n {" \
--vprod " { @VALUENAME@, \"@VALUENAME \", \"@valuenick \" }," \
diff --git a/libgimp/gimp.def b/libgimp/gimp.def
index a244b05..de42af0 100644
--- a/libgimp/gimp.def
+++ b/libgimp/gimp.def
@@ -378,6 +378,7 @@ EXPORTS
gimp_image_attach_parasite
gimp_image_base_type
gimp_image_clean_all
+ gimp_image_convert_color_profile
gimp_image_convert_grayscale
gimp_image_convert_indexed
gimp_image_convert_precision
diff --git a/libgimp/gimpenums.c.tail b/libgimp/gimpenums.c.tail
index 3ab7f62..27da775 100644
--- a/libgimp/gimpenums.c.tail
+++ b/libgimp/gimpenums.c.tail
@@ -11,6 +11,8 @@ static const GimpGetTypeFunc get_type_funcs[] =
gimp_channel_ops_get_type,
gimp_channel_type_get_type,
gimp_clone_type_get_type,
+ gimp_color_management_mode_get_type,
+ gimp_color_rendering_intent_get_type,
gimp_component_type_get_type,
gimp_convert_dither_type_get_type,
gimp_convert_palette_type_get_type,
@@ -69,6 +71,8 @@ static const gchar * const type_names[] =
"GimpChannelOps",
"GimpChannelType",
"GimpCloneType",
+ "GimpColorManagementMode",
+ "GimpColorRenderingIntent",
"GimpComponentType",
"GimpConvertDitherType",
"GimpConvertPaletteType",
diff --git a/libgimp/gimpimagecolorprofile.c b/libgimp/gimpimagecolorprofile.c
index bec5c8e..200ab00 100644
--- a/libgimp/gimpimagecolorprofile.c
+++ b/libgimp/gimpimagecolorprofile.c
@@ -134,3 +134,48 @@ gimp_image_get_effective_color_profile (gint32 image_ID)
return NULL;
}
+
+/**
+ * gimp_image_convert_color_profile:
+ * @image_ID: The image.
+ * @profile: The color profile to convert to.
+ * @intent: Rendering intent.
+ * @bpc: Black point compensation.
+ *
+ * Convert the image's layers to a color profile
+ *
+ * This procedure converts from the image's color profile (or the
+ * default RGB profile if none is set) to the given color profile. Only
+ * RGB color profiles are accepted.
+ *
+ * Returns: TRUE on success.
+ *
+ * Since: 2.10
+ **/
+gboolean
+gimp_image_convert_color_profile (gint32 image_ID,
+ GimpColorProfile profile,
+ GimpColorRenderingIntent intent,
+ gboolean bpc)
+{
+ guint8 *data = NULL;
+ gint length = 0;
+ gboolean success;
+
+ if (profile)
+ {
+ gsize l;
+
+ data = gimp_color_profile_save_to_data (profile, &l, NULL);
+ length = l;
+
+ if (! data)
+ return FALSE;
+ }
+
+ success = _gimp_image_convert_color_profile (image_ID, length, data,
+ intent, bpc);
+ g_free (data);
+
+ return success;
+}
diff --git a/libgimp/gimpimagecolorprofile.h b/libgimp/gimpimagecolorprofile.h
index d6eac9f..33e7cc5 100644
--- a/libgimp/gimpimagecolorprofile.h
+++ b/libgimp/gimpimagecolorprofile.h
@@ -30,11 +30,16 @@ G_BEGIN_DECLS
/* For information look into the C source or the html documentation */
-GimpColorProfile gimp_image_get_color_profile (gint32 image_ID);
-gboolean gimp_image_set_color_profile (gint32 image_ID,
- GimpColorProfile profile);
+GimpColorProfile gimp_image_get_color_profile (gint32 image_ID);
+gboolean gimp_image_set_color_profile (gint32 image_ID,
+ GimpColorProfile profile);
-GimpColorProfile gimp_image_get_effective_color_profile (gint32 image_ID);
+GimpColorProfile gimp_image_get_effective_color_profile (gint32 image_ID);
+
+gboolean gimp_image_convert_color_profile (gint32 image_ID,
+ GimpColorProfile profile,
+ GimpColorRenderingIntent intent,
+ gboolean bpc);
G_END_DECLS
diff --git a/libgimp/gimpimagecolorprofile_pdb.c b/libgimp/gimpimagecolorprofile_pdb.c
index 0318a13..3004c53 100644
--- a/libgimp/gimpimagecolorprofile_pdb.c
+++ b/libgimp/gimpimagecolorprofile_pdb.c
@@ -165,3 +165,48 @@ _gimp_image_get_effective_color_profile (gint32 image_ID,
return profile_data;
}
+
+/**
+ * _gimp_image_convert_color_profile:
+ * @image_ID: The image.
+ * @num_bytes: Number of bytes in the color_profile array.
+ * @color_profile: The serialized color profile.
+ * @intent: Rendering intent.
+ * @bpc: Black point compensation.
+ *
+ * Convert the image's layers to a color profile
+ *
+ * This procedure converts from the image's color profile (or the
+ * default RGB profile if none is set) to the given color profile. Only
+ * RGB color profiles are accepted.
+ *
+ * Returns: TRUE on success.
+ *
+ * Since: 2.10
+ **/
+gboolean
+_gimp_image_convert_color_profile (gint32 image_ID,
+ gint num_bytes,
+ const guint8 *color_profile,
+ GimpColorRenderingIntent intent,
+ gboolean bpc)
+{
+ GimpParam *return_vals;
+ gint nreturn_vals;
+ gboolean success = TRUE;
+
+ return_vals = gimp_run_procedure ("gimp-image-convert-color-profile",
+ &nreturn_vals,
+ GIMP_PDB_IMAGE, image_ID,
+ GIMP_PDB_INT32, num_bytes,
+ GIMP_PDB_INT8ARRAY, color_profile,
+ GIMP_PDB_INT32, intent,
+ GIMP_PDB_INT32, bpc,
+ 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/gimpimagecolorprofile_pdb.h b/libgimp/gimpimagecolorprofile_pdb.h
index 17ec089..f5a1a58 100644
--- a/libgimp/gimpimagecolorprofile_pdb.h
+++ b/libgimp/gimpimagecolorprofile_pdb.h
@@ -32,13 +32,18 @@ G_BEGIN_DECLS
/* For information look into the C source or the html documentation */
-G_GNUC_INTERNAL guint8* _gimp_image_get_color_profile (gint32 image_ID,
- gint *num_bytes);
-G_GNUC_INTERNAL gboolean _gimp_image_set_color_profile (gint32 image_ID,
- gint num_bytes,
- const guint8 *color_profile);
-G_GNUC_INTERNAL guint8* _gimp_image_get_effective_color_profile (gint32 image_ID,
- gint *num_bytes);
+G_GNUC_INTERNAL guint8* _gimp_image_get_color_profile (gint32 image_ID,
+ gint *num_bytes);
+G_GNUC_INTERNAL gboolean _gimp_image_set_color_profile (gint32 image_ID,
+ gint num_bytes,
+ const guint8 *color_profile);
+G_GNUC_INTERNAL guint8* _gimp_image_get_effective_color_profile (gint32 image_ID,
+ gint *num_bytes);
+G_GNUC_INTERNAL gboolean _gimp_image_convert_color_profile (gint32 image_ID,
+ gint num_bytes,
+ const guint8 *color_profile,
+ GimpColorRenderingIntent intent,
+ gboolean bpc);
G_END_DECLS
diff --git a/tools/pdbgen/Makefile.am b/tools/pdbgen/Makefile.am
index ef326b4..eccad93 100644
--- a/tools/pdbgen/Makefile.am
+++ b/tools/pdbgen/Makefile.am
@@ -73,8 +73,9 @@ EXTRA_DIST = \
$(pdb_sources)
enum_headers = \
- ../../libgimpbase/gimpbaseenums.h \
- ../../app/core/core-enums.h \
+ ../../libgimpbase/gimpbaseenums.h \
+ ../../libgimpconfig/gimpcolorconfig-enums.h \
+ ../../app/core/core-enums.h \
../../app/paint/paint-enums.h
pdb_scripts = \
diff --git a/tools/pdbgen/enums.pl b/tools/pdbgen/enums.pl
index e632258..b5d39e2 100644
--- a/tools/pdbgen/enums.pl
+++ b/tools/pdbgen/enums.pl
@@ -602,6 +602,28 @@ package Gimp::CodeGen::enums;
symbols => [ qw(GIMP_VECTORS_STROKE_TYPE_BEZIER) ],
mapping => { GIMP_VECTORS_STROKE_TYPE_BEZIER => '0' }
},
+ GimpColorManagementMode =>
+ { contig => 1,
+ header => 'libgimpconfig/gimpcolorconfig-enums.h',
+ symbols => [ qw(GIMP_COLOR_MANAGEMENT_OFF
+ GIMP_COLOR_MANAGEMENT_DISPLAY
+ GIMP_COLOR_MANAGEMENT_SOFTPROOF) ],
+ mapping => { GIMP_COLOR_MANAGEMENT_OFF => '0',
+ GIMP_COLOR_MANAGEMENT_DISPLAY => '1',
+ GIMP_COLOR_MANAGEMENT_SOFTPROOF => '2' }
+ },
+ GimpColorRenderingIntent =>
+ { contig => 1,
+ header => 'libgimpconfig/gimpcolorconfig-enums.h',
+ symbols => [ qw(GIMP_COLOR_RENDERING_INTENT_PERCEPTUAL
+ GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC
+ GIMP_COLOR_RENDERING_INTENT_SATURATION
+ GIMP_COLOR_RENDERING_INTENT_ABSOLUTE_COLORIMETRIC) ],
+ mapping => { GIMP_COLOR_RENDERING_INTENT_PERCEPTUAL => '0',
+ GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC => '1',
+ GIMP_COLOR_RENDERING_INTENT_SATURATION => '2',
+ GIMP_COLOR_RENDERING_INTENT_ABSOLUTE_COLORIMETRIC => '3' }
+ },
GimpConvertDitherType =>
{ contig => 1,
header => 'core/core-enums.h',
diff --git a/tools/pdbgen/pdb/image_color_profile.pdb b/tools/pdbgen/pdb/image_color_profile.pdb
index 0b14690..c401ebf 100644
--- a/tools/pdbgen/pdb/image_color_profile.pdb
+++ b/tools/pdbgen/pdb/image_color_profile.pdb
@@ -148,6 +148,56 @@ CODE
);
}
+sub image_convert_color_profile {
+ $blurb = "Convert the image's layers to a color profile";
+
+ $help = <<'HELP';
+This procedure converts from the image's color profile (or the default
+RGB profile if none is set) to the given color profile. Only RGB color
+profiles are accepted.
+HELP
+
+ &mitch_pdb_misc('2015', '2.10');
+
+ @inargs = (
+ { name => 'image', type => 'image',
+ desc => 'The image' },
+ { name => 'color_profile', type => 'int8array', wrap => 1,
+ desc => 'The serialized color profile',
+ array => { name => 'num_bytes',
+ desc => 'Number of bytes in the color_profile array' } },
+ { name => 'intent', type => 'enum GimpColorRenderingIntent',
+ desc => 'Rendering intent' },
+ { name => 'bpc', type => 'boolean',
+ desc => 'Black point compensation' }
+ );
+
+ %invoke = (
+ code => <<'CODE'
+{
+ if (color_profile)
+ {
+ GimpColorProfile profile;
+
+ profile = gimp_color_profile_open_from_data (color_profile, num_bytes,
+ error);
+
+ if (profile)
+ {
+ success = gimp_image_convert_color_profile (image, profile,
+ intent, bpc,
+ progress, error);
+ }
+ else
+ success = FALSE;
+ }
+ else
+ success = FALSE;
+}
+CODE
+ );
+}
+
@headers = qw(<cairo.h>
"libgimpcolor/gimpcolor.h"
"core/gimpimage-profile.h"
@@ -155,7 +205,8 @@ CODE
@procs = qw(image_get_color_profile
image_set_color_profile
- image_get_effective_color_profile);
+ image_get_effective_color_profile
+ image_convert_color_profile);
%exports = (app => [ procs], lib => [ procs]);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]