2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2004-10-15 06:06:47 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2004-10-15 06:06:47 +00:00
|
|
|
*
|
|
|
|
*/
|
2005-01-09 16:06:29 +00:00
|
|
|
|
2005-06-24 16:01:42 +00:00
|
|
|
#include "kyra/wsamovie.h"
|
2008-05-02 14:46:30 +00:00
|
|
|
#include "kyra/resource.h"
|
2004-10-15 06:06:47 +00:00
|
|
|
|
2011-04-28 13:39:17 +00:00
|
|
|
#include "common/endian.h"
|
|
|
|
|
2004-10-15 06:06:47 +00:00
|
|
|
namespace Kyra {
|
2011-04-28 13:39:17 +00:00
|
|
|
|
2009-10-26 20:07:37 +00:00
|
|
|
WSAMovie_v1::WSAMovie_v1(KyraEngine_v1 *vm)
|
2011-12-26 20:19:29 +00:00
|
|
|
: Movie(vm), _frameData(0), _frameOffsTable(0), _offscreenBuffer(0), _deltaBuffer(0) {
|
2009-10-26 20:07:37 +00:00
|
|
|
}
|
|
|
|
|
2011-12-26 20:19:29 +00:00
|
|
|
WSAMovie_v1::~WSAMovie_v1() {
|
|
|
|
close();
|
|
|
|
}
|
2006-01-02 13:20:02 +00:00
|
|
|
|
2009-06-22 02:37:20 +00:00
|
|
|
int WSAMovie_v1::open(const char *filename, int offscreenDecode, Palette *palBuf) {
|
2006-01-02 13:20:02 +00:00
|
|
|
close();
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-08-19 22:12:09 +00:00
|
|
|
uint32 flags = 0;
|
|
|
|
uint32 fileSize;
|
2006-01-02 13:20:02 +00:00
|
|
|
uint8 *p = _vm->resource()->fileData(filename, &fileSize);
|
2006-01-07 23:55:50 +00:00
|
|
|
if (!p)
|
2006-08-26 22:17:30 +00:00
|
|
|
return 0;
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2005-08-19 22:12:09 +00:00
|
|
|
const uint8 *wsaData = p;
|
2006-01-02 13:20:02 +00:00
|
|
|
_numFrames = READ_LE_UINT16(wsaData); wsaData += 2;
|
|
|
|
_width = READ_LE_UINT16(wsaData); wsaData += 2;
|
|
|
|
_height = READ_LE_UINT16(wsaData); wsaData += 2;
|
|
|
|
_deltaBufferSize = READ_LE_UINT16(wsaData); wsaData += 2;
|
|
|
|
_offscreenBuffer = NULL;
|
|
|
|
_flags = 0;
|
2007-05-08 11:46:27 +00:00
|
|
|
if (_vm->gameFlags().useAltShapeHeader) {
|
2007-09-19 08:40:12 +00:00
|
|
|
flags = READ_LE_UINT16(wsaData);
|
2007-05-08 11:46:27 +00:00
|
|
|
wsaData += 2;
|
|
|
|
}
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2005-08-19 22:12:09 +00:00
|
|
|
uint32 offsPal = 0;
|
|
|
|
if (flags & 1) {
|
|
|
|
offsPal = 0x300;
|
2006-01-02 13:20:02 +00:00
|
|
|
_flags |= WF_HAS_PALETTE;
|
2007-04-15 16:41:20 +00:00
|
|
|
if (palBuf)
|
2009-06-29 16:08:00 +00:00
|
|
|
_screen->loadPalette(wsaData + 8 + ((_numFrames << 2) & 0xFFFF), *palBuf, 0x300);
|
2004-11-14 20:11:22 +00:00
|
|
|
}
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2005-08-19 22:12:09 +00:00
|
|
|
if (offscreenDecode) {
|
2006-01-02 13:20:02 +00:00
|
|
|
_flags |= WF_OFFSCREEN_DECODE;
|
|
|
|
const int offscreenBufferSize = _width * _height;
|
|
|
|
_offscreenBuffer = new uint8[offscreenBufferSize];
|
|
|
|
memset(_offscreenBuffer, 0, offscreenBufferSize);
|
2005-08-19 22:12:09 +00:00
|
|
|
}
|
|
|
|
|
2006-01-02 13:20:02 +00:00
|
|
|
if (_numFrames & 0x8000) {
|
2009-08-10 22:18:18 +00:00
|
|
|
// This is used in the Amiga version.
|
|
|
|
if (_vm->gameFlags().platform != Common::kPlatformAmiga)
|
|
|
|
warning("Unhandled wsa flags 0x8000");
|
|
|
|
_flags |= WF_FLIPPED;
|
2006-01-02 13:20:02 +00:00
|
|
|
_numFrames &= 0x7FFF;
|
2005-08-19 22:12:09 +00:00
|
|
|
}
|
2006-01-02 13:20:02 +00:00
|
|
|
_currentFrame = _numFrames;
|
2005-08-19 22:12:09 +00:00
|
|
|
|
2006-01-02 13:20:02 +00:00
|
|
|
_deltaBuffer = new uint8[_deltaBufferSize];
|
|
|
|
memset(_deltaBuffer, 0, _deltaBufferSize);
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2005-08-19 22:12:09 +00:00
|
|
|
// read frame offsets
|
2006-01-02 13:20:02 +00:00
|
|
|
_frameOffsTable = new uint32[_numFrames + 2];
|
|
|
|
_frameOffsTable[0] = 0;
|
2005-08-19 22:12:09 +00:00
|
|
|
uint32 frameDataOffs = READ_LE_UINT32(wsaData); wsaData += 4;
|
|
|
|
bool firstFrame = true;
|
2007-05-08 11:46:27 +00:00
|
|
|
|
2005-08-19 22:12:09 +00:00
|
|
|
if (frameDataOffs == 0) {
|
|
|
|
firstFrame = false;
|
|
|
|
frameDataOffs = READ_LE_UINT32(wsaData);
|
2006-01-02 13:20:02 +00:00
|
|
|
_flags |= WF_NO_FIRST_FRAME;
|
2005-08-19 22:12:09 +00:00
|
|
|
}
|
2007-05-08 11:46:27 +00:00
|
|
|
|
2006-01-02 13:20:02 +00:00
|
|
|
for (int i = 1; i < _numFrames + 2; ++i) {
|
2009-06-07 00:58:14 +00:00
|
|
|
_frameOffsTable[i] = READ_LE_UINT32(wsaData);
|
2011-12-12 18:05:29 +00:00
|
|
|
if (_frameOffsTable[i])
|
2009-06-07 00:58:14 +00:00
|
|
|
_frameOffsTable[i] -= frameDataOffs;
|
2005-08-19 22:12:09 +00:00
|
|
|
wsaData += 4;
|
|
|
|
}
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2009-06-07 00:58:14 +00:00
|
|
|
if (!_frameOffsTable[_numFrames + 1])
|
|
|
|
_flags |= WF_NO_LAST_FRAME;
|
|
|
|
|
2005-08-19 22:12:09 +00:00
|
|
|
// skip palette
|
|
|
|
wsaData += offsPal;
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2005-08-19 22:12:09 +00:00
|
|
|
// read frame data
|
|
|
|
const int frameDataSize = p + fileSize - wsaData;
|
2006-01-02 13:20:02 +00:00
|
|
|
_frameData = new uint8[frameDataSize];
|
|
|
|
memcpy(_frameData, wsaData, frameDataSize);
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2005-08-19 22:12:09 +00:00
|
|
|
// decode first frame
|
2007-04-15 16:41:20 +00:00
|
|
|
if (firstFrame)
|
2006-01-02 13:20:02 +00:00
|
|
|
Screen::decodeFrame4(_frameData, _deltaBuffer, _deltaBufferSize);
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2008-05-07 14:20:37 +00:00
|
|
|
delete[] p;
|
2006-01-02 13:20:02 +00:00
|
|
|
_opened = true;
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2006-08-26 22:17:30 +00:00
|
|
|
return _numFrames;
|
2004-11-14 20:11:22 +00:00
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2008-05-11 22:32:37 +00:00
|
|
|
void WSAMovie_v1::close() {
|
2006-01-02 13:20:02 +00:00
|
|
|
if (_opened) {
|
2008-05-07 14:20:37 +00:00
|
|
|
delete[] _deltaBuffer;
|
|
|
|
delete[] _offscreenBuffer;
|
|
|
|
delete[] _frameOffsTable;
|
|
|
|
delete[] _frameData;
|
2006-01-02 13:20:02 +00:00
|
|
|
_opened = false;
|
2005-08-19 22:12:09 +00:00
|
|
|
}
|
2004-11-14 20:11:22 +00:00
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2009-06-09 11:26:15 +00:00
|
|
|
void WSAMovie_v1::displayFrame(int frameNum, int pageNum, int x, int y, uint16 flags, const uint8 *table1, const uint8 *table2) {
|
|
|
|
if (frameNum >= _numFrames || frameNum < 0 || !_opened)
|
2005-11-18 23:55:31 +00:00
|
|
|
return;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2009-05-10 13:40:28 +00:00
|
|
|
_x = x;
|
|
|
|
_y = y;
|
|
|
|
_drawPage = pageNum;
|
|
|
|
|
2009-06-09 11:26:15 +00:00
|
|
|
uint8 *dst = 0;
|
2007-04-15 16:41:20 +00:00
|
|
|
if (_flags & WF_OFFSCREEN_DECODE)
|
2006-01-02 13:20:02 +00:00
|
|
|
dst = _offscreenBuffer;
|
2007-04-15 16:41:20 +00:00
|
|
|
else
|
2009-06-09 11:26:15 +00:00
|
|
|
dst = _screen->getPageRect(_drawPage, _x, _y, _width, _height);
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2006-01-02 13:20:02 +00:00
|
|
|
if (_currentFrame == _numFrames) {
|
|
|
|
if (!(_flags & WF_NO_FIRST_FRAME)) {
|
2007-04-15 16:41:20 +00:00
|
|
|
if (_flags & WF_OFFSCREEN_DECODE)
|
2006-01-02 13:20:02 +00:00
|
|
|
Screen::decodeFrameDelta(dst, _deltaBuffer);
|
2007-04-15 16:41:20 +00:00
|
|
|
else
|
2009-05-21 17:25:29 +00:00
|
|
|
Screen::decodeFrameDeltaPage(dst, _deltaBuffer, _width, (_flags & WF_XOR) == 0);
|
2004-11-11 13:37:35 +00:00
|
|
|
}
|
2006-01-02 13:20:02 +00:00
|
|
|
_currentFrame = 0;
|
2004-11-11 13:37:35 +00:00
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-08-19 22:12:09 +00:00
|
|
|
// try to reduce the number of needed frame operations
|
2006-01-02 13:20:02 +00:00
|
|
|
int diffCount = ABS(_currentFrame - frameNum);
|
2005-08-19 22:12:09 +00:00
|
|
|
int frameStep = 1;
|
|
|
|
int frameCount;
|
2006-01-02 13:20:02 +00:00
|
|
|
if (_currentFrame < frameNum) {
|
|
|
|
frameCount = _numFrames - frameNum + _currentFrame;
|
2009-06-07 00:58:14 +00:00
|
|
|
if (diffCount > frameCount && !(_flags & WF_NO_LAST_FRAME))
|
2005-08-19 22:12:09 +00:00
|
|
|
frameStep = -1;
|
2007-04-15 16:41:20 +00:00
|
|
|
else
|
2005-08-19 22:12:09 +00:00
|
|
|
frameCount = diffCount;
|
2004-11-14 20:11:22 +00:00
|
|
|
} else {
|
2006-01-02 13:20:02 +00:00
|
|
|
frameCount = _numFrames - _currentFrame + frameNum;
|
2009-06-07 00:58:14 +00:00
|
|
|
if (frameCount >= diffCount || (_flags & WF_NO_LAST_FRAME)) {
|
2005-08-19 22:12:09 +00:00
|
|
|
frameStep = -1;
|
|
|
|
frameCount = diffCount;
|
2004-11-11 13:37:35 +00:00
|
|
|
}
|
|
|
|
}
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2005-08-19 22:12:09 +00:00
|
|
|
// process
|
|
|
|
if (frameStep > 0) {
|
2006-01-02 13:20:02 +00:00
|
|
|
uint16 cf = _currentFrame;
|
2005-08-19 22:12:09 +00:00
|
|
|
while (frameCount--) {
|
|
|
|
cf += frameStep;
|
2006-01-02 13:20:02 +00:00
|
|
|
processFrame(cf, dst);
|
2007-04-15 16:41:20 +00:00
|
|
|
if (cf == _numFrames)
|
2005-08-19 22:12:09 +00:00
|
|
|
cf = 0;
|
2004-10-15 06:06:47 +00:00
|
|
|
}
|
2004-11-14 20:11:22 +00:00
|
|
|
} else {
|
2006-01-02 13:20:02 +00:00
|
|
|
uint16 cf = _currentFrame;
|
2005-08-19 22:12:09 +00:00
|
|
|
while (frameCount--) {
|
2007-04-15 16:41:20 +00:00
|
|
|
if (cf == 0)
|
2006-01-02 13:20:02 +00:00
|
|
|
cf = _numFrames;
|
|
|
|
processFrame(cf, dst);
|
2005-08-19 22:12:09 +00:00
|
|
|
cf += frameStep;
|
2004-11-11 13:37:35 +00:00
|
|
|
}
|
|
|
|
}
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2005-08-19 22:12:09 +00:00
|
|
|
// display
|
2006-01-02 13:20:02 +00:00
|
|
|
_currentFrame = frameNum;
|
2009-06-09 11:26:15 +00:00
|
|
|
if (_flags & WF_OFFSCREEN_DECODE) {
|
|
|
|
int pageBackUp = _screen->setCurPage(_drawPage);
|
|
|
|
|
|
|
|
int plotFunc = (flags & 0xFF00) >> 12;
|
|
|
|
int unk1 = flags & 0xFF;
|
|
|
|
|
|
|
|
_screen->copyWsaRect(_x, _y, _width, _height, 0, plotFunc, _offscreenBuffer, unk1, table1, table2);
|
|
|
|
|
|
|
|
_screen->_curPage = pageBackUp;
|
|
|
|
}
|
2005-08-19 22:12:09 +00:00
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2008-05-11 22:32:37 +00:00
|
|
|
void WSAMovie_v1::processFrame(int frameNum, uint8 *dst) {
|
2006-01-02 13:20:02 +00:00
|
|
|
if (!_opened)
|
|
|
|
return;
|
|
|
|
assert(frameNum <= _numFrames);
|
|
|
|
const uint8 *src = _frameData + _frameOffsTable[frameNum];
|
|
|
|
Screen::decodeFrame4(src, _deltaBuffer, _deltaBufferSize);
|
2007-04-15 16:41:20 +00:00
|
|
|
if (_flags & WF_OFFSCREEN_DECODE)
|
2006-01-02 13:20:02 +00:00
|
|
|
Screen::decodeFrameDelta(dst, _deltaBuffer);
|
2007-04-15 16:41:20 +00:00
|
|
|
else
|
2007-01-06 18:52:30 +00:00
|
|
|
Screen::decodeFrameDeltaPage(dst, _deltaBuffer, _width, false);
|
2004-11-14 20:11:22 +00:00
|
|
|
}
|
2006-05-16 16:04:24 +00:00
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
2008-05-11 23:16:50 +00:00
|
|
|
WSAMovieAmiga::WSAMovieAmiga(KyraEngine_v1 *vm) : WSAMovie_v1(vm), _buffer(0) {}
|
2007-03-12 20:43:56 +00:00
|
|
|
|
2009-06-22 02:37:20 +00:00
|
|
|
int WSAMovieAmiga::open(const char *filename, int offscreenDecode, Palette *palBuf) {
|
2008-05-11 22:32:37 +00:00
|
|
|
int res = WSAMovie_v1::open(filename, offscreenDecode, palBuf);
|
2007-03-12 20:43:56 +00:00
|
|
|
|
|
|
|
if (!res)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
_buffer = new uint8[_width * _height];
|
|
|
|
assert(_buffer);
|
2007-09-19 08:40:12 +00:00
|
|
|
return res;
|
2007-03-12 20:43:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WSAMovieAmiga::close() {
|
|
|
|
if (_opened) {
|
2008-05-07 14:20:37 +00:00
|
|
|
delete[] _buffer;
|
2007-03-12 20:43:56 +00:00
|
|
|
_buffer = 0;
|
|
|
|
}
|
2008-05-11 22:32:37 +00:00
|
|
|
WSAMovie_v1::close();
|
2007-03-12 20:43:56 +00:00
|
|
|
}
|
|
|
|
|
2009-06-09 11:26:15 +00:00
|
|
|
void WSAMovieAmiga::displayFrame(int frameNum, int pageNum, int x, int y, uint16 flags, const uint8 *table1, const uint8 *table2) {
|
2008-04-23 18:18:11 +00:00
|
|
|
if (frameNum >= _numFrames || frameNum < 0 || !_opened)
|
2007-03-12 20:43:56 +00:00
|
|
|
return;
|
|
|
|
|
2009-05-10 13:40:28 +00:00
|
|
|
_x = x;
|
|
|
|
_y = y;
|
|
|
|
_drawPage = pageNum;
|
|
|
|
|
2007-03-12 20:43:56 +00:00
|
|
|
uint8 *dst;
|
|
|
|
dst = _buffer;
|
2011-12-26 20:19:29 +00:00
|
|
|
memset(_buffer, 0, _width * _height);
|
2007-03-12 20:43:56 +00:00
|
|
|
|
|
|
|
if (_currentFrame == _numFrames) {
|
|
|
|
if (!(_flags & WF_NO_FIRST_FRAME)) {
|
|
|
|
Screen::decodeFrameDelta(dst, _deltaBuffer, true);
|
2009-08-10 22:18:18 +00:00
|
|
|
Screen::convertAmigaGfx(dst, _width, _height, 5, (_flags & WF_FLIPPED) != 0);
|
2007-03-12 20:43:56 +00:00
|
|
|
|
|
|
|
if (_flags & WF_OFFSCREEN_DECODE) {
|
|
|
|
dst = _offscreenBuffer;
|
|
|
|
const uint8 *src = _buffer;
|
|
|
|
int size = _width * _height;
|
|
|
|
|
2007-04-15 16:41:20 +00:00
|
|
|
for (int i = 0; i < size; ++i)
|
2007-03-12 20:43:56 +00:00
|
|
|
*dst++ ^= *src++;
|
|
|
|
|
|
|
|
dst = _buffer;
|
|
|
|
} else {
|
2009-06-09 11:26:15 +00:00
|
|
|
_screen->copyBlockToPage(_drawPage, _x, _y, _width, _height, _buffer);
|
2007-03-12 20:43:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
_currentFrame = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// try to reduce the number of needed frame operations
|
|
|
|
int diffCount = ABS(_currentFrame - frameNum);
|
|
|
|
int frameStep = 1;
|
|
|
|
int frameCount;
|
|
|
|
if (_currentFrame < frameNum) {
|
|
|
|
frameCount = _numFrames - frameNum + _currentFrame;
|
2009-06-07 00:58:14 +00:00
|
|
|
if (diffCount > frameCount && !(_flags & WF_NO_LAST_FRAME))
|
2007-03-12 20:43:56 +00:00
|
|
|
frameStep = -1;
|
2007-04-15 16:41:20 +00:00
|
|
|
else
|
2007-03-12 20:43:56 +00:00
|
|
|
frameCount = diffCount;
|
|
|
|
} else {
|
|
|
|
frameCount = _numFrames - _currentFrame + frameNum;
|
2009-06-07 00:58:14 +00:00
|
|
|
if (frameCount >= diffCount || (_flags & WF_NO_LAST_FRAME)) {
|
2007-03-12 20:43:56 +00:00
|
|
|
frameStep = -1;
|
|
|
|
frameCount = diffCount;
|
|
|
|
}
|
|
|
|
}
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2007-03-12 20:43:56 +00:00
|
|
|
// process
|
|
|
|
if (frameStep > 0) {
|
|
|
|
uint16 cf = _currentFrame;
|
|
|
|
while (frameCount--) {
|
|
|
|
cf += frameStep;
|
|
|
|
processFrame(cf, dst);
|
2007-04-15 16:41:20 +00:00
|
|
|
if (cf == _numFrames)
|
2007-03-12 20:43:56 +00:00
|
|
|
cf = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
uint16 cf = _currentFrame;
|
|
|
|
while (frameCount--) {
|
2007-04-15 16:41:20 +00:00
|
|
|
if (cf == 0)
|
2007-03-12 20:43:56 +00:00
|
|
|
cf = _numFrames;
|
|
|
|
processFrame(cf, dst);
|
|
|
|
cf += frameStep;
|
|
|
|
}
|
|
|
|
}
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2007-03-12 20:43:56 +00:00
|
|
|
// display
|
|
|
|
_currentFrame = frameNum;
|
2009-06-09 11:26:15 +00:00
|
|
|
if (_flags & WF_OFFSCREEN_DECODE) {
|
|
|
|
int pageBackUp = _screen->setCurPage(_drawPage);
|
|
|
|
|
|
|
|
int plotFunc = (flags & 0xFF00) >> 12;
|
|
|
|
int unk1 = flags & 0xFF;
|
|
|
|
|
|
|
|
_screen->copyWsaRect(_x, _y, _width, _height, 0, plotFunc, _offscreenBuffer, unk1, table1, table2);
|
|
|
|
|
|
|
|
_screen->_curPage = pageBackUp;
|
|
|
|
}
|
2007-03-12 20:43:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WSAMovieAmiga::processFrame(int frameNum, uint8 *dst) {
|
|
|
|
if (!_opened)
|
|
|
|
return;
|
|
|
|
assert(frameNum <= _numFrames);
|
|
|
|
|
2011-12-26 20:19:29 +00:00
|
|
|
memset(dst, 0, _width * _height);
|
2007-03-12 20:43:56 +00:00
|
|
|
|
|
|
|
const uint8 *src = _frameData + _frameOffsTable[frameNum];
|
|
|
|
Screen::decodeFrame4(src, _deltaBuffer, _deltaBufferSize);
|
|
|
|
Screen::decodeFrameDelta(dst, _deltaBuffer, true);
|
2009-08-10 22:18:18 +00:00
|
|
|
Screen::convertAmigaGfx(dst, _width, _height, 5, (_flags & WF_FLIPPED) != 0);
|
2007-03-12 20:43:56 +00:00
|
|
|
|
|
|
|
src = dst;
|
|
|
|
dst = 0;
|
|
|
|
int dstPitch = 0;
|
|
|
|
if (_flags & WF_OFFSCREEN_DECODE) {
|
|
|
|
dst = _offscreenBuffer;
|
|
|
|
dstPitch = _width;
|
|
|
|
} else {
|
2009-06-09 11:26:15 +00:00
|
|
|
dst = _screen->getPageRect(_drawPage, _x, _y, _width, _height);
|
2007-03-12 20:43:56 +00:00
|
|
|
dstPitch = Screen::SCREEN_W;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int y = 0; y < _height; ++y) {
|
2007-04-15 16:41:20 +00:00
|
|
|
for (int x = 0; x < _width; ++x)
|
2007-09-19 08:40:12 +00:00
|
|
|
*dst++ ^= *src++;
|
2007-03-12 20:43:56 +00:00
|
|
|
dst += dstPitch - _width;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
2009-06-09 11:26:15 +00:00
|
|
|
WSAMovie_v2::WSAMovie_v2(KyraEngine_v1 *vm) : WSAMovie_v1(vm), _xAdd(0), _yAdd(0) {}
|
2006-05-16 16:04:24 +00:00
|
|
|
|
2009-06-22 02:37:20 +00:00
|
|
|
int WSAMovie_v2::open(const char *filename, int unk1, Palette *palBuf) {
|
2006-05-16 16:04:24 +00:00
|
|
|
close();
|
|
|
|
|
|
|
|
uint32 flags = 0;
|
|
|
|
uint32 fileSize;
|
|
|
|
uint8 *p = _vm->resource()->fileData(filename, &fileSize);
|
|
|
|
if (!p) {
|
|
|
|
warning("couldn't load wsa file: '%s'", filename);
|
2006-08-26 22:17:30 +00:00
|
|
|
return 0;
|
2006-05-16 16:04:24 +00:00
|
|
|
}
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2006-05-16 16:04:24 +00:00
|
|
|
const uint8 *wsaData = p;
|
|
|
|
_numFrames = READ_LE_UINT16(wsaData); wsaData += 2;
|
|
|
|
_xAdd = (int16)(READ_LE_UINT16(wsaData)); wsaData += 2;
|
|
|
|
_yAdd = (int16)(READ_LE_UINT16(wsaData)); wsaData += 2;
|
|
|
|
_width = READ_LE_UINT16(wsaData); wsaData += 2;
|
|
|
|
_height = READ_LE_UINT16(wsaData); wsaData += 2;
|
|
|
|
_deltaBufferSize = READ_LE_UINT16(wsaData); wsaData += 2;
|
|
|
|
_offscreenBuffer = NULL;
|
|
|
|
_flags = 0;
|
|
|
|
flags = READ_LE_UINT16(wsaData); wsaData += 2;
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2006-05-16 16:04:24 +00:00
|
|
|
uint32 offsPal = 0;
|
|
|
|
if (flags & 1) {
|
|
|
|
offsPal = 0x300;
|
|
|
|
_flags |= WF_HAS_PALETTE;
|
2007-04-15 16:41:20 +00:00
|
|
|
if (palBuf)
|
2009-06-22 02:37:41 +00:00
|
|
|
_screen->loadPalette(wsaData + 8 + ((_numFrames << 2) & 0xFFFF), *palBuf, 0x300);
|
2006-05-16 16:04:24 +00:00
|
|
|
}
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2009-04-25 13:15:05 +00:00
|
|
|
if (flags & 2) {
|
|
|
|
if (_vm->gameFlags().use16ColorMode) {
|
|
|
|
offsPal = 0x30;
|
|
|
|
_flags |= WF_HAS_PALETTE;
|
|
|
|
if (palBuf)
|
2009-06-22 02:37:41 +00:00
|
|
|
_screen->loadPalette(wsaData + 8 + ((_numFrames << 2) & 0xFFFF), *palBuf, 0x30);
|
2009-04-25 13:15:05 +00:00
|
|
|
}
|
2009-05-21 13:13:09 +00:00
|
|
|
|
2007-04-03 14:26:12 +00:00
|
|
|
_flags |= WF_XOR;
|
2009-04-25 13:15:05 +00:00
|
|
|
}
|
|
|
|
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2006-05-16 16:04:24 +00:00
|
|
|
if (!(unk1 & 2)) {
|
|
|
|
_flags |= WF_OFFSCREEN_DECODE;
|
|
|
|
const int offscreenBufferSize = _width * _height;
|
|
|
|
_offscreenBuffer = new uint8[offscreenBufferSize];
|
|
|
|
memset(_offscreenBuffer, 0, offscreenBufferSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_numFrames & 0x8000) {
|
|
|
|
warning("Unhandled wsa flags 0x80");
|
|
|
|
_flags |= 0x80;
|
|
|
|
_numFrames &= 0x7FFF;
|
|
|
|
}
|
|
|
|
_currentFrame = _numFrames;
|
|
|
|
|
|
|
|
_deltaBuffer = new uint8[_deltaBufferSize];
|
|
|
|
memset(_deltaBuffer, 0, _deltaBufferSize);
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2006-05-16 16:04:24 +00:00
|
|
|
// read frame offsets
|
|
|
|
_frameOffsTable = new uint32[_numFrames + 2];
|
|
|
|
_frameOffsTable[0] = 0;
|
|
|
|
uint32 frameDataOffs = READ_LE_UINT32(wsaData); wsaData += 4;
|
2007-10-19 22:16:00 +00:00
|
|
|
bool firstFrame = true;
|
|
|
|
if (frameDataOffs == 0) {
|
|
|
|
firstFrame = false;
|
|
|
|
frameDataOffs = READ_LE_UINT32(wsaData);
|
|
|
|
_flags |= WF_NO_FIRST_FRAME;
|
|
|
|
}
|
|
|
|
|
2009-05-10 17:26:46 +00:00
|
|
|
for (int i = 1; i < _numFrames + 2; ++i) {
|
|
|
|
_frameOffsTable[i] = READ_LE_UINT32(wsaData);
|
2009-06-07 00:51:19 +00:00
|
|
|
if (_frameOffsTable[i])
|
|
|
|
_frameOffsTable[i] -= frameDataOffs;
|
2006-05-16 16:04:24 +00:00
|
|
|
wsaData += 4;
|
|
|
|
}
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2009-06-07 00:51:19 +00:00
|
|
|
if (!_frameOffsTable[_numFrames + 1])
|
|
|
|
_flags |= WF_NO_LAST_FRAME;
|
2009-05-10 13:40:28 +00:00
|
|
|
|
2006-05-16 16:04:24 +00:00
|
|
|
// skip palette
|
|
|
|
wsaData += offsPal;
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2006-05-16 16:04:24 +00:00
|
|
|
// read frame data
|
|
|
|
const int frameDataSize = p + fileSize - wsaData;
|
2009-05-10 13:40:28 +00:00
|
|
|
|
2006-05-16 16:04:24 +00:00
|
|
|
_frameData = new uint8[frameDataSize];
|
|
|
|
memcpy(_frameData, wsaData, frameDataSize);
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2006-05-16 16:04:24 +00:00
|
|
|
// decode first frame
|
2007-10-19 22:16:00 +00:00
|
|
|
if (firstFrame)
|
|
|
|
Screen::decodeFrame4(_frameData, _deltaBuffer, _deltaBufferSize);
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2008-05-07 14:20:37 +00:00
|
|
|
delete[] p;
|
2006-05-16 16:04:24 +00:00
|
|
|
_opened = true;
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2006-08-26 22:17:30 +00:00
|
|
|
return _numFrames;
|
2006-05-16 16:04:24 +00:00
|
|
|
}
|
|
|
|
|
2009-10-04 21:26:33 +00:00
|
|
|
} // End of namespace Kyra
|