From ee221cc5df30ae2b14007e0bb57bffd95c3aa837 Mon Sep 17 00:00:00 2001 From: Oystein Eftevaag Date: Sat, 6 Jan 2007 18:52:30 +0000 Subject: Merging decodeFrameDeltaPage() again and using Fingolfin's template trickery instead svn-id: r25039 --- engines/kyra/screen.cpp | 113 ++++++++++++---------------------------------- engines/kyra/screen.h | 5 +- engines/kyra/wsamovie.cpp | 4 +- 3 files changed, 35 insertions(+), 87 deletions(-) diff --git a/engines/kyra/screen.cpp b/engines/kyra/screen.cpp index 1ee12e2522..80cb2abc65 100644 --- a/engines/kyra/screen.cpp +++ b/engines/kyra/screen.cpp @@ -1487,88 +1487,19 @@ void Screen::decodeFrameDelta(uint8 *dst, const uint8 *src) { } } -void Screen::decodeFrameDeltaPage(uint8 *dst, const uint8 *src, const int pitch) { - debugC(9, kDebugLevelScreen, "Screen::decodeFrameDeltaPage(%p, %p, %d)", (const void *)dst, (const void *)src, pitch); - int count = 0; - uint8 *dstNext = dst; - while (1) { - uint8 code = *src++; - if (code == 0) { - uint8 len = *src++; - code = *src++; - while (len--) { - *dst++ ^= code; - if (++count == pitch) { - count = 0; - dstNext += SCREEN_W; - dst = dstNext; - } - } - } else if (code & 0x80) { - code -= 0x80; - if (code != 0) { - dst += code; - - count += code; - while (count >= pitch) { - count -= pitch; - dstNext += SCREEN_W; - dst = dstNext + count; - } - } else { - uint16 subcode = READ_LE_UINT16(src); src += 2; - if (subcode == 0) { - break; - } else if (subcode & 0x8000) { - subcode -= 0x8000; - if (subcode & 0x4000) { - uint16 len = subcode - 0x4000; - code = *src++; - while (len--) { - *dst++ ^= code; - if (++count == pitch) { - count = 0; - dstNext += SCREEN_W; - dst = dstNext; - } - } - } else { - while (subcode--) { - *dst++ ^= *src++; - if (++count == pitch) { - count = 0; - dstNext += SCREEN_W; - dst = dstNext; - } - } - } - } else { - dst += subcode; - - count += subcode; - while (count >= pitch) { - count -= pitch; - dstNext += SCREEN_W; - dst = dstNext + count; - } - - } - } - } else { - while (code--) { - *dst++ ^= *src++; - if (++count == pitch) { - count = 0; - dstNext += SCREEN_W; - dst = dstNext; - } - } - } +void Screen::decodeFrameDeltaPage(uint8 *dst, const uint8 *src, int pitch, bool noXor) { + debugC(9, kDebugLevelScreen, "Screen::decodeFrameDeltaPage(%p, %p, %d, %d)", (const void *)dst, (const void *)src, pitch, noXor); + + if (noXor) { + wrapped_decodeFrameDeltaPage(dst, src, pitch); + } else { + wrapped_decodeFrameDeltaPage(dst, src, pitch); } } -void Screen::decodeFrameDeltaPageNoXor(uint8 *dst, const uint8 *src, const int pitch) { - debugC(9, kDebugLevelScreen, "Screen::decodeFrameDeltaPageNoXor(%p, %p, %d)", (const void *)dst, (const void *)src, pitch); +template +void Screen::wrapped_decodeFrameDeltaPage(uint8 *dst, const uint8 *src, int pitch) { + debugC(9, kDebugLevelScreen, "Screen::decodeFrameDeltaPage(%p, %p, %d)", (const void *)dst, (const void *)src, pitch); int count = 0; uint8 *dstNext = dst; while (1) { @@ -1577,7 +1508,11 @@ void Screen::decodeFrameDeltaPageNoXor(uint8 *dst, const uint8 *src, const int p uint8 len = *src++; code = *src++; while (len--) { - *dst++ = code; + if (noXor) { + *dst++ = code; + } else { + *dst++ ^= code; + } if (++count == pitch) { count = 0; dstNext += SCREEN_W; @@ -1605,7 +1540,11 @@ void Screen::decodeFrameDeltaPageNoXor(uint8 *dst, const uint8 *src, const int p uint16 len = subcode - 0x4000; code = *src++; while (len--) { - *dst++ = code; + if (noXor) { + *dst++ = code; + } else { + *dst++ ^= code; + } if (++count == pitch) { count = 0; dstNext += SCREEN_W; @@ -1614,7 +1553,11 @@ void Screen::decodeFrameDeltaPageNoXor(uint8 *dst, const uint8 *src, const int p } } else { while (subcode--) { - *dst++ = *src++; + if (noXor) { + *dst++ = *src++; + } else { + *dst++ ^= *src++; + } if (++count == pitch) { count = 0; dstNext += SCREEN_W; @@ -1636,7 +1579,11 @@ void Screen::decodeFrameDeltaPageNoXor(uint8 *dst, const uint8 *src, const int p } } else { while (code--) { - *dst++ = *src++; + if (noXor) { + *dst++ = *src++; + } else { + *dst++ ^= *src++; + } if (++count == pitch) { count = 0; dstNext += SCREEN_W; diff --git a/engines/kyra/screen.h b/engines/kyra/screen.h index b245c938c8..aeaabd792b 100644 --- a/engines/kyra/screen.h +++ b/engines/kyra/screen.h @@ -136,8 +136,7 @@ public: static void decodeFrame3(const uint8 *src, uint8 *dst, uint32 size); static void decodeFrame4(const uint8 *src, uint8 *dst, uint32 dstSize); static void decodeFrameDelta(uint8 *dst, const uint8 *src); - static void decodeFrameDeltaPage(uint8 *dst, const uint8 *src, const int pitch); - static void decodeFrameDeltaPageNoXor(uint8 *dst, const uint8 *src, const int pitch); + static void decodeFrameDeltaPage(uint8 *dst, const uint8 *src, const int pitch, bool noXor); uint8 *encodeShape(int x, int y, int w, int h, int flags); void copyRegionToBuffer(int pageNum, int x, int y, int w, int h, uint8 *dest); @@ -208,6 +207,8 @@ private: void copyScreenFromRect(int x, int y, int w, int h, const uint8 *ptr); void copyScreenToRect(int x, int y, int w, int h, uint8 *ptr); + template static void wrapped_decodeFrameDeltaPage(uint8 *dst, const uint8 *src, const int pitch); + uint8 *_pagePtrs[16]; uint8 *_saveLoadPage[8]; uint8 *_screenPalette; diff --git a/engines/kyra/wsamovie.cpp b/engines/kyra/wsamovie.cpp index 84abac2a4b..229f37eebf 100644 --- a/engines/kyra/wsamovie.cpp +++ b/engines/kyra/wsamovie.cpp @@ -143,7 +143,7 @@ void WSAMovieV1::displayFrame(int frameNum) { if (_flags & WF_OFFSCREEN_DECODE) { Screen::decodeFrameDelta(dst, _deltaBuffer); } else { - Screen::decodeFrameDeltaPageNoXor(dst, _deltaBuffer, _width); + Screen::decodeFrameDeltaPage(dst, _deltaBuffer, _width, true); } } _currentFrame = 0; @@ -206,7 +206,7 @@ void WSAMovieV1::processFrame(int frameNum, uint8 *dst) { if (_flags & WF_OFFSCREEN_DECODE) { Screen::decodeFrameDelta(dst, _deltaBuffer); } else { - Screen::decodeFrameDeltaPage(dst, _deltaBuffer, _width); + Screen::decodeFrameDeltaPage(dst, _deltaBuffer, _width, false); } } -- cgit v1.2.3