Util: Strip loading 16-bit PNGs down to 8-bit

This commit is contained in:
Vicki Pfau 2023-03-25 01:43:22 -07:00
parent 542792215e
commit cb0ad844c1

View File

@ -279,6 +279,14 @@ bool PNGReadPixels(png_structp png, png_infop info, void* pixels, unsigned width
return false;
}
if (png_get_bit_depth(png, info) == 16) {
#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
png_set_scale_16(png);
#else
png_set_strip_16(png);
#endif
}
uint8_t* pixelData = pixels;
unsigned pngHeight = png_get_image_height(png, info);
if (height < pngHeight) {
@ -334,6 +342,14 @@ bool PNGReadPixelsA(png_structp png, png_infop info, void* pixels, unsigned widt
return false;
}
if (png_get_bit_depth(png, info) == 16) {
#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
png_set_scale_16(png);
#else
png_set_strip_16(png);
#endif
}
uint8_t* pixelData = pixels;
unsigned pngHeight = png_get_image_height(png, info);
if (height < pngHeight) {
@ -389,6 +405,14 @@ bool PNGReadPixels8(png_structp png, png_infop info, void* pixels, unsigned widt
return false;
}
if (png_get_bit_depth(png, info) == 16) {
#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
png_set_scale_16(png);
#else
png_set_strip_16(png);
#endif
}
uint8_t* pixelData = pixels;
unsigned pngHeight = png_get_image_height(png, info);
if (height < pngHeight) {