2005-01-09 16:06:29 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
|
|
|
* Copyright (C) 2004-2005 The ScummVM project
|
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
|
|
|
*
|
|
|
|
* $Header$
|
|
|
|
*
|
|
|
|
*/
|
2005-01-09 16:06:29 +00:00
|
|
|
|
2005-06-24 15:23:51 +00:00
|
|
|
#include "common/stdafx.h"
|
2005-08-19 22:12:09 +00:00
|
|
|
#include "kyra/kyra.h"
|
|
|
|
#include "kyra/screen.h"
|
2005-06-24 16:01:42 +00:00
|
|
|
#include "kyra/wsamovie.h"
|
2004-10-15 06:06:47 +00:00
|
|
|
|
2004-11-11 13:37:35 +00:00
|
|
|
|
2004-10-15 06:06:47 +00:00
|
|
|
namespace Kyra {
|
2006-01-02 13:20:02 +00:00
|
|
|
WSAMovieV1::WSAMovieV1(KyraEngine *vm) : Movie(vm) {}
|
|
|
|
WSAMovieV1::~WSAMovieV1() { close(); }
|
|
|
|
|
|
|
|
void WSAMovieV1::open(const char *filename, int offscreenDecode, uint8 *palBuf) {
|
|
|
|
debug(9, "WSAMovieV1::open('%s', %d, 0x%X)", filename, offscreenDecode, palBuf);
|
|
|
|
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)
|
|
|
|
return;
|
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;
|
|
|
|
if (_vm->features() & GF_TALKIE) {
|
2005-08-19 22:12:09 +00:00
|
|
|
flags = READ_LE_UINT16(wsaData); wsaData += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32 offsPal = 0;
|
|
|
|
if (flags & 1) {
|
|
|
|
offsPal = 0x300;
|
2006-01-02 13:20:02 +00:00
|
|
|
_flags |= WF_HAS_PALETTE;
|
2005-08-19 22:12:09 +00:00
|
|
|
if (palBuf) {
|
2006-01-02 13:20:02 +00:00
|
|
|
memcpy(palBuf, wsaData + (_numFrames + 2) * 4, 0x300);
|
2005-08-19 22:12:09 +00:00
|
|
|
}
|
2004-11-14 20:11:22 +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) {
|
2005-08-19 22:12:09 +00:00
|
|
|
warning("Unhandled wsa flags 0x80");
|
2006-01-02 13:20:02 +00:00
|
|
|
_flags |= 0x80;
|
|
|
|
_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);
|
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;
|
|
|
|
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
|
|
|
}
|
2006-01-02 13:20:02 +00:00
|
|
|
for (int i = 1; i < _numFrames + 2; ++i) {
|
|
|
|
_frameOffsTable[i] = READ_LE_UINT32(wsaData) - frameDataOffs;
|
2005-08-19 22:12:09 +00:00
|
|
|
wsaData += 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
// skip palette
|
|
|
|
wsaData += offsPal;
|
|
|
|
|
|
|
|
// 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);
|
2005-08-19 22:12:09 +00:00
|
|
|
|
|
|
|
// decode first frame
|
|
|
|
if (firstFrame) {
|
2006-01-02 13:20:02 +00:00
|
|
|
Screen::decodeFrame4(_frameData, _deltaBuffer, _deltaBufferSize);
|
2005-08-19 22:12:09 +00:00
|
|
|
}
|
|
|
|
|
2006-01-02 13:20:02 +00:00
|
|
|
delete [] p;
|
|
|
|
_opened = true;
|
2004-11-14 20:11:22 +00:00
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2006-01-02 13:20:02 +00:00
|
|
|
void WSAMovieV1::close() {
|
|
|
|
debug(9, "WSAMovieV1::close()");
|
|
|
|
if (_opened) {
|
|
|
|
delete [] _deltaBuffer;
|
|
|
|
delete [] _offscreenBuffer;
|
|
|
|
delete [] _frameOffsTable;
|
|
|
|
delete [] _frameData;
|
|
|
|
_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
|
|
|
|
2006-01-02 13:20:02 +00:00
|
|
|
void WSAMovieV1::displayFrame(int frameNum) {
|
|
|
|
debug(9, "WSAMovieV1::displayFrame(%d)", frameNum);
|
|
|
|
if (frameNum > _numFrames || !_opened)
|
2005-11-18 23:55:31 +00:00
|
|
|
return;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-08-19 22:12:09 +00:00
|
|
|
uint8 *dst;
|
2006-01-02 13:20:02 +00:00
|
|
|
if (_flags & WF_OFFSCREEN_DECODE) {
|
|
|
|
dst = _offscreenBuffer;
|
2004-11-14 20:11:22 +00:00
|
|
|
} else {
|
2006-01-02 13:20:02 +00:00
|
|
|
dst = _vm->screen()->getPagePtr(_drawPage) + _y * Screen::SCREEN_W + _x;
|
2005-08-19 22:12:09 +00:00
|
|
|
}
|
|
|
|
|
2006-01-02 13:20:02 +00:00
|
|
|
if (_currentFrame == _numFrames) {
|
|
|
|
if (!(_flags & WF_OFFSCREEN_DECODE) && (_vm->features() & GF_TALKIE))
|
|
|
|
_vm->screen()->clearPage(_drawPage);
|
|
|
|
if (!(_flags & WF_NO_FIRST_FRAME)) {
|
|
|
|
if (_flags & WF_OFFSCREEN_DECODE) {
|
|
|
|
Screen::decodeFrameDelta(dst, _deltaBuffer);
|
2004-11-14 20:11:22 +00:00
|
|
|
} else {
|
2006-01-02 13:20:02 +00:00
|
|
|
Screen::decodeFrameDeltaPage(dst, _deltaBuffer, _width);
|
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;
|
2005-08-19 22:12:09 +00:00
|
|
|
if (diffCount > frameCount) {
|
|
|
|
frameStep = -1;
|
|
|
|
} else {
|
|
|
|
frameCount = diffCount;
|
2004-11-11 13:37:35 +00:00
|
|
|
}
|
2004-11-14 20:11:22 +00:00
|
|
|
} else {
|
2006-01-02 13:20:02 +00:00
|
|
|
frameCount = _numFrames - _currentFrame + frameNum;
|
2005-08-19 22:12:09 +00:00
|
|
|
if (frameCount >= diffCount) {
|
|
|
|
frameStep = -1;
|
|
|
|
frameCount = diffCount;
|
2004-11-11 13:37:35 +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);
|
|
|
|
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--) {
|
|
|
|
if (cf == 0) {
|
2006-01-02 13:20:02 +00:00
|
|
|
cf = _numFrames;
|
2004-11-11 13:37:35 +00:00
|
|
|
}
|
2006-01-02 13:20:02 +00:00
|
|
|
processFrame(cf, dst);
|
2005-08-19 22:12:09 +00:00
|
|
|
cf += frameStep;
|
2004-11-11 13:37:35 +00:00
|
|
|
}
|
|
|
|
}
|
2005-08-19 22:12:09 +00:00
|
|
|
|
|
|
|
// display
|
2006-01-02 13:20:02 +00:00
|
|
|
_currentFrame = frameNum;
|
|
|
|
if (_flags & WF_OFFSCREEN_DECODE) {
|
|
|
|
_vm->screen()->copyBlockToPage(_drawPage, _x, _y, _width, _height, _offscreenBuffer);
|
2004-11-14 20:11:22 +00:00
|
|
|
}
|
2005-08-19 22:12:09 +00:00
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2006-01-02 13:20:02 +00:00
|
|
|
void WSAMovieV1::processFrame(int frameNum, uint8 *dst) {
|
|
|
|
debug(9, "WSAMovieV1::processFrame(%d, 0x%X)", frameNum, dst);
|
|
|
|
if (!_opened)
|
|
|
|
return;
|
|
|
|
assert(frameNum <= _numFrames);
|
|
|
|
const uint8 *src = _frameData + _frameOffsTable[frameNum];
|
|
|
|
Screen::decodeFrame4(src, _deltaBuffer, _deltaBufferSize);
|
|
|
|
if (_flags & WF_OFFSCREEN_DECODE) {
|
|
|
|
Screen::decodeFrameDelta(dst, _deltaBuffer);
|
2005-08-19 22:12:09 +00:00
|
|
|
} else {
|
2006-01-02 13:20:02 +00:00
|
|
|
Screen::decodeFrameDeltaPage(dst, _deltaBuffer, _width);
|
2004-11-11 13:37:35 +00:00
|
|
|
}
|
2004-11-14 20:11:22 +00:00
|
|
|
}
|
2004-10-15 06:06:47 +00:00
|
|
|
} // end of namespace Kyra
|