Fix bmp16bit with nocomp header (#2769)

This commit is contained in:
Totoo 2025-08-27 13:07:08 +02:00 committed by GitHub
parent 4dda7cfaa5
commit fe826d5d98
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -167,8 +167,18 @@ bool BMPFile::read_next_px(ui::Color& px, bool seek = true) {
if (res.is_error()) return false;
switch (type) {
case 5: {
uint16_t color16 = (uint16_t)buffer[0] | ((uint16_t)buffer[1] << 8);
px = ui::Color(color16); // has glitches!
// ARGB1555
uint16_t val = buffer[0] | (buffer[1] << 8);
// Extract components
//*a = (val >> 15) & 0x01; // 1-bit alpha
uint8_t r = (val >> 10) & 0x1F; // 5-bit red
uint8_t g = (val >> 5) & 0x1F; // 5-bit green
uint8_t b = (val)&0x1F; // 5-bit blue
// expand
r = (r << 3) | (r >> 2);
g = (g << 3) | (g >> 2);
b = (b << 3) | (b >> 2);
px = ui::Color(r, g, b);
break;
}
case 2: // 32