diff options
author | BlueCube3310 <53150244+BlueCube3310@users.noreply.github.com> | 2024-06-05 16:22:11 +0200 |
---|---|---|
committer | BlueCube3310 <53150244+BlueCube3310@users.noreply.github.com> | 2024-08-27 09:23:17 +0200 |
commit | 76c82116532223f8be75816786d7031c25af090e (patch) | |
tree | 0d3b2fb8cdb267bfc26d2adf19a916e621b27a1d /core/io/image.cpp | |
parent | db76de5de8a415b29be4c7dd84b99bd0fe260822 (diff) | |
download | redot-engine-76c82116532223f8be75816786d7031c25af090e.tar.gz |
Image: Add a method for detecting signed values
Diffstat (limited to 'core/io/image.cpp')
-rw-r--r-- | core/io/image.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/core/io/image.cpp b/core/io/image.cpp index 003646d095..f6065d984b 100644 --- a/core/io/image.cpp +++ b/core/io/image.cpp @@ -3824,6 +3824,33 @@ void Image::bump_map_to_normal_map(float bump_scale) { data = result_image; } +bool Image::detect_signed(bool p_include_mips) const { + ERR_FAIL_COND_V(is_compressed(), false); + + if (format >= Image::FORMAT_RH && format <= Image::FORMAT_RGBAH) { + const uint16_t *img_data = reinterpret_cast<const uint16_t *>(data.ptr()); + const uint64_t img_size = p_include_mips ? (data.size() / 2) : (width * height * get_format_pixel_size(format) / 2); + + for (uint64_t i = 0; i < img_size; i++) { + if ((img_data[i] & 0x8000) != 0 && (img_data[i] & 0x7fff) != 0) { + return true; + } + } + + } else if (format >= Image::FORMAT_RF && format <= Image::FORMAT_RGBAF) { + const uint32_t *img_data = reinterpret_cast<const uint32_t *>(data.ptr()); + const uint64_t img_size = p_include_mips ? (data.size() / 4) : (width * height * get_format_pixel_size(format) / 4); + + for (uint64_t i = 0; i < img_size; i++) { + if ((img_data[i] & 0x80000000) != 0 && (img_data[i] & 0x7fffffff) != 0) { + return true; + } + } + } + + return false; +} + void Image::srgb_to_linear() { if (data.size() == 0) { return; |