From 901b4a07a6a033bc871a64a634b5a3564c1a4fc8 Mon Sep 17 00:00:00 2001 From: Paweł Kołodziejski Date: Sat, 24 Aug 2002 17:18:55 +0000 Subject: changed name from Chunck to Chunk svn-id: r4829 --- scumm/smush/blitter.cpp | 6 +- scumm/smush/blitter.h | 6 +- scumm/smush/channel.h | 26 ++-- scumm/smush/chunck.cpp | 288 ------------------------------------------ scumm/smush/chunck.h | 121 ------------------ scumm/smush/chunck_type.h | 57 --------- scumm/smush/chunk.cpp | 288 ++++++++++++++++++++++++++++++++++++++++++ scumm/smush/chunk.h | 121 ++++++++++++++++++ scumm/smush/chunk_type.h | 57 +++++++++ scumm/smush/codec1.cpp | 4 +- scumm/smush/codec1.h | 2 +- scumm/smush/codec37.cpp | 14 +- scumm/smush/codec37.h | 12 +- scumm/smush/codec44.cpp | 4 +- scumm/smush/codec44.h | 2 +- scumm/smush/codec47.cpp | 4 +- scumm/smush/codec47.h | 2 +- scumm/smush/color.h | 12 +- scumm/smush/decoder.h | 4 +- scumm/smush/frenderer.h | 2 +- scumm/smush/imuse_channel.cpp | 36 +++--- scumm/smush/player.cpp | 52 ++++---- scumm/smush/player.h | 36 +++--- scumm/smush/saud_channel.cpp | 26 ++-- 24 files changed, 591 insertions(+), 591 deletions(-) delete mode 100644 scumm/smush/chunck.cpp delete mode 100644 scumm/smush/chunck.h delete mode 100644 scumm/smush/chunck_type.h create mode 100644 scumm/smush/chunk.cpp create mode 100644 scumm/smush/chunk.h create mode 100644 scumm/smush/chunk_type.h (limited to 'scumm') diff --git a/scumm/smush/blitter.cpp b/scumm/smush/blitter.cpp index bbeb7a1864..a209ceb852 100644 --- a/scumm/smush/blitter.cpp +++ b/scumm/smush/blitter.cpp @@ -21,7 +21,7 @@ #include #include "blitter.h" -#include "chunck.h" +#include "chunk.h" #include #include // for memcpy @@ -114,7 +114,7 @@ void Blitter::blit(char * ptr, unsigned int len) { } } -void Blitter::blit(Chunck & src, unsigned int len) { +void Blitter::blit(Chunk & src, unsigned int len) { while(len) { if(_outside) { #ifdef DEBUG_CLIPPER @@ -185,7 +185,7 @@ void Blitter::putBlock(unsigned char * data) { advanceBlock(); } -void Blitter::putBlock(Chunck & src) { +void Blitter::putBlock(Chunk & src) { if(_cur.getX() + 3 < _src.right() && _cur.getY() + 3 < _src.bottom()) { // This is clipping assert((_clip.getX() & 3) == 0); unsigned int * dst = (unsigned int *)_offset; diff --git a/scumm/smush/blitter.h b/scumm/smush/blitter.h index 3515ba0a20..e9d0509cff 100644 --- a/scumm/smush/blitter.h +++ b/scumm/smush/blitter.h @@ -36,7 +36,7 @@ #include "rect.h" -class Chunck; +class Chunk; /*! @brief class for handling blitting on a frame buffer This class allows to perform secure blitting to a frame buffer in several ways. @@ -64,13 +64,13 @@ public: Blitter(char * buffer, const Point & dstsize, const Rect & src); virtual ~Blitter(); void blit(char *, unsigned int); //!< This method allows to blit directly some data from a buffer - void blit(Chunck &, unsigned int); //!< This method allows to blit directly some data from a chunck + void blit(Chunk &, unsigned int); //!< This method allows to blit directly some data from a Chunk void put(char); //!< This method allows to blit one byte void put(char, unsigned int); //!< This method allows to blit one byte several times void advance(int = 1, int = 0); //!< This method allows to advance the current position in the blitter void advanceBlock(int = 1, int = 0); //!< This method allows to advance the current position in the blitter in terms of blocks void putBlock(unsigned int); //!< This method allows to blit one block from an int value repeated 4 time - void putBlock(Chunck &); //!< This method allows to blit one block directly read from a chunck + void putBlock(Chunk &); //!< This method allows to blit one block directly read from a Chunk void putBlock(unsigned char *); //!< This method allows to blit one block directly from a buffer void putBlock(unsigned int, unsigned int, unsigned int, unsigned int); //!< This method allows to blit one block from a 4 int value void blockCopy(int); //!< This method allows to copy one block from another separated by the given offset diff --git a/scumm/smush/channel.h b/scumm/smush/channel.h index 5010c3f581..b13d08d5a5 100644 --- a/scumm/smush/channel.h +++ b/scumm/smush/channel.h @@ -34,8 +34,8 @@ # endif #endif -class Chunck; -class ContChunck; +class Chunk; +class ContChunk; /*! @brief interface for a sound channel (a track) @@ -45,7 +45,7 @@ class _Channel { public: virtual ~_Channel() {}; // called by the smush_player - virtual bool appendData(Chunck & b, int size) = 0; + virtual bool appendData(Chunk & b, int size) = 0; virtual bool setParameters(int, int, int, int) = 0; virtual bool checkParameters(int, int, int, int, int) = 0; // called by the mixer @@ -76,9 +76,9 @@ private: int _sbufferSize; //!< sound buffer size protected: - void handleStrk(Chunck & c); - void handleSmrk(Chunck & c); - void handleShdr(Chunck & c); + void handleStrk(Chunk & c); + void handleSmrk(Chunk & c); + void handleShdr(Chunk & c); bool handleSubTags(int & offset); bool processBuffer(); void recalcVolumeTable(); @@ -89,7 +89,7 @@ public: bool isTerminated() const; bool setParameters(int duration, int flags, int vol1, int vol2); bool checkParameters(int index, int duration, int flags, int vol1, int vol2); - bool appendData(Chunck & b, int size); + bool appendData(Chunk & b, int size); int availableSoundData() const; void getSoundData(short * sound_buffer, int size); void getSoundData(char * sound_buffer, int size) { error("16bit request for SAUD channel should never happen"); }; @@ -128,11 +128,11 @@ protected: int decode(int size, int &ret); void decode(); bool processBuffer(); - bool handleMap(Chunck &); - bool handleFormat(Chunck &); - bool handleText(Chunck &); - bool handleRegion(Chunck &); - bool handleStop(Chunck &); + bool handleMap(Chunk &); + bool handleFormat(Chunk &); + bool handleText(Chunk &); + bool handleRegion(Chunk &); + bool handleStop(Chunk &); bool handleSubTags(int & offset); public: @@ -141,7 +141,7 @@ public: bool isTerminated() const; bool setParameters(int nbframes, int size, int unk1, int unk2); bool checkParameters(int index, int nbframes, int size, int unk1, int unk2); - bool appendData(Chunck & b, int size); + bool appendData(Chunk & b, int size); int availableSoundData() const; void getSoundData(short * sound_buffer, int size); void getSoundData(char * sound_buffer, int size); diff --git a/scumm/smush/chunck.cpp b/scumm/smush/chunck.cpp deleted file mode 100644 index b4bf99fcbc..0000000000 --- a/scumm/smush/chunck.cpp +++ /dev/null @@ -1,288 +0,0 @@ -/* ScummVM - Scumm Interpreter - * Copyright (C) 2001/2002 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * $Header$ - * - */ - -#include -#include "chunck.h" - -#include // for FILE, fopen, fclose, fseek and ftell -#include // for memcpy - -/*! @brief very small and fast wrapper for a ifstream. - - implements reference counting, so that ::file_chunck does not leak memory ! -*/ -class FilePtr { - char * _filename; - FILE * _ifs; - int _refcount; - int _curPos; -public: - FilePtr(const char * fname) : _refcount(1), _curPos(0) { - debug(9, "FilePtr created for %s", fname); - _filename = strdup(fname); - _ifs = fopen(fname, "rb"); - if(_ifs == NULL) error("FilePtr unable to read file \"%s\"", fname); - } - ~FilePtr() { - debug(9, "FilePtr destroyed for %s", _filename); - free(_filename); - fclose(_ifs); - } - int tell() { - return _curPos; - } - bool seek(int pos) { - if(pos != _curPos) { - fseek(_ifs, pos, SEEK_SET); - _curPos = pos; - } - return true; - } - bool read(void * ptr, int size) { - fread(ptr, size, 1, _ifs); - _curPos += size; - return true; - } - void incRef() { - _refcount++; - } - void decRef() { - if(--_refcount == 0) - delete this; - } -}; - -const char * Chunck::ChunckString(Chunck::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; -} - -FileChunck::FileChunck() : _data(0), _type(0), _size(0), _curPos(0) { -} - -FileChunck::~FileChunck() { - if(_data) _data->decRef(); -} - -FileChunck::FileChunck(const char * fname) { - _data = new FilePtr(fname); - _data->read(&_type, 4); - _type = TO_BE_32(_type); - _data->read(&_size, 4); - _size = TO_BE_32(_size); - _offset = _data->tell(); - _curPos = 0; -} - -Chunck::type FileChunck::getType() const { - return _type; -} - -unsigned int FileChunck::getSize() const { - return _size; -} - -Chunck * FileChunck::subBlock() { - FileChunck * ptr = new FileChunck; - ptr->_data = _data; - _data->incRef(); - _data->seek(_offset + _curPos); - unsigned int temp; - _data->read(&temp, 4); - ptr->_type = TO_BE_32(temp); - _data->read(&temp, 4); - ptr->_size = TO_BE_32(temp); - ptr->_offset = _offset + _curPos + 8; - ptr->_curPos = 0; - seek(8 + ptr->getSize()); - return ptr; -} - -bool FileChunck::eof() const { - return _curPos >= _size; -} - -unsigned int FileChunck::tell() const { - return _curPos; -} - -bool FileChunck::seek(int delta, seek_type dir) { - switch(dir) { - case seek_cur: - _curPos += delta; - break; - case seek_start: - if(delta < 0) error("invalid seek request"); - _curPos = (unsigned int)delta; - break; - case seek_end: - if(delta > 0 || (_size + delta) < 0) error("invalid seek request"); - _curPos = (unsigned int)(_size + delta); - break; - } - if(_curPos > _size) { - error("invalid seek request : %d > %d (delta == %d)", _curPos, _size, delta); - } - return true; -} - -bool FileChunck::read(void * buffer, unsigned int size) { - if(size <= 0 || (_curPos + size) > _size) error("invalid buffer read request"); - _data->seek(_offset + _curPos); - _data->read(buffer, size); - _curPos += size; - return true; -} - -char FileChunck::getChar() { - if(_curPos >= _size) error("invalid char read request"); - _data->seek(_offset + _curPos); - char buffer; - _data->read(&buffer, sizeof(buffer)); - _curPos+= sizeof(buffer); - return buffer; -} - -unsigned char FileChunck::getByte() { - if(_curPos >= _size) error("invalid byte read request"); - _data->seek(_offset + _curPos); - unsigned char buffer; - _data->read(&buffer, sizeof(buffer)); - _curPos+= sizeof(buffer); - return buffer; -} - -short FileChunck::getShort() { - unsigned short buffer = getWord(); - return *((short*)&buffer); -} - -unsigned short FileChunck::getWord() { - if(_curPos >= _size - 1) error("invalid word read request"); - _data->seek(_offset + _curPos); - unsigned short buffer; - _data->read(&buffer, sizeof(buffer)); - _curPos+= sizeof(buffer); - return TO_LE_16(buffer); -} - -unsigned int FileChunck::getDword() { - if(_curPos >= _size - 3) error("invalid dword read request"); - _data->seek(_offset + _curPos); - unsigned int buffer; - _data->read(&buffer, sizeof(buffer)); - _curPos+= sizeof(buffer); - return TO_LE_32(buffer); -} - -ContChunck::ContChunck(char * data) { - if(data == 0) error("Chunck() called with NULL pointer"); - _type = (Chunck::type)READ_BE_UINT32(data); - _size = READ_BE_UINT32(data+4); - _data = data + sizeof(Chunck::type) + sizeof(unsigned int); - _curPos = 0; -} - -Chunck::type ContChunck::getType() const { - return _type; -} - -unsigned int ContChunck::getSize() const { - return _size; -} - -Chunck * ContChunck::subBlock() { - ContChunck * ptr = new ContChunck(_data + _curPos); - seek(sizeof(Chunck::type) + sizeof(unsigned int) + ptr->getSize()); - return ptr; -} - -bool ContChunck::eof() const { - return _curPos >= _size; -} - -unsigned int ContChunck::tell() const { - return _curPos; -} - -bool ContChunck::seek(int delta, seek_type dir) { - switch(dir) { - case seek_cur: - _curPos += delta; - break; - case seek_start: - if(delta < 0) error("invalid seek request"); - _curPos = (unsigned int)delta; - break; - case seek_end: - if(delta > 0 || (_size + delta) < 0) error("invalid seek request"); - _curPos = (unsigned int)(_size + delta); - break; - } - if(_curPos > _size) { - error("invalid seek request : %d > %d (delta == %d)", _curPos, _size, delta); - } - return true; -} - -bool ContChunck::read(void * buffer, unsigned int size) { - if(size <= 0 || (_curPos + size) > _size) error("invalid buffer read request"); - memcpy(buffer, _data + _curPos, size); - _curPos += size; - return true; -} - -char ContChunck::getChar() { - if(_curPos >= _size) error("invalid char read request"); - return _data[_curPos++]; -} - -unsigned char ContChunck::getByte() { - if(_curPos >= _size) error("invalid byte read request"); - unsigned char * ptr = (unsigned char *)(_data + _curPos); - _curPos += 1; - return *ptr; -} - -short ContChunck::getShort() { - if(_curPos >= _size - 1) error("invalid short read request"); - unsigned short buffer = getWord(); - return *((short*)&buffer); -} - -unsigned short ContChunck::getWord() { - if(_curPos >= _size - 1) error("invalid word read request"); - unsigned short * ptr = (unsigned short *)(_data + _curPos); - _curPos += 2; - return READ_LE_UINT16(ptr); -} - -unsigned int ContChunck::getDword() { - if(_curPos >= _size - 3) error("invalid dword read request"); - unsigned int * ptr = (unsigned int *)(_data + _curPos); - _curPos += 4; - return READ_LE_UINT32(ptr); -} diff --git a/scumm/smush/chunck.h b/scumm/smush/chunck.h deleted file mode 100644 index 3a1ec6adda..0000000000 --- a/scumm/smush/chunck.h +++ /dev/null @@ -1,121 +0,0 @@ -/* ScummVM - Scumm Interpreter - * Copyright (C) 2001/2002 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * $Header$ - * - */ - -#ifndef __CHUNCK_H_ -#define __CHUNCK_H_ - -#include "config.h" - -/*! @brief Interface for chunck handling - - This class is an interface for reading from a chunck. - - \todo handle big endian system. -*/ -class Chunck { -public: - enum seek_type { seek_start, seek_end, seek_cur }; - virtual ~Chunck() {}; - typedef unsigned int type; //!< type of a chunck (i.e. The first 4byte field of the chunck structure). - /*! @brief convert a type to a string - - Utility function that convert a type to a string. - - @param t the type to convert to a string - - @return the converted string - */ - static const char * ChunckString(type t); - - virtual type getType() const = 0; //!< return the type of the chunck - virtual unsigned int getSize() const = 0; //!< return the size of the chunck - virtual Chunck * subBlock() = 0; //!< extract a subchunck from the current read position - virtual bool eof() const = 0; //!< is the chunck completely read ? - virtual unsigned int tell() const = 0; //!< get the chunck current read position - virtual bool seek(int delta, seek_type dir = seek_cur) = 0; //!< move the current read position inside the chunck - virtual bool read(void * buffer, unsigned int size) = 0; //!< read some data for the current read position - virtual char getChar() = 0; //!< extract the character at the current read position - virtual unsigned char getByte() = 0; //!< extract the byte at the current read position - virtual short getShort() = 0; //!< extract the short at the current read position - virtual unsigned short getWord() = 0; //!< extract the word at the current read position - virtual unsigned int getDword()= 0; //!< extract the dword at the current read position -}; - -class FilePtr; - -/*! @brief file based ::chunck - - This class is an implementation of ::chunck that handles file. - -*/ -class FileChunck : public Chunck { -private: - FilePtr * _data; - type _type; - unsigned int _size; - unsigned int _offset; - unsigned int _curPos; -protected: - FileChunck(); -public: - FileChunck(const char * fname); - virtual ~FileChunck(); - type getType() const; - unsigned int getSize() const; - Chunck * subBlock(); - bool eof() const; - unsigned int tell() const; - bool seek(int delta, seek_type dir = seek_cur); - bool read(void * buffer, unsigned int size); - char getChar(); - unsigned char getByte(); - short getShort(); - unsigned short getWord(); - unsigned int getDword(); -}; - -/*! @brief memory based ::chunck - - This class is an implementation of ::chunck that handles a memory buffer. -*/ -class ContChunck : public Chunck { -private: - char * _data; - Chunck::type _type; - unsigned int _size; - unsigned int _curPos; -public: - ContChunck(char * data); - Chunck::type getType() const; - unsigned int getSize() const; - Chunck * subBlock(); - bool eof() const; - unsigned int tell() const; - bool seek(int delta, seek_type dir = seek_cur); - bool read(void * buffer, unsigned int size); - char getChar(); - unsigned char getByte(); - short getShort(); - unsigned short getWord(); - unsigned int getDword(); -}; - -#endif diff --git a/scumm/smush/chunck_type.h b/scumm/smush/chunck_type.h deleted file mode 100644 index e3e2596175..0000000000 --- a/scumm/smush/chunck_type.h +++ /dev/null @@ -1,57 +0,0 @@ -/* ScummVM - Scumm Interpreter - * Copyright (C) 2001/2002 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * $Header$ - * - */ - -#ifndef __CHUNCK_TYPE_H -#define __CHUNCK_TYPE_H - -#include "chunck.h" - -#define MAKE_TYPE(a,b,c,d) (Chunck::type)( ((a) << 24) | ((b) << 16) | ((c) << 8) | (d) ) - -static const Chunck::type TYPE_ANIM = MAKE_TYPE('A', 'N', 'I', 'M'); -static const Chunck::type TYPE_AHDR = MAKE_TYPE('A', 'H', 'D', 'R'); -static const Chunck::type TYPE_FRME = MAKE_TYPE('F', 'R', 'M', 'E'); -static const Chunck::type TYPE_NPAL = MAKE_TYPE('N', 'P', 'A', 'L'); -static const Chunck::type TYPE_FOBJ = MAKE_TYPE('F', 'O', 'B', 'J'); -static const Chunck::type TYPE_PSAD = MAKE_TYPE('P', 'S', 'A', 'D'); -static const Chunck::type TYPE_TRES = MAKE_TYPE('T', 'R', 'E', 'S'); -static const Chunck::type TYPE_XPAL = MAKE_TYPE('X', 'P', 'A', 'L'); -static const Chunck::type TYPE_IACT = MAKE_TYPE('I', 'A', 'C', 'T'); -static const Chunck::type TYPE_STOR = MAKE_TYPE('S', 'T', 'O', 'R'); -static const Chunck::type TYPE_FTCH = MAKE_TYPE('F', 'T', 'C', 'H'); -static const Chunck::type TYPE_SKIP = MAKE_TYPE('S', 'K', 'I', 'P'); -static const Chunck::type TYPE_STRK = MAKE_TYPE('S', 'T', 'R', 'K'); -static const Chunck::type TYPE_SMRK = MAKE_TYPE('S', 'M', 'R', 'K'); -static const Chunck::type TYPE_SHDR = MAKE_TYPE('S', 'H', 'D', 'R'); -static const Chunck::type TYPE_SDAT = MAKE_TYPE('S', 'D', 'A', 'T'); -static const Chunck::type TYPE_SAUD = MAKE_TYPE('S', 'A', 'U', 'D'); -static const Chunck::type TYPE_iMUS = MAKE_TYPE('i', 'M', 'U', 'S'); -static const Chunck::type TYPE_FRMT = MAKE_TYPE('F', 'R', 'M', 'T'); -static const Chunck::type TYPE_TEXT = MAKE_TYPE('T', 'E', 'X', 'T'); -static const Chunck::type TYPE_REGN = MAKE_TYPE('R', 'E', 'G', 'N'); -static const Chunck::type TYPE_STOP = MAKE_TYPE('S', 'T', 'O', 'P'); -static const Chunck::type TYPE_MAP_ = MAKE_TYPE('M', 'A', 'P', ' '); -static const Chunck::type TYPE_DATA = MAKE_TYPE('D', 'A', 'T', 'A'); -static const Chunck::type TYPE_ETRS = MAKE_TYPE('E', 'T', 'R', 'S'); - -#undef MAKE_TYPE - -#endif diff --git a/scumm/smush/chunk.cpp b/scumm/smush/chunk.cpp new file mode 100644 index 0000000000..bb3b2db2e2 --- /dev/null +++ b/scumm/smush/chunk.cpp @@ -0,0 +1,288 @@ +/* ScummVM - Scumm Interpreter + * Copyright (C) 2001/2002 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Header$ + * + */ + +#include +#include "Chunk.h" + +#include // for FILE, fopen, fclose, fseek and ftell +#include // for memcpy + +/*! @brief very small and fast wrapper for a ifstream. + + implements reference counting, so that ::file_Chunk does not leak memory ! +*/ +class FilePtr { + char * _filename; + FILE * _ifs; + int _refcount; + int _curPos; +public: + FilePtr(const char * fname) : _refcount(1), _curPos(0) { + debug(9, "FilePtr created for %s", fname); + _filename = strdup(fname); + _ifs = fopen(fname, "rb"); + if(_ifs == NULL) error("FilePtr unable to read file \"%s\"", fname); + } + ~FilePtr() { + debug(9, "FilePtr destroyed for %s", _filename); + free(_filename); + fclose(_ifs); + } + int tell() { + return _curPos; + } + bool seek(int pos) { + if(pos != _curPos) { + fseek(_ifs, pos, SEEK_SET); + _curPos = pos; + } + return true; + } + bool read(void * ptr, int size) { + fread(ptr, size, 1, _ifs); + _curPos += size; + return true; + } + void incRef() { + _refcount++; + } + void decRef() { + if(--_refcount == 0) + delete this; + } +}; + +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; +} + +FileChunk::FileChunk() : _data(0), _type(0), _size(0), _curPos(0) { +} + +FileChunk::~FileChunk() { + if(_data) _data->decRef(); +} + +FileChunk::FileChunk(const char * fname) { + _data = new FilePtr(fname); + _data->read(&_type, 4); + _type = TO_BE_32(_type); + _data->read(&_size, 4); + _size = TO_BE_32(_size); + _offset = _data->tell(); + _curPos = 0; +} + +Chunk::type FileChunk::getType() const { + return _type; +} + +unsigned int FileChunk::getSize() const { + return _size; +} + +Chunk * FileChunk::subBlock() { + FileChunk * ptr = new FileChunk; + ptr->_data = _data; + _data->incRef(); + _data->seek(_offset + _curPos); + unsigned int temp; + _data->read(&temp, 4); + ptr->_type = TO_BE_32(temp); + _data->read(&temp, 4); + ptr->_size = TO_BE_32(temp); + ptr->_offset = _offset + _curPos + 8; + ptr->_curPos = 0; + seek(8 + ptr->getSize()); + return ptr; +} + +bool FileChunk::eof() const { + return _curPos >= _size; +} + +unsigned int FileChunk::tell() const { + return _curPos; +} + +bool FileChunk::seek(int delta, seek_type dir) { + switch(dir) { + case seek_cur: + _curPos += delta; + break; + case seek_start: + if(delta < 0) error("invalid seek request"); + _curPos = (unsigned int)delta; + break; + case seek_end: + if(delta > 0 || (_size + delta) < 0) error("invalid seek request"); + _curPos = (unsigned int)(_size + delta); + break; + } + if(_curPos > _size) { + error("invalid seek request : %d > %d (delta == %d)", _curPos, _size, delta); + } + return true; +} + +bool FileChunk::read(void * buffer, unsigned int size) { + if(size <= 0 || (_curPos + size) > _size) error("invalid buffer read request"); + _data->seek(_offset + _curPos); + _data->read(buffer, size); + _curPos += size; + return true; +} + +char FileChunk::getChar() { + if(_curPos >= _size) error("invalid char read request"); + _data->seek(_offset + _curPos); + char buffer; + _data->read(&buffer, sizeof(buffer)); + _curPos+= sizeof(buffer); + return buffer; +} + +unsigned char FileChunk::getByte() { + if(_curPos >= _size) error("invalid byte read request"); + _data->seek(_offset + _curPos); + unsigned char buffer; + _data->read(&buffer, sizeof(buffer)); + _curPos+= sizeof(buffer); + return buffer; +} + +short FileChunk::getShort() { + unsigned short buffer = getWord(); + return *((short*)&buffer); +} + +unsigned short FileChunk::getWord() { + if(_curPos >= _size - 1) error("invalid word read request"); + _data->seek(_offset + _curPos); + unsigned short buffer; + _data->read(&buffer, sizeof(buffer)); + _curPos+= sizeof(buffer); + return TO_LE_16(buffer); +} + +unsigned int FileChunk::getDword() { + if(_curPos >= _size - 3) error("invalid dword read request"); + _data->seek(_offset + _curPos); + unsigned int buffer; + _data->read(&buffer, sizeof(buffer)); + _curPos+= sizeof(buffer); + return TO_LE_32(buffer); +} + +ContChunk::ContChunk(char * 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(unsigned int); + _curPos = 0; +} + +Chunk::type ContChunk::getType() const { + return _type; +} + +unsigned int ContChunk::getSize() const { + return _size; +} + +Chunk * ContChunk::subBlock() { + ContChunk * ptr = new ContChunk(_data + _curPos); + seek(sizeof(Chunk::type) + sizeof(unsigned int) + ptr->getSize()); + return ptr; +} + +bool ContChunk::eof() const { + return _curPos >= _size; +} + +unsigned int ContChunk::tell() const { + return _curPos; +} + +bool ContChunk::seek(int delta, seek_type dir) { + switch(dir) { + case seek_cur: + _curPos += delta; + break; + case seek_start: + if(delta < 0) error("invalid seek request"); + _curPos = (unsigned int)delta; + break; + case seek_end: + if(delta > 0 || (_size + delta) < 0) error("invalid seek request"); + _curPos = (unsigned int)(_size + delta); + break; + } + if(_curPos > _size) { + error("invalid seek request : %d > %d (delta == %d)", _curPos, _size, delta); + } + return true; +} + +bool ContChunk::read(void * buffer, unsigned int size) { + if(size <= 0 || (_curPos + size) > _size) error("invalid buffer read request"); + memcpy(buffer, _data + _curPos, size); + _curPos += size; + return true; +} + +char ContChunk::getChar() { + if(_curPos >= _size) error("invalid char read request"); + return _data[_curPos++]; +} + +unsigned char ContChunk::getByte() { + if(_curPos >= _size) error("invalid byte read request"); + unsigned char * ptr = (unsigned char *)(_data + _curPos); + _curPos += 1; + return *ptr; +} + +short ContChunk::getShort() { + if(_curPos >= _size - 1) error("invalid short read request"); + unsigned short buffer = getWord(); + return *((short*)&buffer); +} + +unsigned short ContChunk::getWord() { + if(_curPos >= _size - 1) error("invalid word read request"); + unsigned short * ptr = (unsigned short *)(_data + _curPos); + _curPos += 2; + return READ_LE_UINT16(ptr); +} + +unsigned int ContChunk::getDword() { + if(_curPos >= _size - 3) error("invalid dword read request"); + unsigned int * ptr = (unsigned int *)(_data + _curPos); + _curPos += 4; + return READ_LE_UINT32(ptr); +} diff --git a/scumm/smush/chunk.h b/scumm/smush/chunk.h new file mode 100644 index 0000000000..3b42800ee2 --- /dev/null +++ b/scumm/smush/chunk.h @@ -0,0 +1,121 @@ +/* ScummVM - Scumm Interpreter + * Copyright (C) 2001/2002 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Header$ + * + */ + +#ifndef __CHUNK_H_ +#define __CHUNK_H_ + +#include "config.h" + +/*! @brief Interface for Chunk handling + + This class is an interface for reading from a Chunk. + + \todo handle big endian system. +*/ +class Chunk { +public: + enum seek_type { seek_start, seek_end, seek_cur }; + virtual ~Chunk() {}; + typedef unsigned int type; //!< type of a Chunk (i.e. The first 4byte field of the Chunk structure). + /*! @brief convert a type to a string + + Utility function that convert a type to a string. + + @param t the type to convert to a string + + @return the converted string + */ + static const char * ChunkString(type t); + + virtual type getType() const = 0; //!< return the type of the Chunk + virtual unsigned int getSize() const = 0; //!< return the size of the Chunk + virtual Chunk * subBlock() = 0; //!< extract a subChunk from the current read position + virtual bool eof() const = 0; //!< is the Chunk completely read ? + virtual unsigned int tell() const = 0; //!< get the Chunk current read position + virtual bool seek(int delta, seek_type dir = seek_cur) = 0; //!< move the current read position inside the Chunk + virtual bool read(void * buffer, unsigned int size) = 0; //!< read some data for the current read position + virtual char getChar() = 0; //!< extract the character at the current read position + virtual unsigned char getByte() = 0; //!< extract the byte at the current read position + virtual short getShort() = 0; //!< extract the short at the current read position + virtual unsigned short getWord() = 0; //!< extract the word at the current read position + virtual unsigned int getDword()= 0; //!< extract the dword at the current read position +}; + +class FilePtr; + +/*! @brief file based ::Chunk + + This class is an implementation of ::Chunk that handles file. + +*/ +class FileChunk : public Chunk { +private: + FilePtr * _data; + type _type; + unsigned int _size; + unsigned int _offset; + unsigned int _curPos; +protected: + FileChunk(); +public: + FileChunk(const char * fname); + virtual ~FileChunk(); + type getType() const; + unsigned int getSize() const; + Chunk * subBlock(); + bool eof() const; + unsigned int tell() const; + bool seek(int delta, seek_type dir = seek_cur); + bool read(void * buffer, unsigned int size); + char getChar(); + unsigned char getByte(); + short getShort(); + unsigned short getWord(); + unsigned int getDword(); +}; + +/*! @brief memory based ::Chunk + + This class is an implementation of ::Chunk that handles a memory buffer. +*/ +class ContChunk : public Chunk { +private: + char * _data; + Chunk::type _type; + unsigned int _size; + unsigned int _curPos; +public: + ContChunk(char * data); + Chunk::type getType() const; + unsigned int getSize() const; + Chunk * subBlock(); + bool eof() const; + unsigned int tell() const; + bool seek(int delta, seek_type dir = seek_cur); + bool read(void * buffer, unsigned int size); + char getChar(); + unsigned char getByte(); + short getShort(); + unsigned short getWord(); + unsigned int getDword(); +}; + +#endif diff --git a/scumm/smush/chunk_type.h b/scumm/smush/chunk_type.h new file mode 100644 index 0000000000..06e5d77415 --- /dev/null +++ b/scumm/smush/chunk_type.h @@ -0,0 +1,57 @@ +/* ScummVM - Scumm Interpreter + * Copyright (C) 2001/2002 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Header$ + * + */ + +#ifndef __CHUNK_TYPE_H +#define __CHUNK_TYPE_H + +#include "Chunk.h" + +#define MAKE_TYPE(a,b,c,d) (Chunk::type)( ((a) << 24) | ((b) << 16) | ((c) << 8) | (d) ) + +static const Chunk::type TYPE_ANIM = MAKE_TYPE('A', 'N', 'I', 'M'); +static const Chunk::type TYPE_AHDR = MAKE_TYPE('A', 'H', 'D', 'R'); +static const Chunk::type TYPE_FRME = MAKE_TYPE('F', 'R', 'M', 'E'); +static const Chunk::type TYPE_NPAL = MAKE_TYPE('N', 'P', 'A', 'L'); +static const Chunk::type TYPE_FOBJ = MAKE_TYPE('F', 'O', 'B', 'J'); +static const Chunk::type TYPE_PSAD = MAKE_TYPE('P', 'S', 'A', 'D'); +static const Chunk::type TYPE_TRES = MAKE_TYPE('T', 'R', 'E', 'S'); +static const Chunk::type TYPE_XPAL = MAKE_TYPE('X', 'P', 'A', 'L'); +static const Chunk::type TYPE_IACT = MAKE_TYPE('I', 'A', 'C', 'T'); +static const Chunk::type TYPE_STOR = MAKE_TYPE('S', 'T', 'O', 'R'); +static const Chunk::type TYPE_FTCH = MAKE_TYPE('F', 'T', 'C', 'H'); +static const Chunk::type TYPE_SKIP = MAKE_TYPE('S', 'K', 'I', 'P'); +static const Chunk::type TYPE_STRK = MAKE_TYPE('S', 'T', 'R', 'K'); +static const Chunk::type TYPE_SMRK = MAKE_TYPE('S', 'M', 'R', 'K'); +static const Chunk::type TYPE_SHDR = MAKE_TYPE('S', 'H', 'D', 'R'); +static const Chunk::type TYPE_SDAT = MAKE_TYPE('S', 'D', 'A', 'T'); +static const Chunk::type TYPE_SAUD = MAKE_TYPE('S', 'A', 'U', 'D'); +static const Chunk::type TYPE_iMUS = MAKE_TYPE('i', 'M', 'U', 'S'); +static const Chunk::type TYPE_FRMT = MAKE_TYPE('F', 'R', 'M', 'T'); +static const Chunk::type TYPE_TEXT = MAKE_TYPE('T', 'E', 'X', 'T'); +static const Chunk::type TYPE_REGN = MAKE_TYPE('R', 'E', 'G', 'N'); +static const Chunk::type TYPE_STOP = MAKE_TYPE('S', 'T', 'O', 'P'); +static const Chunk::type TYPE_MAP_ = MAKE_TYPE('M', 'A', 'P', ' '); +static const Chunk::type TYPE_DATA = MAKE_TYPE('D', 'A', 'T', 'A'); +static const Chunk::type TYPE_ETRS = MAKE_TYPE('E', 'T', 'R', 'S'); + +#undef MAKE_TYPE + +#endif diff --git a/scumm/smush/codec1.cpp b/scumm/smush/codec1.cpp index 495b50404f..857428d595 100644 --- a/scumm/smush/codec1.cpp +++ b/scumm/smush/codec1.cpp @@ -21,13 +21,13 @@ #include #include "codec1.h" -#include "chunck.h" +#include "chunk.h" #include "blitter.h" Codec1Decoder::~Codec1Decoder() { } -bool Codec1Decoder::decode(Blitter & dst, Chunck & src) { +bool Codec1Decoder::decode(Blitter & dst, Chunk & src) { int val; int size_line; int code, length; diff --git a/scumm/smush/codec1.h b/scumm/smush/codec1.h index ae60518d6a..2280da33ca 100644 --- a/scumm/smush/codec1.h +++ b/scumm/smush/codec1.h @@ -42,7 +42,7 @@ class Codec1Decoder : public Decoder { public: virtual ~Codec1Decoder(); - bool decode(Blitter &, Chunck &); + bool decode(Blitter &, Chunk &); }; #endif diff --git a/scumm/smush/codec37.cpp b/scumm/smush/codec37.cpp index 5adaa56d54..f8dd7f99a1 100644 --- a/scumm/smush/codec37.cpp +++ b/scumm/smush/codec37.cpp @@ -21,7 +21,7 @@ #include #include "codec37.h" -#include "chunck.h" +#include "chunk.h" #include "blitter.h" #include @@ -200,7 +200,7 @@ void Codec37Decoder::maketable(int pitch, int index) { } } -void Codec37Decoder::proc1(Blitter & dst, Chunck & src, int next_offs, int bw, int bh, int size) { +void Codec37Decoder::proc1(Blitter & dst, Chunk & src, int next_offs, int bw, int bh, int size) { unsigned char * decoded = new unsigned char[size]; int w = 0; while(!src.eof()) { @@ -234,7 +234,7 @@ void Codec37Decoder::proc1(Blitter & dst, Chunck & src, int next_offs, int bw, i delete []decoded; } -void Codec37Decoder::proc2(Blitter & dst, Chunck & src, int size) { // This is codec1 like... +void Codec37Decoder::proc2(Blitter & dst, Chunk & src, int size) { // This is codec1 like... #ifdef DEBUG_CODEC37_PROC2 int decoded_size = 0; int coded_size = 0; @@ -258,7 +258,7 @@ void Codec37Decoder::proc2(Blitter & dst, Chunck & src, int size) { // This is c } while (size); } -void Codec37Decoder::proc3WithFDFE(Blitter & dst, Chunck & src, int next_offs, int bw, int bh) { +void Codec37Decoder::proc3WithFDFE(Blitter & dst, Chunk & src, int next_offs, int bw, int bh) { do { int i = bw; do { @@ -293,7 +293,7 @@ void Codec37Decoder::proc3WithFDFE(Blitter & dst, Chunck & src, int next_offs, i } while (--bh); } -void Codec37Decoder::proc3WithoutFDFE(Blitter & dst, Chunck & src, int next_offs, int bw, int bh) { +void Codec37Decoder::proc3WithoutFDFE(Blitter & dst, Chunk & src, int next_offs, int bw, int bh) { do { int i = bw; do { @@ -316,7 +316,7 @@ void Codec37Decoder::proc3WithoutFDFE(Blitter & dst, Chunck & src, int next_offs } while (--bh); } -void Codec37Decoder::proc4(Blitter & dst, Chunck & src, int next_offs, int bw, int bh) { +void Codec37Decoder::proc4(Blitter & dst, Chunk & src, int next_offs, int bw, int bh) { #ifdef DEBUG_CODEC37_PROC4 int b_nb = 0; #endif @@ -371,7 +371,7 @@ void Codec37Decoder::proc4(Blitter & dst, Chunck & src, int next_offs, int bw, i } while (--bh); } -bool Codec37Decoder::decode(Blitter & dst, Chunck & src) { +bool Codec37Decoder::decode(Blitter & dst, Chunk & src) { int width = getRect().width(); int height = getRect().height(); int bw = (width + 3) >> 2, bh = (height + 3) >> 2; diff --git a/scumm/smush/codec37.h b/scumm/smush/codec37.h index 65fd7c1195..a98ec3985c 100644 --- a/scumm/smush/codec37.h +++ b/scumm/smush/codec37.h @@ -74,13 +74,13 @@ protected: return r | (r << 16); } void maketable(int, int); - void proc1(Blitter &, Chunck &, int, int, int, int); - void proc2(Blitter &, Chunck &, int); - void proc3WithFDFE(Blitter &, Chunck &, int, int, int); - void proc3WithoutFDFE(Blitter &, Chunck &, int, int, int); - void proc4(Blitter &, Chunck &, int, int, int); + void proc1(Blitter &, Chunk &, int, int, int, int); + void proc2(Blitter &, Chunk &, int); + void proc3WithFDFE(Blitter &, Chunk &, int, int, int); + void proc3WithoutFDFE(Blitter &, Chunk &, int, int, int); + void proc4(Blitter &, Chunk &, int, int, int); public: - bool decode(Blitter &, Chunck &); + bool decode(Blitter &, Chunk &); }; #endif diff --git a/scumm/smush/codec44.cpp b/scumm/smush/codec44.cpp index 9795842e76..be3ff533bb 100644 --- a/scumm/smush/codec44.cpp +++ b/scumm/smush/codec44.cpp @@ -21,10 +21,10 @@ #include #include "codec44.h" -#include "chunck.h" +#include "chunk.h" #include "blitter.h" -bool Codec44Decoder::decode(Blitter & dst, Chunck & src) { +bool Codec44Decoder::decode(Blitter & dst, Chunk & src) { int size_line; int num; int w, width = getRect().width() + 1; diff --git a/scumm/smush/codec44.h b/scumm/smush/codec44.h index a7c39b02fb..4b933c1fbb 100644 --- a/scumm/smush/codec44.h +++ b/scumm/smush/codec44.h @@ -41,7 +41,7 @@ */ class Codec44Decoder : public Decoder { public: - bool decode(Blitter & dst, Chunck & src); + bool decode(Blitter & dst, Chunk & src); }; #endif diff --git a/scumm/smush/codec47.cpp b/scumm/smush/codec47.cpp index 88038bb94d..92c0c14d3f 100644 --- a/scumm/smush/codec47.cpp +++ b/scumm/smush/codec47.cpp @@ -21,13 +21,13 @@ #include #include "codec47.h" -#include "chunck.h" +#include "chunk.h" #include "blitter.h" DumpDecoder::~DumpDecoder() { } -bool DumpDecoder::decode(Blitter & dst, Chunck & src) { +bool DumpDecoder::decode(Blitter & dst, Chunk & src) { int n = 0, i = 0; int seq = src.getWord(); int codec = src.getByte(); diff --git a/scumm/smush/codec47.h b/scumm/smush/codec47.h index ecf34f7e70..5d2df4d9b3 100644 --- a/scumm/smush/codec47.h +++ b/scumm/smush/codec47.h @@ -32,7 +32,7 @@ class DumpDecoder : public Decoder { public: virtual ~DumpDecoder(); - bool decode(Blitter &, Chunck &); + bool decode(Blitter &, Chunk &); }; #endif diff --git a/scumm/smush/color.h b/scumm/smush/color.h index 00c8978162..7ec7bafa93 100644 --- a/scumm/smush/color.h +++ b/scumm/smush/color.h @@ -19,18 +19,18 @@ * */ -#ifndef __COLOR_H_ -#define __COLOR_H_ +#ifndef __Chunk_H_ +#define __Chunk_H_ #include "config.h" -/*! @brief simple class for handling a color. +/*! @brief simple class for handling a Chunk. - This small class is an helper for colors. + This small class is an helper for Chunks. */ class Color { public: - typedef unsigned char value_type; //!< The type of the color components. + typedef unsigned char value_type; //!< The type of the Chunk components. private: value_type _r; //!< The red component. value_type _g; //!< The green component. @@ -47,7 +47,7 @@ public: /*! @brief handle delta palette modification This method is used specifically by player::handleDeltaPalette(). - It updates the color component using delta values given as short. + It updates the Chunk component using delta values given as short. @param ptr pointer to a table of 3 shorts that contain delta values to use. */ diff --git a/scumm/smush/decoder.h b/scumm/smush/decoder.h index a216d2b6b1..79a8dc7c98 100644 --- a/scumm/smush/decoder.h +++ b/scumm/smush/decoder.h @@ -27,7 +27,7 @@ #include "rect.h" class Blitter; -class Chunck; +class Chunk; /*! @brief base class for codec decompression. @@ -45,7 +45,7 @@ public: Decoder() {}; virtual ~Decoder() {}; virtual bool initSize(const Point & p, const Rect & r) { _p = p; _r = r; return true; }; - virtual bool decode(Blitter &, Chunck &) = 0; + virtual bool decode(Blitter &, Chunk &) = 0; }; #endif diff --git a/scumm/smush/frenderer.h b/scumm/smush/frenderer.h index 2ed9cd98cc..26c7d661ba 100644 --- a/scumm/smush/frenderer.h +++ b/scumm/smush/frenderer.h @@ -131,7 +131,7 @@ public: /*! @brief draw a centered and possibly using multiple lines string. This method performs calculation of the string size before choosing where to draw it. - As I still not have figured out exactly what is the meaning of the fields in the TRES chunck, + As I still not have figured out exactly what is the meaning of the fields in the TRES Chunk, the real meaning of the parameters can be quite difficult to understand. @remark The current implementation is incorrect in the sense that it does not conform to the original game. diff --git a/scumm/smush/imuse_channel.cpp b/scumm/smush/imuse_channel.cpp index f082407abd..43d17a60f4 100644 --- a/scumm/smush/imuse_channel.cpp +++ b/scumm/smush/imuse_channel.cpp @@ -21,8 +21,8 @@ #include #include "channel.h" -#include "chunck.h" -#include "chunck_type.h" +#include "chunk.h" +#include "chunk_type.h" #include #include // for memcpy.h @@ -63,12 +63,12 @@ bool ImuseChannel::checkParameters(int index, int nbframes, int size, int unk1, return true; } -bool ImuseChannel::appendData(Chunck & b, int size) { +bool ImuseChannel::appendData(Chunk & b, int size) { if(_dataSize == -1) { // First call assert(size > 8); - Chunck::type imus_type = b.getDword(); imus_type = TO_BE_32(imus_type); + Chunk::type imus_type = b.getDword(); imus_type = TO_BE_32(imus_type); unsigned int imus_size = b.getDword(); imus_size = TO_BE_32(imus_size); - if(imus_type != TYPE_iMUS) error("Invalid CHUNCK for imuse_channel"); + if(imus_type != TYPE_iMUS) error("Invalid Chunk for imuse_channel"); size -= 8; _tbufferSize = size; assert(_tbufferSize); @@ -96,8 +96,8 @@ bool ImuseChannel::appendData(Chunck & b, int size) { return processBuffer(); } -bool ImuseChannel::handleFormat(Chunck & src) { - if(src.getSize() != 20) error("invalid size for FRMT chunck"); +bool ImuseChannel::handleFormat(Chunk & src) { + if(src.getSize() != 20) error("invalid size for FRMT Chunk"); unsigned imuse_start = src.getDword(); imuse_start = TO_BE_32(imuse_start); src.seek(4); @@ -111,23 +111,23 @@ bool ImuseChannel::handleFormat(Chunck & src) { return true; } -bool ImuseChannel::handleText(Chunck & src) { +bool ImuseChannel::handleText(Chunk & src) { return true; } -bool ImuseChannel::handleRegion(Chunck & src) { - if(src.getSize() != 8) error("invalid size for REGN chunck"); +bool ImuseChannel::handleRegion(Chunk & src) { + if(src.getSize() != 8) error("invalid size for REGN Chunk"); return true; } -bool ImuseChannel::handleStop(Chunck & src) { - if(src.getSize() != 4) error("invalid size for STOP chunck"); +bool ImuseChannel::handleStop(Chunk & src) { + if(src.getSize() != 4) error("invalid size for STOP Chunk"); return true; } -bool ImuseChannel::handleMap(Chunck & map) { +bool ImuseChannel::handleMap(Chunk & map) { while(!map.eof()) { - Chunck * sub = map.subBlock(); + Chunk * sub = map.subBlock(); switch(sub->getType()) { case TYPE_FRMT: handleFormat(*sub); @@ -142,7 +142,7 @@ bool ImuseChannel::handleMap(Chunck & map) { handleStop(*sub); break; default: - error("Unknown iMUS subchunck found : %s, %d", Chunck::ChunckString(sub->getType()), sub->getSize()); + error("Unknown iMUS subChunk found : %s, %d", Chunk::ChunkString(sub->getType()), sub->getSize()); } delete sub; } @@ -195,13 +195,13 @@ void ImuseChannel::decode() { bool ImuseChannel::handleSubTags(int & offset) { int available_size = _tbufferSize - offset; if(available_size >= 8) { - Chunck::type type = READ_BE_UINT32(_tbuffer + offset); + Chunk::type type = READ_BE_UINT32(_tbuffer + offset); unsigned int size = READ_BE_UINT32(_tbuffer + offset + 4); switch(type) { case TYPE_MAP_: _inData = false; if(available_size >= (size + 8)) { - ContChunck c((char*)_tbuffer + offset); + ContChunk c((char*)_tbuffer + offset); handleMap(c); } break; @@ -225,7 +225,7 @@ bool ImuseChannel::handleSubTags(int & offset) { } return false; default: - error("unknown chunck in iMUS track : %s ", Chunck::ChunckString(type)); + error("unknown Chunk in iMUS track : %s ", Chunk::ChunkString(type)); } offset += size + 8; return true; diff --git a/scumm/smush/player.cpp b/scumm/smush/player.cpp index 5362f5be9a..4cce9e00fa 100644 --- a/scumm/smush/player.cpp +++ b/scumm/smush/player.cpp @@ -24,7 +24,7 @@ #include "renderer.h" #include "channel.h" -#include "chunck_type.h" +#include "Chunk_type.h" #include "rect.h" #include "blitter.h" @@ -209,16 +209,16 @@ void SmushPlayer::clean() { if(_fr[3]) delete _fr[3]; } -void SmushPlayer::checkBlock(const Chunck & b, Chunck::type type_expected, unsigned int min_size) { +void SmushPlayer::checkBlock(const Chunk & b, Chunk::type type_expected, unsigned int min_size) { if(type_expected != b.getType()) { - error("chunck type is different from expected : %d != %d", b.getType(), type_expected); + error("Chunk type is different from expected : %d != %d", b.getType(), type_expected); } if(min_size > b.getSize()) { - error( "chunck size is inferior than minimum required size : %d < %d", b.getSize(), min_size); + error( "Chunk size is inferior than minimum required size : %d < %d", b.getSize(), min_size); } } -void SmushPlayer::handleSoundBuffer(int track_id, int index, int max_frames, int flags, int vol, int bal, Chunck & b, int size) { +void SmushPlayer::handleSoundBuffer(int track_id, int index, int max_frames, int flags, int vol, int bal, Chunk & b, int size) { debug(6, "smush_player::handleSoundBuffer(%d)", track_id); if(!_voices && (flags & 128) == 128) return; if(!_bgmusic && (flags & 64) == 64) return; @@ -234,7 +234,7 @@ void SmushPlayer::handleSoundBuffer(int track_id, int index, int max_frames, int c->appendData(b, size); } -void SmushPlayer::handleSoundFrame(Chunck & b) { +void SmushPlayer::handleSoundFrame(Chunk & b) { checkBlock(b, TYPE_PSAD); debug(6, "SmushPlayer::handleSoundFrame()"); if(!_outputSound) return; @@ -253,7 +253,7 @@ void SmushPlayer::handleSoundFrame(Chunck & b) { handleSoundBuffer(track_id, index, max_frames, flags, vol, bal, b, size); } -void SmushPlayer::handleSkip(Chunck & b) { +void SmushPlayer::handleSkip(Chunk & b) { checkBlock(b, TYPE_SKIP, 4); int code = b.getDword(); debug(6, "SmushPlayer::handleSkip(%d)", code); @@ -263,17 +263,17 @@ void SmushPlayer::handleSkip(Chunck & b) { _skipNext =true; } -void SmushPlayer::handleStore(Chunck & b) { +void SmushPlayer::handleStore(Chunk & b) { checkBlock(b, TYPE_STOR, 4); debug(6, "SmushPlayer::handleStore()"); } -void SmushPlayer::handleFetch(Chunck & b) { +void SmushPlayer::handleFetch(Chunk & b) { checkBlock(b, TYPE_FTCH, 6); debug(6, "SmushPlayer::handleFetch()"); } -void SmushPlayer::handleImuseBuffer(int track_id, int index, int nbframes, int size, int unk1, int unk2, Chunck & b, int bsize) { +void SmushPlayer::handleImuseBuffer(int track_id, int index, int nbframes, int size, int unk1, int unk2, Chunk & b, int bsize) { _Channel * c = _mixer->findChannel(track_id); if(c == 0) { c = new ImuseChannel(track_id, _soundFrequency); @@ -286,7 +286,7 @@ void SmushPlayer::handleImuseBuffer(int track_id, int index, int nbframes, int s c->appendData(b, bsize); } -void SmushPlayer::handleImuseAction8(Chunck & b, int flags, int unknown, int track_id) { +void SmushPlayer::handleImuseAction8(Chunk & b, int flags, int unknown, int track_id) { assert(flags == 46 && unknown == 0); int unknown2 = b.getWord(); track_id |= unknown2 << 16; @@ -297,7 +297,7 @@ void SmushPlayer::handleImuseAction8(Chunck & b, int flags, int unknown, int tra handleImuseBuffer(track_id, index, nbframes, size, unknown, unknown2, b, bsize); } -void SmushPlayer::handleImuseAction(Chunck & b) { +void SmushPlayer::handleImuseAction(Chunk & b) { checkBlock(b, TYPE_IACT, 8); debug(6, "SmushPlayer::handleImuseAction()"); if(!_outputSound) return; @@ -320,7 +320,7 @@ void SmushPlayer::handleImuseAction(Chunck & b) { } } -void SmushPlayer::handleTextResource(Chunck & b) { +void SmushPlayer::handleTextResource(Chunk & b) { checkBlock(b, TYPE_TRES, 18); int pos_x = b.getShort(); int pos_y = b.getShort(); @@ -375,13 +375,13 @@ void SmushPlayer::handleTextResource(Chunck & b) { } } -void SmushPlayer::readPalette(Palette & out, Chunck & in) { +void SmushPlayer::readPalette(Palette & out, Chunk & in) { unsigned char buffer[768]; in.read(buffer, 768); out = Palette(buffer); } -void SmushPlayer::handleDeltaPalette(Chunck & b) { +void SmushPlayer::handleDeltaPalette(Chunk & b) { checkBlock(b, TYPE_XPAL); debug(6, "SmushPlayer::handleDeltaPalette()"); if(b.getSize() == 768 * 3 + 4) { @@ -407,14 +407,14 @@ void SmushPlayer::handleDeltaPalette(Chunck & b) { } } -void SmushPlayer::handleNewPalette(Chunck & b) { +void SmushPlayer::handleNewPalette(Chunk & b) { checkBlock(b, TYPE_NPAL, 768); debug(6, "SmushPlayer::handleNewPalette()"); readPalette(_pal, b); updatePalette(); } -void SmushPlayer::decodeCodec(Chunck & b, const Rect & r, Decoder & codec) { +void SmushPlayer::decodeCodec(Chunk & b, const Rect & r, Decoder & codec) { assert(_curBuffer); Blitter blit(_curBuffer, _frameSize, r); codec.decode(blit, b); @@ -449,7 +449,7 @@ void SmushPlayer::initSize(const Rect & r, bool always, bool transparent) { _alreadyInit = true; } -void SmushPlayer::handleFrameObject(Chunck & b) { +void SmushPlayer::handleFrameObject(Chunk & b) { checkBlock(b, TYPE_FOBJ, 14); if(_skipNext) { _skipNext = false; @@ -496,14 +496,14 @@ void SmushPlayer::handleFrameObject(Chunck & b) { } } -void SmushPlayer::handleFrame(Chunck & b) { +void SmushPlayer::handleFrame(Chunk & b) { checkBlock(b, TYPE_FRME); debug(6, "SmushPlayer::handleFrame(%d)", _frame); _alreadyInit = false; _skipNext = false; while(!b.eof()) { - Chunck * sub = b.subBlock(); + Chunk * sub = b.subBlock(); if(sub->getSize() & 1) b.seek(1); switch(sub->getType()) { case TYPE_NPAL: @@ -534,7 +534,7 @@ void SmushPlayer::handleFrame(Chunck & b) { handleSkip(*sub); break; default: - error("Unknown frame subchunck found : %s, %d", Chunck::ChunckString(sub->getType()), sub->getSize()); + error("Unknown frame subChunk found : %s, %d", Chunk::ChunkString(sub->getType()), sub->getSize()); } delete sub; } @@ -553,7 +553,7 @@ void SmushPlayer::handleFrame(Chunck & b) { _frame++; } -void SmushPlayer::handleAnimHeader(Chunck & b) { +void SmushPlayer::handleAnimHeader(Chunk & b) { checkBlock(b, TYPE_AHDR, 774); debug(6, "SmushPlayer::handleAnimHeader()"); _version = b.getWord(); @@ -619,7 +619,7 @@ static StringResource * getStrings(const char * file, bool is_encoded) { if(is_encoded) { static const int ETRS_HEADER_LENGTH = 16; assert(length > ETRS_HEADER_LENGTH); - Chunck::type type = READ_BE_UINT32(filebuffer); + Chunk::type type = READ_BE_UINT32(filebuffer); if(type != TYPE_ETRS) error("invalid type for file"); // mem leak !!! char * old = filebuffer; filebuffer = new char[length - ETRS_HEADER_LENGTH]; @@ -730,12 +730,12 @@ bool SmushPlayer::play(const char * file) { } } } - FileChunck base = FileChunck(file); + FileChunk base = FileChunk(file); checkBlock(base, TYPE_ANIM); while(!base.eof()) { - Chunck * sub = base.subBlock(); + Chunk * sub = base.subBlock(); switch(sub->getType()) { case TYPE_AHDR: handleAnimHeader(*sub); @@ -744,7 +744,7 @@ bool SmushPlayer::play(const char * file) { handleFrame(*sub); break; default: - error("Unknown chunck found : %d, %d", sub->getType(), sub->getSize()); + error("Unknown Chunk found : %d, %d", sub->getType(), sub->getSize()); } delete sub; if(_renderer->prematureClose()) diff --git a/scumm/smush/player.h b/scumm/smush/player.h index ceb58eaee2..1221fb6c6b 100644 --- a/scumm/smush/player.h +++ b/scumm/smush/player.h @@ -26,7 +26,7 @@ #include "rect.h" #include "mixer.h" -#include "chunck.h" +#include "chunk.h" #include "palette.h" #include "codec1.h" #include "codec37.h" @@ -81,23 +81,23 @@ public: protected: bool readString(const char * file, bool &); void clean(); - void checkBlock(const Chunck &, Chunck::type, unsigned int = 0); - void handleAnimHeader(Chunck &); - void handleFrame(Chunck &); - void handleNewPalette(Chunck &); - void handleFrameObject(Chunck &); - void handleSoundBuffer(int, int, int, int, int, int, Chunck &, int); - void handleImuseBuffer(int, int, int, int, int, int, Chunck &, int); - void handleSoundFrame(Chunck &); - void handleSkip(Chunck &); - void handleStore(Chunck &); - void handleFetch(Chunck &); - void handleImuseAction8(Chunck &, int flags, int unknown, int track_id); - void handleImuseAction(Chunck &); - void handleTextResource(Chunck &); - void handleDeltaPalette(Chunck &); - void decodeCodec(Chunck &, const Rect &, Decoder &); - void readPalette(Palette &, Chunck &); + void checkBlock(const Chunk &, Chunk::type, unsigned int = 0); + void handleAnimHeader(Chunk &); + void handleFrame(Chunk &); + void handleNewPalette(Chunk &); + void handleFrameObject(Chunk &); + void handleSoundBuffer(int, int, int, int, int, int, Chunk &, int); + void handleImuseBuffer(int, int, int, int, int, int, Chunk &, int); + void handleSoundFrame(Chunk &); + void handleSkip(Chunk &); + void handleStore(Chunk &); + void handleFetch(Chunk &); + void handleImuseAction8(Chunk &, int flags, int unknown, int track_id); + void handleImuseAction(Chunk &); + void handleTextResource(Chunk &); + void handleDeltaPalette(Chunk &); + void decodeCodec(Chunk &, const Rect &, Decoder &); + void readPalette(Palette &, Chunk &); void initSize(const Rect &, bool, bool); }; diff --git a/scumm/smush/saud_channel.cpp b/scumm/smush/saud_channel.cpp index 8fd584b659..8e5480c3a1 100644 --- a/scumm/smush/saud_channel.cpp +++ b/scumm/smush/saud_channel.cpp @@ -21,8 +21,8 @@ #include #include "channel.h" -#include "chunck.h" -#include "chunck_type.h" +#include "chunk.h" +#include "chunk_type.h" #include #include // for memcpy.h @@ -30,18 +30,18 @@ #define min(x, y) ((x) > (y) ? (y) : (x)) #endif -void SaudChannel::handleStrk(Chunck & b) { +void SaudChannel::handleStrk(Chunk & b) { int size = b.getSize(); if(size != 14 && size != 10) { error("STRK has a invalid size : %d", size); } } -void SaudChannel::handleSmrk(Chunck & b) { +void SaudChannel::handleSmrk(Chunk & b) { _markReached = true; } -void SaudChannel::handleShdr(Chunck & b) { +void SaudChannel::handleShdr(Chunk & b) { int size = b.getSize(); if(size != 4) warning("SMRK has a invalid size : %d", size); } @@ -49,14 +49,14 @@ void SaudChannel::handleShdr(Chunck & b) { bool SaudChannel::handleSubTags(int & offset) { int available_size = _tbufferSize - offset; if(available_size >= 8) { - Chunck::type type = READ_BE_UINT32(_tbuffer + offset); + Chunk::type type = READ_BE_UINT32(_tbuffer + offset); unsigned int size = READ_BE_UINT32(_tbuffer + offset + 4); switch(type) { case TYPE_STRK: _inData = false; if(available_size >= (size + 8)) { - ContChunck c((char*)_tbuffer + offset); + ContChunk c((char*)_tbuffer + offset); handleStrk(c); } else @@ -65,7 +65,7 @@ bool SaudChannel::handleSubTags(int & offset) { case TYPE_SMRK: _inData = false; if(available_size >= (size + 8)) { - ContChunck c((char*)_tbuffer + offset); + ContChunk c((char*)_tbuffer + offset); handleSmrk(c); } else @@ -74,7 +74,7 @@ bool SaudChannel::handleSubTags(int & offset) { case TYPE_SHDR: _inData = false; if(available_size >= (size + 8)) { - ContChunck c((char*)_tbuffer + offset); + ContChunk c((char*)_tbuffer + offset); handleShdr(c); } else @@ -86,7 +86,7 @@ bool SaudChannel::handleSubTags(int & offset) { offset += 8; return false; default: - error("unknown chunck in SAUD track : %s ", Chunck::ChunckString(type)); + error("unknown Chunk in SAUD track : %s ", Chunk::ChunkString(type)); } offset += size + 8; return true; @@ -232,12 +232,12 @@ bool SaudChannel::checkParameters(int index, int nb, int flags, int volume, int return true; } -bool SaudChannel::appendData(Chunck & b, int size) { +bool SaudChannel::appendData(Chunk & b, int size) { if(_dataSize == -1) { // First call assert(size > 8); - Chunck::type saud_type = b.getDword(); saud_type = TO_BE_32(saud_type); + Chunk::type saud_type = b.getDword(); saud_type = TO_BE_32(saud_type); unsigned int saud_size = b.getDword(); saud_size = TO_BE_32(saud_size); - if(saud_type != TYPE_SAUD) error("Invalid CHUNCK for SaudChannel : %X", saud_type); + if(saud_type != TYPE_SAUD) error("Invalid Chunk for SaudChannel : %X", saud_type); size -= 8; _dataSize = -2; // We don't get here again... } -- cgit v1.2.3