diff options
author | Max Horn | 2006-02-11 22:45:04 +0000 |
---|---|---|
committer | Max Horn | 2006-02-11 22:45:04 +0000 |
commit | 26ee630756ebdd7c96bccede0881a8c8b98e8f2b (patch) | |
tree | 26e378d5cf990a2b81c2c96e9e683a7f333b62e8 /scumm/smush | |
parent | 2a9a0d4211b1ea5723f1409d91cb95de8984429e (diff) | |
download | scummvm-rg350-26ee630756ebdd7c96bccede0881a8c8b98e8f2b.tar.gz scummvm-rg350-26ee630756ebdd7c96bccede0881a8c8b98e8f2b.tar.bz2 scummvm-rg350-26ee630756ebdd7c96bccede0881a8c8b98e8f2b.zip |
Moved engines to the new engines/ directory
svn-id: r20582
Diffstat (limited to 'scumm/smush')
-rw-r--r-- | scumm/smush/channel.h | 148 | ||||
-rw-r--r-- | scumm/smush/chunk.cpp | 242 | ||||
-rw-r--r-- | scumm/smush/chunk.h | 110 | ||||
-rw-r--r-- | scumm/smush/chunk_type.h | 60 | ||||
-rw-r--r-- | scumm/smush/codec1.cpp | 62 | ||||
-rw-r--r-- | scumm/smush/codec37.cpp | 588 | ||||
-rw-r--r-- | scumm/smush/codec37.h | 62 | ||||
-rw-r--r-- | scumm/smush/codec47.cpp | 630 | ||||
-rw-r--r-- | scumm/smush/codec47.h | 65 | ||||
-rw-r--r-- | scumm/smush/imuse_channel.cpp | 347 | ||||
-rw-r--r-- | scumm/smush/saud_channel.cpp | 268 | ||||
-rw-r--r-- | scumm/smush/smush_font.cpp | 269 | ||||
-rw-r--r-- | scumm/smush/smush_font.h | 54 | ||||
-rw-r--r-- | scumm/smush/smush_mixer.cpp | 163 | ||||
-rw-r--r-- | scumm/smush/smush_mixer.h | 64 | ||||
-rw-r--r-- | scumm/smush/smush_player.cpp | 1359 | ||||
-rw-r--r-- | scumm/smush/smush_player.h | 148 |
17 files changed, 0 insertions, 4639 deletions
diff --git a/scumm/smush/channel.h b/scumm/smush/channel.h deleted file mode 100644 index 52e64c8b2d..0000000000 --- a/scumm/smush/channel.h +++ /dev/null @@ -1,148 +0,0 @@ -/* ScummVM - Scumm Interpreter - * Copyright (C) 2002-2006 The ScummVM project - * - * 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$ - * - */ - -#ifndef SMUSH_CHANNEL_H -#define SMUSH_CHANNEL_H - -#include "common/util.h" - -namespace Scumm { - -class Chunk; -class ContChunk; - -class SmushChannel { -public: - - virtual ~SmushChannel() {}; - virtual bool appendData(Chunk &b, int32 size) = 0; - virtual bool setParameters(int32, int32, int32, int32, int32) = 0; - virtual bool checkParameters(int32, int32, int32, int32, int32) = 0; - virtual bool isTerminated() const = 0; - virtual int32 availableSoundData() const = 0; - virtual void getSoundData(int16 *sound_buffer, int32 size) = 0; - virtual void getSoundData(int8 *sound_buffer, int32 size) = 0; - virtual int32 getRate() = 0; - virtual bool getParameters(int32 &rate, bool &stereo, bool &is_16bit, int32 &vol, int32 &pan) = 0; - virtual int32 getTrackIdentifier() const = 0; -}; - -class SaudChannel : public SmushChannel { -private: - int32 _track; - int32 _nbframes; - int32 _dataSize; - int32 _frequency; - bool _inData; - bool _markReached; - int32 _flags; - int32 _volume; - int32 _pan; - int32 _index; - byte *_tbuffer; - int32 _tbufferSize; - byte *_sbuffer; - int32 _sbufferSize; - bool _keepSize; - -protected: - void handleStrk(Chunk &c); - void handleSmrk(Chunk &c); - void handleShdr(Chunk &c); - bool handleSubTags(int32 &offset); - bool processBuffer(); - -public: - SaudChannel(int32 track, int32 freq); - virtual ~SaudChannel(); - bool isTerminated() const; - bool setParameters(int32 duration, int32 flags, int32 vol1, int32 vol2, int32 index); - bool checkParameters(int32 index, int32 duration, int32 flags, int32 vol1, int32 vol2); - bool appendData(Chunk &b, int32 size); - int32 availableSoundData() const; - void getSoundData(int16 *sound_buffer, int32 size); - void getSoundData(int8 *sound_buffer, int32 size) { error("8bit request for SAUD channel should never happen"); }; - int32 getRate() { return _frequency; } - bool getParameters(int32 &rate, bool &stereo, bool &is_16bit, int32 &vol, int32 &pan) { - rate = _frequency; - stereo = true; - is_16bit = true; - vol = _volume; - pan = _pan; - return true; - }; - virtual int32 getTrackIdentifier() const { return _track; }; -}; - -class ImuseChannel : public SmushChannel { -private: - int32 _track; //!< the track number - byte *_tbuffer; //!< data temporary buffer - int32 _tbufferSize; //!< temporary buffer size - byte *_sbuffer; //!< sound buffer - int32 _sbufferSize; //!< sound buffer size - int32 _srbufferSize; - int32 _frequency; //!< the target frequency of the ::mixer - int32 _dataSize; //!< remaining size of sound data in the iMUS buffer - bool _inData; - int32 _volume; - int32 _pan; - - int32 _bitsize; //!< the bitsize of the original data - int32 _rate; //!< the sampling rate of the original data - int32 _channels; //!< the number of channels of the original data - -protected: - int32 decode(int32 size, int32 &ret); - void decode(); - bool processBuffer(); - bool handleMap(Chunk &); - bool handleFormat(Chunk &); - bool handleRegion(Chunk &); - bool handleStop(Chunk &); - bool handleSubTags(int32 & offset); - -public: - ImuseChannel(int32 track, int32 freq); - virtual ~ImuseChannel(); - bool isTerminated() const; - bool setParameters(int32 nbframes, int32 size, int32 track_flags, int32 unk1, int32); - bool checkParameters(int32 index, int32 nbframes, int32 size, int32 track_flags, int32 unk1); - bool appendData(Chunk &b, int32 size); - int32 availableSoundData() const; - void getSoundData(int16 *sound_buffer, int32 size); - void getSoundData(int8 *sound_buffer, int32 size); - int32 getRate() { return _rate; } - bool getParameters(int32 &rate, bool &stereo, bool &is_16bit, int32 &vol, int32 &pan) { - rate = _rate; - stereo = (_channels == 2); - is_16bit = (_bitsize > 8); - vol = _volume; - pan = _pan; - return true; - }; - virtual int32 getTrackIdentifier() const { return _track; }; -}; - -} // End of namespace Scumm - -#endif diff --git a/scumm/smush/chunk.cpp b/scumm/smush/chunk.cpp deleted file mode 100644 index 60512cdf2f..0000000000 --- a/scumm/smush/chunk.cpp +++ /dev/null @@ -1,242 +0,0 @@ -/* ScummVM - Scumm Interpreter - * Copyright (C) 2002-2006 The ScummVM project - * - * 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 "common/stdafx.h" -#include "scumm/smush/chunk.h" -#include "scumm/scumm.h" - -#include "common/file.h" -#include "common/str.h" -#include "common/util.h" - -namespace Scumm { - -const char *Chunk::ChunkString(Chunk::type t) { - static char data[5]; - data[0] = (char)((t >> 24) & 0xFF); - data[1] = (char)((t >> 16) & 0xFF); - data[2] = (char)((t >> 8) & 0xFF); - data[3] = (char)((t >> 0) & 0xFF); - data[4] = 0; - return data; -} - -BaseChunk::BaseChunk() : - _type(0), - _size(0), - _curPos(0) { -} - -bool BaseChunk::eof() const { - return _curPos >= _size; -} - -uint32 BaseChunk::tell() const { - return _curPos; -} - -Chunk::type BaseChunk::getType() const { - return _type; -} - -uint32 BaseChunk::getSize() const { - return _size; -} - -bool BaseChunk::seek(int32 delta, seek_type dir) { - switch(dir) { - case seek_cur: - _curPos += delta; - break; - case seek_start: - if (delta < 0) - error("invalid seek request"); - - _curPos = (uint32)delta; - break; - case seek_end: - if (delta > 0 || _size < (uint32)-delta) - error("invalid seek request"); - - _curPos = (uint32)(_size + delta); - break; - } - if (_curPos > _size) { - error("invalid seek request : %d > %d (delta == %d)", _curPos, _size, delta); - } - return true; -} - -FileChunk::FileChunk(ScummFile *data, int offset) { - _data = data; - _deleteData = false; - - _data->seek(offset, seek_start); - _type = _data->readUint32BE(); - _size = _data->readUint32BE(); - _offset = _data->pos(); - _curPos = 0; -} - -FileChunk::FileChunk(const Common::String &name, int offset) { - _data = new ScummFile(); - _deleteData = true; - if (!g_scumm->openFile(*_data, name.c_str())) - error("FileChunk: Unable to open file %s", name.c_str()); - - _data->seek(offset, seek_start); - _type = _data->readUint32BE(); - _size = _data->readUint32BE(); - _offset = _data->pos(); - _curPos = 0; -} - -FileChunk::~FileChunk() { - if (_deleteData) - delete _data; -} - -Chunk *FileChunk::subBlock() { - FileChunk *ptr = new FileChunk(_data, _offset + _curPos); - seek(sizeof(Chunk::type) + sizeof(uint32) + ptr->getSize()); - return ptr; -} - -void FileChunk::reseek() { - _data->seek(_offset + _curPos); -} - -bool FileChunk::read(void *buffer, uint32 size) { - if (size <= 0 || (_curPos + size) > _size) - error("invalid buffer read request"); - - _data->read(buffer, size); - _curPos += size; - return true; -} - -int8 FileChunk::getChar() { - return (int8)getByte(); -} - -byte FileChunk::getByte() { - _curPos++; - - if (_curPos > _size) - error("invalid byte read request"); - - return _data->readByte(); -} - -int16 FileChunk::getShort() { - return (int16)getWord(); -} - -uint16 FileChunk::getWord() { - _curPos += 2; - - if (_curPos > _size) - error("invalid word read request"); - - return _data->readUint16LE(); -} - -uint32 FileChunk::getDword() { - _curPos += 4; - - if (_curPos > _size) - error("invalid dword read request"); - - return _data->readUint32LE(); -} - -MemoryChunk::MemoryChunk(byte *data) { - if (data == 0) - error("Chunk() called with NULL pointer"); - - _type = (Chunk::type)READ_BE_UINT32(data); - _size = READ_BE_UINT32(data + 4); - _data = data + sizeof(Chunk::type) + sizeof(uint32); - _curPos = 0; -} - -Chunk *MemoryChunk::subBlock() { - MemoryChunk *ptr = new MemoryChunk(_data + _curPos); - seek(sizeof(Chunk::type) + sizeof(uint32) + ptr->getSize()); - return ptr; -} - -void MemoryChunk::reseek() { -} - -bool MemoryChunk::read(void *buffer, uint32 size) { - if (size <= 0 || (_curPos + size) > _size) - error("invalid buffer read request"); - - memcpy(buffer, _data + _curPos, size); - _curPos += size; - return true; -} - -int8 MemoryChunk::getChar() { - if (_curPos >= _size) - error("invalid char read request"); - - return _data[_curPos++]; -} - -byte MemoryChunk::getByte() { - if (_curPos >= _size) - error("invalid byte read request"); - - byte *ptr = (byte *)(_data + _curPos); - _curPos += 1; - return *ptr; -} - -int16 MemoryChunk::getShort() { - if (_curPos >= _size - 1) - error("invalid int16 read request"); - - int16 buffer = getWord(); - return *((int16 *)&buffer); -} - -uint16 MemoryChunk::getWord() { - if (_curPos >= _size - 1) - error("invalid word read request"); - - uint16 *ptr = (uint16 *)(_data + _curPos); - _curPos += 2; - return READ_LE_UINT16(ptr); -} - -uint32 MemoryChunk::getDword() { - if (_curPos >= _size - 3) - error("invalid dword read request"); - - uint32 *ptr = (uint32 *)(_data + _curPos); - _curPos += 4; - return READ_LE_UINT32(ptr); -} - -} // End of namespace Scumm diff --git a/scumm/smush/chunk.h b/scumm/smush/chunk.h deleted file mode 100644 index 26290538a6..0000000000 --- a/scumm/smush/chunk.h +++ /dev/null @@ -1,110 +0,0 @@ -/* ScummVM - Scumm Interpreter - * Copyright (C) 2002-2006 The ScummVM project - * - * 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$ - * - */ - -#ifndef CHUNK_H -#define CHUNK_H - -#include "common/scummsys.h" -#include "common/str.h" -#include "scumm/util.h" - -namespace Scumm { - -class ScummFile; - -class Chunk { -public: - virtual ~Chunk() {}; - enum seek_type { seek_start, seek_end, seek_cur }; - typedef uint32 type; - static const char *ChunkString(type t); - virtual type getType() const = 0; - virtual uint32 getSize() const = 0; - virtual Chunk *subBlock() = 0; - virtual void reseek() = 0; - virtual bool eof() const = 0; - virtual uint32 tell() const = 0; - virtual bool seek(int32 delta, seek_type dir = seek_cur) = 0; - virtual bool read(void *buffer, uint32 size) = 0; - virtual int8 getChar() = 0; - virtual byte getByte() = 0; - virtual int16 getShort() = 0; - virtual uint16 getWord() = 0; - virtual uint32 getDword() = 0; -}; - -// Common functionality for concrete chunks (FileChunk, MemoryChunk) -class BaseChunk : public Chunk { -protected: - Chunk::type _type; - uint32 _size; - uint32 _curPos; - - BaseChunk(); - -public: - Chunk::type getType() const; - uint32 getSize() const; - bool eof() const; - uint32 tell() const; - bool seek(int32 delta, seek_type dir = seek_cur); -}; - -class FileChunk : public BaseChunk { -private: - ScummFile *_data; - bool _deleteData; - uint32 _offset; - - FileChunk(ScummFile *data, int offset); -public: - FileChunk(const Common::String &name, int offset = 0); - virtual ~FileChunk(); - Chunk *subBlock(); - void reseek(); - bool read(void *buffer, uint32 size); - int8 getChar(); - byte getByte(); - short getShort(); - uint16 getWord(); - uint32 getDword(); -}; - -class MemoryChunk : public BaseChunk { -private: - byte *_data; - -public: - MemoryChunk(byte *data); - Chunk *subBlock(); - void reseek(); - bool read(void *buffer, uint32 size); - int8 getChar(); - byte getByte(); - int16 getShort(); - uint16 getWord(); - uint32 getDword(); -}; - -} // End of namespace Scumm - -#endif diff --git a/scumm/smush/chunk_type.h b/scumm/smush/chunk_type.h deleted file mode 100644 index 18c49f0dbf..0000000000 --- a/scumm/smush/chunk_type.h +++ /dev/null @@ -1,60 +0,0 @@ -/* ScummVM - Scumm Interpreter - * Copyright (C) 2002-2006 The ScummVM project - * - * 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$ - * - */ - -#ifndef CHUNK_TYPE_H -#define CHUNK_TYPE_H - -#include "common/scummsys.h" -#include "scumm/smush/chunk.h" - -namespace Scumm { - -static const Chunk::type TYPE_ANIM = 'ANIM'; -static const Chunk::type TYPE_AHDR = 'AHDR'; -static const Chunk::type TYPE_FRME = 'FRME'; -static const Chunk::type TYPE_NPAL = 'NPAL'; -static const Chunk::type TYPE_FOBJ = 'FOBJ'; -static const Chunk::type TYPE_ZFOB = 'ZFOB'; -static const Chunk::type TYPE_PSAD = 'PSAD'; -static const Chunk::type TYPE_TRES = 'TRES'; -static const Chunk::type TYPE_XPAL = 'XPAL'; -static const Chunk::type TYPE_IACT = 'IACT'; -static const Chunk::type TYPE_STOR = 'STOR'; -static const Chunk::type TYPE_FTCH = 'FTCH'; -static const Chunk::type TYPE_SKIP = 'SKIP'; -static const Chunk::type TYPE_STRK = 'STRK'; -static const Chunk::type TYPE_SMRK = 'SMRK'; -static const Chunk::type TYPE_SHDR = 'SHDR'; -static const Chunk::type TYPE_SDAT = 'SDAT'; -static const Chunk::type TYPE_SAUD = 'SAUD'; -static const Chunk::type TYPE_iMUS = 'iMUS'; -static const Chunk::type TYPE_FRMT = 'FRMT'; -static const Chunk::type TYPE_TEXT = 'TEXT'; -static const Chunk::type TYPE_REGN = 'REGN'; -static const Chunk::type TYPE_STOP = 'STOP'; -static const Chunk::type TYPE_MAP_ = 'MAP '; -static const Chunk::type TYPE_DATA = 'DATA'; -static const Chunk::type TYPE_ETRS = 'ETRS'; - -} // End of namespace Scumm - -#endif diff --git a/scumm/smush/codec1.cpp b/scumm/smush/codec1.cpp deleted file mode 100644 index 04d55e2ed7..0000000000 --- a/scumm/smush/codec1.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/* ScummVM - Scumm Interpreter - * Copyright (C) 2002-2006 The ScummVM project - * - * 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 "common/stdafx.h" -#include "common/scummsys.h" - -namespace Scumm { - -void smush_decode_codec1(byte *dst, const byte *src, int left, int top, int width, int height, int pitch) { - byte val, code; - int32 length; - int h = height, size_line; - - dst += top * pitch; - for (h = 0; h < height; h++) { - size_line = READ_LE_UINT16(src); - src += 2; - dst += left; - while (size_line > 0) { - code = *src++; - size_line--; - length = (code >> 1) + 1; - if (code & 1) { - val = *src++; - size_line--; - if (val) - memset(dst, val, length); - dst += length; - } else { - size_line -= length; - while (length--) { - val = *src++; - if (val) - *dst = val; - dst++; - } - } - } - dst += pitch - left - width; - } -} - -} // End of namespace Scumm diff --git a/scumm/smush/codec37.cpp b/scumm/smush/codec37.cpp deleted file mode 100644 index 732bffeeae..0000000000 --- a/scumm/smush/codec37.cpp +++ /dev/null @@ -1,588 +0,0 @@ -/* ScummVM - Scumm Interpreter - * Copyright (C) 2002-2006 The ScummVM project - * - * 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 "common/stdafx.h" -#include "common/util.h" -#include "scumm/bomp.h" -#include "scumm/smush/codec37.h" - -namespace Scumm { - -void Codec37Decoder::init(int width, int height) { - deinit(); - _width = width; - _height = height; - _frameSize = _width * _height; - _deltaSize = _frameSize * 3 + 0x13600; - _deltaBuf = (byte *)calloc(_deltaSize, sizeof(byte)); - if (_deltaBuf == 0) - error("unable to allocate decoder buffer"); - _deltaBufs[0] = _deltaBuf + 0x4D80; - _deltaBufs[1] = _deltaBuf + 0xE880 + _frameSize; - _offsetTable = new int16[255]; - _curtable = 0; - if (_offsetTable == 0) - error("unable to allocate decoder offset table"); - _tableLastPitch = -1; - _tableLastIndex = -1; -} - -Codec37Decoder::Codec37Decoder() { - _deltaSize = 0; - _deltaBuf = 0; - _deltaBufs[0] = 0; - _deltaBufs[1] = 0; - _curtable = 0; - _offsetTable = 0; - _tableLastPitch = -1; - _tableLastIndex = -1; - _prevSeqNb = 0; -} - -void Codec37Decoder::deinit() { - if (_offsetTable) { - delete []_offsetTable; - _offsetTable = 0; - _tableLastPitch = -1; - _tableLastIndex = -1; - } - if (_deltaBuf) { - free(_deltaBuf); - _deltaSize = 0; - _deltaBuf = 0; - _deltaBufs[0] = 0; - _deltaBufs[1] = 0; - } -} - -Codec37Decoder::~Codec37Decoder() { - deinit(); -} - -void Codec37Decoder::maketable(int pitch, int index) { - static const int8 maketable_bytes[] = { - 0, 0, 1, 0, 2, 0, 3, 0, 5, 0, - 8, 0, 13, 0, 21, 0, -1, 0, -2, 0, - -3, 0, -5, 0, -8, 0, -13, 0, -17, 0, - -21, 0, 0, 1, 1, 1, 2, 1, 3, 1, - 5, 1, 8, 1, 13, 1, 21, 1, -1, 1, - -2, 1, -3, 1, -5, 1, -8, 1, -13, 1, - -17, 1, -21, 1, 0, 2, 1, 2, 2, 2, - 3, 2, 5, 2, 8, 2, 13, 2, 21, 2, - -1, 2, -2, 2, -3, 2, -5, 2, -8, 2, - -13, 2, -17, 2, -21, 2, 0, 3, 1, 3, - 2, 3, 3, 3, 5, 3, 8, 3, 13, 3, - 21, 3, -1, 3, -2, 3, -3, 3, -5, 3, - -8, 3, -13, 3, -17, 3, -21, 3, 0, 5, - 1, 5, 2, 5, 3, 5, 5, 5, 8, 5, - 13, 5, 21, 5, -1, 5, -2, 5, -3, 5, - -5, 5, -8, 5, -13, 5, -17, 5, -21, 5, - 0, 8, 1, 8, 2, 8, 3, 8, 5, 8, - 8, 8, 13, 8, 21, 8, -1, 8, -2, 8, - -3, 8, -5, 8, -8, 8, -13, 8, -17, 8, - -21, 8, 0, 13, 1, 13, 2, 13, 3, 13, - 5, 13, 8, 13, 13, 13, 21, 13, -1, 13, - -2, 13, -3, 13, -5, 13, -8, 13, -13, 13, - -17, 13, -21, 13, 0, 21, 1, 21, 2, 21, - 3, 21, 5, 21, 8, 21, 13, 21, 21, 21, - -1, 21, -2, 21, -3, 21, -5, 21, -8, 21, - -13, 21, -17, 21, -21, 21, 0, -1, 1, -1, - 2, -1, 3, -1, 5, -1, 8, -1, 13, -1, - 21, -1, -1, -1, -2, -1, -3, -1, -5, -1, - -8, -1, -13, -1, -17, -1, -21, -1, 0, -2, - 1, -2, 2, -2, 3, -2, 5, -2, 8, -2, - 13, -2, 21, -2, -1, -2, -2, -2, -3, -2, - -5, -2, -8, -2, -13, -2, -17, -2, -21, -2, - 0, -3, 1, -3, 2, -3, 3, -3, 5, -3, - 8, -3, 13, -3, 21, -3, -1, -3, -2, -3, - -3, -3, -5, -3, -8, -3, -13, -3, -17, -3, - -21, -3, 0, -5, 1, -5, 2, -5, 3, -5, - 5, -5, 8, -5, 13, -5, 21, -5, -1, -5, - -2, -5, -3, -5, -5, -5, -8, -5, -13, -5, - -17, -5, -21, -5, 0, -8, 1, -8, 2, -8, - 3, -8, 5, -8, 8, -8, 13, -8, 21, -8, - -1, -8, -2, -8, -3, -8, -5, -8, -8, -8, - -13, -8, -17, -8, -21, -8, 0, -13, 1, -13, - 2, -13, 3, -13, 5, -13, 8, -13, 13, -13, - 21, -13, -1, -13, -2, -13, -3, -13, -5, -13, - -8, -13, -13, -13, -17, -13, -21, -13, 0, -17, - 1, -17, 2, -17, 3, -17, 5, -17, 8, -17, - 13, -17, 21, -17, -1, -17, -2, -17, -3, -17, - -5, -17, -8, -17, -13, -17, -17, -17, -21, -17, - 0, -21, 1, -21, 2, -21, 3, -21, 5, -21, - 8, -21, 13, -21, 21, -21, -1, -21, -2, -21, - -3, -21, -5, -21, -8, -21, -13, -21, -17, -21, - 0, 0, -8, -29, 8, -29, -18, -25, 17, -25, - 0, -23, -6, -22, 6, -22, -13, -19, 12, -19, - 0, -18, 25, -18, -25, -17, -5, -17, 5, -17, - -10, -15, 10, -15, 0, -14, -4, -13, 4, -13, - 19, -13, -19, -12, -8, -11, -2, -11, 0, -11, - 2, -11, 8, -11, -15, -10, -4, -10, 4, -10, - 15, -10, -6, -9, -1, -9, 1, -9, 6, -9, - -29, -8, -11, -8, -8, -8, -3, -8, 3, -8, - 8, -8, 11, -8, 29, -8, -5, -7, -2, -7, - 0, -7, 2, -7, 5, -7, -22, -6, -9, -6, - -6, -6, -3, -6, -1, -6, 1, -6, 3, -6, - 6, -6, 9, -6, 22, -6, -17, -5, -7, -5, - -4, -5, -2, -5, 0, -5, 2, -5, 4, -5, - 7, -5, 17, -5, -13, -4, -10, -4, -5, -4, - -3, -4, -1, -4, 0, -4, 1, -4, 3, -4, - 5, -4, 10, -4, 13, -4, -8, -3, -6, -3, - -4, -3, -3, -3, -2, -3, -1, -3, 0, -3, - 1, -3, 2, -3, 4, -3, 6, -3, 8, -3, - -11, -2, -7, -2, -5, -2, -3, -2, -2, -2, - -1, -2, 0, -2, 1, -2, 2, -2, 3, -2, - 5, -2, 7, -2, 11, -2, -9, -1, -6, -1, - -4, -1, -3, -1, -2, -1, -1, -1, 0, -1, - 1, -1, 2, -1, 3, -1, 4, -1, 6, -1, - 9, -1, -31, 0, -23, 0, -18, 0, -14, 0, - -11, 0, -7, 0, -5, 0, -4, 0, -3, 0, - -2, 0, -1, 0, 0, -31, 1, 0, 2, 0, - 3, 0, 4, 0, 5, 0, 7, 0, 11, 0, - 14, 0, 18, 0, 23, 0, 31, 0, -9, 1, - -6, 1, -4, 1, -3, 1, -2, 1, -1, 1, - 0, 1, 1, 1, 2, 1, 3, 1, 4, 1, - 6, 1, 9, 1, -11, 2, -7, 2, -5, 2, - -3, 2, -2, 2, -1, 2, 0, 2, 1, 2, - 2, 2, 3, 2, 5, 2, 7, 2, 11, 2, - -8, 3, -6, 3, -4, 3, -2, 3, -1, 3, - 0, 3, 1, 3, 2, 3, 3, 3, 4, 3, - 6, 3, 8, 3, -13, 4, -10, 4, -5, 4, - -3, 4, -1, 4, 0, 4, 1, 4, 3, 4, - 5, 4, 10, 4, 13, 4, -17, 5, -7, 5, - -4, 5, -2, 5, 0, 5, 2, 5, 4, 5, - 7, 5, 17, 5, -22, 6, -9, 6, -6, 6, - -3, 6, -1, 6, 1, 6, 3, 6, 6, 6, - 9, 6, 22, 6, -5, 7, -2, 7, 0, 7, - 2, 7, 5, 7, -29, 8, -11, 8, -8, 8, - -3, 8, 3, 8, 8, 8, 11, 8, 29, 8, - -6, 9, -1, 9, 1, 9, 6, 9, -15, 10, - -4, 10, 4, 10, 15, 10, -8, 11, -2, 11, - 0, 11, 2, 11, 8, 11, 19, 12, -19, 13, - -4, 13, 4, 13, 0, 14, -10, 15, 10, 15, - -5, 17, 5, 17, 25, 17, -25, 18, 0, 18, - -12, 19, 13, 19, -6, 22, 6, 22, 0, 23, - -17, 25, 18, 25, -8, 29, 8, 29, 0, 31, - 0, 0, -6, -22, 6, -22, -13, -19, 12, -19, - 0, -18, -5, -17, 5, -17, -10, -15, 10, -15, - 0, -14, -4, -13, 4, -13, 19, -13, -19, -12, - -8, -11, -2, -11, 0, -11, 2, -11, 8, -11, - -15, -10, -4, -10, 4, -10, 15, -10, -6, -9, - -1, -9, 1, -9, 6, -9, -11, -8, -8, -8, - -3, -8, 0, -8, 3, -8, 8, -8, 11, -8, - -5, -7, -2, -7, 0, -7, 2, -7, 5, -7, - -22, -6, -9, -6, -6, -6, -3, -6, -1, -6, - 1, -6, 3, -6, 6, -6, 9, -6, 22, -6, - -17, -5, -7, -5, -4, -5, -2, -5, -1, -5, - 0, -5, 1, -5, 2, -5, 4, -5, 7, -5, - 17, -5, -13, -4, -10, -4, -5, -4, -3, -4, - -2, -4, -1, -4, 0, -4, 1, -4, 2, -4, - 3, -4, 5, -4, 10, -4, 13, -4, -8, -3, - -6, -3, -4, -3, -3, -3, -2, -3, -1, -3, - 0, -3, 1, -3, 2, -3, 3, -3, 4, -3, - 6, -3, 8, -3, -11, -2, -7, -2, -5, -2, - -4, -2, -3, -2, -2, -2, -1, -2, 0, -2, - 1, -2, 2, -2, 3, -2, 4, -2, 5, -2, - 7, -2, 11, -2, -9, -1, -6, -1, -5, -1, - -4, -1, -3, -1, -2, -1, -1, -1, 0, -1, - 1, -1, 2, -1, 3, -1, 4, -1, 5, -1, - 6, -1, 9, -1, -23, 0, -18, 0, -14, 0, - -11, 0, -7, 0, -5, 0, -4, 0, -3, 0, - -2, 0, -1, 0, 0, -23, 1, 0, 2, 0, - 3, 0, 4, 0, 5, 0, 7, 0, 11, 0, - 14, 0, 18, 0, 23, 0, -9, 1, -6, 1, - -5, 1, -4, 1, -3, 1, -2, 1, -1, 1, - 0, 1, 1, 1, 2, 1, 3, 1, 4, 1, - 5, 1, 6, 1, 9, 1, -11, 2, -7, 2, - -5, 2, -4, 2, -3, 2, -2, 2, -1, 2, - 0, 2, 1, 2, 2, 2, 3, 2, 4, 2, - 5, 2, 7, 2, 11, 2, -8, 3, -6, 3, - -4, 3, -3, 3, -2, 3, -1, 3, 0, 3, - 1, 3, 2, 3, 3, 3, 4, 3, 6, 3, - 8, 3, -13, 4, -10, 4, -5, 4, -3, 4, - -2, 4, -1, 4, 0, 4, 1, 4, 2, 4, - 3, 4, 5, 4, 10, 4, 13, 4, -17, 5, - -7, 5, -4, 5, -2, 5, -1, 5, 0, 5, - 1, 5, 2, 5, 4, 5, 7, 5, 17, 5, - -22, 6, -9, 6, -6, 6, -3, 6, -1, 6, - 1, 6, 3, 6, 6, 6, 9, 6, 22, 6, - -5, 7, -2, 7, 0, 7, 2, 7, 5, 7, - -11, 8, -8, 8, -3, 8, 0, 8, 3, 8, - 8, 8, 11, 8, -6, 9, -1, 9, 1, 9, - 6, 9, -15, 10, -4, 10, 4, 10, 15, 10, - -8, 11, -2, 11, 0, 11, 2, 11, 8, 11, - 19, 12, -19, 13, -4, 13, 4, 13, 0, 14, - -10, 15, 10, 15, -5, 17, 5, 17, 0, 18, - -12, 19, 13, 19, -6, 22, 6, 22, 0, 23, - }; - - if (_tableLastPitch == pitch && _tableLastIndex == index) - return; - - _tableLastPitch = pitch; - _tableLastIndex = index; - index *= 255; - assert(index + 254 < (int32)(sizeof(maketable_bytes) / 2)); - - for (int32 i = 0; i < 255; i++) { - int32 j = (i + index) * 2; - _offsetTable[i] = maketable_bytes[j + 1] * pitch + maketable_bytes[j]; - } -} - -#if defined(SCUMM_NEED_ALIGNMENT) - -#define DECLARE_LITERAL_TEMP(v) \ - byte v - -#define READ_LITERAL_PIXEL(src, v) \ - v = *src++ - -#define WRITE_4X1_LINE(dst, v) \ - do { \ - int j; \ - for (j=0; j<4; j++) \ - (dst)[j] = v; \ - } while (0) - -#define COPY_4X1_LINE(dst, src) \ - do { \ - int j; \ - for (j=0; j<4; j++) \ - (dst)[j] = (src)[j]; \ - } while (0) - -#else /* SCUMM_NEED_ALIGNMENT */ - -#define DECLARE_LITERAL_TEMP(v) \ - uint32 v - -#define READ_LITERAL_PIXEL(src, v) \ - do { \ - v = *src++; \ - v += (v << 8) + (v << 16) + (v << 24); \ - } while (0) - -#define WRITE_4X1_LINE(dst, v) \ - *(uint32 *)(dst) = v - -#define COPY_4X1_LINE(dst, src) \ - *(uint32 *)(dst) = *(const uint32 *)(src) - -#endif /* SCUMM_NEED_ALIGNMENT */ - -/* Fill a 4x4 pixel block with a literal pixel value */ - -#define LITERAL_4X4(src, dst, pitch) \ - do { \ - int x; \ - DECLARE_LITERAL_TEMP(t); \ - READ_LITERAL_PIXEL(src, t); \ - for (x=0; x<4; x++) { \ - WRITE_4X1_LINE(dst + pitch * x, t); \ - } \ - dst += 4; \ - } while (0) - -/* Fill four 4x1 pixel blocks with literal pixel values */ - -#define LITERAL_4X1(src, dst, pitch) \ - do { \ - int x; \ - DECLARE_LITERAL_TEMP(t); \ - for (x=0; x<4; x++) { \ - READ_LITERAL_PIXEL(src, t); \ - WRITE_4X1_LINE(dst + pitch * x, t); \ - } \ - dst += 4; \ - } while (0) - -/* Fill sixteen 1x1 pixel blocks with literal pixel values */ - -#define LITERAL_1X1(src, dst, pitch) \ - do { \ - int x; \ - for (x=0; x<4; x++) { \ - COPY_4X1_LINE(dst + pitch * x, src); \ - src += 4; \ - } \ - dst += 4; \ - } while (0) - -/* Copy a 4x4 pixel block from a different place in the framebuffer */ - -#define COPY_4X4(dst2, dst, pitch) \ - do { \ - int x; \ - for (x=0; x<4; x++) { \ - COPY_4X1_LINE(dst + pitch * x, dst2 + pitch * x); \ - } \ - dst += 4; \ - } while (0) - -void Codec37Decoder::proc1(byte *dst, const byte *src, int32 next_offs, int bw, int bh, int pitch, int16 *offset_table) { - uint8 code; - bool filling, skipCode; - int32 len; - int i, p; - uint32 pitches[16]; - - i = bw; - for (p = 0; p < 16; ++p) { - pitches[p] = (p >> 2) * pitch + (p & 0x3); - } - code = 0; - filling = false; - len = -1; - while (1) { - if (len < 0) { - filling = (*src & 1) == 1; - len = *src++ >> 1; - skipCode = false; - } else { - skipCode = true; - } - if (!filling || !skipCode) { - code = *src++; - if (code == 0xFF) { - --len; - for (p = 0; p < 0x10; ++p) { - if (len < 0) { - filling = (*src & 1) == 1; - len = *src++ >> 1; - if (filling) { - code = *src++; - } - } - if (filling) { - *(dst + pitches[p]) = code; - } else { - *(dst + pitches[p]) = *src++; - } - --len; - } - dst += 4; - --i; - if (i == 0) { - dst += pitch * 3; - --bh; - if (bh == 0) return; - i = bw; - } - continue; - } - } - byte *dst2 = dst + offset_table[code] + next_offs; - COPY_4X4(dst2, dst, pitch); - --i; - if (i == 0) { - dst += pitch * 3; - --bh; - if (bh == 0) return; - i = bw; - } - --len; - } -} - -void Codec37Decoder::proc3WithFDFE(byte *dst, const byte *src, int32 next_offs, int bw, int bh, int pitch, int16 *offset_table) { - do { - int32 i = bw; - do { - int32 code = *src++; - if (code == 0xFD) { - LITERAL_4X4(src, dst, pitch); - } else if (code == 0xFE) { - LITERAL_4X1(src, dst, pitch); - } else if (code == 0xFF) { - LITERAL_1X1(src, dst, pitch); - } else { - byte *dst2 = dst + _offsetTable[code] + next_offs; - COPY_4X4(dst2, dst, pitch); - } - } while (--i); - dst += pitch * 3; - } while (--bh); -} - -void Codec37Decoder::proc3WithoutFDFE(byte *dst, const byte *src, int32 next_offs, int bw, int bh, int pitch, int16 *offset_table) { - do { - int32 i = bw; - do { - int32 code = *src++; - if (code == 0xFF) { - LITERAL_1X1(src, dst, pitch); - } else { - byte *dst2 = dst + _offsetTable[code] + next_offs; - COPY_4X4(dst2, dst, pitch); - } - } while (--i); - dst += pitch * 3; - } while (--bh); -} - -void Codec37Decoder::proc4WithFDFE(byte *dst, const byte *src, int32 next_offs, int bw, int bh, int pitch, int16 *offset_table) { - do { - int32 i = bw; - do { - int32 code = *src++; - if (code == 0xFD) { - LITERAL_4X4(src, dst, pitch); - } else if (code == 0xFE) { - LITERAL_4X1(src, dst, pitch); - } else if (code == 0xFF) { - LITERAL_1X1(src, dst, pitch); - } else if (code == 0x00) { - int32 length = *src++ + 1; - for (int32 l = 0; l < length; l++) { - byte *dst2 = dst + next_offs; - COPY_4X4(dst2, dst, pitch); - i--; - if (i == 0) { - dst += pitch * 3; - bh--; - i = bw; - } - } - if (bh == 0) { - return; - } - i++; - } else { - byte *dst2 = dst + _offsetTable[code] + next_offs; - COPY_4X4(dst2, dst, pitch); - } - } while (--i); - dst += pitch * 3; - } while (--bh); -} - -void Codec37Decoder::proc4WithoutFDFE(byte *dst, const byte *src, int32 next_offs, int bw, int bh, int pitch, int16 *offset_table) { - do { - int32 i = bw; - do { - int32 code = *src++; - if (code == 0xFF) { - LITERAL_1X1(src, dst, pitch); - } else if (code == 0x00) { - int32 length = *src++ + 1; - for (int32 l = 0; l < length; l++) { - byte *dst2 = dst + next_offs; - COPY_4X4(dst2, dst, pitch); - i--; - if (i == 0) { - dst += pitch * 3; - bh--; - i = bw; - } - } - if (bh == 0) { - return; - } - i++; - } else { - byte *dst2 = dst + _offsetTable[code] + next_offs; - COPY_4X4(dst2, dst, pitch); - } - } while (--i); - dst += pitch * 3; - } while (--bh); -} - -void Codec37Decoder::decode(byte *dst, const byte *src) { - int32 bw = (_width + 3) / 4, bh = (_height + 3) / 4; - int32 pitch = bw * 4; - - int16 seq_nb = READ_LE_UINT16(src + 2); - int32 decoded_size = READ_LE_UINT32(src + 4); - byte mask_flags = src[12]; - maketable(pitch, src[1]); - int32 tmp; - - switch(src[0]) { - case 0: - if ((_deltaBufs[_curtable] - _deltaBuf) > 0) { - memset(_deltaBuf, 0, _deltaBufs[_curtable] - _deltaBuf); - } - tmp = (_deltaBuf + _deltaSize) - _deltaBufs[_curtable] - decoded_size; - if (tmp > 0) { - memset(_deltaBufs[_curtable] + decoded_size, 0, tmp); - } - memcpy(_deltaBufs[_curtable], src + 16, decoded_size); - break; - case 1: - if ((seq_nb & 1) || !(mask_flags & 1)) { - _curtable ^= 1; - } - proc1(_deltaBufs[_curtable], src + 16, _deltaBufs[_curtable ^ 1] - _deltaBufs[_curtable], - bw, bh, pitch, _offsetTable); - break; - case 2: - bompDecodeLine(_deltaBufs[_curtable], src + 16, decoded_size); - if ((_deltaBufs[_curtable] - _deltaBuf) > 0) { - memset(_deltaBuf, 0, _deltaBufs[_curtable] - _deltaBuf); - } - tmp = (_deltaBuf + _deltaSize) - _deltaBufs[_curtable] - decoded_size; - if (tmp > 0) { - memset(_deltaBufs[_curtable] + decoded_size, 0, tmp); - } - break; - case 3: - if ((seq_nb & 1) || !(mask_flags & 1)) { - _curtable ^= 1; - } - - if ((mask_flags & 4) != 0) { - proc3WithFDFE(_deltaBufs[_curtable], src + 16, - _deltaBufs[_curtable ^ 1] - _deltaBufs[_curtable], bw, bh, - pitch, _offsetTable); - } else { - proc3WithoutFDFE(_deltaBufs[_curtable], src + 16, - _deltaBufs[_curtable ^ 1] - _deltaBufs[_curtable], bw, bh, - pitch, _offsetTable); - } - break; - case 4: - if ((seq_nb & 1) || !(mask_flags & 1)) { - _curtable ^= 1; - } - - if ((mask_flags & 4) != 0) { - proc4WithFDFE(_deltaBufs[_curtable], src + 16, - _deltaBufs[_curtable ^ 1] - _deltaBufs[_curtable], bw, bh, - pitch, _offsetTable); - } else { - proc4WithoutFDFE(_deltaBufs[_curtable], src + 16, - _deltaBufs[_curtable ^ 1] - _deltaBufs[_curtable], bw, bh, - pitch, _offsetTable); - } - break; - default: - break; - } - _prevSeqNb = seq_nb; - - memcpy(dst, _deltaBufs[_curtable], _frameSize); -} - -} // End of namespace Scumm - diff --git a/scumm/smush/codec37.h b/scumm/smush/codec37.h deleted file mode 100644 index 534316c1e5..0000000000 --- a/scumm/smush/codec37.h +++ /dev/null @@ -1,62 +0,0 @@ -/* ScummVM - Scumm Interpreter - * Copyright (C) 2002-2006 The ScummVM project - * - * 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$ - * - */ - -#ifndef SMUSH_CODEC37_H -#define SMUSH_CODEC37_H - -#include "common/scummsys.h" - -namespace Scumm { - -class Codec37Decoder { -private: - - int32 _deltaSize; - byte *_deltaBufs[2]; - byte *_deltaBuf; - int16 *_offsetTable; - int _curtable; - uint16 _prevSeqNb; - int _tableLastPitch; - int _tableLastIndex; - int32 _frameSize; - int _width, _height; - -public: - Codec37Decoder(); - ~Codec37Decoder(); - void init(int width, int height); - void deinit(); -protected: - void maketable(int, int); - void proc1(byte *dst, const byte *src, int32, int, int, int, int16 *); - void proc3WithFDFE(byte *dst, const byte *src, int32, int, int, int, int16 *); - void proc3WithoutFDFE(byte *dst, const byte *src, int32, int, int, int, int16 *); - void proc4WithFDFE(byte *dst, const byte *src, int32, int, int, int, int16 *); - void proc4WithoutFDFE(byte *dst, const byte *src, int32, int, int, int, int16 *); -public: - void decode(byte *dst, const byte *src); -}; - -} // End of namespace Scumm - -#endif diff --git a/scumm/smush/codec47.cpp b/scumm/smush/codec47.cpp deleted file mode 100644 index ef10a282a9..0000000000 --- a/scumm/smush/codec47.cpp +++ /dev/null @@ -1,630 +0,0 @@ -/* ScummVM - Scumm Interpreter - * Copyright (C) 2002-2006 The ScummVM project - * - * 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 "common/stdafx.h" -#include "common/util.h" -#include "scumm/bomp.h" -#include "scumm/smush/codec47.h" - -namespace Scumm { - -#if defined(SCUMM_NEED_ALIGNMENT) - -#define COPY_4X1_LINE(dst, src) \ - do { \ - (dst)[0] = (src)[0]; \ - (dst)[1] = (src)[1]; \ - (dst)[2] = (src)[2]; \ - (dst)[3] = (src)[3]; \ - } while (0) - -#define COPY_2X1_LINE(dst, src) \ - do { \ - (dst)[0] = (src)[0]; \ - (dst)[1] = (src)[1]; \ - } while (0) - - -#else /* SCUMM_NEED_ALIGNMENT */ - -#define COPY_4X1_LINE(dst, src) \ - *(uint32 *)(dst) = *(const uint32 *)(src) - -#define COPY_2X1_LINE(dst, src) \ - *(uint16 *)(dst) = *(const uint16 *)(src) - -#endif - -#define FILL_4X1_LINE(dst, val) \ - do { \ - (dst)[0] = val; \ - (dst)[1] = val; \ - (dst)[2] = val; \ - (dst)[3] = val; \ - } while (0) - -#define FILL_2X1_LINE(dst, val) \ - do { \ - (dst)[0] = val; \ - (dst)[1] = val; \ - } while (0) - -static int8 codec47_table_small1[] = { - 0, 1, 2, 3, 3, 3, 3, 2, 1, 0, 0, 0, 1, 2, 2, 1, -}; - -static int8 codec47_table_small2[] = { - 0, 0, 0, 0, 1, 2, 3, 3, 3, 3, 2, 1, 1, 1, 2, 2, -}; - -static int8 codec47_table_big1[] = { - 0, 2, 5, 7, 7, 7, 7, 7, 7, 5, 2, 0, 0, 0, 0, 0, -}; - -static int8 codec47_table_big2[] = { - 0, 0, 0, 0, 1, 3, 4, 6, 7, 7, 7, 7, 6, 4, 3, 1, -}; - -#ifdef PALMOS_68K -static const int8 *codec47_table; -#else -static const int8 codec47_table[] = { - 0, 0, -1, -43, 6, -43, -9, -42, 13, -41, - -16, -40, 19, -39, -23, -36, 26, -34, -2, -33, - 4, -33, -29, -32, -9, -32, 11, -31, -16, -29, - 32, -29, 18, -28, -34, -26, -22, -25, -1, -25, - 3, -25, -7, -24, 8, -24, 24, -23, 36, -23, - -12, -22, 13, -21, -38, -20, 0, -20, -27, -19, - -4, -19, 4, -19, -17, -18, -8, -17, 8, -17, - 18, -17, 28, -17, 39, -17, -12, -15, 12, -15, - -21, -14, -1, -14, 1, -14, -41, -13, -5, -13, - 5, -13, 21, -13, -31, -12, -15, -11, -8, -11, - 8, -11, 15, -11, -2, -10, 1, -10, 31, -10, - -23, -9, -11, -9, -5, -9, 4, -9, 11, -9, - 42, -9, 6, -8, 24, -8, -18, -7, -7, -7, - -3, -7, -1, -7, 2, -7, 18, -7, -43, -6, - -13, -6, -4, -6, 4, -6, 8, -6, -33, -5, - -9, -5, -2, -5, 0, -5, 2, -5, 5, -5, - 13, -5, -25, -4, -6, -4, -3, -4, 3, -4, - 9, -4, -19, -3, -7, -3, -4, -3, -2, -3, - -1, -3, 0, -3, 1, -3, 2, -3, 4, -3, - 6, -3, 33, -3, -14, -2, -10, -2, -5, -2, - -3, -2, -2, -2, -1, -2, 0, -2, 1, -2, - 2, -2, 3, -2, 5, -2, 7, -2, 14, -2, - 19, -2, 25, -2, 43, -2, -7, -1, -3, -1, - -2, -1, -1, -1, 0, -1, 1, -1, 2, -1, - 3, -1, 10, -1, -5, 0, -3, 0, -2, 0, - -1, 0, 1, 0, 2, 0, 3, 0, 5, 0, - 7, 0, -10, 1, -7, 1, -3, 1, -2, 1, - -1, 1, 0, 1, 1, 1, 2, 1, 3, 1, - -43, 2, -25, 2, -19, 2, -14, 2, -5, 2, - -3, 2, -2, 2, -1, 2, 0, 2, 1, 2, - 2, 2, 3, 2, 5, 2, 7, 2, 10, 2, - 14, 2, -33, 3, -6, 3, -4, 3, -2, 3, - -1, 3, 0, 3, 1, 3, 2, 3, 4, 3, - 19, 3, -9, 4, -3, 4, 3, 4, 7, 4, - 25, 4, -13, 5, -5, 5, -2, 5, 0, 5, - 2, 5, 5, 5, 9, 5, 33, 5, -8, 6, - -4, 6, 4, 6, 13, 6, 43, 6, -18, 7, - -2, 7, 0, 7, 2, 7, 7, 7, 18, 7, - -24, 8, -6, 8, -42, 9, -11, 9, -4, 9, - 5, 9, 11, 9, 23, 9, -31, 10, -1, 10, - 2, 10, -15, 11, -8, 11, 8, 11, 15, 11, - 31, 12, -21, 13, -5, 13, 5, 13, 41, 13, - -1, 14, 1, 14, 21, 14, -12, 15, 12, 15, - -39, 17, -28, 17, -18, 17, -8, 17, 8, 17, - 17, 18, -4, 19, 0, 19, 4, 19, 27, 19, - 38, 20, -13, 21, 12, 22, -36, 23, -24, 23, - -8, 24, 7, 24, -3, 25, 1, 25, 22, 25, - 34, 26, -18, 28, -32, 29, 16, 29, -11, 31, - 9, 32, 29, 32, -4, 33, 2, 33, -26, 34, - 23, 36, -19, 39, 16, 40, -13, 41, 9, 42, - -6, 43, 1, 43, 0, 0, 0, 0, 0, 0 -}; -#endif - -void Codec47Decoder::makeTablesInterpolation(int param) { - int32 variable1, variable2; - int32 b1, b2; - int32 value_table47_1_2, value_table47_1_1, value_table47_2_2, value_table47_2_1; - int32 tableSmallBig[64], tmp, s; - int8 *table47_1 = 0, *table47_2 = 0; - int32 *ptr_small_big; - byte *ptr; - int i, x, y; - - if (param == 8) { - table47_1 = codec47_table_big1; - table47_2 = codec47_table_big2; - ptr = _tableBig + 384; - for (i = 0; i < 256; i++) { - *ptr = 0; - ptr += 388; - } - ptr = _tableBig + 385; - for (i = 0; i < 256; i++) { - *ptr = 0; - ptr += 388; - } - } else if (param == 4) { - table47_1 = codec47_table_small1; - table47_2 = codec47_table_small2; - ptr = _tableSmall + 96; - for (i = 0; i < 256; i++) { - *ptr = 0; - ptr += 128; - } - ptr = _tableSmall + 97; - for (i = 0; i < 256; i++) { - *ptr = 0; - ptr += 128; - } - } else { - error("Codec47Decoder::makeTablesInterpolation: unknown param %d", param); - } - - s = 0; - for (x = 0; x < 16; x++) { - value_table47_1_1 = table47_1[x]; - value_table47_2_1 = table47_2[x]; - for (y = 0; y < 16; y++) { - value_table47_1_2 = table47_1[y]; - value_table47_2_2 = table47_2[y]; - - if (value_table47_2_1 == 0) { - b1 = 0; - } else if (value_table47_2_1 == param - 1) { - b1 = 1; - } else if (value_table47_1_1 == 0) { - b1 = 2; - } else if (value_table47_1_1 == param - 1) { - b1 = 3; - } else { - b1 = 4; - } - - if (value_table47_2_2 == 0) { - b2 = 0; - } else if (value_table47_2_2 == param - 1) { - b2 = 1; - } else if (value_table47_1_2 == 0) { - b2 = 2; - } else if (value_table47_1_2 == param - 1) { - b2 = 3; - } else { - b2 = 4; - } - - memset(tableSmallBig, 0, param * param * 4); - - variable2 = ABS(value_table47_2_2 - value_table47_2_1); - tmp = ABS(value_table47_1_2 - value_table47_1_1); - if (variable2 <= tmp) { - variable2 = tmp; - } - - for (variable1 = 0; variable1 <= variable2; variable1++) { - int32 variable3, variable4; - - if (variable2 > 0) { - // Linearly interpolate between value_table47_1_1 and value_table47_1_2 - // respectively value_table47_2_1 and value_table47_2_2. - variable4 = (value_table47_1_1 * variable1 + value_table47_1_2 * (variable2 - variable1) + variable2 / 2) / variable2; - variable3 = (value_table47_2_1 * variable1 + value_table47_2_2 * (variable2 - variable1) + variable2 / 2) / variable2; - } else { - variable4 = value_table47_1_1; - variable3 = value_table47_2_1; - } - ptr_small_big = &tableSmallBig[param * variable3 + variable4]; - *ptr_small_big = 1; - - if ((b1 == 2 && b2 == 3) || (b2 == 2 && b1 == 3) || - (b1 == 0 && b2 != 1) || (b2 == 0 && b1 != 1)) { - if (variable3 >= 0) { - i = variable3 + 1; - while (i--) { - *ptr_small_big = 1; - ptr_small_big -= param; - } - } - } else if ((b2 != 0 && b1 == 1) || (b1 != 0 && b2 == 1)) { - if (param > variable3) { - i = param - variable3; - while (i--) { - *ptr_small_big = 1; - ptr_small_big += param; - } - } - } else if ((b1 == 2 && b2 != 3) || (b2 == 2 && b1 != 3)) { - if (variable4 >= 0) { - i = variable4 + 1; - while (i--) { - *(ptr_small_big--) = 1; - } - } - } else if ((b1 == 0 && b2 == 1) || (b2 == 0 && b1 == 1) || - (b1 == 3 && b2 != 2) || (b2 == 3 && b1 != 2)) { - if (param > variable4) { - i = param - variable4; - while (i--) { - *(ptr_small_big++) = 1; - } - } - } - } - - if (param == 8) { - for (i = 64 - 1; i >= 0; i--) { - if (tableSmallBig[i] != 0) { - _tableBig[256 + s + _tableBig[384 + s]] = (byte)i; - _tableBig[384 + s]++; - } else { - _tableBig[320 + s + _tableBig[385 + s]] = (byte)i; - _tableBig[385 + s]++; - } - } - s += 388; - } - if (param == 4) { - for (i = 16 - 1; i >= 0; i--) { - if (tableSmallBig[i] != 0) { - _tableSmall[64 + s + _tableSmall[96 + s]] = (byte)i; - _tableSmall[96 + s]++; - } else { - _tableSmall[80 + s + _tableSmall[97 + s]] = (byte)i; - _tableSmall[97 + s]++; - } - } - s += 128; - } - } - } -} - -void Codec47Decoder::makeTables47(int width) { - if (_lastTableWidth == width) - return; - - _lastTableWidth = width; - - int32 a, c, d; - int16 tmp; - - for (int l = 0; l < 512; l += 2) { - _table[l / 2] = (int16)(codec47_table[l + 1] * width + codec47_table[l]); - } - - a = 0; - c = 0; - do { - for (d = 0; d < _tableSmall[96 + c]; d++) { - tmp = _tableSmall[64 + c + d]; - tmp = (int16)((byte)(tmp >> 2) * width + (tmp & 3)); - _tableSmall[c + d * 2] = (byte)tmp; - _tableSmall[c + d * 2 + 1] = tmp >> 8; - } - for (d = 0; d < _tableSmall[97 + c]; d++) { - tmp = _tableSmall[80 + c + d]; - tmp = (int16)((byte)(tmp >> 2) * width + (tmp & 3)); - _tableSmall[32 + c + d * 2] = (byte)tmp; - _tableSmall[32 + c + d * 2 + 1] = tmp >> 8; - } - for (d = 0; d < _tableBig[384 + a]; d++) { - tmp = _tableBig[256 + a + d]; - tmp = (int16)((byte)(tmp >> 3) * width + (tmp & 7)); - _tableBig[a + d * 2] = (byte)tmp; - _tableBig[a + d * 2 + 1] = tmp >> 8; - } - for (d = 0; d < _tableBig[385 + a]; d++) { - tmp = _tableBig[320 + a + d]; - tmp = (int16)((byte)(tmp >> 3) * width + (tmp & 7)); - _tableBig[128 + a + d * 2] = (byte)tmp; - _tableBig[128 + a + d * 2 + 1] = tmp >> 8; - } - - a += 388; - c += 128; - } while (c < 32768); -} - -void Codec47Decoder::level3(byte *d_dst) { - int32 tmp; - byte code = *_d_src++; - - if (code < 0xF8) { - tmp = _table[code] + _offset1; - COPY_2X1_LINE(d_dst, d_dst + tmp); - COPY_2X1_LINE(d_dst + _d_pitch, d_dst + _d_pitch + tmp); - } else if (code == 0xFF) { - COPY_2X1_LINE(d_dst, _d_src + 0); - COPY_2X1_LINE(d_dst + _d_pitch, _d_src + 2); - _d_src += 4; - } else if (code == 0xFE) { - byte t = *_d_src++; - FILL_2X1_LINE(d_dst, t); - FILL_2X1_LINE(d_dst + _d_pitch, t); - } else if (code == 0xFC) { - tmp = _offset2; - COPY_2X1_LINE(d_dst, d_dst + tmp); - COPY_2X1_LINE(d_dst + _d_pitch, d_dst + _d_pitch + tmp); - } else { - byte t = _paramPtr[code]; - FILL_2X1_LINE(d_dst, t); - FILL_2X1_LINE(d_dst + _d_pitch, t); - } -} - -void Codec47Decoder::level2(byte *d_dst) { - int32 tmp; - byte code = *_d_src++; - int i; - - if (code < 0xF8) { - tmp = _table[code] + _offset1; - for (i = 0; i < 4; i++) { - COPY_4X1_LINE(d_dst, d_dst + tmp); - d_dst += _d_pitch; - } - } else if (code == 0xFF) { - level3(d_dst); - d_dst += 2; - level3(d_dst); - d_dst += _d_pitch * 2 - 2; - level3(d_dst); - d_dst += 2; - level3(d_dst); - } else if (code == 0xFE) { - byte t = *_d_src++; - for (i = 0; i < 4; i++) { - FILL_4X1_LINE(d_dst, t); - d_dst += _d_pitch; - } - } else if (code == 0xFD) { - byte *tmp_ptr = _tableSmall + *_d_src++ * 128; - int32 l = tmp_ptr[96]; - byte val = *_d_src++; - int16 *tmp_ptr2 = (int16 *)tmp_ptr; - while (l--) { - *(d_dst + READ_LE_UINT16(tmp_ptr2)) = val; - tmp_ptr2++; - } - l = tmp_ptr[97]; - val = *_d_src++; - tmp_ptr2 = (int16 *)(tmp_ptr + 32); - while (l--) { - *(d_dst + READ_LE_UINT16(tmp_ptr2)) = val; - tmp_ptr2++; - } - } else if (code == 0xFC) { - tmp = _offset2; - for (i = 0; i < 4; i++) { - COPY_4X1_LINE(d_dst, d_dst + tmp); - d_dst += _d_pitch; - } - } else { - byte t = _paramPtr[code]; - for (i = 0; i < 4; i++) { - FILL_4X1_LINE(d_dst, t); - d_dst += _d_pitch; - } - } -} - -void Codec47Decoder::level1(byte *d_dst) { - int32 tmp, tmp2; - byte code = *_d_src++; - int i; - - if (code < 0xF8) { - tmp2 = _table[code] + _offset1; - for (i = 0; i < 8; i++) { - COPY_4X1_LINE(d_dst + 0, d_dst + tmp2); - COPY_4X1_LINE(d_dst + 4, d_dst + tmp2 + 4); - d_dst += _d_pitch; - } - } else if (code == 0xFF) { - level2(d_dst); - d_dst += 4; - level2(d_dst); - d_dst += _d_pitch * 4 - 4; - level2(d_dst); - d_dst += 4; - level2(d_dst); - } else if (code == 0xFE) { - byte t = *_d_src++; - for (i = 0; i < 8; i++) { - FILL_4X1_LINE(d_dst, t); - FILL_4X1_LINE(d_dst + 4, t); - d_dst += _d_pitch; - } - } else if (code == 0xFD) { - tmp = *_d_src++; - byte *tmp_ptr = _tableBig + tmp * 388; - byte l = tmp_ptr[384]; - byte val = *_d_src++; - int16 *tmp_ptr2 = (int16 *)tmp_ptr; - while (l--) { - *(d_dst + READ_LE_UINT16(tmp_ptr2)) = val; - tmp_ptr2++; - } - l = tmp_ptr[385]; - val = *_d_src++; - tmp_ptr2 = (int16 *)(tmp_ptr + 128); - while (l--) { - *(d_dst + READ_LE_UINT16(tmp_ptr2)) = val; - tmp_ptr2++; - } - } else if (code == 0xFC) { - tmp2 = _offset2; - for (i = 0; i < 8; i++) { - COPY_4X1_LINE(d_dst + 0, d_dst + tmp2); - COPY_4X1_LINE(d_dst + 4, d_dst + tmp2 + 4); - d_dst += _d_pitch; - } - } else { - byte t = _paramPtr[code]; - for (i = 0; i < 8; i++) { - FILL_4X1_LINE(d_dst, t); - FILL_4X1_LINE(d_dst + 4, t); - d_dst += _d_pitch; - } - } -} - -void Codec47Decoder::decode2(byte *dst, const byte *src, int width, int height, const byte *param_ptr) { - _d_src = src; - _paramPtr = param_ptr - 0xf8; - int bw = (width + 7) / 8; - int bh = (height + 7) / 8; - int next_line = width * 7; - _d_pitch = width; - - do { - int tmp_bw = bw; - do { - level1(dst); - dst += 8; - } while (--tmp_bw); - dst += next_line; - } while (--bh); -} - -void Codec47Decoder::init(int width, int height) { - deinit(); - _width = width; - _height = height; - makeTablesInterpolation(4); - makeTablesInterpolation(8); - - _frameSize = _width * _height; - _deltaSize = _frameSize * 3; - _deltaBuf = (byte *)malloc(_deltaSize); - _deltaBufs[0] = _deltaBuf; - _deltaBufs[1] = _deltaBuf + _frameSize; - _curBuf = _deltaBuf + _frameSize * 2; -} - -Codec47Decoder::Codec47Decoder() { - _tableBig = (byte *)malloc(99328); - _tableSmall = (byte *)malloc(32768); - _deltaBuf = NULL; -} - -void Codec47Decoder::deinit() { - _lastTableWidth = -1; - if (_deltaBuf) { - free(_deltaBuf); - _deltaSize = 0; - _deltaBuf = NULL; - _deltaBufs[0] = NULL; - _deltaBufs[1] = NULL; - } -} - -Codec47Decoder::~Codec47Decoder() { - if (_tableBig) { - free(_tableBig); - _tableBig = NULL; - } - if (_tableSmall) { - free(_tableSmall); - _tableSmall = NULL; - } - deinit(); -} - -bool Codec47Decoder::decode(byte *dst, const byte *src) { - _offset1 = _deltaBufs[1] - _curBuf; - _offset2 = _deltaBufs[0] - _curBuf; - - int32 seq_nb = READ_LE_UINT16(src + 0); - - const byte *gfx_data = src + 26; - byte *tmp_ptr; - - if (seq_nb == 0) { - makeTables47(_width); - memset(_deltaBufs[0], src[12], _frameSize); - memset(_deltaBufs[1], src[13], _frameSize); - _prevSeqNb = -1; - } - - if ((src[4] & 1) != 0) { - gfx_data += 32896; - } - - switch(src[2]) { - case 0: - memcpy(_curBuf, gfx_data, _frameSize); - break; - case 1: - error("codec47: not implemented decode1 proc"); - break; - case 2: - if (seq_nb == _prevSeqNb + 1) { - decode2(_curBuf, gfx_data, _width, _height, src + 8); - } - break; - case 3: - memcpy(_curBuf, _deltaBufs[1], _frameSize); - break; - case 4: - memcpy(_curBuf, _deltaBufs[0], _frameSize); - break; - case 5: - bompDecodeLine(_curBuf, gfx_data, READ_LE_UINT32(src + 14)); - break; - } - - memcpy(dst, _curBuf, _frameSize); - - if (seq_nb == _prevSeqNb + 1) { - if (src[3] == 1) { - tmp_ptr = _curBuf; - _curBuf = _deltaBufs[1]; - _deltaBufs[1] = tmp_ptr; - } else if (src[3] == 2) { - tmp_ptr = _deltaBufs[0]; - _deltaBufs[0] = _deltaBufs[1]; - _deltaBufs[1] = _curBuf; - _curBuf = tmp_ptr; - } - } - _prevSeqNb = seq_nb; - - return true; -} - -} // End of namespace Scumm - -#ifdef PALMOS_68K -#include "scumm_globals.h" - -_GINIT(Codec47) -_GSETPTR(Scumm::codec47_table, GBVARS_CODEC47TABLE_INDEX, int8, GBVARS_SCUMM) -_GEND - -_GRELEASE(Codec47) -_GRELEASEPTR(GBVARS_CODEC47TABLE_INDEX, GBVARS_SCUMM) -_GEND - -#endif diff --git a/scumm/smush/codec47.h b/scumm/smush/codec47.h deleted file mode 100644 index ea71c22963..0000000000 --- a/scumm/smush/codec47.h +++ /dev/null @@ -1,65 +0,0 @@ -/* ScummVM - Scumm Interpreter - * Copyright (C) 2002-2006 The ScummVM project - * - * 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$ - * - */ - -#ifndef SMUSH_CODEC_47_H -#define SMUSH_CODEC_47_H - -#include "common/scummsys.h" - -namespace Scumm { - -class Codec47Decoder { -private: - - int32 _deltaSize; - byte *_deltaBufs[2]; - byte *_deltaBuf; - byte *_curBuf; - int32 _prevSeqNb; - int _lastTableWidth; - const byte *_d_src, *_paramPtr; - int _d_pitch; - int32 _offset1, _offset2; - byte *_tableBig; - byte *_tableSmall; - int16 _table[256]; - int32 _frameSize; - int _width, _height; - - void makeTablesInterpolation(int param); - void makeTables47(int width); - void level1(byte *d_dst); - void level2(byte *d_dst); - void level3(byte *d_dst); - void decode2(byte *dst, const byte *src, int width, int height, const byte *param_ptr); - -public: - Codec47Decoder(); - ~Codec47Decoder(); - void init(int width, int height); - void deinit(); - bool decode(byte *dst, const byte *src); -}; - -} // End of namespace Scumm - -#endif diff --git a/scumm/smush/imuse_channel.cpp b/scumm/smush/imuse_channel.cpp deleted file mode 100644 index 76a10a9e9e..0000000000 --- a/scumm/smush/imuse_channel.cpp +++ /dev/null @@ -1,347 +0,0 @@ -/* ScummVM - Scumm Interpreter - * Copyright (C) 2002-2006 The ScummVM project - * - * 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 "common/stdafx.h" -#include "scumm/scumm.h" -#include "scumm/smush/channel.h" -#include "scumm/smush/chunk.h" -#include "scumm/smush/chunk_type.h" - -namespace Scumm { - -ImuseChannel::ImuseChannel(int32 track, int32 freq) : - _track(track), - _tbuffer(0), - _tbufferSize(0), - _sbuffer(0), - _sbufferSize(0), - _frequency(freq), - _dataSize(-1), - _inData(false) { -} - -ImuseChannel::~ImuseChannel() { - if (_tbuffer) { - delete []_tbuffer; - } - if (_sbuffer) { - warning("_sbuffer should be 0 !!!"); - delete []_sbuffer; - } -} - -bool ImuseChannel::isTerminated() const { - return (_dataSize <= 0 && _sbuffer == 0); -} - -bool ImuseChannel::setParameters(int32 nb, int32 size, int32 flags, int32 unk1, int32) { - if ((flags == 1) || (flags == 2) || (flags == 3)) { - _volume = 127; - } else if ((flags >= 100) && (flags <= 163)) { - _volume = flags * 2 - 200; - } else if ((flags >= 200) && (flags <= 263)) { - _volume = flags * 2 - 400; - } else if ((flags >= 300) && (flags <= 363)) { - _volume = flags * 2 - 600; - } else { - error("ImuseChannel::setParameters(): bad flags: %d", flags); - } - _pan = 0; - return true; -} - -bool ImuseChannel::checkParameters(int32 index, int32 nbframes, int32 size, int32 track_flags, int32 unk1) { - return true; -} - -bool ImuseChannel::appendData(Chunk &b, int32 size) { - if (_dataSize == -1) { - assert(size > 8); - Chunk::type imus_type = b.getDword(); imus_type = SWAP_BYTES_32(imus_type); - uint32 imus_size = b.getDword(); imus_size = SWAP_BYTES_32(imus_size); - if (imus_type != TYPE_iMUS) - error("Invalid Chunk for imuse_channel"); - size -= 8; - _tbufferSize = size; - assert(_tbufferSize); - _tbuffer = new byte[_tbufferSize]; - if (!_tbuffer) - error("imuse_channel failed to allocate memory"); - b.read(_tbuffer, size); - _dataSize = -2; - } else { - if (_tbuffer) { - byte *old = _tbuffer; - int32 new_size = size + _tbufferSize; - _tbuffer = new byte[new_size]; - if (!_tbuffer) - error("imuse_channel failed to allocate memory"); - memcpy(_tbuffer, old, _tbufferSize); - delete []old; - b.read(_tbuffer + _tbufferSize, size); - _tbufferSize += size; - } else { - _tbufferSize = size; - _tbuffer = new byte[_tbufferSize]; - if (!_tbuffer) - error("imuse_channel failed to allocate memory"); - b.read(_tbuffer, size); - } - } - return processBuffer(); -} - -bool ImuseChannel::handleFormat(Chunk &src) { - if (src.getSize() != 20) error("invalid size for FRMT Chunk"); - uint32 imuse_start = src.getDword(); - imuse_start = SWAP_BYTES_32(imuse_start); - src.seek(4); - _bitsize = src.getDword(); - _bitsize = SWAP_BYTES_32(_bitsize); - _rate = src.getDword(); - _rate = SWAP_BYTES_32(_rate); - _channels = src.getDword(); - _channels = SWAP_BYTES_32(_channels); - assert(_channels == 1 || _channels == 2); - return true; -} - -bool ImuseChannel::handleRegion(Chunk &src) { - if (src.getSize() != 8) - error("invalid size for REGN Chunk"); - return true; -} - -bool ImuseChannel::handleStop(Chunk &src) { - if (src.getSize() != 4) - error("invalid size for STOP Chunk"); - return true; -} - -bool ImuseChannel::handleMap(Chunk &map) { - while (!map.eof()) { - Chunk *sub = map.subBlock(); - switch(sub->getType()) { - case TYPE_FRMT: - handleFormat(*sub); - break; - case TYPE_TEXT: - break; - case TYPE_REGN: - handleRegion(*sub); - break; - case TYPE_STOP: - handleStop(*sub); - break; - default: - error("Unknown iMUS subChunk found : %s, %d", Chunk::ChunkString(sub->getType()), sub->getSize()); - } - delete sub; - } - return true; -} - -void ImuseChannel::decode() { - int remaining_size = _sbufferSize % 3; - if (remaining_size) { - _srbufferSize -= remaining_size; - assert(_inData); - if (_tbuffer == 0) { - _tbuffer = new byte[remaining_size]; - memcpy(_tbuffer, _sbuffer + _sbufferSize - remaining_size, remaining_size); - _tbufferSize = remaining_size; - _sbufferSize -= remaining_size; - } else { - debugC(DEBUG_SMUSH, "impossible ! : %p, %d, %d, %p(%d), %p(%d, %d)", - this, _dataSize, _inData, _tbuffer, _tbufferSize, _sbuffer, _sbufferSize, _srbufferSize); - byte *old = _tbuffer; - int new_size = remaining_size + _tbufferSize; - _tbuffer = new byte[new_size]; - if (!_tbuffer) error("imuse_channel failed to allocate memory"); - memcpy(_tbuffer, old, _tbufferSize); - delete []old; - memcpy(_tbuffer + _tbufferSize, _sbuffer + _sbufferSize - remaining_size, remaining_size); - _tbufferSize += remaining_size; - } - } - - // FIXME: Code duplication! See decode12BitsSample() in scumm/imuse_digi.cpp - - int loop_size = _sbufferSize / 3; - int new_size = loop_size * 4; - byte *keep, *decoded; - uint32 value; - keep = decoded = new byte[new_size]; - assert(keep); - unsigned char * source = _sbuffer; - - while (loop_size--) { - byte v1 = *source++; - byte v2 = *source++; - byte v3 = *source++; - value = ((((v2 & 0x0f) << 8) | v1) << 4) - 0x8000; - WRITE_BE_UINT16(decoded, value); decoded += 2; - value = ((((v2 & 0xf0) << 4) | v3) << 4) - 0x8000; - WRITE_BE_UINT16(decoded, value); decoded += 2; - } - delete []_sbuffer; - _sbuffer = (byte *)keep; - _sbufferSize = new_size; -} - -bool ImuseChannel::handleSubTags(int32 &offset) { - if (_tbufferSize - offset >= 8) { - Chunk::type type = READ_BE_UINT32(_tbuffer + offset); - uint32 size = READ_BE_UINT32(_tbuffer + offset + 4); - uint32 available_size = _tbufferSize - offset; - switch(type) { - case TYPE_MAP_: - _inData = false; - if (available_size >= (size + 8)) { - MemoryChunk c((byte *)_tbuffer + offset); - handleMap(c); - } - break; - case TYPE_DATA: - _inData = true; - _dataSize = size; - offset += 8; - { - int reqsize = 1; - if (_channels == 2) - reqsize *= 2; - if (_bitsize == 16) - reqsize *= 2; - else if (_bitsize == 12) { - if (reqsize > 1) - reqsize = reqsize * 3 / 2; - else reqsize = 3; - } - if ((size % reqsize) != 0) { - debugC(DEBUG_SMUSH, "Invalid iMUS sound data size : (%d %% %d) != 0, correcting...", size, reqsize); - size += 3 - (size % reqsize); - } - } - return false; - default: - error("unknown Chunk in iMUS track : %s ", Chunk::ChunkString(type)); - } - offset += size + 8; - return true; - } - return false; -} - -bool ImuseChannel::processBuffer() { - assert(_tbuffer != 0); - assert(_tbufferSize != 0); - assert(_sbuffer == 0); - assert(_sbufferSize == 0); - - if (_inData) { - if (_dataSize < _tbufferSize) { - int32 offset= _dataSize; - while (handleSubTags(offset)); - _sbufferSize = _dataSize; - _sbuffer = _tbuffer; - if (offset < _tbufferSize) { - int32 new_size = _tbufferSize - offset; - _tbuffer = new byte[new_size]; - if (!_tbuffer) error("imuse_channel failed to allocate memory"); - memcpy(_tbuffer, _sbuffer + offset, new_size); - _tbufferSize = new_size; - } else { - _tbuffer = 0; - _tbufferSize = 0; - } - if (_sbufferSize == 0) { - delete []_sbuffer; - _sbuffer = 0; - } - } else { - _sbufferSize = _tbufferSize; - _sbuffer = _tbuffer; - _tbufferSize = 0; - _tbuffer = 0; - } - } else { - int32 offset = 0; - while (handleSubTags(offset)); - if (_inData) { - _sbufferSize = _tbufferSize - offset; - assert(_sbufferSize); - _sbuffer = new byte[_sbufferSize]; - if (!_sbuffer) error("imuse_channel failed to allocate memory"); - memcpy(_sbuffer, _tbuffer + offset, _sbufferSize); - delete []_tbuffer; - _tbuffer = 0; - _tbufferSize = 0; - } else { - if (offset) { - byte * old = _tbuffer; - int32 new_size = _tbufferSize - offset; - _tbuffer = new byte[new_size]; - if (!_tbuffer) error("imuse_channel failed to allocate memory"); - memcpy(_tbuffer, old + offset, new_size); - _tbufferSize = new_size; - delete []old; - } - } - } - _srbufferSize = _sbufferSize; - if (_sbuffer && _bitsize == 12) decode(); - return true; -} - -int32 ImuseChannel::availableSoundData(void) const { - int32 ret = _sbufferSize; - if (_channels == 2) ret /= 2; - if (_bitsize > 8) ret /= 2; - return ret; -} - -void ImuseChannel::getSoundData(int16 *snd, int32 size) { - if (_dataSize <= 0 || _bitsize <= 8) error("invalid call to imuse_channel::read_sound_data()"); - if (_channels == 2) size *= 2; - - memcpy(snd, _sbuffer, size * 2); - - delete []_sbuffer; - assert(_sbufferSize == 2 * size); - _sbuffer = 0; - _sbufferSize = 0; - _dataSize -= _srbufferSize; -} - -void ImuseChannel::getSoundData(int8 *snd, int32 size) { - if (_dataSize <= 0 || _bitsize > 8) error("invalid call to imuse_channel::read_sound_data()"); - if (_channels == 2) size *= 2; - - memcpy(snd, _sbuffer, size); - - delete []_sbuffer; - _sbuffer = 0; - _sbufferSize = 0; - _dataSize -= _srbufferSize; -} - -} // End of namespace Scumm diff --git a/scumm/smush/saud_channel.cpp b/scumm/smush/saud_channel.cpp deleted file mode 100644 index 2277336570..0000000000 --- a/scumm/smush/saud_channel.cpp +++ /dev/null @@ -1,268 +0,0 @@ -/* ScummVM - Scumm Interpreter - * Copyright (C) 2002-2006 The ScummVM project - * - * 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 "common/stdafx.h" - -#include "scumm/smush/channel.h" -#include "scumm/smush/chunk.h" -#include "scumm/smush/chunk_type.h" - -namespace Scumm { - -void SaudChannel::handleStrk(Chunk &b) { - int32 size = b.getSize(); - if (size != 14 && size != 10) { - error("STRK has an invalid size : %d", size); - } -} - -void SaudChannel::handleSmrk(Chunk &b) { - _markReached = true; -} - -void SaudChannel::handleShdr(Chunk &b) { - int32 size = b.getSize(); - if (size != 4) - error("SHDR has an invalid size : %d", size); -} - -bool SaudChannel::handleSubTags(int32 &offset) { - if (_tbufferSize - offset >= 8) { - Chunk::type type = READ_BE_UINT32(_tbuffer + offset); - uint32 size = READ_BE_UINT32(_tbuffer + offset + 4); - uint32 available_size = _tbufferSize - offset; - - switch(type) { - case TYPE_STRK: - _inData = false; - if (available_size >= (size + 8)) { - MemoryChunk c((byte *)_tbuffer + offset); - handleStrk(c); - } else - return false; - break; - case TYPE_SMRK: - _inData = false; - if (available_size >= (size + 8)) { - MemoryChunk c((byte *)_tbuffer + offset); - handleSmrk(c); - } else - return false; - break; - case TYPE_SHDR: - _inData = false; - if (available_size >= (size + 8)) { - MemoryChunk c((byte *)_tbuffer + offset); - handleShdr(c); - } else - return false; - break; - case TYPE_SDAT: - _inData = true; - _dataSize = size; - offset += 8; - return false; - default: - error("unknown Chunk in SAUD track : %s ", Chunk::ChunkString(type)); - } - offset += size + 8; - return true; - } - return false; -} - -bool SaudChannel::processBuffer() { - assert(_tbuffer != 0); - assert(_tbufferSize != 0); - assert(_sbuffer == 0); - assert(_sbufferSize == 0); - - if (_keepSize) { - _sbufferSize = _tbufferSize; - _sbuffer = _tbuffer; - _tbufferSize = 0; - _tbuffer = 0; - } else if (_inData) { - if (_dataSize < _tbufferSize) { - int32 offset = _dataSize; - while (handleSubTags(offset)) ; - _sbufferSize = _dataSize; - _sbuffer = _tbuffer; - if (offset < _tbufferSize) { - int new_size = _tbufferSize - offset; - _tbuffer = new byte[new_size]; - if (!_tbuffer) - error("SaudChannel failed to allocate memory"); - memcpy(_tbuffer, _sbuffer + offset, new_size); - _tbufferSize = new_size; - } else { - _tbuffer = 0; - _tbufferSize = 0; - } - if (_sbufferSize == 0) { - delete []_sbuffer; - _sbuffer = 0; - } - } else { - _sbufferSize = _tbufferSize; - _sbuffer = _tbuffer; - _tbufferSize = 0; - _tbuffer = 0; - } - } else { - int32 offset = 0; - while (handleSubTags(offset)); - if (_inData) { - _sbufferSize = _tbufferSize - offset; - assert(_sbufferSize); - _sbuffer = new byte[_sbufferSize]; - if (!_sbuffer) - error("saud_channel failed to allocate memory"); - memcpy(_sbuffer, _tbuffer + offset, _sbufferSize); - delete []_tbuffer; - _tbuffer = 0; - _tbufferSize = 0; - } else { - if (offset) { - byte *old = _tbuffer; - int32 new_size = _tbufferSize - offset; - _tbuffer = new byte[new_size]; - if (!_tbuffer) - error("SaudChannel failed to allocate memory"); - memcpy(_tbuffer, old + offset, new_size); - _tbufferSize = new_size; - delete []old; - } - } - } - return true; -} - -SaudChannel::SaudChannel(int32 track, int32 freq) : - _track(track), - _nbframes(0), - _dataSize(-1), - _frequency(freq), - _inData(false), - _markReached(false), - _index(0), - _tbuffer(0), - _tbufferSize(0), - _sbuffer(0), - _sbufferSize(0), - _keepSize(false) { -} - -SaudChannel::~SaudChannel() { - _dataSize = 0; - _tbufferSize = 0; - _sbufferSize = 0; - _markReached = true; - if (_tbuffer) - delete []_tbuffer; - if (_sbuffer) { - // _sbuffer can be not empty here with insane when it seeks in video - delete []_sbuffer; - } - _sbuffer = 0; -} - -bool SaudChannel::isTerminated() const { - return (_markReached && _dataSize == 0 && _sbuffer == 0); -} - -bool SaudChannel::setParameters(int32 nb, int32 flags, int32 volume, int32 pan, int32 index) { - _nbframes = nb; - _flags = flags; // bit 7 == IS_VOICE, bit 6 == IS_BACKGROUND_MUSIC, other ?? - _volume = volume; - _pan = pan; - _index = index; - if (index != 0) { - _dataSize = -2; - _keepSize = true; - _inData = true; - } - return true; -} - -bool SaudChannel::checkParameters(int32 index, int32 nb, int32 flags, int32 volume, int32 pan) { - if (++_index != index) - error("invalid index in SaudChannel::checkParameters()"); - if (_nbframes != nb) - error("invalid duration in SaudChannel::checkParameters()"); - if (_flags != flags) - error("invalid flags in SaudChannel::checkParameters()"); - if (_volume != volume || _pan != pan) { - _volume = volume; - _pan = pan; - } - return true; -} - -bool SaudChannel::appendData(Chunk &b, int32 size) { - if (_dataSize == -1) { - assert(size > 8); - Chunk::type saud_type = b.getDword(); - saud_type = SWAP_BYTES_32(saud_type); - uint32 saud_size = b.getDword(); - saud_size = SWAP_BYTES_32(saud_size); - if (saud_type != TYPE_SAUD) - error("Invalid Chunk for SaudChannel : %X", saud_type); - size -= 8; - _dataSize = -2; - } - if (_tbuffer) { - byte *old = _tbuffer; - _tbuffer = new byte[_tbufferSize + size]; - if (!_tbuffer) - error("saud_channel failed to allocate memory"); - memcpy(_tbuffer, old, _tbufferSize); - delete []old; - b.read(_tbuffer + _tbufferSize, size); - _tbufferSize += size; - } else { - _tbufferSize = size; - _tbuffer = new byte[_tbufferSize]; - if (!_tbuffer) - error("saud_channel failed to allocate memory"); - b.read(_tbuffer, _tbufferSize); - } - return processBuffer(); -} - -int32 SaudChannel::availableSoundData(void) const { - return _sbufferSize; -} - -void SaudChannel::getSoundData(int16 *snd, int32 size) { - for (int32 i = 0; i < size; i++) { - snd[2 * i] = TO_LE_16(_sbuffer[i] ^ 0x80); - snd[2 * i + 1] = TO_LE_16(_sbuffer[i] ^ 0x80); - } - if (!_keepSize) - _dataSize -= size; - delete []_sbuffer; - _sbuffer = 0; - _sbufferSize = 0; -} - -} // End of namespace Scumm diff --git a/scumm/smush/smush_font.cpp b/scumm/smush/smush_font.cpp deleted file mode 100644 index 96d9e2f7c5..0000000000 --- a/scumm/smush/smush_font.cpp +++ /dev/null @@ -1,269 +0,0 @@ -/* ScummVM - Scumm Interpreter - * Copyright (C) 2002-2006 The ScummVM project - * - * 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 "common/stdafx.h" -#include "common/file.h" -#include "scumm/scumm.h" -#include "scumm/util.h" - -#include "scumm/smush/smush_font.h" - -namespace Scumm { - -SmushFont::SmushFont(ScummEngine *vm, bool use_original_colors, bool new_colors) : - NutRenderer(vm), - _color(-1), - _new_colors(new_colors), - _original(use_original_colors) { -} - -int SmushFont::getStringWidth(const char *str) { - assert(str); - if (!_loaded) { - error("SmushFont::getStringWidth() Font is not loaded"); - return 0; - } - - int width = 0; - while (*str) { - if (*str & 0x80 && _vm->_useCJKMode) { - width += _vm->_2byteWidth + 1; - str += 2; - } else - width += getCharWidth(*str++); - } - return width; -} - -int SmushFont::getStringHeight(const char *str) { - assert(str); - if (!_loaded) { - error("SmushFont::getStringHeight() Font is not loaded"); - return 0; - } - - int height = 0; - while (*str) { - int charHeight = getCharHeight(*str++); - if (height < charHeight) - height = charHeight; - } - return height; -} - -int SmushFont::drawChar(byte *buffer, int dst_width, int x, int y, byte chr) { - int w = _chars[chr].width; - int h = _chars[chr].height; - const byte *src = _chars[chr].src; - byte *dst = buffer + dst_width * y + x; - - assert(dst_width == _vm->_screenWidth); - - if (_original) { - for (int j = 0; j < h; j++) { - for (int i = 0; i < w; i++) { - int8 value = *src++; - if (value) - dst[i] = value; - } - dst += dst_width; - } - } else { - char color = (_color != -1) ? _color : 1; - if (_new_colors) { - for (int j = 0; j < h; j++) { - for (int i = 0; i < w; i++) { - int8 value = *src++; - if (value == -color) { - dst[i] = 0xFF; - } else if (value == -31) { - dst[i] = 0; - } else if (value) { - dst[i] = value; - } - } - dst += dst_width; - } - } else { - for (int j = 0; j < h; j++) { - for (int i = 0; i < w; i++) { - int8 value = *src++; - if (value == 1) { - dst[i] = color; - } else if (value) { - dst[i] = 0; - } - } - dst += dst_width; - } - } - } - return w; -} - -int SmushFont::draw2byte(byte *buffer, int dst_width, int x, int y, int idx) { - int w = _vm->_2byteWidth; - int h = _vm->_2byteHeight; - - byte *src = _vm->get2byteCharPtr(idx); - byte *dst = buffer + dst_width * (y + (_vm->_gameId == GID_CMI ? 7 : (_vm->_gameId == GID_DIG ? 2 : 0))) + x; - byte bits = 0; - - char color = (_color != -1) ? _color : 1; - - if (_new_colors) - color = (char)0xff; - - if (_vm->_gameId == GID_FT) - color = 1; - - for (int j = 0; j < h; j++) { - for (int i = 0; i < w; i++) { - if ((i % 8) == 0) - bits = *src++; - if (bits & revBitMask(i % 8)) { - dst[i + 1] = 0; - dst[dst_width + i] = 0; - dst[dst_width + i + 1] = 0; - dst[i] = color; - } - } - dst += dst_width; - } - return w + 1; -} - -void SmushFont::drawSubstring(const char *str, byte *buffer, int dst_width, int x, int y) { - // This happens in the Full Throttle intro. I don't know if our - // text-drawing functions are buggy, or if this function is supposed - // to have to check for it. - if (x < 0) - x = 0; - - for (int i = 0; str[i] != 0; i++) { - if ((byte)str[i] >= 0x80 && _vm->_useCJKMode) { - x += draw2byte(buffer, dst_width, x, y, (byte)str[i] + 256 * (byte)str[i+1]); - i++; - } else - x += drawChar(buffer, dst_width, x, y, str[i]); - } -} - -#define MAX_WORDS 60 - - -void SmushFont::drawString(const char *str, byte *buffer, int dst_width, int dst_height, int x, int y, bool center) { - debugC(DEBUG_SMUSH, "SmushFont::drawString(%s, %d, %d, %d)", str, x, y, center); - - while (str) { - char line[256]; - char *pos = (char *)strchr(str, '\n'); - if (pos) { - memcpy(line, str, pos - str - 1); - line[pos - str - 1] = 0; - str = pos + 1; - } else { - strcpy(line, str); - str = 0; - } - drawSubstring(line, buffer, dst_width, center ? (x - getStringWidth(line) / 2) : x, y); - y += getStringHeight(line); - } -} - -void SmushFont::drawStringWrap(const char *str, byte *buffer, int dst_width, int dst_height, int x, int y, int left, int right, bool center) { - debugC(DEBUG_SMUSH, "SmushFont::drawStringWrap(%s, %d, %d, %d, %d, %d)", str, x, y, left, right, center); - - const int width = right - left; - char *s = strdup(str); - char *words[MAX_WORDS]; - int word_count = 0; - - char *tmp = s; - while (tmp) { - assert(word_count < MAX_WORDS); - words[word_count++] = tmp; - tmp = strpbrk(tmp, " \t\r\n"); - if (tmp == 0) - break; - *tmp++ = 0; - } - - int i = 0, max_width = 0, height = 0, line_count = 0; - - char *substrings[MAX_WORDS]; - int substr_widths[MAX_WORDS]; - const int space_width = getCharWidth(' '); - - i = 0; - while (i < word_count) { - char *substr = words[i++]; - int substr_width = getStringWidth(substr); - - while (i < word_count) { - int word_width = getStringWidth(words[i]); - if ((substr_width + space_width + word_width) >= width) - break; - substr_width += word_width + space_width; - *(words[i]-1) = ' '; // Convert 0 byte back to space - i++; - } - - substrings[line_count] = substr; - substr_widths[line_count++] = substr_width; - if (max_width < substr_width) - max_width = substr_width; - height += getStringHeight(substr); - } - - if (y > dst_height - height) { - y = dst_height - height; - } - - if (center) { - max_width = (max_width + 1) / 2; - x = left + width / 2; - - if (x < left + max_width) - x = left + max_width; - if (x > right - max_width) - x = right - max_width; - - for (i = 0; i < line_count; i++) { - drawSubstring(substrings[i], buffer, dst_width, x - substr_widths[i] / 2, y); - y += getStringHeight(substrings[i]); - } - } else { - if (x > dst_width - max_width) - x = dst_width - max_width; - - for (i = 0; i < line_count; i++) { - drawSubstring(substrings[i], buffer, dst_width, x, y); - y += getStringHeight(substrings[i]); - } - } - - free(s); -} - -} // End of namespace Scumm - diff --git a/scumm/smush/smush_font.h b/scumm/smush/smush_font.h deleted file mode 100644 index 724eb46658..0000000000 --- a/scumm/smush/smush_font.h +++ /dev/null @@ -1,54 +0,0 @@ -/* ScummVM - Scumm Interpreter - * Copyright (C) 2002-2006 The ScummVM project - * - * 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$ - * - */ - -#ifndef SMUSH_FONT_H -#define SMUSH_FONT_H - -#include "common/scummsys.h" -#include "scumm/nut_renderer.h" - -namespace Scumm { - -class SmushFont : public NutRenderer { -protected: - int16 _color; - bool _new_colors; - bool _original; - - - int getStringWidth(const char *str); - int getStringHeight(const char *str); - int draw2byte(byte *buffer, int dst_width, int x, int y, int idx); - int drawChar(byte *buffer, int dst_width, int x, int y, byte chr); - void drawSubstring(const char *str, byte *buffer, int dst_width, int x, int y); - -public: - SmushFont(ScummEngine *vm, bool use_original_colors, bool new_colors); - - void setColor(byte c) { _color = c; } - void drawString (const char *str, byte *buffer, int dst_width, int dst_height, int x, int y, bool center); - void drawStringWrap(const char *str, byte *buffer, int dst_width, int dst_height, int x, int y, int left, int right, bool center); -}; - -} // End of namespace Scumm - -#endif diff --git a/scumm/smush/smush_mixer.cpp b/scumm/smush/smush_mixer.cpp deleted file mode 100644 index 00a50321da..0000000000 --- a/scumm/smush/smush_mixer.cpp +++ /dev/null @@ -1,163 +0,0 @@ -/* ScummVM - Scumm Interpreter - * Copyright (C) 2002-2006 The ScummVM project - * - * 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 "common/stdafx.h" -#include "common/util.h" - -#include "scumm/smush/smush_mixer.h" -#include "scumm/smush/channel.h" -#include "scumm/scumm.h" -#include "scumm/sound.h" -#include "scumm/imuse.h" - -#include "sound/mixer.h" - - -namespace Scumm { - -SmushMixer::SmushMixer(Audio::Mixer *m) : - _mixer(m), - _soundFrequency(22050) { - for (int32 i = 0; i < NUM_CHANNELS; i++) { - _channels[i].id = -1; - _channels[i].chan = NULL; - _channels[i].stream = NULL; - } -} - -SmushMixer::~SmushMixer() { - Common::StackLock lock(_mutex); - for (int32 i = 0; i < NUM_CHANNELS; i++) { - _mixer->stopHandle(_channels[i].handle); - } -} - -SmushChannel *SmushMixer::findChannel(int32 track) { - Common::StackLock lock(_mutex); - debugC(DEBUG_SMUSH, "SmushMixer::findChannel(%d)", track); - for (int32 i = 0; i < NUM_CHANNELS; i++) { - if (_channels[i].id == track) - return _channels[i].chan; - } - return NULL; -} - -void SmushMixer::addChannel(SmushChannel *c) { - Common::StackLock lock(_mutex); - int32 track = c->getTrackIdentifier(); - int i; - - debugC(DEBUG_SMUSH, "SmushMixer::addChannel(%d)", track); - - for (i = 0; i < NUM_CHANNELS; i++) { - if (_channels[i].id == track) - debugC(DEBUG_SMUSH, "SmushMixer::addChannel(%d): channel already exists", track); - } - - for (i = 0; i < NUM_CHANNELS; i++) { - if ((_channels[i].chan == NULL || _channels[i].id == -1) && !_mixer->isSoundHandleActive(_channels[i].handle)) { - _channels[i].chan = c; - _channels[i].id = track; - return; - } - } - - for (i = 0; i < NUM_CHANNELS; i++) { - debugC(DEBUG_SMUSH, "channel %d : %p(%d, %d)", i, (void *)_channels[i].chan, - _channels[i].chan ? _channels[i].chan->getTrackIdentifier() : -1, - _channels[i].chan ? _channels[i].chan->isTerminated() : 1); - } - - error("SmushMixer::addChannel(%d): no channel available", track); -} - -bool SmushMixer::handleFrame() { - Common::StackLock lock(_mutex); - debugC(DEBUG_SMUSH, "SmushMixer::handleFrame()"); - for (int i = 0; i < NUM_CHANNELS; i++) { - if (_channels[i].id != -1) { - if (_channels[i].chan->isTerminated()) { - delete _channels[i].chan; - _channels[i].id = -1; - _channels[i].chan = NULL; - if (_channels[i].stream) { - _channels[i].stream->finish(); - _channels[i].stream = 0; - } - } else { - int32 rate, vol, pan; - bool stereo, is_16bit; - void *data; - - _channels[i].chan->getParameters(rate, stereo, is_16bit, vol, pan); - int32 size = _channels[i].chan->availableSoundData(); - byte flags = stereo ? Audio::Mixer::FLAG_STEREO : 0; - - if (is_16bit) { - data = malloc(size * (stereo ? 2 : 1) * 4); - _channels[i].chan->getSoundData((int16 *)data, size); - size *= stereo ? 4 : 2; - - flags |= Audio::Mixer::FLAG_16BITS; - - } else { - data = malloc(size * (stereo ? 2 : 1) * 2); - _channels[i].chan->getSoundData((int8 *)data, size); - size *= stereo ? 2 : 1; - - flags |= Audio::Mixer::FLAG_UNSIGNED; - } - - if (_mixer->isReady()) { - if (!_channels[i].stream) { - _channels[i].stream = makeAppendableAudioStream(rate, flags, 500000); - _mixer->playInputStream(Audio::Mixer::kSFXSoundType, &_channels[i].handle, _channels[i].stream); - } - _mixer->setChannelVolume(_channels[i].handle, vol); - _mixer->setChannelBalance(_channels[i].handle, pan); - _channels[i].stream->append((byte *)data, size); - } - free(data); - } - } - } - return true; -} - -bool SmushMixer::stop() { - Common::StackLock lock(_mutex); - debugC(DEBUG_SMUSH, "SmushMixer::stop()"); - for (int i = 0; i < NUM_CHANNELS; i++) { - if (_channels[i].id != -1) { - delete _channels[i].chan; - _channels[i].id = -1; - _channels[i].chan = NULL; - if (_channels[i].stream) { - _channels[i].stream->finish(); - _channels[i].stream = 0; - } - } - } - return true; -} - -} // End of namespace Scumm diff --git a/scumm/smush/smush_mixer.h b/scumm/smush/smush_mixer.h deleted file mode 100644 index 2a7c2d3ebc..0000000000 --- a/scumm/smush/smush_mixer.h +++ /dev/null @@ -1,64 +0,0 @@ -/* ScummVM - Scumm Interpreter - * Copyright (C) 2002-2006 The ScummVM project - * - * 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$ - * - */ - -#ifndef SMUSH_MIXER_H -#define SMUSH_MIXER_H - -#include "common/stdafx.h" -#include "scumm/sound.h" - -namespace Scumm { - -class SmushChannel; - -class SmushMixer { - enum { - NUM_CHANNELS = 16 - }; -private: - - Audio::Mixer *_mixer; - struct channels { - int id; - SmushChannel *chan; - Audio::SoundHandle handle; - AppendableAudioStream *stream; - } _channels[NUM_CHANNELS]; - - int _soundFrequency; - - Common::Mutex _mutex; - -public: - - SmushMixer(Audio::Mixer *); - virtual ~SmushMixer(); - SmushChannel *findChannel(int32 track); - void addChannel(SmushChannel *c); - bool handleFrame(); - bool stop(); - bool update(); -}; - -} // End of namespace Scumm - -#endif diff --git a/scumm/smush/smush_player.cpp b/scumm/smush/smush_player.cpp deleted file mode 100644 index 926e7f9f87..0000000000 --- a/scumm/smush/smush_player.cpp +++ /dev/null @@ -1,1359 +0,0 @@ -/* ScummVM - Scumm Interpreter - * Copyright (C) 2002-2006 The ScummVM project - * - * 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 "common/stdafx.h" - -#include "base/engine.h" - -#include "common/config-manager.h" -#include "common/file.h" -#include "common/system.h" -#include "common/timer.h" -#include "common/util.h" - -#include "scumm/bomp.h" -#include "scumm/imuse_digi/dimuse.h" -#include "scumm/imuse.h" -#include "scumm/scumm.h" -#include "scumm/sound.h" -#include "scumm/smush/channel.h" -#include "scumm/smush/chunk_type.h" -#include "scumm/smush/chunk.h" -#include "scumm/smush/smush_font.h" -#include "scumm/smush/smush_mixer.h" -#include "scumm/smush/smush_player.h" - -#include "scumm/insane/insane.h" - -#include "sound/mixer.h" -#include "sound/vorbis.h" -#include "sound/mp3.h" - -#ifdef DUMP_SMUSH_FRAMES -#include <png.h> -#endif - -#ifdef USE_ZLIB -#include <zlib.h> -#endif - -namespace Scumm { - -const int MAX_STRINGS = 200; - -class StringResource { -private: - - struct { - int id; - char *string; - } _strings[MAX_STRINGS]; - - int _nbStrings; - int _lastId; - const char *_lastString; - -public: - - StringResource() : - _nbStrings(0), - _lastId(-1) { - }; - ~StringResource() { - for (int32 i = 0; i < _nbStrings; i++) { - delete []_strings[i].string; - } - } - - bool init(char *buffer, int32 length) { - char *def_start = strchr(buffer, '#'); - while (def_start != NULL) { - char *def_end = strchr(def_start, '\n'); - assert(def_end != NULL); - - char *id_end = def_end; - while (id_end >= def_start && !isdigit(*(id_end-1))) { - id_end--; - } - - assert(id_end > def_start); - char *id_start = id_end; - while (isdigit(*(id_start - 1))) { - id_start--; - } - - char idstring[32]; - memcpy(idstring, id_start, id_end - id_start); - idstring[id_end - id_start] = 0; - int32 id = atoi(idstring); - char *data_start = def_end; - - while (*data_start == '\n' || *data_start == '\r') { - data_start++; - } - char *data_end = data_start; - - while (1) { - if (data_end[-2] == '\r' && data_end[-1] == '\n' && data_end[0] == '\r' && data_end[1] == '\n') { - break; - } - // In Russian Full Throttle strings are finished with - // just one pair of CR-LF - if (data_end[-2] == '\r' && data_end[-1] == '\n' && data_end[0] == '#') { - break; - } - data_end++; - if (data_end >= buffer + length) { - data_end = buffer + length; - break; - } - } - - data_end -= 2; - assert(data_end > data_start); - char *value = new char[data_end - data_start + 1]; - assert(value); - memcpy(value, data_start, data_end - data_start); - value[data_end - data_start] = 0; - char *line_start = value; - char *line_end; - - while ((line_end = strchr(line_start, '\n'))) { - line_start = line_end+1; - if (line_start[0] == '/' && line_start[1] == '/') { - line_start += 2; - if (line_end[-1] == '\r') - line_end[-1] = ' '; - else - *line_end++ = ' '; - memmove(line_end, line_start, strlen(line_start)+1); - } - } - _strings[_nbStrings].id = id; - _strings[_nbStrings].string = value; - _nbStrings ++; - def_start = strchr(data_end + 2, '#'); - } - return true; - } - - const char *get(int id) { - if (id == _lastId) { - return _lastString; - } - debugC(DEBUG_SMUSH, "StringResource::get(%d)", id); - for (int i = 0; i < _nbStrings; i++) { - if (_strings[i].id == id) { - _lastId = id; - _lastString = _strings[i].string; - return _strings[i].string; - } - } - warning("invalid string id : %d", id); - _lastId = -1; - _lastString = "unknown string"; - return _lastString; - } -}; - -static StringResource *getStrings(ScummEngine *vm, const char *file, bool is_encoded) { - debugC(DEBUG_SMUSH, "trying to read text ressources from %s", file); - ScummFile theFile; - - vm->openFile(theFile, file); - if (!theFile.isOpen()) { - return 0; - } - int32 length = theFile.size(); - char *filebuffer = new char [length + 1]; - assert(filebuffer); - theFile.read(filebuffer, length); - filebuffer[length] = 0; - - if (is_encoded) { - enum { - ETRS_HEADER_LENGTH = 16 - }; - assert(length > ETRS_HEADER_LENGTH); - Chunk::type type = READ_BE_UINT32(filebuffer); - - if (type != TYPE_ETRS) { - delete [] filebuffer; - return getStrings(vm, file, false); - } - - char *old = filebuffer; - filebuffer = new char[length - ETRS_HEADER_LENGTH + 1]; - for (int32 i = ETRS_HEADER_LENGTH; i < length; i++) { - filebuffer[i - ETRS_HEADER_LENGTH] = old[i] ^ 0xCC; - } - filebuffer[length - ETRS_HEADER_LENGTH] = '\0'; - delete []old; - length -= ETRS_HEADER_LENGTH; - } - StringResource *sr = new StringResource; - assert(sr); - sr->init(filebuffer, length); - delete []filebuffer; - return sr; -} - -void SmushPlayer::timerCallback(void *refCon) { - ((SmushPlayer *)refCon)->parseNextFrame(); -#ifdef _WIN32_WCE - ((SmushPlayer *)refCon)->_inTimer = true; - ((SmushPlayer *)refCon)->_inTimerCount++; -#endif -} - -SmushPlayer::SmushPlayer(ScummEngine_v6 *scumm, int speed) { - _vm = scumm; - _version = -1; - _nbframes = 0; - _smixer = 0; - _strings = NULL; - _sf[0] = NULL; - _sf[1] = NULL; - _sf[2] = NULL; - _sf[3] = NULL; - _sf[4] = NULL; - _base = NULL; - _frameBuffer = NULL; - _specialBuffer = NULL; - - _seekPos = -1; - - _skipNext = false; - _subtitles = ConfMan.getBool("subtitles"); - _dst = NULL; - _storeFrame = false; - _compressedFileMode = false; - _width = 0; - _height = 0; - _IACTpos = 0; - _soundFrequency = 22050; - _initDone = false; - _speed = speed; - _insanity = false; - _middleAudio = false; - _skipPalette = false; - _IACTstream = NULL; -#ifdef _WIN32_WCE - _inTimer = false; - _inTimerCount = 0; - _inTimerCountRedraw = ConfMan.getInt("Smush_force_redraw"); -#endif -} - -SmushPlayer::~SmushPlayer() { - release(); -} - -void SmushPlayer::init() { - _frame = 0; - _alreadyInit = false; - _vm->_smushVideoShouldFinish = false; - _vm->setDirtyColors(0, 255); - _dst = _vm->virtscr[0].getPixels(0, 0); - - // HACK HACK HACK: This is an *evil* trick, beware! - // We do this to fix bug #1037052. A proper solution would change all the - // drawing code to use the pitch value specified by the virtual screen. - // However, since a lot of the SMUSH code currently assumes the screen - // width and pitch to be equal, this will require lots of changes. So - // we resort to this hackish solution for now. - _origPitch = _vm->virtscr[0].pitch; - _origNumStrips = _vm->gdi._numStrips; - _vm->virtscr[0].pitch = _vm->virtscr[0].w; - _vm->gdi._numStrips = _vm->virtscr[0].w / 8; - - _smixer = new SmushMixer(_vm->_mixer); - Common::g_timer->installTimerProc(&timerCallback, 1000000 / _speed, this); - - _initDone = true; -} - -void SmushPlayer::release() { - if (!_initDone) - return; - - _vm->_timer->removeTimerProc(&timerCallback); - - _vm->_smushVideoShouldFinish = true; - - for (int i = 0; i < 5; i++) { - delete _sf[i]; - _sf[i] = NULL; - } - - delete _strings; - _strings = NULL; - - if (_smixer) - _smixer->stop(); - - delete _smixer; - _smixer = NULL; - - delete _base; - _base = NULL; - - free(_specialBuffer); - _specialBuffer = NULL; - - free(_frameBuffer); - _frameBuffer = NULL; - - _vm->_mixer->stopHandle(_compressedFileSoundHandle); - - _vm->_mixer->stopHandle(_IACTchannel); - _IACTstream = 0; - - _vm->_fullRedraw = true; - - // WORKAROUND bug #1035739: This is hack to workaround some ugly palette - // issues, see the mentioned bug report for details. - _vm->_doEffect = false; - - - // HACK HACK HACK: This is an *evil* trick, beware! See above for - // some explanation. - _vm->virtscr[0].pitch = _origPitch; - _vm->gdi._numStrips = _origNumStrips; - - - _initDone = false; -} - -void SmushPlayer::checkBlock(const Chunk &b, Chunk::type type_expected, uint32 min_size) { - if (type_expected != b.getType()) { - error("Chunk type is different from expected : %x != %x", b.getType(), type_expected); - } - if (min_size > b.getSize()) { - error("Chunk size is inferior than minimum required size : %d < %d", b.getSize(), min_size); - } -} - -void SmushPlayer::handleSoundBuffer(int32 track_id, int32 index, int32 max_frames, int32 flags, int32 vol, int32 pan, Chunk &b, int32 size) { - debugC(DEBUG_SMUSH, "SmushPlayer::handleSoundBuffer(%d, %d)", track_id, index); -// if ((flags & 128) == 128) { -// return; -// } -// if ((flags & 64) == 64) { -// return; -// } - SmushChannel *c = _smixer->findChannel(track_id); - if (c == NULL) { - c = new SaudChannel(track_id, _soundFrequency); - _smixer->addChannel(c); - } - - if (_middleAudio || (index == 0)) { - c->setParameters(max_frames, flags, vol, pan, index); - } else { - c->checkParameters(index, max_frames, flags, vol, pan); - } - _middleAudio = false; - c->appendData(b, size); -} - -void SmushPlayer::handleSoundFrame(Chunk &b) { - checkBlock(b, TYPE_PSAD); - debugC(DEBUG_SMUSH, "SmushPlayer::handleSoundFrame()"); - - int32 track_id = b.getWord(); - int32 index = b.getWord(); - int32 max_frames = b.getWord(); - int32 flags = b.getWord(); - int32 vol = b.getByte(); - int32 pan = b.getChar(); - if (index == 0) { - debugC(DEBUG_SMUSH, "track_id:%d, max_frames:%d, flags:%d, vol:%d, pan:%d", track_id, max_frames, flags, vol, pan); - } - int32 size = b.getSize() - 10; - handleSoundBuffer(track_id, index, max_frames, flags, vol, pan, b, size); -} - -void SmushPlayer::handleSkip(Chunk &b) { - checkBlock(b, TYPE_SKIP, 4); - int32 code = b.getDword(); - debugC(DEBUG_SMUSH, "SmushPlayer::handleSkip(%d)", code); - if (code >= 0 && code < 37) - _skipNext = _skips[code]; - else - _skipNext = true; -} - -void SmushPlayer::handleStore(Chunk &b) { - debugC(DEBUG_SMUSH, "SmushPlayer::handleStore()"); - checkBlock(b, TYPE_STOR, 4); - _storeFrame = true; -} - -void SmushPlayer::handleFetch(Chunk &b) { - debugC(DEBUG_SMUSH, "SmushPlayer::handleFetch()"); - checkBlock(b, TYPE_FTCH, 6); - - if (_frameBuffer != NULL) { - memcpy(_dst, _frameBuffer, _width * _height); - } -} - -void SmushPlayer::handleIACT(Chunk &b) { - checkBlock(b, TYPE_IACT, 8); - debugC(DEBUG_SMUSH, "SmushPlayer::handleImuseAction()"); - - /* int code = */ b.getWord(); - int flags = b.getWord(); - int unknown = b.getShort(); - int track_flags = b.getWord(); - - assert(flags == 46 && unknown == 0); - int track_id = b.getWord(); - int index = b.getWord(); - int nbframes = b.getWord(); - int32 size = b.getDword(); - int32 bsize = b.getSize() - 18; - - if (_vm->_gameId != GID_CMI) { - int32 track = track_id; - if (track_flags == 1) { - track = track_id + 100; - } else if (track_flags == 2) { - track = track_id + 200; - } else if (track_flags == 3) { - track = track_id + 300; - } else if ((track_flags >= 100) && (track_flags <= 163)) { - track = track_id + 400; - } else if ((track_flags >= 200) && (track_flags <= 263)) { - track = track_id + 500; - } else if ((track_flags >= 300) && (track_flags <= 363)) { - track = track_id + 600; - } else { - error("ImuseChannel::handleIACT(): bad track_flags: %d", track_flags); - } - debugC(DEBUG_SMUSH, "SmushPlayer::handleIACT(): %d, %d, %d", track, index, track_flags); - - SmushChannel *c = _smixer->findChannel(track); - if (c == 0) { - c = new ImuseChannel(track, _soundFrequency); - _smixer->addChannel(c); - } - if (index == 0) - c->setParameters(nbframes, size, track_flags, unknown, 0); - else - c->checkParameters(index, nbframes, size, track_flags, unknown); - c->appendData(b, bsize); - } else { - byte output_data[4096]; - byte *src = (byte *)malloc(bsize); - b.read(src, bsize); - byte *d_src = src; - byte value; - - while (bsize > 0) { - if (_IACTpos >= 2) { - int32 len = READ_BE_UINT16(_IACToutput) + 2; - len -= _IACTpos; - if (len > bsize) { - memcpy(_IACToutput + _IACTpos, d_src, bsize); - _IACTpos += bsize; - bsize = 0; - } else { - memcpy(_IACToutput + _IACTpos, d_src, len); - byte *dst = output_data; - byte *d_src2 = _IACToutput; - d_src2 += 2; - int32 count = 1024; - byte variable1 = *d_src2++; - byte variable2 = variable1 / 16; - variable1 &= 0x0f; - do { - value = *(d_src2++); - if (value == 0x80) { - *dst++ = *d_src2++; - *dst++ = *d_src2++; - } else { - int16 val = (int8)value << variable2; - *dst++ = val >> 8; - *dst++ = (byte)(val); - } - value = *(d_src2++); - if (value == 0x80) { - *dst++ = *d_src2++; - *dst++ = *d_src2++; - } else { - int16 val = (int8)value << variable1; - *dst++ = val >> 8; - *dst++ = (byte)(val); - } - } while (--count); - - if (!_IACTstream) { - _IACTstream = makeAppendableAudioStream(22050, Audio::Mixer::FLAG_STEREO | Audio::Mixer::FLAG_16BITS, 400000); - _vm->_mixer->playInputStream(Audio::Mixer::kSFXSoundType, &_IACTchannel, _IACTstream); - } - _IACTstream->append(output_data, 0x1000); - - bsize -= len; - d_src += len; - _IACTpos = 0; - } - } else { - if (bsize > 1 && _IACTpos == 0) { - *(_IACToutput + 0) = *d_src++; - _IACTpos = 1; - bsize--; - } - *(_IACToutput + _IACTpos) = *d_src++; - _IACTpos++; - bsize--; - } - } - - free(src); - } -} - -void SmushPlayer::handleTextResource(Chunk &b) { - int pos_x = b.getShort(); - int pos_y = b.getShort(); - int flags = b.getShort(); - int left = b.getShort(); - int top = b.getShort(); - int right = b.getShort(); - /*int32 height =*/ b.getShort(); - /*int32 unk2 =*/ b.getWord(); - - const char *str; - char *string = NULL, *string2 = NULL; - if (b.getType() == TYPE_TEXT) { - string = (char *)malloc(b.getSize() - 16); - str = string; - b.read(string, b.getSize() - 16); - } else { - int string_id = b.getWord(); - if (!_strings) - return; - str = _strings->get(string_id); - } - - // if subtitles disabled and bit 3 is set, then do not draw - if ((!_subtitles) && ((flags & 8) == 8)) - return; - - SmushFont *sf = _sf[0]; - int color = 15; - while (*str == '/') { - str++; // For Full Throttle text resources - } - - byte transBuf[512]; - if (_vm->_gameId == GID_CMI) { - _vm->translateText((const byte *)str - 1, transBuf); - while (*str++ != '/') - ; - string2 = (char *)transBuf; - - // If string2 contains formatting information there probably - // wasn't any translation for it in the language.tab file. In - // that case, pretend there is no string2. - if (string2[0] == '^') - string2[0] = 0; - } - - while (str[0] == '^') { - switch (str[1]) { - case 'f': - { - int id = str[3] - '0'; - str += 4; - sf = _sf[id]; - } - break; - case 'c': - { - color = str[4] - '0' + 10 *(str[3] - '0'); - str += 5; - } - break; - default: - error("invalid escape code in text string"); - } - } - - // HACK. This is to prevent bug #1310846. In updated Win95 dig - // there is such line: - // - // ^f01^c001LEAD TESTER - // Chris Purvis - // ^f01 - // ^f01^c001WINDOWS COMPATIBILITY - // Chip Hinnenberg - // ^f01^c001WINDOWS TESTING - // Jim Davison - // Lynn Selk - // - // i.e. formatting exists not in the first line only - // We just strip that off and assume that neither font - // nor font color was altered. Proper fix would be to feed - // drawString() with each line sequentally - char *string3 = NULL, *sptr2; - const char *sptr; - - if (strchr(str, '^')) { - string3 = (char *)malloc(strlen(str) + 1); - - for (sptr = str, sptr2 = string3; *sptr;) { - if (*sptr == '^') { - switch (sptr[1]) { - case 'f': - sptr += 4; - break; - case 'c': - sptr += 5; - break; - default: - error("invalid escape code in text string"); - } - } else { - *sptr2++ = *sptr++; - } - } - *sptr2++ = *sptr++; // copy zero character - str = string3; - } - - assert(sf != NULL); - sf->setColor(color); - - if (_vm->_gameId == GID_CMI && string2[0] != 0) { - str = string2; - } - - // flags: - // bit 0 - center 1 - // bit 1 - not used 2 - // bit 2 - ??? 4 - // bit 3 - wrap around 8 - switch (flags & 9) { - case 0: - sf->drawString(str, _dst, _width, _height, pos_x, pos_y, false); - break; - case 1: - sf->drawString(str, _dst, _width, _height, pos_x, MAX(pos_y, top), true); - break; - case 8: - // FIXME: Is 'right' the maximum line width here, just - // as it is in the next case? It's used several times - // in The Dig's intro, where 'left' and 'right' are - // always 0 and 321 respectively, and apparently we - // handle that correctly. - sf->drawStringWrap(str, _dst, _width, _height, pos_x, MAX(pos_y, top), left, right, false); - break; - case 9: - // In this case, the 'right' parameter is actually the - // maximum line width. This explains why it's sometimes - // smaller than 'left'. - // - // Note that in The Dig's "Spacetime Six" movie it's - // 621. I have no idea what that means. - sf->drawStringWrap(str, _dst, _width, _height, pos_x, MAX(pos_y, top), left, MIN(left + right, _width), true); - break; - default: - error("SmushPlayer::handleTextResource. Not handled flags: %d", flags); - } - - if (string != NULL) { - free (string); - } - if (string3 != NULL) { - free (string3); - } -} - -const char *SmushPlayer::getString(int id) { - return _strings->get(id); -} - -bool SmushPlayer::readString(const char *file) { - const char *i = strrchr(file, '.'); - if (i == NULL) { - error("invalid filename : %s", file); - } - char fname[260]; - memcpy(fname, file, i - file); - strcpy(fname + (i - file), ".trs"); - if ((_strings = getStrings(_vm, fname, false)) != 0) { - return true; - } - - if ((_strings = getStrings(_vm, "digtxt.trs", true)) != 0) { - return true; - } - return false; -} - -void SmushPlayer::readPalette(byte *out, Chunk &in) { - in.read(out, 0x300); -} - -static byte delta_color(byte org_color, int16 delta_color) { - int t = (org_color * 129 + delta_color) / 128; - if (t > 255) - t = 255; - if (t < 0) - t = 0; - return (byte)t; -} - -void SmushPlayer::handleDeltaPalette(Chunk &b) { - checkBlock(b, TYPE_XPAL); - debugC(DEBUG_SMUSH, "SmushPlayer::handleDeltaPalette()"); - - if (b.getSize() == 0x300 * 3 + 4) { - - b.getWord(); - b.getWord(); - - for (int i = 0; i < 0x300; i++) { - _deltaPal[i] = b.getWord(); - } - readPalette(_pal, b); - setDirtyColors(0, 255); - } else if (b.getSize() == 6) { - - b.getWord(); - b.getWord(); - b.getWord(); - - for (int i = 0; i < 0x300; i++) { - _pal[i] = delta_color(_pal[i], _deltaPal[i]); - } - setDirtyColors(0, 255); - } else { - error("SmushPlayer::handleDeltaPalette() Wrong size for DeltaPalette"); - } -} - -void SmushPlayer::handleNewPalette(Chunk &b) { - checkBlock(b, TYPE_NPAL, 0x300); - debugC(DEBUG_SMUSH, "SmushPlayer::handleNewPalette()"); - - if (_skipPalette) - return; - - readPalette(_pal, b); - setDirtyColors(0, 255); -} - -void smush_decode_codec1(byte *dst, const byte *src, int left, int top, int width, int height, int pitch); - -#ifdef USE_ZLIB -void SmushPlayer::handleZlibFrameObject(Chunk &b) { - if (_skipNext) { - _skipNext = false; - return; - } - - int32 chunkSize = b.getSize(); - byte *chunkBuffer = (byte *)malloc(chunkSize); - assert(chunkBuffer); - b.read(chunkBuffer, chunkSize); - - unsigned long decompressedSize = READ_BE_UINT32(chunkBuffer); - byte *fobjBuffer = (byte *)malloc(decompressedSize); - int result = uncompress(fobjBuffer, &decompressedSize, chunkBuffer + 4, chunkSize - 4); - if (result != Z_OK) - error("SmushPlayer::handleZlibFrameObject() Zlib uncompress error"); - free(chunkBuffer); - - byte *ptr = fobjBuffer; - int codec = READ_LE_UINT16(ptr); ptr += 2; - int left = READ_LE_UINT16(ptr); ptr += 2; - int top = READ_LE_UINT16(ptr); ptr += 2; - int width = READ_LE_UINT16(ptr); ptr += 2; - int height = READ_LE_UINT16(ptr); ptr += 2; - - if ((height == 242) && (width == 384)) { - if (_specialBuffer == 0) - _specialBuffer = (byte *)malloc(242 * 384); - _dst = _specialBuffer; - } else if ((height > _vm->_screenHeight) || (width > _vm->_screenWidth)) - return; - // FT Insane uses smaller frames to draw overlays with moving objects - // Other .san files do have them as well but their purpose in unknown - // and often it causes memory overdraw. So just skip those frames - else if (!_insanity && ((height != _vm->_screenHeight) || (width != _vm->_screenWidth))) - return; - - if (!_alreadyInit) { - _codec37.init(width, height); - _codec47.init(width, height); - _alreadyInit = true; - } - - if ((height == 242) && (width == 384)) { - _width = width; - _height = height; - } else { - _width = _vm->_screenWidth; - _height = _vm->_screenHeight; - } - - switch (codec) { - case 1: - case 3: - smush_decode_codec1(_dst, fobjBuffer + 14, left, top, width, height, _vm->_screenWidth); - break; - case 37: - _codec37.decode(_dst, fobjBuffer + 14); - break; - case 47: - _codec47.decode(_dst, fobjBuffer + 14); - break; - default: - error("Invalid codec for frame object : %d", (int)codec); - } - - if (_storeFrame) { - if (_frameBuffer == NULL) { - _frameBuffer = (byte *)malloc(_width * _height); - } - memcpy(_frameBuffer, _dst, _width * _height); - _storeFrame = false; - } - - free(fobjBuffer); -} -#endif - -void SmushPlayer::handleFrameObject(Chunk &b) { - checkBlock(b, TYPE_FOBJ, 14); - if (_skipNext) { - _skipNext = false; - return; - } - - int codec = b.getWord(); - int left = b.getWord(); - int top = b.getWord(); - int width = b.getWord(); - int height = b.getWord(); - - if ((height == 242) && (width == 384)) { - if (_specialBuffer == 0) - _specialBuffer = (byte *)malloc(242 * 384); - _dst = _specialBuffer; - } else if ((height > _vm->_screenHeight) || (width > _vm->_screenWidth)) - return; - // FT Insane uses smaller frames to draw overlays with moving objects - // Other .san files do have them as well but their purpose in unknown - // and often it causes memory overdraw. So just skip those frames - else if (!_insanity && ((height != _vm->_screenHeight) || (width != _vm->_screenWidth))) - return; - - if (!_alreadyInit) { - _codec37.init(width, height); - _codec47.init(width, height); - _alreadyInit = true; - } - - if ((height == 242) && (width == 384)) { - _width = width; - _height = height; - } else { - _width = _vm->_screenWidth; - _height = _vm->_screenHeight; - } - - b.getWord(); - b.getWord(); - - int32 chunk_size = b.getSize() - 14; - byte *chunk_buffer = (byte *)malloc(chunk_size); - assert(chunk_buffer); - b.read(chunk_buffer, chunk_size); - - switch (codec) { - case 1: - case 3: - smush_decode_codec1(_dst, chunk_buffer, left, top, width, height, _vm->_screenWidth); - break; - case 37: - _codec37.decode(_dst, chunk_buffer); - break; - case 47: - _codec47.decode(_dst, chunk_buffer); - break; - default: - error("Invalid codec for frame object : %d", (int)codec); - } - - if (_storeFrame) { - if (_frameBuffer == NULL) { - _frameBuffer = (byte *)malloc(_width * _height); - } - memcpy(_frameBuffer, _dst, _width * _height); - _storeFrame = false; - } - - free(chunk_buffer); -} - -void SmushPlayer::handleFrame(Chunk &b) { - checkBlock(b, TYPE_FRME); - debugC(DEBUG_SMUSH, "SmushPlayer::handleFrame(%d)", _frame); - _skipNext = false; - - uint32 start_time, end_time; - start_time = _vm->_system->getMillis(); - - if (_insanity) { - _vm->_insane->procPreRendering(); - } - - while (!b.eof()) { - Chunk *sub = b.subBlock(); - switch (sub->getType()) { - case TYPE_NPAL: - handleNewPalette(*sub); - break; - case TYPE_FOBJ: - handleFrameObject(*sub); - break; -#ifdef USE_ZLIB - case TYPE_ZFOB: - handleZlibFrameObject(*sub); - break; -#endif - case TYPE_PSAD: - if (!_compressedFileMode) - handleSoundFrame(*sub); - break; - case TYPE_TRES: - handleTextResource(*sub); - break; - case TYPE_XPAL: - handleDeltaPalette(*sub); - break; - case TYPE_IACT: - // FIXME: check parameters - if (_insanity) - _vm->_insane->procIACT(_dst, 0, 0, 0, *sub, 0, 0); - else { - if (!_compressedFileMode) - handleIACT(*sub); - } - break; - case TYPE_STOR: - handleStore(*sub); - break; - case TYPE_FTCH: - handleFetch(*sub); - break; - case TYPE_SKIP: - if (_insanity) - _vm->_insane->procSKIP(*sub); - else - handleSkip(*sub); - break; - case TYPE_TEXT: - handleTextResource(*sub); - break; - default: - error("Unknown frame subChunk found : %s, %d", Chunk::ChunkString(sub->getType()), sub->getSize()); - } - - b.reseek(); - if (sub->getSize() & 1) - b.seek(1); - - delete sub; - } - - if (_insanity) { - _vm->_insane->procPostRendering(_dst, 0, 0, 0, _frame, _nbframes-1); - } - - end_time = _vm->_system->getMillis(); - - if (_width != 0 && _height != 0) { -#ifdef _WIN32_WCE - if (!_inTimer || _inTimerCount == _inTimerCountRedraw) { - updateScreen(); - _inTimerCount = 0; - } -#else - updateScreen(); -#endif - } - _smixer->handleFrame(); - - debugC(DEBUG_SMUSH, "Smush stats: FRME( %03d ), Limit(%d)", end_time - start_time, _speed); - - _frame++; -} - -void SmushPlayer::handleAnimHeader(Chunk &b) { - checkBlock(b, TYPE_AHDR, 0x300 + 6); - debugC(DEBUG_SMUSH, "SmushPlayer::handleAnimHeader()"); - - _version = b.getWord(); - _nbframes = b.getWord(); - b.getWord(); - - if (_skipPalette) - return; - - readPalette(_pal, b); - setDirtyColors(0, 255); -} - -void SmushPlayer::setupAnim(const char *file) { - int i; - char file_font[11]; - - if (_insanity) { - if (!((_vm->_features & GF_DEMO) && (_vm->_platform == Common::kPlatformPC))) - readString("mineroad.trs"); - } else - readString(file); - - if (_vm->_gameId == GID_FT) { - if (!((_vm->_features & GF_DEMO) && (_vm->_platform == Common::kPlatformPC))) { - _sf[0] = new SmushFont(_vm, true, false); - _sf[1] = new SmushFont(_vm, true, false); - _sf[2] = new SmushFont(_vm, true, false); - _sf[3] = new SmushFont(_vm, true, false); - _sf[0]->loadFont("scummfnt.nut"); - _sf[1]->loadFont("techfnt.nut"); - _sf[2]->loadFont("titlfnt.nut"); - _sf[3]->loadFont("specfnt.nut"); - } - } else if (_vm->_gameId == GID_DIG) { - if (!(_vm->_features & GF_DEMO)) { - for (i = 0; i < 4; i++) { - sprintf(file_font, "font%d.nut", i); - _sf[i] = new SmushFont(_vm, i != 0, false); - _sf[i]->loadFont(file_font); - } - } - } else if (_vm->_gameId == GID_CMI) { - for (i = 0; i < 5; i++) { - if ((_vm->_features & GF_DEMO) && (i == 4)) - break; - sprintf(file_font, "font%d.nut", i); - _sf[i] = new SmushFont(_vm, false, true); - _sf[i]->loadFont(file_font); - } - } else { - error("SmushPlayer::setupAnim() Unknown font setup for game"); - } -} - -void SmushPlayer::parseNextFrame() { - Common::StackLock lock(_mutex); - - Chunk *sub; - - if (_vm->_smushPaused) - return; - - if (_seekPos >= 0) { - if (_smixer) - _smixer->stop(); - - if (_seekFile.size() > 0) { - delete _base; - _base = new FileChunk(_seekFile); - - if (_seekPos > 0) { - assert(_seekPos > 8); - // In this case we need to get palette and number of frames - sub = _base->subBlock(); - checkBlock(*sub, TYPE_AHDR); - handleAnimHeader(*sub); - delete sub; - - _middleAudio = true; - _seekPos -= 8; - } else { - // We need this in Full Throttle when entering/leaving - // the old mine road. - tryCmpFile(_seekFile.c_str()); - } - _skipPalette = false; - } else { - _skipPalette = true; - } - - _base->seek(_seekPos, FileChunk::seek_start); - _frame = _seekFrame; - - _seekPos = -1; - } - - assert(_base); - if (_base->eof()) { - _vm->_smushVideoShouldFinish = true; - return; - } - - sub = _base->subBlock(); - - switch (sub->getType()) { - case TYPE_AHDR: // FT INSANE may seek file to the beginning - handleAnimHeader(*sub); - break; - case TYPE_FRME: - handleFrame(*sub); - break; - default: - error("Unknown Chunk found at %x: %x, %d", _base->tell(), sub->getType(), sub->getSize()); - } - delete sub; - - _base->reseek(); - - if (_insanity) - _vm->_sound->processSound(); - - _vm->_imuseDigital->flushTracks(); -} - -void SmushPlayer::setPalette(const byte *palette) { - memcpy(_pal, palette, 0x300); - setDirtyColors(0, 255); -} - -void SmushPlayer::setPaletteValue(int n, byte r, byte g, byte b) { - _pal[n * 3 + 0] = r; - _pal[n * 3 + 1] = g; - _pal[n * 3 + 2] = b; - setDirtyColors(n, n); -} - -void SmushPlayer::setDirtyColors(int min, int max) { - if (_palDirtyMin > min) - _palDirtyMin = min; - if (_palDirtyMax < max) - _palDirtyMax = max; -} - -void SmushPlayer::warpMouse(int x, int y, int buttons) { - _warpNeeded = true; - _warpX = x; - _warpY = y; - _warpButtons = buttons; -} - -void SmushPlayer::updateScreen() { -#ifdef DUMP_SMUSH_FRAMES - char fileName[100]; - // change path below for dump png files - sprintf(fileName, "/path/to/somethere/%s%04d.png", _vm->getBaseName(), _frame); - FILE *file = fopen(fileName, "wb"); - if (file == NULL) - error("can't open file for writing png"); - - png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0); - if (png_ptr == NULL) { - fclose(file); - error("can't write png header"); - } - png_infop info_ptr = png_create_info_struct(png_ptr); - if (info_ptr == NULL) { - fclose(file); - error("can't create png info struct"); - } - if (setjmp(png_ptr->jmpbuf)) { - fclose(file); - error("png jmpbuf error"); - } - - png_init_io(png_ptr, file); - - png_set_IHDR(png_ptr, info_ptr, _width, _height, 8, PNG_COLOR_TYPE_PALETTE, PNG_INTERLACE_NONE, - PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); - - png_colorp palette = (png_colorp)png_malloc(png_ptr, PNG_MAX_PALETTE_LENGTH * sizeof (png_color)); - for (int i = 0; i != 256; ++i) { - (palette + i)->red = _pal[i * 3 + 0]; - (palette + i)->green = _pal[i * 3 + 1]; - (palette + i)->blue = _pal[i * 3 + 2]; - } - - png_set_PLTE(png_ptr, info_ptr, palette, PNG_MAX_PALETTE_LENGTH); - - png_write_info(png_ptr, info_ptr); - png_set_flush(png_ptr, 10); - - png_bytep row_pointers[480]; - for (int y = 0 ; y < _height ; y++) - row_pointers[y] = (png_byte *) (_dst + y * _width); - png_write_image(png_ptr, row_pointers); - png_write_end(png_ptr, info_ptr); - png_free(png_ptr, palette); - - fclose(file); - png_destroy_write_struct(&png_ptr, &info_ptr); -#endif - - uint32 end_time, start_time = _vm->_system->getMillis(); - _updateNeeded = true; - end_time = _vm->_system->getMillis(); - debugC(DEBUG_SMUSH, "Smush stats: updateScreen( %03d )", end_time - start_time); -} - -void SmushPlayer::insanity(bool flag) { - _insanity = flag; -} - -void SmushPlayer::seekSan(const char *file, int32 pos, int32 contFrame) { - Common::StackLock lock(_mutex); - - _seekFile = file ? file : ""; - _seekPos = pos; - _seekFrame = contFrame; -} - -void SmushPlayer::tryCmpFile(const char *filename) { - if (_compressedFile.isOpen()) { - _vm->_mixer->stopHandle(_compressedFileSoundHandle); - _compressedFile.close(); - } - _compressedFileMode = false; - const char *i = strrchr(filename, '.'); - if (i == NULL) { - error("invalid filename : %s", filename); - } -#if defined(USE_MAD) || defined(USE_VORBIS) - char fname[260]; -#endif -#ifdef USE_MAD - memcpy(fname, filename, i - filename); - strcpy(fname + (i - filename), ".mp3"); - _compressedFile.open(fname); - if (_compressedFile.isOpen()) { - int size = _compressedFile.size(); - _compressedFileMode = true; - _vm->_mixer->playInputStream(Audio::Mixer::kSFXSoundType, &_compressedFileSoundHandle, makeMP3Stream(&_compressedFile, size)); - return; - } -#endif -#ifdef USE_VORBIS - memcpy(fname, filename, i - filename); - strcpy(fname + (i - filename), ".ogg"); - _compressedFile.open(fname); - if (_compressedFile.isOpen()) { - int size = _compressedFile.size(); - _compressedFileMode = true; - _vm->_mixer->playInputStream(Audio::Mixer::kSFXSoundType, &_compressedFileSoundHandle, makeVorbisStream(&_compressedFile, size)); - return; - } -#endif -} - -void SmushPlayer::play(const char *filename, int32 offset, int32 startFrame) { - - // Verify the specified file exists - ScummFile f; - _vm->openFile(f, filename); - if (!f.isOpen()) { - warning("SmushPlayer::play() File not found %s", filename); - return; - } - f.close(); - - _updateNeeded = false; - _warpNeeded = false; - _palDirtyMin = 256; - _palDirtyMax = -1; - - // Hide mouse - bool oldMouseState = _vm->_system->showMouse(false); - - // Load the video - _seekFile = filename; - _seekPos = offset; - _seekFrame = startFrame; - _base = 0; - - setupAnim(filename); - init(); - - for (;;) { - if (_warpNeeded) { - _vm->_system->warpMouse(_warpX, _warpY); - _warpNeeded = false; - } - _vm->parseEvents(); - _vm->processKbd(true); - if (_palDirtyMax >= _palDirtyMin) { - byte palette_colors[1024]; - byte *p = palette_colors; - - for (int i = _palDirtyMin; i <= _palDirtyMax; i++) { - byte *data = _pal + i * 3; - - *p++ = data[0]; - *p++ = data[1]; - *p++ = data[2]; - *p++ = 0; - } - - _vm->_system->setPalette(palette_colors, _palDirtyMin, _palDirtyMax - _palDirtyMin + 1); - - _palDirtyMax = -1; - _palDirtyMin = 256; - } - if (_updateNeeded) { - uint32 end_time, start_time; - - start_time = _vm->_system->getMillis(); - _vm->_system->copyRectToScreen(_dst, _width, 0, 0, _width, _height); - _vm->_system->updateScreen(); - _updateNeeded = false; -#ifdef _WIN32_WCE - _inTimer = false; - _inTimerCount = 0; -#endif - - end_time = _vm->_system->getMillis(); - - debugC(DEBUG_SMUSH, "Smush stats: BackendUpdateScreen( %03d )", end_time - start_time); - - } - if (_vm->_smushVideoShouldFinish || _vm->_quit || _vm->_saveLoadFlag) - break; - _vm->_system->delayMillis(10); - } - - release(); - - // Reset mouse state - _vm->_system->showMouse(oldMouseState); -} - -} // End of namespace Scumm - diff --git a/scumm/smush/smush_player.h b/scumm/smush/smush_player.h deleted file mode 100644 index f697057d89..0000000000 --- a/scumm/smush/smush_player.h +++ /dev/null @@ -1,148 +0,0 @@ -/* ScummVM - Scumm Interpreter - * Copyright (C) 2002-2006 The ScummVM project - * - * 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$ - * - */ - -#if !defined(SMUSH_PLAYER_H) && !defined(DISABLE_SCUMM_7_8) -#define SMUSH_PLAYER_H - -#include "common/util.h" -#include "scumm/smush/chunk.h" -#include "scumm/smush/codec37.h" -#include "scumm/smush/codec47.h" -#include "scumm/sound.h" - -namespace Scumm { - -class ScummEngine_v6; -class SmushFont; -class SmushMixer; -class StringResource; - -class SmushPlayer { - friend class Insane; -private: - ScummEngine_v6 *_vm; - int _version; - int32 _nbframes; - SmushMixer *_smixer; - int16 _deltaPal[0x300]; - byte _pal[0x300]; - StringResource *_strings; - Codec37Decoder _codec37; - Codec47Decoder _codec47; - FileChunk *_base; - byte *_frameBuffer; - byte *_specialBuffer; - - Common::String _seekFile; - int32 _seekPos; - int32 _seekFrame; - - bool _skipNext; - bool _subtitles; - bool _skips[37]; - int32 _frame; - - Audio::SoundHandle _IACTchannel; - AppendableAudioStream *_IACTstream; - - Audio::SoundHandle _compressedFileSoundHandle; - bool _compressedFileMode; - Common::File _compressedFile; - byte _IACToutput[4096]; - int32 _IACTpos; - bool _storeFrame; - int _soundFrequency; - bool _alreadyInit; - bool _initDone; - int _speed; - bool _outputSound; - - byte *_dst; - bool _updateNeeded; - bool _warpNeeded; - int _palDirtyMin, _palDirtyMax; - int _warpX, _warpY; - int _warpButtons; - bool _insanity; - bool _middleAudio; - bool _skipPalette; -#ifdef _WIN32_WCE - bool _inTimer; - int16 _inTimerCount; - int16 _inTimerCountRedraw; -#endif - - Common::Mutex _mutex; - -public: - SmushPlayer(ScummEngine_v6 *scumm, int speed); - ~SmushPlayer(); - - void play(const char *filename, int32 offset = 0, int32 startFrame = 0); - void warpMouse(int x, int y, int buttons); - -protected: - SmushFont *_sf[5]; - int _width, _height; - - int _origPitch, _origNumStrips; - - void insanity(bool); - void setPalette(const byte *palette); - void setPaletteValue(int n, byte r, byte g, byte b); - void setDirtyColors(int min, int max); - void seekSan(const char *file, int32 pos, int32 contFrame); - const char *getString(int id); - -private: - void parseNextFrame(); - void init(); - void release(); - void setupAnim(const char *file); - void updateScreen(); - void tryCmpFile(const char *filename); - - bool readString(const char *file); - void checkBlock(const Chunk &, Chunk::type, uint32 = 0); - void handleAnimHeader(Chunk &); - void handleFrame(Chunk &); - void handleNewPalette(Chunk &); -#ifdef USE_ZLIB - void handleZlibFrameObject(Chunk &b); -#endif - void handleFrameObject(Chunk &); - void handleSoundBuffer(int32, int32, int32, int32, int32, int32, Chunk &, int32); - void handleSoundFrame(Chunk &); - void handleSkip(Chunk &); - void handleStore(Chunk &); - void handleFetch(Chunk &); - void handleIACT(Chunk &); - void handleTextResource(Chunk &); - void handleDeltaPalette(Chunk &); - void readPalette(byte *, Chunk &); - - static void timerCallback(void *ptr); -}; - -} // End of namespace Scumm - -#endif |