diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2021-03-26 22:12:53 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-26 22:12:53 +0100 |
commit | 5cdd4ee8bced19a5f7e74c6d3d693bbb39e27bd7 (patch) | |
tree | 0cdc556bb90af1e1d70af0bae718850564fbb4eb | |
parent | 2bd89ac24960c105e1f570d991def4dc3667d1fa (diff) | |
parent | 4763835c11c6772e4da84fa8bfec6c02ca06bc0b (diff) |
Merge pull request #47396 from reduz/optimize-channel-detection
Optimize image channel detection
-rw-r--r-- | core/io/image.cpp | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/core/io/image.cpp b/core/io/image.cpp index 5d46d75efe..873eb66f33 100644 --- a/core/io/image.cpp +++ b/core/io/image.cpp @@ -3010,26 +3010,28 @@ Image::UsedChannels Image::detect_used_channels(CompressSource p_source) { ERR_FAIL_COND_V(is_compressed(), USED_CHANNELS_RGBA); bool r = false, g = false, b = false, a = false, c = false; - for (int i = 0; i < width; i++) { - for (int j = 0; j < height; j++) { - Color col = get_pixel(i, j); + const uint8_t *data_ptr = data.ptr(); - if (col.r > 0.001) { - r = true; - } - if (col.g > 0.001) { - g = true; - } - if (col.b > 0.001) { - b = true; - } - if (col.a < 0.999) { - a = true; - } + uint32_t data_total = width * height; - if (col.r != col.b || col.r != col.g || col.b != col.g) { - c = true; - } + for (uint32_t i = 0; i < data_total; i++) { + Color col = _get_color_at_ofs(data_ptr, i); + + if (col.r > 0.001) { + r = true; + } + if (col.g > 0.001) { + g = true; + } + if (col.b > 0.001) { + b = true; + } + if (col.a < 0.999) { + a = true; + } + + if (col.r != col.b || col.r != col.g || col.b != col.g) { + c = true; } } |