Navigation Menu

Skip to content

Commit

Permalink
Merged with tip
Browse files Browse the repository at this point in the history
  • Loading branch information
ferzkopp committed Feb 12, 2013
2 parents 04f64d2 + c2f3f48 commit f67b63b
Show file tree
Hide file tree
Showing 20 changed files with 1,615 additions and 153 deletions.
2 changes: 1 addition & 1 deletion IMG.c
Expand Up @@ -123,7 +123,7 @@ void IMG_Quit()
SDL_Surface *IMG_Load(const char *file)
{
SDL_RWops *src = SDL_RWFromFile(file, "rb");
char *ext = strrchr(file, '.');
const char *ext = strrchr(file, '.');
if(ext) {
ext++;
}
Expand Down
14 changes: 7 additions & 7 deletions IMG_bmp.c
Expand Up @@ -35,7 +35,7 @@
/* See if an image is contained in a data source */
int IMG_isBMP(SDL_RWops *src)
{
int start;
Sint64 start;
int is_BMP;
char magic[2];

Expand All @@ -44,7 +44,7 @@ int IMG_isBMP(SDL_RWops *src)
start = SDL_RWtell(src);
is_BMP = 0;
if ( SDL_RWread(src, magic, sizeof(magic), 1) ) {
if ( strncmp(magic, "BM", 2) == 0 ) {
if ( SDL_strncmp(magic, "BM", 2) == 0 ) {
is_BMP = 1;
}
}
Expand All @@ -54,7 +54,7 @@ int IMG_isBMP(SDL_RWops *src)

static int IMG_isICOCUR(SDL_RWops *src, int type)
{
int start;
Sint64 start;
int is_ICOCUR;

/* The Win32 ICO file header (14 bytes) */
Expand Down Expand Up @@ -187,7 +187,7 @@ static int readRlePixels(SDL_Surface * surface, SDL_RWops * src, int isRle8)
static SDL_Surface *LoadBMP_RW (SDL_RWops *src, int freesrc)
{
SDL_bool was_error;
long fp_offset;
Sint64 fp_offset;
int bmpPitch;
int i, pad;
SDL_Surface *surface;
Expand Down Expand Up @@ -237,7 +237,7 @@ static SDL_Surface *LoadBMP_RW (SDL_RWops *src, int freesrc)
was_error = SDL_TRUE;
goto done;
}
if ( strncmp(magic, "BM", 2) != 0 ) {
if ( SDL_strncmp(magic, "BM", 2) != 0 ) {
IMG_SetError("File is not a Windows BMP file");
was_error = SDL_TRUE;
goto done;
Expand Down Expand Up @@ -404,7 +404,7 @@ static SDL_Surface *LoadBMP_RW (SDL_RWops *src, int freesrc)
goto done;
}
if ((biCompression == BI_RLE4) || (biCompression == BI_RLE8)) {
was_error = readRlePixels(surface, src, biCompression == BI_RLE8);
was_error = (SDL_bool)readRlePixels(surface, src, biCompression == BI_RLE8);
if (was_error) IMG_SetError("Error reading from BMP");
goto done;
}
Expand Down Expand Up @@ -520,7 +520,7 @@ static SDL_Surface *
LoadICOCUR_RW(SDL_RWops * src, int type, int freesrc)
{
SDL_bool was_error;
long fp_offset;
Sint64 fp_offset;
int bmpPitch;
int i, pad;
SDL_Surface *surface;
Expand Down
31 changes: 21 additions & 10 deletions IMG_gif.c
Expand Up @@ -33,7 +33,7 @@
/* See if an image is contained in a data source */
int IMG_isGIF(SDL_RWops *src)
{
int start;
Sint64 start;
int is_GIF;
char magic[6];

Expand All @@ -42,9 +42,9 @@ int IMG_isGIF(SDL_RWops *src)
start = SDL_RWtell(src);
is_GIF = 0;
if ( SDL_RWread(src, magic, sizeof(magic), 1) ) {
if ( (strncmp(magic, "GIF", 3) == 0) &&
((memcmp(magic + 3, "87a", 3) == 0) ||
(memcmp(magic + 3, "89a", 3) == 0)) ) {
if ( (SDL_strncmp(magic, "GIF", 3) == 0) &&
((SDL_memcmp(magic + 3, "87a", 3) == 0) ||
(SDL_memcmp(magic + 3, "89a", 3) == 0)) ) {
is_GIF = 1;
}
}
Expand Down Expand Up @@ -152,7 +152,7 @@ static Image *ReadImage(SDL_RWops * src, int len, int height, int,
Image *
IMG_LoadGIF_RW(SDL_RWops *src)
{
int start;
Sint64 start;
unsigned char buf[16];
unsigned char c;
unsigned char localColorMap[3][MAXCOLORMAPSIZE];
Expand All @@ -173,14 +173,14 @@ IMG_LoadGIF_RW(SDL_RWops *src)
RWSetMsg("error reading magic number");
goto done;
}
if (strncmp((char *) buf, "GIF", 3) != 0) {
if (SDL_strncmp((char *) buf, "GIF", 3) != 0) {
RWSetMsg("not a GIF file");
goto done;
}
memcpy(version, (char *) buf + 3, 3);
SDL_memcpy(version, (char *) buf + 3, 3);
version[3] = '\0';

if ((strcmp(version, "87a") != 0) && (strcmp(version, "89a") != 0)) {
if ((SDL_strcmp(version, "87a") != 0) && (SDL_strcmp(version, "89a") != 0)) {
RWSetMsg("bad version number, not '87a' or '89a'");
goto done;
}
Expand Down Expand Up @@ -337,7 +337,7 @@ DoExtension(SDL_RWops *src, int label)
return FALSE;
default:
str = (char *)buf;
sprintf(str, "UNKNOWN (0x%02x)", label);
SDL_snprintf(str, 256, "UNKNOWN (0x%02x)", label);
break;
}

Expand Down Expand Up @@ -439,8 +439,9 @@ LWZReadByte(SDL_RWops *src, int flag, int input_code_size)
table[0][i] = 0;
table[1][i] = i;
}
table[1][0] = 0;
for (; i < (1 << MAX_LWZ_BITS); ++i)
table[0][i] = table[1][0] = 0;
table[0][i] = 0;

sp = stack;

Expand Down Expand Up @@ -493,12 +494,22 @@ LWZReadByte(SDL_RWops *src, int flag, int input_code_size)
code = oldcode;
}
while (code >= clear_code) {
/* Guard against buffer overruns */
if (code < 0 || code >= (1 << MAX_LWZ_BITS)) {
RWSetMsg("invalid LWZ data");
return -3;
}
*sp++ = table[1][code];
if (code == table[0][code])
RWSetMsg("circular table entry BIG ERROR");
code = table[0][code];
}

/* Guard against buffer overruns */
if (code < 0 || code >= (1 << MAX_LWZ_BITS)) {
RWSetMsg("invalid LWZ data");
return -4;
}
*sp++ = firstcode = table[1][code];

if ((code = max_code) < (1 << MAX_LWZ_BITS)) {
Expand Down
12 changes: 6 additions & 6 deletions IMG_jpg.c
Expand Up @@ -177,7 +177,7 @@ void IMG_QuitJPG()
/* See if an image is contained in a data source */
int IMG_isJPG(SDL_RWops *src)
{
int start;
Sint64 start;
int is_JPG;
int in_scan;
Uint8 magic[4];
Expand Down Expand Up @@ -214,13 +214,13 @@ int IMG_isJPG(SDL_RWops *src)
is_JPG = 0;
} else {
/* Yes, it's big-endian */
Uint32 start;
Sint64 innerStart;
Uint32 size;
Uint32 end;
start = SDL_RWtell(src);
Sint64 end;
innerStart = SDL_RWtell(src);
size = (magic[2] << 8) + magic[3];
end = SDL_RWseek(src, size-2, RW_SEEK_CUR);
if ( end != start + size - 2 ) is_JPG = 0;
if ( end != innerStart + size - 2 ) is_JPG = 0;
if ( magic[1] == 0xDA ) {
/* Now comes the actual JPEG meat */
#ifdef FAST_IS_JPEG
Expand Down Expand Up @@ -374,7 +374,7 @@ static void output_no_message(j_common_ptr cinfo)
/* Load a JPEG type image from an SDL datasource */
SDL_Surface *IMG_LoadJPG_RW(SDL_RWops *src)
{
int start;
Sint64 start;
struct jpeg_decompress_struct cinfo;
JSAMPROW rowptr[1];
SDL_Surface *volatile surface = NULL;
Expand Down
42 changes: 19 additions & 23 deletions IMG_lbm.c
Expand Up @@ -61,7 +61,7 @@ typedef struct

int IMG_isLBM( SDL_RWops *src )
{
int start;
Sint64 start;
int is_LBM;
Uint8 magic[4+4+4];

Expand All @@ -71,9 +71,9 @@ int IMG_isLBM( SDL_RWops *src )
is_LBM = 0;
if ( SDL_RWread( src, magic, sizeof(magic), 1 ) )
{
if ( !memcmp( magic, "FORM", 4 ) &&
( !memcmp( magic + 8, "PBM ", 4 ) ||
!memcmp( magic + 8, "ILBM", 4 ) ) )
if ( !SDL_memcmp( magic, "FORM", 4 ) &&
( !SDL_memcmp( magic + 8, "PBM ", 4 ) ||
!SDL_memcmp( magic + 8, "ILBM", 4 ) ) )
{
is_LBM = 1;
}
Expand All @@ -84,7 +84,7 @@ int IMG_isLBM( SDL_RWops *src )

SDL_Surface *IMG_LoadLBM_RW( SDL_RWops *src )
{
int start;
Sint64 start;
SDL_Surface *Image;
Uint8 id[4], pbm, colormap[MAXCOLORS*3], *MiniBuf, *ptr, count, color, msk;
Uint32 size, bytesloaded, nbcolors;
Expand Down Expand Up @@ -135,20 +135,20 @@ SDL_Surface *IMG_LoadLBM_RW( SDL_RWops *src )
pbm = 0;

/* File format : PBM=Packed Bitmap, ILBM=Interleaved Bitmap */
if ( !memcmp( id, "PBM ", 4 ) ) pbm = 1;
else if ( memcmp( id, "ILBM", 4 ) )
if ( !SDL_memcmp( id, "PBM ", 4 ) ) pbm = 1;
else if ( SDL_memcmp( id, "ILBM", 4 ) )
{
error="not a IFF picture";
goto done;
}

nbcolors = 0;

memset( &bmhd, 0, sizeof( BMHD ) );
SDL_memset( &bmhd, 0, sizeof( BMHD ) );
flagHAM = 0;
flagEHB = 0;

while ( memcmp( id, "BODY", 4 ) != 0 )
while ( SDL_memcmp( id, "BODY", 4 ) != 0 )
{
if ( !SDL_RWread( src, id, 4, 1 ) )
{
Expand All @@ -166,7 +166,7 @@ SDL_Surface *IMG_LoadLBM_RW( SDL_RWops *src )

size = SDL_SwapBE32( size );

if ( !memcmp( id, "BMHD", 4 ) ) /* Bitmap header */
if ( !SDL_memcmp( id, "BMHD", 4 ) ) /* Bitmap header */
{
if ( !SDL_RWread( src, &bmhd, sizeof( BMHD ), 1 ) )
{
Expand All @@ -185,7 +185,7 @@ SDL_Surface *IMG_LoadLBM_RW( SDL_RWops *src )
bmhd.Hpage = SDL_SwapBE16( bmhd.Hpage );
}

if ( !memcmp( id, "CMAP", 4 ) ) /* palette ( Color Map ) */
if ( !SDL_memcmp( id, "CMAP", 4 ) ) /* palette ( Color Map ) */
{
if ( !SDL_RWread( src, &colormap, size, 1 ) )
{
Expand Down Expand Up @@ -214,7 +214,7 @@ SDL_Surface *IMG_LoadLBM_RW( SDL_RWops *src )
flagEHB = 1;
}

if ( memcmp( id, "BODY", 4 ) )
if ( SDL_memcmp( id, "BODY", 4 ) )
{
if ( size & 1 ) ++size; /* padding ! */
size -= bytesloaded;
Expand Down Expand Up @@ -242,7 +242,7 @@ SDL_Surface *IMG_LoadLBM_RW( SDL_RWops *src )
/* Allocate memory for a temporary buffer ( used for
decompression/deinterleaving ) */

MiniBuf = (void *)malloc( bytesperline * (nbplanes + stencil) );
MiniBuf = (Uint8 *)SDL_malloc( bytesperline * (nbplanes + stencil) );
if ( MiniBuf == NULL )
{
error="no enough memory for temporary buffer";
Expand Down Expand Up @@ -335,7 +335,7 @@ SDL_Surface *IMG_LoadLBM_RW( SDL_RWops *src )
error="error reading BODY chunk";
goto done;
}
memset( ptr, color, count );
SDL_memset( ptr, color, count );
}
else
{
Expand Down Expand Up @@ -365,7 +365,7 @@ SDL_Surface *IMG_LoadLBM_RW( SDL_RWops *src )

/* One line has been read, store it ! */

ptr = Image->pixels;
ptr = (Uint8 *)Image->pixels;
if ( nbplanes==24 || flagHAM==1 )
ptr += h * width * 3;
else
Expand Down Expand Up @@ -449,19 +449,15 @@ SDL_Surface *IMG_LoadLBM_RW( SDL_RWops *src )
{
finalcolor = pixelcolor;
}
if ( SDL_BYTEORDER == SDL_LIL_ENDIAN )
{
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
*ptr++ = (Uint8)(finalcolor>>16);
*ptr++ = (Uint8)(finalcolor>>8);
*ptr++ = (Uint8)(finalcolor);
}
else
{
*ptr++ = (Uint8)(finalcolor);
#else
*ptr++ = (Uint8)(finalcolor);
*ptr++ = (Uint8)(finalcolor>>8);
*ptr++ = (Uint8)(finalcolor>>16);
}

#endif
maskBit = maskBit>>1;
}
}
Expand Down

0 comments on commit f67b63b

Please sign in to comment.