Re: [AD] Endianness in file routines |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
> This reminds me, has anyone checked this? It looks to me like the code
> assumes little endianness.
/* pack_igetw:
* Reads a 16 bit word from a file, using intel byte ordering.
*/
int pack_igetw(PACKFILE *f)
{
int b1, b2;
ASSERT(f);
if ((b1 = pack_getc(f)) != EOF)
if ((b2 = pack_getc(f)) != EOF)
return ((b2 << 8) | b1);
return EOF;
}
/* pack_iputw:
* Writes a 16 bit int to a file, using intel byte ordering.
*/
int pack_iputw(int w, PACKFILE *f)
{
int b1, b2;
ASSERT(f);
b1 = (w & 0xFF00) >> 8;
b2 = w & 0x00FF;
if (pack_putc(b2,f)==b2)
if (pack_putc(b1,f)==b1)
return w;
return EOF;
}
Both functions looks ok to me.
On the other hand, I've attached a patch that fixes an assumption of
little-endianess in src/bmp.c:read_24bit_line(). Does it seem correct to
you?
--
Eric Botcazou
--- /cvs/allegro/src/bmp.c Wed Oct 16 14:02:38 2002
+++ allegro/src/bmp.c Mon Oct 28 11:23:44 2002
@@ -262,9 +262,7 @@
c.b = pack_getc(f);
c.g = pack_getc(f);
c.r = pack_getc(f);
- bmp->line[line][i*3+_rgb_r_shift_24/8] = c.r;
- bmp->line[line][i*3+_rgb_g_shift_24/8] = c.g;
- bmp->line[line][i*3+_rgb_b_shift_24/8] = c.b;
+ bmp_write24((unsigned long)bmp->line[line]+i*3, makecol24(c.r, c.g, c.b));
nbytes += 3;
}