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.
This commit is contained in:
Michael Natterer 2015-06-10 01:38:20 +02:00
parent 1ade7ffee5
commit c632ffad18
12 changed files with 289 additions and 16 deletions

View File

@ -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);
}

View File

@ -28,7 +28,7 @@
#include "internal-procs.h"
/* 760 procedures registered total */
/* 761 procedures registered total */
void
internal_procs_init (GimpPDB *pdb)

View File

@ -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@\" }," \

View File

@ -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

View File

@ -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",

View File

@ -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;
}

View File

@ -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

View File

@ -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;
}

View File

@ -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

View File

@ -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 = \

View File

@ -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',

View File

@ -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]);