IMG_pnm.c
changeset 343 5bf0f0d6a74e
parent 320 aa5d55b11751
child 347 ad5034cad524
equal deleted inserted replaced
341:18ab81286e51 343:5bf0f0d6a74e
    37 #ifdef LOAD_PNM
    37 #ifdef LOAD_PNM
    38 
    38 
    39 /* See if an image is contained in a data source */
    39 /* See if an image is contained in a data source */
    40 int IMG_isPNM(SDL_RWops *src)
    40 int IMG_isPNM(SDL_RWops *src)
    41 {
    41 {
    42 	int start;
    42 	Sint64 start;
    43 	int is_PNM;
    43 	int is_PNM;
    44 	char magic[2];
    44 	char magic[2];
    45 
    45 
    46 	if ( !src )
    46 	if ( !src )
    47 		return 0;
    47 		return 0;
   103 	return(number);
   103 	return(number);
   104 }
   104 }
   105 
   105 
   106 SDL_Surface *IMG_LoadPNM_RW(SDL_RWops *src)
   106 SDL_Surface *IMG_LoadPNM_RW(SDL_RWops *src)
   107 {
   107 {
   108 	int start;
   108 	Sint64 start;
   109 	SDL_Surface *surface = NULL;
   109 	SDL_Surface *surface = NULL;
   110 	int width, height;
   110 	int width, height;
   111 	int maxval, y, bpl;
   111 	int maxval, y, bpl;
   112 	Uint8 *row;
   112 	Uint8 *row;
   113 	Uint8 *buf = NULL;
   113 	Uint8 *buf = NULL;
   175 		SDL_Color *c = surface->format->palette->colors;
   175 		SDL_Color *c = surface->format->palette->colors;
   176 		c[0].r = c[0].g = c[0].b = 255;
   176 		c[0].r = c[0].g = c[0].b = 255;
   177 		c[1].r = c[1].g = c[1].b = 0;
   177 		c[1].r = c[1].g = c[1].b = 0;
   178 		surface->format->palette->ncolors = 2;
   178 		surface->format->palette->ncolors = 2;
   179 		bpl = (width + 7) >> 3;
   179 		bpl = (width + 7) >> 3;
   180 		buf = malloc(bpl);
   180 		buf = (Uint8 *)SDL_malloc(bpl);
   181 		if(buf == NULL)
   181 		if(buf == NULL)
   182 			ERROR("Out of memory");
   182 			ERROR("Out of memory");
   183 	}
   183 	}
   184 
   184 
   185 	/* Read the image into the surface */
   185 	/* Read the image into the surface */
   186 	row = surface->pixels;
   186 	row = (Uint8 *)surface->pixels;
   187 	for(y = 0; y < height; y++) {
   187 	for(y = 0; y < height; y++) {
   188 		if(ascii) {
   188 		if(ascii) {
   189 			int i;
   189 			int i;
   190 			if(kind == PBM) {
   190 			if(kind == PBM) {
   191 				for(i = 0; i < width; i++) {
   191 				for(i = 0; i < width; i++) {