diff options
Diffstat (limited to 'engines/fullpipe/gfx.cpp')
-rw-r--r-- | engines/fullpipe/gfx.cpp | 450 |
1 files changed, 206 insertions, 244 deletions
diff --git a/engines/fullpipe/gfx.cpp b/engines/fullpipe/gfx.cpp index 7c66a9a747..61fbf7192f 100644 --- a/engines/fullpipe/gfx.cpp +++ b/engines/fullpipe/gfx.cpp @@ -33,51 +33,6 @@ namespace Fullpipe { -Bitmap::Bitmap() { - _x = 0; - _y = 0; - _width = 0; - _height = 0; - _pixels = 0; - _type = 0; - _dataSize = 0; - _flags = 0; -} - -Bitmap::Bitmap(Bitmap *src) { - _x = src->_x; - _y = src->_y; - _flags = src->_flags; - _dataSize = src->_dataSize; - _type = src->_type; - _width = src->_width; - _height = src->_height; - _pixels = src->_pixels; -} - -Bitmap::~Bitmap() { - if (_pixels) - free(_pixels); - - _pixels = 0; -} - -void Bitmap::load(Common::ReadStream *s) { - debug(5, "Bitmap::load()"); - - _x = s->readUint32LE(); - _y = s->readUint32LE(); - _width = s->readUint32LE(); - _height = s->readUint32LE(); - s->readUint32LE(); // pixels - _type = s->readUint32LE(); - _dataSize = s->readUint32LE(); - _flags = s->readUint32LE(); - - debug(8, "Bitmap: x: %d y: %d w: %d h: %d dataSize: 0x%x", _x, _y, _width, _height, _dataSize); - debug(8, "Bitmap: type: %s (0x%04x) flags: 0x%x", Common::tag2string(_type).c_str(), _type, _flags); -} - Background::Background() { _x = 0; _y = 0; @@ -145,7 +100,7 @@ void Background::addPictureObject(PictureObject *pct) { bool inserted = false; for (uint i = 1; i < _picObjList.size(); i++) { - if (((PictureObject *)_picObjList[i])->_priority <= pct->_priority) { + if (_picObjList[i]->_priority <= pct->_priority) { _picObjList.insert_at(i, pct); inserted = true; break; @@ -192,7 +147,7 @@ bool PictureObject::load(MfcArchive &file, bool bigPicture) { _picture->load(file); - _pictureObject2List = new PtrList(); + _pictureObject2List = new Common::Array<GameObject *>; int count = file.readUint16LE(); @@ -351,7 +306,25 @@ void GameObject::setOXY(int x, int y) { _oy = y; } -void GameObject::renumPictures(PtrList *lst) { +void GameObject::renumPictures(Common::Array<StaticANIObject *> *lst) { + int *buf = (int *)calloc(lst->size() + 2, sizeof(int)); + + for (uint i = 0; i < lst->size(); i++) { + if (_id == ((GameObject *)((*lst)[i]))->_id) + buf[((GameObject *)((*lst)[i]))->_okeyCode] = 1; + } + + if (buf[_okeyCode]) { + uint count; + for (count = 1; buf[count] && count < lst->size() + 2; count++) + ; + _okeyCode = count; + } + + free(buf); +} + +void GameObject::renumPictures(Common::Array<PictureObject *> *lst) { int *buf = (int *)calloc(lst->size() + 2, sizeof(int)); for (uint i = 0; i < lst->size(); i++) { @@ -380,6 +353,7 @@ bool GameObject::getPicAniInfo(PicAniInfo *info) { info->ox = _ox; info->oy = _oy; info->priority = _priority; + warning("Yep %d", _id); return true; } @@ -495,7 +469,7 @@ void Picture::freePicture() { if (_bitmap) { if (testFlags() && !_field_54) { freeData(); - free(_bitmap); + //free(_bitmap); _bitmap = 0; } } @@ -614,6 +588,10 @@ void Picture::getDibInfo() { _bitmap->load(s); _bitmap->_pixels = _data; + + _bitmap->decode((int32 *)(_paletteData ? _paletteData : g_fp->_globalPalette)); + + _bitmap->_pixels = 0; } Bitmap *Picture::getPixelData() { @@ -658,12 +636,12 @@ void Picture::draw(int x, int y, int style, int angle) { case 1: //flip getDimensions(&point); - _bitmap->flipVertical()->drawShaded(1, x1, y1 + 30 + point.y, pal); + _bitmap->flipVertical()->drawShaded(1, x1, y1 + 30 + point.y, pal, _alpha); break; case 2: //vrtSetFadeRatio(g_vrtDrawHandle, 0.34999999); //vrtSetFadeTable(g_vrtDrawHandle, &unk_477F88, 1.0, 1000.0, 0, 0); - _bitmap->drawShaded(2, x1, y1, pal); + _bitmap->drawShaded(2, x1, y1, pal, _alpha); //vrtSetFadeRatio(g_vrtDrawHandle, 0.0); //vrtSetFadeTable(g_vrtDrawHandle, &unk_477F90, 1.0, 1000.0, 0, 0); break; @@ -671,7 +649,7 @@ void Picture::draw(int x, int y, int style, int angle) { if (angle) drawRotated(x1, y1, angle); else { - _bitmap->putDib(x1, y1, (int32 *)pal); + _bitmap->putDib(x1, y1, (int32 *)pal, _alpha); } } } @@ -770,54 +748,71 @@ int Picture::getPixelAtPosEx(int x, int y) { return 0; } -bool Bitmap::isPixelHitAtPos(int x, int y) { - if (x < _x || x >= _width + _x || y < _y || y >= _y + _height) - return false; +Bitmap::Bitmap() { + _x = 0; + _y = 0; + _width = 0; + _height = 0; + _pixels = 0; + _type = 0; + _dataSize = 0; + _flags = 0; + _surface = 0; + _flipping = Graphics::FLIP_NONE; +} - int off; +Bitmap::Bitmap(Bitmap *src) { + _x = src->_x; + _y = src->_y; + _flags = src->_flags; + _dataSize = src->_dataSize; + _type = src->_type; + _width = src->_width; + _height = src->_height; + _pixels = src->_pixels; + _surface = new Graphics::TransparentSurface(*src->_surface); + _flipping = src->_flipping; +} - if (_type == 'CB\x05e') - off = 2 * ((_width + 1) / 2); - else - off = 4 * ((_width + 3) / 4); +Bitmap::~Bitmap() { + if (_pixels) + free(_pixels); - off = x + off * (_y + _height - y - 1) - _x; + delete _surface; - if (_flags & 0x1000000) { - switch (_type) { - case 'CB\0\0': - if (_pixels[off] == (_flags & 0xff)) - return false; - break; - case 'CB\x05e': - if (!*(int16 *)&_pixels[2 * off]) - return false; - break; - case 'RB\0\0': - return isPixelAtHitPosRB(x, y); - } - } - return true; + _pixels = 0; } -bool Bitmap::isPixelAtHitPosRB(int x, int y) { - int ox = _x; - int oy = _y; +void Bitmap::load(Common::ReadStream *s) { + debug(5, "Bitmap::load()"); - _x = _y = 0; + _x = s->readUint32LE(); + _y = s->readUint32LE(); + _width = s->readUint32LE(); + _height = s->readUint32LE(); + s->readUint32LE(); // pixels + _type = s->readUint32LE(); + _dataSize = s->readUint32LE(); + _flags = s->readUint32LE(); - bool res = putDibRB(0, x, y); - _x = ox; - _y = oy; + debug(8, "Bitmap: x: %d y: %d w: %d h: %d dataSize: 0x%x", _x, _y, _width, _height, _dataSize); + debug(8, "Bitmap: type: %s (0x%04x) flags: 0x%x", Common::tag2string(_type).c_str(), _type, _flags); +} - return res; +bool Bitmap::isPixelHitAtPos(int x, int y) { + if (x < _x || x >= _width + _x || y < _y || y >= _y + _height) + return false; + + if (!_surface) + return false; + + return ((*((int32 *)_surface->getBasePtr(x, y)) & 0xff000000) != 0); } -void Bitmap::putDib(int x, int y, int32 *palette) { - debug(7, "Bitmap::putDib(%d, %d)", x, y); +void Bitmap::decode(int32 *palette) { + _surface = new Graphics::TransparentSurface; - _x = x - g_fp->_sceneRect.left; - _y = y - g_fp->_sceneRect.top; + _surface->create(_width, _height, Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0)); if (_type == MKTAG('R', 'B', '\0', '\0')) putDibRB(palette); @@ -825,46 +820,64 @@ void Bitmap::putDib(int x, int y, int32 *palette) { putDibCB(palette); } -bool Bitmap::putDibRB(int32 *palette, int pX, int pY) { - uint16 *curDestPtr; +void Bitmap::putDib(int x, int y, int32 *palette, int alpha) { + debug(7, "Bitmap::putDib(%d, %d)", x, y); + + int x1 = x - g_fp->_sceneRect.left; + int y1 = y - g_fp->_sceneRect.top; + + if (!_width || !_height || !_surface) + return; + + Common::Rect sub(0, 0, _width, _height); + + if (x1 < 0) { + sub.left = -x1; + x1 = 0; + } + + if (y1 < 0) { + sub.top = -y1; + y1 = 0; + } + + if (x1 + sub.width() > 799) + sub.right -= x1 + sub.width() - 799; + + if (y1 + sub.height() > 599) + sub.bottom -= y1 + sub.height() - 599; + + if (sub.width() <= 0 || sub.height() <= 0) + return; + + int alphac = TS_ARGB(0xff, alpha, 0xff, 0xff); + + _surface->blit(g_fp->_backgroundSurface, x1, y1, _flipping, &sub, alphac); + g_fp->_system->copyRectToScreen(g_fp->_backgroundSurface.getBasePtr(x1, y1), g_fp->_backgroundSurface.pitch, x1, y1, sub.width(), sub.height()); +} + +bool Bitmap::putDibRB(int32 *palette) { + uint32 *curDestPtr; int endy; int x; int start1; int fillLen; uint16 pixel; - int endx; int y; uint16 *srcPtr2; uint16 *srcPtr; - if (!palette && pX == -1) { + if (!palette) { debug(2, "Bitmap::putDibRB(): Both global and local palettes are empty"); return false; } debug(8, "Bitmap::putDibRB()"); - endx = _width + _x - 1; - endy = _height + _y - 1; - - if (_x > 799 || endx < 0 || _y > 599 || endy < 0) - return false; + endy = _height - 1; - if (pX == -1) { - if (endy > 599) - endy = 599; - - if (endx > 799) - endx = 799; - } - - int startx = _x; - if (startx < 0) - startx = 0; - - int starty = _y; - if (starty < 0) - starty = 0; + int startx = 0; + int starty = 0; y = endy; @@ -908,14 +921,9 @@ bool Bitmap::putDibRB(int32 *palette, int pX, int pY) { if (fillLen > 0 || start1 >= 0) { if (x <= 799 + 1 || (fillLen += 799 - x + 1, fillLen > 0)) { if (y <= endy) { - if (pX == -1) { - int bgcolor = palette[(pixel >> 8) & 0xff]; - curDestPtr = (uint16 *)g_fp->_backgroundSurface.getBasePtr(start1, y); - colorFill(curDestPtr, fillLen, bgcolor); - } else { - if (y == pY && pX >= start1 && pX < start1 + fillLen) - return true; - } + int bgcolor = palette[(pixel >> 8) & 0xff]; + curDestPtr = (uint32 *)_surface->getBasePtr(start1, y); + colorFill(curDestPtr, fillLen, bgcolor); } } } @@ -940,45 +948,26 @@ bool Bitmap::putDibRB(int32 *palette, int pX, int pY) { } if (y <= endy) { - if (pX == -1) { - curDestPtr = (uint16 *)g_fp->_backgroundSurface.getBasePtr(start1, y); - paletteFill(curDestPtr, (byte *)srcPtr2, fillLen, (int32 *)palette); - } else { - if (y == pY && pX >= start1 && pX < start1 + fillLen) - return true; - } + curDestPtr = (uint32 *)_surface->getBasePtr(start1, y); + paletteFill(curDestPtr, (byte *)srcPtr2, fillLen, (int32 *)palette); } } } } - if (pX == -1) - g_fp->_system->copyRectToScreen(g_fp->_backgroundSurface.getBasePtr(startx, starty), g_fp->_backgroundSurface.pitch, startx, starty, endx + 1 - startx, endy + 1 - starty); - return false; } void Bitmap::putDibCB(int32 *palette) { - uint16 *curDestPtr; + uint32 *curDestPtr; int endx; int endy; int bpp; uint pitch; bool cb05_format; - endx = _width + _x - 1; - endy = _height + _y - 1; - - debug(8, "Bitmap::putDibCB(): %d, %d, %d, %d [%d, %d]", _x, _y, endx, endy, _width, _height); - - if (_x > 799 || endx < 0 || _y > 599 || endy < 0) - return; - - if (endy > 599) - endy = 599; - - if (endx > 799) - endx = 799; + endx = _width - 1; + endy = _height - 1; cb05_format = (_type == MKTAG('C', 'B', '\05', 'e')); @@ -988,39 +977,28 @@ void Bitmap::putDibCB(int32 *palette) { bpp = cb05_format ? 2 : 1; pitch = (bpp * _width + 3) & 0xFFFFFFFC; - byte *srcPtr = &_pixels[pitch * (endy - _y)]; + byte *srcPtr = &_pixels[pitch * endy]; - if (endy - _y < _height) + if (endy < _height) srcPtr = &_pixels[pitch * (_height - 1)]; - int starty = _y; - if (starty < 0) { - starty = 0; - srcPtr = &_pixels[pitch * (_height + _y)]; - } - - int startx = _x; - if (startx < 0) { - srcPtr += bpp * -_x; - startx = 0; - } + int starty = 0; + int startx = 0; if (_flags & 0x1000000) { for (int y = starty; y <= endy; srcPtr -= pitch, y++) { - curDestPtr = (uint16 *)g_fp->_backgroundSurface.getBasePtr(startx, y); + curDestPtr = (uint32 *)_surface->getBasePtr(startx, y); copierKeyColor(curDestPtr, srcPtr, endx - startx + 1, _flags & 0xff, (int32 *)palette, cb05_format); } } else { for (int y = starty; y <= endy; srcPtr -= pitch, y++) { - curDestPtr = (uint16 *)g_fp->_backgroundSurface.getBasePtr(startx, y); + curDestPtr = (uint32 *)_surface->getBasePtr(startx, y); copier(curDestPtr, srcPtr, endx - startx + 1, (int32 *)palette, cb05_format); } } - - g_fp->_system->copyRectToScreen(g_fp->_backgroundSurface.getBasePtr(startx, starty), g_fp->_backgroundSurface.pitch, startx, starty, endx + 1 - startx, endy + 1 - starty); } -void Bitmap::colorFill(uint16 *dest, int len, int32 color) { +void Bitmap::colorFill(uint32 *dest, int len, int32 color) { #if 0 if (blendMode) { if (blendMode != 1) @@ -1031,12 +1009,17 @@ void Bitmap::colorFill(uint16 *dest, int len, int32 color) { colorFill = ptrfillColor16bit; } #endif + byte r, g, b; + + g_fp->_origFormat->colorToRGB(color, r, g, b); + + uint32 c = TS_ARGB(0xff, r, g, b); for (int i = 0; i < len; i++) - *dest++ = (int16)(color & 0xffff); + *dest++ = c; } -void Bitmap::paletteFill(uint16 *dest, byte *src, int len, int32 *palette) { +void Bitmap::paletteFill(uint32 *dest, byte *src, int len, int32 *palette) { #if 0 if (blendMode) { if (blendMode != 1) @@ -1048,11 +1031,16 @@ void Bitmap::paletteFill(uint16 *dest, byte *src, int len, int32 *palette) { } #endif - for (int i = 0; i < len; i++) - *dest++ = READ_LE_UINT32(&palette[*src++]) & 0xffff; + byte r, g, b; + + for (int i = 0; i < len; i++) { + g_fp->_origFormat->colorToRGB(READ_LE_UINT32(&palette[*src++]) & 0xffff, r, g, b); + + *dest++ = TS_ARGB(0xff, r, g, b); + } } -void Bitmap::copierKeyColor(uint16 *dest, byte *src, int len, int keyColor, int32 *palette, bool cb05_format) { +void Bitmap::copierKeyColor(uint32 *dest, byte *src, int len, int keyColor, int32 *palette, bool cb05_format) { #if 0 if (blendMode) { if (blendMode == 1) { @@ -1070,10 +1058,14 @@ void Bitmap::copierKeyColor(uint16 *dest, byte *src, int len, int keyColor, int3 } #endif + byte r, g, b; + if (!cb05_format) { for (int i = 0; i < len; i++) { - if (*src != keyColor) - *dest = READ_LE_UINT32(&palette[*src]) & 0xffff; + if (*src != keyColor) { + g_fp->_origFormat->colorToRGB(READ_LE_UINT32(&palette[*src]) & 0xffff, r, g, b); + *dest = TS_ARGB(0xff, r, g, b); + } dest++; src++; @@ -1082,8 +1074,10 @@ void Bitmap::copierKeyColor(uint16 *dest, byte *src, int len, int keyColor, int3 int16 *src16 = (int16 *)src; for (int i = 0; i < len; i++) { - if (*src16 != 0) - *dest = *src16; + if (*src16 != 0) { + g_fp->_origFormat->colorToRGB(READ_LE_UINT16(src16) & 0xffff, r, g, b); + *dest = TS_ARGB(0xff, r, g, b); + } dest++; src16++; @@ -1091,7 +1085,7 @@ void Bitmap::copierKeyColor(uint16 *dest, byte *src, int len, int keyColor, int3 } } -void Bitmap::copier(uint16 *dest, byte *src, int len, int32 *palette, bool cb05_format) { +void Bitmap::copier(uint32 *dest, byte *src, int len, int32 *palette, bool cb05_format) { #if 0 if (blendMode) { if (blendMode == 1) { @@ -1109,100 +1103,49 @@ void Bitmap::copier(uint16 *dest, byte *src, int len, int32 *palette, bool cb05_ } #endif - if (!cb05_format) { - for (int i = 0; i < len; i++) - *dest++ = READ_LE_UINT32(&palette[*src++]) & 0xffff; - } else { - int16 *src16 = (int16 *)src; - - for (int i = 0; i < len; i++) - *dest++ = *src16++; - } -} - -Bitmap *Bitmap::reverseImage() { - switch (_type) { - case MKTAG('R', 'B', '\0', '\0'): - return reverseImageRB(); - case MKTAG('C', 'B', '\0', '\0'): - return reverseImageCB(); - case MKTAG('C', 'B', '\05', 'e'): - return reverseImageCB05(); - default: - error("Bitmap::reverseImage: Unknown image type: %x", _type); - } - - return 0; -} - -Bitmap *Bitmap::reverseImageRB() { - uint16 *newpixels = (uint16 *)calloc(((_dataSize + 15) & 0xfffffff0) + sizeof(Bitmap), 1); - uint16 *srcPtr = (uint16 *)_pixels; + byte r, g, b; - int idx = 0; - while (srcPtr[idx] != 0x100) { - uint16 *srcPtr2 = &srcPtr[idx]; - - int prevIdx = idx; - int i = idx; + if (!cb05_format) { + for (int i = 0; i < len; i++) { + g_fp->_origFormat->colorToRGB(READ_LE_UINT32(&palette[*src++]) & 0xffff, r, g, b); - while (*srcPtr2) { - ++srcPtr2; - ++idx; + *dest++ = TS_ARGB(0xff, r, g, b); } + } else { + int16 *src16 = (int16 *)src; - int idx2 = idx; - - newpixels[idx] = srcPtr[idx]; - - while (i != idx) { - int fillLen = 2 - ((srcPtr[prevIdx] & 0xff) != 0 ? 1 : 0); - idx2 -= fillLen; - memcpy(&newpixels[idx2], &srcPtr[prevIdx], 2 * fillLen); - prevIdx = fillLen + i; - i += fillLen; + for (int i = 0; i < len; i++) { + g_fp->_origFormat->colorToRGB(READ_LE_UINT32(src16++) & 0xffff, r, g, b); + *dest++ = TS_ARGB(0xff, r, g, b); } - ++idx; } - newpixels[idx] = 256; - - int oldBmp = ((_dataSize + 15) >> 1) & 0x7FFFFFF8; - memcpy(&newpixels[oldBmp], &srcPtr[oldBmp], sizeof(Bitmap)); - - Bitmap *res = new Bitmap(this); - res->_pixels = (byte *)newpixels; - - return res; } -Bitmap *Bitmap::reverseImageCB() { - warning("STUB: Bitmap::reverseImageCB()"); - - return this; -} - -Bitmap *Bitmap::reverseImageCB05() { - warning("STUB: Bitmap::reverseImageCB05()"); +Bitmap *Bitmap::reverseImage(bool flip) { + if (flip) + _flipping = Graphics::FLIP_H; + else + _flipping = Graphics::FLIP_NONE; return this; } Bitmap *Bitmap::flipVertical() { - warning("STUB: Bitmap::flipVertical()"); + _flipping = Graphics::FLIP_V; return this; } -void Bitmap::drawShaded(int type, int x, int y, byte *palette) { +void Bitmap::drawShaded(int type, int x, int y, byte *palette, int alpha) { warning("STUB: Bitmap::drawShaded(%d, %d, %d)", type, x, y); - putDib(x, y, (int32 *)palette); + putDib(x, y, (int32 *)palette, alpha); } - void Bitmap::drawRotated(int x, int y, int angle, byte *palette) { +void Bitmap::drawRotated(int x, int y, int angle, byte *palette, int alpha) { warning("STUB: Bitmap::drawShaded(%d, %d, %d)", x, y, angle); - putDib(x, y, (int32 *)palette); + putDib(x, y, (int32 *)palette, alpha); } bool BigPicture::load(MfcArchive &file) { @@ -1232,7 +1175,7 @@ void BigPicture::draw(int x, int y, int style, int angle) { //vrtSetAlphaBlendMode(g_vrtDrawHandle, 1, v9); } - _bitmap->putDib(nx, ny, 0); + _bitmap->putDib(nx, ny, 0, 0xff); if (_alpha < 0xFF) { //vrtSetAlphaBlendMode(g_vrtDrawHandle, 0, 255); @@ -1313,4 +1256,23 @@ void FullpipeEngine::drawAlphaRectangle(int x1, int y1, int x2, int y2, int alph warning("STUB: FullpipeEngine::drawAlphaRectangle()"); } +void FullpipeEngine::sceneFade(Scene *sc, bool direction) { + warning("STUB: FullpipeEngine::sceneFade()"); + +#if 0 + for (int dim = 0; dim < 255; dim += 20) { + v5 = GetTickCount(); + vrtSetAlphaBlendMode(*(_DWORD *)virt, 0, 255); + sc->draw(); + drawAlphaRectangle(0, 0, 800, 600, direction ? 255 - dim : dim); + vrtFlush(*(_DWORD *)virt); + v7 = GetTickCount(); + if ( v7 - v5 < 42 ) + Sleep(v5 - v7 + 42); + } + vrtSetAlphaBlendMode(*(_DWORD *)virt, 0, 255); +#endif + +} + } // End of namespace Fullpipe |