pdb, libgimp: add gimp_image_set_color_profile_from_file()

which sets the profile from a file containing an ICC profile.
This commit is contained in:
Michael Natterer 2015-07-28 23:01:18 +02:00
parent ccd2264a4c
commit b0735c9448
6 changed files with 166 additions and 4 deletions

View File

@ -179,6 +179,50 @@ image_set_color_profile_invoker (GimpProcedure *procedure,
error ? *error : NULL);
}
static GimpValueArray *
image_set_color_profile_from_file_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GimpValueArray *args,
GError **error)
{
gboolean success = TRUE;
GimpImage *image;
const gchar *uri;
image = gimp_value_get_image (gimp_value_array_index (args, 0), gimp);
uri = g_value_get_string (gimp_value_array_index (args, 1));
if (success)
{
if (uri)
{
GFile *file = g_file_new_for_uri (uri);
GimpColorProfile *profile;
profile = gimp_color_profile_new_from_file (file, error);
if (profile)
{
success = gimp_image_set_color_profile (image, profile, error);
g_object_unref (profile);
}
else
success = FALSE;
g_object_unref (file);
}
else
{
success = gimp_image_set_color_profile (image, NULL, error);
}
}
return gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
}
static GimpValueArray *
image_convert_color_profile_invoker (GimpProcedure *procedure,
Gimp *gimp,
@ -310,7 +354,7 @@ register_image_color_profile_procs (GimpPDB *pdb)
gimp_procedure_set_static_strings (procedure,
"gimp-image-set-color-profile",
"Sets the image's color profile",
"This procedure sets the image's color profile, or unsets it if NULL is passed as 'color_profile'.",
"This procedure sets the image's color profile, or unsets it if NULL is passed as 'color_profile'. This procedure does no color conversion.",
"Michael Natterer <mitch@gimp.org>",
"Michael Natterer",
"2015",
@ -335,6 +379,36 @@ register_image_color_profile_procs (GimpPDB *pdb)
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-image-set-color-profile-from-file
*/
procedure = gimp_procedure_new (image_set_color_profile_from_file_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-image-set-color-profile-from-file");
gimp_procedure_set_static_strings (procedure,
"gimp-image-set-color-profile-from-file",
"Sets the image's color profile from an ICC file",
"This procedure sets the image's color profile from a file containing an ICC profile, or unsets it if NULL is passed as 'uri'. This procedure does no color conversion.",
"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_string ("uri",
"uri",
"The URI of the file containing the new color profile",
FALSE, FALSE, FALSE,
NULL,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-image-convert-color-profile
*/

View File

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

View File

@ -498,6 +498,7 @@ EXPORTS
gimp_image_set_active_vectors
gimp_image_set_cmap
gimp_image_set_color_profile
gimp_image_set_color_profile_from_file
gimp_image_set_colormap
gimp_image_set_component_active
gimp_image_set_component_visible

View File

@ -137,7 +137,8 @@ _gimp_image_get_effective_color_profile (gint32 image_ID,
* Sets the image's color profile
*
* This procedure sets the image's color profile, or unsets it if NULL
* is passed as 'color_profile'.
* is passed as 'color_profile'. This procedure does no color
* conversion.
*
* Returns: TRUE on success.
*
@ -166,6 +167,42 @@ _gimp_image_set_color_profile (gint32 image_ID,
return success;
}
/**
* gimp_image_set_color_profile_from_file:
* @image_ID: The image.
* @uri: The URI of the file containing the new color profile.
*
* Sets the image's color profile from an ICC file
*
* This procedure sets the image's color profile from a file containing
* an ICC profile, or unsets it if NULL is passed as 'uri'. This
* procedure does no color conversion.
*
* Returns: TRUE on success.
*
* Since: 2.10
**/
gboolean
gimp_image_set_color_profile_from_file (gint32 image_ID,
const gchar *uri)
{
GimpParam *return_vals;
gint nreturn_vals;
gboolean success = TRUE;
return_vals = gimp_run_procedure ("gimp-image-set-color-profile-from-file",
&nreturn_vals,
GIMP_PDB_IMAGE, image_ID,
GIMP_PDB_STRING, uri,
GIMP_PDB_END);
success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
gimp_destroy_params (return_vals, nreturn_vals);
return success;
}
/**
* _gimp_image_convert_color_profile:
* @image_ID: The image.

View File

@ -39,6 +39,8 @@ G_GNUC_INTERNAL guint8* _gimp_image_get_effective_color_profile (gint32
G_GNUC_INTERNAL gboolean _gimp_image_set_color_profile (gint32 image_ID,
gint num_bytes,
const guint8 *color_profile);
gboolean gimp_image_set_color_profile_from_file (gint32 image_ID,
const gchar *uri);
G_GNUC_INTERNAL gboolean _gimp_image_convert_color_profile (gint32 image_ID,
gint num_bytes,
const guint8 *color_profile,

View File

@ -113,7 +113,7 @@ sub image_set_color_profile {
$help = <<'HELP';
This procedure sets the image's color profile, or unsets it if NULL is
passed as 'color_profile'.
passed as 'color_profile'. This procedure does no color conversion.
HELP
&mitch_pdb_misc('2015', '2.10');
@ -155,6 +155,53 @@ CODE
);
}
sub image_set_color_profile_from_file {
$blurb = "Sets the image's color profile from an ICC file";
$help = <<'HELP';
This procedure sets the image's color profile from a file containing
an ICC profile, or unsets it if NULL is passed as 'uri'. This
procedure does no color conversion.
HELP
&mitch_pdb_misc('2015', '2.10');
@inargs = (
{ name => 'image', type => 'image',
desc => 'The image' },
{ name => 'uri', type => 'string',
desc => 'The URI of the file containing the new color profile' }
);
%invoke = (
code => <<'CODE'
{
if (uri)
{
GFile *file = g_file_new_for_uri (uri);
GimpColorProfile *profile;
profile = gimp_color_profile_new_from_file (file, error);
if (profile)
{
success = gimp_image_set_color_profile (image, profile, error);
g_object_unref (profile);
}
else
success = FALSE;
g_object_unref (file);
}
else
{
success = gimp_image_set_color_profile (image, NULL, error);
}
}
CODE
);
}
sub image_convert_color_profile {
$blurb = "Convert the image's layers to a color profile";
@ -215,6 +262,7 @@ CODE
@procs = qw(image_get_color_profile
image_get_effective_color_profile
image_set_color_profile
image_set_color_profile_from_file
image_convert_color_profile);
%exports = (app => [@procs], lib => [@procs]);