mirror of
https://github.com/webmproject/libwebp.git
synced 2024-11-19 20:08:28 +01:00
PNG decoder: handle gAMA chunk
Apply gamma correction to the decoded RGB values. This handles corner cases where the PNG file doesn't have a standard 1/2.2 gamma value. BUG=webp:369 Change-Id: I9907b6e2c458002de7c26d0b9e416278cca33990
This commit is contained in:
parent
664c21dd01
commit
78318b30e5
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user