2010-08-08 00:33:59 +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.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-01-08 03:36:21 +00:00
|
|
|
#include "common/scummsys.h"
|
|
|
|
|
2011-01-23 17:37:17 +00:00
|
|
|
#include "video/coktel_decoder.h"
|
2011-01-08 03:36:21 +00:00
|
|
|
|
2011-01-23 17:37:17 +00:00
|
|
|
#include "video/codecs/codec.h"
|
|
|
|
#include "video/codecs/indeo3.h"
|
2010-08-08 00:33:59 +00:00
|
|
|
|
2011-01-23 17:37:17 +00:00
|
|
|
#ifdef VIDEO_COKTELDECODER_H
|
2010-08-08 00:33:59 +00:00
|
|
|
|
2011-02-09 01:09:01 +00:00
|
|
|
#include "audio/audiostream.h"
|
|
|
|
#include "audio/decoders/raw.h"
|
2010-11-19 17:03:07 +00:00
|
|
|
#include "common/memstream.h"
|
2010-08-08 00:41:56 +00:00
|
|
|
|
2010-08-08 00:56:58 +00:00
|
|
|
static const uint32 kVideoCodecIndeo3 = MKID_BE('iv32');
|
|
|
|
|
2011-01-23 19:08:09 +00:00
|
|
|
namespace Video {
|
2010-08-08 00:33:59 +00:00
|
|
|
|
2010-08-08 00:39:03 +00:00
|
|
|
CoktelDecoder::State::State() : flags(0), speechId(0) {
|
2010-08-08 00:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-08 01:07:17 +00:00
|
|
|
CoktelDecoder::CoktelDecoder(Audio::Mixer *mixer, Audio::Mixer::SoundType soundType) :
|
|
|
|
_mixer(mixer), _soundType(soundType), _width(0), _height(0), _x(0), _y(0),
|
2010-08-08 00:41:56 +00:00
|
|
|
_defaultX(0), _defaultY(0), _features(0), _frameCount(0), _paletteDirty(false),
|
|
|
|
_ownSurface(true), _frameRate(12), _hasSound(false), _soundEnabled(false),
|
|
|
|
_soundStage(kSoundNone), _audioStream(0) {
|
2010-08-08 00:33:59 +00:00
|
|
|
|
2010-08-08 01:07:17 +00:00
|
|
|
assert(_mixer);
|
|
|
|
|
2010-08-08 00:33:59 +00:00
|
|
|
memset(_palette, 0, 768);
|
|
|
|
}
|
|
|
|
|
|
|
|
CoktelDecoder::~CoktelDecoder() {
|
|
|
|
}
|
|
|
|
|
2010-08-08 00:56:29 +00:00
|
|
|
bool CoktelDecoder::evaluateSeekFrame(int32 &frame, int whence) const {
|
|
|
|
if (!isVideoLoaded())
|
|
|
|
// Nothing to do
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Find the frame to which to seek
|
|
|
|
if (whence == SEEK_CUR)
|
|
|
|
frame += _curFrame;
|
|
|
|
else if (whence == SEEK_END)
|
|
|
|
frame = _frameCount - frame - 1;
|
|
|
|
else if (whence == SEEK_SET)
|
|
|
|
frame--;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if ((frame < -1) || (frame >= ((int32) _frameCount)))
|
|
|
|
// Out of range
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-08-08 00:37:52 +00:00
|
|
|
void CoktelDecoder::setSurfaceMemory(void *mem, uint16 width, uint16 height, uint8 bpp) {
|
|
|
|
freeSurface();
|
|
|
|
|
2011-01-23 03:46:38 +00:00
|
|
|
if (!hasVideo())
|
|
|
|
return;
|
|
|
|
|
2010-08-08 00:52:30 +00:00
|
|
|
// Sanity checks
|
2010-08-08 00:37:52 +00:00
|
|
|
assert((width > 0) && (height > 0));
|
|
|
|
assert(bpp == getPixelFormat().bytesPerPixel);
|
|
|
|
|
2010-08-08 00:52:30 +00:00
|
|
|
// Create a surface over this memory
|
2010-08-08 00:37:52 +00:00
|
|
|
_surface.w = width;
|
|
|
|
_surface.h = height;
|
|
|
|
_surface.pitch = width * bpp;
|
|
|
|
_surface.pixels = mem;
|
|
|
|
_surface.bytesPerPixel = bpp;
|
|
|
|
|
|
|
|
_ownSurface = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CoktelDecoder::setSurfaceMemory() {
|
|
|
|
freeSurface();
|
|
|
|
createSurface();
|
|
|
|
|
|
|
|
_ownSurface = true;
|
|
|
|
}
|
|
|
|
|
2011-01-23 19:08:09 +00:00
|
|
|
const Graphics::Surface *CoktelDecoder::getSurface() const {
|
2010-08-08 00:53:55 +00:00
|
|
|
if (!isVideoLoaded())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return &_surface;
|
|
|
|
}
|
|
|
|
|
2010-08-08 00:37:52 +00:00
|
|
|
bool CoktelDecoder::hasSurface() {
|
|
|
|
return _surface.pixels != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CoktelDecoder::createSurface() {
|
|
|
|
if (hasSurface())
|
|
|
|
return;
|
|
|
|
|
2011-01-23 03:46:38 +00:00
|
|
|
if (!hasVideo())
|
|
|
|
return;
|
|
|
|
|
2010-08-08 00:37:52 +00:00
|
|
|
if ((_width > 0) && (_height > 0))
|
|
|
|
_surface.create(_width, _height, getPixelFormat().bytesPerPixel);
|
|
|
|
|
|
|
|
_ownSurface = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CoktelDecoder::freeSurface() {
|
|
|
|
if (!_ownSurface) {
|
|
|
|
_surface.w = 0;
|
|
|
|
_surface.h = 0;
|
|
|
|
_surface.pitch = 0;
|
|
|
|
_surface.pixels = 0;
|
|
|
|
_surface.bytesPerPixel = 0;
|
|
|
|
} else
|
|
|
|
_surface.free();
|
|
|
|
|
|
|
|
_ownSurface = true;
|
|
|
|
}
|
|
|
|
|
2010-08-08 00:38:26 +00:00
|
|
|
void CoktelDecoder::setXY(uint16 x, uint16 y) {
|
|
|
|
_x = x;
|
|
|
|
_y = y;
|
|
|
|
}
|
|
|
|
|
2010-08-08 00:41:56 +00:00
|
|
|
void CoktelDecoder::setXY() {
|
|
|
|
setXY(_defaultX, _defaultY);
|
|
|
|
}
|
|
|
|
|
2010-08-08 00:39:32 +00:00
|
|
|
void CoktelDecoder::setFrameRate(Common::Rational frameRate) {
|
|
|
|
_frameRate = frameRate;
|
|
|
|
}
|
|
|
|
|
2010-08-08 00:41:56 +00:00
|
|
|
uint16 CoktelDecoder::getDefaultX() const {
|
|
|
|
return _defaultX;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16 CoktelDecoder::getDefaultY() const {
|
|
|
|
return _defaultY;
|
|
|
|
}
|
|
|
|
|
2010-08-08 00:39:03 +00:00
|
|
|
const Common::List<Common::Rect> &CoktelDecoder::getDirtyRects() const {
|
|
|
|
return _dirtyRects;
|
|
|
|
}
|
|
|
|
|
2010-08-08 00:42:59 +00:00
|
|
|
bool CoktelDecoder::hasPalette() const {
|
|
|
|
return (_features & kFeaturesPalette) != 0;
|
|
|
|
}
|
|
|
|
|
2011-01-20 12:28:22 +00:00
|
|
|
bool CoktelDecoder::hasVideo() const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-08-08 00:41:56 +00:00
|
|
|
bool CoktelDecoder::hasSound() const {
|
|
|
|
return _hasSound;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CoktelDecoder::isSoundEnabled() const {
|
|
|
|
return _soundEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CoktelDecoder::isSoundPlaying() const {
|
|
|
|
return _audioStream && _mixer->isSoundHandleActive(_audioHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CoktelDecoder::enableSound() {
|
|
|
|
if (!hasSound() || isSoundEnabled())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Sanity check
|
|
|
|
if (_mixer->getOutputRate() == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Only possible on the first frame
|
|
|
|
if (_curFrame > -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_soundEnabled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CoktelDecoder::disableSound() {
|
|
|
|
if (_audioStream) {
|
2011-01-20 17:07:17 +00:00
|
|
|
if ((_soundStage == kSoundPlaying) || (_soundStage == kSoundFinished)) {
|
2010-08-08 00:41:56 +00:00
|
|
|
_audioStream->finish();
|
|
|
|
_mixer->stopHandle(_audioHandle);
|
2011-01-20 17:07:17 +00:00
|
|
|
}
|
2010-08-08 00:41:56 +00:00
|
|
|
|
2011-01-20 17:07:17 +00:00
|
|
|
delete _audioStream;
|
2010-08-08 00:41:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_soundEnabled = false;
|
|
|
|
_soundStage = kSoundNone;
|
|
|
|
|
2011-01-20 17:07:17 +00:00
|
|
|
_audioStream = 0;
|
2010-08-08 00:41:56 +00:00
|
|
|
}
|
|
|
|
|
2011-01-24 14:09:47 +00:00
|
|
|
void CoktelDecoder::finishSound() {
|
|
|
|
if (!_audioStream)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_audioStream->finish();
|
|
|
|
_soundStage = kSoundFinished;
|
|
|
|
}
|
|
|
|
|
2011-01-16 16:27:52 +00:00
|
|
|
void CoktelDecoder::colorModeChanged() {
|
|
|
|
}
|
|
|
|
|
2010-08-08 01:02:19 +00:00
|
|
|
bool CoktelDecoder::getFrameCoords(int16 frame, int16 &x, int16 &y, int16 &width, int16 &height) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-08-08 00:57:27 +00:00
|
|
|
bool CoktelDecoder::hasEmbeddedFiles() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-08-08 00:46:34 +00:00
|
|
|
bool CoktelDecoder::hasEmbeddedFile(const Common::String &fileName) const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-11-19 01:37:04 +00:00
|
|
|
Common::SeekableReadStream *CoktelDecoder::getEmbeddedFile(const Common::String &fileName) const {
|
2010-08-08 00:46:34 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-08-08 01:05:16 +00:00
|
|
|
int32 CoktelDecoder::getSubtitleIndex() const {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-01-16 16:27:52 +00:00
|
|
|
bool CoktelDecoder::isPaletted() const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-08-08 00:37:52 +00:00
|
|
|
void CoktelDecoder::close() {
|
2010-08-08 00:41:56 +00:00
|
|
|
disableSound();
|
2010-08-08 00:37:52 +00:00
|
|
|
freeSurface();
|
2010-08-08 00:38:26 +00:00
|
|
|
|
|
|
|
_x = 0;
|
|
|
|
_y = 0;
|
|
|
|
|
2010-08-08 00:41:56 +00:00
|
|
|
_defaultX = 0;
|
|
|
|
_defaultY = 0;
|
|
|
|
|
|
|
|
_features = 0;
|
|
|
|
|
2010-08-08 00:38:26 +00:00
|
|
|
_frameCount = 0;
|
2010-08-08 00:41:56 +00:00
|
|
|
|
|
|
|
_hasSound = false;
|
2010-08-08 00:37:52 +00:00
|
|
|
}
|
|
|
|
|
2010-08-08 00:33:59 +00:00
|
|
|
uint16 CoktelDecoder::getWidth() const {
|
|
|
|
return _width;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16 CoktelDecoder::getHeight() const {
|
|
|
|
return _height;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32 CoktelDecoder::getFrameCount() const {
|
|
|
|
return _frameCount;
|
|
|
|
}
|
|
|
|
|
2010-12-16 01:41:11 +00:00
|
|
|
const byte *CoktelDecoder::getPalette() {
|
2010-08-08 00:33:59 +00:00
|
|
|
return _palette;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CoktelDecoder::hasDirtyPalette() const {
|
2010-08-08 00:41:56 +00:00
|
|
|
return (_features & kFeaturesPalette) && _paletteDirty;
|
2010-08-08 00:33:59 +00:00
|
|
|
}
|
|
|
|
|
2011-01-16 16:27:22 +00:00
|
|
|
uint32 CoktelDecoder::deLZ77(byte *dest, const byte *src, uint32 srcSize, uint32 destSize) {
|
|
|
|
uint32 frameLength = READ_LE_UINT32(src);
|
|
|
|
if (frameLength > destSize) {
|
|
|
|
warning("CoktelDecoder::deLZ77(): Uncompressed size bigger than buffer size (%d > %d)", frameLength, destSize);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(srcSize >= 4);
|
|
|
|
|
|
|
|
uint32 realSize = frameLength;
|
|
|
|
|
|
|
|
src += 4;
|
|
|
|
srcSize -= 4;
|
|
|
|
|
2010-08-08 00:42:59 +00:00
|
|
|
uint16 bufPos1;
|
|
|
|
bool mode;
|
2011-01-16 16:27:22 +00:00
|
|
|
if ((READ_LE_UINT16(src) == 0x1234) && (READ_LE_UINT16(src + 2) == 0x5678)) {
|
|
|
|
assert(srcSize >= 4);
|
2010-08-08 00:42:59 +00:00
|
|
|
|
2011-01-16 16:27:22 +00:00
|
|
|
src += 4;
|
|
|
|
srcSize -= 4;
|
2010-08-08 00:42:59 +00:00
|
|
|
|
|
|
|
bufPos1 = 273;
|
2011-01-16 16:27:22 +00:00
|
|
|
mode = 1; // 123Ch (cmp al, 12h)
|
2010-08-08 00:42:59 +00:00
|
|
|
} else {
|
|
|
|
bufPos1 = 4078;
|
2011-01-16 16:27:22 +00:00
|
|
|
mode = 0; // 275h (jnz +2)
|
2010-08-08 00:42:59 +00:00
|
|
|
}
|
|
|
|
|
2011-01-16 16:27:22 +00:00
|
|
|
byte buf[4370];
|
2010-08-08 00:42:59 +00:00
|
|
|
memset(buf, 32, bufPos1);
|
2011-01-16 16:27:22 +00:00
|
|
|
|
|
|
|
uint8 chunkCount = 1;
|
|
|
|
uint8 chunkBitField = 0;
|
2010-08-08 00:42:59 +00:00
|
|
|
|
|
|
|
while (frameLength > 0) {
|
|
|
|
chunkCount--;
|
2011-01-16 16:27:22 +00:00
|
|
|
|
2010-08-08 00:42:59 +00:00
|
|
|
if (chunkCount == 0) {
|
2011-01-16 16:27:22 +00:00
|
|
|
chunkCount = 8;
|
|
|
|
chunkBitField = *src++;
|
2010-08-08 00:42:59 +00:00
|
|
|
}
|
2011-01-16 16:27:22 +00:00
|
|
|
|
2010-08-08 00:42:59 +00:00
|
|
|
if (chunkBitField % 2) {
|
2011-01-16 16:27:22 +00:00
|
|
|
assert(srcSize >= 1);
|
|
|
|
|
2010-08-08 00:42:59 +00:00
|
|
|
chunkBitField >>= 1;
|
|
|
|
buf[bufPos1] = *src;
|
|
|
|
*dest++ = *src++;
|
|
|
|
bufPos1 = (bufPos1 + 1) % 4096;
|
|
|
|
frameLength--;
|
2011-01-16 16:27:22 +00:00
|
|
|
srcSize--;
|
2010-08-08 00:42:59 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
chunkBitField >>= 1;
|
|
|
|
|
2011-01-16 16:27:22 +00:00
|
|
|
assert(srcSize >= 2);
|
|
|
|
|
|
|
|
uint16 tmp = READ_LE_UINT16(src);
|
|
|
|
uint16 chunkLength = ((tmp & 0xF00) >> 8) + 3;
|
|
|
|
|
|
|
|
src += 2;
|
|
|
|
srcSize -= 2;
|
2010-08-08 00:42:59 +00:00
|
|
|
|
|
|
|
if ((mode && ((chunkLength & 0xFF) == 0x12)) ||
|
2011-01-16 16:27:22 +00:00
|
|
|
(!mode && (chunkLength == 0))) {
|
|
|
|
assert(srcSize >= 1);
|
|
|
|
|
2010-08-08 00:42:59 +00:00
|
|
|
chunkLength = *src++ + 0x12;
|
2011-01-16 16:27:22 +00:00
|
|
|
srcSize--;
|
|
|
|
}
|
2010-08-08 00:42:59 +00:00
|
|
|
|
2011-01-16 16:27:22 +00:00
|
|
|
uint16 bufPos2 = (tmp & 0xFF) + ((tmp >> 4) & 0x0F00);
|
2010-08-08 00:42:59 +00:00
|
|
|
if (((tmp + chunkLength) >= 4096) ||
|
|
|
|
((chunkLength + bufPos1) >= 4096)) {
|
|
|
|
|
2011-01-16 16:27:22 +00:00
|
|
|
for (int i = 0; i < chunkLength; i++, dest++) {
|
2010-08-08 00:42:59 +00:00
|
|
|
*dest = buf[bufPos2];
|
|
|
|
buf[bufPos1] = buf[bufPos2];
|
|
|
|
bufPos1 = (bufPos1 + 1) % 4096;
|
|
|
|
bufPos2 = (bufPos2 + 1) % 4096;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (((tmp + chunkLength) < bufPos1) ||
|
|
|
|
((chunkLength + bufPos1) < bufPos2)) {
|
|
|
|
|
|
|
|
memcpy(dest, buf + bufPos2, chunkLength);
|
|
|
|
memmove(buf + bufPos1, buf + bufPos2, chunkLength);
|
|
|
|
|
2011-01-16 16:27:22 +00:00
|
|
|
dest += chunkLength;
|
2010-08-08 00:42:59 +00:00
|
|
|
bufPos1 += chunkLength;
|
|
|
|
bufPos2 += chunkLength;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2011-01-16 16:27:22 +00:00
|
|
|
for (int i = 0; i < chunkLength; i++, dest++, bufPos1++, bufPos2++) {
|
2010-08-08 00:42:59 +00:00
|
|
|
*dest = buf[bufPos2];
|
|
|
|
buf[bufPos1] = buf[bufPos2];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
frameLength -= chunkLength;
|
|
|
|
|
|
|
|
}
|
2011-01-16 16:27:22 +00:00
|
|
|
|
|
|
|
return realSize;
|
2010-08-08 00:42:59 +00:00
|
|
|
}
|
|
|
|
|
2010-08-08 01:01:17 +00:00
|
|
|
void CoktelDecoder::deRLE(byte *&destPtr, const byte *&srcPtr, int16 destLen, int16 srcLen) {
|
|
|
|
srcPtr++;
|
|
|
|
|
|
|
|
if (srcLen & 1) {
|
|
|
|
byte data = *srcPtr++;
|
|
|
|
|
|
|
|
if (destLen > 0) {
|
|
|
|
*destPtr++ = data;
|
|
|
|
destLen--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
srcLen >>= 1;
|
|
|
|
|
|
|
|
while (srcLen > 0) {
|
|
|
|
uint8 tmp = *srcPtr++;
|
|
|
|
if (tmp & 0x80) { // Verbatim copy
|
|
|
|
tmp &= 0x7F;
|
|
|
|
|
|
|
|
int16 copyCount = MAX<int16>(0, MIN<int16>(destLen, tmp * 2));
|
|
|
|
|
|
|
|
memcpy(destPtr, srcPtr, copyCount);
|
|
|
|
|
|
|
|
srcPtr += tmp * 2;
|
|
|
|
destPtr += copyCount;
|
|
|
|
destLen -= copyCount;
|
|
|
|
} else { // 2 bytes tmp times
|
|
|
|
for (int i = 0; (i < tmp) && (destLen > 0); i++) {
|
|
|
|
for (int j = 0; j < 2; j++) {
|
|
|
|
if (destLen <= 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
*destPtr++ = srcPtr[j];
|
|
|
|
destLen--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
srcPtr += 2;
|
|
|
|
}
|
|
|
|
srcLen -= tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-08 00:42:59 +00:00
|
|
|
// A whole, completely filled block
|
2011-01-23 19:08:09 +00:00
|
|
|
void CoktelDecoder::renderBlockWhole(Graphics::Surface &dstSurf, const byte *src, Common::Rect &rect) {
|
2010-08-08 00:59:58 +00:00
|
|
|
Common::Rect srcRect = rect;
|
2010-08-08 00:42:59 +00:00
|
|
|
|
2011-01-16 16:29:43 +00:00
|
|
|
rect.clip(dstSurf.w, dstSurf.h);
|
2010-08-08 00:42:59 +00:00
|
|
|
|
2011-01-16 16:29:43 +00:00
|
|
|
byte *dst = (byte *)dstSurf.pixels + (rect.top * dstSurf.pitch) + rect.left * dstSurf.bytesPerPixel;
|
2010-08-08 00:59:58 +00:00
|
|
|
for (int i = 0; i < rect.height(); i++) {
|
2011-01-16 16:29:43 +00:00
|
|
|
memcpy(dst, src, rect.width() * dstSurf.bytesPerPixel);
|
2010-08-08 00:42:59 +00:00
|
|
|
|
2011-01-16 16:29:43 +00:00
|
|
|
src += srcRect.width() * dstSurf.bytesPerPixel;
|
|
|
|
dst += dstSurf.pitch;
|
2010-08-08 00:42:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// A quarter-wide whole, completely filled block
|
2011-01-23 19:08:09 +00:00
|
|
|
void CoktelDecoder::renderBlockWhole4X(Graphics::Surface &dstSurf, const byte *src, Common::Rect &rect) {
|
2010-08-08 00:59:58 +00:00
|
|
|
Common::Rect srcRect = rect;
|
2010-08-08 00:42:59 +00:00
|
|
|
|
2011-01-16 16:29:43 +00:00
|
|
|
rect.clip(dstSurf.w, dstSurf.h);
|
2010-08-08 00:42:59 +00:00
|
|
|
|
2011-01-16 16:29:43 +00:00
|
|
|
byte *dst = (byte *)dstSurf.pixels + (rect.top * dstSurf.pitch) + rect.left;
|
2010-08-08 00:59:58 +00:00
|
|
|
for (int i = 0; i < rect.height(); i++) {
|
2010-08-08 00:42:59 +00:00
|
|
|
byte *dstRow = dst;
|
|
|
|
const byte *srcRow = src;
|
|
|
|
|
2010-08-08 00:59:58 +00:00
|
|
|
int16 count = rect.width();
|
2010-08-08 00:42:59 +00:00
|
|
|
while (count >= 0) {
|
|
|
|
memset(dstRow, *srcRow, MIN<int16>(count, 4));
|
|
|
|
|
|
|
|
count -= 4;
|
|
|
|
dstRow += 4;
|
|
|
|
srcRow += 1;
|
|
|
|
}
|
|
|
|
|
2010-08-08 00:59:58 +00:00
|
|
|
src += srcRect.width() / 4;
|
2011-01-16 16:29:43 +00:00
|
|
|
dst += dstSurf.pitch;
|
2010-08-08 00:42:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// A half-high whole, completely filled block
|
2011-01-23 19:08:09 +00:00
|
|
|
void CoktelDecoder::renderBlockWhole2Y(Graphics::Surface &dstSurf, const byte *src, Common::Rect &rect) {
|
2010-08-08 00:59:58 +00:00
|
|
|
Common::Rect srcRect = rect;
|
2010-08-08 00:42:59 +00:00
|
|
|
|
2011-01-16 16:29:43 +00:00
|
|
|
rect.clip(dstSurf.w, dstSurf.h);
|
2010-08-08 00:42:59 +00:00
|
|
|
|
2010-08-08 00:59:58 +00:00
|
|
|
int16 height = rect.height();
|
2010-08-08 00:42:59 +00:00
|
|
|
|
2011-01-16 16:29:43 +00:00
|
|
|
byte *dst = (byte *)dstSurf.pixels + (rect.top * dstSurf.pitch) + rect.left;
|
2010-08-08 00:42:59 +00:00
|
|
|
while (height > 1) {
|
2010-08-08 00:59:58 +00:00
|
|
|
memcpy(dst , src, rect.width());
|
2011-01-16 16:29:43 +00:00
|
|
|
memcpy(dst + dstSurf.pitch, src, rect.width());
|
2010-08-08 00:42:59 +00:00
|
|
|
|
|
|
|
height -= 2;
|
2010-08-08 00:59:58 +00:00
|
|
|
src += srcRect.width();
|
2011-01-16 16:29:43 +00:00
|
|
|
dst += 2 * dstSurf.pitch;
|
2010-08-08 00:42:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (height == 1)
|
2010-08-08 00:59:58 +00:00
|
|
|
memcpy(dst, src, rect.width());
|
2010-08-08 00:42:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// A sparse block
|
2011-01-23 19:08:09 +00:00
|
|
|
void CoktelDecoder::renderBlockSparse(Graphics::Surface &dstSurf, const byte *src, Common::Rect &rect) {
|
2010-08-08 00:59:58 +00:00
|
|
|
Common::Rect srcRect = rect;
|
2010-08-08 00:42:59 +00:00
|
|
|
|
2011-01-16 16:29:43 +00:00
|
|
|
rect.clip(dstSurf.w, dstSurf.h);
|
2010-08-08 00:42:59 +00:00
|
|
|
|
2011-01-16 16:29:43 +00:00
|
|
|
byte *dst = (byte *)dstSurf.pixels + (rect.top * dstSurf.pitch) + rect.left;
|
2010-08-08 00:59:58 +00:00
|
|
|
for (int i = 0; i < rect.height(); i++) {
|
2010-08-08 00:42:59 +00:00
|
|
|
byte *dstRow = dst;
|
|
|
|
int16 pixWritten = 0;
|
|
|
|
|
2010-08-08 00:59:58 +00:00
|
|
|
while (pixWritten < srcRect.width()) {
|
2010-08-08 00:42:59 +00:00
|
|
|
int16 pixCount = *src++;
|
|
|
|
|
|
|
|
if (pixCount & 0x80) { // Data
|
|
|
|
int16 copyCount;
|
|
|
|
|
2010-08-08 00:59:58 +00:00
|
|
|
pixCount = MIN((pixCount & 0x7F) + 1, srcRect.width() - pixWritten);
|
|
|
|
copyCount = CLIP<int16>(rect.width() - pixWritten, 0, pixCount);
|
2010-08-08 00:42:59 +00:00
|
|
|
memcpy(dstRow, src, copyCount);
|
|
|
|
|
|
|
|
pixWritten += pixCount;
|
|
|
|
dstRow += pixCount;
|
|
|
|
src += pixCount;
|
|
|
|
} else { // "Hole"
|
|
|
|
pixWritten += pixCount + 1;
|
|
|
|
dstRow += pixCount + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-01-16 16:29:43 +00:00
|
|
|
dst += dstSurf.pitch;
|
2010-08-08 00:42:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// A half-high sparse block
|
2011-01-23 19:08:09 +00:00
|
|
|
void CoktelDecoder::renderBlockSparse2Y(Graphics::Surface &dstSurf, const byte *src, Common::Rect &rect) {
|
2010-08-08 00:42:59 +00:00
|
|
|
warning("renderBlockSparse2Y");
|
|
|
|
|
2010-08-08 00:59:58 +00:00
|
|
|
Common::Rect srcRect = rect;
|
2010-08-08 00:42:59 +00:00
|
|
|
|
2011-01-16 16:29:43 +00:00
|
|
|
rect.clip(dstSurf.w, dstSurf.h);
|
2010-08-08 00:42:59 +00:00
|
|
|
|
2011-01-16 16:29:43 +00:00
|
|
|
byte *dst = (byte *)dstSurf.pixels + (rect.top * dstSurf.pitch) + rect.left;
|
2010-08-08 00:59:58 +00:00
|
|
|
for (int i = 0; i < rect.height(); i += 2) {
|
2010-08-08 00:42:59 +00:00
|
|
|
byte *dstRow = dst;
|
|
|
|
int16 pixWritten = 0;
|
|
|
|
|
2010-08-08 00:59:58 +00:00
|
|
|
while (pixWritten < srcRect.width()) {
|
2010-08-08 00:42:59 +00:00
|
|
|
int16 pixCount = *src++;
|
|
|
|
|
|
|
|
if (pixCount & 0x80) { // Data
|
|
|
|
int16 copyCount;
|
|
|
|
|
2010-08-08 00:59:58 +00:00
|
|
|
pixCount = MIN((pixCount & 0x7F) + 1, srcRect.width() - pixWritten);
|
|
|
|
copyCount = CLIP<int16>(rect.width() - pixWritten, 0, pixCount);
|
2010-08-08 00:42:59 +00:00
|
|
|
memcpy(dstRow , src, pixCount);
|
2011-01-16 16:29:43 +00:00
|
|
|
memcpy(dstRow + dstSurf.pitch, src, pixCount);
|
2010-08-08 00:42:59 +00:00
|
|
|
|
|
|
|
pixWritten += pixCount;
|
|
|
|
dstRow += pixCount;
|
|
|
|
src += pixCount;
|
|
|
|
} else { // "Hole"
|
|
|
|
pixWritten += pixCount + 1;
|
|
|
|
dstRow += pixCount + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-01-16 16:29:43 +00:00
|
|
|
dst += dstSurf.pitch;
|
2010-08-08 00:42:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-23 19:08:09 +00:00
|
|
|
void CoktelDecoder::renderBlockRLE(Graphics::Surface &dstSurf, const byte *src, Common::Rect &rect) {
|
2010-08-08 01:01:17 +00:00
|
|
|
Common::Rect srcRect = rect;
|
2010-08-08 01:00:23 +00:00
|
|
|
|
2011-01-16 16:29:43 +00:00
|
|
|
rect.clip(dstSurf.w, dstSurf.h);
|
2010-08-08 01:01:17 +00:00
|
|
|
|
2011-01-16 16:29:43 +00:00
|
|
|
byte *dst = (byte *)dstSurf.pixels + (rect.top * dstSurf.pitch) + rect.left;
|
2010-08-08 01:01:17 +00:00
|
|
|
for (int i = 0; i < rect.height(); i++) {
|
|
|
|
byte *dstRow = dst;
|
|
|
|
int16 pixWritten = 0;
|
|
|
|
|
|
|
|
while (pixWritten < srcRect.width()) {
|
|
|
|
int16 pixCount = *src++;
|
|
|
|
|
|
|
|
if (pixCount & 0x80) {
|
|
|
|
int16 copyCount;
|
|
|
|
|
|
|
|
pixCount = MIN((pixCount & 0x7F) + 1, srcRect.width() - pixWritten);
|
|
|
|
copyCount = CLIP<int16>(rect.width() - pixWritten, 0, pixCount);
|
|
|
|
|
|
|
|
if (*src != 0xFF) { // Normal copy
|
|
|
|
|
|
|
|
memcpy(dstRow, src, copyCount);
|
|
|
|
dstRow += copyCount;
|
|
|
|
src += pixCount;
|
|
|
|
} else
|
|
|
|
deRLE(dstRow, src, copyCount, pixCount);
|
|
|
|
|
|
|
|
pixWritten += pixCount;
|
|
|
|
} else { // "Hole"
|
|
|
|
int16 copyCount = CLIP<int16>(rect.width() - pixWritten, 0, pixCount + 1);
|
|
|
|
|
|
|
|
dstRow += copyCount;
|
|
|
|
pixWritten += pixCount + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-01-16 16:29:43 +00:00
|
|
|
dst += dstSurf.pitch;
|
2010-08-08 01:01:17 +00:00
|
|
|
}
|
2010-08-08 01:00:23 +00:00
|
|
|
}
|
|
|
|
|
2010-08-08 00:33:59 +00:00
|
|
|
Common::Rational CoktelDecoder::getFrameRate() const {
|
|
|
|
return _frameRate;
|
|
|
|
}
|
|
|
|
|
2011-01-20 03:22:43 +00:00
|
|
|
uint32 CoktelDecoder::getStaticTimeToNextFrame() const {
|
|
|
|
return (1000 / _frameRate).toInt();
|
|
|
|
}
|
|
|
|
|
2010-08-08 00:42:30 +00:00
|
|
|
inline void CoktelDecoder::unsignedToSigned(byte *buffer, int length) {
|
|
|
|
while (length-- > 0) *buffer++ ^= 0x80;
|
|
|
|
}
|
|
|
|
|
2010-08-08 00:33:59 +00:00
|
|
|
|
|
|
|
PreIMDDecoder::PreIMDDecoder(uint16 width, uint16 height,
|
2010-08-08 01:07:17 +00:00
|
|
|
Audio::Mixer *mixer, Audio::Mixer::SoundType soundType) : CoktelDecoder(mixer, soundType),
|
2010-08-08 00:36:19 +00:00
|
|
|
_stream(0), _videoBuffer(0), _videoBufferSize(0) {
|
2010-08-08 00:33:59 +00:00
|
|
|
|
|
|
|
_width = width;
|
|
|
|
_height = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
PreIMDDecoder::~PreIMDDecoder() {
|
2010-08-08 00:36:19 +00:00
|
|
|
close();
|
2010-08-08 00:33:59 +00:00
|
|
|
}
|
|
|
|
|
2010-08-08 00:36:19 +00:00
|
|
|
bool PreIMDDecoder::seek(int32 frame, int whence, bool restart) {
|
2010-08-08 00:56:29 +00:00
|
|
|
if (!evaluateSeekFrame(frame, whence))
|
2010-08-08 00:36:19 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (frame == _curFrame)
|
|
|
|
// Nothing to do
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Run through the frames
|
|
|
|
_curFrame = -1;
|
|
|
|
_stream->seek(2);
|
|
|
|
while (_curFrame != frame) {
|
|
|
|
uint16 frameSize = _stream->readUint16LE();
|
|
|
|
|
|
|
|
_stream->skip(frameSize + 2);
|
|
|
|
|
|
|
|
_curFrame++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2010-08-08 00:33:59 +00:00
|
|
|
}
|
|
|
|
|
2011-02-07 17:54:16 +00:00
|
|
|
bool PreIMDDecoder::loadStream(Common::SeekableReadStream *stream) {
|
2010-08-08 00:36:19 +00:00
|
|
|
// Since PreIMDs don't have any width and height values stored,
|
|
|
|
// we need them to be specified in the constructor
|
|
|
|
assert((_width > 0) && (_height > 0));
|
|
|
|
|
|
|
|
close();
|
|
|
|
|
2010-08-08 00:58:00 +00:00
|
|
|
_stream = stream;
|
2010-08-08 00:36:19 +00:00
|
|
|
|
|
|
|
_stream->seek(0);
|
|
|
|
|
|
|
|
_frameCount = _stream->readUint16LE();
|
|
|
|
|
|
|
|
_videoBufferSize = _width * _height;
|
|
|
|
_videoBuffer = new byte[_videoBufferSize];
|
|
|
|
|
|
|
|
memset(_videoBuffer, 0, _videoBufferSize);
|
|
|
|
|
|
|
|
return true;
|
2010-08-08 00:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PreIMDDecoder::close() {
|
2010-08-08 00:36:19 +00:00
|
|
|
reset();
|
|
|
|
|
2010-08-08 00:37:52 +00:00
|
|
|
CoktelDecoder::close();
|
2010-08-08 00:36:19 +00:00
|
|
|
|
|
|
|
delete _stream;
|
|
|
|
|
|
|
|
delete[] _videoBuffer;
|
|
|
|
|
|
|
|
_stream = 0;
|
|
|
|
|
|
|
|
_videoBuffer = 0;
|
|
|
|
_videoBufferSize = 0;
|
2010-08-08 00:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool PreIMDDecoder::isVideoLoaded() const {
|
2010-08-08 00:36:19 +00:00
|
|
|
return _stream != 0;
|
2010-08-08 00:33:59 +00:00
|
|
|
}
|
|
|
|
|
2011-01-23 19:08:09 +00:00
|
|
|
const Graphics::Surface *PreIMDDecoder::decodeNextFrame() {
|
2010-08-08 00:36:19 +00:00
|
|
|
if (!isVideoLoaded() || endOfVideo())
|
|
|
|
return 0;
|
|
|
|
|
2010-08-08 00:37:52 +00:00
|
|
|
createSurface();
|
|
|
|
|
2010-08-08 00:36:19 +00:00
|
|
|
processFrame();
|
|
|
|
renderFrame();
|
|
|
|
|
2010-08-08 00:39:32 +00:00
|
|
|
if (_curFrame == 0)
|
|
|
|
_startTime = g_system->getMillis();
|
|
|
|
|
2010-08-08 00:36:19 +00:00
|
|
|
return &_surface;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PreIMDDecoder::processFrame() {
|
2010-11-08 17:03:27 +00:00
|
|
|
_curFrame++;
|
|
|
|
|
2010-08-08 00:36:19 +00:00
|
|
|
uint16 frameSize = _stream->readUint16LE();
|
2010-11-08 17:03:27 +00:00
|
|
|
if (_stream->eos() || (frameSize == 0))
|
2010-11-04 20:36:28 +00:00
|
|
|
return;
|
2010-08-08 00:36:19 +00:00
|
|
|
|
|
|
|
uint32 nextFramePos = _stream->pos() + frameSize + 2;
|
|
|
|
|
|
|
|
byte cmd;
|
|
|
|
|
|
|
|
cmd = _stream->readByte();
|
|
|
|
frameSize--;
|
|
|
|
|
|
|
|
if (cmd == 0) {
|
2010-08-08 00:52:30 +00:00
|
|
|
// Palette. Ignored by Fascination, though.
|
|
|
|
|
|
|
|
// NOTE: If we ever find another game using this format,
|
|
|
|
// palettes may need to be evaluated.
|
2010-08-08 00:36:19 +00:00
|
|
|
|
|
|
|
_stream->skip(768);
|
|
|
|
|
|
|
|
frameSize -= 769;
|
|
|
|
|
|
|
|
cmd = _stream->readByte();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cmd != 2) {
|
|
|
|
// Partial frame data
|
|
|
|
|
|
|
|
uint32 fSize = frameSize;
|
|
|
|
uint32 vidSize = _videoBufferSize;
|
|
|
|
|
|
|
|
byte *vidBuffer = _videoBuffer;
|
|
|
|
|
|
|
|
while ((fSize > 0) && (vidSize > 0)) {
|
|
|
|
uint32 n = _stream->readByte();
|
|
|
|
fSize--;
|
|
|
|
|
|
|
|
if ((n & 0x80) != 0) {
|
|
|
|
// Data
|
|
|
|
|
|
|
|
n = MIN<uint32>((n & 0x7F) + 1, MIN(fSize, vidSize));
|
|
|
|
|
|
|
|
_stream->read(vidBuffer, n);
|
|
|
|
|
|
|
|
vidBuffer += n;
|
|
|
|
vidSize -= n;
|
|
|
|
fSize -= n;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// Skip
|
|
|
|
|
|
|
|
n = MIN<uint32>(n + 1, vidSize);
|
|
|
|
|
|
|
|
vidBuffer += n;
|
|
|
|
vidSize -= n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// Full direct frame
|
|
|
|
|
|
|
|
uint32 vidSize = MIN<uint32>(_videoBufferSize, frameSize);
|
|
|
|
|
|
|
|
_stream->read(_videoBuffer, vidSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
_stream->seek(nextFramePos);
|
|
|
|
}
|
|
|
|
|
2010-08-08 00:52:30 +00:00
|
|
|
// Just a simple blit
|
2010-08-08 00:36:19 +00:00
|
|
|
void PreIMDDecoder::renderFrame() {
|
2010-08-08 00:39:03 +00:00
|
|
|
_dirtyRects.clear();
|
|
|
|
|
2010-08-08 00:38:26 +00:00
|
|
|
uint16 w = CLIP<int32>(_surface.w - _x, 0, _width);
|
|
|
|
uint16 h = CLIP<int32>(_surface.h - _y, 0, _height);
|
2010-08-08 00:36:19 +00:00
|
|
|
|
|
|
|
const byte *src = _videoBuffer;
|
2010-08-08 00:52:30 +00:00
|
|
|
byte *dst = (byte *)_surface.pixels + (_y * _surface.pitch) + _x;
|
2010-08-08 00:36:19 +00:00
|
|
|
|
|
|
|
uint32 frameDataSize = _videoBufferSize;
|
|
|
|
|
|
|
|
while (h-- > 0) {
|
|
|
|
uint32 n = MIN<uint32>(w, frameDataSize);
|
|
|
|
|
|
|
|
memcpy(dst, src, n);
|
|
|
|
|
|
|
|
src += _width;
|
|
|
|
dst += _surface.pitch;
|
|
|
|
|
|
|
|
frameDataSize -= n;
|
|
|
|
}
|
2010-08-08 00:39:03 +00:00
|
|
|
|
|
|
|
_dirtyRects.push_back(Common::Rect(_x, _y, _x + _width, _y + _height));
|
2010-08-08 00:33:59 +00:00
|
|
|
}
|
|
|
|
|
2011-01-23 19:08:09 +00:00
|
|
|
Graphics::PixelFormat PreIMDDecoder::getPixelFormat() const {
|
|
|
|
return Graphics::PixelFormat::createFormatCLUT8();
|
2010-08-08 00:33:59 +00:00
|
|
|
}
|
|
|
|
|
2010-08-08 00:40:24 +00:00
|
|
|
|
2010-08-08 01:07:17 +00:00
|
|
|
IMDDecoder::IMDDecoder(Audio::Mixer *mixer, Audio::Mixer::SoundType soundType) : CoktelDecoder(mixer, soundType),
|
2010-08-08 00:41:56 +00:00
|
|
|
_stream(0), _version(0), _stdX(-1), _stdY(-1), _stdWidth(-1), _stdHeight(-1),
|
2011-01-16 16:26:52 +00:00
|
|
|
_flags(0), _firstFramePos(0), _framePos(0), _frameCoords(0), _videoBufferSize(0),
|
2010-08-08 00:41:56 +00:00
|
|
|
_soundFlags(0), _soundFreq(0), _soundSliceSize(0), _soundSlicesCount(0) {
|
|
|
|
|
2011-01-16 16:26:52 +00:00
|
|
|
_videoBuffer [0] = 0;
|
|
|
|
_videoBuffer [1] = 0;
|
|
|
|
_videoBufferLen[0] = 0;
|
|
|
|
_videoBufferLen[1] = 0;
|
2010-08-08 00:40:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
IMDDecoder::~IMDDecoder() {
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IMDDecoder::seek(int32 frame, int whence, bool restart) {
|
2010-08-08 00:56:29 +00:00
|
|
|
if (!evaluateSeekFrame(frame, whence))
|
2010-08-08 00:40:24 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (frame == _curFrame)
|
|
|
|
// Nothing to do
|
|
|
|
return true;
|
|
|
|
|
2010-08-08 00:41:56 +00:00
|
|
|
// Try every possible way to find a file offset to that frame
|
|
|
|
uint32 framePos = 0;
|
|
|
|
if (frame == -1) {
|
2010-08-08 00:52:30 +00:00
|
|
|
// First frame, we know that position
|
2010-08-08 00:41:56 +00:00
|
|
|
|
|
|
|
framePos = _firstFramePos;
|
|
|
|
|
|
|
|
} else if (frame == 0) {
|
2010-08-08 00:52:30 +00:00
|
|
|
// Second frame, can be calculated from the first frame's position
|
2010-08-08 00:41:56 +00:00
|
|
|
|
|
|
|
framePos = _firstFramePos;
|
|
|
|
_stream->seek(framePos);
|
|
|
|
framePos += _stream->readUint16LE() + 4;
|
|
|
|
|
|
|
|
} else if (_framePos) {
|
2010-08-08 00:52:30 +00:00
|
|
|
// If we have an array of frame positions, use that
|
2010-08-08 00:41:56 +00:00
|
|
|
|
|
|
|
framePos = _framePos[frame + 1];
|
|
|
|
|
|
|
|
} else if (restart && (_soundStage == kSoundNone)) {
|
2010-08-08 00:52:30 +00:00
|
|
|
// If we are asked to restart the video if necessary and have no
|
|
|
|
// audio to worry about, restart the video and run through the frames
|
2010-08-08 00:41:56 +00:00
|
|
|
|
2010-08-08 00:49:15 +00:00
|
|
|
_curFrame = 0;
|
|
|
|
_stream->seek(_firstFramePos);
|
|
|
|
|
2010-08-08 00:41:56 +00:00
|
|
|
for (int i = ((frame > _curFrame) ? _curFrame : 0); i <= frame; i++)
|
|
|
|
processFrame();
|
|
|
|
|
2010-08-08 00:47:25 +00:00
|
|
|
return true;
|
|
|
|
|
2010-08-08 00:41:56 +00:00
|
|
|
} else {
|
2010-08-08 00:52:30 +00:00
|
|
|
// Not possible
|
|
|
|
|
2010-08-08 00:42:59 +00:00
|
|
|
warning("IMDDecoder::seek(): Frame %d is not directly accessible", frame + 1);
|
2010-08-08 00:41:56 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Seek
|
|
|
|
_stream->seek(framePos);
|
|
|
|
_curFrame = frame;
|
2010-08-08 00:40:24 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-08-08 00:42:59 +00:00
|
|
|
void IMDDecoder::setXY(uint16 x, uint16 y) {
|
|
|
|
// Adjusting the standard coordinates
|
|
|
|
if (_stdX != -1) {
|
|
|
|
if (x != 0xFFFF)
|
|
|
|
_stdX = _stdX - _x + x;
|
|
|
|
if (y != 0xFFFF)
|
|
|
|
_stdY = _stdY - _y + y;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Going through the coordinate table as well
|
|
|
|
if (_frameCoords) {
|
|
|
|
for (uint32 i = 0; i < _frameCount; i++) {
|
|
|
|
if (_frameCoords[i].left != -1) {
|
|
|
|
if (x != 0xFFFF) {
|
|
|
|
_frameCoords[i].left = _frameCoords[i].left - _x + x;
|
|
|
|
_frameCoords[i].right = _frameCoords[i].right - _x + x;
|
|
|
|
}
|
|
|
|
if (y != 0xFFFF) {
|
|
|
|
_frameCoords[i].top = _frameCoords[i].top - _y + y;
|
|
|
|
_frameCoords[i].bottom = _frameCoords[i].bottom - _y + y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (x != 0xFFFF)
|
|
|
|
_x = x;
|
|
|
|
if (y != 0xFFFF)
|
|
|
|
_y = y;
|
|
|
|
}
|
|
|
|
|
2011-02-07 17:54:16 +00:00
|
|
|
bool IMDDecoder::loadStream(Common::SeekableReadStream *stream) {
|
2010-08-08 00:40:24 +00:00
|
|
|
close();
|
|
|
|
|
2010-08-08 00:58:00 +00:00
|
|
|
_stream = stream;
|
2010-08-08 00:40:24 +00:00
|
|
|
|
2010-08-08 00:41:56 +00:00
|
|
|
uint16 handle;
|
2010-08-08 00:40:24 +00:00
|
|
|
|
2010-08-08 00:41:56 +00:00
|
|
|
handle = _stream->readUint16LE();
|
|
|
|
_version = _stream->readByte();
|
|
|
|
|
|
|
|
// Version checking
|
|
|
|
if ((handle != 0) || (_version < 2)) {
|
2011-02-07 17:54:16 +00:00
|
|
|
warning("IMDDecoder::loadStream(): Version incorrect (%d, 0x%X)", handle, _version);
|
2010-08-08 00:41:56 +00:00
|
|
|
close();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rest header
|
|
|
|
_features = _stream->readByte();
|
|
|
|
_frameCount = _stream->readUint16LE();
|
|
|
|
_defaultX = _stream->readSint16LE();
|
|
|
|
_defaultY = _stream->readSint16LE();
|
|
|
|
_width = _stream->readSint16LE();
|
|
|
|
_height = _stream->readSint16LE();
|
|
|
|
_flags = _stream->readUint16LE();
|
|
|
|
_firstFramePos = _stream->readUint16LE();
|
|
|
|
|
|
|
|
_x = _defaultX;
|
|
|
|
_y = _defaultY;
|
|
|
|
|
|
|
|
// IMDs always have video
|
|
|
|
_features |= kFeaturesVideo;
|
|
|
|
// IMDs always have palettes
|
|
|
|
_features |= kFeaturesPalette;
|
|
|
|
|
|
|
|
// Palette
|
2010-08-08 01:08:17 +00:00
|
|
|
for (int i = 0; i < 768; i++)
|
|
|
|
_palette[i] = _stream->readByte() << 2;
|
2010-08-08 00:41:56 +00:00
|
|
|
|
|
|
|
_paletteDirty = true;
|
|
|
|
|
|
|
|
if (!loadCoordinates()) {
|
|
|
|
close();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32 framePosPos, frameCoordsPos;
|
|
|
|
if (!loadFrameTableOffsets(framePosPos, frameCoordsPos)) {
|
|
|
|
close();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!assessAudioProperties()) {
|
|
|
|
close();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!assessVideoProperties()) {
|
|
|
|
close();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!loadFrameTables(framePosPos, frameCoordsPos)) {
|
|
|
|
close();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Seek to the first frame
|
|
|
|
_stream->seek(_firstFramePos);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IMDDecoder::loadCoordinates() {
|
|
|
|
// Standard coordinates
|
|
|
|
if (_version >= 3) {
|
|
|
|
uint16 count = _stream->readUint16LE();
|
|
|
|
if (count > 1) {
|
2010-08-08 00:42:59 +00:00
|
|
|
warning("IMDDecoder::loadCoordinates(): More than one standard coordinate quad found (%d)", count);
|
2010-08-08 00:41:56 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count != 0) {
|
|
|
|
_stdX = _stream->readSint16LE();
|
|
|
|
_stdY = _stream->readSint16LE();
|
|
|
|
_stdWidth = _stream->readSint16LE();
|
|
|
|
_stdHeight = _stream->readSint16LE();
|
|
|
|
_features |= kFeaturesStdCoords;
|
|
|
|
} else
|
|
|
|
_stdX = _stdY = _stdWidth = _stdHeight = -1;
|
2010-08-08 00:40:24 +00:00
|
|
|
|
2010-08-08 00:41:56 +00:00
|
|
|
} else
|
|
|
|
_stdX = _stdY = _stdWidth = _stdHeight = -1;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IMDDecoder::loadFrameTableOffsets(uint32 &framePosPos, uint32 &frameCoordsPos) {
|
|
|
|
framePosPos = 0;
|
|
|
|
frameCoordsPos = 0;
|
|
|
|
|
|
|
|
// Frame positions
|
|
|
|
if (_version >= 4) {
|
|
|
|
framePosPos = _stream->readUint32LE();
|
|
|
|
if (framePosPos != 0) {
|
|
|
|
_framePos = new uint32[_frameCount];
|
|
|
|
_features |= kFeaturesFramePos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Frame coordinates
|
|
|
|
if (_features & kFeaturesFrameCoords)
|
|
|
|
frameCoordsPos = _stream->readUint32LE();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IMDDecoder::assessVideoProperties() {
|
2011-01-16 16:26:52 +00:00
|
|
|
uint32 suggestedVideoBufferSize = 0;
|
|
|
|
|
2010-08-08 00:41:56 +00:00
|
|
|
// Sizes of the frame data and extra video buffer
|
|
|
|
if (_features & kFeaturesDataSize) {
|
2011-01-16 16:26:52 +00:00
|
|
|
uint32 size1, size2;
|
|
|
|
|
|
|
|
size1 = _stream->readUint16LE();
|
|
|
|
if (size1 == 0) {
|
|
|
|
size1 = _stream->readUint32LE();
|
|
|
|
size2 = _stream->readUint32LE();
|
2010-08-08 00:41:56 +00:00
|
|
|
} else
|
2011-01-16 16:26:52 +00:00
|
|
|
size2 = _stream->readUint16LE();
|
|
|
|
|
|
|
|
suggestedVideoBufferSize = MAX(size1, size2);
|
2010-08-08 00:41:56 +00:00
|
|
|
}
|
|
|
|
|
2011-01-16 16:26:52 +00:00
|
|
|
_videoBufferSize = _width * _height + 1000;
|
|
|
|
|
|
|
|
if (suggestedVideoBufferSize > _videoBufferSize) {
|
|
|
|
warning("Suggested video buffer size greater than what should be needed (%d, %d, %dx%d",
|
|
|
|
suggestedVideoBufferSize, _videoBufferSize, _width, _height);
|
|
|
|
|
|
|
|
_videoBufferSize = suggestedVideoBufferSize;
|
|
|
|
}
|
2010-08-08 00:41:56 +00:00
|
|
|
|
2011-01-16 16:26:52 +00:00
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
_videoBuffer[i] = new byte[_videoBufferSize];
|
|
|
|
memset(_videoBuffer[i], 0, _videoBufferSize);
|
|
|
|
}
|
2010-08-08 00:41:56 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IMDDecoder::assessAudioProperties() {
|
|
|
|
if (_features & kFeaturesSound) {
|
|
|
|
_soundFreq = _stream->readSint16LE();
|
|
|
|
_soundSliceSize = _stream->readSint16LE();
|
|
|
|
_soundSlicesCount = _stream->readSint16LE();
|
|
|
|
|
|
|
|
if (_soundFreq < 0)
|
|
|
|
_soundFreq = -_soundFreq;
|
|
|
|
|
|
|
|
if (_soundSlicesCount < 0)
|
|
|
|
_soundSlicesCount = -_soundSlicesCount - 1;
|
|
|
|
|
|
|
|
if (_soundSlicesCount > 40) {
|
|
|
|
warning("IMDDecoder::assessAudioProperties(): More than 40 sound slices found (%d)", _soundSlicesCount);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-08-08 17:51:50 +00:00
|
|
|
_frameRate = Common::Rational(_soundFreq, _soundSliceSize);
|
2010-08-08 00:41:56 +00:00
|
|
|
|
2010-08-08 00:42:30 +00:00
|
|
|
_hasSound = true;
|
|
|
|
_soundEnabled = true;
|
|
|
|
_soundStage = kSoundLoaded;
|
2010-08-08 00:41:56 +00:00
|
|
|
|
|
|
|
_audioStream = Audio::makeQueuingAudioStream(_soundFreq, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IMDDecoder::loadFrameTables(uint32 framePosPos, uint32 frameCoordsPos) {
|
|
|
|
// Positions table
|
|
|
|
if (_framePos) {
|
|
|
|
_stream->seek(framePosPos);
|
|
|
|
for (uint32 i = 0; i < _frameCount; i++)
|
|
|
|
_framePos[i] = _stream->readUint32LE();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Coordinates table
|
|
|
|
if (_features & kFeaturesFrameCoords) {
|
|
|
|
_stream->seek(frameCoordsPos);
|
|
|
|
_frameCoords = new Coord[_frameCount];
|
|
|
|
assert(_frameCoords);
|
|
|
|
for (uint32 i = 0; i < _frameCount; i++) {
|
|
|
|
_frameCoords[i].left = _stream->readSint16LE();
|
|
|
|
_frameCoords[i].top = _stream->readSint16LE();
|
|
|
|
_frameCoords[i].right = _stream->readSint16LE();
|
|
|
|
_frameCoords[i].bottom = _stream->readSint16LE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2010-08-08 00:40:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void IMDDecoder::close() {
|
|
|
|
reset();
|
|
|
|
|
|
|
|
CoktelDecoder::close();
|
|
|
|
|
|
|
|
delete _stream;
|
|
|
|
|
2010-08-08 00:41:56 +00:00
|
|
|
delete[] _framePos;
|
|
|
|
delete[] _frameCoords;
|
|
|
|
|
2011-01-16 16:26:52 +00:00
|
|
|
delete[] _videoBuffer[0];
|
|
|
|
delete[] _videoBuffer[1];
|
2010-08-08 00:40:24 +00:00
|
|
|
|
|
|
|
_stream = 0;
|
|
|
|
|
2010-08-08 00:41:56 +00:00
|
|
|
_version = 0;
|
|
|
|
|
|
|
|
_stdX = -1;
|
|
|
|
_stdY = -1;
|
|
|
|
_stdWidth = -1;
|
|
|
|
_stdHeight = -1;
|
|
|
|
|
|
|
|
_flags = 0;
|
|
|
|
|
|
|
|
_firstFramePos = 0;
|
|
|
|
_framePos = 0;
|
|
|
|
_frameCoords = 0;
|
|
|
|
|
2011-01-16 16:26:52 +00:00
|
|
|
_videoBufferSize = 0;
|
|
|
|
_videoBuffer [0] = 0;
|
|
|
|
_videoBuffer [1] = 0;
|
|
|
|
_videoBufferLen[0] = 0;
|
|
|
|
_videoBufferLen[1] = 0;
|
2010-08-08 00:41:56 +00:00
|
|
|
|
|
|
|
_soundFlags = 0;
|
|
|
|
_soundFreq = 0;
|
|
|
|
_soundSliceSize = 0;
|
|
|
|
_soundSlicesCount = 0;
|
|
|
|
|
|
|
|
_hasSound = false;
|
|
|
|
_soundEnabled = false;
|
|
|
|
_soundStage = kSoundNone;
|
2010-08-08 00:40:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool IMDDecoder::isVideoLoaded() const {
|
|
|
|
return _stream != 0;
|
|
|
|
}
|
|
|
|
|
2011-01-23 19:08:09 +00:00
|
|
|
const Graphics::Surface *IMDDecoder::decodeNextFrame() {
|
2010-08-08 00:40:24 +00:00
|
|
|
if (!isVideoLoaded() || endOfVideo())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
createSurface();
|
|
|
|
|
|
|
|
processFrame();
|
|
|
|
|
|
|
|
if (_curFrame == 0)
|
|
|
|
_startTime = g_system->getMillis();
|
|
|
|
|
|
|
|
return &_surface;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IMDDecoder::processFrame() {
|
2010-08-08 00:42:30 +00:00
|
|
|
_curFrame++;
|
2010-08-08 00:41:56 +00:00
|
|
|
|
2010-08-08 00:42:30 +00:00
|
|
|
_dirtyRects.clear();
|
|
|
|
|
|
|
|
_paletteDirty = false;
|
|
|
|
|
|
|
|
uint32 cmd = 0;
|
|
|
|
bool hasNextCmd = false;
|
|
|
|
bool startSound = false;
|
|
|
|
|
|
|
|
do {
|
|
|
|
cmd = _stream->readUint16LE();
|
|
|
|
|
|
|
|
if ((cmd & kCommandBreakMask) == kCommandBreak) {
|
|
|
|
// Flow control
|
|
|
|
|
|
|
|
if (cmd == kCommandBreak) {
|
|
|
|
_stream->skip(2);
|
|
|
|
cmd = _stream->readUint16LE();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Break
|
|
|
|
if (cmd == kCommandBreakSkip0) {
|
|
|
|
continue;
|
|
|
|
} else if (cmd == kCommandBreakSkip16) {
|
|
|
|
cmd = _stream->readUint16LE();
|
|
|
|
_stream->skip(cmd);
|
|
|
|
continue;
|
|
|
|
} else if (cmd == kCommandBreakSkip32) {
|
|
|
|
cmd = _stream->readUint32LE();
|
|
|
|
_stream->skip(cmd);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Audio
|
2010-08-08 00:51:33 +00:00
|
|
|
if (cmd == kCommandNextSound) {
|
2010-08-08 00:42:30 +00:00
|
|
|
|
2010-08-08 00:51:33 +00:00
|
|
|
nextSoundSlice(hasNextCmd);
|
|
|
|
cmd = _stream->readUint16LE();
|
2010-08-08 00:42:30 +00:00
|
|
|
|
2010-08-08 00:51:33 +00:00
|
|
|
} else if (cmd == kCommandStartSound) {
|
2010-08-08 00:42:30 +00:00
|
|
|
|
2010-08-08 00:51:33 +00:00
|
|
|
startSound = initialSoundSlice(hasNextCmd);
|
|
|
|
cmd = _stream->readUint16LE();
|
2010-08-08 00:42:30 +00:00
|
|
|
|
2010-08-08 00:51:33 +00:00
|
|
|
} else
|
|
|
|
emptySoundSlice(hasNextCmd);
|
2010-08-08 00:42:30 +00:00
|
|
|
|
|
|
|
// Set palette
|
|
|
|
if (cmd == kCommandPalette) {
|
|
|
|
_stream->skip(2);
|
|
|
|
|
|
|
|
_paletteDirty = true;
|
|
|
|
|
2010-08-08 01:08:17 +00:00
|
|
|
for (int i = 0; i < 768; i++)
|
|
|
|
_palette[i] = _stream->readByte() << 2;
|
|
|
|
|
2010-08-08 00:42:30 +00:00
|
|
|
cmd = _stream->readUint16LE();
|
|
|
|
}
|
|
|
|
|
|
|
|
hasNextCmd = false;
|
|
|
|
|
|
|
|
if (cmd == kCommandJump) {
|
|
|
|
// Jump to frame
|
|
|
|
|
|
|
|
int16 frame = _stream->readSint16LE();
|
|
|
|
if (_framePos) {
|
|
|
|
_curFrame = frame - 1;
|
|
|
|
_stream->seek(_framePos[frame]);
|
|
|
|
|
|
|
|
hasNextCmd = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (cmd == kCommandVideoData) {
|
2010-08-08 00:42:59 +00:00
|
|
|
|
2011-01-16 16:26:52 +00:00
|
|
|
_videoBufferLen[0] = _stream->readUint32LE() + 2;
|
|
|
|
_stream->read(_videoBuffer[0], _videoBufferLen[0]);
|
2010-08-08 00:59:58 +00:00
|
|
|
|
|
|
|
Common::Rect rect = calcFrameCoords(_curFrame);
|
|
|
|
|
|
|
|
if (renderFrame(rect))
|
|
|
|
_dirtyRects.push_back(rect);
|
2010-08-08 00:42:30 +00:00
|
|
|
|
2010-08-08 00:42:59 +00:00
|
|
|
} else if (cmd != 0) {
|
|
|
|
|
2011-01-16 16:26:52 +00:00
|
|
|
_videoBufferLen[0] = cmd + 2;
|
|
|
|
_stream->read(_videoBuffer[0], _videoBufferLen[0]);
|
2010-08-08 00:59:58 +00:00
|
|
|
|
|
|
|
Common::Rect rect = calcFrameCoords(_curFrame);
|
|
|
|
|
|
|
|
if (renderFrame(rect))
|
|
|
|
_dirtyRects.push_back(rect);
|
|
|
|
|
2010-08-08 00:42:59 +00:00
|
|
|
}
|
2010-08-08 00:42:30 +00:00
|
|
|
|
|
|
|
} while (hasNextCmd);
|
|
|
|
|
2010-08-08 00:52:30 +00:00
|
|
|
// Start the audio stream if necessary
|
2010-08-08 00:42:30 +00:00
|
|
|
if (startSound && _soundEnabled) {
|
2011-01-20 17:07:17 +00:00
|
|
|
_mixer->playStream(_soundType, &_audioHandle, _audioStream,
|
|
|
|
-1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO);
|
2010-08-08 00:42:30 +00:00
|
|
|
_soundStage = kSoundPlaying;
|
|
|
|
}
|
|
|
|
|
2010-08-08 00:52:30 +00:00
|
|
|
// End the audio stream if necessary
|
2010-08-08 00:42:30 +00:00
|
|
|
if ((_curFrame >= (int32)(_frameCount - 1)) && (_soundStage == kSoundPlaying)) {
|
|
|
|
_audioStream->finish();
|
2011-01-20 17:07:17 +00:00
|
|
|
_soundStage = kSoundFinished;
|
2010-08-08 00:42:30 +00:00
|
|
|
}
|
2010-08-08 00:41:56 +00:00
|
|
|
|
2010-08-08 00:40:24 +00:00
|
|
|
}
|
|
|
|
|
2010-08-08 00:59:58 +00:00
|
|
|
Common::Rect IMDDecoder::calcFrameCoords(uint32 frame) {
|
|
|
|
Common::Rect rect;
|
2010-08-08 00:52:30 +00:00
|
|
|
|
|
|
|
if (frame == 0) {
|
|
|
|
// First frame is always a full "keyframe"
|
|
|
|
|
2010-08-08 00:59:58 +00:00
|
|
|
rect.left = _x;
|
|
|
|
rect.top = _y;
|
|
|
|
rect.right = _x + _width;
|
|
|
|
rect.bottom = _y + _height;
|
2010-08-08 00:52:30 +00:00
|
|
|
} else if (_frameCoords && ((_frameCoords[frame].left != -1))) {
|
|
|
|
// We have frame coordinates for that frame
|
|
|
|
|
2010-08-08 00:59:58 +00:00
|
|
|
rect.left = _frameCoords[frame].left;
|
|
|
|
rect.top = _frameCoords[frame].top;
|
|
|
|
rect.right = _frameCoords[frame].right + 1;
|
|
|
|
rect.bottom = _frameCoords[frame].bottom + 1;
|
2010-08-08 00:52:30 +00:00
|
|
|
} else if (_stdX != -1) {
|
|
|
|
// We have standard coordinates
|
|
|
|
|
2010-08-08 00:59:58 +00:00
|
|
|
rect.left = _stdX;
|
|
|
|
rect.top = _stdY;
|
|
|
|
rect.right = _stdX + _stdWidth;
|
|
|
|
rect.bottom = _stdY + _stdHeight;
|
2010-08-08 00:52:30 +00:00
|
|
|
} else {
|
|
|
|
// Otherwise, it must be a full "keyframe"
|
|
|
|
|
2010-08-08 00:59:58 +00:00
|
|
|
rect.left = _x;
|
|
|
|
rect.top = _y;
|
|
|
|
rect.right = _x + _width;
|
|
|
|
rect.bottom = _y + _height;
|
2010-08-08 00:52:30 +00:00
|
|
|
}
|
|
|
|
|
2010-08-08 00:59:58 +00:00
|
|
|
return rect;
|
2010-08-08 00:42:30 +00:00
|
|
|
}
|
|
|
|
|
2010-08-08 00:59:58 +00:00
|
|
|
bool IMDDecoder::renderFrame(Common::Rect &rect) {
|
|
|
|
if (!rect.isValidRect())
|
|
|
|
// Invalid rendering area
|
|
|
|
return false;
|
2010-08-08 00:42:59 +00:00
|
|
|
|
2010-08-08 00:59:58 +00:00
|
|
|
// Clip the rendering area to the video's visible area
|
2010-08-08 00:42:59 +00:00
|
|
|
rect.clip(Common::Rect(_x, _y, _x + _width, _y + _height));
|
2010-08-08 00:59:58 +00:00
|
|
|
if (!rect.isValidRect() || rect.isEmpty())
|
2010-08-08 00:52:30 +00:00
|
|
|
// Result is empty => nothing to do
|
2010-08-08 00:59:58 +00:00
|
|
|
return false;
|
2010-08-08 00:42:59 +00:00
|
|
|
|
2011-01-16 16:27:22 +00:00
|
|
|
byte *dataPtr = _videoBuffer[0];
|
|
|
|
uint32 dataSize = _videoBufferLen[0] - 1;
|
2010-08-08 00:42:59 +00:00
|
|
|
|
|
|
|
uint8 type = *dataPtr++;
|
|
|
|
|
2010-08-08 00:52:30 +00:00
|
|
|
if (type & 0x10) {
|
|
|
|
// Palette data
|
|
|
|
|
2010-08-08 00:42:59 +00:00
|
|
|
// One byte index
|
|
|
|
int index = *dataPtr++;
|
2010-08-08 01:08:17 +00:00
|
|
|
|
|
|
|
int count = MIN((255 - index) * 3, 48);
|
|
|
|
for (int i = 0; i < count; i++)
|
|
|
|
_palette[index * 3 + i] = dataPtr[i] << 2;
|
2010-08-08 00:42:59 +00:00
|
|
|
|
2011-01-16 16:27:22 +00:00
|
|
|
dataPtr += 48;
|
|
|
|
dataSize -= 49;
|
2010-08-08 00:42:59 +00:00
|
|
|
type ^= 0x10;
|
|
|
|
|
|
|
|
_paletteDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type & 0x80) {
|
|
|
|
// Frame data is compressed
|
|
|
|
|
|
|
|
type &= 0x7F;
|
|
|
|
|
2010-08-08 00:52:59 +00:00
|
|
|
if ((type == 2) && (rect.width() == _surface.w) && (_x == 0)) {
|
2010-08-08 00:42:59 +00:00
|
|
|
// Directly uncompress onto the video surface
|
2011-03-29 10:39:51 +00:00
|
|
|
const int offsetX = rect.left * _surface.bytesPerPixel;
|
|
|
|
const int offsetY = (_y + rect.top) * _surface.pitch;
|
|
|
|
const int offset = offsetX + offsetY;
|
2011-01-24 16:06:27 +00:00
|
|
|
|
2011-03-29 10:39:51 +00:00
|
|
|
deLZ77((byte *)_surface.pixels + offset, dataPtr, dataSize,
|
|
|
|
_surface.w * _surface.h * _surface.bytesPerPixel - offset);
|
2010-08-08 00:59:58 +00:00
|
|
|
return true;
|
2010-08-08 00:42:59 +00:00
|
|
|
}
|
|
|
|
|
2011-01-16 16:27:22 +00:00
|
|
|
_videoBufferLen[1] = deLZ77(_videoBuffer[1], dataPtr, dataSize, _videoBufferSize);
|
2010-08-08 00:42:59 +00:00
|
|
|
|
2011-01-16 16:27:22 +00:00
|
|
|
dataPtr = _videoBuffer[1];
|
|
|
|
dataSize = _videoBufferLen[1];
|
2010-08-08 00:42:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Evaluate the block type
|
|
|
|
if (type == 0x01)
|
2011-01-16 16:29:43 +00:00
|
|
|
renderBlockSparse (_surface, dataPtr, rect);
|
2010-08-08 00:42:59 +00:00
|
|
|
else if (type == 0x02)
|
2011-01-16 16:29:43 +00:00
|
|
|
renderBlockWhole (_surface, dataPtr, rect);
|
2010-08-08 00:42:59 +00:00
|
|
|
else if (type == 0x42)
|
2011-01-16 16:29:43 +00:00
|
|
|
renderBlockWhole4X (_surface, dataPtr, rect);
|
2010-08-08 00:42:59 +00:00
|
|
|
else if ((type & 0x0F) == 0x02)
|
2011-01-16 16:29:43 +00:00
|
|
|
renderBlockWhole2Y (_surface, dataPtr, rect);
|
2010-08-08 00:42:59 +00:00
|
|
|
else
|
2011-01-16 16:29:43 +00:00
|
|
|
renderBlockSparse2Y(_surface, dataPtr, rect);
|
2010-08-08 00:59:58 +00:00
|
|
|
|
|
|
|
return true;
|
2010-08-08 00:42:30 +00:00
|
|
|
}
|
2010-08-08 00:41:56 +00:00
|
|
|
|
2010-08-08 00:42:30 +00:00
|
|
|
void IMDDecoder::nextSoundSlice(bool hasNextCmd) {
|
2011-01-19 09:02:07 +00:00
|
|
|
if (hasNextCmd || !_soundEnabled || !_audioStream) {
|
2010-08-08 00:52:30 +00:00
|
|
|
// Skip sound
|
|
|
|
|
2010-08-08 00:42:30 +00:00
|
|
|
_stream->skip(_soundSliceSize);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-08-08 00:52:30 +00:00
|
|
|
// Read, convert, queue
|
|
|
|
|
2010-08-08 00:42:30 +00:00
|
|
|
byte *soundBuf = (byte *)malloc(_soundSliceSize);
|
|
|
|
|
|
|
|
_stream->read(soundBuf, _soundSliceSize);
|
|
|
|
unsignedToSigned(soundBuf, _soundSliceSize);
|
|
|
|
|
|
|
|
_audioStream->queueBuffer(soundBuf, _soundSliceSize, DisposeAfterUse::YES, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IMDDecoder::initialSoundSlice(bool hasNextCmd) {
|
|
|
|
int dataLength = _soundSliceSize * _soundSlicesCount;
|
|
|
|
|
2011-01-19 09:03:09 +00:00
|
|
|
if (hasNextCmd || !_soundEnabled) {
|
2010-08-08 00:52:30 +00:00
|
|
|
// Skip sound
|
|
|
|
|
2010-08-08 00:42:30 +00:00
|
|
|
_stream->skip(dataLength);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-01-20 17:07:17 +00:00
|
|
|
if (!_audioStream || (_soundStage == kSoundFinished)) {
|
|
|
|
delete _audioStream;
|
|
|
|
|
2011-01-19 09:03:09 +00:00
|
|
|
_audioStream = Audio::makeQueuingAudioStream(_soundFreq, false);
|
|
|
|
_soundStage = kSoundLoaded;
|
|
|
|
}
|
|
|
|
|
2010-08-08 00:52:30 +00:00
|
|
|
// Read, convert, queue
|
|
|
|
|
2010-08-08 00:42:30 +00:00
|
|
|
byte *soundBuf = (byte *)malloc(dataLength);
|
|
|
|
|
|
|
|
_stream->read(soundBuf, dataLength);
|
|
|
|
unsignedToSigned(soundBuf, dataLength);
|
|
|
|
|
|
|
|
_audioStream->queueBuffer(soundBuf, dataLength, DisposeAfterUse::YES, 0);
|
|
|
|
|
|
|
|
return _soundStage == kSoundLoaded;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IMDDecoder::emptySoundSlice(bool hasNextCmd) {
|
2011-01-19 09:02:07 +00:00
|
|
|
if (hasNextCmd || !_soundEnabled || !_audioStream)
|
2010-08-08 00:42:30 +00:00
|
|
|
return;
|
|
|
|
|
2010-08-08 00:52:30 +00:00
|
|
|
// Create an empty sound buffer and queue it
|
|
|
|
|
2010-08-08 00:42:30 +00:00
|
|
|
byte *soundBuf = (byte *)malloc(_soundSliceSize);
|
|
|
|
|
|
|
|
memset(soundBuf, 0, _soundSliceSize);
|
|
|
|
|
|
|
|
_audioStream->queueBuffer(soundBuf, _soundSliceSize, DisposeAfterUse::YES, 0);
|
2010-08-08 00:40:24 +00:00
|
|
|
}
|
|
|
|
|
2011-01-23 19:08:09 +00:00
|
|
|
Graphics::PixelFormat IMDDecoder::getPixelFormat() const {
|
|
|
|
return Graphics::PixelFormat::createFormatCLUT8();
|
2010-08-08 00:40:24 +00:00
|
|
|
}
|
|
|
|
|
2010-08-08 00:56:04 +00:00
|
|
|
|
2010-08-08 00:56:58 +00:00
|
|
|
VMDDecoder::File::File() {
|
|
|
|
offset = 0;
|
|
|
|
size = 0;
|
|
|
|
realSize = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VMDDecoder::Part::Part() {
|
|
|
|
type = kPartTypeSeparator;
|
|
|
|
field_1 = 0;
|
|
|
|
field_E = 0;
|
|
|
|
size = 0;
|
|
|
|
left = 0;
|
|
|
|
top = 0;
|
|
|
|
right = 0;
|
|
|
|
bottom = 0;
|
|
|
|
id = 0;
|
|
|
|
flags = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VMDDecoder::Frame::Frame() {
|
|
|
|
parts = 0;
|
|
|
|
offset = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
VMDDecoder::Frame::~Frame() {
|
|
|
|
delete[] parts;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const uint16 VMDDecoder::_tableDPCM[128] = {
|
|
|
|
0x0000, 0x0008, 0x0010, 0x0020, 0x0030, 0x0040, 0x0050, 0x0060, 0x0070, 0x0080,
|
|
|
|
0x0090, 0x00A0, 0x00B0, 0x00C0, 0x00D0, 0x00E0, 0x00F0, 0x0100, 0x0110, 0x0120,
|
|
|
|
0x0130, 0x0140, 0x0150, 0x0160, 0x0170, 0x0180, 0x0190, 0x01A0, 0x01B0, 0x01C0,
|
|
|
|
0x01D0, 0x01E0, 0x01F0, 0x0200, 0x0208, 0x0210, 0x0218, 0x0220, 0x0228, 0x0230,
|
|
|
|
0x0238, 0x0240, 0x0248, 0x0250, 0x0258, 0x0260, 0x0268, 0x0270, 0x0278, 0x0280,
|
|
|
|
0x0288, 0x0290, 0x0298, 0x02A0, 0x02A8, 0x02B0, 0x02B8, 0x02C0, 0x02C8, 0x02D0,
|
|
|
|
0x02D8, 0x02E0, 0x02E8, 0x02F0, 0x02F8, 0x0300, 0x0308, 0x0310, 0x0318, 0x0320,
|
|
|
|
0x0328, 0x0330, 0x0338, 0x0340, 0x0348, 0x0350, 0x0358, 0x0360, 0x0368, 0x0370,
|
|
|
|
0x0378, 0x0380, 0x0388, 0x0390, 0x0398, 0x03A0, 0x03A8, 0x03B0, 0x03B8, 0x03C0,
|
|
|
|
0x03C8, 0x03D0, 0x03D8, 0x03E0, 0x03E8, 0x03F0, 0x03F8, 0x0400, 0x0440, 0x0480,
|
|
|
|
0x04C0, 0x0500, 0x0540, 0x0580, 0x05C0, 0x0600, 0x0640, 0x0680, 0x06C0, 0x0700,
|
|
|
|
0x0740, 0x0780, 0x07C0, 0x0800, 0x0900, 0x0A00, 0x0B00, 0x0C00, 0x0D00, 0x0E00,
|
|
|
|
0x0F00, 0x1000, 0x1400, 0x1800, 0x1C00, 0x2000, 0x3000, 0x4000
|
|
|
|
};
|
|
|
|
|
|
|
|
const int32 VMDDecoder::_tableADPCM[] = {
|
|
|
|
7, 8, 9, 10, 11, 12, 13, 14,
|
|
|
|
16, 17, 19, 21, 23, 25, 28, 31,
|
|
|
|
34, 37, 41, 45, 50, 55, 60, 66,
|
|
|
|
73, 80, 88, 97, 107, 118, 130, 143,
|
|
|
|
157, 173, 190, 209, 230, 253, 279, 307,
|
|
|
|
337, 371, 408, 449, 494, 544, 598, 658,
|
|
|
|
724, 796, 876, 963, 1060, 1166, 1282, 1411,
|
|
|
|
1552, 1707, 1878, 2066, 2272, 2499, 2749, 3024,
|
|
|
|
3327, 3660, 4026, 4428, 4871, 5358, 5894, 6484,
|
|
|
|
7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899,
|
|
|
|
15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794,
|
|
|
|
32767, 0
|
|
|
|
};
|
|
|
|
|
|
|
|
const int32 VMDDecoder::_tableADPCMStep[] = {
|
|
|
|
-1, -1, -1, -1, 2, 4, 6, 8,
|
|
|
|
-1, -1, -1, -1, 2, 4, 6, 8
|
|
|
|
};
|
|
|
|
|
2010-08-08 01:07:17 +00:00
|
|
|
VMDDecoder::VMDDecoder(Audio::Mixer *mixer, Audio::Mixer::SoundType soundType) : CoktelDecoder(mixer, soundType),
|
2010-08-08 00:56:58 +00:00
|
|
|
_stream(0), _version(0), _flags(0), _frameInfoOffset(0), _partsPerFrame(0), _frames(0),
|
|
|
|
_soundFlags(0), _soundFreq(0), _soundSliceSize(0), _soundSlicesCount(0),
|
|
|
|
_soundBytesPerSample(0), _soundStereo(0), _soundHeaderSize(0), _soundDataSize(0),
|
2011-01-24 14:09:47 +00:00
|
|
|
_soundLastFilledFrame(0), _audioFormat(kAudioFormat8bitRaw),
|
|
|
|
_hasVideo(false), _videoCodec(0), _blitMode(0), _bytesPerPixel(0),
|
|
|
|
_firstFramePos(0), _videoBufferSize(0), _externalCodec(false), _codec(0),
|
|
|
|
_subtitle(-1), _isPaletted(true) {
|
2010-08-08 00:56:04 +00:00
|
|
|
|
2011-01-16 16:26:52 +00:00
|
|
|
_videoBuffer [0] = 0;
|
|
|
|
_videoBuffer [1] = 0;
|
2011-01-16 16:29:43 +00:00
|
|
|
_videoBuffer [2] = 0;
|
2011-01-16 16:26:52 +00:00
|
|
|
_videoBufferLen[0] = 0;
|
|
|
|
_videoBufferLen[1] = 0;
|
2011-01-16 16:29:43 +00:00
|
|
|
_videoBufferLen[2] = 0;
|
2010-08-08 00:56:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VMDDecoder::~VMDDecoder() {
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VMDDecoder::seek(int32 frame, int whence, bool restart) {
|
2010-08-08 00:56:29 +00:00
|
|
|
if (!evaluateSeekFrame(frame, whence))
|
2010-08-08 00:56:04 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (frame == _curFrame)
|
|
|
|
// Nothing to do
|
|
|
|
return true;
|
|
|
|
|
2010-08-08 00:58:29 +00:00
|
|
|
// Restart sound
|
2011-01-20 17:07:17 +00:00
|
|
|
if (_hasSound && (frame == -1) &&
|
|
|
|
((_soundStage == kSoundNone) || (_soundStage == kSoundFinished))) {
|
|
|
|
|
|
|
|
delete _audioStream;
|
|
|
|
|
2010-08-08 00:58:29 +00:00
|
|
|
_soundStage = kSoundLoaded;
|
|
|
|
_audioStream = Audio::makeQueuingAudioStream(_soundFreq, _soundStereo != 0);
|
|
|
|
}
|
|
|
|
|
2011-01-22 08:00:57 +00:00
|
|
|
_subtitle = -1;
|
|
|
|
|
|
|
|
if ((_blitMode > 0) && (_flags & 0x4000)) {
|
|
|
|
if (_curFrame > frame) {
|
|
|
|
_stream->seek(_frames[0].offset);
|
|
|
|
_curFrame = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (frame > _curFrame)
|
|
|
|
decodeNextFrame();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-08-08 00:58:29 +00:00
|
|
|
// Seek
|
2010-08-08 01:00:53 +00:00
|
|
|
_stream->seek(_frames[frame + 1].offset);
|
2010-08-08 00:58:29 +00:00
|
|
|
_curFrame = frame;
|
2011-01-20 18:17:39 +00:00
|
|
|
_startTime = g_system->getMillis() - ((frame + 2) * getStaticTimeToNextFrame());
|
2010-08-08 00:56:04 +00:00
|
|
|
|
2010-08-08 01:05:16 +00:00
|
|
|
|
2010-08-08 00:56:04 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-08-08 01:03:50 +00:00
|
|
|
void VMDDecoder::setXY(uint16 x, uint16 y) {
|
2011-01-22 07:20:16 +00:00
|
|
|
uint16 curX = _x;
|
|
|
|
uint16 setX = x;
|
|
|
|
|
|
|
|
if ((x != 0xFFFF) && (_blitMode == 1)) {
|
|
|
|
curX *= _bytesPerPixel;
|
|
|
|
setX *= _bytesPerPixel;
|
|
|
|
}
|
2011-01-16 16:29:43 +00:00
|
|
|
|
2010-08-08 01:03:50 +00:00
|
|
|
for (uint32 i = 0; i < _frameCount; i++) {
|
|
|
|
for (int j = 0; j < _partsPerFrame; j++) {
|
|
|
|
|
|
|
|
if (_frames[i].parts[j].type == kPartTypeVideo) {
|
|
|
|
if (x != 0xFFFF) {
|
2011-01-22 07:20:16 +00:00
|
|
|
_frames[i].parts[j].left = _frames[i].parts[j].left - curX + setX;
|
|
|
|
_frames[i].parts[j].right = _frames[i].parts[j].right - curX + setX;
|
2010-08-08 01:03:50 +00:00
|
|
|
}
|
|
|
|
if (y != 0xFFFF) {
|
|
|
|
_frames[i].parts[j].top = _frames[i].parts[j].top - _y + y;
|
|
|
|
_frames[i].parts[j].bottom = _frames[i].parts[j].bottom - _y + y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (x != 0xFFFF)
|
|
|
|
_x = x;
|
|
|
|
if (y != 0xFFFF)
|
|
|
|
_y = y;
|
|
|
|
}
|
|
|
|
|
2011-01-16 16:27:52 +00:00
|
|
|
bool VMDDecoder::openExternalCodec() {
|
|
|
|
delete _codec;
|
|
|
|
_codec = 0;
|
|
|
|
|
|
|
|
if (_externalCodec) {
|
|
|
|
if (_videoCodec == kVideoCodecIndeo3) {
|
|
|
|
_isPaletted = false;
|
|
|
|
|
|
|
|
#ifdef USE_INDEO3
|
|
|
|
_codec = new Indeo3Decoder(_width, _height);
|
|
|
|
#else
|
|
|
|
warning("VMDDecoder::openExternalCodec(): Indeo3 decoder not compiled in");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
} else {
|
|
|
|
warning("VMDDecoder::openExternalCodec(): Unknown video codec FourCC \"%s\"",
|
|
|
|
tag2str(_videoCodec));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VMDDecoder::colorModeChanged() {
|
|
|
|
openExternalCodec();
|
|
|
|
}
|
|
|
|
|
2011-02-07 17:54:16 +00:00
|
|
|
bool VMDDecoder::loadStream(Common::SeekableReadStream *stream) {
|
2010-08-08 00:56:04 +00:00
|
|
|
close();
|
|
|
|
|
2010-08-08 00:58:00 +00:00
|
|
|
_stream = stream;
|
2010-08-08 00:56:04 +00:00
|
|
|
|
|
|
|
_stream->seek(0);
|
|
|
|
|
2010-08-08 00:56:58 +00:00
|
|
|
uint16 headerLength;
|
|
|
|
uint16 handle;
|
2010-08-08 00:56:04 +00:00
|
|
|
|
2010-08-08 00:56:58 +00:00
|
|
|
headerLength = _stream->readUint16LE();
|
|
|
|
handle = _stream->readUint16LE();
|
|
|
|
_version = _stream->readUint16LE();
|
|
|
|
|
|
|
|
// Version checking
|
|
|
|
if (headerLength == 50) {
|
|
|
|
// Newer version, used in Addy 5 upwards
|
2011-02-07 17:54:16 +00:00
|
|
|
warning("VMDDecoder::loadStream(): TODO: Addy 5 videos");
|
2010-08-08 00:56:58 +00:00
|
|
|
} else if (headerLength == 814) {
|
|
|
|
// Old version
|
|
|
|
_features |= kFeaturesPalette;
|
|
|
|
} else {
|
2011-02-07 17:54:16 +00:00
|
|
|
warning("VMDDecoder::loadStream(): Version incorrect (%d, %d, %d)", headerLength, handle, _version);
|
2010-08-08 00:56:58 +00:00
|
|
|
close();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
_frameCount = _stream->readUint16LE();
|
|
|
|
|
|
|
|
_defaultX = _stream->readSint16LE();
|
|
|
|
_defaultY = _stream->readSint16LE();
|
|
|
|
_width = _stream->readSint16LE();
|
|
|
|
_height = _stream->readSint16LE();
|
|
|
|
|
|
|
|
_x = _defaultX;
|
|
|
|
_y = _defaultY;
|
|
|
|
|
|
|
|
if ((_width != 0) && (_height != 0)) {
|
|
|
|
|
|
|
|
_hasVideo = true;
|
|
|
|
_features |= kFeaturesVideo;
|
|
|
|
|
|
|
|
} else
|
|
|
|
_hasVideo = false;
|
|
|
|
|
|
|
|
_bytesPerPixel = 1;
|
|
|
|
if (_version & 4)
|
|
|
|
_bytesPerPixel = handle + 1;
|
|
|
|
|
|
|
|
if (_bytesPerPixel > 3) {
|
2011-02-07 17:54:16 +00:00
|
|
|
warning("VMDDecoder::loadStream(): Requested %d bytes per pixel (%d, %d, %d)",
|
2010-08-08 00:56:58 +00:00
|
|
|
_bytesPerPixel, headerLength, handle, _version);
|
|
|
|
close();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
_flags = _stream->readUint16LE();
|
|
|
|
|
|
|
|
_partsPerFrame = _stream->readUint16LE();
|
|
|
|
_firstFramePos = _stream->readUint32LE();
|
|
|
|
|
|
|
|
_videoCodec = _stream->readUint32BE();
|
|
|
|
|
2010-08-08 01:07:45 +00:00
|
|
|
if (_features & kFeaturesPalette) {
|
2010-08-08 01:08:17 +00:00
|
|
|
for (int i = 0; i < 768; i++)
|
|
|
|
_palette[i] = _stream->readByte() << 2;
|
2010-08-08 00:56:58 +00:00
|
|
|
|
2010-08-08 01:07:45 +00:00
|
|
|
_paletteDirty = true;
|
|
|
|
}
|
|
|
|
|
2011-01-16 16:26:52 +00:00
|
|
|
uint32 videoBufferSize1 = _stream->readUint32LE();
|
|
|
|
uint32 videoBufferSize2 = _stream->readUint32LE();
|
|
|
|
|
|
|
|
_videoBufferSize = MAX(videoBufferSize1, videoBufferSize2);
|
2010-08-08 00:56:58 +00:00
|
|
|
|
|
|
|
if (_hasVideo) {
|
|
|
|
if (!assessVideoProperties()) {
|
|
|
|
close();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_soundFreq = _stream->readSint16LE();
|
|
|
|
_soundSliceSize = _stream->readSint16LE();
|
|
|
|
_soundSlicesCount = _stream->readSint16LE();
|
|
|
|
_soundFlags = _stream->readUint16LE();
|
|
|
|
|
|
|
|
_hasSound = (_soundFreq != 0);
|
|
|
|
|
|
|
|
if (_hasSound) {
|
|
|
|
if (!assessAudioProperties()) {
|
|
|
|
close();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
_frameRate = 12;
|
|
|
|
|
|
|
|
_frameInfoOffset = _stream->readUint32LE();
|
|
|
|
|
|
|
|
int numFiles;
|
|
|
|
if (!readFrameTable(numFiles)) {
|
|
|
|
close();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
_stream->seek(_firstFramePos);
|
|
|
|
|
|
|
|
if (numFiles == 0)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
_files.reserve(numFiles);
|
|
|
|
if (!readFiles()) {
|
|
|
|
close();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
_stream->seek(_firstFramePos);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VMDDecoder::assessVideoProperties() {
|
2011-01-16 16:27:52 +00:00
|
|
|
_isPaletted = true;
|
|
|
|
|
2010-08-08 00:56:58 +00:00
|
|
|
if ((_version & 2) && !(_version & 8)) {
|
2011-01-16 16:26:52 +00:00
|
|
|
_externalCodec = true;
|
|
|
|
_videoBufferSize = 0;
|
2010-08-08 00:56:58 +00:00
|
|
|
} else
|
|
|
|
_externalCodec = false;
|
|
|
|
|
2011-01-16 16:27:52 +00:00
|
|
|
if (!openExternalCodec())
|
|
|
|
return false;
|
2010-08-08 00:56:58 +00:00
|
|
|
|
|
|
|
if (_externalCodec)
|
|
|
|
_blitMode = 0;
|
|
|
|
else if (_bytesPerPixel == 1)
|
|
|
|
_blitMode = 0;
|
|
|
|
else if ((_bytesPerPixel == 2) || (_bytesPerPixel == 3)) {
|
|
|
|
int n = (_flags & 0x80) ? 2 : 3;
|
|
|
|
|
2011-01-16 16:29:43 +00:00
|
|
|
_blitMode = _bytesPerPixel - 1;
|
2010-08-08 00:56:58 +00:00
|
|
|
_bytesPerPixel = n;
|
2011-01-16 16:27:52 +00:00
|
|
|
|
|
|
|
_isPaletted = false;
|
2010-08-08 00:56:58 +00:00
|
|
|
}
|
|
|
|
|
2011-01-22 07:20:16 +00:00
|
|
|
if (_blitMode == 1) {
|
|
|
|
_width /= _bytesPerPixel;
|
|
|
|
_defaultX /= _bytesPerPixel;
|
|
|
|
_x /= _bytesPerPixel;
|
|
|
|
}
|
2011-01-16 16:26:52 +00:00
|
|
|
|
2010-08-08 00:56:58 +00:00
|
|
|
if (_hasVideo) {
|
2011-01-16 16:26:52 +00:00
|
|
|
uint32 suggestedVideoBufferSize = _videoBufferSize;
|
2010-08-08 00:56:58 +00:00
|
|
|
|
2011-01-16 16:26:52 +00:00
|
|
|
_videoBufferSize = _width * _height * _bytesPerPixel + 1000;
|
|
|
|
|
|
|
|
if ((suggestedVideoBufferSize > _videoBufferSize) && (suggestedVideoBufferSize < 2097152)) {
|
|
|
|
warning("Suggested video buffer size greater than what should be needed (%d, %d, %dx%d",
|
|
|
|
suggestedVideoBufferSize, _videoBufferSize, _width, _height);
|
|
|
|
|
|
|
|
_videoBufferSize = suggestedVideoBufferSize;
|
|
|
|
}
|
2010-08-08 00:56:58 +00:00
|
|
|
|
2011-01-16 16:29:43 +00:00
|
|
|
for (int i = 0; i < 3; i++) {
|
2011-01-16 16:26:52 +00:00
|
|
|
_videoBuffer[i] = new byte[_videoBufferSize];
|
|
|
|
memset(_videoBuffer[i], 0, _videoBufferSize);
|
2011-01-16 16:29:43 +00:00
|
|
|
|
|
|
|
_8bppSurface[i].w = _width * _bytesPerPixel;
|
|
|
|
_8bppSurface[i].h = _height;
|
|
|
|
_8bppSurface[i].pitch = _width * _bytesPerPixel;
|
|
|
|
_8bppSurface[i].pixels = _videoBuffer[i];
|
|
|
|
_8bppSurface[i].bytesPerPixel = 1;
|
2011-01-16 16:26:52 +00:00
|
|
|
}
|
2010-08-08 00:56:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VMDDecoder::assessAudioProperties() {
|
|
|
|
bool supportedFormat = true;
|
|
|
|
|
|
|
|
_features |= kFeaturesSound;
|
|
|
|
|
|
|
|
_soundStereo = (_soundFlags & 0x8000) ? 1 : ((_soundFlags & 0x200) ? 2 : 0);
|
|
|
|
|
|
|
|
if (_soundSliceSize < 0) {
|
|
|
|
_soundBytesPerSample = 2;
|
|
|
|
_soundSliceSize = -_soundSliceSize;
|
|
|
|
|
|
|
|
if (_soundFlags & 0x10) {
|
|
|
|
_audioFormat = kAudioFormat16bitADPCM;
|
|
|
|
_soundHeaderSize = 3;
|
|
|
|
_soundDataSize = _soundSliceSize >> 1;
|
|
|
|
|
|
|
|
if (_soundStereo > 0)
|
|
|
|
supportedFormat = false;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
_audioFormat = kAudioFormat16bitDPCM;
|
|
|
|
_soundHeaderSize = 1;
|
|
|
|
_soundDataSize = _soundSliceSize;
|
|
|
|
|
|
|
|
if (_soundStereo == 1) {
|
|
|
|
supportedFormat = false;
|
|
|
|
} else if (_soundStereo == 2) {
|
|
|
|
_soundDataSize = 2 * _soundDataSize + 2;
|
|
|
|
_soundHeaderSize = 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_soundBytesPerSample = 1;
|
|
|
|
_audioFormat = kAudioFormat8bitRaw;
|
|
|
|
_soundHeaderSize = 0;
|
|
|
|
_soundDataSize = _soundSliceSize;
|
|
|
|
|
|
|
|
if (_soundStereo > 0)
|
|
|
|
supportedFormat = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!supportedFormat) {
|
|
|
|
warning("VMDDecoder::assessAudioProperties(): Unsupported audio format: %d bits, encoding %d, stereo %d",
|
|
|
|
_soundBytesPerSample * 8, _audioFormat, _soundStereo);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-08-08 17:51:50 +00:00
|
|
|
_frameRate = Common::Rational(_soundFreq, _soundSliceSize);
|
2010-08-08 00:56:58 +00:00
|
|
|
|
|
|
|
_hasSound = true;
|
|
|
|
_soundEnabled = true;
|
|
|
|
_soundStage = kSoundLoaded;
|
|
|
|
|
|
|
|
_audioStream = Audio::makeQueuingAudioStream(_soundFreq, _soundStereo != 0);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VMDDecoder::readFrameTable(int &numFiles) {
|
|
|
|
numFiles = 0;
|
|
|
|
|
|
|
|
_stream->seek(_frameInfoOffset);
|
|
|
|
_frames = new Frame[_frameCount];
|
|
|
|
for (uint16 i = 0; i < _frameCount; i++) {
|
|
|
|
_frames[i].parts = new Part[_partsPerFrame];
|
|
|
|
_stream->skip(2); // Unknown
|
|
|
|
_frames[i].offset = _stream->readUint32LE();
|
|
|
|
}
|
|
|
|
|
2011-01-24 14:09:47 +00:00
|
|
|
_soundLastFilledFrame = 0;
|
2010-08-08 00:56:58 +00:00
|
|
|
for (uint16 i = 0; i < _frameCount; i++) {
|
|
|
|
bool separator = false;
|
|
|
|
|
|
|
|
for (uint16 j = 0; j < _partsPerFrame; j++) {
|
|
|
|
|
|
|
|
_frames[i].parts[j].type = (PartType) _stream->readByte();
|
|
|
|
_frames[i].parts[j].field_1 = _stream->readByte();
|
|
|
|
_frames[i].parts[j].size = _stream->readUint32LE();
|
|
|
|
|
|
|
|
if (_frames[i].parts[j].type == kPartTypeAudio) {
|
|
|
|
|
|
|
|
_frames[i].parts[j].flags = _stream->readByte();
|
|
|
|
_stream->skip(9); // Unknown
|
|
|
|
|
2011-01-24 14:09:47 +00:00
|
|
|
if (_frames[i].parts[j].flags != 3)
|
|
|
|
_soundLastFilledFrame = i;
|
|
|
|
|
2010-08-08 00:56:58 +00:00
|
|
|
} else if (_frames[i].parts[j].type == kPartTypeVideo) {
|
|
|
|
|
|
|
|
_frames[i].parts[j].left = _stream->readUint16LE();
|
|
|
|
_frames[i].parts[j].top = _stream->readUint16LE();
|
|
|
|
_frames[i].parts[j].right = _stream->readUint16LE();
|
|
|
|
_frames[i].parts[j].bottom = _stream->readUint16LE();
|
|
|
|
_frames[i].parts[j].field_E = _stream->readByte();
|
|
|
|
_frames[i].parts[j].flags = _stream->readByte();
|
|
|
|
|
2010-08-08 00:58:59 +00:00
|
|
|
} else if (_frames[i].parts[j].type == kPartTypeSubtitle) {
|
2010-08-08 00:56:58 +00:00
|
|
|
_frames[i].parts[j].id = _stream->readUint16LE();
|
|
|
|
// Speech text file name
|
|
|
|
_stream->skip(8);
|
|
|
|
} else if (_frames[i].parts[j].type == kPartTypeFile) {
|
|
|
|
if (!separator)
|
|
|
|
numFiles++;
|
|
|
|
_stream->skip(10);
|
|
|
|
} else if (_frames[i].parts[j].type == kPartTypeSeparator) {
|
|
|
|
separator = true;
|
|
|
|
_stream->skip(10);
|
|
|
|
} else {
|
2010-08-08 02:55:45 +00:00
|
|
|
// Unknown type
|
2010-08-08 00:56:58 +00:00
|
|
|
_stream->skip(10);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VMDDecoder::readFiles() {
|
|
|
|
uint32 ssize = _stream->size();
|
|
|
|
for (uint16 i = 0; i < _frameCount; i++) {
|
|
|
|
_stream->seek(_frames[i].offset);
|
|
|
|
|
|
|
|
for (uint16 j = 0; j < _partsPerFrame; j++) {
|
|
|
|
if (_frames[i].parts[j].type == kPartTypeSeparator)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (_frames[i].parts[j].type == kPartTypeFile) {
|
2010-09-02 05:12:07 +00:00
|
|
|
File file;
|
2010-08-08 00:56:58 +00:00
|
|
|
|
|
|
|
file.offset = _stream->pos() + 20;
|
|
|
|
file.size = _frames[i].parts[j].size;
|
|
|
|
file.realSize = _stream->readUint32LE();
|
|
|
|
|
|
|
|
char name[16];
|
|
|
|
|
|
|
|
_stream->read(name, 16);
|
|
|
|
name[15] = '\0';
|
|
|
|
|
|
|
|
file.name = name;
|
|
|
|
|
|
|
|
_stream->skip(_frames[i].parts[j].size - 20);
|
|
|
|
|
2010-08-08 01:01:45 +00:00
|
|
|
if ((((uint32) file.realSize) >= ssize) || (file.name == ""))
|
2010-08-08 00:56:58 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
_files.push_back(file);
|
|
|
|
|
|
|
|
} else
|
|
|
|
_stream->skip(_frames[i].parts[j].size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2010-08-08 00:56:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void VMDDecoder::close() {
|
|
|
|
reset();
|
|
|
|
|
|
|
|
CoktelDecoder::close();
|
|
|
|
|
|
|
|
delete _stream;
|
|
|
|
|
2010-08-08 00:56:58 +00:00
|
|
|
delete[] _frames;
|
|
|
|
|
2011-01-16 16:26:52 +00:00
|
|
|
delete[] _videoBuffer[0];
|
|
|
|
delete[] _videoBuffer[1];
|
2011-01-16 16:29:43 +00:00
|
|
|
delete[] _videoBuffer[2];
|
2010-08-08 00:56:04 +00:00
|
|
|
|
2010-08-08 00:56:58 +00:00
|
|
|
delete _codec;
|
|
|
|
|
|
|
|
_files.clear();
|
|
|
|
|
|
|
|
|
2010-08-08 00:56:04 +00:00
|
|
|
_stream = 0;
|
|
|
|
|
2010-08-08 00:56:58 +00:00
|
|
|
_version = 0;
|
|
|
|
_flags = 0;
|
|
|
|
|
|
|
|
_frameInfoOffset = 0;
|
|
|
|
_partsPerFrame = 0;
|
|
|
|
_frames = 0;
|
|
|
|
|
2011-01-24 14:09:47 +00:00
|
|
|
_soundFlags = 0;
|
|
|
|
_soundFreq = 0;
|
|
|
|
_soundSliceSize = 0;
|
|
|
|
_soundSlicesCount = 0;
|
|
|
|
_soundBytesPerSample = 0;
|
|
|
|
_soundStereo = 0;
|
|
|
|
_soundHeaderSize = 0;
|
|
|
|
_soundDataSize = 0;
|
|
|
|
_soundLastFilledFrame = 0;
|
|
|
|
_audioFormat = kAudioFormat8bitRaw;
|
2010-08-08 00:56:58 +00:00
|
|
|
|
|
|
|
_hasVideo = false;
|
|
|
|
_videoCodec = 0;
|
|
|
|
_blitMode = 0;
|
|
|
|
_bytesPerPixel = 0;
|
|
|
|
|
|
|
|
_firstFramePos = 0;
|
|
|
|
|
2011-01-16 16:26:52 +00:00
|
|
|
_videoBufferSize = 0;
|
|
|
|
_videoBuffer [0] = 0;
|
|
|
|
_videoBuffer [1] = 0;
|
2011-01-16 16:29:43 +00:00
|
|
|
_videoBuffer [2] = 0;
|
2011-01-16 16:26:52 +00:00
|
|
|
_videoBufferLen[0] = 0;
|
|
|
|
_videoBufferLen[1] = 0;
|
2011-01-16 16:29:43 +00:00
|
|
|
_videoBufferLen[2] = 0;
|
2010-08-08 00:56:58 +00:00
|
|
|
|
|
|
|
_externalCodec = false;
|
|
|
|
_codec = 0;
|
2011-01-16 16:27:52 +00:00
|
|
|
|
|
|
|
_isPaletted = true;
|
2010-08-08 00:56:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool VMDDecoder::isVideoLoaded() const {
|
|
|
|
return _stream != 0;
|
|
|
|
}
|
|
|
|
|
2011-01-23 19:08:09 +00:00
|
|
|
const Graphics::Surface *VMDDecoder::decodeNextFrame() {
|
2010-08-08 00:56:04 +00:00
|
|
|
if (!isVideoLoaded() || endOfVideo())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
createSurface();
|
|
|
|
|
|
|
|
processFrame();
|
|
|
|
|
|
|
|
if (_curFrame == 0)
|
|
|
|
_startTime = g_system->getMillis();
|
|
|
|
|
|
|
|
return &_surface;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VMDDecoder::processFrame() {
|
|
|
|
_curFrame++;
|
2010-08-08 00:58:59 +00:00
|
|
|
|
|
|
|
_dirtyRects.clear();
|
|
|
|
|
|
|
|
_paletteDirty = false;
|
2010-08-08 01:05:16 +00:00
|
|
|
_subtitle = -1;
|
2010-08-08 00:58:59 +00:00
|
|
|
|
|
|
|
bool startSound = false;
|
|
|
|
|
|
|
|
for (uint16 i = 0; i < _partsPerFrame; i++) {
|
|
|
|
uint32 pos = _stream->pos();
|
|
|
|
|
|
|
|
Part &part = _frames[_curFrame].parts[i];
|
|
|
|
|
|
|
|
if (part.type == kPartTypeAudio) {
|
|
|
|
|
|
|
|
if (part.flags == 1) {
|
|
|
|
// Next sound slice data
|
|
|
|
|
|
|
|
if (_soundEnabled) {
|
|
|
|
filledSoundSlice(part.size);
|
|
|
|
|
|
|
|
if (_soundStage == kSoundLoaded)
|
|
|
|
startSound = true;
|
|
|
|
|
|
|
|
} else
|
|
|
|
_stream->skip(part.size);
|
|
|
|
|
|
|
|
} else if (part.flags == 2) {
|
|
|
|
// Initial sound data (all slices)
|
|
|
|
|
|
|
|
if (_soundEnabled) {
|
|
|
|
uint32 mask = _stream->readUint32LE();
|
|
|
|
filledSoundSlices(part.size - 4, mask);
|
|
|
|
|
|
|
|
if (_soundStage == kSoundLoaded)
|
|
|
|
startSound = true;
|
|
|
|
|
|
|
|
} else
|
|
|
|
_stream->skip(part.size);
|
|
|
|
|
|
|
|
} else if (part.flags == 3) {
|
|
|
|
// Empty sound slice
|
|
|
|
|
|
|
|
if (_soundEnabled) {
|
2011-01-24 14:09:47 +00:00
|
|
|
if ((uint32)_curFrame < _soundLastFilledFrame)
|
|
|
|
emptySoundSlice(_soundDataSize * _soundBytesPerSample);
|
2010-08-08 00:58:59 +00:00
|
|
|
|
|
|
|
if (_soundStage == kSoundLoaded)
|
|
|
|
startSound = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
_stream->skip(part.size);
|
|
|
|
} else if (part.flags == 4) {
|
2010-08-08 00:59:28 +00:00
|
|
|
warning("VMDDecoder::processFrame(): TODO: Addy 5 sound type 4 (%d)", part.size);
|
2010-08-08 00:58:59 +00:00
|
|
|
disableSound();
|
|
|
|
_stream->skip(part.size);
|
|
|
|
} else {
|
2010-08-08 00:59:28 +00:00
|
|
|
warning("VMDDecoder::processFrame(): Unknown sound type %d", part.flags);
|
2010-08-08 00:58:59 +00:00
|
|
|
_stream->skip(part.size);
|
|
|
|
}
|
|
|
|
|
|
|
|
_stream->seek(pos + part.size);
|
|
|
|
|
|
|
|
} else if ((part.type == kPartTypeVideo) && !_hasVideo) {
|
|
|
|
|
2010-08-08 00:59:28 +00:00
|
|
|
warning("VMDDecoder::processFrame(): Header claims there's no video, but video found (%d)", part.size);
|
2010-08-08 00:58:59 +00:00
|
|
|
_stream->skip(part.size);
|
|
|
|
|
|
|
|
} else if ((part.type == kPartTypeVideo) && _hasVideo) {
|
|
|
|
|
|
|
|
uint32 size = part.size;
|
|
|
|
|
|
|
|
// New palette
|
|
|
|
if (part.flags & 2) {
|
|
|
|
uint8 index = _stream->readByte();
|
|
|
|
uint8 count = _stream->readByte();
|
|
|
|
|
2010-08-08 01:08:17 +00:00
|
|
|
for (int j = 0; j < ((count + 1) * 3); j++)
|
|
|
|
_palette[index * 3 + j] = _stream->readByte() << 2;
|
|
|
|
|
2010-08-08 00:58:59 +00:00
|
|
|
_stream->skip((255 - count) * 3);
|
|
|
|
|
|
|
|
_paletteDirty = true;
|
|
|
|
|
|
|
|
size -= (768 + 2);
|
|
|
|
}
|
|
|
|
|
2011-01-16 16:26:52 +00:00
|
|
|
_stream->read(_videoBuffer[0], size);
|
|
|
|
_videoBufferLen[0] = size;
|
2010-08-08 00:58:59 +00:00
|
|
|
|
2010-08-08 00:59:58 +00:00
|
|
|
Common::Rect rect(part.left, part.top, part.right + 1, part.bottom + 1);
|
|
|
|
if (renderFrame(rect))
|
|
|
|
_dirtyRects.push_back(rect);
|
2010-08-08 00:58:59 +00:00
|
|
|
|
|
|
|
} else if (part.type == kPartTypeSeparator) {
|
|
|
|
|
|
|
|
// Ignore
|
|
|
|
|
|
|
|
} else if (part.type == kPartTypeFile) {
|
|
|
|
|
|
|
|
// Ignore
|
|
|
|
_stream->skip(part.size);
|
|
|
|
|
|
|
|
} else if (part.type == kPartType4) {
|
|
|
|
|
|
|
|
// Unknown, ignore
|
|
|
|
_stream->skip(part.size);
|
|
|
|
|
|
|
|
} else if (part.type == kPartTypeSubtitle) {
|
|
|
|
|
2010-08-08 01:05:16 +00:00
|
|
|
_subtitle = part.id;
|
2010-08-08 00:58:59 +00:00
|
|
|
_stream->skip(part.size);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2010-08-08 00:59:28 +00:00
|
|
|
warning("VMDDecoder::processFrame(): Unknown frame part type %d, size %d (%d of %d)",
|
2010-08-08 00:58:59 +00:00
|
|
|
part.type, part.size, i + 1, _partsPerFrame);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (startSound && _soundEnabled) {
|
|
|
|
if (_hasSound && _audioStream) {
|
2011-01-20 17:07:17 +00:00
|
|
|
_mixer->playStream(_soundType, &_audioHandle, _audioStream,
|
|
|
|
-1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO);
|
2010-08-08 00:58:59 +00:00
|
|
|
_soundStage = kSoundPlaying;
|
|
|
|
} else
|
|
|
|
_soundStage = kSoundNone;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (((uint32)_curFrame == (_frameCount - 1)) && (_soundStage == 2)) {
|
|
|
|
_audioStream->finish();
|
2011-01-20 17:07:17 +00:00
|
|
|
_soundStage = kSoundFinished;
|
2010-08-08 00:58:59 +00:00
|
|
|
}
|
2010-08-08 00:56:04 +00:00
|
|
|
}
|
|
|
|
|
2010-08-08 00:59:58 +00:00
|
|
|
bool VMDDecoder::renderFrame(Common::Rect &rect) {
|
2011-01-22 07:20:16 +00:00
|
|
|
Common::Rect realRect, fakeRect;
|
|
|
|
if (!getRenderRects(rect, realRect, fakeRect))
|
2010-08-08 01:00:23 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (_externalCodec) {
|
2010-09-30 13:05:40 +00:00
|
|
|
if (!_codec)
|
|
|
|
return false;
|
|
|
|
|
2011-01-16 16:26:52 +00:00
|
|
|
Common::MemoryReadStream frameStream(_videoBuffer[0], _videoBufferLen[0]);
|
2011-01-23 19:08:09 +00:00
|
|
|
const Graphics::Surface *codecSurf = _codec->decodeImage(&frameStream);
|
2010-09-30 13:05:40 +00:00
|
|
|
if (!codecSurf)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
rect = Common::Rect(_x, _y, _x + codecSurf->w, _y + codecSurf->h);
|
|
|
|
rect.clip(Common::Rect(_x, _y, _x + _width, _y + _height));
|
|
|
|
|
2011-01-16 16:29:43 +00:00
|
|
|
renderBlockWhole(_surface, (const byte *) codecSurf->pixels, rect);
|
2010-09-30 13:05:40 +00:00
|
|
|
return true;
|
2010-08-08 01:00:23 +00:00
|
|
|
}
|
|
|
|
|
2011-01-16 16:29:43 +00:00
|
|
|
uint8 srcBuffer = 0;
|
|
|
|
byte *dataPtr = _videoBuffer[srcBuffer];
|
|
|
|
uint32 dataSize = _videoBufferLen[srcBuffer] - 1;
|
2010-08-08 01:00:23 +00:00
|
|
|
|
|
|
|
uint8 type = *dataPtr++;
|
|
|
|
|
|
|
|
if (type & 0x80) {
|
|
|
|
// Frame data is compressed
|
|
|
|
|
|
|
|
type &= 0x7F;
|
|
|
|
|
2011-01-16 16:29:43 +00:00
|
|
|
if ((type == 2) && (rect.width() == _surface.w) && (_x == 0) && (_blitMode == 0)) {
|
2010-08-08 01:00:23 +00:00
|
|
|
// Directly uncompress onto the video surface
|
2011-03-29 10:39:51 +00:00
|
|
|
const int offsetX = rect.left * _surface.bytesPerPixel;
|
|
|
|
const int offsetY = (_y + rect.top) * _surface.pitch;
|
|
|
|
const int offset = offsetX - offsetY;
|
2011-01-24 16:06:27 +00:00
|
|
|
|
2011-03-29 10:39:51 +00:00
|
|
|
deLZ77((byte *)_surface.pixels + offset, dataPtr, dataSize,
|
|
|
|
_surface.w * _surface.h * _surface.bytesPerPixel - offset);
|
2010-08-08 01:00:23 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-01-16 16:29:43 +00:00
|
|
|
srcBuffer = 1;
|
|
|
|
_videoBufferLen[srcBuffer] =
|
|
|
|
deLZ77(_videoBuffer[srcBuffer], dataPtr, dataSize, _videoBufferSize);
|
2010-08-08 01:00:23 +00:00
|
|
|
|
2011-01-16 16:29:43 +00:00
|
|
|
dataPtr = _videoBuffer[srcBuffer];
|
|
|
|
dataSize = _videoBufferLen[srcBuffer];
|
|
|
|
}
|
|
|
|
|
2011-01-23 19:08:09 +00:00
|
|
|
Common::Rect *blockRect = &fakeRect;
|
|
|
|
Graphics::Surface *surface = &_surface;
|
2011-01-16 16:29:43 +00:00
|
|
|
if (_blitMode == 0) {
|
|
|
|
*blockRect = Common::Rect(blockRect->left + _x, blockRect->top + _y,
|
|
|
|
blockRect->right + _x, blockRect->bottom + _y);
|
|
|
|
} else {
|
|
|
|
surface = &_8bppSurface[2];
|
2010-08-08 01:00:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Evaluate the block type
|
|
|
|
if (type == 0x01)
|
2011-01-16 16:29:43 +00:00
|
|
|
renderBlockSparse (*surface, dataPtr, *blockRect);
|
2010-08-08 01:00:23 +00:00
|
|
|
else if (type == 0x02)
|
2011-01-16 16:29:43 +00:00
|
|
|
renderBlockWhole (*surface, dataPtr, *blockRect);
|
2010-08-08 01:00:23 +00:00
|
|
|
else if (type == 0x03)
|
2011-01-16 16:29:43 +00:00
|
|
|
renderBlockRLE (*surface, dataPtr, *blockRect);
|
2010-08-08 01:00:23 +00:00
|
|
|
else if (type == 0x42)
|
2011-01-16 16:29:43 +00:00
|
|
|
renderBlockWhole4X (*surface, dataPtr, *blockRect);
|
2010-08-08 01:00:23 +00:00
|
|
|
else if ((type & 0x0F) == 0x02)
|
2011-01-16 16:29:43 +00:00
|
|
|
renderBlockWhole2Y (*surface, dataPtr, *blockRect);
|
2010-08-08 01:00:23 +00:00
|
|
|
else
|
2011-01-16 16:29:43 +00:00
|
|
|
renderBlockSparse2Y(*surface, dataPtr, *blockRect);
|
2010-08-08 01:00:23 +00:00
|
|
|
|
2011-01-16 16:29:43 +00:00
|
|
|
if (_blitMode > 0) {
|
|
|
|
if (_bytesPerPixel == 2)
|
|
|
|
blit16(*surface, *blockRect);
|
|
|
|
else if (_bytesPerPixel == 3)
|
|
|
|
blit24(*surface, *blockRect);
|
|
|
|
|
2011-01-22 07:20:16 +00:00
|
|
|
*blockRect = Common::Rect(blockRect->left + _x, blockRect->top + _y,
|
|
|
|
blockRect->right + _x, blockRect->bottom + _y);
|
2011-01-16 16:29:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rect = *blockRect;
|
2010-08-08 01:00:23 +00:00
|
|
|
return true;
|
2010-08-08 00:58:59 +00:00
|
|
|
}
|
|
|
|
|
2011-01-22 07:20:16 +00:00
|
|
|
bool VMDDecoder::getRenderRects(const Common::Rect &rect,
|
|
|
|
Common::Rect &realRect, Common::Rect &fakeRect) {
|
|
|
|
|
|
|
|
realRect = rect;
|
|
|
|
fakeRect = rect;
|
|
|
|
|
|
|
|
if (_blitMode == 0) {
|
|
|
|
|
|
|
|
realRect = Common::Rect(realRect.left - _x, realRect.top - _y,
|
|
|
|
realRect.right - _x, realRect.bottom - _y);
|
|
|
|
|
|
|
|
fakeRect = Common::Rect(fakeRect.left - _x, fakeRect.top - _y,
|
|
|
|
fakeRect.right - _x, fakeRect.bottom - _y);
|
|
|
|
|
|
|
|
} else if (_blitMode == 1) {
|
|
|
|
|
|
|
|
realRect = Common::Rect(rect.left / _bytesPerPixel, rect.top,
|
|
|
|
rect.right / _bytesPerPixel, rect.bottom);
|
|
|
|
|
|
|
|
realRect = Common::Rect(realRect.left - _x, realRect.top - _y,
|
|
|
|
realRect.right - _x, realRect.bottom - _y);
|
|
|
|
|
|
|
|
fakeRect = Common::Rect(fakeRect.left - _x * _bytesPerPixel, fakeRect.top - _y,
|
|
|
|
fakeRect.right - _x * _bytesPerPixel, fakeRect.bottom - _y);
|
|
|
|
|
|
|
|
} else if (_blitMode == 2) {
|
|
|
|
|
|
|
|
fakeRect = Common::Rect(rect.left * _bytesPerPixel, rect.top,
|
|
|
|
rect.right * _bytesPerPixel, rect.bottom);
|
|
|
|
|
|
|
|
realRect = Common::Rect(realRect.left - _x, realRect.top - _y,
|
|
|
|
realRect.right - _x, realRect.bottom - _y);
|
|
|
|
|
|
|
|
fakeRect = Common::Rect(fakeRect.left - _x * _bytesPerPixel, fakeRect.top - _y,
|
|
|
|
fakeRect.right - _x * _bytesPerPixel, fakeRect.bottom - _y);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
realRect.clip(Common::Rect(_surface.w, _surface.h));
|
|
|
|
fakeRect.clip(Common::Rect(_surface.w * _bytesPerPixel, _surface.h));
|
|
|
|
|
|
|
|
if (!realRect.isValidRect() || realRect.isEmpty())
|
|
|
|
return false;
|
|
|
|
if (!fakeRect.isValidRect() || realRect.isEmpty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-01-23 19:08:09 +00:00
|
|
|
void VMDDecoder::blit16(const Graphics::Surface &srcSurf, Common::Rect &rect) {
|
2011-01-16 16:29:43 +00:00
|
|
|
rect = Common::Rect(rect.left / 2, rect.top, rect.right / 2, rect.bottom);
|
|
|
|
|
|
|
|
Common::Rect srcRect = rect;
|
|
|
|
|
|
|
|
rect.clip(_surface.w, _surface.h);
|
|
|
|
|
2011-01-23 19:08:09 +00:00
|
|
|
Graphics::PixelFormat pixelFormat = getPixelFormat();
|
2011-01-16 16:29:43 +00:00
|
|
|
|
|
|
|
const byte *src = (byte *)srcSurf.pixels +
|
|
|
|
(srcRect.top * srcSurf.pitch) + srcRect.left * _bytesPerPixel;
|
|
|
|
byte *dst = (byte *)_surface.pixels +
|
2011-01-22 07:20:16 +00:00
|
|
|
((_y + rect.top) * _surface.pitch) + (_x + rect.left) * _surface.bytesPerPixel;
|
2011-01-16 16:29:43 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < rect.height(); i++) {
|
|
|
|
const byte *srcRow = src;
|
|
|
|
byte *dstRow = dst;
|
|
|
|
|
|
|
|
for (int j = 0; j < rect.width(); j++, srcRow += 2, dstRow += _surface.bytesPerPixel) {
|
|
|
|
uint16 data = READ_LE_UINT16(srcRow);
|
|
|
|
|
|
|
|
byte r = ((data & 0x7C00) >> 10) << 3;
|
|
|
|
byte g = ((data & 0x03E0) >> 5) << 3;
|
|
|
|
byte b = ((data & 0x001F) >> 0) << 3;
|
|
|
|
|
|
|
|
uint32 c = pixelFormat.RGBToColor(r, g, b);
|
|
|
|
if ((r == 0) && (g == 0) && (b == 0))
|
|
|
|
c = 0;
|
|
|
|
|
|
|
|
if (_surface.bytesPerPixel == 2)
|
|
|
|
*((uint16 *)dstRow) = (uint16) c;
|
|
|
|
}
|
|
|
|
|
|
|
|
src += srcSurf .pitch;
|
|
|
|
dst += _surface.pitch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-23 19:08:09 +00:00
|
|
|
void VMDDecoder::blit24(const Graphics::Surface &srcSurf, Common::Rect &rect) {
|
2011-01-16 16:41:27 +00:00
|
|
|
rect = Common::Rect(rect.left / 3, rect.top, rect.right / 3, rect.bottom);
|
|
|
|
|
|
|
|
Common::Rect srcRect = rect;
|
|
|
|
|
|
|
|
rect.clip(_surface.w, _surface.h);
|
|
|
|
|
2011-01-23 19:08:09 +00:00
|
|
|
Graphics::PixelFormat pixelFormat = getPixelFormat();
|
2011-01-16 16:41:27 +00:00
|
|
|
|
|
|
|
const byte *src = (byte *)srcSurf.pixels +
|
|
|
|
(srcRect.top * srcSurf.pitch) + srcRect.left * _bytesPerPixel;
|
|
|
|
byte *dst = (byte *)_surface.pixels +
|
2011-01-22 07:20:16 +00:00
|
|
|
((_y + rect.top) * _surface.pitch) + (_x + rect.left) * _surface.bytesPerPixel;
|
2011-01-16 16:41:27 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < rect.height(); i++) {
|
|
|
|
const byte *srcRow = src;
|
|
|
|
byte *dstRow = dst;
|
|
|
|
|
|
|
|
for (int j = 0; j < rect.width(); j++, srcRow += 3, dstRow += _surface.bytesPerPixel) {
|
|
|
|
byte r = srcRow[2];
|
|
|
|
byte g = srcRow[1];
|
|
|
|
byte b = srcRow[0];
|
|
|
|
|
|
|
|
uint32 c = pixelFormat.RGBToColor(r, g, b);
|
|
|
|
if ((r == 0) && (g == 0) && (b == 0))
|
|
|
|
c = 0;
|
|
|
|
|
|
|
|
if (_surface.bytesPerPixel == 2)
|
|
|
|
*((uint16 *)dstRow) = (uint16) c;
|
|
|
|
}
|
|
|
|
|
|
|
|
src += srcSurf .pitch;
|
|
|
|
dst += _surface.pitch;
|
|
|
|
}
|
2011-01-16 16:29:43 +00:00
|
|
|
}
|
|
|
|
|
2010-08-08 00:58:59 +00:00
|
|
|
void VMDDecoder::emptySoundSlice(uint32 size) {
|
2010-08-08 00:59:28 +00:00
|
|
|
byte *sound = soundEmpty(size);
|
|
|
|
|
|
|
|
if (sound) {
|
|
|
|
uint32 flags = 0;
|
|
|
|
flags |= (_soundBytesPerSample == 2) ? Audio::FLAG_16BITS : 0;
|
|
|
|
flags |= (_soundStereo > 0) ? Audio::FLAG_STEREO : 0;
|
|
|
|
|
|
|
|
_audioStream->queueBuffer(sound, size, DisposeAfterUse::YES, flags);
|
|
|
|
}
|
2010-08-08 00:58:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void VMDDecoder::filledSoundSlice(uint32 size) {
|
2010-08-08 00:59:28 +00:00
|
|
|
byte *sound = 0;
|
|
|
|
if (_audioFormat == kAudioFormat8bitRaw)
|
|
|
|
sound = sound8bitRaw(size);
|
|
|
|
else if (_audioFormat == kAudioFormat16bitDPCM)
|
|
|
|
sound = sound16bitDPCM(size);
|
|
|
|
else if (_audioFormat == kAudioFormat16bitADPCM)
|
|
|
|
sound = sound16bitADPCM(size);
|
|
|
|
|
|
|
|
if (sound) {
|
|
|
|
uint32 flags = 0;
|
|
|
|
flags |= (_soundBytesPerSample == 2) ? Audio::FLAG_16BITS : 0;
|
|
|
|
flags |= (_soundStereo > 0) ? Audio::FLAG_STEREO : 0;
|
|
|
|
|
|
|
|
_audioStream->queueBuffer(sound, size, DisposeAfterUse::YES, flags);
|
|
|
|
}
|
2010-08-08 00:58:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void VMDDecoder::filledSoundSlices(uint32 size, uint32 mask) {
|
2010-08-08 00:59:28 +00:00
|
|
|
bool fillInfo[32];
|
|
|
|
|
|
|
|
uint8 max;
|
|
|
|
uint8 n = evaluateMask(mask, fillInfo, max);
|
|
|
|
|
|
|
|
int32 extraSize;
|
|
|
|
|
|
|
|
extraSize = size - n * _soundDataSize;
|
|
|
|
|
|
|
|
if (_soundSlicesCount > 32)
|
|
|
|
extraSize -= (_soundSlicesCount - 32) * _soundDataSize;
|
|
|
|
|
|
|
|
if (n > 0)
|
|
|
|
extraSize /= n;
|
|
|
|
|
|
|
|
for (uint8 i = 0; i < max; i++)
|
|
|
|
if (fillInfo[i])
|
|
|
|
filledSoundSlice(_soundDataSize + extraSize);
|
|
|
|
else
|
|
|
|
emptySoundSlice(_soundDataSize * _soundBytesPerSample);
|
|
|
|
|
|
|
|
if (_soundSlicesCount > 32)
|
|
|
|
filledSoundSlice((_soundSlicesCount - 32) * _soundDataSize + _soundHeaderSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8 VMDDecoder::evaluateMask(uint32 mask, bool *fillInfo, uint8 &max) {
|
|
|
|
max = MIN<int>(_soundSlicesCount - 1, 31);
|
|
|
|
|
|
|
|
uint8 n = 0;
|
|
|
|
for (int i = 0; i < max; i++) {
|
|
|
|
|
|
|
|
if (!(mask & 1)) {
|
|
|
|
n++;
|
|
|
|
*fillInfo++ = true;
|
|
|
|
} else
|
|
|
|
*fillInfo++ = false;
|
|
|
|
|
|
|
|
mask >>= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
byte *VMDDecoder::soundEmpty(uint32 &size) {
|
|
|
|
if (!_audioStream)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
byte *soundBuf = (byte *)malloc(size);
|
|
|
|
memset(soundBuf, 0, size);
|
|
|
|
|
|
|
|
return soundBuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
byte *VMDDecoder::sound8bitRaw(uint32 &size) {
|
|
|
|
if (!_audioStream) {
|
|
|
|
_stream->skip(size);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
byte *soundBuf = (byte *)malloc(size);
|
|
|
|
_stream->read(soundBuf, size);
|
|
|
|
unsignedToSigned(soundBuf, size);
|
|
|
|
|
|
|
|
return soundBuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
byte *VMDDecoder::sound16bitDPCM(uint32 &size) {
|
|
|
|
if (!_audioStream) {
|
|
|
|
_stream->skip(size);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32 init[2];
|
|
|
|
|
|
|
|
init[0] = _stream->readSint16LE();
|
|
|
|
size -= 2;
|
|
|
|
|
|
|
|
if (_soundStereo > 0) {
|
|
|
|
init[1] = _stream->readSint16LE();
|
|
|
|
size -= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
byte *data = new byte[size];
|
|
|
|
byte *sound = 0;
|
|
|
|
|
|
|
|
if (_stream->read(data, size) == size)
|
|
|
|
sound = deDPCM(data, size, init);
|
|
|
|
|
|
|
|
delete[] data;
|
|
|
|
|
|
|
|
return sound;
|
|
|
|
}
|
|
|
|
|
|
|
|
byte *VMDDecoder::sound16bitADPCM(uint32 &size) {
|
|
|
|
if (!_audioStream) {
|
|
|
|
_stream->skip(size);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32 init = _stream->readSint16LE();
|
|
|
|
size -= 2;
|
|
|
|
|
|
|
|
int32 index = _stream->readByte();
|
|
|
|
size--;
|
|
|
|
|
|
|
|
byte *data = new byte[size];
|
|
|
|
byte *sound = 0;
|
|
|
|
|
|
|
|
if (_stream->read(data, size) == size)
|
|
|
|
sound = deADPCM(data, size, init, index);
|
|
|
|
|
|
|
|
delete[] data;
|
|
|
|
|
|
|
|
return sound;
|
|
|
|
}
|
|
|
|
|
|
|
|
byte *VMDDecoder::deDPCM(const byte *data, uint32 &size, int32 init[2]) {
|
|
|
|
if (!data || (size == 0))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
int channels = (_soundStereo > 0) ? 2 : 1;
|
|
|
|
|
|
|
|
uint32 inSize = size;
|
|
|
|
uint32 outSize = size + channels;
|
|
|
|
|
|
|
|
int16 *out = (int16 *)malloc(outSize * 2);
|
2010-10-15 13:56:14 +00:00
|
|
|
byte *sound = (byte *)out;
|
|
|
|
|
|
|
|
if (!out)
|
|
|
|
return 0;
|
2010-08-08 00:59:28 +00:00
|
|
|
|
|
|
|
int channel = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < channels; i++) {
|
2010-10-15 13:56:14 +00:00
|
|
|
*out++ = TO_BE_16(init[channel]);
|
2010-08-08 00:59:28 +00:00
|
|
|
|
|
|
|
channel = (channel + 1) % channels;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (inSize-- > 0) {
|
|
|
|
if (*data & 0x80)
|
|
|
|
init[channel] -= _tableDPCM[*data++ & 0x7F];
|
|
|
|
else
|
|
|
|
init[channel] += _tableDPCM[*data++];
|
|
|
|
|
|
|
|
init[channel] = CLIP<int32>(init[channel], -32768, 32767);
|
|
|
|
*out++ = TO_BE_16(init[channel]);
|
|
|
|
|
|
|
|
channel = (channel + 1) % channels;
|
|
|
|
}
|
|
|
|
|
|
|
|
size = outSize * 2;
|
|
|
|
return sound;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Yet another IMA ADPCM variant
|
|
|
|
byte *VMDDecoder::deADPCM(const byte *data, uint32 &size, int32 init, int32 index) {
|
|
|
|
if (!data || (size == 0))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
uint32 outSize = size * 2;
|
|
|
|
|
|
|
|
int16 *out = (int16 *)malloc(outSize * 2);
|
|
|
|
byte *sound = (byte *) out;
|
|
|
|
|
|
|
|
index = CLIP<int32>(index, 0, 88);
|
|
|
|
|
|
|
|
int32 predictor = _tableADPCM[index];
|
|
|
|
|
|
|
|
uint32 dataByte = 0;
|
|
|
|
bool newByte = true;
|
|
|
|
|
|
|
|
size *= 2;
|
|
|
|
while (size -- > 0) {
|
|
|
|
byte code = 0;
|
|
|
|
|
|
|
|
if (newByte) {
|
|
|
|
dataByte = *data++;
|
|
|
|
code = (dataByte >> 4) & 0xF;
|
|
|
|
} else
|
|
|
|
code = dataByte & 0xF;
|
|
|
|
|
|
|
|
newByte = !newByte;
|
|
|
|
|
|
|
|
index += _tableADPCMStep[code];
|
|
|
|
index = CLIP<int32>(index, 0, 88);
|
|
|
|
|
|
|
|
int32 value = predictor / 8;
|
|
|
|
|
|
|
|
if (code & 4)
|
|
|
|
value += predictor;
|
|
|
|
if (code & 2)
|
|
|
|
value += predictor / 2;
|
|
|
|
if (code & 1)
|
|
|
|
value += predictor / 4;
|
|
|
|
|
|
|
|
if (code & 8)
|
|
|
|
init -= value;
|
|
|
|
else
|
|
|
|
init += value;
|
|
|
|
|
|
|
|
init = CLIP<int32>(init, -32768, 32767);
|
|
|
|
|
|
|
|
predictor = _tableADPCM[index];
|
|
|
|
|
|
|
|
*out++ = TO_BE_16(init);
|
|
|
|
}
|
|
|
|
|
|
|
|
size = outSize * 2;
|
|
|
|
return sound;
|
2010-08-08 00:56:04 +00:00
|
|
|
}
|
|
|
|
|
2011-01-23 19:08:09 +00:00
|
|
|
Graphics::PixelFormat VMDDecoder::getPixelFormat() const {
|
2011-01-19 00:16:13 +00:00
|
|
|
if (_externalCodec) {
|
|
|
|
if (_codec)
|
|
|
|
return _codec->getPixelFormat();
|
|
|
|
|
|
|
|
// If we don't have the needed codec, just assume it's in the
|
|
|
|
// current screen format
|
|
|
|
return g_system->getScreenFormat();
|
|
|
|
}
|
2010-09-30 13:05:40 +00:00
|
|
|
|
2011-01-16 16:29:43 +00:00
|
|
|
if (_blitMode > 0)
|
|
|
|
return g_system->getScreenFormat();
|
|
|
|
|
2011-01-23 19:08:09 +00:00
|
|
|
return Graphics::PixelFormat::createFormatCLUT8();
|
2010-08-08 00:56:04 +00:00
|
|
|
}
|
|
|
|
|
2010-08-08 01:02:19 +00:00
|
|
|
bool VMDDecoder::getPartCoords(int16 frame, PartType type, int16 &x, int16 &y, int16 &width, int16 &height) {
|
|
|
|
if (frame >= ((int32) _frameCount))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Frame &f = _frames[frame];
|
|
|
|
|
|
|
|
// Look for a part matching the requested type, stopping at a separator
|
|
|
|
Part *part = 0;
|
|
|
|
for (int i = 0; i < _partsPerFrame; i++) {
|
|
|
|
Part &p = f.parts[i];
|
|
|
|
|
|
|
|
if ((p.type == kPartTypeSeparator) || (p.type == type)) {
|
|
|
|
part = &p;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!part)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
x = part->left;
|
|
|
|
y = part->top;
|
|
|
|
width = part->right - part->left + 1;
|
|
|
|
height = part->bottom - part->top + 1;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VMDDecoder::getFrameCoords(int16 frame, int16 &x, int16 &y, int16 &width, int16 &height) {
|
|
|
|
return getPartCoords(frame, kPartTypeVideo, x, y, width, height);
|
|
|
|
}
|
|
|
|
|
2010-08-08 00:57:27 +00:00
|
|
|
bool VMDDecoder::hasEmbeddedFiles() const {
|
|
|
|
return !_files.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VMDDecoder::hasEmbeddedFile(const Common::String &fileName) const {
|
|
|
|
for (Common::Array<File>::const_iterator file = _files.begin(); file != _files.end(); ++file)
|
|
|
|
if (!file->name.compareToIgnoreCase(fileName))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-11-19 01:37:04 +00:00
|
|
|
Common::SeekableReadStream *VMDDecoder::getEmbeddedFile(const Common::String &fileName) const {
|
2010-08-08 00:57:27 +00:00
|
|
|
const File *file = 0;
|
|
|
|
|
|
|
|
for (Common::Array<File>::const_iterator it = _files.begin(); it != _files.end(); ++it)
|
|
|
|
if (!it->name.compareToIgnoreCase(fileName)) {
|
|
|
|
file = &*it;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!file)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if ((file->size - 20) != file->realSize) {
|
|
|
|
warning("VMDDecoder::getEmbeddedFile(): Sizes for \"%s\" differ! (%d, %d)",
|
|
|
|
fileName.c_str(), (file->size - 20), file->realSize);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_stream->seek(file->offset)) {
|
|
|
|
warning("VMDDecoder::getEmbeddedFile(): Can't seek to offset %d to (file \"%s\")",
|
|
|
|
file->offset, fileName.c_str());
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
byte *data = (byte *) malloc(file->realSize);
|
|
|
|
if (_stream->read(data, file->realSize) != file->realSize) {
|
|
|
|
free(data);
|
|
|
|
warning("VMDDecoder::getEmbeddedFile(): Couldn't read %d bytes (file \"%s\")",
|
|
|
|
file->realSize, fileName.c_str());
|
2010-10-15 13:56:14 +00:00
|
|
|
return 0;
|
2010-08-08 00:57:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Common::MemoryReadStream *stream =
|
|
|
|
new Common::MemoryReadStream(data, file->realSize, DisposeAfterUse::YES);
|
|
|
|
|
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
|
2010-08-08 01:05:16 +00:00
|
|
|
int32 VMDDecoder::getSubtitleIndex() const {
|
|
|
|
return _subtitle;
|
|
|
|
}
|
|
|
|
|
2011-01-20 12:28:22 +00:00
|
|
|
bool VMDDecoder::hasVideo() const {
|
|
|
|
return _hasVideo;
|
|
|
|
}
|
|
|
|
|
2011-01-16 16:27:52 +00:00
|
|
|
bool VMDDecoder::isPaletted() const {
|
|
|
|
return _isPaletted;
|
|
|
|
}
|
|
|
|
|
2011-01-23 19:08:09 +00:00
|
|
|
} // End of namespace Video
|
2010-08-08 00:33:59 +00:00
|
|
|
|
2011-01-23 17:37:17 +00:00
|
|
|
#endif // VIDEO_COKTELDECODER_H
|