Re: [AD] Problem loading 32bit bmp file |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
On Wednesday 17 August 2005 14:21, Michal Molhanec wrote:
> That's no surprise. The Allegro docs says:
>
> BITMAP *load_bmp(const char *filename, RGB *pal);
> Loads a 256-color or 24-bit truecolor Windows or OS/2 BMP file.
>
> So you cannot expect that it will load 32-bit bitmap.
Hmm... the docs are incorrect anyway, since Allegro can load 16 bit BMP
files too (at least, looking at the code suggests that it can, I haven't
tried it). But you're right in that it doesn't say it can read 32 bit BMP
files.
Anyway, the fix appears to be simple enough. Proposed patch attached.
Evert
Index: src/bmp.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/bmp.c,v
retrieving revision 1.17
diff -u -r1.17 bmp.c
--- src/bmp.c 19 Mar 2005 11:15:06 -0000 1.17
+++ src/bmp.c 17 Aug 2005 12:30:32 -0000
@@ -276,6 +276,27 @@
+/* read_32bit_line:
+ * Support function for reading the 32 bit bitmap file format, doing
+ * our best to convert it down to a 256 color palette.
+ */
+static void read_32bit_line(int length, PACKFILE *f, BITMAP *bmp, int line)
+{
+ int i;
+ RGB c;
+ char a;
+
+ for (i=0; i<length; i++) {
+ c.b = pack_getc(f);
+ c.g = pack_getc(f);
+ c.r = pack_getc(f);
+ a = pack_getc(f);
+ WRITE3BYTES(bmp->line[line]+i*4, makeacol32(c.r, c.g, c.b, a));
+ }
+}
+
+
+
/* read_bitfields_image:
* For reading the bitfield compressed BMP image format.
*/
@@ -353,6 +374,10 @@
case 24:
read_24bit_line(infoheader->biWidth, f, bmp, infoheader->biHeight-i-1);
break;
+
+ case 32:
+ read_32bit_line(infoheader->biWidth, f, bmp, infoheader->biHeight-i-1);
+ break;
}
}
}
@@ -592,6 +617,8 @@
bpp = 24;
else if (infoheader.biBitCount == 16)
bpp = 16;
+ else if (infoheader.biBitCount == 32)
+ bpp = 32;
else
bpp = 8;