Skip to content

Commit

Permalink
Optimize image channel detection
Browse files Browse the repository at this point in the history
Speeds up compression
  • Loading branch information
reduz committed Mar 26, 2021
1 parent 2bd89ac commit 33b4c5d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion core/io/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3010,9 +3010,12 @@ 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;

const uint8_t *data_ptr = data.ptr();

for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
Color col = get_pixel(i, j);
uint32_t ofs = j * width + i;
Color col = _get_color_at_ofs(data_ptr, ofs);

if (col.r > 0.001) {
r = true;
Expand Down

0 comments on commit 33b4c5d

Please sign in to comment.