plug-ins: follow the assigned profile TRC in PNG export.
Similar to JPEG export (commit c5f7bac2ba
)
as discussed with Ell. GIMP should follow and save as-is any *assigned*
profile. We only make a decision about whether to convert from storage
precision to another format when the profile is the default GIMP one.
This commit is contained in:
@ -1463,7 +1463,7 @@ save_image (const gchar *filename,
|
|||||||
gint num; /* Number of rows to load */
|
gint num; /* Number of rows to load */
|
||||||
FILE *fp; /* File pointer */
|
FILE *fp; /* File pointer */
|
||||||
GimpColorProfile *profile = NULL; /* Color profile */
|
GimpColorProfile *profile = NULL; /* Color profile */
|
||||||
gboolean linear; /* Save linear RGB */
|
gboolean out_linear; /* Save linear RGB */
|
||||||
GeglBuffer *buffer; /* GEGL buffer for layer */
|
GeglBuffer *buffer; /* GEGL buffer for layer */
|
||||||
const Babl *file_format; /* BABL format of file */
|
const Babl *file_format; /* BABL format of file */
|
||||||
png_structp pp; /* PNG read pointer */
|
png_structp pp; /* PNG read pointer */
|
||||||
@ -1478,47 +1478,57 @@ save_image (const gchar *filename,
|
|||||||
time_t cutime; /* Time since epoch */
|
time_t cutime; /* Time since epoch */
|
||||||
struct tm *gmt; /* GMT broken down */
|
struct tm *gmt; /* GMT broken down */
|
||||||
gint color_type; /* PNG color type */
|
gint color_type; /* PNG color type */
|
||||||
gint bit_depth = 16; /* Default to bit bepth 16 */
|
gint bit_depth; /* Default to bit depth 16 */
|
||||||
|
|
||||||
guchar remap[256]; /* Re-mapping for the palette */
|
guchar remap[256]; /* Re-mapping for the palette */
|
||||||
|
|
||||||
png_textp text = NULL;
|
png_textp text = NULL;
|
||||||
|
|
||||||
|
out_linear = FALSE;
|
||||||
#if defined(PNG_iCCP_SUPPORTED)
|
#if defined(PNG_iCCP_SUPPORTED)
|
||||||
|
profile = gimp_image_get_color_profile (orig_image_ID);
|
||||||
if (pngvals.save_profile)
|
if (pngvals.save_profile)
|
||||||
|
{
|
||||||
|
if (profile && gimp_color_profile_is_linear (profile) &&
|
||||||
|
pngvals.export_format == PNG_FORMAT_AUTO)
|
||||||
|
out_linear = TRUE;
|
||||||
|
|
||||||
|
if (! profile)
|
||||||
profile = gimp_image_get_effective_color_profile (orig_image_ID);
|
profile = gimp_image_get_effective_color_profile (orig_image_ID);
|
||||||
|
|
||||||
|
if (! out_linear && gimp_color_profile_is_linear (profile))
|
||||||
|
{
|
||||||
|
/* This should happen only when using default linear profile
|
||||||
|
* (no profile explicitly set) or when not exporting to
|
||||||
|
* PNG_FORMAT_AUTO.
|
||||||
|
*/
|
||||||
|
GimpColorProfile *saved_profile;
|
||||||
|
|
||||||
|
saved_profile = gimp_color_profile_new_srgb_trc_from_color_profile (profile);
|
||||||
|
g_object_unref (profile);
|
||||||
|
profile = saved_profile;
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* We save as 8-bit PNG only if:
|
||||||
|
* (1) Work image is 8-bit linear with linear profile to be saved.
|
||||||
|
* (2) Work image is 8-bit non-linear or perceptual with or without
|
||||||
|
* profile.
|
||||||
|
*/
|
||||||
|
bit_depth = 16;
|
||||||
switch (gimp_image_get_precision (image_ID))
|
switch (gimp_image_get_precision (image_ID))
|
||||||
{
|
{
|
||||||
case GIMP_PRECISION_U8_LINEAR:
|
case GIMP_PRECISION_U8_LINEAR:
|
||||||
/* only keep 8 bit linear RGB if we also save a profile */
|
if (out_linear)
|
||||||
if (profile)
|
|
||||||
bit_depth = 8;
|
bit_depth = 8;
|
||||||
|
|
||||||
case GIMP_PRECISION_U16_LINEAR:
|
|
||||||
case GIMP_PRECISION_U32_LINEAR:
|
|
||||||
case GIMP_PRECISION_HALF_LINEAR:
|
|
||||||
case GIMP_PRECISION_FLOAT_LINEAR:
|
|
||||||
case GIMP_PRECISION_DOUBLE_LINEAR:
|
|
||||||
/* save linear RGB only if we save a profile, or a loader won't
|
|
||||||
* do the right thing
|
|
||||||
*/
|
|
||||||
if (profile)
|
|
||||||
linear = TRUE;
|
|
||||||
else
|
|
||||||
linear = FALSE;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GIMP_PRECISION_U8_GAMMA:
|
case GIMP_PRECISION_U8_GAMMA:
|
||||||
bit_depth = 8;
|
bit_depth = 8;
|
||||||
|
break;
|
||||||
|
|
||||||
case GIMP_PRECISION_U16_GAMMA:
|
default:
|
||||||
case GIMP_PRECISION_U32_GAMMA:
|
|
||||||
case GIMP_PRECISION_HALF_GAMMA:
|
|
||||||
case GIMP_PRECISION_FLOAT_GAMMA:
|
|
||||||
case GIMP_PRECISION_DOUBLE_GAMMA:
|
|
||||||
linear = FALSE;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1604,14 +1614,14 @@ save_image (const gchar *filename,
|
|||||||
color_type = PNG_COLOR_TYPE_RGB;
|
color_type = PNG_COLOR_TYPE_RGB;
|
||||||
if (bit_depth == 8)
|
if (bit_depth == 8)
|
||||||
{
|
{
|
||||||
if (linear)
|
if (out_linear)
|
||||||
file_format = babl_format ("RGB u8");
|
file_format = babl_format ("RGB u8");
|
||||||
else
|
else
|
||||||
file_format = babl_format ("R'G'B' u8");
|
file_format = babl_format ("R'G'B' u8");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (linear)
|
if (out_linear)
|
||||||
file_format = babl_format ("RGB u16");
|
file_format = babl_format ("RGB u16");
|
||||||
else
|
else
|
||||||
file_format = babl_format ("R'G'B' u16");
|
file_format = babl_format ("R'G'B' u16");
|
||||||
@ -1622,14 +1632,14 @@ save_image (const gchar *filename,
|
|||||||
color_type = PNG_COLOR_TYPE_RGB_ALPHA;
|
color_type = PNG_COLOR_TYPE_RGB_ALPHA;
|
||||||
if (bit_depth == 8)
|
if (bit_depth == 8)
|
||||||
{
|
{
|
||||||
if (linear)
|
if (out_linear)
|
||||||
file_format = babl_format ("RGBA u8");
|
file_format = babl_format ("RGBA u8");
|
||||||
else
|
else
|
||||||
file_format = babl_format ("R'G'B'A u8");
|
file_format = babl_format ("R'G'B'A u8");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (linear)
|
if (out_linear)
|
||||||
file_format = babl_format ("RGBA u16");
|
file_format = babl_format ("RGBA u16");
|
||||||
else
|
else
|
||||||
file_format = babl_format ("R'G'B'A u16");
|
file_format = babl_format ("R'G'B'A u16");
|
||||||
@ -1640,14 +1650,14 @@ save_image (const gchar *filename,
|
|||||||
color_type = PNG_COLOR_TYPE_GRAY;
|
color_type = PNG_COLOR_TYPE_GRAY;
|
||||||
if (bit_depth == 8)
|
if (bit_depth == 8)
|
||||||
{
|
{
|
||||||
if (linear)
|
if (out_linear)
|
||||||
file_format = babl_format ("Y u8");
|
file_format = babl_format ("Y u8");
|
||||||
else
|
else
|
||||||
file_format = babl_format ("Y' u8");
|
file_format = babl_format ("Y' u8");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (linear)
|
if (out_linear)
|
||||||
file_format = babl_format ("Y u16");
|
file_format = babl_format ("Y u16");
|
||||||
else
|
else
|
||||||
file_format = babl_format ("Y' u16");
|
file_format = babl_format ("Y' u16");
|
||||||
@ -1658,14 +1668,14 @@ save_image (const gchar *filename,
|
|||||||
color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
|
color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
|
||||||
if (bit_depth == 8)
|
if (bit_depth == 8)
|
||||||
{
|
{
|
||||||
if (linear)
|
if (out_linear)
|
||||||
file_format = babl_format ("YA u8");
|
file_format = babl_format ("YA u8");
|
||||||
else
|
else
|
||||||
file_format = babl_format ("Y'A u8");
|
file_format = babl_format ("Y'A u8");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (linear)
|
if (out_linear)
|
||||||
file_format = babl_format ("YA u16");
|
file_format = babl_format ("YA u16");
|
||||||
else
|
else
|
||||||
file_format = babl_format ("Y'A u16");
|
file_format = babl_format ("Y'A u16");
|
||||||
@ -1739,14 +1749,6 @@ save_image (const gchar *filename,
|
|||||||
bit_depth = 16;
|
bit_depth = 16;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (linear && profile)
|
|
||||||
{
|
|
||||||
GimpColorProfile *saved_profile;
|
|
||||||
|
|
||||||
saved_profile = gimp_color_profile_new_srgb_trc_from_color_profile (profile);
|
|
||||||
g_object_unref (profile);
|
|
||||||
profile = saved_profile;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bpp = babl_format_get_bytes_per_pixel (file_format);
|
bpp = babl_format_get_bytes_per_pixel (file_format);
|
||||||
@ -1831,7 +1833,7 @@ save_image (const gchar *filename,
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if defined(PNG_iCCP_SUPPORTED)
|
#if defined(PNG_iCCP_SUPPORTED)
|
||||||
if (profile)
|
if (pngvals.save_profile)
|
||||||
{
|
{
|
||||||
GimpParasite *parasite;
|
GimpParasite *parasite;
|
||||||
gchar *profile_name = NULL;
|
gchar *profile_name = NULL;
|
||||||
@ -1855,9 +1857,9 @@ save_image (const gchar *filename,
|
|||||||
icc_length);
|
icc_length);
|
||||||
|
|
||||||
g_free (profile_name);
|
g_free (profile_name);
|
||||||
|
|
||||||
g_object_unref (profile);
|
|
||||||
}
|
}
|
||||||
|
if (profile)
|
||||||
|
g_object_unref (profile);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef PNG_zTXt_SUPPORTED
|
#ifdef PNG_zTXt_SUPPORTED
|
||||||
|
Reference in New Issue
Block a user