forked from libsdl-org/SDL_image
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sam Lantinga
committed
Aug 10, 2000
0 parents
commit 4ddea44
Showing
31 changed files
with
18,830 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
1.0.9: | ||
Mattias Engdeg�rd - Sat Jul 1 17:57:37 PDT 2000 | ||
* PNG loader properly sets the colorkey on 8-bit transparent images | ||
Mattias Engdeg�rd - Sat Jul 1 13:24:47 PDT 2000 | ||
* Fixed a bug in PCX detection | ||
* Added support for TGA files | ||
* showimage shows a checker background for transparent images | ||
|
||
1.0.8: | ||
Mark Baker - Tue May 30 12:20:00 PDT 2000 | ||
* Added TIFF format loading support | ||
|
||
1.0.7: | ||
Mattias Engdeg�rd - Sat May 27 14:18:33 PDT 2000 | ||
* Added fixes for loading images on big-endian systems | ||
|
||
1.0.6: | ||
Sam Lantinga - Sat Apr 29 10:18:32 PDT 2000 | ||
* showimage puts the name of the image in the title bar caption | ||
Sam Lantinga - Sat Apr 29 10:05:58 PDT 2000 | ||
* Removed pitch check, since PNG already loads to a list of row pointers | ||
|
||
1.0.5: | ||
Sam Lantinga - Sun Apr 23 14:41:32 PDT 2000 | ||
* Added support for GIF transparency | ||
Sam Lantinga - Wed Apr 12 14:39:20 PDT 2000 | ||
* Fixed memory heap crash on NT using PNG images | ||
Matt Campbell - Thu, 13 Apr 2000 13:29:17 -0700 | ||
* Fixed PNG detection on some Linux systems | ||
|
||
1.0.4: | ||
Sam Lantinga - Tue Feb 1 13:33:53 PST 2000 | ||
* Cleaned up for Visual C++ | ||
* Added Visual C++ project file | ||
|
||
1.0.3: | ||
Sam Lantinga - Wed Jan 19 22:10:52 PST 2000 | ||
* Added CHANGES | ||
* Added rpm spec file contributed by Hakan Tandogan | ||
* Changed the name of the example program from "show" to "showimage" |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
/* | ||
IMGLIB: An example image loading library for use with SDL | ||
Copyright (C) 1999 Sam Lantinga | ||
This library is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU Library General Public | ||
License as published by the Free Software Foundation; either | ||
version 2 of the License, or (at your option) any later version. | ||
This library is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
Library General Public License for more details. | ||
You should have received a copy of the GNU Library General Public | ||
License along with this library; if not, write to the Free | ||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
Sam Lantinga | ||
5635-34 Springhouse Dr. | ||
Pleasanton, CA 94588 (USA) | ||
[email protected] | ||
*/ | ||
|
||
/* A simple library to load images of various formats as SDL surfaces */ | ||
|
||
#include <stdio.h> | ||
#include <string.h> | ||
#include <ctype.h> | ||
|
||
#include "SDL_image.h" | ||
|
||
/* Table of image detection and loading functions */ | ||
static struct { | ||
char *type; | ||
int (*is)(SDL_RWops *src); | ||
SDL_Surface *(*load)(SDL_RWops *src); | ||
} supported[] = { | ||
/* keep magicless formats first (denoted by is==NULL) */ | ||
{ "TGA", NULL, IMG_LoadTGA_RW }, | ||
{ "BMP", IMG_isBMP, IMG_LoadBMP_RW }, | ||
{ "PPM", IMG_isPPM, IMG_LoadPPM_RW }, | ||
{ "PCX", IMG_isPCX, IMG_LoadPCX_RW }, | ||
{ "GIF", IMG_isGIF, IMG_LoadGIF_RW }, | ||
{ "JPG", IMG_isJPG, IMG_LoadJPG_RW }, | ||
{ "TIF", IMG_isTIF, IMG_LoadTIF_RW }, | ||
{ "PNG", IMG_isPNG, IMG_LoadPNG_RW }, | ||
}; | ||
|
||
/* Does the alpha value correspond to transparency or opacity? | ||
Default: transparency | ||
*/ | ||
int IMG_invert_alpha = 0; | ||
|
||
/* Load an image from a file */ | ||
SDL_Surface *IMG_Load(const char *file) | ||
{ | ||
SDL_RWops *src = SDL_RWFromFile(file, "rb"); | ||
char *ext = strrchr(file, '.'); | ||
if(ext) | ||
ext++; | ||
return IMG_LoadTyped_RW(src, 1, ext); | ||
} | ||
|
||
/* Load an image from an SDL datasource (for compatibility) */ | ||
SDL_Surface *IMG_Load_RW(SDL_RWops *src, int freesrc) | ||
{ | ||
return IMG_LoadTyped_RW(src, freesrc, NULL); | ||
} | ||
|
||
/* Portable case-insensitive string compare function */ | ||
static int string_equals(const char *str1, const char *str2) | ||
{ | ||
while ( *str1 && *str2 ) { | ||
if ( toupper((unsigned char)*str1) != | ||
toupper((unsigned char)*str2) ) | ||
break; | ||
++str1; | ||
++str2; | ||
} | ||
return (!*str1 && !*str2); | ||
} | ||
|
||
/* Load an image from an SDL datasource, optionally specifying the type */ | ||
SDL_Surface *IMG_LoadTyped_RW(SDL_RWops *src, int freesrc, char *type) | ||
{ | ||
int i, start; | ||
SDL_Surface *image; | ||
|
||
/* Make sure there is something to do.. */ | ||
if ( src == NULL ) { | ||
return(NULL); | ||
} | ||
|
||
/* See whether or not this data source can handle seeking */ | ||
if ( SDL_RWseek(src, 0, SEEK_CUR) < 0 ) { | ||
IMG_SetError("Can't seek in this data source"); | ||
return(NULL); | ||
} | ||
|
||
/* Detect the type of image being loaded */ | ||
start = SDL_RWtell(src); | ||
image = NULL; | ||
for ( i=0; supported[i].type && !image; ++i ) { | ||
if( (supported[i].is | ||
&& (SDL_RWseek(src, start, SEEK_SET), | ||
supported[i].is(src))) | ||
|| (type && string_equals(type, supported[i].type))) { | ||
#ifdef DEBUG_IMGLIB | ||
fprintf(stderr, "IMGLIB: Loading image as %s\n", | ||
supported[i].type); | ||
#endif | ||
SDL_RWseek(src, start, SEEK_SET); | ||
image = supported[i].load(src); | ||
break; | ||
} | ||
} | ||
|
||
/* Clean up, check for errors, and return */ | ||
if ( freesrc ) { | ||
SDL_RWclose(src); | ||
} | ||
if ( image == NULL ) { | ||
IMG_SetError("Unsupported image format"); | ||
} | ||
return(image); | ||
} | ||
|
||
/* Invert the alpha of a surface for use with OpenGL | ||
If you want to use a surface loaded with this library as an OpenGL texture, | ||
set invart_alpha to 1. If you want to use it with SDL alpha blit routines, | ||
set it to 0. | ||
This function returns the old alpha inversion value. | ||
Currently this is is only used by the PNG and TGA loaders. | ||
*/ | ||
int IMG_InvertAlpha(int on) | ||
{ | ||
int old_alpha_value; | ||
|
||
old_alpha_value = IMG_invert_alpha; | ||
IMG_invert_alpha = on; | ||
return(old_alpha_value); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
IMGLIB: An example image loading library for use with SDL | ||
Copyright (C) 1999 Sam Lantinga | ||
This library is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU Library General Public | ||
License as published by the Free Software Foundation; either | ||
version 2 of the License, or (at your option) any later version. | ||
This library is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
Library General Public License for more details. | ||
You should have received a copy of the GNU Library General Public | ||
License along with this library; if not, write to the Free | ||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
Sam Lantinga | ||
5635-34 Springhouse Dr. | ||
Pleasanton, CA 94588 (USA) | ||
[email protected] | ||
*/ | ||
|
||
/* This is a BMP image file loading framework */ | ||
|
||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
#include "SDL_image.h" | ||
|
||
#ifdef LOAD_BMP | ||
|
||
/* See if an image is contained in a data source */ | ||
int IMG_isBMP(SDL_RWops *src) | ||
{ | ||
int is_BMP; | ||
char magic[2]; | ||
|
||
is_BMP = 0; | ||
if ( SDL_RWread(src, magic, 2, 1) ) { | ||
if ( strncmp(magic, "BM", 2) == 0 ) { | ||
is_BMP = 1; | ||
} | ||
} | ||
return(is_BMP); | ||
} | ||
|
||
/* Load a BMP type image from an SDL datasource */ | ||
SDL_Surface *IMG_LoadBMP_RW(SDL_RWops *src) | ||
{ | ||
return(SDL_LoadBMP_RW(src, 0)); | ||
} | ||
|
||
#else | ||
|
||
/* See if an image is contained in a data source */ | ||
int IMG_isBMP(SDL_RWops *src) | ||
{ | ||
return(0); | ||
} | ||
|
||
/* Load a BMP type image from an SDL datasource */ | ||
SDL_Surface *IMG_LoadBMP_RW(SDL_RWops *src) | ||
{ | ||
return(NULL); | ||
} | ||
|
||
#endif /* LOAD_BMP */ |
Oops, something went wrong.