From f735bb053bb944b84c70b117297c7559b8b7c61c Mon Sep 17 00:00:00 2001 From: gewlitys Date: Wed, 16 Jul 2003 00:06:47 +0000 Subject: [PATCH] Fixed overflow bug with 32bpp bilinear,biadapt,biadv scalers git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@1054 8092fc87-c524-0410-9efc-e669fe64eaf9 --- sc2/ChangeLog | 1 + sc2/src/sc2code/libs/graphics/sdl/2xscalers.c | 43 +++++++++++++------ 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/sc2/ChangeLog b/sc2/ChangeLog index a9e8cf78f..35c2941c4 100644 --- a/sc2/ChangeLog +++ b/sc2/ChangeLog @@ -1,4 +1,5 @@ Changes towards version 0.3: +- Fixed overflow problem with 32bpp bilinear,biadapt,biadv scalers -Mika - MixSDL now handles resampling correctly (less cracklings); added cubic interpolation for high quality mode -Mika - Removed the redundant "GameExiting" variable -Michael diff --git a/sc2/src/sc2code/libs/graphics/sdl/2xscalers.c b/sc2/src/sc2code/libs/graphics/sdl/2xscalers.c index a5b84b3d3..de0064cd4 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/2xscalers.c +++ b/sc2/src/sc2code/libs/graphics/sdl/2xscalers.c @@ -186,7 +186,19 @@ Scale_BlendPixels (SDL_PixelFormat* fmt, Uint32 pix1, Uint32 pix2) ) >> 1) & fmt->Gmask) | ((((pix1 & fmt->Bmask) + (pix2 & fmt->Bmask) - ) >> 1) & fmt->Bmask); + ) >> 1) & fmt->Bmask); +} + +// blends two pixels with ratio 50% - 50% (safe for 32bpp surfaces) +__inline__ Uint32 +Scale_BlendPixels_32bpp_safe (SDL_PixelFormat* fmt, Uint32 pix1, Uint32 pix2) +{ + return ((((((pix1 & fmt->Rmask) >> fmt->Rshift) + + ((pix2 & fmt->Rmask) >> fmt->Rshift)) >> 1) << fmt->Rshift) & fmt->Rmask) | + ((((((pix1 & fmt->Gmask) >> fmt->Gshift) + + ((pix2 & fmt->Gmask) >> fmt->Gshift)) >> 1) << fmt->Gshift) & fmt->Gmask) | + ((((((pix1 & fmt->Bmask) >> fmt->Bshift) + + ((pix2 & fmt->Bmask) >> fmt->Bshift)) >> 1) << fmt->Bshift) & fmt->Bmask); } // compare pixels by their RGB @@ -706,6 +718,7 @@ Scale_BiAdaptFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r) #define BIADAPT_GETPIX(p) ( *(Uint32 *)(p) ) #define BIADAPT_SETPIX(p, c) ( *(Uint32 *)(p) = (c) ) #define BIADAPT_BUF Uint32 + #define Scale_BlendPixels Scale_BlendPixels_32bpp_safe { BIADAPT_BUF *src_p = (BIADAPT_BUF *)src->pixels; BIADAPT_BUF *dst_p = (BIADAPT_BUF *)dst->pixels; @@ -899,7 +912,7 @@ Scale_BiAdaptFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r) #undef BIADAPT_GETPIX #undef BIADAPT_SETPIX #undef BIADAPT_BUF - #undef BIADAPT_CLR + #undef Scale_BlendPixels } } @@ -1877,6 +1890,7 @@ Scale_BiAdaptAdvFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r) #define BIADAPT_GETPIX(p) ( *(Uint32 *)(p) ) #define BIADAPT_SETPIX(p, c) ( *(Uint32 *)(p) = (c) ) #define BIADAPT_BUF Uint32 + #define Scale_BlendPixels Scale_BlendPixels_32bpp_safe { BIADAPT_BUF *src_p = (BIADAPT_BUF *)src->pixels; BIADAPT_BUF *dst_p = (BIADAPT_BUF *)dst->pixels; @@ -2324,6 +2338,7 @@ Scale_BiAdaptAdvFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r) #undef BIADAPT_GETPIX #undef BIADAPT_SETPIX #undef BIADAPT_BUF + #undef Scale_BlendPixels } #undef BIADAPT_CMPRGB @@ -2585,18 +2600,18 @@ void Scale_BilinearFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r) fd = bilinear_table[j][3]; *dst_p++ = - (((((p[0] & fmt->Rmask) * fa) + - ((p[1] & fmt->Rmask) * fb) + - ((p[2] & fmt->Rmask) * fc) + - ((p[3] & fmt->Rmask) * fd)) >> 4) & fmt->Rmask) | - (((((p[0] & fmt->Gmask) * fa) + - ((p[1] & fmt->Gmask) * fb) + - ((p[2] & fmt->Gmask) * fc) + - ((p[3] & fmt->Gmask) * fd)) >> 4) & fmt->Gmask) | - (((((p[0] & fmt->Bmask) * fa) + - ((p[1] & fmt->Bmask) * fb) + - ((p[2] & fmt->Bmask) * fc) + - ((p[3] & fmt->Bmask) * fd)) >> 4) & fmt->Bmask); + (((((((p[0] & fmt->Rmask) >> fmt->Rshift) * fa) + + (((p[1] & fmt->Rmask) >> fmt->Rshift) * fb) + + (((p[2] & fmt->Rmask) >> fmt->Rshift) * fc) + + (((p[3] & fmt->Rmask) >> fmt->Rshift) * fd)) >> 4) << fmt->Rshift) & fmt->Rmask) | + (((((((p[0] & fmt->Gmask) >> fmt->Gshift) * fa) + + (((p[1] & fmt->Gmask) >> fmt->Gshift) * fb) + + (((p[2] & fmt->Gmask) >> fmt->Gshift) * fc) + + (((p[3] & fmt->Gmask) >> fmt->Gshift) * fd)) >> 4) << fmt->Gshift) & fmt->Gmask) | + (((((((p[0] & fmt->Bmask) >> fmt->Bshift) * fa) + + (((p[1] & fmt->Bmask) >> fmt->Bshift) * fb) + + (((p[2] & fmt->Bmask) >> fmt->Bshift) * fc) + + (((p[3] & fmt->Bmask) >> fmt->Bshift) * fd)) >> 4) << fmt->Bshift) & fmt->Bmask); if (j & 2) {