diff --git a/imageio/pngdec.c b/imageio/pngdec.c index 22e60f3c..46223533 100644 --- a/imageio/pngdec.c +++ b/imageio/pngdec.c @@ -185,7 +185,6 @@ static int ExtractMetadataFromPNG(png_structp png, } } } - return 1; } @@ -265,6 +264,16 @@ int ReadPNG(const uint8_t* const data, size_t data_size, has_alpha = !!(color_type & PNG_COLOR_MASK_ALPHA); } + // Apply gamma correction if needed. + { + double image_gamma = 1 / 2.2, screen_gamma = 2.2; + int srgb_intent; + if (png_get_sRGB(png, info, &srgb_intent) || + png_get_gAMA(png, info, &image_gamma)) { + png_set_gamma(png, screen_gamma, image_gamma); + } + } + if (!keep_alpha) { png_set_strip_alpha(png); has_alpha = 0;