Skip to content

Commit a2aefab

Browse files
committed
Merge pull request #106486 from BlueCube3310/image-ch-detect-fix
Image: Fix detecting color channels
2 parents 0f21ccd + 0f99864 commit a2aefab

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

core/io/image.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3464,18 +3464,24 @@ Image::UsedChannels Image::detect_used_channels(CompressSource p_source) const {
34643464

34653465
UsedChannels used_channels;
34663466

3467-
if (!c && !a) {
3468-
used_channels = USED_CHANNELS_L;
3469-
} else if (!c && a) {
3470-
used_channels = USED_CHANNELS_LA;
3471-
} else if (r && !g && !b && !a) {
3472-
used_channels = USED_CHANNELS_R;
3473-
} else if (r && g && !b && !a) {
3474-
used_channels = USED_CHANNELS_RG;
3475-
} else if (r && g && b && !a) {
3476-
used_channels = USED_CHANNELS_RGB;
3467+
if (!c) {
3468+
// Uniform RGB (grayscale).
3469+
if (a) {
3470+
used_channels = USED_CHANNELS_LA;
3471+
} else {
3472+
used_channels = USED_CHANNELS_L;
3473+
}
34773474
} else {
3478-
used_channels = USED_CHANNELS_RGBA;
3475+
// Colored image.
3476+
if (a) {
3477+
used_channels = USED_CHANNELS_RGBA;
3478+
} else if (b) {
3479+
used_channels = USED_CHANNELS_RGB;
3480+
} else if (g) {
3481+
used_channels = USED_CHANNELS_RG;
3482+
} else {
3483+
used_channels = USED_CHANNELS_R;
3484+
}
34793485
}
34803486

34813487
if (p_source == COMPRESS_SOURCE_SRGB && (used_channels == USED_CHANNELS_R || used_channels == USED_CHANNELS_RG)) {

0 commit comments

Comments
 (0)