Fix big endian bug in bmp loader (jogness, ticket 195).

SVN revision: 38767
This commit is contained in:
Kim Woelders 2009-01-24 23:51:05 +00:00
parent d4577b5d4e
commit a7b230a6f8
1 changed files with 0 additions and 32 deletions

View File

@ -38,11 +38,7 @@ ReadleShort(FILE * file, unsigned short *ret)
if (fread(b, sizeof(unsigned char), 2, file) != 2)
return 0;
#ifdef WORDS_BIGENDIAN
*ret = (b[0] << 8) | b[1];
#else
*ret = (b[1] << 8) | b[0];
#endif
return 1;
}
@ -54,11 +50,7 @@ ReadleLong(FILE * file, unsigned long *ret)
if (fread(b, sizeof(unsigned char), 4, file) != 4)
return 0;
#ifdef WORDS_BIGENDIAN
*ret = (b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3];
#else
*ret = (b[3] << 24) | (b[2] << 16) | (b[1] << 8) | b[0];
#endif
return 1;
}
@ -79,21 +71,12 @@ WriteleShort(FILE * file, unsigned short val)
{
int rc;
#ifdef WORDS_BIGENDIAN
rc = fputc ((int) ((val >> 8) & 0xff), file);
if (rc == EOF)
return 0;
rc = fputc ((int) (val & 0xff), file);
if (rc == EOF)
return 0;
#else
rc = fputc ((int) (val & 0xff), file);
if (rc == EOF)
return 0;
rc = fputc ((int) ((val >> 8) & 0xff), file);
if (rc == EOF)
return 0;
#endif
return 1;
}
@ -103,20 +86,6 @@ WriteleLong(FILE * file, unsigned long val)
{
int rc;
#ifdef WORDS_BIGENDIAN
rc = fputc ((int) ((val >> 24) & 0xff), file);
if (rc == EOF)
return 0;
rc = fputc ((int) ((val >> 16) & 0xff), file);
if (rc == EOF)
return 0;
rc = fputc ((int) ((val >> 8) & 0xff), file);
if (rc == EOF)
return 0;
rc = fputc ((int) (val & 0xff), file);
if (rc == EOF)
return 0;
#else
rc = fputc ((int) (val & 0xff), file);
if (rc == EOF)
return 0;
@ -129,7 +98,6 @@ WriteleLong(FILE * file, unsigned long val)
rc = fputc ((int) ((val >> 24) & 0xff), file);
if (rc == EOF)
return 0;
#endif
return 1;
}