[AD] Extra byte in 24 bit bitmaps

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Hello,

I need to read pixels in a 24 bit memory bitmap. It is then much faster to
read 32 bits at a time and shift out the components than to read one byte
three times (according to a test it's somewhat more than twice as fast on
my P133). However, this will read one byte outside the allocated memory on
the last pixel in the bitmap. Would it be possible to allocate one extra
byte at the end of 24 bit bitmaps for this purpose? I attach a patch that
does this. A better solution would of course be if someone could prove that
it is harmless to read an extra unallocated byte on all platforms...

Sven
--- graphics.c	Sun Jan 30 21:46:56 2000
+++ graphics.c	Fri Mar 10 16:07:46 2000
@@ -673,7 +673,8 @@
    if (!bitmap)
       return NULL;
 
-   bitmap->dat = malloc(width * height * BYTES_PER_PIXEL(color_depth));
+   bitmap->dat = malloc(width * height * BYTES_PER_PIXEL(color_depth) +
+			(color_depth == 24 ? 1 : 0));
    if (!bitmap->dat) {
       free(bitmap);
       return NULL;






Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/