Handle 16 bit PNG files in sRGB format
This commit is contained in:
@ -58,7 +58,7 @@ static bool check_error(const png_image &image) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Error png_to_image(const uint8_t *p_source, size_t p_size, Ref<Image> p_image) {
|
||||
Error png_to_image(const uint8_t *p_source, size_t p_size, bool p_force_linear, Ref<Image> p_image) {
|
||||
png_image png_img;
|
||||
zeromem(&png_img, sizeof(png_img));
|
||||
png_img.version = PNG_IMAGE_VERSION;
|
||||
@ -99,6 +99,11 @@ Error png_to_image(const uint8_t *p_source, size_t p_size, Ref<Image> p_image) {
|
||||
return ERR_UNAVAILABLE;
|
||||
}
|
||||
|
||||
if (!p_force_linear) {
|
||||
// assume 16 bit pngs without sRGB or gAMA chunks are in sRGB format
|
||||
png_img.flags |= PNG_IMAGE_FLAG_16BIT_sRGB;
|
||||
}
|
||||
|
||||
const png_uint_32 stride = PNG_IMAGE_ROW_STRIDE(png_img);
|
||||
Vector<uint8_t> buffer;
|
||||
Error err = buffer.resize(PNG_IMAGE_BUFFER_SIZE(png_img, stride));
|
||||
|
||||
Reference in New Issue
Block a user