Skip to content

Commit a6ed54e

Browse files
committed
Image display: Render PNG images with correct colors that have a gamma value different from the sRGB gamma value set in their metadata
1 parent 95132b4 commit a6ed54e

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

kitty/png-reader.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ inflate_png_inner(png_read_data *d, const uint8_t *buf, size_t bufsz) {
6161
d->height = png_get_image_height(png, info);
6262
color_type = png_get_color_type(png, info);
6363
bit_depth = png_get_bit_depth(png, info);
64+
double image_gamma;
65+
int intent;
66+
if (png_get_sRGB(png, info, &intent)) {
67+
// do nothing since we output sRGB
68+
} else if (png_get_gAMA(png, info, &image_gamma)) {
69+
if (image_gamma != 0 && fabs(image_gamma - 1.0/2.2) > 0.0001) png_set_gamma(png, 2.2, image_gamma);
70+
} else {
71+
// do nothing since we don't know what gamma the source image is in
72+
// TODO: handle images with color profiles
73+
}
6474

6575
// Ensure we get RGBA data out of libpng
6676
if (bit_depth == 16) png_set_strip_16(png);

0 commit comments

Comments
 (0)