plug-ins: export linear WebP if and only if the work image was 8-bit...

... linear itself AND if we export the profile.
Implement similar logics to WebP export as I did to JPEG in my previous
commit.

(cherry picked from commit b9458f8a6e)
This commit is contained in:
Jehan
2019-04-15 23:52:53 +02:00
parent ec132fa396
commit d1d0022500

View File

@ -160,21 +160,32 @@ save_layer (const gchar *filename,
struct stat stsz; struct stat stsz;
int fd_outfile; int fd_outfile;
WebPData chunk; WebPData chunk;
gboolean out_linear = FALSE;
int res; int res;
profile = gimp_image_get_color_profile (image_ID); profile = gimp_image_get_color_profile (image_ID);
if (profile && gimp_color_profile_is_linear (profile)) if (profile && gimp_color_profile_is_linear (profile))
{ {
/* We always save as sRGB data, especially since WebP is /* Since WebP is apparently 8-bit max, we export it as sRGB to
* apparently 8-bit max (at least how we export it). If original * avoid shadow posterization.
* data was linear, let's convert the profile. * We do an exception for 8-bit linear work image, when the
* profile is also exported.
*/ */
if (gimp_image_get_precision (image_ID) != GIMP_PRECISION_U8_LINEAR)
{
/* If original data was linear, let's convert the profile. */
GimpColorProfile *saved_profile; GimpColorProfile *saved_profile;
saved_profile = gimp_color_profile_new_srgb_trc_from_color_profile (profile); saved_profile = gimp_color_profile_new_srgb_trc_from_color_profile (profile);
g_object_unref (profile); g_object_unref (profile);
profile = saved_profile; profile = saved_profile;
} }
else
{
/* Keep linear profile as-is. */
out_linear = TRUE;
}
}
/* The do...while() loop is a neat little trick that makes it easier /* The do...while() loop is a neat little trick that makes it easier
* to jump to error handling code while still ensuring proper * to jump to error handling code while still ensuring proper
@ -202,9 +213,19 @@ save_layer (const gchar *filename,
has_alpha = gimp_drawable_has_alpha (drawable_ID); has_alpha = gimp_drawable_has_alpha (drawable_ID);
if (has_alpha) if (has_alpha)
{
if (out_linear)
format = babl_format ("RGBA u8");
else
format = babl_format ("R'G'B'A u8"); format = babl_format ("R'G'B'A u8");
}
else
{
if (out_linear)
format = babl_format ("RGB u8");
else else
format = babl_format ("R'G'B' u8"); format = babl_format ("R'G'B' u8");
}
bpp = babl_format_get_bytes_per_pixel (format); bpp = babl_format_get_bytes_per_pixel (format);