IMG_jpg.c
changeset 343 5bf0f0d6a74e
parent 322 92e073f230d0
child 347 ad5034cad524
equal deleted inserted replaced
341:18ab81286e51 343:5bf0f0d6a74e
   175 #endif /* LOAD_JPG_DYNAMIC */
   175 #endif /* LOAD_JPG_DYNAMIC */
   176 
   176 
   177 /* See if an image is contained in a data source */
   177 /* See if an image is contained in a data source */
   178 int IMG_isJPG(SDL_RWops *src)
   178 int IMG_isJPG(SDL_RWops *src)
   179 {
   179 {
   180 	int start;
   180 	Sint64 start;
   181 	int is_JPG;
   181 	int is_JPG;
   182 	int in_scan;
   182 	int in_scan;
   183 	Uint8 magic[4];
   183 	Uint8 magic[4];
   184 
   184 
   185 	/* This detection code is by Steaphan Greene <stea@cs.binghamton.edu> */
   185 	/* This detection code is by Steaphan Greene <stea@cs.binghamton.edu> */
   212 					/* These have nothing else */
   212 					/* These have nothing else */
   213 				} else if(SDL_RWread(src, magic+2, 1, 2) != 2) {
   213 				} else if(SDL_RWread(src, magic+2, 1, 2) != 2) {
   214 					is_JPG = 0;
   214 					is_JPG = 0;
   215 				} else {
   215 				} else {
   216 					/* Yes, it's big-endian */
   216 					/* Yes, it's big-endian */
   217 					Uint32 start;
   217 					Sint64 innerStart;
   218 					Uint32 size;
   218 					Uint32 size;
   219 					Uint32 end;
   219 					Sint64 end;
   220 					start = SDL_RWtell(src);
   220 					innerStart = SDL_RWtell(src);
   221 					size = (magic[2] << 8) + magic[3];
   221 					size = (magic[2] << 8) + magic[3];
   222 					end = SDL_RWseek(src, size-2, RW_SEEK_CUR);
   222 					end = SDL_RWseek(src, size-2, RW_SEEK_CUR);
   223 					if ( end != start + size - 2 ) is_JPG = 0;
   223 					if ( end != innerStart + size - 2 ) is_JPG = 0;
   224 					if ( magic[1] == 0xDA ) {
   224 					if ( magic[1] == 0xDA ) {
   225 						/* Now comes the actual JPEG meat */
   225 						/* Now comes the actual JPEG meat */
   226 #ifdef	FAST_IS_JPEG
   226 #ifdef	FAST_IS_JPEG
   227 						/* Ok, I'm convinced.  It is a JPEG. */
   227 						/* Ok, I'm convinced.  It is a JPEG. */
   228 						break;
   228 						break;
   372 }
   372 }
   373 
   373 
   374 /* Load a JPEG type image from an SDL datasource */
   374 /* Load a JPEG type image from an SDL datasource */
   375 SDL_Surface *IMG_LoadJPG_RW(SDL_RWops *src)
   375 SDL_Surface *IMG_LoadJPG_RW(SDL_RWops *src)
   376 {
   376 {
   377 	int start;
   377 	Sint64 start;
   378 	struct jpeg_decompress_struct cinfo;
   378 	struct jpeg_decompress_struct cinfo;
   379 	JSAMPROW rowptr[1];
   379 	JSAMPROW rowptr[1];
   380 	SDL_Surface *volatile surface = NULL;
   380 	SDL_Surface *volatile surface = NULL;
   381 	struct my_error_mgr jerr;
   381 	struct my_error_mgr jerr;
   382 
   382