diff options
Diffstat (limited to 'scumm/script_v72he.cpp')
-rw-r--r-- | scumm/script_v72he.cpp | 536 |
1 files changed, 0 insertions, 536 deletions
diff --git a/scumm/script_v72he.cpp b/scumm/script_v72he.cpp index 47ffe6d35e..9f5193dbd7 100644 --- a/scumm/script_v72he.cpp +++ b/scumm/script_v72he.cpp @@ -683,252 +683,6 @@ void ScummEngine_v72he::o72_getObjectImageY() { push(_objs[objnum].y_pos); } -struct wizPackCtx { - uint32 len; - uint8 saveCode; - uint8 saveBuf[0x100]; -}; - -static void wizPackType1Helper1(uint8 *&dst, int len, byte newColor, byte prevColor, wizPackCtx *ctx) { - assert(len > 0); - if (newColor == prevColor) { - do { - int blockLen = MIN(len, 0x7F); - len -= blockLen; - if (dst) { - *dst++ = (blockLen * 2) | 1; - } - ++ctx->len; - } while (len > 0); - } else { - do { - int blockLen = MIN(len, 0x40); - len -= blockLen; - if (dst) { - *dst++ = ((blockLen - 1) * 4) | 2; - } - ++ctx->len; - if (dst) { - *dst++ = newColor; - } - ++ctx->len; - } while (len > 0); - } -} - -static void wizPackType1Helper2(uint8 *&dst, int len, wizPackCtx *ctx) { - assert(len > 0); - const uint8 *src = ctx->saveBuf; - do { - int blockLen = MIN(len, 0x40); - len -= blockLen; - if (dst) { - *dst++ = (blockLen - 1) * 4; - } - ++ctx->len; - while (blockLen--) { - if (dst) { - *dst++ = *src++; - } - ++ctx->len; - } - } while (len > 0); -} - -static int wizPackType1(uint8 *dst, const uint8 *src, int srcPitch, const Common::Rect& rCapt, uint8 tColor) { - debug(1, "wizPackType1(%d, [%d,%d,%d,%d])", tColor, rCapt.left, rCapt.top, rCapt.right, rCapt.bottom); - wizPackCtx ctx; - memset(&ctx, 0, sizeof(ctx)); - - src += rCapt.top * srcPitch + rCapt.left; - int w = rCapt.width(); - int h = rCapt.height(); - - uint8 *nextDstPtr, *curDstPtr; - uint8 curColor, prevColor; - int saveBufPos; - - nextDstPtr = curDstPtr = 0; - - int dataSize = 0; - while (h--) { - if (dst) { - curDstPtr = dst; - nextDstPtr = dst; - dst += 2; - } - dataSize += 2; - int numBytes = 0; - - int i, code; - for (i = 0; i < w; ++i) { - if (src[i] != tColor) - break; - } - if (i != w) { - curDstPtr = dst; - ctx.len = 0; - prevColor = ctx.saveBuf[0] = *src; - const uint8 *curSrcPtr = src + 1; - saveBufPos = 1; - code = (tColor - ctx.saveBuf[0] == 0) ? 1 : 0; - int curw = w; - while (curw--) { - ctx.saveBuf[saveBufPos] = curColor = *curSrcPtr++; - ++saveBufPos; - if (code == 0) { - if (curColor == tColor) { - --saveBufPos; - wizPackType1Helper2(curDstPtr, saveBufPos, &ctx); - code = saveBufPos = 1; - ctx.saveBuf[0] = curColor; - numBytes = 0; - prevColor = curColor; - continue; - } - if (saveBufPos > 0x80) { - --saveBufPos; - wizPackType1Helper2(curDstPtr, saveBufPos, &ctx); - saveBufPos = 1; - ctx.saveBuf[0] = curColor; - numBytes = 0; - prevColor = curColor; - continue; - } - if (prevColor != curColor) { - numBytes = saveBufPos - 1; - prevColor = curColor; - continue; - } - code = 1; - if (numBytes != 0) { - if (saveBufPos - numBytes < 3) { - code = 0; - } else { - wizPackType1Helper2(curDstPtr, numBytes, &ctx); - } - } - } - if (prevColor != curColor || saveBufPos - numBytes > 0x80) { - saveBufPos -= numBytes; - --saveBufPos; - wizPackType1Helper1(curDstPtr, saveBufPos, prevColor, tColor, &ctx); - saveBufPos = 1; - numBytes = 0; - ctx.saveBuf[0] = curColor; - code = (tColor - ctx.saveBuf[0] == 0) ? 1 : 0; - } - prevColor = curColor; - } - if (code == 0) { - wizPackType1Helper2(curDstPtr, saveBufPos, &ctx); - } else { - saveBufPos -= numBytes; - wizPackType1Helper1(curDstPtr, saveBufPos, prevColor, tColor, &ctx); - } - dataSize += ctx.len; - src += srcPitch; - if (dst) { - dst += ctx.len; - *(uint16 *)nextDstPtr = TO_LE_16(ctx.len); - } - } - } - return dataSize; -} - -static int wizPackType0(uint8 *dst, const uint8 *src, int srcPitch, const Common::Rect& rCapt, uint8 tColor) { - int w = rCapt.width(); - int h = rCapt.height(); - int size = w * h; - if (dst) { - src += rCapt.top * srcPitch + rCapt.left; - while (h--) { - memcpy(dst, src, w); - dst += w; - src += srcPitch; - } - } - return size; -} - -void ScummEngine_v72he::captureWizImage(int resType, int resNum, const Common::Rect& r, bool frontBuffer, int compType) { - debug(1, "ScummEngine_v72he::captureWizImage(%d, %d, %d, [%d,%d,%d,%d])", resType, resNum, compType, r.left, r.top, r.right, r.bottom); - uint8 *src = NULL; - VirtScreen *pvs = &virtscr[kMainVirtScreen]; - if (frontBuffer) { - src = pvs->getPixels(0, 0); - } else { - src = pvs->getBackPixels(0, 0); - } - Common::Rect rCapt(0, 0, pvs->w, pvs->h); - if (rCapt.intersects(r)) { - rCapt.clip(r); - const uint8 *palPtr = _currentPalette; - - int w = rCapt.width(); - int h = rCapt.height(); - int tColor = (VAR_WIZ_TCOLOR != 0xFF) ? VAR(VAR_WIZ_TCOLOR) : 5; - - // compute compressed size - int dataSize = 0; - int headerSize = palPtr ? 1080 : 36; - switch (compType) { - case 1: - dataSize = wizPackType1(0, src, pvs->pitch, rCapt, tColor); - break; - case 0: - dataSize = wizPackType0(0, src, pvs->pitch, rCapt, tColor); - break; - default: - warning("unhandled compression type %d", compType); - break; - } - - // alignment - dataSize = (dataSize + 1) & ~1; - int wizSize = headerSize + dataSize; - // write header - uint8 *wizImg = createResource(resType, resNum, dataSize + headerSize); - *(uint32 *)(wizImg + 0x00) = MKID('AWIZ'); - *(uint32 *)(wizImg + 0x04) = TO_BE_32(wizSize); - *(uint32 *)(wizImg + 0x08) = MKID('WIZH'); - *(uint32 *)(wizImg + 0x0C) = TO_BE_32(0x14); - *(uint32 *)(wizImg + 0x10) = TO_LE_32(compType); - *(uint32 *)(wizImg + 0x14) = TO_LE_32(w); - *(uint32 *)(wizImg + 0x18) = TO_LE_32(h); - int curSize = 0x1C; - if (palPtr) { - *(uint32 *)(wizImg + 0x1C) = MKID('RGBS'); - *(uint32 *)(wizImg + 0x20) = TO_BE_32(0x308); - memcpy(wizImg + 0x24, palPtr, 0x300); - *(uint32 *)(wizImg + 0x324) = MKID('RMAP'); - *(uint32 *)(wizImg + 0x328) = TO_BE_32(0x10C); - *(uint32 *)(wizImg + 0x32C) = 0; - curSize = 0x330; - for (int i = 0; i < 256; ++i) { - wizImg[curSize] = i; - ++curSize; - } - } - *(uint32 *)(wizImg + curSize + 0x0) = MKID('WIZD'); - *(uint32 *)(wizImg + curSize + 0x4) = TO_BE_32(dataSize + 8); - curSize += 8; - - // write compressed data - switch (compType) { - case 1: - wizPackType1(wizImg + headerSize, src, pvs->pitch, rCapt, tColor); - break; - case 0: - wizPackType0(wizImg + headerSize, src, pvs->pitch, rCapt, tColor); - break; - default: - break; - } - } -} - void ScummEngine_v72he::o72_captureWizImage() { Common::Rect grab; grab.bottom = pop() + 1; @@ -1713,296 +1467,6 @@ void ScummEngine_v72he::o72_traceStatus() { pop(); } -void ScummEngine_v72he::displayWizImage(const WizImage *pwi) { - if (_fullRedraw) { - assert(_wizImagesNum < ARRAYSIZE(_wizImages)); - memcpy(&_wizImages[_wizImagesNum], pwi, sizeof(WizImage)); - ++_wizImagesNum; - } else if (pwi->flags & 0x40) { - drawWizPolygon(pwi->resNum, pwi->state, pwi->x1, pwi->flags); - } else { - drawWizImage(rtImage, pwi); - } -} - -void ScummEngine_v72he::getWizImageDim(int resnum, int state, int32 &w, int32 &h) { - const uint8 *dataPtr = getResourceAddress(rtImage, resnum); - if (dataPtr) { - const uint8 *wizh = findWrappedBlock(MKID('WIZH'), dataPtr, state, 0); - w = READ_LE_UINT32(wizh + 0x4); - h = READ_LE_UINT32(wizh + 0x8); - } else { - w = 0; - h = 0; - } -} - -uint8 *ScummEngine_v72he::drawWizImage(int restype, const WizImage *pwi) { - debug(1, "drawWizImage(%d, %d, %d, %d, 0x%X)", restype, pwi->resNum, pwi->x1, pwi->y1, pwi->flags); - uint8 *dst = NULL; - const uint8 *dataPtr = getResourceAddress(restype, pwi->resNum); - if (dataPtr) { - const uint8 *rmap = NULL; - const uint8 *xmap = findWrappedBlock(MKID('XMAP'), dataPtr, pwi->state, 0); - - const uint8 *wizh = findWrappedBlock(MKID('WIZH'), dataPtr, pwi->state, 0); - assert(wizh); - uint32 comp = READ_LE_UINT32(wizh + 0x0); - uint32 width = READ_LE_UINT32(wizh + 0x4); - uint32 height = READ_LE_UINT32(wizh + 0x8); - assert(comp == 0 || comp == 1 || comp == 2 || comp == 3 || comp == 10 || comp == 11); - - const uint8 *wizd = findWrappedBlock(MKID('WIZD'), dataPtr, pwi->state, 0); - assert(wizd); - if (pwi->flags & 1) { - const uint8 *pal = findWrappedBlock(MKID('RGBS'), dataPtr, pwi->state, 0); - assert(pal); - setPaletteFromPtr(pal, 256); - } - if (pwi->flags & 2) { - rmap = findWrappedBlock(MKID('RMAP'), dataPtr, pwi->state, 0); - assert(rmap); - const uint8 *rgbs = findWrappedBlock(MKID('RGBS'), dataPtr, pwi->state, 0); - assert(rgbs); - warning("drawWizImage() unhandled flag 0x2"); - // XXX modify 'RMAP' buffer - } - if (pwi->flags & 4) { - warning("WizImage printing is unimplemented"); - return NULL; - } - uint32 cw, ch; - if (pwi->flags & 0x20) { - dst = (uint8 *)malloc(width * height); - int color = 255; // FIXME: should be (VAR_WIZ_TCOLOR != 0xFF) ? VAR(VAR_WIZ_TCOLOR) : 5; - memset(dst, color, width * height); - cw = width; - ch = height; - } else { - VirtScreen *pvs = &virtscr[kMainVirtScreen]; - if (pwi->flags & 0x10) { - dst = pvs->getPixels(0, pvs->topline); - } else { - dst = pvs->getBackPixels(0, pvs->topline); - } - cw = pvs->w; - ch = pvs->h; - } - Common::Rect rScreen(cw, ch); - // XXX handle 'XMAP' / 'RMAP' data - if (comp == 1) { - if (pwi->flags & 0x80) { - warning("drawWizImage() unhandled flag 0x80"); - } else if (pwi->flags & 0x100) { - warning("drawWizImage() unhandled flag 0x100"); - } else { - gdi.copyWizImage(dst, wizd, cw, ch, pwi->x1, pwi->y1, width, height, &rScreen); - } - } else if (comp == 0 || comp == 2) { - const uint8 *trns = findWrappedBlock(MKID('TRNS'), dataPtr, pwi->state, 0); - int color = (trns == NULL) ? VAR(VAR_WIZ_TCOLOR) : -1; - const uint8 *pal = xmap; - if (pwi->flags & 2) { - pal = rmap + 4; - } - gdi.copyRawWizImage(dst, wizd, cw, ch, pwi->x1, pwi->y1, width, height, &rScreen, pwi->flags, pal, color); - } else { - warning("unhandled wiz compression type %d", comp); - } - - if (!(pwi->flags & 0x20)) { - Common::Rect rImage(pwi->x1, pwi->y1, pwi->x1 + width, pwi->y1 + height); - if (rImage.intersects(rScreen)) { - rImage.clip(rScreen); - if (!(pwi->flags & 8) && pwi->flags & 0x18) { - ++rImage.bottom; - markRectAsDirty(kMainVirtScreen, rImage); - } else { - gdi.copyVirtScreenBuffers(rImage); - } - } - } - } - return dst; -} - -struct PolygonDrawData { - struct InterArea { - bool valid; - int32 xmin; - int32 xmax; - int32 x1; - int32 y1; - int32 x2; - int32 y2; - }; - Common::Point pto; - InterArea *ia; - int areasNum; - - PolygonDrawData(int n) { - areasNum = n; - ia = new InterArea[areasNum]; - memset(ia, 0, sizeof(InterArea) * areasNum); - } - - ~PolygonDrawData() { - delete[] ia; - } - - void calcIntersection(const Common::Point *p1, const Common::Point *p2, const Common::Point *p3, const Common::Point *p4) { - int32 x1_acc = p1->x << 0x10; - int32 x3_acc = p3->x << 0x10; - int32 y3_acc = p3->y << 0x10; - uint16 dy = ABS(p2->y - p1->y) + 1; - int32 x1_step = ((p2->x - p1->x) << 0x10) / dy; - int32 x3_step = ((p4->x - p3->x) << 0x10) / dy; - int32 y3_step = ((p4->y - p3->y) << 0x10) / dy; - - int iaidx = p1->y - pto.y; - while (dy--) { - assert(iaidx >= 0 && iaidx < areasNum); - InterArea *pia = &ia[iaidx]; - int32 tx1 = x1_acc >> 0x10; - int32 tx3 = x3_acc >> 0x10; - int32 ty3 = y3_acc >> 0x10; - - if (!pia->valid || pia->xmin > tx1) { - pia->xmin = tx1; - pia->x1 = tx3; - pia->y1 = ty3; - } - if (!pia->valid || pia->xmax < tx1) { - pia->xmax = tx1; - pia->x2 = tx3; - pia->y2 = ty3; - } - pia->valid = true; - - x1_acc += x1_step; - x3_acc += x3_step; - y3_acc += y3_step; - - if (p2->y <= p1->y) { - --iaidx; - } else { - ++iaidx; - } - } - } -}; - -void ScummEngine_v72he::drawWizPolygon(int resnum, int state, int id, int flags) { - int i; - WizPolygon *wp = NULL; - for (i = 0; i < _wizNumPolygons; ++i) { - if (_wizPolygons[i].id == id) { - wp = &_wizPolygons[i]; - break; - } - } - if (!wp) { - error("Polygon %d is not defined", id); - } - if (wp->numVerts != 5) { - error("Invalid point count %d for Polygon %d", wp->numVerts, id); - } - WizImage wi; - wi.resNum = resnum; - wi.state = state; - wi.x1 = wi.y1 = 0; - wi.flags = 0x20; - uint8 *srcWizBuf = drawWizImage(rtImage, &wi); - if (srcWizBuf) { - uint8 *dst; - VirtScreen *pvs = &virtscr[kMainVirtScreen]; - if (flags & 0x10) { - dst = pvs->getPixels(0, 0); - } else { - dst = pvs->getBackPixels(0, 0); - } - if (wp->bound.left < 0 || wp->bound.top < 0 || wp->bound.right >= pvs->w || wp->bound.bottom >= pvs->h) { - error("Invalid coords polygon %d", wp->id); - } - - int32 wizW, wizH; - getWizImageDim(resnum, state, wizW, wizH); - Common::Point bbox[4]; - bbox[0].x = 0; - bbox[0].y = 0; - bbox[1].x = wizW - 1; - bbox[1].y = 0; - bbox[2].x = wizW - 1; - bbox[2].y = wizH - 1; - bbox[3].x = 0; - bbox[3].y = wizH - 1; - - int16 xmin_p, xmax_p, ymin_p, ymax_p; - xmin_p = xmax_p = wp->vert[0].x; - ymin_p = ymax_p = wp->vert[0].y; - for (i = 1; i < 4; ++i) { - xmin_p = MIN(wp->vert[i].x, xmin_p); - xmax_p = MAX(wp->vert[i].x, xmax_p); - ymin_p = MIN(wp->vert[i].y, ymin_p); - ymax_p = MAX(wp->vert[i].y, ymax_p); - } - - int16 xmin_b, xmax_b, ymin_b, ymax_b; - xmin_b = 0; - xmax_b = wizW - 1; - ymin_b = 0; - ymax_b = wizH - 1; - - PolygonDrawData pdd(ymax_p - ymin_p + 1); - pdd.pto.x = xmin_p; - pdd.pto.y = ymin_p; - - for (i = 0; i < 3; ++i) { - pdd.calcIntersection(&wp->vert[i], &wp->vert[i + 1], &bbox[i], &bbox[i + 1]); - } - pdd.calcIntersection(&wp->vert[3], &wp->vert[0], &bbox[3], &bbox[0]); - - uint yoff = pdd.pto.y * pvs->w; - for (i = 0; i < pdd.areasNum; ++i) { - PolygonDrawData::InterArea *pia = &pdd.ia[i]; - uint16 dx = pia->xmax - pia->xmin + 1; - uint8 *dstPtr = dst + pia->xmin + yoff; - int32 x_acc = pia->x1 << 0x10; - int32 y_acc = pia->y1 << 0x10; - int32 x_step = ((pia->x2 - pia->x1) << 0x10) / dx; - int32 y_step = ((pia->y2 - pia->y1) << 0x10) / dx; - while (dx--) { - uint srcWizOff = (y_acc >> 0x10) * wizW + (x_acc >> 0x10); - assert(srcWizOff < (uint32)(wizW * wizH)); - x_acc += x_step; - y_acc += y_step; - *dstPtr++ = srcWizBuf[srcWizOff]; - } - yoff += pvs->pitch; - } - - if (flags & 0x10) { - markRectAsDirty(kMainVirtScreen, wp->bound); - } else { - gdi.copyVirtScreenBuffers(wp->bound); - } - - free(srcWizBuf); - } -} - -void ScummEngine_v72he::flushWizBuffer() { - for (int i = 0; i < _wizImagesNum; ++i) { - WizImage *pwi = &_wizImages[i]; - if (pwi->flags & 0x40) { - drawWizPolygon(pwi->resNum, pwi->state, pwi->x1, pwi->flags); - } else { - drawWizImage(rtImage, pwi); - } - } - _wizImagesNum = 0; -} - void ScummEngine_v72he::o72_kernelGetFunctions() { int args[29]; int retval; |