From 2c04afce9c35c7832977a407c791dc82828beed5 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 1 Sep 2000 00:45:57 +0000 Subject: [PATCH] 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 | 5 +++++ IMG.c | 19 ++-------------- IMG_pcx.c | 8 +++---- IMG_png.c | 29 ++++++++++++++----------- IMG_tga.c | 16 +++----------- IMG_tif.c | 61 ++++++++++++++-------------------------------------- SDL_image.h | 9 ++------ configure.in | 8 +++---- showimage.c | 6 +++--- 9 files changed, 55 insertions(+), 106 deletions(-) diff --git a/CHANGES b/CHANGES index c68426c0..393c1624 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,10 @@ 1.0.10: +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 Ray Kelm - Fri, 04 Aug 2000 20:58:00 -0400 * Added support for cross-compiling Windows DLL from Linux diff --git a/IMG.c b/IMG.c index 9e7407f4..eaf0d087 100644 --- a/IMG.c +++ b/IMG.c @@ -47,11 +47,6 @@ static struct { { "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) { @@ -127,19 +122,9 @@ SDL_Surface *IMG_LoadTyped_RW(SDL_RWops *src, int freesrc, char *type) } /* 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. + This function is a no-op and only kept for backwards compatibility. */ int IMG_InvertAlpha(int on) { - int old_alpha_value; - - old_alpha_value = IMG_invert_alpha; - IMG_invert_alpha = on; - return(old_alpha_value); + return 1; } - diff --git a/IMG_pcx.c b/IMG_pcx.c index 5faa73d4..1ec0444f 100644 --- a/IMG_pcx.c +++ b/IMG_pcx.c @@ -112,13 +112,11 @@ SDL_Surface *IMG_LoadPCX_RW(SDL_RWops *src) Rmask = 0x000000FF; Gmask = 0x0000FF00; Bmask = 0x00FF0000; - Amask = 0xFF000000; } else { int s = (pcxh.NPlanes == 4) ? 0 : 8; - Rmask = 0xFF000000 >> s; - Gmask = 0x00FF0000 >> s; - Bmask = 0x0000FF00 >> s; - Amask = 0x000000FF >> s; + Rmask = 0xFF0000; + Gmask = 0x00FF00; + Bmask = 0x0000FF; } } surface = SDL_AllocSurface(SDL_SWSURFACE, width, height, diff --git a/IMG_png.c b/IMG_png.c index 9fb3e3d2..cae94482 100644 --- a/IMG_png.c +++ b/IMG_png.c @@ -31,8 +31,6 @@ #ifdef LOAD_PNG -extern int IMG_invert_alpha; - /*============================================================================= File: SDL_png.c Purpose: A PNG loader and saver for the SDL library @@ -158,10 +156,9 @@ SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *src) */ png_set_packing(png_ptr); - /* SDL and PNG have inverted ideas of alpha */ - if ( ! IMG_invert_alpha ) { - png_set_invert_alpha(png_ptr); - } + /* scale greyscale values to the range 0..255 */ + if(color_type == PNG_COLOR_TYPE_GRAY) + png_set_expand(png_ptr); /* For images with a single "transparent colour", set colour key; if more than one index has transparency, use full alpha channel */ @@ -180,8 +177,7 @@ SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *src) ckey = 0; /* actual value will be set later */ } - if ( (color_type == PNG_COLOR_TYPE_GRAY) || - (color_type == PNG_COLOR_TYPE_GRAY_ALPHA) ) + if ( color_type == PNG_COLOR_TYPE_GRAY_ALPHA ) png_set_gray_to_rgb(png_ptr); png_read_update_info(png_ptr, info_ptr); @@ -240,13 +236,22 @@ SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *src) /* Load the palette, if any */ palette = surface->format->palette; - if ( palette && (info_ptr->num_palette > 0) ) { + if ( palette ) { + if(color_type == PNG_COLOR_TYPE_GRAY) { + palette->ncolors = 256; + for(i = 0; i < 256; i++) { + palette->colors[i].r = i; + palette->colors[i].g = i; + palette->colors[i].b = i; + } + } else if (info_ptr->num_palette > 0 ) { palette->ncolors = info_ptr->num_palette; for( i=0; inum_palette; ++i ) { - palette->colors[i].b =(Uint8)info_ptr->palette[i].blue; - palette->colors[i].g =(Uint8)info_ptr->palette[i].green; - palette->colors[i].r =(Uint8)info_ptr->palette[i].red; + palette->colors[i].b = info_ptr->palette[i].blue; + palette->colors[i].g = info_ptr->palette[i].green; + palette->colors[i].r = info_ptr->palette[i].red; } + } } done: /* Clean up and return */ diff --git a/IMG_tga.c b/IMG_tga.c index 2a23e9c5..d9c2a611 100644 --- a/IMG_tga.c +++ b/IMG_tga.c @@ -38,10 +38,9 @@ * * 2000-06-10 Mattias Engdegård : initial version * 2000-06-26 Mattias Engdegård : read greyscale TGAs + * 2000-08-09 Mattias Engdegård : alpha inversion removed */ -extern int IMG_invert_alpha; - struct TGAheader { Uint8 infolen; /* length of info field */ Uint8 has_cmap; /* 1 if image has colormap, 0 otherwise */ @@ -143,20 +142,19 @@ SDL_Surface *IMG_LoadTGA_RW(SDL_RWops *src) } bpp = (hdr.pixel_bits + 7) >> 3; + rmask = gmask = bmask = amask = 0; switch(hdr.pixel_bits) { case 8: if(!indexed) { unsupported(); return NULL; } - rmask = gmask = bmask = amask = 0; break; case 15: case 16: /* 15 and 16bpp both seem to use 5 bits/plane. The extra alpha bit is ignored for now. */ - amask = 0; rmask = 0x7c00; gmask = 0x03e0; bmask = 0x001f; @@ -246,7 +244,7 @@ SDL_Surface *IMG_LoadTGA_RW(SDL_RWops *src) if(hdr.flags & TGA_ORIGIN_UPPER) { lstep = img->pitch; - dst = (Uint8 *)img->pixels; + dst = img->pixels; } else { lstep = -img->pitch; dst = (Uint8 *)img->pixels + (h - 1) * img->pitch; @@ -302,16 +300,8 @@ SDL_Surface *IMG_LoadTGA_RW(SDL_RWops *src) for(x = 0; x < w; x++) p[x] = SDL_Swap16(p[x]); } - if(alpha && !IMG_invert_alpha) { - /* TGA stores alpha traditionally (0 transparent, 0xff opaque) */ - int x; - for(x = 0; x < w; x++) - dst[x * 4 + 3] ^= 0xff; - } dst += lstep; } - if(alpha) - SDL_SetAlpha(img, SDL_SRCALPHA, 0); return img; error: diff --git a/IMG_tif.c b/IMG_tif.c index 12a9c8b7..f5057d8a 100644 --- a/IMG_tif.c +++ b/IMG_tif.c @@ -22,6 +22,9 @@ slouken@devolution.com 5/29/2000: TIFF loader written. Mark Baker (mbaker@0x7a69.net) + 2000-07-28: Fixed two off-by one bugs in reversal loop and made it work on + big-endian machines (Mattias) + 2000-08-09: Removed alpha inversion (Mattias) */ @@ -36,7 +39,6 @@ #include - /* * These are the thunking routine to use the SDL_RWops* routines from * libtiff's internals. @@ -109,11 +111,9 @@ SDL_Surface* IMG_LoadTIF_RW(SDL_RWops* src) TIFF* tiff; SDL_Surface* surface = NULL; Uint32 img_width, img_height; - Uint32 Rmask, Gmask, Bmask, Amask; + Uint32 Rmask, Gmask, Bmask, Amask, mask; Uint32 x, y; Uint32 half; - Uint32 tl_coord, bl_coord; - Uint32 tl_pixel, bl_pixel; /* turn off memory mapped access with the m flag */ @@ -126,21 +126,10 @@ SDL_Surface* IMG_LoadTIF_RW(SDL_RWops* src) TIFFGetField(tiff, TIFFTAG_IMAGEWIDTH, &img_width); TIFFGetField(tiff, TIFFTAG_IMAGELENGTH, &img_height); - if (SDL_BYTEORDER == SDL_LIL_ENDIAN) - { - Rmask = 0x000000FF; - Gmask = 0x0000FF00; - Bmask = 0x00FF0000; - Amask = 0xFF000000; - } - else - { - Rmask = 0xFF000000; - Gmask = 0x00FF0000; - Bmask = 0x0000FF00; - Amask = 0x000000FF; - } - + Rmask = 0x000000FF; + Gmask = 0x0000FF00; + Bmask = 0x00FF0000; + Amask = 0xFF000000; surface = SDL_AllocSurface(SDL_SWSURFACE, img_width, img_height, 32, Rmask, Gmask, Bmask, Amask); if(!surface) @@ -149,36 +138,18 @@ SDL_Surface* IMG_LoadTIF_RW(SDL_RWops* src) if(!TIFFReadRGBAImage(tiff, img_width, img_height, surface->pixels, 0)) return NULL; - /* - * For this to make any sense, a little information is needed. - * Firstly, SDL uses more or less the opposite value for alpha as - * libtiff, so we need to invert the alpha channel of each pixel. - * To do this, I'm just xor it with the alpha mask. - * - * Secondly, libtiff loads the image more or less inverted. - * So the top left of the image ends up being the bottom left. - * To correct for this, we swap the pixels as we're inverting the - * alpha channel - */ - - // We only need to loop 1/2 the height, because we're swapping values. + /* libtiff loads the image upside-down, flip it back */ half = img_height / 2; - - for(y = 0; y <= half; y++) + for(y = 0; y < half; y++) { + Uint32 *top = (Uint32 *)surface->pixels + y * surface->pitch/4; + Uint32 *bot = (Uint32 *)surface->pixels + + (img_height - y - 1) * surface->pitch/4; for(x = 0; x < img_width; x++) { - tl_coord = y * img_width + x; - bl_coord = (img_height - y - 1) * img_width + x; - - /* Invert the value of the alpha channel, while copying the pixel */ - tl_pixel = *((Uint32*)surface->pixels + tl_coord) ^ Amask; - bl_pixel = *((Uint32*)surface->pixels + bl_coord) ^ Amask; - - /* Now invert the location of the pixel relative to the image */ - *((Uint32*)surface->pixels + bl_coord) = tl_pixel; - *((Uint32*)surface->pixels + tl_coord) = bl_pixel; - + Uint32 tmp = top[x]; + top[x] = bot[x]; + bot[x] = tmp; } } TIFFClose(tiff); diff --git a/SDL_image.h b/SDL_image.h index dadd1c69..ee147119 100644 --- a/SDL_image.h +++ b/SDL_image.h @@ -50,13 +50,8 @@ extern DECLSPEC SDL_Surface *IMG_Load(const char *file); extern DECLSPEC SDL_Surface *IMG_Load_RW(SDL_RWops *src, int freesrc); /* 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. - */ + This function is now a no-op, and only provided for backwards compatibility. +*/ extern DECLSPEC int IMG_InvertAlpha(int on); /* Functions to detect a file type, given a seekable source */ diff --git a/configure.in b/configure.in index baf2d9ec..9542f285 100644 --- a/configure.in +++ b/configure.in @@ -13,9 +13,9 @@ dnl Set various version strings - taken gratefully from the GTk sources MAJOR_VERSION=1 MINOR_VERSION=0 -MICRO_VERSION=9 -INTERFACE_AGE=0 -BINARY_AGE=9 +MICRO_VERSION=10 +INTERFACE_AGE=1 +BINARY_AGE=10 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION AC_SUBST(MAJOR_VERSION) @@ -64,7 +64,7 @@ case "$target" in esac dnl Check for SDL -SDL_VERSION=1.1.3 +SDL_VERSION=1.1.5 AM_PATH_SDL($SDL_VERSION, :, AC_MSG_ERROR([*** SDL version $SDL_VERSION not found!]) diff --git a/showimage.c b/showimage.c index 134fc0a7..a41fef19 100644 --- a/showimage.c +++ b/showimage.c @@ -30,7 +30,7 @@ /* Draw a Gimpish background pattern to show transparency in the image */ -void draw_background(SDL_Surface *image, SDL_Surface *screen) +void draw_background(SDL_Surface *screen) { Uint8 *dst = screen->pixels; int x, y; @@ -69,7 +69,7 @@ void draw_background(SDL_Surface *image, SDL_Surface *screen) } } -main(int argc, char *argv[]) +int main(int argc, char *argv[]) { SDL_Surface *screen, *image; int i, depth; @@ -117,7 +117,7 @@ main(int argc, char *argv[]) /* Draw a background pattern if the surface has transparency */ if(image->flags & (SDL_SRCALPHA | SDL_SRCCOLORKEY)) - draw_background(image, screen); + draw_background(screen); /* Display the image */ SDL_BlitSurface(image, NULL, screen, NULL);