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$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "graphics/video/coktel_decoder.h"
|
|
|
|
|
|
|
|
#ifdef GRAPHICS_VIDEO_COKTELDECODER_H
|
|
|
|
|
|
|
|
namespace Graphics {
|
|
|
|
|
|
|
|
CoktelDecoder::State::State() : left(0), top(0), right(0), bottom(0), flags(0), speechId(0) {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CoktelDecoder::CoktelDecoder(Audio::Mixer &mixer, Audio::Mixer::SoundType soundType) :
|
2010-08-08 00:38:26 +00:00
|
|
|
_mixer(&mixer), _soundType(soundType), _width(0), _height(0), _x(0), _y(0), _frameCount(0),
|
2010-08-08 00:37:52 +00:00
|
|
|
_paletteDirty(false), _ownSurface(true) {
|
2010-08-08 00:33:59 +00:00
|
|
|
|
|
|
|
memset(_palette, 0, 768);
|
|
|
|
}
|
|
|
|
|
|
|
|
CoktelDecoder::~CoktelDecoder() {
|
|
|
|
}
|
|
|
|
|
2010-08-08 00:37:52 +00:00
|
|
|
void CoktelDecoder::setSurfaceMemory(void *mem, uint16 width, uint16 height, uint8 bpp) {
|
|
|
|
freeSurface();
|
|
|
|
|
|
|
|
assert((width > 0) && (height > 0));
|
|
|
|
assert(bpp == getPixelFormat().bytesPerPixel);
|
|
|
|
|
|
|
|
_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;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CoktelDecoder::hasSurface() {
|
|
|
|
return _surface.pixels != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CoktelDecoder::createSurface() {
|
|
|
|
if (hasSurface())
|
|
|
|
return;
|
|
|
|
|
|
|
|
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:37:52 +00:00
|
|
|
void CoktelDecoder::close() {
|
|
|
|
freeSurface();
|
2010-08-08 00:38:26 +00:00
|
|
|
|
|
|
|
_x = 0;
|
|
|
|
_y = 0;
|
|
|
|
|
|
|
|
_frameCount = 0;
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
byte *CoktelDecoder::getPalette() {
|
|
|
|
return _palette;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CoktelDecoder::hasDirtyPalette() const {
|
|
|
|
return _paletteDirty;
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::Rational CoktelDecoder::getFrameRate() const {
|
|
|
|
return _frameRate;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PreIMDDecoder::PreIMDDecoder(uint16 width, uint16 height,
|
2010-08-08 00:36:19 +00:00
|
|
|
Audio::Mixer &mixer, Audio::Mixer::SoundType soundType) : CoktelDecoder(mixer, soundType),
|
|
|
|
_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) {
|
|
|
|
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) || (((uint32) frame) >= _frameCount))
|
|
|
|
// Out of range
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
bool PreIMDDecoder::load(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();
|
|
|
|
|
|
|
|
_stream = &stream;
|
|
|
|
|
|
|
|
_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
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
_curFrame++;
|
|
|
|
|
|
|
|
return &_surface;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PreIMDDecoder::processFrame() {
|
|
|
|
uint16 frameSize = _stream->readUint16LE();
|
|
|
|
|
|
|
|
uint32 nextFramePos = _stream->pos() + frameSize + 2;
|
|
|
|
|
|
|
|
byte cmd;
|
|
|
|
|
|
|
|
cmd = _stream->readByte();
|
|
|
|
frameSize--;
|
|
|
|
|
|
|
|
if (cmd == 0) {
|
|
|
|
// Palette. Ignored by Fascination, though
|
|
|
|
|
|
|
|
_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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PreIMDDecoder::renderFrame() {
|
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:38:26 +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:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PixelFormat PreIMDDecoder::getPixelFormat() const {
|
|
|
|
return PixelFormat::createFormatCLUT8();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace Graphics
|
|
|
|
|
|
|
|
#endif // GRAPHICS_VIDEO_COKTELDECODER_H
|