From 7ddbd4f886510f1a0064be32aed0ea24c38ce403 Mon Sep 17 00:00:00 2001 From: engineer_apple Date: Wed, 11 Feb 2009 23:53:15 +0000 Subject: [PATCH] - destination alpha saving for CImage git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2211 dfc29bdd-3216-0410-991c-e03cc46cb475 --- examples/21.Quake3Explorer/main.cpp | 1 + source/Irrlicht/CImage.cpp | 18 +++++++++------ source/Irrlicht/SoftwareDriver2_helper.h | 29 ++++++++++++++++-------- 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/examples/21.Quake3Explorer/main.cpp b/examples/21.Quake3Explorer/main.cpp index 0b0bceb6..f8cf762a 100644 --- a/examples/21.Quake3Explorer/main.cpp +++ b/examples/21.Quake3Explorer/main.cpp @@ -2052,6 +2052,7 @@ void runGame ( GameData *game ) #pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup") #endif + /*! */ int IRRCALLCONV main(int argc, char* argv[]) diff --git a/source/Irrlicht/CImage.cpp b/source/Irrlicht/CImage.cpp index 9866863a..ad9a36ce 100644 --- a/source/Irrlicht/CImage.cpp +++ b/source/Irrlicht/CImage.cpp @@ -287,9 +287,10 @@ static void RenderLine32_Blend(video::IImage *t, m = dy << 1; run = dx; + const u32 packA = packAlpha ( alpha ); while ( run ) { - *dst = PixelBlend32( *dst, argb, alpha ); + *dst = packA | PixelBlend32( *dst, argb, alpha ); dst = (u32*) ( (u8*) dst + xInc ); // x += xInc d += m; @@ -374,8 +375,8 @@ static void RenderLine16_Decal(video::IImage *t, static void RenderLine16_Blend(video::IImage *t, const core::position2d &p0, const core::position2d &p1, - u32 argb, - u32 alpha) + u16 argb, + u16 alpha) { s32 dx = p1.X - p0.X; s32 dy = p1.Y - p0.Y; @@ -418,9 +419,10 @@ static void RenderLine16_Blend(video::IImage *t, m = dy << 1; run = dx; + const u16 packA = alpha ? 0x8000 : 0; while ( run ) { - *dst = PixelBlend16( *dst, argb, alpha ); + *dst = packA | PixelBlend16( *dst, argb, alpha ); dst = (u16*) ( (u8*) dst + xInc ); // x += xInc d += m; @@ -724,14 +726,16 @@ static void executeBlit_ColorAlpha_16_to_16( const SBlitJob * job ) { u16 *dst = (u16*) job->dst; - const u32 alpha = extractAlpha( job->argb ) >> 3; + const u16 alpha = extractAlpha( job->argb ) >> 3; + if ( 0 == alpha ) + return; const u32 src = video::A8R8G8B8toA1R5G5B5( job->argb ); for ( s32 dy = 0; dy != job->height; ++dy ) { for ( s32 dx = 0; dx != job->width; ++dx ) { - dst[dx] = PixelBlend16( dst[dx], src, alpha ); + dst[dx] = 0x8000 | PixelBlend16( dst[dx], src, alpha ); } dst = (u16*) ( (u8*) (dst) + job->dstPitch ); } @@ -750,7 +754,7 @@ static void executeBlit_ColorAlpha_32_to_32( const SBlitJob * job ) { for ( s32 dx = 0; dx != job->width; ++dx ) { - dst[dx] = PixelBlend32( dst[dx], src, alpha ); + dst[dx] = (job->argb & 0xFF000000 ) | PixelBlend32( dst[dx], src, alpha ); } dst = (u32*) ( (u8*) (dst) + job->dstPitch ); } diff --git a/source/Irrlicht/SoftwareDriver2_helper.h b/source/Irrlicht/SoftwareDriver2_helper.h index b8da7541..41d9e977 100644 --- a/source/Irrlicht/SoftwareDriver2_helper.h +++ b/source/Irrlicht/SoftwareDriver2_helper.h @@ -182,17 +182,17 @@ REALINLINE u32 PixelBlend32 ( const u32 c2, const u32 c1, u32 alpha ) Pixel = dest * ( 1 - alpha ) + source * alpha alpha [0;32] */ -inline u16 PixelBlend16 ( const u16 c2, const u32 c1, const u32 alpha ) +inline u16 PixelBlend16 ( const u16 c2, const u32 c1, const u16 alpha ) { - u32 srcRB = c1 & 0x7C1F; - u32 srcXG = c1 & 0x03E0; + u16 srcRB = c1 & 0x7C1F; + u16 srcXG = c1 & 0x03E0; - u32 dstRB = c2 & 0x7C1F; - u32 dstXG = c2 & 0x03E0; + u16 dstRB = c2 & 0x7C1F; + u16 dstXG = c2 & 0x03E0; - u32 rb = srcRB - dstRB; - u32 xg = srcXG - dstXG; + u16 rb = srcRB - dstRB; + u16 xg = srcXG - dstXG; rb *= alpha; xg *= alpha; @@ -230,14 +230,23 @@ inline u32 PixelLerp32 ( const u32 source, const u32 value ) } /* - return alpha in [0;256] Granularity - add highbit alpha ( alpha > 127 ? + 1 ) + return alpha in [0;256] Granularity rom 32-Bit ARGB + add highbit alpha ( alpha > 127 ? + 1 ) */ inline u32 extractAlpha ( const u32 c ) { return ( c >> 24 ) + ( c >> 31 ); } +/* + return alpha in [0;255] Granularity and 32-Bit ARGB + add highbit alpha ( alpha > 127 ? + 1 ) +*/ +inline u32 packAlpha ( const u32 c ) +{ + return (c > 127 ? c - 1 : c) << 24; +} + /* Pixel = c0 * (c1/31). c0 Alpha retain */ @@ -384,7 +393,7 @@ inline u32 PixelBlend32 ( const u32 c2, const u32 c1 ) rb &= 0x00FF00FF; xg &= 0x0000FF00; - return rb | xg; + return (c1 & 0xFF000000) | rb | xg; }