app, libgimp, pdb: fix gimp_image_convert_color_profile() to allow NULL profile.

The function's documentation was already saying that we could set no
profile, except that in reality, setting NULL for the profile was simply
failing. Unless one checked the return value, the failure is also quite
silent. So let's actually implement what the docs say.

Also the concept of "default" profile might be a bit unclear in GIMP as
it could mean either built-in profiles or preferred ones (as set in
Preferences). I chose the former for this function, so I reword this
part of the docs.
This commit is contained in:
Jehan 2026-03-11 19:03:35 +01:00
parent dc3a2a4f32
commit ef4c0a9504
4 changed files with 46 additions and 36 deletions

View file

@ -470,26 +470,31 @@ image_convert_color_profile_invoker (GimpProcedure *procedure,
if (success)
{
if (color_profile)
{
GimpColorProfile *profile;
GimpColorProfile *profile;
if (color_profile && g_bytes_get_size (color_profile) > 0)
{
profile = gimp_color_profile_new_from_icc_profile (g_bytes_get_data (color_profile, NULL),
g_bytes_get_size (color_profile),
error);
if (profile)
{
success = gimp_image_convert_color_profile (image, profile,
intent, bpc,
progress, error);
g_object_unref (profile);
}
else
success = FALSE;
}
else
success = FALSE;
{
profile = gimp_image_get_builtin_color_profile (image);
g_object_ref (profile);
}
if (profile)
{
success = gimp_image_convert_color_profile (image, profile,
intent, bpc,
progress, error);
g_object_unref (profile);
}
else
{
success = FALSE;
}
}
return gimp_procedure_get_return_values (procedure, success,
@ -875,7 +880,7 @@ register_image_color_profile_procs (GimpPDB *pdb)
"gimp-image-convert-color-profile");
gimp_procedure_set_static_help (procedure,
"Convert the image's layers to a color profile",
"This procedure converts from the image's color profile (or the default RGB or grayscale profile if none is set) to the given color profile. Only RGB and grayscale color profiles are accepted, according to the image's type.",
"This procedure converts from the image's color profile (or the built-in RGB or grayscale profile if none is set) to the given color profile. Only RGB and grayscale color profiles are accepted, according to the image's type.",
NULL);
gimp_procedure_set_static_attribution (procedure,
"Michael Natterer <mitch@gimp.org>",

View file

@ -212,14 +212,14 @@ gimp_image_get_effective_color_profile (GimpImage *image)
/**
* gimp_image_convert_color_profile:
* @image: The image.
* @profile: The color profile to convert to.
* @profile: (nullable): The color profile to convert to.
* @intent: Rendering intent.
* @bpc: Black point compensation.
*
* Convert the image's layers to a color profile
* Convert the image's layers to a color profile.
*
* This procedure converts from the image's color profile (or the
* default profile if none is set) to the given color profile.
* built-in profile if none is set) to the given color profile.
*
* Only RGB and grayscale color profiles are accepted, according to the
* image's type.

View file

@ -470,14 +470,14 @@ gimp_image_set_simulation_bpc (GimpImage *image,
/**
* _gimp_image_convert_color_profile:
* @image: The image.
* @color_profile: The serialized color profile.
* @color_profile: (nullable): 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 or grayscale profile if none is set) to the given color
* built-in RGB or grayscale profile if none is set) to the given color
* profile. Only RGB and grayscale color profiles are accepted,
* according to the image's type.
*

View file

@ -453,7 +453,7 @@ 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
This procedure converts from the image's color profile (or the built-in
RGB or grayscale profile if none is set) to the given color profile. Only
RGB and grayscale color profiles are accepted, according to the image's
type.
@ -466,7 +466,7 @@ HELP
@inargs = (
{ name => 'image', type => 'image',
desc => 'The image' },
{ name => 'color_profile', type => 'bytes',
{ name => 'color_profile', type => 'bytes', none_ok => 1,
desc => 'The serialized color profile' },
{ name => 'intent', type => 'enum GimpColorRenderingIntent',
desc => 'Rendering intent' },
@ -477,26 +477,31 @@ HELP
%invoke = (
code => <<'CODE'
{
if (color_profile)
{
GimpColorProfile *profile;
GimpColorProfile *profile;
if (color_profile && g_bytes_get_size (color_profile) > 0)
{
profile = gimp_color_profile_new_from_icc_profile (g_bytes_get_data (color_profile, NULL),
g_bytes_get_size (color_profile),
error);
if (profile)
{
success = gimp_image_convert_color_profile (image, profile,
intent, bpc,
progress, error);
g_object_unref (profile);
}
else
success = FALSE;
}
else
success = FALSE;
{
profile = gimp_image_get_builtin_color_profile (image);
g_object_ref (profile);
}
if (profile)
{
success = gimp_image_convert_color_profile (image, profile,
intent, bpc,
progress, error);
g_object_unref (profile);
}
else
{
success = FALSE;
}
}
CODE
);