mirror of https://github.com/GNOME/gimp.git
plug-ins: follow the assigned profile TRC in PNG export.
Similar to JPEG export (commitc5f7bac2ba
) 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. Picked from commit72c5d24fe9
. Some changes may have to happen later on the master code as the space invasion changes a bit how default profiles are handled.
This commit is contained in:
parent
31b90638cb
commit
cf37d1ae56
|
@ -1471,7 +1471,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 */
|
||||||
|
@ -1486,44 +1486,58 @@ 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)
|
||||||
profile = gimp_image_get_effective_color_profile (orig_image_ID);
|
{
|
||||||
|
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);
|
||||||
|
|
||||||
|
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_NON_LINEAR:
|
case GIMP_PRECISION_U8_NON_LINEAR:
|
||||||
case GIMP_PRECISION_U8_PERCEPTUAL:
|
case GIMP_PRECISION_U8_PERCEPTUAL:
|
||||||
bit_depth = 8;
|
bit_depth = 8;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
linear = FALSE;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1609,14 +1623,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");
|
||||||
|
@ -1627,14 +1641,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");
|
||||||
|
@ -1645,14 +1659,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");
|
||||||
|
@ -1663,14 +1677,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");
|
||||||
|
@ -1744,14 +1758,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);
|
||||||
|
@ -1836,7 +1842,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;
|
||||||
|
@ -1861,10 +1867,10 @@ save_image (const gchar *filename,
|
||||||
|
|
||||||
g_free (profile_name);
|
g_free (profile_name);
|
||||||
|
|
||||||
g_object_unref (profile);
|
|
||||||
|
|
||||||
*profile_saved = TRUE;
|
*profile_saved = TRUE;
|
||||||
}
|
}
|
||||||
|
if (profile)
|
||||||
|
g_object_unref (profile);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef PNG_zTXt_SUPPORTED
|
#ifdef PNG_zTXt_SUPPORTED
|
||||||
|
|
Loading…
Reference in New Issue