Mattias Engdeg�rd - Wed Aug 9 20:32:22 MET DST 2000
authorSam Lantinga <slouken@lokigames.com>
Fri, 01 Sep 2000 00:45:57 +0000
changeset 4b1bb33e907f8
parent 3 242657bf16f3
child 5 e5fbb4b15ebe
Mattias Engdeg�rd - Wed Aug 9 20:32:22 MET DST 2000
* Removed the alpha flipping, made IMG_InvertAlpha() a noop
* Fixed nonexisting PCX alpha support
* Some TIFF bugfixes
* PNG greyscale images are loaded as 8bpp with a greyscale palette
CHANGES
IMG.c
IMG_pcx.c
IMG_png.c
IMG_tga.c
IMG_tif.c
SDL_image.h
configure.in
showimage.c
     1.1 --- a/CHANGES	Thu Aug 10 06:15:57 2000 +0000
     1.2 +++ b/CHANGES	Fri Sep 01 00:45:57 2000 +0000
     1.3 @@ -1,5 +1,10 @@
     1.4  
     1.5  1.0.10:
     1.6 +Mattias Engdegrd - Wed Aug  9 20:32:22 MET DST 2000
     1.7 + * Removed the alpha flipping, made IMG_InvertAlpha() a noop
     1.8 + * Fixed nonexisting PCX alpha support
     1.9 + * Some TIFF bugfixes
    1.10 + * PNG greyscale images are loaded as 8bpp with a greyscale palette
    1.11  Ray Kelm - Fri, 04 Aug 2000 20:58:00 -0400
    1.12   * Added support for cross-compiling Windows DLL from Linux
    1.13  
     2.1 --- a/IMG.c	Thu Aug 10 06:15:57 2000 +0000
     2.2 +++ b/IMG.c	Fri Sep 01 00:45:57 2000 +0000
     2.3 @@ -47,11 +47,6 @@
     2.4  	{ "PNG", IMG_isPNG, IMG_LoadPNG_RW },
     2.5  };
     2.6  
     2.7 -/* Does the alpha value correspond to transparency or opacity?
     2.8 -   Default: transparency
     2.9 -*/
    2.10 -int IMG_invert_alpha = 0;
    2.11 -
    2.12  /* Load an image from a file */
    2.13  SDL_Surface *IMG_Load(const char *file)
    2.14  {
    2.15 @@ -127,19 +122,9 @@
    2.16  }
    2.17  
    2.18  /* Invert the alpha of a surface for use with OpenGL
    2.19 -   If you want to use a surface loaded with this library as an OpenGL texture,
    2.20 -   set invart_alpha to 1.  If you want to use it with SDL alpha blit routines,
    2.21 -   set it to 0.
    2.22 -   This function returns the old alpha inversion value.
    2.23 -
    2.24 -   Currently this is is only used by the PNG and TGA loaders.
    2.25 +   This function is a no-op and only kept for backwards compatibility.
    2.26   */
    2.27  int IMG_InvertAlpha(int on)
    2.28  {
    2.29 -	int old_alpha_value;
    2.30 -
    2.31 -	old_alpha_value = IMG_invert_alpha;
    2.32 -	IMG_invert_alpha = on;
    2.33 -	return(old_alpha_value);
    2.34 +    return 1;
    2.35  }
    2.36 -
     3.1 --- a/IMG_pcx.c	Thu Aug 10 06:15:57 2000 +0000
     3.2 +++ b/IMG_pcx.c	Fri Sep 01 00:45:57 2000 +0000
     3.3 @@ -112,13 +112,11 @@
     3.4  			Rmask = 0x000000FF;
     3.5  			Gmask = 0x0000FF00;
     3.6  			Bmask = 0x00FF0000;
     3.7 -			Amask = 0xFF000000;
     3.8  		} else {
     3.9  		        int s = (pcxh.NPlanes == 4) ? 0 : 8;
    3.10 -			Rmask = 0xFF000000 >> s;
    3.11 -			Gmask = 0x00FF0000 >> s;
    3.12 -			Bmask = 0x0000FF00 >> s;
    3.13 -			Amask = 0x000000FF >> s;
    3.14 +			Rmask = 0xFF0000;
    3.15 +			Gmask = 0x00FF00;
    3.16 +			Bmask = 0x0000FF;
    3.17  		}
    3.18  	}
    3.19  	surface = SDL_AllocSurface(SDL_SWSURFACE, width, height,
     4.1 --- a/IMG_png.c	Thu Aug 10 06:15:57 2000 +0000
     4.2 +++ b/IMG_png.c	Fri Sep 01 00:45:57 2000 +0000
     4.3 @@ -31,8 +31,6 @@
     4.4  
     4.5  #ifdef LOAD_PNG
     4.6  
     4.7 -extern int IMG_invert_alpha;
     4.8 -
     4.9  /*=============================================================================
    4.10          File: SDL_png.c
    4.11       Purpose: A PNG loader and saver for the SDL library      
    4.12 @@ -158,10 +156,9 @@
    4.13  	 */
    4.14  	png_set_packing(png_ptr);
    4.15  
    4.16 -	/* SDL and PNG have inverted ideas of alpha */
    4.17 -	if ( ! IMG_invert_alpha ) {
    4.18 -		png_set_invert_alpha(png_ptr);
    4.19 -	}
    4.20 +	/* scale greyscale values to the range 0..255 */
    4.21 +	if(color_type == PNG_COLOR_TYPE_GRAY)
    4.22 +		png_set_expand(png_ptr);
    4.23  
    4.24  	/* For images with a single "transparent colour", set colour key;
    4.25  	   if more than one index has transparency, use full alpha channel */
    4.26 @@ -180,8 +177,7 @@
    4.27  		    ckey = 0; /* actual value will be set later */
    4.28  	}
    4.29  
    4.30 -	if ( (color_type == PNG_COLOR_TYPE_GRAY) ||
    4.31 -		  (color_type == PNG_COLOR_TYPE_GRAY_ALPHA) )
    4.32 +	if ( color_type == PNG_COLOR_TYPE_GRAY_ALPHA )
    4.33  		png_set_gray_to_rgb(png_ptr);
    4.34  
    4.35  	png_read_update_info(png_ptr, info_ptr);
    4.36 @@ -240,13 +236,22 @@
    4.37  
    4.38  	/* Load the palette, if any */
    4.39  	palette = surface->format->palette;
    4.40 -	if ( palette && (info_ptr->num_palette > 0) ) {
    4.41 +	if ( palette ) {
    4.42 +	    if(color_type == PNG_COLOR_TYPE_GRAY) {
    4.43 +		palette->ncolors = 256;
    4.44 +		for(i = 0; i < 256; i++) {
    4.45 +		    palette->colors[i].r = i;
    4.46 +		    palette->colors[i].g = i;
    4.47 +		    palette->colors[i].b = i;
    4.48 +		}
    4.49 +	    } else if (info_ptr->num_palette > 0 ) {
    4.50  		palette->ncolors = info_ptr->num_palette; 
    4.51  		for( i=0; i<info_ptr->num_palette; ++i ) {
    4.52 -			palette->colors[i].b =(Uint8)info_ptr->palette[i].blue;
    4.53 -			palette->colors[i].g =(Uint8)info_ptr->palette[i].green;
    4.54 -			palette->colors[i].r =(Uint8)info_ptr->palette[i].red;
    4.55 +		    palette->colors[i].b = info_ptr->palette[i].blue;
    4.56 +		    palette->colors[i].g = info_ptr->palette[i].green;
    4.57 +		    palette->colors[i].r = info_ptr->palette[i].red;
    4.58  		}
    4.59 +	    }
    4.60  	}
    4.61  
    4.62  done:	/* Clean up and return */
     5.1 --- a/IMG_tga.c	Thu Aug 10 06:15:57 2000 +0000
     5.2 +++ b/IMG_tga.c	Fri Sep 01 00:45:57 2000 +0000
     5.3 @@ -38,10 +38,9 @@
     5.4   *
     5.5   * 2000-06-10 Mattias Engdegrd <f91-men@nada.kth.se>: initial version
     5.6   * 2000-06-26 Mattias Engdegrd <f91-men@nada.kth.se>: read greyscale TGAs
     5.7 + * 2000-08-09 Mattias Engdegrd <f91-men@nada.kth.se>: alpha inversion removed
     5.8   */
     5.9  
    5.10 -extern int IMG_invert_alpha;
    5.11 -
    5.12  struct TGAheader {
    5.13      Uint8 infolen;		/* length of info field */
    5.14      Uint8 has_cmap;		/* 1 if image has colormap, 0 otherwise */
    5.15 @@ -143,20 +142,19 @@
    5.16      }
    5.17  
    5.18      bpp = (hdr.pixel_bits + 7) >> 3;
    5.19 +    rmask = gmask = bmask = amask = 0;
    5.20      switch(hdr.pixel_bits) {
    5.21      case 8:
    5.22  	if(!indexed) {
    5.23  	    unsupported();
    5.24  	    return NULL;
    5.25  	}
    5.26 -	rmask = gmask = bmask = amask = 0;
    5.27  	break;
    5.28  
    5.29      case 15:
    5.30      case 16:
    5.31  	/* 15 and 16bpp both seem to use 5 bits/plane. The extra alpha bit
    5.32  	   is ignored for now. */
    5.33 -	amask = 0;
    5.34  	rmask = 0x7c00;
    5.35  	gmask = 0x03e0;
    5.36  	bmask = 0x001f;
    5.37 @@ -246,7 +244,7 @@
    5.38  
    5.39      if(hdr.flags & TGA_ORIGIN_UPPER) {
    5.40  	lstep = img->pitch;
    5.41 -	dst = (Uint8 *)img->pixels;
    5.42 +	dst = img->pixels;
    5.43      } else {
    5.44  	lstep = -img->pitch;
    5.45  	dst = (Uint8 *)img->pixels + (h - 1) * img->pitch;
    5.46 @@ -302,16 +300,8 @@
    5.47  	    for(x = 0; x < w; x++)
    5.48  		p[x] = SDL_Swap16(p[x]);
    5.49  	}
    5.50 -	if(alpha && !IMG_invert_alpha) {
    5.51 -	    /* TGA stores alpha traditionally (0 transparent, 0xff opaque) */
    5.52 -	    int x;
    5.53 -	    for(x = 0; x < w; x++)
    5.54 -		dst[x * 4 + 3] ^= 0xff;
    5.55 -	}
    5.56  	dst += lstep;
    5.57      }
    5.58 -    if(alpha)
    5.59 -	SDL_SetAlpha(img, SDL_SRCALPHA, 0);
    5.60      return img;
    5.61  
    5.62  error:
     6.1 --- a/IMG_tif.c	Thu Aug 10 06:15:57 2000 +0000
     6.2 +++ b/IMG_tif.c	Fri Sep 01 00:45:57 2000 +0000
     6.3 @@ -22,6 +22,9 @@
     6.4      slouken@devolution.com
     6.5  
     6.6      5/29/2000: TIFF loader written. Mark Baker (mbaker@0x7a69.net)
     6.7 +    2000-07-28: Fixed two off-by one bugs in reversal loop and made it work on
     6.8 +                big-endian machines (Mattias)
     6.9 +    2000-08-09: Removed alpha inversion (Mattias)
    6.10  */
    6.11  
    6.12  
    6.13 @@ -36,7 +39,6 @@
    6.14  
    6.15  #include <tiffio.h>
    6.16  
    6.17 -
    6.18  /*
    6.19   * These are the thunking routine to use the SDL_RWops* routines from
    6.20   * libtiff's internals.
    6.21 @@ -109,11 +111,9 @@
    6.22  	TIFF* tiff;
    6.23  	SDL_Surface* surface = NULL;
    6.24  	Uint32 img_width, img_height;
    6.25 -	Uint32 Rmask, Gmask, Bmask, Amask;
    6.26 +	Uint32 Rmask, Gmask, Bmask, Amask, mask;
    6.27  	Uint32 x, y;
    6.28  	Uint32 half;
    6.29 -	Uint32 tl_coord, bl_coord;
    6.30 -	Uint32 tl_pixel, bl_pixel;
    6.31  
    6.32  
    6.33  	/* turn off memory mapped access with the m flag */
    6.34 @@ -126,21 +126,10 @@
    6.35  	TIFFGetField(tiff, TIFFTAG_IMAGEWIDTH, &img_width);
    6.36  	TIFFGetField(tiff, TIFFTAG_IMAGELENGTH, &img_height);
    6.37  
    6.38 -	if (SDL_BYTEORDER == SDL_LIL_ENDIAN)
    6.39 -	{
    6.40 -		Rmask = 0x000000FF;
    6.41 -		Gmask = 0x0000FF00;
    6.42 -		Bmask = 0x00FF0000;
    6.43 -		Amask = 0xFF000000;
    6.44 -	}
    6.45 -	else
    6.46 -	{
    6.47 -		Rmask = 0xFF000000;
    6.48 -		Gmask = 0x00FF0000;
    6.49 -		Bmask = 0x0000FF00;
    6.50 -		Amask = 0x000000FF;
    6.51 -	}              
    6.52 -
    6.53 +	Rmask = 0x000000FF;
    6.54 +	Gmask = 0x0000FF00;
    6.55 +	Bmask = 0x00FF0000;
    6.56 +	Amask = 0xFF000000;
    6.57  	surface = SDL_AllocSurface(SDL_SWSURFACE, img_width, img_height, 32,
    6.58  		Rmask, Gmask, Bmask, Amask);
    6.59  	if(!surface)
    6.60 @@ -149,36 +138,18 @@
    6.61  	if(!TIFFReadRGBAImage(tiff, img_width, img_height, surface->pixels, 0))
    6.62  		return NULL;
    6.63  
    6.64 -	/* 
    6.65 -	 * For this to make any sense, a little information is needed.
    6.66 -	 * Firstly, SDL uses more or less the opposite value for alpha as
    6.67 -	 * libtiff, so we need to invert the alpha channel of each pixel.
    6.68 -	 * To do this, I'm just xor it with the alpha mask.
    6.69 -	 *
    6.70 -	 * Secondly, libtiff loads the image more or less inverted.
    6.71 -	 * So the top left of the image ends up being the bottom left.
    6.72 -	 * To correct for this, we swap the pixels as we're inverting the 
    6.73 -	 * alpha channel
    6.74 -	*/
    6.75 -
    6.76 -	// We only need to loop 1/2 the height, because we're swapping values.
    6.77 +	/* libtiff loads the image upside-down, flip it back */
    6.78  	half = img_height / 2;
    6.79 -
    6.80 -	for(y = 0; y <= half; y++)
    6.81 +	for(y = 0; y < half; y++)
    6.82  	{
    6.83 +	        Uint32 *top = (Uint32 *)surface->pixels + y * surface->pitch/4;
    6.84 +	        Uint32 *bot = (Uint32 *)surface->pixels
    6.85 +		              + (img_height - y - 1) * surface->pitch/4;
    6.86  		for(x = 0; x < img_width; x++)
    6.87  		{
    6.88 -			tl_coord = y * img_width + x;
    6.89 -			bl_coord = (img_height - y - 1) * img_width + x;
    6.90 -
    6.91 -			/* Invert the value of the alpha channel, while copying the pixel */
    6.92 -			tl_pixel = *((Uint32*)surface->pixels + tl_coord) ^ Amask;
    6.93 -			bl_pixel = *((Uint32*)surface->pixels + bl_coord) ^ Amask;
    6.94 -
    6.95 -			/* Now invert the location of the pixel relative to the image */
    6.96 -			*((Uint32*)surface->pixels + bl_coord) = tl_pixel;
    6.97 -			*((Uint32*)surface->pixels + tl_coord) = bl_pixel;
    6.98 -
    6.99 +		        Uint32 tmp = top[x];
   6.100 +			top[x] = bot[x];
   6.101 +			bot[x] = tmp;
   6.102  		}
   6.103  	}
   6.104  	TIFFClose(tiff);
     7.1 --- a/SDL_image.h	Thu Aug 10 06:15:57 2000 +0000
     7.2 +++ b/SDL_image.h	Fri Sep 01 00:45:57 2000 +0000
     7.3 @@ -50,13 +50,8 @@
     7.4  extern DECLSPEC SDL_Surface *IMG_Load_RW(SDL_RWops *src, int freesrc);
     7.5  
     7.6  /* Invert the alpha of a surface for use with OpenGL
     7.7 -   If you want to use a surface loaded with this library as an OpenGL texture,
     7.8 -   set invart_alpha to 1.  If you want to use it with SDL alpha blit routines,
     7.9 -   set it to 0.
    7.10 -   This function returns the old alpha inversion value.
    7.11 -
    7.12 -   Currently this is is only used by the PNG and TGA loaders.
    7.13 - */
    7.14 +   This function is now a no-op, and only provided for backwards compatibility.
    7.15 +*/
    7.16  extern DECLSPEC int IMG_InvertAlpha(int on);
    7.17  
    7.18  /* Functions to detect a file type, given a seekable source */
     8.1 --- a/configure.in	Thu Aug 10 06:15:57 2000 +0000
     8.2 +++ b/configure.in	Fri Sep 01 00:45:57 2000 +0000
     8.3 @@ -13,9 +13,9 @@
     8.4  
     8.5  MAJOR_VERSION=1
     8.6  MINOR_VERSION=0
     8.7 -MICRO_VERSION=9
     8.8 -INTERFACE_AGE=0
     8.9 -BINARY_AGE=9
    8.10 +MICRO_VERSION=10
    8.11 +INTERFACE_AGE=1
    8.12 +BINARY_AGE=10
    8.13  VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION
    8.14  
    8.15  AC_SUBST(MAJOR_VERSION)
    8.16 @@ -64,7 +64,7 @@
    8.17  esac
    8.18  
    8.19  dnl Check for SDL
    8.20 -SDL_VERSION=1.1.3
    8.21 +SDL_VERSION=1.1.5
    8.22  AM_PATH_SDL($SDL_VERSION,
    8.23              :,
    8.24  	    AC_MSG_ERROR([*** SDL version $SDL_VERSION not found!])
     9.1 --- a/showimage.c	Thu Aug 10 06:15:57 2000 +0000
     9.2 +++ b/showimage.c	Fri Sep 01 00:45:57 2000 +0000
     9.3 @@ -30,7 +30,7 @@
     9.4  
     9.5  
     9.6  /* Draw a Gimpish background pattern to show transparency in the image */
     9.7 -void draw_background(SDL_Surface *image, SDL_Surface *screen)
     9.8 +void draw_background(SDL_Surface *screen)
     9.9  {
    9.10      Uint8 *dst = screen->pixels;
    9.11      int x, y;
    9.12 @@ -69,7 +69,7 @@
    9.13      }
    9.14  }
    9.15  
    9.16 -main(int argc, char *argv[])
    9.17 +int main(int argc, char *argv[])
    9.18  {
    9.19  	SDL_Surface *screen, *image;
    9.20  	int i, depth;
    9.21 @@ -117,7 +117,7 @@
    9.22  
    9.23  	/* Draw a background pattern if the surface has transparency */
    9.24  	if(image->flags & (SDL_SRCALPHA | SDL_SRCCOLORKEY))
    9.25 -	    draw_background(image, screen);
    9.26 +	    draw_background(screen);
    9.27  
    9.28  	/* Display the image */
    9.29  	SDL_BlitSurface(image, NULL, screen, NULL);