From af9d472619948d70e3fe2601810cdaffda1720dd Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Wed, 6 Apr 2016 13:46:26 +0200 Subject: [PATCH] Unstubbed the Dithered Portable C functions (ordered one unstested) --- Sources/Engine/Graphics/Graphics.cpp | 64 ++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 3 deletions(-) diff --git a/Sources/Engine/Graphics/Graphics.cpp b/Sources/Engine/Graphics/Graphics.cpp index 7114770..feadd99 100644 --- a/Sources/Engine/Graphics/Graphics.cpp +++ b/Sources/Engine/Graphics/Graphics.cpp @@ -653,6 +653,15 @@ __int64 mmShifter = 0; __int64 mmMask = 0; ULONG *pulDitherTable; +#ifdef USE_PORTABLE_C +extern const UBYTE *pubClipByte; +// increment a byte without overflowing it +static inline void IncrementByteWithClip( UBYTE &ub, SLONG slAdd) +{ + ub = pubClipByte[(SLONG)ub+slAdd]; +} +#endif + // performs dithering of a 32-bit bipmap (can be in-place) void DitherBitmap( INDEX iDitherType, ULONG *pulSrc, ULONG *pulDst, PIX pixWidth, PIX pixHeight, PIX pixCanvasWidth, PIX pixCanvasHeight) @@ -774,7 +783,32 @@ void DitherBitmap( INDEX iDitherType, ULONG *pulSrc, ULONG *pulDst, PIX pixWidth ditherOrder: #if (defined USE_PORTABLE_C) - STUBBED("ordered matrix dithering routine"); + union uConv + { + ULONG val; + DWORD dwords[2]; + UWORD words[4]; + WORD iwords[4]; + UBYTE bytes[8]; + }; + for (int i=0; i>= mmShifter; } + dith.val &= mmMask; + uConv* src = (uConv*)(pulSrc+i*pixWidth); + uConv* dst = (uConv*)(pulDst+i*pixWidth); + for (int j=0; j>4; + p5.words[k] = (p1.words[k]*5)>>4; + p7.words[k] = (p1.words[k]*7)>>4; } + for (int k=0; k<4; k++) { p1.words[k] -= (p3.words[k] + p5.words[k] + p7.words[k]);} + for (int k=0; k<4; k++) { + IncrementByteWithClip( src[k + step] , p7.words[k]); + IncrementByteWithClip( src[pixCanvasWidth*4 -step +k], p5.words[k]); + IncrementByteWithClip( src[pixCanvasWidth*4 +0 +k], p3.words[k]); + IncrementByteWithClip( src[pixCanvasWidth*4 +step +k], p1.words[k]); + } + } + } + #endif #elif (defined __MSVC_INLINE__) __asm { @@ -1585,7 +1643,7 @@ void FilterBitmap( INDEX iFilter, ULONG *pulSrc, ULONG *pulDst, PIX pixWidth, PI ULONG *dst = pulDst; ULONG *rowptr = aulRows; - ExtPix rmm1, rmm2, rmm3, rmm4, rmm5, rmm6, rmm7; + ExtPix rmm1={0}, rmm2={0}, rmm3={0}, rmm4={0}, rmm5={0}, rmm6={0}, rmm7={0}; #define EXTPIXFROMINT64(x) ExtPix r##x; extpix_fromi64(r##x, x); EXTPIXFROMINT64(mmCm); EXTPIXFROMINT64(mmCe);