Merge pull request #47396 from reduz/optimize-channel-detection

Optimize image channel detection
This commit is contained in:
Rémi Verschelde 2021-03-26 22:12:53 +01:00 committed by GitHub
commit 5cdd4ee8bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 18 deletions

View File

@ -3010,26 +3010,28 @@ Image::UsedChannels Image::detect_used_channels(CompressSource p_source) {
ERR_FAIL_COND_V(is_compressed(), USED_CHANNELS_RGBA); ERR_FAIL_COND_V(is_compressed(), USED_CHANNELS_RGBA);
bool r = false, g = false, b = false, a = false, c = false; bool r = false, g = false, b = false, a = false, c = false;
for (int i = 0; i < width; i++) { const uint8_t *data_ptr = data.ptr();
for (int j = 0; j < height; j++) {
Color col = get_pixel(i, j);
if (col.r > 0.001) { uint32_t data_total = width * height;
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) { for (uint32_t i = 0; i < data_total; i++) {
c = true; 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;
} }
} }