diff options
Diffstat (limited to 'scumm/gfx.cpp')
-rw-r--r-- | scumm/gfx.cpp | 467 |
1 files changed, 1 insertions, 466 deletions
diff --git a/scumm/gfx.cpp b/scumm/gfx.cpp index a98f4cf13e..96405490e5 100644 --- a/scumm/gfx.cpp +++ b/scumm/gfx.cpp @@ -1437,7 +1437,7 @@ void Gdi::drawBMAPObject(const byte *ptr, VirtScreen *vs, int obj, int x, int y, if (code == 8 || code == 9) { Common::Rect rScreen(0, 0, vs->w, vs->h); byte *dst = (byte *)_vm->virtscr[0].backBuf + scrX; - copyWizImage(dst, bmap_ptr, vs->w, vs->h, x - scrX, y, w, h, &rScreen); + _vm->_wiz.copyWizImage(dst, bmap_ptr, vs->w, vs->h, x - scrX, y, w, h, &rScreen); } Common::Rect rect1(x, y, x + w, y + h); @@ -1453,471 +1453,6 @@ void Gdi::drawBMAPObject(const byte *ptr, VirtScreen *vs, int obj, int x, int y, } } -static bool calcClipRects(int dst_w, int dst_h, int src_x, int src_y, int src_w, int src_h, const Common::Rect *rect, Common::Rect &srcRect, Common::Rect &dstRect) { - Common::Rect r3; - if (rect) { - r3 = *rect; - Common::Rect r4(dst_w, dst_h); - if (r3.intersects(r4)) { - r3.clip(r4); - } else { - return false; - } - } else { - r3 = Common::Rect(dst_w, dst_h); - } - dstRect = Common::Rect(src_x, src_y, src_x + src_w, src_y + src_h); - dstRect.clip(r3); - srcRect = dstRect; - srcRect.moveTo(0, 0); - return srcRect.isValidRect() && dstRect.isValidRect(); -} - -void Gdi::copyWizImage(uint8 *dst, const uint8 *src, int dstw, int dsth, int srcx, int srcy, int srcw, int srch, const Common::Rect *rect) { - Common::Rect r1, r2; - if (calcClipRects(dstw, dsth, srcx, srcy, srcw, srch, rect, r1, r2)) { - for (int i = 0; i < 256; i++) - _wizImagePalette[i] = i; - dst += r2.left + r2.top * dstw; - decompressWizImage(dst, dstw, r2, src, r1); - } -} - -void Gdi::copyRawWizImage(uint8 *dst, const uint8 *src, int dstw, int dsth, int srcx, int srcy, int srcw, int srch, const Common::Rect *rect, int flags, const uint8 *palPtr, int transColor) { - Common::Rect r1, r2; - if (calcClipRects(dstw, dsth, srcx, srcy, srcw, srch, rect, r1, r2)) { - if (flags & 0x400) { - int l = r1.left; - int r = r1.right; - r1.left = srcw - r; - r1.right = srcw - l; - } - if (flags & 0x800) { - int t = r1.top; - int b = r1.bottom; - r1.top = srch - b; - r1.bottom = srch - t; - } - if (!palPtr) { - for (int i = 0; i < 256; i++) { - _wizImagePalette[i] = i; - } - palPtr = _wizImagePalette; - } - int h = r1.height(); - int w = r1.width(); - dst += r2.left + r2.top * dstw; - while (h--) { - for (int i = 0; i < w; ++i) { - uint8 col = *src++; - if (transColor == -1 || transColor != col) { - dst[i] = palPtr[col]; - } - } - dst += dstw; - } - } -} - -void Gdi::decompressWizImage(uint8 *dst, int dstPitch, const Common::Rect &dstRect, const uint8 *src, const Common::Rect &srcRect) { - const uint8 *dataPtr, *dataPtrNext; - uint8 *dstPtr, *dstPtrNext; - uint32 code; - uint8 databit; - int h, w, xoff; - uint16 off; - int color; - - dstPtr = dst; - dataPtr = src; - - // Skip over the first 'srcRect->top' lines in the data - h = srcRect.top; - while (h--) { - dataPtr += READ_LE_UINT16(dataPtr) + 2; - } - h = srcRect.height(); - if (h <= 0) - return; - w = srcRect.width(); - if (w <= 0) - return; - - while (h--) { - xoff = srcRect.left; - off = READ_LE_UINT16(dataPtr); - w = srcRect.right - srcRect.left; - dstPtrNext = dstPitch + dstPtr; - dataPtrNext = off + 2 + dataPtr; - dataPtr += 2; - if (off == 0) - goto dec_next; - - // Skip over the leftmost 'srcRect->left' pixels. - // TODO: This code could be merged (at a loss of efficency) with the - // loop below which does the actual drawing. - while (xoff > 0) { - code = *dataPtr++; - databit = code & 1; - code >>= 1; - if (databit) { - xoff -= code; - if (xoff < 0) { - code = -xoff; - goto dec_sub1; - } - } else { - databit = code & 1; - code = (code >> 1) + 1; - if (databit) { - ++dataPtr; - xoff -= code; - if (xoff < 0) { - code = -xoff; - --dataPtr; - goto dec_sub2; - } - } else { - dataPtr += code; - xoff -= code; - if (xoff < 0) { - dataPtr += xoff; - code = -xoff; - goto dec_sub3; - } - } - } - } - - while (w > 0) { - code = *dataPtr++; - databit = code & 1; - code >>= 1; - if (databit) { -dec_sub1: dstPtr += code; - w -= code; - } else { - databit = code & 1; - code = (code >> 1) + 1; - if (databit) { -dec_sub2: w -= code; - if (w < 0) { - code += w; - } - color = _wizImagePalette[*dataPtr++]; - memset(dstPtr, color, code); - dstPtr += code; - } else { -dec_sub3: w -= code; - if (w < 0) { - code += w; - } - while (code--) { - color = _wizImagePalette[*dataPtr++]; - *dstPtr++ = color; - } - } - } - } -dec_next: - dataPtr = dataPtrNext; - dstPtr = dstPtrNext; - } -} - -int Gdi::isWizPixelNonTransparent(const uint8 *data, int x, int y, int w, int h) { - int ret = 0; - while (y != 0) { - data += READ_LE_UINT16(data) + 2; - --y; - } - uint16 off = READ_LE_UINT16(data); data += 2; - if (off != 0) { - if (x == 0) { - ret = (~*data) & 1; - } else { - do { - uint8 code = *data++; - if (code & 1) { - code >>= 1; - if (code > x) { - ret = 0; - break; - } - x -= code; - } else if (code & 2) { - code = (code >> 2) + 1; - if (code > x) { - ret = 1; - break; - } - x -= code; - ++data; - } else { - code = (code >> 2) + 1; - if (code > x) { - ret = 1; - break; - } - x -= code; - data += code; - } - } while (x > 0); - } - } - return ret; -} - -uint8 Gdi::getRawWizPixelColor(const uint8 *data, int x, int y, int w, int h, uint8 color) { - uint8 c; - if (x >= 0 && x < w && y >= 0 && y < h) { - c = *(data + y * w + x); - } else { - c = color; - } - return c; -} - -uint8 Gdi::getWizPixelColor(const uint8 *data, int x, int y, int w, int h, uint8 color) { - uint8 c = color; - if (x >= 0 && x < w && y >= 0 && y < h) { - while (y != 0) { - data += READ_LE_UINT16(data) + 2; - --y; - } - uint16 off = READ_LE_UINT16(data); data += 2; - if (off != 0) { - if (x == 0) { - c = (*data & 1) ? color : *data; - } else { - do { - uint8 code = *data++; - if (code & 1) { - code >>= 1; - if (code > x) { - c = color; - break; - } - x -= code; - } else if (code & 2) { - code = (code >> 2) + 1; - if (code > x) { - c = *data; - break; - } - x -= code; - ++data; - } else { - code = (code >> 2) + 1; - if (code > x) { - c = *(data + x); - break; - } - x -= code; - data += code; - } - } while (x > 0); - } - } - } - return c; -} - -void Gdi::computeWizHistogram(uint32 *histogram, const uint8 *data, const Common::Rect *srcRect) { - int y = srcRect->top; - while (y != 0) { - data += READ_LE_UINT16(data) + 2; - --y; - } - int ih = srcRect->height(); - while (ih--) { - uint16 off = READ_LE_UINT16(data); data += 2; - if (off != 0) { - const uint8 *p = data; - int x1 = srcRect->left; - int x2 = srcRect->right; - uint8 code; - while (x1 > 0) { - code = *p++; - if (code & 1) { - code >>= 1; - if (code > x1) { - code -= x1; - x2 -= code; - break; - } - x1 -= code; - } else if (code & 2) { - code = (code >> 2) + 1; - if (code > x1) { - code -= x1; - goto dec_sub2; - } - x1 -= code; - ++p; - } else { - code = (code >> 2) + 1; - if (code > x1) { - code -= x1; - p += x1; - goto dec_sub3; - } - x1 -= code; - p += code; - } - } - while (x2 > 0) { - code = *p++; - if (code & 1) { - code >>= 1; - x2 -= code; - } else if (code & 2) { - code = (code >> 2) + 1; -dec_sub2: x2 -= code; - if (x2 < 0) { - code += x2; - } - histogram[*p++] += code; - } else { - code = (code >> 2) + 1; -dec_sub3: x2 -= code; - if (x2 < 0) { - code += x2; - } - int n = code; - while (n--) { - ++histogram[*p++]; - } - } - } - data += off; - } - } -} - -void Gdi::computeRawWizHistogram(uint32 *histogram, const uint8 *data, int srcPitch, const Common::Rect *srcRect) { - data += srcRect->top * srcPitch + srcRect->left; - int iw = srcRect->width(); - int ih = srcRect->height(); - while (ih--) { - for (int i = 0; i < iw; ++i) { - ++histogram[data[i]]; - } - data += srcPitch; - } -} - -void Gdi::copyAuxImage(uint8 *dst1, uint8 *dst2, const uint8 *src, int dstw, int dsth, int srcx, int srcy, int srcw, int srch, const Common::Rect *rect) { - Common::Rect r1, r2; - if (calcClipRects(dstw, dsth, srcx, srcy, srcw, srch, rect, r1, r2)) { - decompressAuxImage(dst1, dst2, dstw, r2, src, r1); - } -} - -void Gdi::decompressAuxImage(uint8 *dst1, uint8 *dst2, int dstPitch, const Common::Rect &dstRect, const uint8 *src, const Common::Rect &srcRect) { - const uint8 *dataPtr, *dataPtrNext; - uint8 *dst1Ptr, *dst2Ptr, *dst1PtrNext, *dst2PtrNext; - int h, w, xoff; - uint16 off; - uint8 code; - - dst1Ptr = dst1 + dstRect.left + dstRect.top * dstPitch; - dst2Ptr = dst2 + dstRect.left + dstRect.top * dstPitch; - dataPtr = src; - - // Skip over the first 'srcRect->top' lines in the data - h = srcRect.top; - while (h--) { - dataPtr += READ_LE_UINT16(dataPtr) + 2; - } - h = srcRect.height(); - if (h <= 0) - return; - w = srcRect.width(); - if (w <= 0) - return; - - while (h--) { - xoff = srcRect.left; - off = READ_LE_UINT16(dataPtr); - w = srcRect.right - srcRect.left; - dst1PtrNext = dstPitch + dst1Ptr; - dst2PtrNext = dstPitch + dst2Ptr; - dataPtrNext = off + 2 + dataPtr; - dataPtr += 2; - if (off == 0) - goto dec_next; - - // Skip over the leftmost 'srcRect->left' pixels. - // TODO: This code could be merged (at a loss of efficency) with the - // loop below which does the actual drawing. - while (xoff > 0) { - code = *dataPtr++; - if (code & 1) { - code >>= 1; - if (code > xoff) { - code -= xoff; - goto dec_sub1; - } - xoff -= code; - } else if (code & 2) { - code = (code >> 2) + 1; - if (code > xoff) { - code -= xoff; - goto dec_sub2; - } - xoff -= code; - ++dataPtr; - } else { - code = (code >> 2) + 1; - if (code > xoff) { - code -= xoff; - dataPtr += xoff; - goto dec_sub3; - } - xoff -= code; - dataPtr += code; - } - } - while (w > 0) { - code = *dataPtr++; - if (code & 1) { - code >>= 1; -dec_sub1: dst1Ptr += code; - dst2Ptr += code; - w -= code; - } else if (code & 2) { - code = (code >> 2) + 1; -dec_sub2: w -= code; - if (w >= 0) { - memset(dst1Ptr, *dataPtr++, code); - dst1Ptr += code; - dst2Ptr += code; - } else { - code += w; - memset(dst1Ptr, *dataPtr, code); - } - } else { - code = (code >> 2) + 1; -dec_sub3: w -= code; - if (w >= 0) { - memcpy(dst1Ptr, dst2Ptr, code); - dst1Ptr += code; - dst2Ptr += code; - } else { - code += w; - memcpy(dst1Ptr, dst2Ptr, code); - } - } - } - -dec_next: - dataPtr = dataPtrNext; - dst1Ptr = dst1PtrNext; - dst2Ptr = dst2PtrNext; - } -} - void Gdi::copyVirtScreenBuffers(const Common::Rect &rect) { const int rw = rect.width(); const int rh = rect.height(); |