Skip to content

Commit

Permalink
Portability fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Lantinga committed Nov 30, 2000
1 parent 384fc25 commit 63c7812
Show file tree
Hide file tree
Showing 7 changed files with 479 additions and 443 deletions.
12 changes: 9 additions & 3 deletions IMG_png.c
Expand Up @@ -66,6 +66,9 @@

#include "SDL_endian.h"

#ifdef macintosh
#define MACOS
#endif
#include <png.h>

#define PNG_BYTES_TO_CHECK 4
Expand Down Expand Up @@ -210,8 +213,11 @@ SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *src)

if(ckey != -1) {
if(color_type != PNG_COLOR_TYPE_PALETTE)
ckey = SDL_MapRGB(surface->format, transv->red,
transv->green, transv->blue);
/* FIXME: Should these be truncated or shifted down? */
ckey = SDL_MapRGB(surface->format,
(Uint8)transv->red,
(Uint8)transv->green,
(Uint8)transv->blue);
SDL_SetColorKey(surface, SDL_SRCCOLORKEY, ckey);
}

Expand All @@ -223,7 +229,7 @@ SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *src)
surface = NULL;
goto done;
}
for (row = 0; row < height; row++) {
for (row = 0; row < (int)height; row++) {
row_pointers[row] = (png_bytep)
(Uint8 *)surface->pixels + row*surface->pitch;
}
Expand Down
3 changes: 2 additions & 1 deletion IMG_tga.c
Expand Up @@ -22,8 +22,9 @@
slouken@devolution.com
*/

#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include "SDL_endian.h"

Expand Down
41 changes: 35 additions & 6 deletions IMG_xpm.c
Expand Up @@ -24,6 +24,7 @@

/* This is an XPM image file loading framework */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
Expand All @@ -47,6 +48,34 @@ int IMG_isXPM(SDL_RWops *src)
return(is_XPM);
}

static char *my_strdup(const char *string)
{
char *newstring;

newstring = (char *)malloc(strlen(string)+1);
if ( newstring ) {
strcpy(newstring, string);
}
return(newstring);
}

/* Not exactly the same semantics as strncasecmp(), but portable */
static int my_strncasecmp(const char *str1, const char *str2, int len)
{
if ( len == 0 ) {
len = strlen(str2);
if ( len != strlen(str1) ) {
return(-1);
}
}
while ( len-- > 0 ) {
if ( tolower(*str1++) != tolower(*str2++) ) {
return(-1);
}
}
return(0);
}

static char *SDL_RWgets(char *string, int maxlen, SDL_RWops *src)
{
int i;
Expand All @@ -64,7 +93,7 @@ static char *SDL_RWgets(char *string, int maxlen, SDL_RWops *src)
as line separators because blank lines are just
ignored by the XPM format.
*/
if ( (string[i] == '\n') || (string[i] == '\n') ) {
if ( (string[i] == '\r') || (string[i] == '\n') ) {
break;
}
}
Expand Down Expand Up @@ -119,7 +148,7 @@ static int add_colorhash(struct color_hash *hash,
return(0);
}
entry->keylen = cpp;
entry->key = strdup(key);
entry->key = my_strdup(key);
if ( ! entry->key ) {
free(entry);
return(0);
Expand Down Expand Up @@ -181,13 +210,13 @@ static int color_to_rgb(const char *colorspec, int *r, int *g, int *b)
char bbuf[3];

/* Handle monochrome black and white */
if ( strcasecmp(colorspec, "black") == 0 ) {
if ( my_strncasecmp(colorspec, "black", 0) == 0 ) {
*r = 0;
*g = 0;
*b = 0;
return(1);
}
if ( strcasecmp(colorspec, "white") == 0 ) {
if ( my_strncasecmp(colorspec, "white", 0) == 0 ) {
*r = 255;
*g = 255;
*b = 255;
Expand Down Expand Up @@ -369,8 +398,8 @@ SDL_Surface *IMG_LoadXPM_RW(SDL_RWops *src)
}
++here;
while ( isspace(*here) ) ++here;
if ( strncasecmp(here, "None", 4) == 0 ) {
colorkey_string = strdup(key);
if ( my_strncasecmp(here, "None", 4) == 0 ) {
colorkey_string = my_strdup(key);
if ( indexed ) {
colorkey = (Uint32)index;
} else {
Expand Down
852 changes: 426 additions & 426 deletions MPWmake.sea.hqx

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README
@@ -1,5 +1,5 @@

SDL_image 1.0
SDL_image 1.1

The latest version of this library is available from:
http://www.devolution.com/~slouken/SDL/projects/SDL_image/
Expand Down
Binary file modified VisualC.zip
Binary file not shown.
12 changes: 6 additions & 6 deletions showimage.c
Expand Up @@ -77,21 +77,21 @@ int main(int argc, char *argv[])
/* Check command line usage */
if ( ! argv[1] ) {
fprintf(stderr, "Usage: %s <image_file>\n", argv[0]);
exit(1);
return(1);
}

/* Initialize the SDL library */
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
exit(255);
return(255);
}

/* Open the image file */
image = IMG_Load(argv[1]);
if ( image == NULL ) {
fprintf(stderr,"Couldn't load %s: %s\n",argv[1],SDL_GetError());
SDL_Quit();
exit(2);
return(2);
}
SDL_WM_SetCaption(argv[1], "showimage");

Expand All @@ -107,7 +107,7 @@ int main(int argc, char *argv[])
fprintf(stderr,"Couldn't set %dx%dx%d video mode: %s\n",
image->w, image->h, depth, SDL_GetError());
SDL_Quit();
exit(3);
return(3);
}

/* Set the palette, if one exists */
Expand All @@ -134,7 +134,7 @@ int main(int argc, char *argv[])
break;
default:
/* We don't want this event */
SDL_EventState(i, SDL_IGNORE);
SDL_EventState((Uint8)i, SDL_IGNORE);
break;
}
}
Expand All @@ -143,5 +143,5 @@ int main(int argc, char *argv[])
/* We're done! */
SDL_FreeSurface(image);
SDL_Quit();
exit(0);
return(0);
}

0 comments on commit 63c7812

Please sign in to comment.