|
@@ -58,8 +58,7 @@ static bool check_error(const png_image &image) {
|
|
return false;
|
|
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;
|
|
png_image png_img;
|
|
zeromem(&png_img, sizeof(png_img));
|
|
zeromem(&png_img, sizeof(png_img));
|
|
png_img.version = PNG_IMAGE_VERSION;
|
|
png_img.version = PNG_IMAGE_VERSION;
|
|
@@ -100,6 +99,11 @@ Error png_to_image(const uint8_t *p_source, size_t p_size, Ref<Image> p_image) {
|
|
return ERR_UNAVAILABLE;
|
|
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);
|
|
const png_uint_32 stride = PNG_IMAGE_ROW_STRIDE(png_img);
|
|
PoolVector<uint8_t> buffer;
|
|
PoolVector<uint8_t> buffer;
|
|
Error err = buffer.resize(PNG_IMAGE_BUFFER_SIZE(png_img, stride));
|
|
Error err = buffer.resize(PNG_IMAGE_BUFFER_SIZE(png_img, stride));
|