mirror of
https://github.com/kevinbentley/Descent3.git
synced 2025-01-22 11:28:56 +00:00
Fix endian issues with iff importer.
It should now work on big-endian machines.
This commit is contained in:
parent
7695296ca0
commit
d817c1930e
@ -145,6 +145,24 @@ static int bm_iff_parse_delta(CFILE *ifile, int len, iff_bitmap_header *bmheader
|
|||||||
static int bm_iff_parse_file(CFILE *ifile, iff_bitmap_header *bmheader, iff_bitmap_header *prev_bm);
|
static int bm_iff_parse_file(CFILE *ifile, iff_bitmap_header *bmheader, iff_bitmap_header *prev_bm);
|
||||||
static void bm_iff_convert_8_to_16(int dest_bm, iff_bitmap_header *iffbm);
|
static void bm_iff_convert_8_to_16(int dest_bm, iff_bitmap_header *iffbm);
|
||||||
|
|
||||||
|
/// Read and return a raw integer (32 bits).
|
||||||
|
///
|
||||||
|
/// Throws an exception of type (cfile_error *) if the OS returns an error on read
|
||||||
|
static int32_t cf_ReadIntRaw(CFILE *cfp) {
|
||||||
|
int32_t i;
|
||||||
|
cf_ReadBytes((uint8_t *)&i, sizeof(i), cfp);
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Read and return a raw \c int16_t (16 bits)
|
||||||
|
///
|
||||||
|
/// Throws an exception of type (cfile_error *) if the OS returns an error on read
|
||||||
|
static int16_t cf_ReadShortRaw(CFILE *cfp) {
|
||||||
|
int16_t i;
|
||||||
|
cf_ReadBytes((uint8_t *)&i, sizeof(i), cfp);
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
int bm_iff_get_sig(CFILE *f) {
|
int bm_iff_get_sig(CFILE *f) {
|
||||||
char s[4];
|
char s[4];
|
||||||
int i;
|
int i;
|
||||||
@ -176,27 +194,22 @@ int bm_iff_get_sig(CFILE *f) {
|
|||||||
int bm_iff_parse_bmhd(CFILE *ifile, uint32_t len, iff_bitmap_header *bmheader) {
|
int bm_iff_parse_bmhd(CFILE *ifile, uint32_t len, iff_bitmap_header *bmheader) {
|
||||||
len = len;
|
len = len;
|
||||||
|
|
||||||
bmheader->w = cf_ReadShort(ifile);
|
bmheader->w = D3::convert_be(cf_ReadShortRaw(ifile));
|
||||||
bmheader->w = MOTOROLA_SHORT(bmheader->w);
|
bmheader->h = D3::convert_be(cf_ReadShortRaw(ifile));
|
||||||
bmheader->h = cf_ReadShort(ifile);
|
bmheader->x = D3::convert_be(cf_ReadShortRaw(ifile));
|
||||||
bmheader->h = MOTOROLA_SHORT(bmheader->h);
|
bmheader->y = D3::convert_be(cf_ReadShortRaw(ifile));
|
||||||
bmheader->x = cf_ReadShort(ifile);
|
|
||||||
bmheader->x = MOTOROLA_SHORT(bmheader->x);
|
|
||||||
bmheader->y = cf_ReadShort(ifile);
|
|
||||||
bmheader->y = MOTOROLA_SHORT(bmheader->y);
|
|
||||||
|
|
||||||
bmheader->nplanes = cf_ReadByte(ifile);
|
bmheader->nplanes = cf_ReadByte(ifile);
|
||||||
bmheader->masking = cf_ReadByte(ifile);
|
bmheader->masking = cf_ReadByte(ifile);
|
||||||
bmheader->compression = cf_ReadByte(ifile);
|
bmheader->compression = cf_ReadByte(ifile);
|
||||||
cf_ReadByte(ifile); /* skip pad */
|
cf_ReadByte(ifile); /* skip pad */
|
||||||
|
|
||||||
bmheader->transparentcolor = cf_ReadShort(ifile);
|
bmheader->transparentcolor = D3::convert_be(cf_ReadShortRaw(ifile));
|
||||||
bmheader->transparentcolor = MOTOROLA_SHORT(bmheader->transparentcolor);
|
|
||||||
bmheader->xaspect = cf_ReadByte(ifile);
|
bmheader->xaspect = cf_ReadByte(ifile);
|
||||||
bmheader->yaspect = cf_ReadByte(ifile);
|
bmheader->yaspect = cf_ReadByte(ifile);
|
||||||
|
|
||||||
bmheader->pagewidth = cf_ReadShort(ifile);
|
bmheader->pagewidth = D3::convert_be(cf_ReadShortRaw(ifile));
|
||||||
bmheader->pageheight = cf_ReadShort(ifile);
|
bmheader->pageheight = D3::convert_be(cf_ReadShortRaw(ifile));
|
||||||
|
|
||||||
iff_transparent_color = bmheader->transparentcolor;
|
iff_transparent_color = bmheader->transparentcolor;
|
||||||
|
|
||||||
@ -383,8 +396,7 @@ int bm_iff_parse_file(CFILE *ifile, iff_bitmap_header *bmheader, iff_bitmap_head
|
|||||||
|
|
||||||
sig = bm_iff_get_sig(ifile);
|
sig = bm_iff_get_sig(ifile);
|
||||||
|
|
||||||
len = cf_ReadInt(ifile);
|
len = D3::convert_be(cf_ReadIntRaw(ifile));
|
||||||
len = MOTOROLA_INT(len);
|
|
||||||
|
|
||||||
switch (sig) {
|
switch (sig) {
|
||||||
case IFF_SIG_FORM: {
|
case IFF_SIG_FORM: {
|
||||||
@ -568,7 +580,7 @@ int bm_iff_read_animbrush(const char *ifilename, int *bm_list) {
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
sig = bm_iff_get_sig(ifile);
|
sig = bm_iff_get_sig(ifile);
|
||||||
form_len = cf_ReadInt(ifile);
|
form_len = D3::convert_be(cf_ReadIntRaw(ifile));
|
||||||
|
|
||||||
if (sig != IFF_SIG_FORM) {
|
if (sig != IFF_SIG_FORM) {
|
||||||
mprintf(0, "Not a valid IFF file.\n");
|
mprintf(0, "Not a valid IFF file.\n");
|
||||||
|
Loading…
Reference in New Issue
Block a user