diff options
Diffstat (limited to 'core/io/image.cpp')
-rw-r--r-- | core/io/image.cpp | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/core/io/image.cpp b/core/io/image.cpp index 736a3ec82e..9bb987b670 100644 --- a/core/io/image.cpp +++ b/core/io/image.cpp @@ -468,7 +468,7 @@ int Image::get_mipmap_count() const { //using template generates perfectly optimized code due to constant expression reduction and unused variable removal present in all compilers template <uint32_t read_bytes, bool read_alpha, uint32_t write_bytes, bool write_alpha, bool read_gray, bool write_gray> static void _convert(int p_width, int p_height, const uint8_t *p_src, uint8_t *p_dst) { - uint32_t max_bytes = MAX(read_bytes, write_bytes); + constexpr uint32_t max_bytes = MAX(read_bytes, write_bytes); for (int y = 0; y < p_height; y++) { for (int x = 0; x < p_width; x++) { @@ -492,8 +492,9 @@ static void _convert(int p_width, int p_height, const uint8_t *p_src, uint8_t *p } if constexpr (write_gray) { - //TODO: not correct grayscale, should use fixed point version of actual weights - wofs[0] = uint8_t((uint16_t(rgba[0]) + uint16_t(rgba[1]) + uint16_t(rgba[2])) / 3); + // REC.709 + const uint8_t luminance = (13938U * rgba[0] + 46869U * rgba[1] + 4729U * rgba[2] + 32768U) >> 16U; + wofs[0] = luminance; } else { for (uint32_t i = 0; i < write_bytes; i++) { wofs[i] = rgba[i]; @@ -2649,7 +2650,7 @@ Error Image::compress_from_channels(CompressMode p_mode, UsedChannels p_channels _image_compress_bptc_func(this, p_channels); } break; case COMPRESS_ASTC: { - ERR_FAIL_COND_V(!_image_compress_bptc_func, ERR_UNAVAILABLE); + ERR_FAIL_COND_V(!_image_compress_astc_func, ERR_UNAVAILABLE); _image_compress_astc_func(this, p_astc_format); } break; case COMPRESS_MAX: { @@ -3535,6 +3536,8 @@ void Image::_bind_methods() { BIND_ENUM_CONSTANT(COMPRESS_ETC); BIND_ENUM_CONSTANT(COMPRESS_ETC2); BIND_ENUM_CONSTANT(COMPRESS_BPTC); + BIND_ENUM_CONSTANT(COMPRESS_ASTC); + BIND_ENUM_CONSTANT(COMPRESS_MAX); BIND_ENUM_CONSTANT(USED_CHANNELS_L); BIND_ENUM_CONSTANT(USED_CHANNELS_LA); @@ -3716,9 +3719,9 @@ void Image::premultiply_alpha() { for (int j = 0; j < width; j++) { uint8_t *ptr = &data_ptr[(i * width + j) * 4]; - ptr[0] = (uint16_t(ptr[0]) * uint16_t(ptr[3])) >> 8; - ptr[1] = (uint16_t(ptr[1]) * uint16_t(ptr[3])) >> 8; - ptr[2] = (uint16_t(ptr[2]) * uint16_t(ptr[3])) >> 8; + ptr[0] = (uint16_t(ptr[0]) * uint16_t(ptr[3]) + 255U) >> 8; + ptr[1] = (uint16_t(ptr[1]) * uint16_t(ptr[3]) + 255U) >> 8; + ptr[2] = (uint16_t(ptr[2]) * uint16_t(ptr[3]) + 255U) >> 8; } } } |