Commit b3dbb968 authored by Michael Natterer's avatar Michael Natterer 😴

app: correctly deal with color profiles when converting from/to GRAY

Convert the layers to the new GimpImageBaseType's builtin color
profile because the converted image will have its color profile
removed.
parent 3deab93b
......@@ -1092,7 +1092,10 @@ gimp_image_convert_type (GimpImage *image,
break;
}
/* TODO: attach or remove the ICC profile */
/* When converting to/from GRAY, remove the profile.
* gimp_layer_convert_type() has converted the layers to
* new_type's builtin profile.
*/
switch (new_type)
{
case GIMP_RGB:
......@@ -1100,11 +1103,10 @@ gimp_image_convert_type (GimpImage *image,
if (old_type == GIMP_GRAY)
gimp_image_set_color_profile (image, NULL, NULL);
break;
case GIMP_GRAY:
gimp_image_set_color_profile (image, NULL, NULL);
break;
default:
break;
}
/* Delete the quantizer object, if there is one */
......
......@@ -173,7 +173,7 @@ static void gimp_layer_convert_type (GimpDrawable *drawable,
GimpPrecision new_precision,
gint layer_dither_type,
gint mask_dither_type,
gboolean convert_type,
gboolean convert_profile,
gboolean push_undo,
GimpProgress *progress);
static void gimp_layer_invalidate_boundary (GimpDrawable *drawable);
......@@ -1122,14 +1122,16 @@ gimp_layer_convert_type (GimpDrawable *drawable,
{
const Babl *src_format = gimp_drawable_get_format (drawable);
/* when converting between linear and gamma, we create a new
* profile using the original profile's chromacities and
* whitepoint, but a linear/sRGB-gamma TRC.
* gimp_image_convert_precision() will use the same profile.
*/
if (gimp_babl_format_get_linear (src_format) !=
gimp_babl_format_get_linear (new_format))
{
/* when converting between linear and gamma, we create a
* new profile using the original profile's chromacities
* and whitepoint, but a linear/sRGB-gamma TRC.
* gimp_image_convert_precision() will use the same
* profile.
*/
src_profile =
gimp_color_managed_get_color_profile (GIMP_COLOR_MANAGED (layer));
......@@ -1144,9 +1146,9 @@ gimp_layer_convert_type (GimpDrawable *drawable,
gimp_color_profile_new_srgb_gamma_from_color_profile (src_profile);
}
/* if a new profile cannot be be generated, convert to the
* builtin profile, which is better than leaving the user
* with broken colors
/* if a new profile cannot be be generated, convert to
* the builtin profile, which is better than leaving the
* user with broken colors
*/
if (! dest_profile)
{
......@@ -1155,6 +1157,22 @@ gimp_layer_convert_type (GimpDrawable *drawable,
g_object_ref (dest_profile);
}
}
else if (gimp_drawable_get_base_type (drawable) != new_base_type &&
(gimp_drawable_get_base_type (drawable) == GIMP_GRAY ||
new_base_type == GIMP_GRAY))
{
/* when converting to/from GRAY, convert to the new
* type's builtin profile because the conversion will
* get rid of the profile, see gimp_image_convert_type().
*/
src_profile =
gimp_color_managed_get_color_profile (GIMP_COLOR_MANAGED (layer));
dest_profile =
gimp_image_get_builtin_color_profile (dest_image);
g_object_ref (dest_profile);
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment