Bug 765176 - ICC profile conversions between grayscale and RGB images

Add a dest_profile parameter to gimp_image_convert_type() so a profile
can be chosen when converting between RGB and GRAY. Has no GUI yet.
This commit is contained in:
Michael Natterer
2016-04-30 17:48:07 +02:00
parent 33adec2a3e
commit 12f9aa9bd2
6 changed files with 40 additions and 26 deletions

View File

@ -195,7 +195,7 @@ image_convert_base_type_cmd_callback (GtkAction *action,
if (dialog)
gtk_widget_destroy (dialog);
if (! gimp_image_convert_type (image, value, NULL, &error))
if (! gimp_image_convert_type (image, value, NULL, NULL, &error))
{
gimp_message_literal (image->gimp,
G_OBJECT (widget), GIMP_MESSAGE_WARNING,

View File

@ -42,32 +42,38 @@
gboolean
gimp_image_convert_type (GimpImage *image,
GimpImageBaseType new_type,
GimpColorProfile *dest_profile,
GimpProgress *progress,
GError **error)
{
GimpImageBaseType old_type;
const Babl *new_layer_format;
GList *all_layers;
GList *list;
const gchar *undo_desc = NULL;
GimpProgress *sub_progress = NULL;
GimpColorProfile *dest_profile = NULL;
gint nth_layer;
gint n_layers;
g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
g_return_val_if_fail (new_type != gimp_image_get_base_type (image), FALSE);
g_return_val_if_fail (new_type != GIMP_INDEXED, FALSE);
g_return_val_if_fail (dest_profile == NULL || GIMP_IS_COLOR_PROFILE (dest_profile),
FALSE);
g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
gimp_set_busy (image->gimp);
new_layer_format = gimp_babl_format (new_type,
gimp_image_get_precision (image),
TRUE);
all_layers = gimp_image_get_layer_list (image);
n_layers = g_list_length (all_layers);
if (progress)
sub_progress = gimp_sub_progress_new (progress);
if (dest_profile &&
! gimp_image_validate_color_profile_by_format (new_layer_format,
dest_profile,
NULL, error))
{
return FALSE;
}
switch (new_type)
{
@ -83,6 +89,15 @@ gimp_image_convert_type (GimpImage *image,
g_return_val_if_reached (FALSE);
}
gimp_set_busy (image->gimp);
all_layers = gimp_image_get_layer_list (image);
n_layers = g_list_length (all_layers);
if (progress)
sub_progress = gimp_sub_progress_new (progress);
g_object_freeze_notify (G_OBJECT (image));
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_IMAGE_CONVERT,
@ -96,13 +111,13 @@ gimp_image_convert_type (GimpImage *image,
g_object_set (image, "base-type", new_type, NULL);
/* when converting to/from GRAY, convert to the new type's builtin
* profile.
/* When converting to/from GRAY, convert to the new type's builtin
* profile if none was passed.
*/
if (old_type == GIMP_GRAY ||
new_type == GIMP_GRAY)
{
if (gimp_image_get_color_profile (image))
if (! dest_profile && gimp_image_get_color_profile (image))
dest_profile = gimp_image_get_builtin_color_profile (image);
}

View File

@ -21,6 +21,7 @@
gboolean gimp_image_convert_type (GimpImage *image,
GimpImageBaseType new_type,
GimpColorProfile *dest_profile,
GimpProgress *progress,
GError **error);

View File

@ -64,7 +64,7 @@ image_convert_rgb_invoker (GimpProcedure *procedure,
{
if (gimp_pdb_image_is_not_base_type (image, GIMP_RGB, error))
{
success = gimp_image_convert_type (image, GIMP_RGB, NULL, error);
success = gimp_image_convert_type (image, GIMP_RGB, NULL, NULL, error);
}
else
{
@ -93,7 +93,7 @@ image_convert_grayscale_invoker (GimpProcedure *procedure,
{
if (gimp_pdb_image_is_not_base_type (image, GIMP_GRAY, error))
{
success = gimp_image_convert_type (image, GIMP_GRAY, NULL, error);
success = gimp_image_convert_type (image, GIMP_GRAY, NULL, NULL, error);
}
else
{
@ -292,8 +292,8 @@ register_image_convert_procs (GimpPDB *pdb)
"gimp-image-convert-grayscale");
gimp_procedure_set_static_strings (procedure,
"gimp-image-convert-grayscale",
"Convert specified image to grayscale (256 intensity levels)",
"This procedure converts the specified image to grayscale with 8 bits per pixel (256 intensity levels). This process requires an image in RGB or Indexed color mode.",
"Convert specified image to grayscale",
"This procedure converts the specified image to grayscale. This process requires an image in RGB or Indexed color mode.",
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1995-1996",

View File

@ -70,11 +70,10 @@ gimp_image_convert_rgb (gint32 image_ID)
* gimp_image_convert_grayscale:
* @image_ID: The image.
*
* Convert specified image to grayscale (256 intensity levels)
* Convert specified image to grayscale
*
* This procedure converts the specified image to grayscale with 8 bits
* per pixel (256 intensity levels). This process requires an image in
* RGB or Indexed color mode.
* This procedure converts the specified image to grayscale. This
* process requires an image in RGB or Indexed color mode.
*
* Returns: TRUE on success.
**/

View File

@ -37,7 +37,7 @@ HELP
{
if (gimp_pdb_image_is_not_base_type (image, GIMP_RGB, error))
{
success = gimp_image_convert_type (image, GIMP_RGB, NULL, error);
success = gimp_image_convert_type (image, GIMP_RGB, NULL, NULL, error);
}
else
{
@ -49,12 +49,11 @@ CODE
}
sub image_convert_grayscale {
$blurb = 'Convert specified image to grayscale (256 intensity levels)';
$blurb = 'Convert specified image to grayscale';
$help = <<'HELP';
This procedure converts the specified image to grayscale with 8 bits
per pixel (256 intensity levels). This process requires an image in RGB
or Indexed color mode.
This procedure converts the specified image to grayscale. This process
requires an image in RGB or Indexed color mode.
HELP
&std_pdb_misc;
@ -69,7 +68,7 @@ HELP
{
if (gimp_pdb_image_is_not_base_type (image, GIMP_GRAY, error))
{
success = gimp_image_convert_type (image, GIMP_GRAY, NULL, error);
success = gimp_image_convert_type (image, GIMP_GRAY, NULL, NULL, error);
}
else
{