Skip to content

Commit 785d8af

Browse files
ferdymercurylinev
authored andcommitted
[afterimage] correctly normalize 5-bit bmp color to 32-bit buffer
This is needed for correct color normalization, since buf-> expects a range between 0 and 255 but data contains 5-bit colors from 0 to 31.
1 parent e952913 commit 785d8af

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

  • graf2d/asimage/src/libAfterImage

graf2d/asimage/src/libAfterImage/bmp.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,12 @@ dib_data_to_scanline( ASScanline *buf,
8383
{
8484
CARD8 c1 = data[2 * x];
8585
CARD8 c2 = data[2 * x + 1];
86-
buf->blue[x] = c1&0x1F;
87-
buf->green[x] = ((c1>>5)&0x07)|((c2<<3)&0x18);
88-
buf->red[x] = ((c2>>2)&0x1F);
86+
// Assumed RGB555, ie R.G.B.A.X 5.5.5.0.1
87+
const CARD32 bufmax = 0xFF;
88+
const CARD32 chmax = 0x1F;
89+
buf->blue[x] = ((c1 & 0x1F) * bufmax) / chmax;
90+
buf->green[x] = ((((c1 >> 5) & 0x07) | ((c2 << 3) & 0x18)) * bufmax) / chmax;
91+
buf->red[x] = ((((c2 >> 2) & 0x1F)) * bufmax) / chmax;
8992
}
9093
break ;
9194
default:

0 commit comments

Comments
 (0)