comparison src/video/SDL_blit_N.c @ 1232:0aa0000081d5

Added optimized C 32bit RGB<->RGBA alpha masking blitter from Alex Volkov. Fixes Bugzilla #11.
author Ryan C. Gordon <icculus@icculus.org>
date Thu, 05 Jan 2006 16:40:51 +0000
parents f033d9589ca1
children c9b51268668f
comparison
equal deleted inserted replaced
1231:cf59e7b91ed4 1232:0aa0000081d5
1989 src += srcskip; 1989 src += srcskip;
1990 dst += dstskip; 1990 dst += dstskip;
1991 } 1991 }
1992 } 1992 }
1993 } 1993 }
1994
1995 /* blits 32 bit RGB<->RGBA with both surfaces having the same R,G,B fields */
1996 static void Blit4to4MaskAlpha(SDL_BlitInfo *info)
1997 {
1998 int width = info->d_width;
1999 int height = info->d_height;
2000 Uint32 *src = (Uint32 *)info->s_pixels;
2001 int srcskip = info->s_skip;
2002 Uint32 *dst = (Uint32 *)info->d_pixels;
2003 int dstskip = info->d_skip;
2004 SDL_PixelFormat *srcfmt = info->src;
2005 SDL_PixelFormat *dstfmt = info->dst;
2006
2007 if (dstfmt->Amask) {
2008 /* RGB->RGBA, SET_ALPHA */
2009 Uint32 mask = (srcfmt->alpha >> dstfmt->Aloss) << dstfmt->Ashift;
2010
2011 while ( height-- ) {
2012 DUFFS_LOOP(
2013 {
2014 *dst = *src | mask;
2015 ++dst;
2016 ++src;
2017 },
2018 width);
2019 src = (Uint32*)((Uint8*)src + srcskip);
2020 dst = (Uint32*)((Uint8*)dst + dstskip);
2021 }
2022 } else {
2023 /* RGBA->RGB, NO_ALPHA */
2024 Uint32 mask = srcfmt->Rmask | srcfmt->Gmask | srcfmt->Bmask;
2025
2026 while ( height-- ) {
2027 DUFFS_LOOP(
2028 {
2029 *dst = *src & mask;
2030 ++dst;
2031 ++src;
2032 },
2033 width);
2034 src = (Uint32*)((Uint8*)src + srcskip);
2035 dst = (Uint32*)((Uint8*)dst + dstskip);
2036 }
2037 }
2038 }
2039
1994 static void BlitNtoN(SDL_BlitInfo *info) 2040 static void BlitNtoN(SDL_BlitInfo *info)
1995 { 2041 {
1996 int width = info->d_width; 2042 int width = info->d_width;
1997 int height = info->d_height; 2043 int height = info->d_height;
1998 Uint8 *src = info->s_pixels; 2044 Uint8 *src = info->s_pixels;
2412 ((table[which].blit_features & GetBlitFeatures()) == table[which].blit_features) ) 2458 ((table[which].blit_features & GetBlitFeatures()) == table[which].blit_features) )
2413 break; 2459 break;
2414 } 2460 }
2415 sdata->aux_data = table[which].aux_data; 2461 sdata->aux_data = table[which].aux_data;
2416 blitfun = table[which].blitfunc; 2462 blitfun = table[which].blitfunc;
2417 if(a_need == COPY_ALPHA && blitfun == BlitNtoN) 2463
2418 blitfun = BlitNtoNCopyAlpha; 2464 if(blitfun == BlitNtoN) { /* default C fallback catch-all. Slow! */
2465 /* Fastpath C fallback: 32bit RGB<->RGBA blit with matching RGB */
2466 if ( srcfmt->BytesPerPixel == 4 && dstfmt->BytesPerPixel == 4 &&
2467 srcfmt->Rmask == dstfmt->Rmask &&
2468 srcfmt->Gmask == dstfmt->Gmask &&
2469 srcfmt->Bmask == dstfmt->Bmask ) {
2470 blitfun = Blit4to4MaskAlpha;
2471 } else if ( a_need == COPY_ALPHA ) {
2472 blitfun = BlitNtoNCopyAlpha;
2473 }
2474 }
2419 } 2475 }
2420 2476
2421 #ifdef DEBUG_ASM 2477 #ifdef DEBUG_ASM
2422 #ifdef USE_ASMBLIT 2478 #ifdef USE_ASMBLIT
2423 if ( blitfun == ConvertMMX ) 2479 if ( blitfun == ConvertMMX )