Re: [AD] datafile.c bugfix |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
> This patch fixes problems whith fixup_datafile that converted 24bpp
> bitmaps to wrong colors.
This bug is in Allegro 3.12!
Thanks for spotting it. However, this code is little-endian only and, now
that PowerPC has joined SPARC as a regularly tested platform, we must be
careful about endianess problems.
[As a rule of thumb, all the 24-bit graphics code is highly suspect because
we need to manipulate 24-bit chunk byte per byte. Patches are welcome.]
[The function also has problems on x86-64 because it uses 'long' to hold
32-bit values and 'long' is 64-bit on x86-64. Patches are welcome too.]
Does the attached fix work for you?
--
Eric Botcazou
--- /home/eric/cvs/allegro/src/datafile.c Fri Feb 7 14:23:40 2003
+++ allegro/src/datafile.c Thu May 22 23:14:43 2003
@@ -1657,6 +1657,7 @@
RLE_SPRITE *rle;
int i, c, r, g, b, a, x, y;
int bpp, depth;
+ unsigned char *p8;
unsigned short *p16;
unsigned long *p32;
signed short *s16;
@@ -1748,13 +1749,14 @@
case 24:
/* fix up a 24 bit truecolor bitmap */
for (y=0; y<bmp->h; y++) {
+ p8 = bmp->line[y];
+
for (x=0; x<bmp->w; x++) {
- r = bmp->line[y][x*3];
- g = bmp->line[y][x*3+1];
- b = bmp->line[y][x*3+2];
- bmp->line[y][x*3+_rgb_r_shift_24/8] = r;
- bmp->line[y][x*3+_rgb_r_shift_24/8] = g;
- bmp->line[y][x*3+_rgb_r_shift_24/8] = b;
+ c = READ3BYTES(p8+x*3);
+ r = (c & 0xFF);
+ g = (c >> 8) & 0xFF;
+ b = (c >> 16) & 0xFF;
+ WRITE3BYTES(p8+x*3, makecol24(r, g, b));
}
}
break;