Fixed and optimized 2- and 4-pixel blends in biadapt, biadv (hopefully fixes #421); also fixed a nasty bug in biadv

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@1056 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
avolkov
2003-07-16 07:46:24 +00:00
parent b598140f88
commit 405ec79939
+151 -199
View File
@@ -174,31 +174,52 @@ Scale_ExpandRect (SDL_Rect* rect, int expansion, SDL_Rect* limits)
rect->h = limits->h - rect->y; rect->h = limits->h - rect->y;
} }
typedef struct _BLEND_PARAMS
{
int shift_bits;
Uint32 low_mask;
Uint32 high_mask;
} BLEND_PARAMS;
// blends two pixels with ratio 50% - 50% // blends two pixels with ratio 50% - 50%
__inline__ Uint32 __inline__ Uint32
Scale_BlendPixels (SDL_PixelFormat* fmt, Uint32 pix1, Uint32 pix2) Scale_BlendPixels_2 (BLEND_PARAMS bp, Uint32 pix1, Uint32 pix2)
{ {
return ((((pix1 & fmt->Rmask) + return (pix1 & pix2 & bp.low_mask) +
(pix2 & fmt->Rmask) ((pix1 & bp.high_mask) >> 1) + ((pix2 & bp.high_mask) >> 1);
) >> 1) & fmt->Rmask) |
((((pix1 & fmt->Gmask) +
(pix2 & fmt->Gmask)
) >> 1) & fmt->Gmask) |
((((pix1 & fmt->Bmask) +
(pix2 & fmt->Bmask)
) >> 1) & fmt->Bmask);
} }
// blends two pixels with ratio 50% - 50% (safe for 32bpp surfaces) // blends four pixels with equal weight
__inline__ Uint32 __inline__ Uint32
Scale_BlendPixels_32bpp_safe (SDL_PixelFormat* fmt, Uint32 pix1, Uint32 pix2) Scale_BlendPixels_4 (BLEND_PARAMS bp, Uint32 pix1, Uint32 pix2,
Uint32 pix3, Uint32 pix4)
{ {
return ((((((pix1 & fmt->Rmask) >> fmt->Rshift) + return ((((pix1 & bp.low_mask) + (pix2 & bp.low_mask) +
((pix2 & fmt->Rmask) >> fmt->Rshift)) >> 1) << fmt->Rshift) & fmt->Rmask) | (pix3 & bp.low_mask) + (pix4 & bp.low_mask)
((((((pix1 & fmt->Gmask) >> fmt->Gshift) + ) >> 2) & bp.low_mask) +
((pix2 & fmt->Gmask) >> fmt->Gshift)) >> 1) << fmt->Gshift) & fmt->Gmask) | ((pix1 & bp.high_mask) >> 2) + ((pix2 & bp.high_mask) >> 2) +
((((((pix1 & fmt->Bmask) >> fmt->Bshift) + ((pix3 & bp.high_mask) >> 2) + ((pix4 & bp.high_mask) >> 2);
((pix2 & fmt->Bmask) >> fmt->Bshift)) >> 1) << fmt->Bshift) & fmt->Bmask); }
// compute optimized masks for N-pixel blending
// N must be a power of 2 and cannot be more than 2^(B/2),
// where B is the number of bits/channel
__inline__ void
Scale_CalcBlendMasks (SDL_PixelFormat* fmt, unsigned int npixels,
BLEND_PARAMS* pbp)
{
// mask-on the bits used for the low-part
int mask = npixels - 1;
// this just does an integer log-base-2(npixels)
for (pbp->shift_bits = 0, npixels >>= 1; npixels != 0; npixels >>= 1)
pbp->shift_bits++;
pbp->low_mask = (mask << fmt->Rshift) |
(mask << fmt->Gshift) |
(mask << fmt->Bshift);
pbp->high_mask = (fmt->Rmask | fmt->Gmask | fmt->Bmask) ^ pbp->low_mask;
} }
// compare pixels by their RGB // compare pixels by their RGB
@@ -301,6 +322,7 @@ Scale_BiAdaptFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
SDL_Rect *region = r; SDL_Rect *region = r;
SDL_Rect limits; SDL_Rect limits;
SDL_PixelFormat *fmt = dst->format; SDL_PixelFormat *fmt = dst->format;
BLEND_PARAMS blend2, blend4;
// expand updated region if necessary // expand updated region if necessary
// pixels neighbooring the updated region may // pixels neighbooring the updated region may
@@ -316,6 +338,10 @@ Scale_BiAdaptFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
dsrc = w - region->w; dsrc = w - region->w;
ddst = (dw - region->w) * 2; ddst = (dw - region->w) * 2;
// precompute the blending masks and shifts
Scale_CalcBlendMasks (fmt, 2, &blend2);
Scale_CalcBlendMasks (fmt, 4, &blend4);
switch (fmt->BytesPerPixel) switch (fmt->BytesPerPixel)
{ {
case 2: // 16bpp scaling case 2: // 16bpp scaling
@@ -347,8 +373,8 @@ Scale_BiAdaptFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
if (pixval_tl == pixval_bl) if (pixval_tl == pixval_bl)
BIADAPT_SETPIX (dst_p + dw, pixval_tl); BIADAPT_SETPIX (dst_p + dw, pixval_tl);
else else
BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels ( BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels_2 (
fmt, pixval_tl, pixval_bl) blend2, pixval_tl, pixval_bl)
); );
} }
else else
@@ -373,8 +399,8 @@ Scale_BiAdaptFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
if (pixval_tl == pixval_tr) if (pixval_tl == pixval_tr)
BIADAPT_SETPIX (dst_p, pixval_tr); BIADAPT_SETPIX (dst_p, pixval_tr);
else else
BIADAPT_SETPIX (dst_p, Scale_BlendPixels ( BIADAPT_SETPIX (dst_p, Scale_BlendPixels_2 (
fmt, pixval_tl, pixval_tr) blend2, pixval_tl, pixval_tr)
); );
if (y + 1 >= h) if (y + 1 >= h)
@@ -473,7 +499,7 @@ Scale_BiAdaptFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
BIADAPT_SETPIX (dst_p + dw, pixval_tl); BIADAPT_SETPIX (dst_p + dw, pixval_tl);
else else
BIADAPT_SETPIX (dst_p + dw, BIADAPT_SETPIX (dst_p + dw,
Scale_BlendPixels (fmt, pixval_tl, Scale_BlendPixels_2 (blend2, pixval_tl,
pixval_tr)); pixval_tr));
} }
else if (pixval_tl == pixval_br) else if (pixval_tl == pixval_br)
@@ -491,22 +517,9 @@ Scale_BiAdaptFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
else else
{ {
// blend all 4 // blend all 4
BIADAPT_SETPIX (dst_p + dw, BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels_4 (
((((pixval_tl & fmt->Rmask) + blend4, pixval_tl, pixval_bl, pixval_tr, pixval_br
(pixval_bl & fmt->Rmask) + ));
(pixval_tr & fmt->Rmask) +
(pixval_br & fmt->Rmask)
) >> 2) & fmt->Rmask) |
((((pixval_tl & fmt->Gmask) +
(pixval_bl & fmt->Gmask) +
(pixval_tr & fmt->Gmask) +
(pixval_br & fmt->Gmask)
) >> 2) & fmt->Gmask) |
((((pixval_tl & fmt->Bmask) +
(pixval_bl & fmt->Bmask) +
(pixval_tr & fmt->Bmask) +
(pixval_br & fmt->Bmask)
) >> 2) & fmt->Bmask));
} }
} }
} }
@@ -545,8 +558,8 @@ Scale_BiAdaptFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
if (pixval_tl == pixval_bl) if (pixval_tl == pixval_bl)
BIADAPT_SETPIX (dst_p + dw, pixval_tl); BIADAPT_SETPIX (dst_p + dw, pixval_tl);
else else
BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels ( BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels_2 (
fmt, pixval_tl, pixval_bl) blend2, pixval_tl, pixval_bl)
); );
} }
else else
@@ -571,8 +584,8 @@ Scale_BiAdaptFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
if (pixval_tl == pixval_tr) if (pixval_tl == pixval_tr)
BIADAPT_SETPIX (dst_p, pixval_tr); BIADAPT_SETPIX (dst_p, pixval_tr);
else else
BIADAPT_SETPIX (dst_p, Scale_BlendPixels ( BIADAPT_SETPIX (dst_p, Scale_BlendPixels_2 (
fmt, pixval_tl, pixval_tr) blend2, pixval_tl, pixval_tr)
); );
if (y + 1 >= h) if (y + 1 >= h)
@@ -671,7 +684,7 @@ Scale_BiAdaptFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
BIADAPT_SETPIX (dst_p + dw, pixval_tl); BIADAPT_SETPIX (dst_p + dw, pixval_tl);
else else
BIADAPT_SETPIX (dst_p + dw, BIADAPT_SETPIX (dst_p + dw,
Scale_BlendPixels (fmt, pixval_tl, Scale_BlendPixels_2 (blend2, pixval_tl,
pixval_tr)); pixval_tr));
} }
else if (pixval_tl == pixval_br) else if (pixval_tl == pixval_br)
@@ -689,22 +702,9 @@ Scale_BiAdaptFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
else else
{ {
// blend all 4 // blend all 4
BIADAPT_SETPIX (dst_p + dw, BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels_4 (
((((pixval_tl & fmt->Rmask) + blend4, pixval_tl, pixval_bl, pixval_tr, pixval_br
(pixval_bl & fmt->Rmask) + ));
(pixval_tr & fmt->Rmask) +
(pixval_br & fmt->Rmask)
) >> 2) & fmt->Rmask) |
((((pixval_tl & fmt->Gmask) +
(pixval_bl & fmt->Gmask) +
(pixval_tr & fmt->Gmask) +
(pixval_br & fmt->Gmask)
) >> 2) & fmt->Gmask) |
((((pixval_tl & fmt->Bmask) +
(pixval_bl & fmt->Bmask) +
(pixval_tr & fmt->Bmask) +
(pixval_br & fmt->Bmask)
) >> 2) & fmt->Bmask));
} }
} }
} }
@@ -718,7 +718,6 @@ Scale_BiAdaptFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
#define BIADAPT_GETPIX(p) ( *(Uint32 *)(p) ) #define BIADAPT_GETPIX(p) ( *(Uint32 *)(p) )
#define BIADAPT_SETPIX(p, c) ( *(Uint32 *)(p) = (c) ) #define BIADAPT_SETPIX(p, c) ( *(Uint32 *)(p) = (c) )
#define BIADAPT_BUF Uint32 #define BIADAPT_BUF Uint32
#define Scale_BlendPixels Scale_BlendPixels_32bpp_safe
{ {
BIADAPT_BUF *src_p = (BIADAPT_BUF *)src->pixels; BIADAPT_BUF *src_p = (BIADAPT_BUF *)src->pixels;
BIADAPT_BUF *dst_p = (BIADAPT_BUF *)dst->pixels; BIADAPT_BUF *dst_p = (BIADAPT_BUF *)dst->pixels;
@@ -744,8 +743,8 @@ Scale_BiAdaptFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
if (pixval_tl == pixval_bl) if (pixval_tl == pixval_bl)
BIADAPT_SETPIX (dst_p + dw, pixval_tl); BIADAPT_SETPIX (dst_p + dw, pixval_tl);
else else
BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels ( BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels_2 (
fmt, pixval_tl, pixval_bl) blend2, pixval_tl, pixval_bl)
); );
} }
else else
@@ -770,8 +769,8 @@ Scale_BiAdaptFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
if (pixval_tl == pixval_tr) if (pixval_tl == pixval_tr)
BIADAPT_SETPIX (dst_p, pixval_tr); BIADAPT_SETPIX (dst_p, pixval_tr);
else else
BIADAPT_SETPIX (dst_p, Scale_BlendPixels ( BIADAPT_SETPIX (dst_p, Scale_BlendPixels_2 (
fmt, pixval_tl, pixval_tr) blend2, pixval_tl, pixval_tr)
); );
if (y + 1 >= h) if (y + 1 >= h)
@@ -870,7 +869,7 @@ Scale_BiAdaptFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
BIADAPT_SETPIX (dst_p + dw, pixval_tl); BIADAPT_SETPIX (dst_p + dw, pixval_tl);
else else
BIADAPT_SETPIX (dst_p + dw, BIADAPT_SETPIX (dst_p + dw,
Scale_BlendPixels (fmt, pixval_tl, Scale_BlendPixels_2 (blend2, pixval_tl,
pixval_tr)); pixval_tr));
} }
else if (pixval_tl == pixval_br) else if (pixval_tl == pixval_br)
@@ -888,22 +887,9 @@ Scale_BiAdaptFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
else else
{ {
// blend all 4 // blend all 4
BIADAPT_SETPIX (dst_p + dw, BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels_4 (
((((pixval_tl & fmt->Rmask) + blend4, pixval_tl, pixval_bl, pixval_tr, pixval_br
(pixval_bl & fmt->Rmask) + ));
(pixval_tr & fmt->Rmask) +
(pixval_br & fmt->Rmask)
) >> 2) & fmt->Rmask) |
((((pixval_tl & fmt->Gmask) +
(pixval_bl & fmt->Gmask) +
(pixval_tr & fmt->Gmask) +
(pixval_br & fmt->Gmask)
) >> 2) & fmt->Gmask) |
((((pixval_tl & fmt->Bmask) +
(pixval_bl & fmt->Bmask) +
(pixval_tr & fmt->Bmask) +
(pixval_br & fmt->Bmask)
) >> 2) & fmt->Bmask));
} }
} }
} }
@@ -912,7 +898,6 @@ Scale_BiAdaptFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
#undef BIADAPT_GETPIX #undef BIADAPT_GETPIX
#undef BIADAPT_SETPIX #undef BIADAPT_SETPIX
#undef BIADAPT_BUF #undef BIADAPT_BUF
#undef Scale_BlendPixels
} }
} }
@@ -928,6 +913,7 @@ Scale_BiAdaptAdvFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
SDL_Rect *region = r; SDL_Rect *region = r;
SDL_Rect limits; SDL_Rect limits;
SDL_PixelFormat *fmt = dst->format; SDL_PixelFormat *fmt = dst->format;
BLEND_PARAMS blend2, blend4;
// for clarity purposes, the 'pixels' array here is transposed // for clarity purposes, the 'pixels' array here is transposed
Uint32 pixels[4][4]; Uint32 pixels[4][4];
static int resolve_coord[][2] = static int resolve_coord[][2] =
@@ -980,6 +966,10 @@ Scale_BiAdaptAdvFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
dsrc = w - region->w; dsrc = w - region->w;
ddst = (dw - region->w) * 2; ddst = (dw - region->w) * 2;
// precompute the blending masks and shifts
Scale_CalcBlendMasks (fmt, 2, &blend2);
Scale_CalcBlendMasks (fmt, 4, &blend4);
switch (fmt->BytesPerPixel) switch (fmt->BytesPerPixel)
{ {
case 2: // 16bpp scaling case 2: // 16bpp scaling
@@ -1049,7 +1039,7 @@ Scale_BiAdaptAdvFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
if (cmatch == 3) if (cmatch == 3)
{ {
if (y + 1 < h || x + 1 < w) if (y + 1 >= h || x + 1 >= w)
{ {
// last pixel in row/column and nearest // last pixel in row/column and nearest
// neighboor is identical // neighboor is identical
@@ -1185,8 +1175,8 @@ Scale_BiAdaptAdvFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
{ {
if (BIADAPT_CMPYUV (PIX (0, 0), PIX (0, 1)) <= BIADAPT_YUVLOW) if (BIADAPT_CMPYUV (PIX (0, 0), PIX (0, 1)) <= BIADAPT_YUVLOW)
{ {
BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels ( BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels_2 (
fmt, PIX (0, 0), PIX (0, 1)) blend2, PIX (0, 0), PIX (0, 1))
); );
cmatch |= 1; cmatch |= 1;
} }
@@ -1243,8 +1233,8 @@ Scale_BiAdaptAdvFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
BIADAPT_SETPIX (dst_p + dw, PIX (0, 1)); BIADAPT_SETPIX (dst_p + dw, PIX (0, 1));
} }
else else
BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels ( BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels_2 (
fmt, PIX (0, 0), PIX (0, 1)) blend2, PIX (0, 0), PIX (0, 1))
); );
} }
@@ -1255,8 +1245,8 @@ Scale_BiAdaptAdvFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
{ {
if (BIADAPT_CMPYUV (PIX (0, 0), PIX (1, 0)) <= BIADAPT_YUVLOW) if (BIADAPT_CMPYUV (PIX (0, 0), PIX (1, 0)) <= BIADAPT_YUVLOW)
{ {
BIADAPT_SETPIX (dst_p, Scale_BlendPixels ( BIADAPT_SETPIX (dst_p, Scale_BlendPixels_2 (
fmt, PIX (0, 0), PIX (1, 0)) blend2, PIX (0, 0), PIX (1, 0))
); );
cmatch |= 2; cmatch |= 2;
} }
@@ -1314,8 +1304,8 @@ Scale_BiAdaptAdvFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
BIADAPT_SETPIX (dst_p, PIX (1, 0)); BIADAPT_SETPIX (dst_p, PIX (1, 0));
} }
else else
BIADAPT_SETPIX (dst_p, Scale_BlendPixels ( BIADAPT_SETPIX (dst_p, Scale_BlendPixels_2 (
fmt, PIX (0, 0), PIX (1, 0)) blend2, PIX (0, 0), PIX (1, 0))
); );
} }
@@ -1348,7 +1338,7 @@ Scale_BiAdaptAdvFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
else if (cr > cl) else if (cr > cl)
clr = PIX (0, 0); clr = PIX (0, 0);
else else
clr = Scale_BlendPixels (fmt, clr = Scale_BlendPixels_2 (blend2,
PIX (0, 0), PIX (1, 0)); PIX (0, 0), PIX (1, 0));
BIADAPT_SETPIX (dst_p + dw, clr); BIADAPT_SETPIX (dst_p + dw, clr);
@@ -1359,15 +1349,15 @@ Scale_BiAdaptAdvFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
|| (BIADAPT_CMPYUV_LOW (PIX (1, 0), PIX (0, 1)) || (BIADAPT_CMPYUV_LOW (PIX (1, 0), PIX (0, 1))
&& BIADAPT_CMPYUV_LOW (PIX (1, 0), PIX (1, 1)))) && BIADAPT_CMPYUV_LOW (PIX (1, 0), PIX (1, 1))))
{ {
BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels ( BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels_2 (
fmt, PIX (0, 1), PIX (1, 0)) blend2, PIX (0, 1), PIX (1, 0))
); );
continue; continue;
} }
else if (cmatch && BIADAPT_CMPYUV_LOW (PIX (0, 0), PIX (1, 1))) else if (cmatch && BIADAPT_CMPYUV_LOW (PIX (0, 0), PIX (1, 1)))
{ {
BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels ( BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels_2 (
fmt, PIX (0, 0), PIX (1, 1)) blend2, PIX (0, 0), PIX (1, 1))
); );
continue; continue;
} }
@@ -1379,14 +1369,14 @@ Scale_BiAdaptAdvFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
if (Scale_GetPixY (fmt, PIX (0, 0)) if (Scale_GetPixY (fmt, PIX (0, 0))
> Scale_GetPixY (fmt, PIX (1, 0))) > Scale_GetPixY (fmt, PIX (1, 0)))
{ {
BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels ( BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels_2 (
fmt, PIX (0, 0), PIX (1, 1)) blend2, PIX (0, 0), PIX (1, 1))
); );
} }
else else
{ {
BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels ( BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels_2 (
fmt, PIX (1, 0), PIX (0, 1)) blend2, PIX (1, 0), PIX (0, 1))
); );
} }
} }
@@ -1394,37 +1384,25 @@ Scale_BiAdaptAdvFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
{ {
// main diagonal is same color // main diagonal is same color
// use its value // use its value
BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels ( BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels_2 (
fmt, PIX (0, 0), PIX (1, 1)) blend2, PIX (0, 0), PIX (1, 1))
); );
} }
else if (BIADAPT_CMPYUV_HIGH (PIX (1, 0), PIX (0, 1))) else if (BIADAPT_CMPYUV_HIGH (PIX (1, 0), PIX (0, 1)))
{ {
// 2nd diagonal is same color // 2nd diagonal is same color
// use its value // use its value
BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels ( BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels_2 (
fmt, PIX (1, 0), PIX (0, 1)) blend2, PIX (1, 0), PIX (0, 1))
); );
} }
else else
{ {
// blend all 4 // blend all 4
BIADAPT_SETPIX (dst_p + dw, BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels_4 (
((((PIX (0, 0) & fmt->Rmask) + blend4, PIX (0, 0), PIX (0, 1),
(PIX (0, 1) & fmt->Rmask) + PIX (1, 0), PIX (1, 1)
(PIX (1, 0) & fmt->Rmask) + ));
(PIX (1, 1) & fmt->Rmask)
) >> 2) & fmt->Rmask) |
((((PIX (0, 0) & fmt->Gmask) +
(PIX (0, 1) & fmt->Gmask) +
(PIX (1, 0) & fmt->Gmask) +
(PIX (1, 1) & fmt->Gmask)
) >> 2) & fmt->Gmask) |
((((PIX (0, 0) & fmt->Bmask) +
(PIX (0, 1) & fmt->Bmask) +
(PIX (1, 0) & fmt->Bmask) +
(PIX (1, 1) & fmt->Bmask)
) >> 2) & fmt->Bmask));
} }
} }
} }
@@ -1501,7 +1479,7 @@ Scale_BiAdaptAdvFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
if (cmatch == 3) if (cmatch == 3)
{ {
if (y + 1 < h || x + 1 < w) if (y + 1 >= h || x + 1 >= w)
{ {
// last pixel in row/column and nearest // last pixel in row/column and nearest
// neighboor is identical // neighboor is identical
@@ -1637,8 +1615,8 @@ Scale_BiAdaptAdvFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
{ {
if (BIADAPT_CMPYUV (PIX (0, 0), PIX (0, 1)) <= BIADAPT_YUVLOW) if (BIADAPT_CMPYUV (PIX (0, 0), PIX (0, 1)) <= BIADAPT_YUVLOW)
{ {
BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels ( BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels_2 (
fmt, PIX (0, 0), PIX (0, 1)) blend2, PIX (0, 0), PIX (0, 1))
); );
cmatch |= 1; cmatch |= 1;
} }
@@ -1695,8 +1673,8 @@ Scale_BiAdaptAdvFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
BIADAPT_SETPIX (dst_p + dw, PIX (0, 1)); BIADAPT_SETPIX (dst_p + dw, PIX (0, 1));
} }
else else
BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels ( BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels_2 (
fmt, PIX (0, 0), PIX (0, 1)) blend2, PIX (0, 0), PIX (0, 1))
); );
} }
@@ -1707,8 +1685,8 @@ Scale_BiAdaptAdvFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
{ {
if (BIADAPT_CMPYUV (PIX (0, 0), PIX (1, 0)) <= BIADAPT_YUVLOW) if (BIADAPT_CMPYUV (PIX (0, 0), PIX (1, 0)) <= BIADAPT_YUVLOW)
{ {
BIADAPT_SETPIX (dst_p, Scale_BlendPixels ( BIADAPT_SETPIX (dst_p, Scale_BlendPixels_2 (
fmt, PIX (0, 0), PIX (1, 0)) blend2, PIX (0, 0), PIX (1, 0))
); );
cmatch |= 2; cmatch |= 2;
} }
@@ -1766,8 +1744,8 @@ Scale_BiAdaptAdvFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
BIADAPT_SETPIX (dst_p, PIX (1, 0)); BIADAPT_SETPIX (dst_p, PIX (1, 0));
} }
else else
BIADAPT_SETPIX (dst_p, Scale_BlendPixels ( BIADAPT_SETPIX (dst_p, Scale_BlendPixels_2 (
fmt, PIX (0, 0), PIX (1, 0)) blend2, PIX (0, 0), PIX (1, 0))
); );
} }
@@ -1800,7 +1778,7 @@ Scale_BiAdaptAdvFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
else if (cr > cl) else if (cr > cl)
clr = PIX (0, 0); clr = PIX (0, 0);
else else
clr = Scale_BlendPixels (fmt, clr = Scale_BlendPixels_2 (blend2,
PIX (0, 0), PIX (1, 0)); PIX (0, 0), PIX (1, 0));
BIADAPT_SETPIX (dst_p + dw, clr); BIADAPT_SETPIX (dst_p + dw, clr);
@@ -1811,15 +1789,15 @@ Scale_BiAdaptAdvFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
|| (BIADAPT_CMPYUV_LOW (PIX (1, 0), PIX (0, 1)) || (BIADAPT_CMPYUV_LOW (PIX (1, 0), PIX (0, 1))
&& BIADAPT_CMPYUV_LOW (PIX (1, 0), PIX (1, 1)))) && BIADAPT_CMPYUV_LOW (PIX (1, 0), PIX (1, 1))))
{ {
BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels ( BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels_2 (
fmt, PIX (0, 1), PIX (1, 0)) blend2, PIX (0, 1), PIX (1, 0))
); );
continue; continue;
} }
else if (cmatch && BIADAPT_CMPYUV_LOW (PIX (0, 0), PIX (1, 1))) else if (cmatch && BIADAPT_CMPYUV_LOW (PIX (0, 0), PIX (1, 1)))
{ {
BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels ( BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels_2 (
fmt, PIX (0, 0), PIX (1, 1)) blend2, PIX (0, 0), PIX (1, 1))
); );
continue; continue;
} }
@@ -1831,14 +1809,14 @@ Scale_BiAdaptAdvFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
if (Scale_GetPixY (fmt, PIX (0, 0)) if (Scale_GetPixY (fmt, PIX (0, 0))
> Scale_GetPixY (fmt, PIX (1, 0))) > Scale_GetPixY (fmt, PIX (1, 0)))
{ {
BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels ( BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels_2 (
fmt, PIX (0, 0), PIX (1, 1)) blend2, PIX (0, 0), PIX (1, 1))
); );
} }
else else
{ {
BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels ( BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels_2 (
fmt, PIX (1, 0), PIX (0, 1)) blend2, PIX (1, 0), PIX (0, 1))
); );
} }
} }
@@ -1846,37 +1824,25 @@ Scale_BiAdaptAdvFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
{ {
// main diagonal is same color // main diagonal is same color
// use its value // use its value
BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels ( BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels_2 (
fmt, PIX (0, 0), PIX (1, 1)) blend2, PIX (0, 0), PIX (1, 1))
); );
} }
else if (BIADAPT_CMPYUV_HIGH (PIX (1, 0), PIX (0, 1))) else if (BIADAPT_CMPYUV_HIGH (PIX (1, 0), PIX (0, 1)))
{ {
// 2nd diagonal is same color // 2nd diagonal is same color
// use its value // use its value
BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels ( BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels_2 (
fmt, PIX (1, 0), PIX (0, 1)) blend2, PIX (1, 0), PIX (0, 1))
); );
} }
else else
{ {
// blend all 4 // blend all 4
BIADAPT_SETPIX (dst_p + dw, BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels_4 (
((((PIX (0, 0) & fmt->Rmask) + blend4, PIX (0, 0), PIX (0, 1),
(PIX (0, 1) & fmt->Rmask) + PIX (1, 0), PIX (1, 1)
(PIX (1, 0) & fmt->Rmask) + ));
(PIX (1, 1) & fmt->Rmask)
) >> 2) & fmt->Rmask) |
((((PIX (0, 0) & fmt->Gmask) +
(PIX (0, 1) & fmt->Gmask) +
(PIX (1, 0) & fmt->Gmask) +
(PIX (1, 1) & fmt->Gmask)
) >> 2) & fmt->Gmask) |
((((PIX (0, 0) & fmt->Bmask) +
(PIX (0, 1) & fmt->Bmask) +
(PIX (1, 0) & fmt->Bmask) +
(PIX (1, 1) & fmt->Bmask)
) >> 2) & fmt->Bmask));
} }
} }
} }
@@ -1890,7 +1856,6 @@ Scale_BiAdaptAdvFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
#define BIADAPT_GETPIX(p) ( *(Uint32 *)(p) ) #define BIADAPT_GETPIX(p) ( *(Uint32 *)(p) )
#define BIADAPT_SETPIX(p, c) ( *(Uint32 *)(p) = (c) ) #define BIADAPT_SETPIX(p, c) ( *(Uint32 *)(p) = (c) )
#define BIADAPT_BUF Uint32 #define BIADAPT_BUF Uint32
#define Scale_BlendPixels Scale_BlendPixels_32bpp_safe
{ {
BIADAPT_BUF *src_p = (BIADAPT_BUF *)src->pixels; BIADAPT_BUF *src_p = (BIADAPT_BUF *)src->pixels;
BIADAPT_BUF *dst_p = (BIADAPT_BUF *)dst->pixels; BIADAPT_BUF *dst_p = (BIADAPT_BUF *)dst->pixels;
@@ -1954,7 +1919,7 @@ Scale_BiAdaptAdvFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
if (cmatch == 3) if (cmatch == 3)
{ {
if (y + 1 < h || x + 1 < w) if (y + 1 >= h || x + 1 >= w)
{ {
// last pixel in row/column and nearest // last pixel in row/column and nearest
// neighboor is identical // neighboor is identical
@@ -2090,8 +2055,8 @@ Scale_BiAdaptAdvFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
{ {
if (BIADAPT_CMPYUV (PIX (0, 0), PIX (0, 1)) <= BIADAPT_YUVLOW) if (BIADAPT_CMPYUV (PIX (0, 0), PIX (0, 1)) <= BIADAPT_YUVLOW)
{ {
BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels ( BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels_2 (
fmt, PIX (0, 0), PIX (0, 1)) blend2, PIX (0, 0), PIX (0, 1))
); );
cmatch |= 1; cmatch |= 1;
} }
@@ -2148,8 +2113,8 @@ Scale_BiAdaptAdvFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
BIADAPT_SETPIX (dst_p + dw, PIX (0, 1)); BIADAPT_SETPIX (dst_p + dw, PIX (0, 1));
} }
else else
BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels ( BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels_2 (
fmt, PIX (0, 0), PIX (0, 1)) blend2, PIX (0, 0), PIX (0, 1))
); );
} }
@@ -2160,8 +2125,8 @@ Scale_BiAdaptAdvFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
{ {
if (BIADAPT_CMPYUV (PIX (0, 0), PIX (1, 0)) <= BIADAPT_YUVLOW) if (BIADAPT_CMPYUV (PIX (0, 0), PIX (1, 0)) <= BIADAPT_YUVLOW)
{ {
BIADAPT_SETPIX (dst_p, Scale_BlendPixels ( BIADAPT_SETPIX (dst_p, Scale_BlendPixels_2 (
fmt, PIX (0, 0), PIX (1, 0)) blend2, PIX (0, 0), PIX (1, 0))
); );
cmatch |= 2; cmatch |= 2;
} }
@@ -2219,8 +2184,8 @@ Scale_BiAdaptAdvFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
BIADAPT_SETPIX (dst_p, PIX (1, 0)); BIADAPT_SETPIX (dst_p, PIX (1, 0));
} }
else else
BIADAPT_SETPIX (dst_p, Scale_BlendPixels ( BIADAPT_SETPIX (dst_p, Scale_BlendPixels_2 (
fmt, PIX (0, 0), PIX (1, 0)) blend2, PIX (0, 0), PIX (1, 0))
); );
} }
@@ -2253,7 +2218,7 @@ Scale_BiAdaptAdvFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
else if (cr > cl) else if (cr > cl)
clr = PIX (0, 0); clr = PIX (0, 0);
else else
clr = Scale_BlendPixels (fmt, clr = Scale_BlendPixels_2 (blend2,
PIX (0, 0), PIX (1, 0)); PIX (0, 0), PIX (1, 0));
BIADAPT_SETPIX (dst_p + dw, clr); BIADAPT_SETPIX (dst_p + dw, clr);
@@ -2264,15 +2229,15 @@ Scale_BiAdaptAdvFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
|| (BIADAPT_CMPYUV_LOW (PIX (1, 0), PIX (0, 1)) || (BIADAPT_CMPYUV_LOW (PIX (1, 0), PIX (0, 1))
&& BIADAPT_CMPYUV_LOW (PIX (1, 0), PIX (1, 1)))) && BIADAPT_CMPYUV_LOW (PIX (1, 0), PIX (1, 1))))
{ {
BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels ( BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels_2 (
fmt, PIX (0, 1), PIX (1, 0)) blend2, PIX (0, 1), PIX (1, 0))
); );
continue; continue;
} }
else if (cmatch && BIADAPT_CMPYUV_LOW (PIX (0, 0), PIX (1, 1))) else if (cmatch && BIADAPT_CMPYUV_LOW (PIX (0, 0), PIX (1, 1)))
{ {
BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels ( BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels_2 (
fmt, PIX (0, 0), PIX (1, 1)) blend2, PIX (0, 0), PIX (1, 1))
); );
continue; continue;
} }
@@ -2284,14 +2249,14 @@ Scale_BiAdaptAdvFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
if (Scale_GetPixY (fmt, PIX (0, 0)) if (Scale_GetPixY (fmt, PIX (0, 0))
> Scale_GetPixY (fmt, PIX (1, 0))) > Scale_GetPixY (fmt, PIX (1, 0)))
{ {
BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels ( BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels_2 (
fmt, PIX (0, 0), PIX (1, 1)) blend2, PIX (0, 0), PIX (1, 1))
); );
} }
else else
{ {
BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels ( BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels_2 (
fmt, PIX (1, 0), PIX (0, 1)) blend2, PIX (1, 0), PIX (0, 1))
); );
} }
} }
@@ -2299,37 +2264,25 @@ Scale_BiAdaptAdvFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
{ {
// main diagonal is same color // main diagonal is same color
// use its value // use its value
BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels ( BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels_2 (
fmt, PIX (0, 0), PIX (1, 1)) blend2, PIX (0, 0), PIX (1, 1))
); );
} }
else if (BIADAPT_CMPYUV_HIGH (PIX (1, 0), PIX (0, 1))) else if (BIADAPT_CMPYUV_HIGH (PIX (1, 0), PIX (0, 1)))
{ {
// 2nd diagonal is same color // 2nd diagonal is same color
// use its value // use its value
BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels ( BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels_2 (
fmt, PIX (1, 0), PIX (0, 1)) blend2, PIX (1, 0), PIX (0, 1))
); );
} }
else else
{ {
// blend all 4 // blend all 4
BIADAPT_SETPIX (dst_p + dw, BIADAPT_SETPIX (dst_p + dw, Scale_BlendPixels_4 (
((((PIX (0, 0) & fmt->Rmask) + blend4, PIX (0, 0), PIX (0, 1),
(PIX (0, 1) & fmt->Rmask) + PIX (1, 0), PIX (1, 1)
(PIX (1, 0) & fmt->Rmask) + ));
(PIX (1, 1) & fmt->Rmask)
) >> 2) & fmt->Rmask) |
((((PIX (0, 0) & fmt->Gmask) +
(PIX (0, 1) & fmt->Gmask) +
(PIX (1, 0) & fmt->Gmask) +
(PIX (1, 1) & fmt->Gmask)
) >> 2) & fmt->Gmask) |
((((PIX (0, 0) & fmt->Bmask) +
(PIX (0, 1) & fmt->Bmask) +
(PIX (1, 0) & fmt->Bmask) +
(PIX (1, 1) & fmt->Bmask)
) >> 2) & fmt->Bmask));
} }
} }
} }
@@ -2338,7 +2291,6 @@ Scale_BiAdaptAdvFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r)
#undef BIADAPT_GETPIX #undef BIADAPT_GETPIX
#undef BIADAPT_SETPIX #undef BIADAPT_SETPIX
#undef BIADAPT_BUF #undef BIADAPT_BUF
#undef Scale_BlendPixels
} }
#undef BIADAPT_CMPRGB #undef BIADAPT_CMPRGB