Quick shortcut for all-black blocks since they are very common

This commit is contained in:
Andrew Cassidy 2021-02-27 17:03:19 -08:00
parent 9435003553
commit 193ac22eb5

View File

@ -277,8 +277,12 @@ void BC1Encoder::EncodeBlockSingleColor(Color color, BC1Block *dest) const {
uint8_t mask = 0xAA; // 2222 uint8_t mask = 0xAA; // 2222
uint16_t min16, max16; uint16_t min16, max16;
bool using_3color = false; if ((color.r | color.g | color.g) == 0) {
// quick shortcut for all-black blocks
min16 = 0;
max16 = 1;
mask = 0x55; // 1111 (Min value only, max is ignored)
} else {
// why is there no subscript operator for shared_ptr<array> // why is there no subscript operator for shared_ptr<array>
EncodeResults result; EncodeResults result;
FindEndpointsSingleColor(result, color, false); FindEndpointsSingleColor(result, color, false);
@ -312,7 +316,8 @@ void BC1Encoder::EncodeBlockSingleColor(Color color, BC1Block *dest) const {
} }
assert(max16 > min16); assert(max16 > min16);
} else if (max16 > min16) { } else if (max16 > min16) {
std::swap(min16, max16); std::swap(min16, max16); // assure 3-color blocks
}
} }
dest->SetLowColor(max16); dest->SetLowColor(max16);