[Scummvm-cvs-logs] SF.net SVN: scummvm:[40755] scummvm/trunk
thebluegr at users.sourceforge.net
thebluegr at users.sourceforge.net
Thu May 21 12:48:03 CEST 2009
Revision: 40755
http://scummvm.svn.sourceforge.net/scummvm/?rev=40755&view=rev
Author: thebluegr
Date: 2009-05-21 10:48:03 +0000 (Thu, 21 May 2009)
Log Message:
-----------
Moved the Coktel video player into its own subdirectory
Modified Paths:
--------------
scummvm/trunk/engines/gob/videoplayer.h
scummvm/trunk/graphics/module.mk
Added Paths:
-----------
scummvm/trunk/graphics/video/coktelvideo/
scummvm/trunk/graphics/video/coktelvideo/coktelvideo.cpp
scummvm/trunk/graphics/video/coktelvideo/coktelvideo.h
scummvm/trunk/graphics/video/coktelvideo/indeo3.cpp
scummvm/trunk/graphics/video/coktelvideo/indeo3.h
scummvm/trunk/graphics/video/coktelvideo/indeo3data.h
Removed Paths:
-------------
scummvm/trunk/graphics/video/coktelvideo.cpp
scummvm/trunk/graphics/video/coktelvideo.h
scummvm/trunk/graphics/video/indeo3.cpp
scummvm/trunk/graphics/video/indeo3.h
scummvm/trunk/graphics/video/indeo3data.h
Modified: scummvm/trunk/engines/gob/videoplayer.h
===================================================================
--- scummvm/trunk/engines/gob/videoplayer.h 2009-05-21 10:34:13 UTC (rev 40754)
+++ scummvm/trunk/engines/gob/videoplayer.h 2009-05-21 10:48:03 UTC (rev 40755)
@@ -28,7 +28,7 @@
#include "common/array.h"
-#include "graphics/video/coktelvideo.h"
+#include "graphics/video/coktelvideo/coktelvideo.h"
#include "gob/dataio.h"
Modified: scummvm/trunk/graphics/module.mk
===================================================================
--- scummvm/trunk/graphics/module.mk 2009-05-21 10:34:13 UTC (rev 40754)
+++ scummvm/trunk/graphics/module.mk 2009-05-21 10:48:03 UTC (rev 40755)
@@ -23,8 +23,8 @@
video/mpeg_player.o \
video/smk_player.o \
video/video_player.o \
- video/indeo3.o \
- video/coktelvideo.o
+ video/coktelvideo/indeo3.o \
+ video/coktelvideo/coktelvideo.o
ifndef DISABLE_SCALERS
MODULE_OBJS += \
Copied: scummvm/trunk/graphics/video/coktelvideo/coktelvideo.cpp (from rev 40752, scummvm/trunk/graphics/video/coktelvideo.cpp)
===================================================================
--- scummvm/trunk/graphics/video/coktelvideo/coktelvideo.cpp (rev 0)
+++ scummvm/trunk/graphics/video/coktelvideo/coktelvideo.cpp 2009-05-21 10:48:03 UTC (rev 40755)
@@ -0,0 +1,1837 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#include "common/endian.h"
+#include "common/system.h"
+
+#include "graphics/dither.h"
+#include "graphics/video/coktelvideo/coktelvideo.h"
+#include "graphics/video/coktelvideo/indeo3.h"
+
+namespace Graphics {
+
+Imd::Imd() {
+ clear(false);
+}
+
+Imd::~Imd() {
+ clear();
+}
+
+bool Imd::load(Common::SeekableReadStream &stream) {
+ unload();
+
+ _stream = &stream;
+
+ // Version
+ uint16 handle = _stream->readUint16LE();
+ _version = _stream->readByte();
+
+ // Version checking
+ if ((handle != 0) || (_version < 2)) {
+ warning("IMD Version incorrect (%d,%X)", handle, _version);
+ unload();
+ return false;
+ }
+
+ // Rest header
+ _features = _stream->readByte();
+ _framesCount = _stream->readUint16LE();
+ _x = _stream->readSint16LE();
+ _y = _stream->readSint16LE();
+ _width = _stream->readSint16LE();
+ _height = _stream->readSint16LE();
+ _flags = _stream->readUint16LE();
+ _firstFramePos = _stream->readUint16LE();
+
+ // IMDs always have video
+ _features |= kFeaturesVideo;
+ // IMDs always have palettes
+ _features |= kFeaturesPalette;
+
+ // Palette
+ _stream->read((byte *) _palette, 768);
+
+ // Standard coordinates
+ if (_version >= 3) {
+ _stdX = _stream->readUint16LE();
+ if (_stdX > 1) {
+ warning("IMD: More than one standard coordinate quad found (%d)", _stdX);
+ unload();
+ return false;
+ }
+ if (_stdX != 0) {
+ _stdX = _stream->readSint16LE();
+ _stdY = _stream->readSint16LE();
+ _stdWidth = _stream->readSint16LE();
+ _stdHeight = _stream->readSint16LE();
+ _features |= kFeaturesStdCoords;
+ } else
+ _stdX = -1;
+ } else
+ _stdX = -1;
+
+ // Offset to frame positions table
+ uint32 framesPosPos = 0;
+ if (_version >= 4) {
+ framesPosPos = _stream->readUint32LE();
+ if (framesPosPos != 0) {
+ _framesPos = new uint32[_framesCount];
+ assert(_framesPos);
+ _features |= kFeaturesFramesPos;
+ }
+ }
+
+ // Offset to frame coordinates
+ uint32 framesCoordsPos = 0;
+ if (_features & kFeaturesFrameCoords)
+ framesCoordsPos = _stream->readUint32LE();
+
+ // Sound
+ if (_features & kFeaturesSound) {
+ _soundFreq = _stream->readSint16LE();
+ _soundSliceSize = _stream->readSint16LE();
+ _soundSlicesCount = _stream->readSint16LE();
+
+ if (_soundFreq < 0)
+ _soundFreq = -_soundFreq;
+
+ if (_soundSlicesCount < 0)
+ _soundSlicesCount = -_soundSlicesCount - 1;
+
+ if (_soundSlicesCount > 40) {
+ warning("IMD: More than 40 sound slices found (%d)", _soundSlicesCount);
+ unload();
+ return false;
+ }
+
+ _soundSliceLength = (uint32) (((double) (1000 << 16)) /
+ ((double) _soundFreq / (double) _soundSliceSize));
+ _frameLength = _soundSliceLength >> 16;
+
+ _soundStage = 1;
+ _hasSound = true;
+
+ _audioStream = Audio::makeAppendableAudioStream(_soundFreq, 0);
+ } else
+ _frameLength = 1000 / _frameRate;
+
+ // Sizes of the frame data and extra video buffer
+ if (_features & kFeaturesDataSize) {
+ _frameDataSize = _stream->readUint16LE();
+ if (_frameDataSize == 0) {
+ _frameDataSize = _stream->readUint32LE();
+ _vidBufferSize = _stream->readUint32LE();
+ } else
+ _vidBufferSize = _stream->readUint16LE();
+ } else {
+ _frameDataSize = _width * _height + 500;
+ if (!(_flags & 0x100) || (_flags & 0x1000))
+ _vidBufferSize = _frameDataSize;
+ }
+
+ // Frame positions table
+ if (_framesPos) {
+ _stream->seek(framesPosPos, SEEK_SET);
+ for (int i = 0; i < _framesCount; i++)
+ _framesPos[i] = _stream->readUint32LE();
+ }
+
+ // Frame coordinates table
+ if (_features & kFeaturesFrameCoords) {
+ _stream->seek(framesCoordsPos, SEEK_SET);
+ _frameCoords = new Coord[_framesCount];
+ assert(_frameCoords);
+ for (int i = 0; i < _framesCount; i++) {
+ _frameCoords[i].left = _stream->readSint16LE();
+ _frameCoords[i].top = _stream->readSint16LE();
+ _frameCoords[i].right = _stream->readSint16LE();
+ _frameCoords[i].bottom = _stream->readSint16LE();
+ }
+ }
+
+ // Seek to the first frame
+ _stream->seek(_firstFramePos, SEEK_SET);
+
+ // Allocating working memory
+ _frameData = new byte[_frameDataSize + 500];
+ assert(_frameData);
+ memset(_frameData, 0, _frameDataSize + 500);
+ _vidBuffer = new byte[_vidBufferSize + 500];
+ assert(_vidBuffer);
+ memset(_vidBuffer, 0, _vidBufferSize + 500);
+
+ return true;
+}
+
+void Imd::unload() {
+ clear();
+}
+
+void Imd::setFrameRate(int16 frameRate) {
+ if (frameRate == 0)
+ frameRate = 1;
+
+ _frameRate = frameRate;
+ _frameLength = 1000 / _frameRate;
+}
+
+void Imd::setXY(int16 x, int16 y) {
+ // Adjusting the standard coordinates
+ if (_stdX != -1) {
+ if (x >= 0)
+ _stdX = _stdX - _x + x;
+ if (y >= 0)
+ _stdY = _stdY - _y + y;
+ }
+
+ // Going through the coordinate table as well
+ if (_frameCoords) {
+ for (int i = 0; i < _framesCount; i++) {
+ if (_frameCoords[i].left != -1) {
+ if (x >= 0) {
+ _frameCoords[i].left = _frameCoords[i].left - _x + x;
+ _frameCoords[i].right = _frameCoords[i].right - _x + x;
+ }
+ if (y >= 0) {
+ _frameCoords[i].top = _frameCoords[i].top - _y + y;
+ _frameCoords[i].bottom = _frameCoords[i].bottom - _y + y;
+ }
+ }
+ }
+ }
+
+ if (x >= 0)
+ _x = x;
+ if (y >= 0)
+ _y = y;
+}
+
+void Imd::setVideoMemory(byte *vidMem, uint16 width, uint16 height) {
+ deleteVidMem();
+
+ _hasOwnVidMem = false;
+ _vidMem = vidMem;
+ _vidMemWidth = width;
+ _vidMemHeight = height;
+}
+
+void Imd::setVideoMemory() {
+ deleteVidMem();
+
+ if ((_width > 0) && (_height > 0)) {
+ setXY(0, 0);
+ _hasOwnVidMem = true;
+ _vidMem = new byte[_width * _height];
+ _vidMemWidth = _width;
+ _vidMemHeight = _height;
+ }
+}
+
+void Imd::enableSound(Audio::Mixer &mixer) {
+ // Only possible on the first frame
+ if (_curFrame > 0)
+ return;
+
+ _mixer = &mixer;
+ _soundEnabled = true;
+}
+
+void Imd::disableSound() {
+ if (_audioStream) {
+
+ if (_soundStage == 2) {
+ _audioStream->finish();
+ _mixer->stopHandle(_audioHandle);
+ } else
+ delete _audioStream;
+
+ _audioStream = 0;
+ _soundStage = 0;
+ }
+ _soundEnabled = false;
+ _mixer = 0;
+}
+
+bool Imd::isSoundPlaying() const {
+ if (_audioStream && _mixer->isSoundHandleActive(_audioHandle))
+ return true;
+
+ return false;
+}
+
+void Imd::seekFrame(int32 frame, int16 whence, bool restart) {
+ if (!_stream)
+ // Nothing to do
+ return;
+
+ // Find the frame to which to seek
+ if (whence == SEEK_CUR)
+ frame += _curFrame;
+ else if (whence == SEEK_END)
+ frame = _framesCount - frame - 1;
+ else if (whence != SEEK_SET)
+ return;
+
+ if ((frame < 0) || (frame >= _framesCount) || (frame == _curFrame))
+ // Nothing to do
+ return;
+
+ // Try every possible way to find a file offset to that frame
+ uint32 framePos = 0;
+ if (frame == 0) {
+ framePos = _firstFramePos;
+ } else if (frame == 1) {
+ framePos = _firstFramePos;
+ _stream->seek(framePos, SEEK_SET);
+ framePos += _stream->readUint16LE() + 4;
+ } else if (_framesPos) {
+ framePos = _framesPos[frame];
+ } else if (restart && (_soundStage == 0)) {
+ for (int i = ((frame > _curFrame) ? _curFrame : 0); i <= frame; i++)
+ processFrame(i);
+ } else
+ error("Frame %d is not directly accessible", frame);
+
+ // Seek
+ _stream->seek(framePos);
+ _curFrame = frame;
+}
+
+CoktelVideo::State Imd::nextFrame() {
+ return processFrame(_curFrame);
+}
+
+void Imd::waitEndFrame() {
+ if (_soundEnabled && _hasSound) {
+ if (_soundStage != 2)
+ return;
+
+ if (_skipFrames == 0) {
+ int32 waitTime = (int16) (((_curFrame * _soundSliceLength) -
+ (_mixer->getSoundElapsedTime(_audioHandle) << 16)) >> 16);
+
+ if (waitTime < 0) {
+ _skipFrames = -waitTime / (_soundSliceLength >> 16);
+ warning("Video A/V sync broken, skipping %d frame(s)", _skipFrames + 1);
+ } else if (waitTime > 0)
+ g_system->delayMillis(waitTime);
+
+ } else
+ _skipFrames--;
+ } else
+ g_system->delayMillis(_frameLength);
+}
+
+void Imd::copyCurrentFrame(byte *dest,
+ uint16 left, uint16 top, uint16 width, uint16 height,
+ uint16 x, uint16 y, uint16 pitch, int16 transp) {
+
+ if (!_vidMem)
+ return;
+
+ if (((left + width) > _width) || ((top + height) > _height))
+ return;
+
+ dest += pitch * y;
+ byte *vidMem = _vidMem + _width * top;
+
+ if (transp < 0) {
+ // No transparency
+ if ((x > 0) || (left > 0) || (pitch != _width) || (width != _width)) {
+ // Copy row-by-row
+ for (int i = 0; i < height; i++) {
+ byte *d = dest + x;
+ byte *s = vidMem + left;
+
+ memcpy(d, s, width);
+
+ dest += pitch;
+ vidMem += _width;
+ }
+ } else
+ // Dimensions fit, copy everything at once
+ memcpy(dest, vidMem, width * height);
+
+ return;
+ }
+
+ for (int i = 0; i < height; i++) {
+ byte *d = dest + x;
+ byte *s = vidMem + left;
+
+ for (int j = 0; j < width; j++) {
+ if (*s != transp)
+ *d = *s;
+
+ s++;
+ d++;
+ }
+
+ dest += pitch;
+ vidMem += _width;
+ }
+
+}
+
+void Imd::deleteVidMem(bool del) {
+ if (del) {
+ if (_hasOwnVidMem)
+ delete[] _vidMem;
+ }
+
+ _hasOwnVidMem = false;
+ _vidMem = 0;
+ _vidMemWidth = _vidMemHeight = 0;
+}
+
+void Imd::clear(bool del) {
+ if (del) {
+ delete[] _framesPos;
+ delete[] _frameCoords;
+ delete[] _frameData;
+ delete[] _vidBuffer;
+
+ disableSound();
+ }
+
+ _stream = 0;
+
+ _version = 0;
+ _features = 0;
+ _flags = 0;
+ _x = _y = _width = _height = 0;
+ _stdX = _stdY = _stdWidth = _stdHeight = 0;
+ _framesCount = _curFrame = 0;
+ _framesPos = 0;
+ _firstFramePos = 0;
+ _frameCoords = 0;
+
+ _frameDataSize = _vidBufferSize = 0;
+ _frameData = _vidBuffer = 0;
+ _frameDataLen = 0;
+
+ memset(_palette, 0, 768);
+
+ deleteVidMem(del);
+
+ _hasSound = false;
+ _soundEnabled = false;
+ _soundStage = 0;
+ _skipFrames = 0;
+
+ _soundFlags = 0;
+ _soundFreq = 0;
+ _soundSliceSize = 0;
+ _soundSlicesCount = 0;
+ _soundSliceLength = 0;
+
+ _audioStream = 0;
+
+ _frameRate = 12;
+ _frameLength = 0;
+ _lastFrameTime = 0;
+}
+
+CoktelVideo::State Imd::processFrame(uint16 frame) {
+ State state;
+ uint32 cmd = 0;
+ bool hasNextCmd = false;
+ bool startSound = false;
+
+ if (!_stream || (frame >= _framesCount)) {
+ state.flags = kStateBreak;
+ return state;
+ }
+
+ if (frame != _curFrame) {
+ state.flags |= kStateSeeked;
+ seekFrame(frame);
+ }
+
+ if (!_vidMem)
+ setVideoMemory();
+
+ state.left = _x;
+ state.top = _y;
+ state.right = _width + state.left - 1;
+ state.bottom = _height + state.top - 1;
+
+ do {
+ if (frame != 0) {
+ if (_stdX != -1) {
+ state.left = _stdX;
+ state.top = _stdY;
+ state.right = _stdWidth + state.left - 1;
+ state.bottom = _stdHeight + state.top - 1;
+ state.flags |= kStateStdCoords;
+ }
+ if (_frameCoords &&
+ (_frameCoords[frame].left != -1)) {
+ state.left = _frameCoords[frame].left;
+ state.top = _frameCoords[frame].top;
+ state.right = _frameCoords[frame].right;
+ state.bottom = _frameCoords[frame].bottom;
+ state.flags |= kStateFrameCoords;
+ }
+ }
+
+ cmd = _stream->readUint16LE();
+
+ if ((cmd & 0xFFF8) == 0xFFF0) {
+ if (cmd == 0xFFF0) {
+ _stream->seek(2, SEEK_CUR);
+ cmd = _stream->readUint16LE();
+ }
+
+ if (cmd == 0xFFF1) {
+ state.flags = kStateBreak;
+ continue;
+ } else if (cmd == 0xFFF2) { // Skip (16 bit)
+ cmd = _stream->readUint16LE();
+ _stream->seek(cmd, SEEK_CUR);
+ state.flags = kStateBreak;
+ continue;
+ } else if (cmd == 0xFFF3) { // Skip (32 bit)
+ cmd = _stream->readUint32LE();
+ _stream->seek(cmd, SEEK_CUR);
+ state.flags = kStateBreak;
+ continue;
+ }
+ }
+
+ if (_soundStage != 0) {
+ byte *soundBuf;
+
+ // Next sound slice data
+ if (cmd == 0xFF00) {
+
+ if (!hasNextCmd && _soundEnabled) {
+ soundBuf = new byte[_soundSliceSize];
+ assert(soundBuf);
+
+ _stream->read(soundBuf, _soundSliceSize);
+ unsignedToSigned(soundBuf, _soundSliceSize);
+ _audioStream->queueBuffer(soundBuf, _soundSliceSize);
+ } else
+ _stream->seek(_soundSliceSize, SEEK_CUR);
+
+ cmd = _stream->readUint16LE();
+
+ // Initial sound data (all slices)
+ } else if (cmd == 0xFF01) {
+ int dataLength = _soundSliceSize * _soundSlicesCount;
+
+ if (!hasNextCmd && _soundEnabled) {
+ soundBuf = new byte[dataLength];
+ assert(soundBuf);
+
+ _stream->read(soundBuf, dataLength);
+ unsignedToSigned(soundBuf, dataLength);
+
+ if (_soundStage == 1)
+ startSound = true;
+
+ _audioStream->queueBuffer(soundBuf, dataLength);
+ } else
+ _stream->seek(dataLength, SEEK_CUR);
+
+ cmd = _stream->readUint16LE();
+
+ // Empty sound slice
+ } else if (!hasNextCmd && (_soundEnabled)) {
+ soundBuf = new byte[_soundSliceSize];
+ assert(soundBuf);
+
+ memset(soundBuf, 0, _soundSliceSize);
+
+ _audioStream->queueBuffer(soundBuf, _soundSliceSize);
+ }
+ }
+
+ // Set palette
+ if (cmd == 0xFFF4) {
+ _stream->seek(2, SEEK_CUR);
+ state.flags |= kStatePalette;
+
+ _stream->read(_palette, 768);
+ cmd = _stream->readUint16LE();
+ }
+
+ hasNextCmd = false;
+
+ // Jump to frame
+ if (cmd == 0xFFFD) {
+
+ frame = _stream->readSint16LE();
+ if (_framesPos) {
+ _curFrame = frame;
+ _stream->seek(_framesPos[frame], SEEK_SET);
+
+ hasNextCmd = true;
+ state.flags |= kStateJump;
+ }
+
+ } else if (cmd == 0xFFFC) {
+
+ state.flags |= 1;
+ cmd = _stream->readUint32LE();
+ _stream->read(_frameData, cmd + 2);
+ _frameDataLen = cmd + 2;
+
+ if (_vidMemWidth <= state.right) {
+ state.left = 0;
+ state.right -= state.left;
+ }
+ if (_vidMemWidth <= state.right)
+ state.right = _vidMemWidth - 1;
+ if (_vidMemHeight <= state.bottom) {
+ state.top = 0;
+ state.bottom -= state.top;
+ }
+ if (_vidMemHeight <= state.bottom)
+ state.bottom = _vidMemHeight -1;
+
+ state.flags |= renderFrame(state.left, state.top, state.right, state.bottom);
+ state.flags |= _frameData[0];
+
+ // Frame video data
+ } else if (cmd != 0) {
+
+ _stream->read(_frameData, cmd + 2);
+ _frameDataLen = cmd + 2;
+
+ state.flags |= renderFrame(state.left, state.top, state.right, state.bottom);
+ state.flags |= _frameData[0];
+
+ } else
+ state.flags |= kStateNoVideoData;
+
+ } while (hasNextCmd);
+
+ if (startSound && _soundEnabled) {
+ _mixer->playInputStream(Audio::Mixer::kSFXSoundType, &_audioHandle, _audioStream);
+ _skipFrames = 0;
+ _soundStage = 2;
+ }
+
+ _curFrame++;
+ if ((_curFrame == _framesCount) && (_soundStage == 2)) {
+ _audioStream->finish();
+ _mixer->stopHandle(_audioHandle);
+ _audioStream = 0;
+ _soundStage = 0;
+ }
+
+ _lastFrameTime = g_system->getMillis();
+ return state;
+}
+
+uint32 Imd::renderFrame(int16 left, int16 top, int16 right, int16 bottom) {
+ if (!_frameData || !_vidMem || (_width <= 0) || (_height <= 0))
+ return 0;
+
+ uint32 retVal = 0;
+ int16 width = right - left + 1;
+ int16 height = bottom - top + 1;
+ int16 sW = _vidMemWidth;
+ byte *dataPtr = _frameData;
+ byte *imdVidMem = _vidMem + sW * top + left;
+ byte *srcPtr;
+ uint8 type = *dataPtr++;
+
+ if (type & 0x10) { // Palette data
+ // One byte index
+ int index = *dataPtr++;
+ // 16 entries with each 3 bytes (RGB)
+ memcpy(_palette + index * 3, dataPtr, MIN((255 - index) * 3, 48));
+
+ retVal = kStatePalette;
+ dataPtr += 48;
+ type ^= 0x10;
+ }
+
+ srcPtr = dataPtr;
+
+ if (type & 0x80) { // Frame data is compressed
+ srcPtr = _vidBuffer;
+ type &= 0x7F;
+ if ((type == 2) && (width == sW)) {
+ deLZ77(imdVidMem, dataPtr);
+ return retVal;
+ } else
+ deLZ77(srcPtr, dataPtr);
+ }
+
+ uint16 pixCount, pixWritten;
+ byte *imdVidMemBak;
+
+ if (type == 2) { // Whole block
+ for (int i = 0; i < height; i++) {
+ memcpy(imdVidMem, srcPtr, width);
+ srcPtr += width;
+ imdVidMem += sW;
+ }
+ } else if (type == 1) { // Sparse block
+ imdVidMemBak = imdVidMem;
+ for (int i = 0; i < height; i++) {
+ pixWritten = 0;
+ while (pixWritten < width) {
+ pixCount = *srcPtr++;
+ if (pixCount & 0x80) { // Data
+ pixCount = MIN((pixCount & 0x7F) + 1, width - pixWritten);
+ memcpy(imdVidMem, srcPtr, pixCount);
+
+ pixWritten += pixCount;
+ imdVidMem += pixCount;
+ srcPtr += pixCount;
+ } else { // "Hole"
+ pixCount = (pixCount + 1) % 256;
+ pixWritten += pixCount;
+ imdVidMem += pixCount;
+ }
+ }
+ imdVidMemBak += sW;
+ imdVidMem = imdVidMemBak;
+ }
+ } else if (type == 0x42) { // Whole quarter-wide block
+ for (int i = 0; i < height; i++) {
+ imdVidMemBak = imdVidMem;
+
+ for (int j = 0; j < width; j += 4, imdVidMem += 4, srcPtr++)
+ memset(imdVidMem, *srcPtr, 4);
+
+ imdVidMemBak += sW;
+ imdVidMem = imdVidMemBak;
+ }
+ } else if ((type & 0xF) == 2) { // Whole half-high block
+ for (; height > 1; height -= 2, imdVidMem += sW + sW, srcPtr += width) {
+ memcpy(imdVidMem, srcPtr, width);
+ memcpy(imdVidMem + sW, srcPtr, width);
+ }
+ if (height == -1)
+ memcpy(imdVidMem, srcPtr, width);
+ } else { // Sparse half-high block
+ imdVidMemBak = imdVidMem;
+ for (int i = 0; i < height; i += 2) {
+ pixWritten = 0;
+ while (pixWritten < width) {
+ pixCount = *srcPtr++;
+ if (pixCount & 0x80) { // Data
+ pixCount = MIN((pixCount & 0x7F) + 1, width - pixWritten);
+ memcpy(imdVidMem, srcPtr, pixCount);
+ memcpy(imdVidMem + sW, srcPtr, pixCount);
+
+ pixWritten += pixCount;
+ imdVidMem += pixCount;
+ srcPtr += pixCount;
+ } else { // "Hole"
+ pixCount = (pixCount + 1) % 256;
+ pixWritten += pixCount;
+ imdVidMem += pixCount;
+ }
+ }
+ imdVidMemBak += sW + sW;
+ imdVidMem = imdVidMemBak;
+ }
+ }
+
+ return retVal;
+}
+
+void Imd::deLZ77(byte *dest, byte *src) {
+ int i;
+ byte buf[4370];
+ uint16 chunkLength;
+ uint32 frameLength;
+ uint16 bufPos1;
+ uint16 bufPos2;
+ uint16 tmp;
+ uint8 chunkBitField;
+ uint8 chunkCount;
+ bool mode;
+
+ frameLength = READ_LE_UINT32(src);
+ src += 4;
+
+ if ((READ_LE_UINT16(src) == 0x1234) && (READ_LE_UINT16(src + 2) == 0x5678)) {
+ src += 4;
+ bufPos1 = 273;
+ mode = 1; // 123Ch (cmp al, 12h)
+ } else {
+ bufPos1 = 4078;
+ mode = 0; // 275h (jnz +2)
+ }
+
+ memset(buf, 32, bufPos1);
+ chunkCount = 1;
+ chunkBitField = 0;
+
+ while (frameLength > 0) {
+ chunkCount--;
+ if (chunkCount == 0) {
+ tmp = *src++;
+ chunkCount = 8;
+ chunkBitField = tmp;
+ }
+ if (chunkBitField % 2) {
+ chunkBitField >>= 1;
+ buf[bufPos1] = *src;
+ *dest++ = *src++;
+ bufPos1 = (bufPos1 + 1) % 4096;
+ frameLength--;
+ continue;
+ }
+ chunkBitField >>= 1;
+
+ tmp = READ_LE_UINT16(src);
+ src += 2;
+ chunkLength = ((tmp & 0xF00) >> 8) + 3;
+
+ if ((mode && ((chunkLength & 0xFF) == 0x12)) ||
+ (!mode && (chunkLength == 0)))
+ chunkLength = *src++ + 0x12;
+
+ bufPos2 = (tmp & 0xFF) + ((tmp >> 4) & 0x0F00);
+ if (((tmp + chunkLength) >= 4096) ||
+ ((chunkLength + bufPos1) >= 4096)) {
+
+ for (i = 0; i < chunkLength; i++, dest++) {
+ *dest = buf[bufPos2];
+ buf[bufPos1] = buf[bufPos2];
+ bufPos1 = (bufPos1 + 1) % 4096;
+ bufPos2 = (bufPos2 + 1) % 4096;
+ }
+
+ } else if (((tmp + chunkLength) < bufPos1) ||
+ ((chunkLength + bufPos1) < bufPos2)) {
+
+ memcpy(dest, buf + bufPos2, chunkLength);
+ memmove(buf + bufPos1, buf + bufPos2, chunkLength);
+
+ dest += chunkLength;
+ bufPos1 += chunkLength;
+ bufPos2 += chunkLength;
+
+ } else {
+
+ for (i = 0; i < chunkLength; i++, dest++, bufPos1++, bufPos2++) {
+ *dest = buf[bufPos2];
+ buf[bufPos1] = buf[bufPos2];
+ }
+
+ }
+ frameLength -= chunkLength;
+
+ }
+}
+
+const uint16 Vmd::_tableADPCM[128] = {
+ 0x0000, 0x0008, 0x0010, 0x0020, 0x0030, 0x0040, 0x0050, 0x0060, 0x0070, 0x0080,
+ 0x0090, 0x00A0, 0x00B0, 0x00C0, 0x00D0, 0x00E0, 0x00F0, 0x0100, 0x0110, 0x0120,
+ 0x0130, 0x0140, 0x0150, 0x0160, 0x0170, 0x0180, 0x0190, 0x01A0, 0x01B0, 0x01C0,
+ 0x01D0, 0x01E0, 0x01F0, 0x0200, 0x0208, 0x0210, 0x0218, 0x0220, 0x0228, 0x0230,
+ 0x0238, 0x0240, 0x0248, 0x0250, 0x0258, 0x0260, 0x0268, 0x0270, 0x0278, 0x0280,
+ 0x0288, 0x0290, 0x0298, 0x02A0, 0x02A8, 0x02B0, 0x02B8, 0x02C0, 0x02C8, 0x02D0,
+ 0x02D8, 0x02E0, 0x02E8, 0x02F0, 0x02F8, 0x0300, 0x0308, 0x0310, 0x0318, 0x0320,
+ 0x0328, 0x0330, 0x0338, 0x0340, 0x0348, 0x0350, 0x0358, 0x0360, 0x0368, 0x0370,
+ 0x0378, 0x0380, 0x0388, 0x0390, 0x0398, 0x03A0, 0x03A8, 0x03B0, 0x03B8, 0x03C0,
+ 0x03C8, 0x03D0, 0x03D8, 0x03E0, 0x03E8, 0x03F0, 0x03F8, 0x0400, 0x0440, 0x0480,
+ 0x04C0, 0x0500, 0x0540, 0x0580, 0x05C0, 0x0600, 0x0640, 0x0680, 0x06C0, 0x0700,
+ 0x0740, 0x0780, 0x07C0, 0x0800, 0x0900, 0x0A00, 0x0B00, 0x0C00, 0x0D00, 0x0E00,
+ 0x0F00, 0x1000, 0x1400, 0x1800, 0x1C00, 0x2000, 0x3000, 0x4000
+};
+
+Vmd::Vmd(Graphics::PaletteLUT *palLUT) : _palLUT(palLUT) {
+ clear(false);
+}
+
+Vmd::~Vmd() {
+ clear();
+}
+
+bool Vmd::load(Common::SeekableReadStream &stream) {
+ unload();
+
+ _stream = &stream;
+
+ uint16 headerLength = _stream->readUint16LE();
+ uint16 handle = _stream->readUint16LE();
+ _version = _stream->readUint16LE();
+
+ if (!(_version & 2))
+ _features |= kFeaturesPalette;
+ else
+ _features |= kFeaturesFullColor;
+
+ // 0x4 (4)
+
+ // Version checking
+ if (headerLength != 814) {
+ warning("VMD Version incorrect (%d, %d, %d)", headerLength, handle, _version);
+ unload();
+ return false;
+ }
+
+ _framesCount = _stream->readUint16LE();
+
+ // 0x6 (6)
+
+ _x = _stream->readSint16LE();
+ _y = _stream->readSint16LE();
+ _width = _stream->readSint16LE();
+ _height = _stream->readSint16LE();
+
+ // 0xE (14)
+
+ if ((_width != 0) && (_height != 0)) {
+ _hasVideo = true;
+ _features |= kFeaturesVideo;
+ if (_features & kFeaturesFullColor)
+ _codecIndeo3 = new Indeo3(_width, _height, _palLUT);
+ } else
+ _hasVideo = false;
+
+ if (_width > 320) {
+ if (!(_version & 4)) {
+ _version |= 4;
+ handle = 0;
+ }
+ }
+
+ if (handle > 2) {
+ warning("VMD Version incorrect (%d, %d, %d)", headerLength, handle, _version);
+ unload();
+ return false;
+ }
+
+ _bytesPerPixel = handle + 1;
+
+ if (_bytesPerPixel > 1) {
+ _features |= kFeaturesFullColor;
+ _features &= ~kFeaturesPalette;
+ }
+
+ _flags = _stream->readUint16LE();
+
+ _partsPerFrame = _stream->readUint16LE();
+ _firstFramePos = _stream->readUint32LE();
+ _stream->skip(4); // Unknown
+
+ // 0x1A (26)
+
+ _stream->read((byte *) _palette, 768);
+
+ // 0x31A (794)
+
+ _frameDataSize = _stream->readUint32LE();
+ _vidBufferSize = _stream->readUint32LE();
+
+ _doubleMode = false;
+
+ if ((_version & 2) && !(_version & 8)) {
+ _externalCodec = true;
+ _frameDataSize = _vidBufferSize = 0;
+ } else
+ _externalCodec = false;
+
+ _preScaleX = 1;
+ _postScaleX = 1;
+
+ if (_externalCodec)
+ _blitMode = 0;
+ else if (_bytesPerPixel == 1)
+ _blitMode = 0;
+ else if ((_bytesPerPixel == 2) || (_bytesPerPixel == 3)) {
+ int n = (_flags & 0x80) ? 2 : 3;
+
+ _blitMode = n - 1;
+
+ if (_bytesPerPixel == 2) {
+ _preScaleX = n;
+ _postScaleX = 1;
+ } else if (_bytesPerPixel == 3) {
+ _preScaleX = 1;
+ _postScaleX = n;
+ }
+
+ _bytesPerPixel = n;
+ }
+
+ _scaleExternalX = 1;
+ if (!_externalCodec && !(_flags & 0x1000))
+ _scaleExternalX = _bytesPerPixel;
+
+ // 0x322 (802)
+
+ if (_hasVideo) {
+ if ((_frameDataSize == 0) || (_frameDataSize > 1048576))
+ _frameDataSize = _width * _height + 1000;
+ if ((_vidBufferSize == 0) || (_vidBufferSize > 1048576))
+ _vidBufferSize = _frameDataSize;
+
+ _frameData = new byte[_frameDataSize];
+ assert(_frameData);
+ memset(_frameData, 0, _frameDataSize);
+
+ _vidBuffer = new byte[_vidBufferSize];
+ assert(_vidBuffer);
+ memset(_vidBuffer, 0, _vidBufferSize);
+
+ if (_blitMode > 0) {
+ _vidMemBuffer = new byte[_bytesPerPixel * (_width * _height + 1000)];
+ memset(_vidMemBuffer, 0, _bytesPerPixel * (_width * _height + 1000));
+ }
+ }
+
+ if (_externalCodec && _codecIndeo3)
+ _features |= kFeaturesSupportsDouble;
+
+ _soundFreq = _stream->readSint16LE();
+ _soundSliceSize = _stream->readSint16LE();
+ _soundSlicesCount = _stream->readSint16LE();
+ _soundFlags = _stream->readUint16LE();
+ _hasSound = (_soundFreq != 0);
+
+ // 0x32A (810)
+
+ if (_hasSound) {
+ _features |= kFeaturesSound;
+
+ _soundStereo = (_soundFlags & 0x8000) ? 1 : ((_soundFlags & 0x200) ? 2 : 0);
+ if (_soundStereo > 0) {
+ warning("TODO: VMD stereo");
+ unload();
+ return false;
+ }
+
+ if (_soundSliceSize < 0) {
+ _soundBytesPerSample = 2;
+ _soundSliceSize = -_soundSliceSize;
+ }
+
+ _soundSliceLength = (uint32) (((double) (1000 << 16)) /
+ ((double) _soundFreq / (double) _soundSliceSize));
+ _frameLength = _soundSliceLength >> 16;
+
+ _soundStage = 1;
+ _audioStream = Audio::makeAppendableAudioStream(_soundFreq,
+ (_soundBytesPerSample == 2) ? Audio::Mixer::FLAG_16BITS : 0);
+ } else
+ _frameLength = 1000 / _frameRate;
+
+ _frameInfoOffset = _stream->readUint32LE();
+
+ int numExtraData = 0;
+
+ _stream->seek(_frameInfoOffset);
+ _frames = new Frame[_framesCount];
+ for (uint16 i = 0; i < _framesCount; i++) {
+ _frames[i].parts = new Part[_partsPerFrame];
+ _stream->skip(2); // Unknown
+ _frames[i].offset = _stream->readUint32LE();
+ }
+ for (uint16 i = 0; i < _framesCount; i++) {
+ bool separator = false;
+
+ for (uint16 j = 0; j < _partsPerFrame; j++) {
+
+ _frames[i].parts[j].type = (PartType) _stream->readByte();
+ _frames[i].parts[j].field_1 = _stream->readByte();
+ _frames[i].parts[j].size = _stream->readUint32LE();
+
+ if (_frames[i].parts[j].type == kPartTypeAudio) {
+
+ _frames[i].parts[j].flags = _stream->readByte();
+ _stream->skip(9); // Unknown
+
+ } else if (_frames[i].parts[j].type == kPartTypeVideo) {
+
+ _frames[i].parts[j].left = _stream->readUint16LE();
+ _frames[i].parts[j].top = _stream->readUint16LE();
+ _frames[i].parts[j].right = _stream->readUint16LE();
+ _frames[i].parts[j].bottom = _stream->readUint16LE();
+ _frames[i].parts[j].field_E = _stream->readByte();
+ _frames[i].parts[j].flags = _stream->readByte();
+
+ } else if (_frames[i].parts[j].type == kPartTypeExtraData) {
+ if (!separator)
+ numExtraData++;
+ _stream->skip(10);
+ } else if (_frames[i].parts[j].type == kPartTypeSeparator) {
+ separator = true;
+ _stream->skip(10);
+ } else {
+ // Unknow type
+ _stream->skip(10);
+ }
+
+ }
+ }
+
+ _stream->seek(_firstFramePos);
+
+ if (numExtraData == 0)
+ return true;
+
+ _extraData.reserve(numExtraData);
+
+ numExtraData = 0;
+
+ uint32 ssize = _stream->size();
+ for (uint16 i = 0; i < _framesCount; i++) {
+ _stream->seek(_frames[i].offset);
+
+ for (uint16 j = 0; j < _partsPerFrame; j++) {
+ if (_frames[i].parts[j].type == kPartTypeSeparator)
+ break;
+
+ if (_frames[i].parts[j].type == kPartTypeExtraData) {
+ ExtraData data;
+
+ data.offset = _stream->pos() + 20;
+ data.size = _frames[i].parts[j].size;
+ data.realSize = _stream->readUint32LE();
+ _stream->read(data.name, 16);
+ data.name[15] = '\0';
+
+ _stream->skip(_frames[i].parts[j].size - 20);
+
+ if ((((uint32) data.realSize) >= ssize) || (data.name[0] == 0))
+ continue;
+
+ _extraData.push_back(data);
+
+ } else
+ _stream->skip(_frames[i].parts[j].size);
+ }
+ }
+
+ _stream->seek(_firstFramePos);
+ return true;
+}
+
+void Vmd::unload() {
+ clear();
+}
+
+int16 Vmd::getWidth() const {
+ return preScaleX(_width);
+}
+
+void Vmd::setXY(int16 x, int16 y) {
+
+ x *= _scaleExternalX;
+
+ for (int i = 0; i < _framesCount; i++) {
+ for (int j = 0; j < _partsPerFrame; j++) {
+
+ if (_frames[i].parts[j].type == kPartTypeVideo) {
+ if (x >= 0) {
+ _frames[i].parts[j].left = _frames[i].parts[j].left - _x + x;
+ _frames[i].parts[j].right = _frames[i].parts[j].right - _x + x;
+ }
+ if (y >= 0) {
+ _frames[i].parts[j].top = _frames[i].parts[j].top - _y + y;
+ _frames[i].parts[j].bottom = _frames[i].parts[j].bottom - _y + y;
+ }
+ }
+
+ }
+ }
+
+ if (x >= 0)
+ _x = x;
+ if (y >= 0)
+ _y = y;
+}
+
+void Vmd::setDoubleMode(bool doubleMode) {
+ if (_doubleMode == doubleMode)
+ return;
+
+ if (_vidBuffer) {
+ delete[] _vidBuffer;
+
+ if (doubleMode)
+ _vidBufferSize *= 4;
+ else
+ _vidBufferSize /= 4;
+
+ _vidBuffer = new byte[_vidBufferSize];
+ assert(_vidBuffer);
+ memset(_vidBuffer, 0, _vidBufferSize);
+
+ }
+
+ if (_codecIndeo3) {
+ delete _codecIndeo3;
+
+ _codecIndeo3 = new Indeo3(_width * (doubleMode ? 2 : 1),
+ _height * (doubleMode ? 2 : 1), _palLUT);
+ }
+
+ _doubleMode = doubleMode;
+}
+
+void Vmd::seekFrame(int32 frame, int16 whence, bool restart) {
+ if (!_stream)
+ // Nothing to do
+ return;
+
+ // Find the frame to which to seek
+ if (whence == SEEK_CUR)
+ frame += _curFrame;
+ else if (whence == SEEK_END)
+ frame = _framesCount - frame - 1;
+ else if (whence != SEEK_SET)
+ return;
+
+ if ((frame < 0) || (frame >= _framesCount))
+ // Nothing to do
+ return;
+
+ // Restart sound
+ if (_hasSound && (frame == 0) && (_soundStage == 0) && !_audioStream) {
+ _soundStage = 1;
+ _audioStream = Audio::makeAppendableAudioStream(_soundFreq,
+ (_soundBytesPerSample == 2) ? Audio::Mixer::FLAG_16BITS : 0);
+ }
+
+ // Seek
+ _stream->seek(_frames[frame].offset);
+ _curFrame = frame;
+}
+
+CoktelVideo::State Vmd::nextFrame() {
+ State state;
+
+ state = processFrame(_curFrame);
+ _curFrame++;
+ return state;
+}
+
+void Vmd::clear(bool del) {
+ Imd::clear(del);
+
+ if (del) {
+ delete _codecIndeo3;
+ delete[] _frames;
+ delete[] _vidMemBuffer;
+ }
+
+ _hasVideo = true;
+
+ _codecIndeo3 = 0;
+
+ _partsPerFrame = 0;
+ _frames = 0;
+
+ _extraData.clear();
+
+ _soundBytesPerSample = 1;
+ _soundStereo = 0;
+
+ _externalCodec = false;
+ _doubleMode = false;
+ _blitMode = 0;
+ _bytesPerPixel = 1;
+ _preScaleX = 1;
+ _postScaleX = 1;
+ _scaleExternalX = 1;
+ _vidMemBuffer = 0;
+}
+
+CoktelVideo::State Vmd::processFrame(uint16 frame) {
+ State state;
+ bool startSound = false;
+
+ seekFrame(frame);
+
+ state.flags |= kStateNoVideoData;
+ state.left = 0x7FFF;
+ state.top = 0x7FFF;
+ state.right = 0;
+ state.bottom = 0;
+
+ if (!_vidMem)
+ setVideoMemory();
+
+ for (uint16 i = 0; (i < _partsPerFrame) && (frame < _framesCount); i++) {
+ Part &part = _frames[frame].parts[i];
+
+ if (part.type == kPartTypeAudio) {
+ // Next sound slice data
+ if (part.flags == 1) {
+
+ if (_soundEnabled) {
+ filledSoundSlice(part.size);
+
+ if (_soundStage == 1)
+ startSound = true;
+
+ } else
+ _stream->skip(part.size);
+
+ // Initial sound data (all slices)
+ } else if (part.flags == 2) {
+
+ if (_soundEnabled) {
+ uint32 mask = _stream->readUint32LE();
+ filledSoundSlices(part.size - 4, mask);
+
+ if (_soundStage == 1)
+ startSound = true;
+
+ } else
+ _stream->skip(part.size);
+
+ // Empty sound slice
+ } else if (part.flags == 3) {
+
+ if (_soundEnabled) {
+ emptySoundSlice(_soundSliceSize * _soundBytesPerSample);
+
+ if (_soundStage == 1)
+ startSound = true;
+ }
+
+ _stream->skip(part.size);
+ } else {
+ warning("Unknown sound part type %d", part.flags);
+ _stream->skip(part.size);
+ }
+
+ } else if (part.type == kPartTypeVideo) {
+ state.flags &= ~kStateNoVideoData;
+
+ uint32 size = part.size;
+
+ // New palette
+ if (part.flags & 2) {
+ uint8 index = _stream->readByte();
+ uint8 count = _stream->readByte();
+
+ _stream->read(_palette + index * 3, (count + 1) * 3);
+ _stream->skip((255 - count) * 3);
+
+ state.flags |= kStatePalette;
+
+ size -= (768 + 2);
+ }
+
+ _stream->read(_frameData, size);
+ _frameDataLen = size;
+
+ int16 l = part.left, t = part.top, r = part.right, b = part.bottom;
+ if (renderFrame(l, t, r, b)) {
+ if (!_externalCodec) {
+ l = preScaleX(l);
+ r = preScaleX(r);
+ }
+ // Rendering succeeded, merging areas
+ state.left = MIN(state.left, l);
+ state.top = MIN(state.top, t);
+ state.right = MAX(state.right, r);
+ state.bottom = MAX(state.bottom, b);
+ }
+
+ } else if (part.type == 4) {
+ // Unknown
+ _stream->skip(part.size);
+ } else {
+ // Unknow type
+// warning("Unknown frame part type %d, size %d (%d of %d)", part.type, part.size, i + 1, _partsPerFrame);
+ }
+ }
+
+ if (startSound && _soundEnabled) {
+ _mixer->playInputStream(Audio::Mixer::kSFXSoundType, &_audioHandle, _audioStream);
+ _skipFrames = 0;
+ _soundStage = 2;
+ }
+
+ if ((_curFrame == (_framesCount - 1)) && (_soundStage == 2)) {
+ _audioStream->finish();
+ _mixer->stopHandle(_audioHandle);
+ _audioStream = 0;
+ _soundStage = 0;
+ }
+
+ // If these are still 0x7FFF, no video data has been processed
+ if ((state.left == 0x7FFF) || (state.top == 0x7FFF))
+ state.left = state.top = state.right = state.bottom = 0;
+
+ _lastFrameTime = g_system->getMillis();
+ return state;
+}
+
+void Vmd::deRLE(byte *&srcPtr, byte *&destPtr, int16 len) {
+ srcPtr++;
+
+ if (len & 1)
+ *destPtr++ = *srcPtr++;
+
+ len >>= 1;
+
+ while (len > 0) {
+ uint8 tmp = *srcPtr++;
+ if (tmp & 0x80) { // Verbatim copy
+ tmp &= 0x7F;
+
+ memcpy(destPtr, srcPtr, tmp * 2);
+ destPtr += tmp * 2;
+ srcPtr += tmp * 2;
+ } else { // 2 bytes tmp times
+ for (int i = 0; i < tmp; i++) {
+ *destPtr++ = srcPtr[0];
+ *destPtr++ = srcPtr[1];
+ }
+ srcPtr += 2;
+ }
+ len -= tmp;
+ }
+}
+
+uint32 Vmd::renderFrame(int16 &left, int16 &top, int16 &right, int16 &bottom) {
+ if (!_frameData || !_vidMem || (_width <= 0) || (_height <= 0))
+ return 0;
+
+ int16 width = right - left + 1;
+ int16 height = bottom - top + 1;
+ int16 sW = _vidMemWidth;
+ int16 sH = _vidMemHeight;
+ uint32 dataLen = _frameDataLen;
+ byte *dataPtr = _frameData;
+ byte *imdVidMem = _vidMem + sW * top + left;
+ byte *srcPtr;
+ uint8 type;
+
+ if ((width < 0) || (height < 0))
+ return 1;
+
+ byte *dest = imdVidMem;
+
+ if (Indeo3::isIndeo3(dataPtr, dataLen)) {
+ if (!_codecIndeo3)
+ return 0;
+
+ if (!_codecIndeo3->decompressFrame(dataPtr, dataLen, _vidBuffer,
+ width * (_doubleMode ? 2 : 1), height * (_doubleMode ? 2 : 1)))
+ return 0;
+
+ type = 2;
+ srcPtr = _vidBuffer;
+ width = _width * (_doubleMode ? 2 : 1);
+ height = _height * (_doubleMode ? 2 : 1);
+ right = left + width - 1;
+ bottom = top + height - 1;
+
+ } else {
+
+ if (_externalCodec) {
+ warning("Unknown external codec");
+ return 0;
+ }
+
+ type = *dataPtr++;
+ srcPtr = dataPtr;
+
+ if (_blitMode > 0) {
+ dest = _vidMemBuffer + postScaleX(_width) * (top - _y) + postScaleX((left - _x));
+ imdVidMem = _vidMem + _vidMemWidth * top + preScaleX(left);
+ sW = postScaleX(_width);
+ sH = _height;
+ }
+
+ if (type & 0x80) { // Frame data is compressed
+ srcPtr = _vidBuffer;
+ type &= 0x7F;
+ if ((type == 2) && (postScaleX(width) == sW)) {
+ deLZ77(dest, dataPtr);
+ blit(imdVidMem, dest, width, height);
+ return 1;
+ } else
+ deLZ77(srcPtr, dataPtr);
+ }
+
+ }
+
+ uint16 pixCount, pixWritten;
+ byte *destBak;
+
+ if (type == 1) { // Sparse block
+ destBak = dest;
+ for (int i = 0; i < height; i++) {
+ pixWritten = 0;
+ while (pixWritten < postScaleX(width)) {
+ pixCount = *srcPtr++;
+ if (pixCount & 0x80) { // Data
+ pixCount = MIN<int>((pixCount & 0x7F) + 1, postScaleX(width) - pixWritten);
+ memcpy(dest, srcPtr, pixCount);
+
+ pixWritten += pixCount;
+ dest += pixCount;
+ srcPtr += pixCount;
+ } else { // "Hole"
+ pixCount = (pixCount + 1) % 256;
+ pixWritten += pixCount;
+ dest += pixCount;
+ }
+ }
+ destBak += sW;
+ dest = destBak;
+ }
+ } else if (type == 2) { // Whole block
+ int16 w = MIN<int32>(postScaleX(width), sW);
+ int16 h = MIN(height, sH);
+
+ for (int i = 0; i < h; i++) {
+ memcpy(dest, srcPtr, w);
+ srcPtr += postScaleX(width);
+ dest += sW;
+ }
+
+ } else if (type == 3) { // RLE block
+ for (int i = 0; i < height; i++) {
+ destBak = dest;
+
+ pixWritten = 0;
+ while (pixWritten < width) {
+ pixCount = *srcPtr++;
+ if (pixCount & 0x80) {
+ pixCount = (pixCount & 0x7F) + 1;
+
+ if (*srcPtr != 0xFF) { // Normal copy
+ memcpy(dest, srcPtr, pixCount);
+ dest += pixCount;
+ srcPtr += pixCount;
+ } else
+ deRLE(srcPtr, dest, pixCount);
+
+ pixWritten += pixCount;
+ } else { // "Hole"
+ dest += pixCount + 1;
+ pixWritten += pixCount + 1;
+ }
+
+ }
+ destBak += sW;
+ dest = destBak;
+ }
+ } else if (type == 0x42) { // Whole quarter-wide block
+ for (int i = 0; i < height; i++) {
+ destBak = dest;
+
+ for (int j = 0; j < width; j += 4, dest += 4, srcPtr++)
+ memset(dest, *srcPtr, 4);
+
+ destBak += sW;
+ dest = destBak;
+ }
+ } else if ((type & 0xF) == 2) { // Whole half-high block
+ for (; height > 1; height -= 2, dest += sW + sW, srcPtr += width) {
+ memcpy(dest, srcPtr, width);
+ memcpy(dest + sW, srcPtr, width);
+ }
+ if (height == -1)
+ memcpy(dest, srcPtr, width);
+ } else { // Sparse half-high block
+ destBak = dest;
+ for (int i = 0; i < height; i += 2) {
+ pixWritten = 0;
+ while (pixWritten < width) {
+ pixCount = *srcPtr++;
+ if (pixCount & 0x80) { // Data
+ pixCount = MIN((pixCount & 0x7F) + 1, width - pixWritten);
+ memcpy(dest, srcPtr, pixCount);
+ memcpy(dest + sW, srcPtr, pixCount);
+
+ pixWritten += pixCount;
+ dest += pixCount;
+ srcPtr += pixCount;
+ } else { // "Hole"
+ pixCount = (pixCount + 1) % 256;
+ pixWritten += pixCount;
+ dest += pixCount;
+ }
+ }
+ destBak += sW + sW;
+ dest = destBak;
+ }
+ }
+
+ dest = _vidMemBuffer + postScaleX(_width) * (top - _y) + postScaleX(left - _x);
+ blit(imdVidMem, dest, width, height);
+
+ return 1;
+}
+
+inline int32 Vmd::preScaleX(int32 x) const {
+ return x / _preScaleX;
+}
+
+inline int32 Vmd::postScaleX(int32 x) const {
+ return x * _postScaleX;
+}
+
+void Vmd::blit(byte *dest, byte *src, int16 width, int16 height) {
+ if (_blitMode == 0)
+ return;
+
+ if (_blitMode == 1)
+ blit16(dest, src, preScaleX(_width), preScaleX(width), height);
+ else if (_blitMode == 2)
+ blit24(dest, src, preScaleX(_width), preScaleX(width), height);
+}
+
+void Vmd::blit16(byte *dest, byte *src, int16 srcPitch, int16 width, int16 height) {
+ assert(_palLUT);
+
+ Graphics::SierraLight *dither =
+ new Graphics::SierraLight(width, _palLUT);
+
+ for (int i = 0; i < height; i++) {
+ byte *d = dest;
+ byte *s = src;
+
+ for (int j = 0; j < width; j++, s += 2) {
+ uint16 data = READ_LE_UINT16(s);
+ byte r = ((data & 0x7C00) >> 10);
+ byte g = ((data & 0x03E0) >> 5);
+ byte b = ((data & 0x001F) >> 0);
+ byte dY, dU, dV;
+
+ Graphics::PaletteLUT::RGB2YUV(r << 3, g << 3, b << 3, dY, dU, dV);
+
+ byte p = dither->dither(dY, dU, dV, j);
+
+ if ((dY == 0) || ((r == 0) && (g == 0) && (b == 0)))
+ *d++ = 0;
+ else
+ *d++ = p;
+ }
+
+ dither->nextLine();
+ dest += _vidMemWidth;
+ src += 2 * srcPitch;
+ }
+
+ delete dither;
+}
+
+void Vmd::blit24(byte *dest, byte *src, int16 srcPitch, int16 width, int16 height) {
+ assert(_palLUT);
+
+ Graphics::SierraLight *dither =
+ new Graphics::SierraLight(width, _palLUT);
+
+ for (int i = 0; i < height; i++) {
+ byte *d = dest;
+ byte *s = src;
+
+ for (int j = 0; j < width; j++, s += 3) {
+ byte r = s[2];
+ byte g = s[1];
+ byte b = s[0];
+ byte dY, dU, dV;
+
+ Graphics::PaletteLUT::RGB2YUV(r, g, b, dY, dU, dV);
+
+ byte p = dither->dither(dY, dU, dV, j);
+
+ if ((dY == 0) || ((r == 0) && (g == 0) && (b == 0)))
+ *d++ = 0;
+ else
+ *d++ = p;
+ }
+
+ dither->nextLine();
+ dest += _vidMemWidth;
+ src += 3 * srcPitch;
+ }
+
+ delete dither;
+}
+
+void Vmd::emptySoundSlice(uint32 size) {
+ if (!_audioStream)
+ return;
+
+ byte *soundBuf = new byte[size];
+ assert(soundBuf);
+
+ memset(soundBuf, 0, size);
+
+ _audioStream->queueBuffer(soundBuf, size);
+}
+
+void Vmd::soundSlice8bit(uint32 size) {
+ if (!_audioStream)
+ return;
+
+ byte *soundBuf = new byte[size];
+ assert(soundBuf);
+
+ _stream->read(soundBuf, size);
+ unsignedToSigned(soundBuf, size);
+
+ _audioStream->queueBuffer(soundBuf, size);
+}
+
+void Vmd::soundSlice16bit(uint32 size, int16 &init) {
+ if (!_audioStream)
+ return;
+
+ byte *dataBuf = new byte[size];
+ byte *soundBuf = new byte[size * 2];
+
+ _stream->read(dataBuf, size);
+ deADPCM(soundBuf, dataBuf, init, size);
+ _audioStream->queueBuffer(soundBuf, size * 2);
+
+ delete[] dataBuf;
+}
+
+void Vmd::filledSoundSlice(uint32 size) {
+ if (_soundBytesPerSample == 1) {
+ soundSlice8bit(size);
+ } else if (_soundBytesPerSample == 2) {
+ int16 init = _stream->readSint16LE();
+ soundSlice16bit(size - 2, init);
+ }
+}
+
+void Vmd::filledSoundSlices(uint32 size, uint32 mask) {
+ int n = MIN<int>(_soundSlicesCount - 1, 31);
+ for (int i = 0; i < n; i++) {
+
+ if (mask & 1)
+ emptySoundSlice(_soundSliceSize * _soundBytesPerSample);
+ else
+ filledSoundSlice(_soundSliceSize + 1);
+
+ mask >>= 1;
+ }
+ if (_soundSlicesCount > 32)
+ filledSoundSlice((_soundSlicesCount - 32) * _soundSliceSize);
+}
+
+void Vmd::deADPCM(byte *soundBuf, byte *dataBuf, int16 &init, uint32 n) {
+ int16 *out = (int16 *) soundBuf;
+
+ int32 s = init;
+ for (uint32 i = 0; i < n; i++) {
+ if (dataBuf[i] & 0x80)
+ s -= _tableADPCM[dataBuf[i] & 0x7F];
+ else
+ s += _tableADPCM[dataBuf[i]];
+
+ s = CLIP<int32>(s, -32768, 32767);
+ *out++ = TO_BE_16(s);
+ }
+}
+
+bool Vmd::getAnchor(int16 frame, uint16 partType,
+ int16 &x, int16 &y, int16 &width, int16 &height) {
+
+ uint32 pos = _stream->pos();
+
+ _stream->seek(_frameInfoOffset);
+ // Offsets to frames
+ _stream->skip(_framesCount * 6);
+ // Jump to the specified frame
+ _stream->skip(_partsPerFrame * frame * 16);
+
+ // Find the anchor part
+ uint16 i;
+ for (i = 0; i < _partsPerFrame; i++) {
+ byte type = _stream->readByte();
+
+ if ((type == kPartTypeSeparator) || (type == partType))
+ break;
+
+ _stream->skip(15);
+ }
+
+ if (i == _partsPerFrame) {
+ // No anchor
+
+ _stream->seek(pos);
+ return false;
+ }
+
+ _stream->skip(5);
+ x = _stream->readSint16LE();
+ y = _stream->readSint16LE();
+ width = _stream->readSint16LE() - x + 1;
+ height = _stream->readSint16LE() - y + 1;
+
+ _stream->seek(pos);
+ return true;
+}
+
+bool Vmd::hasExtraData(const char *fileName) const {
+ for (uint i = 0; i < _extraData.size(); i++)
+ if (!scumm_stricmp(_extraData[i].name, fileName))
+ return true;
+
+ return false;
+}
+
+Common::MemoryReadStream *Vmd::getExtraData(const char *fileName) {
+ uint i = 0;
+
+ for (i = 0; i < _extraData.size(); i++)
+ if (!scumm_stricmp(_extraData[i].name, fileName))
+ break;
+
+ if (i >= _extraData.size())
+ return 0;
+
+ if ((_extraData[i].size - 20) != _extraData[i].realSize) {
+ warning("Vmd::getExtraData(): Sizes for \"%s\" differ! (%d, %d)",
+ fileName, (_extraData[i].size - 20), _extraData[i].realSize);
+ return 0;
+ }
+
+ byte *data = (byte *) malloc(_extraData[i].realSize);
+
+ _stream->seek(_extraData[i].offset);
+ if (_stream->ioFailed() || (((uint32) _stream->pos()) != _extraData[i].offset)) {
+ warning("Vmd::getExtraData(): Can't seek to offset %d to get extra data file \"%s\"",
+ _extraData[i].offset, fileName);
+ return 0;
+ }
+
+ _stream->read(data, _extraData[i].realSize);
+
+ Common::MemoryReadStream *stream =
+ new Common::MemoryReadStream(data, _extraData[i].realSize, true);
+
+ return stream;
+}
+
+} // End of namespace Graphics
Property changes on: scummvm/trunk/graphics/video/coktelvideo/coktelvideo.cpp
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:mergeinfo
+
Added: svn:eol-style
+ native
Copied: scummvm/trunk/graphics/video/coktelvideo/coktelvideo.h (from rev 40752, scummvm/trunk/graphics/video/coktelvideo.h)
===================================================================
--- scummvm/trunk/graphics/video/coktelvideo/coktelvideo.h (rev 0)
+++ scummvm/trunk/graphics/video/coktelvideo/coktelvideo.h 2009-05-21 10:48:03 UTC (rev 40755)
@@ -0,0 +1,417 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef GRAPHICS_VIDEO_COKTELVIDEO_H
+#define GRAPHICS_VIDEO_COKTELVIDEO_H
+
+#include "common/stream.h"
+#include "common/array.h"
+#include "graphics/dither.h"
+#include "sound/mixer.h"
+#include "sound/audiostream.h"
+
+namespace Graphics {
+
+class Indeo3;
+
+/** Common interface for handling Coktel Vision videos and derivated formats. */
+class CoktelVideo {
+public:
+ enum Features {
+ kFeaturesNone = 0,
+ /** Has an own palette. */
+ kFeaturesPalette = 8,
+ /** Suggests a data size. */
+ kFeaturesDataSize = 0x20,
+ /** Has sound. */
+ kFeaturesSound = 0x40,
+ /** Has specific frame coordinates. */
+ kFeaturesFrameCoords = 0x80,
+ /** Has general standard coordinates. */
+ kFeaturesStdCoords = 0x100,
+ /** Has a frame positions table. */
+ kFeaturesFramesPos = 0x200,
+ /** Has video. */
+ kFeaturesVideo = 0x400,
+ /** Is a full color (non-paletted) video. */
+ kFeaturesFullColor = 0x4000,
+ /** Supports automatic doubling. */
+ kFeaturesSupportsDouble = 0x40000000
+ };
+
+ enum StateFlags {
+ kStateNone = 0,
+ /** Changed the palette. */
+ kStatePalette = 0x10,
+ /** Performed a jump to another frame. */
+ kStateJump = 0x200,
+ /** Updated according to the specific frame coordinates. */
+ kStateFrameCoords = 0x400,
+ /** Got no frame data. */
+ kStateNoVideoData = 0x800,
+ /** Updated according to the general standard coordinates. */
+ kStateStdCoords = 0x1000,
+ /** Had to explicitely seek to the frame. */
+ kStateSeeked = 0x2000,
+ /** Reached a break-point. */
+ kStateBreak = 0x8000
+ };
+
+ struct State {
+ /** Left-most value of the updated rectangle. */
+ int16 left;
+ /** Top-most value of the updated rectangle. */
+ int16 top;
+ /** Right-most value of the updated rectangle. */
+ int16 right;
+ /** Bottom-most value of the updated rectangle. */
+ int16 bottom;
+ /** Set accordingly to what was done. */
+ uint32 flags;
+
+ State() : left(0), top(0), right(0), bottom(0), flags(0) { }
+ };
+
+ virtual ~CoktelVideo() { }
+
+ /** Returns the features the loaded video possesses. */
+ virtual uint32 getFeatures() const = 0;
+ /** Returns the flags the loaded video possesses. */
+ virtual uint16 getFlags() const = 0;
+ /** Returns the x coordinate of the video. */
+ virtual int16 getX() const = 0;
+ /** Returns the y coordinate of the video. */
+ virtual int16 getY() const = 0;
+ /** Returns the width of the video. */
+ virtual int16 getWidth() const = 0;
+ /** Returns the height of the video. */
+ virtual int16 getHeight() const = 0;
+ /** Returns the number of frames the loaded video has. */
+ virtual uint16 getFramesCount() const = 0;
+ /** Returns the current frame number.
+ *
+ * This is the current frame after the last nextFrame()-call,
+ * i.e. it's 0 after loading, 1 after the first nextFrame()-call, etc..
+ */
+ virtual uint16 getCurrentFrame() const = 0;
+ /** Returns the frame rate. */
+ virtual int16 getFrameRate() const = 0;
+ /** Returns the number of frames the video lags behind the audio. */
+ virtual uint32 getSyncLag() const = 0;
+ /** Returns the current frame's palette. */
+ virtual const byte *getPalette() const = 0;
+
+ /** Reads the video's anchor pointer */
+ virtual bool getAnchor(int16 frame, uint16 partType,
+ int16 &x, int16 &y, int16 &width, int16 &height) = 0;
+
+ /** Returns whether that extra data file exists */
+ virtual bool hasExtraData(const char *fileName) const = 0;
+ /** Returns an extra data file */
+ virtual Common::MemoryReadStream *getExtraData(const char *fileName) = 0;
+
+ /** Load a video out of a stream. */
+ virtual bool load(Common::SeekableReadStream &stream) = 0;
+ /** Unload the currently loaded video. */
+ virtual void unload() = 0;
+
+ /** Set the frame rate. */
+ virtual void setFrameRate(int16 frameRate) = 0;
+
+ /** Set the coordinations where to draw the video. */
+ virtual void setXY(int16 x, int16 y) = 0;
+ /** Use a specific memory block as video memory. */
+ virtual void setVideoMemory(byte *vidMem, uint16 width, uint16 height) = 0;
+ /** Use an own memory block as video memory. */
+ virtual void setVideoMemory() = 0;
+
+ /** Double the video's resolution. */
+ virtual void setDoubleMode(bool doubleMode) = 0;
+
+ /** Play sound (if the video has sound). */
+ virtual void enableSound(Audio::Mixer &mixer) = 0;
+ /** Don't play sound or stop currently playing sound. */
+ virtual void disableSound() = 0;
+
+ /** Is sound currently playing? */
+ virtual bool isSoundPlaying() const = 0;
+
+ /** Seek to a specific frame.
+ *
+ * @param frame The frame to which to seek.
+ * @param whence The offset from whence the frame is given.
+ * @param restart Restart the video to reach an otherwise inaccessible frame?
+ */
+ virtual void seekFrame(int32 frame, int16 whence = SEEK_SET, bool restart = false) = 0;
+
+ /** Render the next frame. */
+ virtual State nextFrame() = 0;
+ /** Wait for the frame to end. */
+ virtual void waitEndFrame() = 0;
+
+ /** Notifies the video that it was paused for duration ms. */
+ virtual void notifyPaused(uint32 duration) = 0;
+
+ /** Copy the current frame.
+ *
+ * @param dest The memory to which to copy the current frame.
+ * @param left The x position within the frame.
+ * @param top The y position within the frame.
+ * @param width The width of the area to copy.
+ * @param height The height of the area to copy.
+ * @param x The x position to where to copy.
+ * @param y The y position to where to copy.
+ * @param pitch The buffer's width.
+ * @param transp Which color should be seen as transparent?
+ */
+ virtual void copyCurrentFrame(byte *dest,
+ uint16 left, uint16 top, uint16 width, uint16 height,
+ uint16 x, uint16 y, uint16 pitch, int16 transp = -1) = 0;
+};
+
+/** Coktel Vision's IMD files.
+ */
+class Imd : public CoktelVideo {
+public:
+ Imd();
+ ~Imd();
+
+ uint32 getFeatures() const { return _features; }
+ uint16 getFlags() const { return _flags; }
+ int16 getX() const { return _x; }
+ int16 getY() const { return _y; }
+ int16 getWidth() const { return _width; }
+ int16 getHeight() const { return _height; }
+ uint16 getFramesCount() const { return _framesCount; }
+ uint16 getCurrentFrame() const { return _curFrame; }
+ int16 getFrameRate() const {
+ if (_hasSound)
+ return 1000 / (_soundSliceLength >> 16);
+ return _frameRate;
+ }
+ uint32 getSyncLag() const { return _skipFrames; }
+ const byte *getPalette() const { return _palette; }
+
+ bool getAnchor(int16 frame, uint16 partType,
+ int16 &x, int16 &y, int16 &width, int16 &height) { return false; }
+
+ bool hasExtraData(const char *fileName) const { return false; }
+ Common::MemoryReadStream *getExtraData(const char *fileName) { return 0; }
+
+ void notifyPaused(uint32 duration) { }
+
+ void setFrameRate(int16 frameRate);
+
+ bool load(Common::SeekableReadStream &stream);
+ void unload();
+
+ void setXY(int16 x, int16 y);
+ void setVideoMemory(byte *vidMem, uint16 width, uint16 height);
+ void setVideoMemory();
+
+ void setDoubleMode(bool doubleMode) { }
+
+ void enableSound(Audio::Mixer &mixer);
+ void disableSound();
+
+ bool isSoundPlaying() const;
+
+ void seekFrame(int32 frame, int16 whence = SEEK_SET, bool restart = false);
+
+ State nextFrame();
+ void waitEndFrame();
+
+ void copyCurrentFrame(byte *dest,
+ uint16 left, uint16 top, uint16 width, uint16 height,
+ uint16 x, uint16 y, uint16 pitch, int16 transp = -1);
+
+protected:
+ struct Coord {
+ int16 left;
+ int16 top;
+ int16 right;
+ int16 bottom;
+ } PACKED_STRUCT;
+
+ Common::SeekableReadStream *_stream;
+ uint16 _version;
+ uint32 _features;
+ uint16 _flags;
+ int16 _x, _y, _width, _height;
+ int16 _stdX, _stdY, _stdWidth, _stdHeight;
+ uint16 _framesCount, _curFrame;
+ uint32 *_framesPos;
+ uint32 _firstFramePos;
+ Coord *_frameCoords;
+
+ uint32 _frameDataSize, _vidBufferSize;
+ byte *_frameData, *_vidBuffer;
+ uint32 _frameDataLen;
+
+ byte _palette[768];
+
+ bool _hasOwnVidMem;
+ byte *_vidMem;
+ uint16 _vidMemWidth, _vidMemHeight;
+
+ bool _hasSound;
+ bool _soundEnabled;
+ uint8 _soundStage; // (0: no sound, 1: loaded, 2: playing)
+ uint32 _skipFrames;
+
+ uint16 _soundFlags;
+ int16 _soundFreq;
+ int16 _soundSliceSize;
+ int16 _soundSlicesCount;
+ uint32 _soundSliceLength;
+
+ Audio::AppendableAudioStream *_audioStream;
+ Audio::SoundHandle _audioHandle;
+
+ int16 _frameRate;
+ uint32 _frameLength;
+ uint32 _lastFrameTime;
+
+ Audio::Mixer *_mixer;
+
+ void unsignedToSigned(byte *buffer, int length) {
+ while (length-- > 0) *buffer++ ^= 0x80;
+ }
+
+ void deleteVidMem(bool del = true);
+ void clear(bool del = true);
+
+ State processFrame(uint16 frame);
+ uint32 renderFrame(int16 left, int16 top, int16 right, int16 bottom);
+ void deLZ77(byte *dest, byte *src);
+};
+
+class Vmd : public Imd {
+public:
+ Vmd(Graphics::PaletteLUT *palLUT = 0);
+ ~Vmd();
+
+ bool getAnchor(int16 frame, uint16 partType,
+ int16 &x, int16 &y, int16 &width, int16 &height);
+
+ bool hasExtraData(const char *fileName) const;
+ Common::MemoryReadStream *getExtraData(const char *fileName);
+
+ bool load(Common::SeekableReadStream &stream);
+ void unload();
+
+ int16 getWidth() const;
+
+ void setXY(int16 x, int16 y);
+
+ void setDoubleMode(bool doubleMode);
+
+ void seekFrame(int32 frame, int16 whence = SEEK_SET, bool restart = false);
+
+ State nextFrame();
+
+protected:
+ enum PartType {
+ kPartTypeSeparator = 0,
+ kPartTypeAudio = 1,
+ kPartTypeVideo = 2,
+ kPartTypeExtraData = 3
+ };
+ struct ExtraData {
+ char name[16];
+ uint32 offset;
+ uint32 size;
+ uint32 realSize;
+ } PACKED_STRUCT;
+ struct Part {
+ PartType type;
+ byte field_1;
+ byte field_E;
+ uint32 size;
+ int16 left;
+ int16 top;
+ int16 right;
+ int16 bottom;
+ byte flags;
+ } PACKED_STRUCT;
+ struct Frame {
+ uint32 offset;
+ Part *parts;
+
+ Frame() : parts(0) { }
+ ~Frame() { delete[] parts; }
+ } PACKED_STRUCT;
+
+ static const uint16 _tableADPCM[128];
+
+ bool _hasVideo;
+
+ uint32 _frameInfoOffset;
+ uint16 _partsPerFrame;
+ Frame *_frames;
+
+ Common::Array<ExtraData> _extraData;
+
+ byte _soundBytesPerSample;
+ byte _soundStereo; // (0: mono, 1: old-style stereo, 2: new-style stereo)
+
+ bool _externalCodec;
+ byte _blitMode;
+ byte _bytesPerPixel;
+ byte _preScaleX;
+ byte _postScaleX;
+ byte _scaleExternalX;
+ byte *_vidMemBuffer;
+
+ bool _doubleMode;
+
+ Graphics::PaletteLUT *_palLUT;
+ Indeo3 *_codecIndeo3;
+
+ void clear(bool del = true);
+
+ State processFrame(uint16 frame);
+ uint32 renderFrame(int16 &left, int16 &top, int16 &right, int16 &bottom);
+
+ void deRLE(byte *&srcPtr, byte *&destPtr, int16 len);
+
+ inline int32 preScaleX(int32 x) const;
+ inline int32 postScaleX(int32 x) const;
+
+ void blit(byte *dest, byte *src, int16 width, int16 height);
+ void blit16(byte *dest, byte *src, int16 srcPitch, int16 width, int16 height);
+ void blit24(byte *dest, byte *src, int16 srcPitch, int16 width, int16 height);
+
+ void emptySoundSlice(uint32 size);
+ void soundSlice8bit(uint32 size);
+ void soundSlice16bit(uint32 size, int16 &init);
+ void filledSoundSlice(uint32 size);
+ void filledSoundSlices(uint32 size, uint32 mask);
+ void deADPCM(byte *soundBuf, byte *dataBuf, int16 &init, uint32 n);
+};
+
+} // End of namespace Graphics
+
+#endif // GRAPHICS_VIDEO_COKTELVIDEO_H
Property changes on: scummvm/trunk/graphics/video/coktelvideo/coktelvideo.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:mergeinfo
+
Added: svn:eol-style
+ native
Copied: scummvm/trunk/graphics/video/coktelvideo/indeo3.cpp (from rev 40752, scummvm/trunk/graphics/video/indeo3.cpp)
===================================================================
--- scummvm/trunk/graphics/video/coktelvideo/indeo3.cpp (rev 0)
+++ scummvm/trunk/graphics/video/coktelvideo/indeo3.cpp 2009-05-21 10:48:03 UTC (rev 40755)
@@ -0,0 +1,1155 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+/* Intel Indeo 3 decompressor, derived from ffmpeg.
+ *
+ * Original copyright note: * Intel Indeo 3 (IV31, IV32, etc.) video decoder for ffmpeg
+ * written, produced, and directed by Alan Smithee
+ */
+
+#include "common/system.h"
+#include "common/endian.h"
+#include "common/frac.h"
+#include "common/file.h"
+
+#include "graphics/dither.h"
+#include "graphics/video/coktelvideo/indeo3.h"
+#include "graphics/video/coktelvideo/indeo3data.h"
+
+namespace Graphics {
+
+Indeo3::Indeo3(int16 width, int16 height, Graphics::PaletteLUT *palLUT) {
+ assert((width > 0) && (height > 0));
+
+ _width = width;
+ _height = height;
+ _palLUT = palLUT;
+
+ _ditherSL = 0;
+ setDither(kDitherSierraLight);
+
+ buildModPred();
+ allocFrames();
+}
+
+Indeo3::~Indeo3() {
+ delete[] _iv_frame[0].the_buf;
+ delete[] _ModPred;
+ delete[] _corrector_type;
+ delete _ditherSL;
+}
+
+bool Indeo3::isIndeo3(byte *data, uint32 dataLen) {
+ // No data, no Indeo 3
+ if (!data)
+ return false;
+
+ // Less than 16 bytes? This can't be right
+ if (dataLen < 16)
+ return false;
+
+ // Unknown, but according to the docs, always 0
+ if (READ_LE_UINT32(data + 4) != 0)
+ return false;
+
+ uint32 id;
+ id = READ_LE_UINT32(data ); // frame number
+ id ^= READ_LE_UINT32(data + 4); // unknown
+ id ^= READ_LE_UINT32(data + 8); // checksum
+ id ^= READ_LE_UINT32(data + 12); // frame data length
+
+ // These 4 uint32s XOR'd need to spell "FRMH"
+ if (id != MKID_BE('FRMH'))
+ return false;
+
+ return true;
+}
+
+void Indeo3::setDither(DitherAlgorithm dither) {
+ delete _ditherSL;
+ _ditherSL = 0;
+
+ _dither = dither;
+
+ switch(dither) {
+ case kDitherSierraLight:
+ _ditherSL = new Graphics::SierraLight(_width, _palLUT);
+ break;
+
+ default:
+ return;
+ }
+}
+
+void Indeo3::buildModPred() {
+ _ModPred = new byte[8 * 128];
+
+ for (int i = 0; i < 128; i++) {
+ _ModPred[i+0*128] = (i > 126) ? 254 : 2*((i + 1) - ((i + 1) % 2));
+ _ModPred[i+1*128] = (i == 7) ? 20 : ((i == 119 || i == 120)
+ ? 236 : 2*((i + 2) - ((i + 1) % 3)));
+ _ModPred[i+2*128] = (i > 125) ? 248 : 2*((i + 2) - ((i + 2) % 4));
+ _ModPred[i+3*128] = 2*((i + 1) - ((i - 3) % 5));
+ _ModPred[i+4*128] = (i == 8) ? 20 : 2*((i + 1) - ((i - 3) % 6));
+ _ModPred[i+5*128] = 2*((i + 4) - ((i + 3) % 7));
+ _ModPred[i+6*128] = (i > 123) ? 240 : 2*((i + 4) - ((i + 4) % 8));
+ _ModPred[i+7*128] = 2*((i + 5) - ((i + 4) % 9));
+ }
+
+ _corrector_type = new uint16[24 * 256];
+
+ for (int i = 0; i < 24; i++) {
+ for (int j = 0; j < 256; j++) {
+ _corrector_type[i*256+j] =
+ (j < _corrector_type_0[i]) ? 1 :
+ ((j < 248 || (i == 16 && j == 248)) ? 0 :
+ _corrector_type_2[j - 248]);
+ }
+ }
+}
+
+void Indeo3::allocFrames() {
+ int32 luma_width = (_width + 3) & (~3);
+ int32 luma_height = (_height + 3) & (~3);
+
+ int32 chroma_width = ((luma_width >> 2) + 3) & (~3);
+ int32 chroma_height = ((luma_height>> 2) + 3) & (~3);
+
+ int32 luma_pixels = luma_width * luma_height;
+ int32 chroma_pixels = chroma_width * chroma_height;
+
+ uint32 bufsize = luma_pixels * 2 + luma_width * 3 +
+ (chroma_pixels + chroma_width) * 4;
+
+ _iv_frame[0].y_w = _iv_frame[1].y_w = luma_width;
+ _iv_frame[0].y_h = _iv_frame[1].y_h = luma_height;
+ _iv_frame[0].uv_w = _iv_frame[1].uv_w = chroma_width;
+ _iv_frame[0].uv_h = _iv_frame[1].uv_h = chroma_height;
+
+ _iv_frame[0].the_buf_size = bufsize;
+ _iv_frame[1].the_buf_size = 0;
+
+ _iv_frame[0].the_buf = new byte[bufsize];
+ memset(_iv_frame[0].the_buf, 0, bufsize);
+ _iv_frame[1].the_buf = 0;
+
+ uint32 offs = 0;
+
+ _iv_frame[0].Ybuf = _iv_frame[0].the_buf + luma_width;
+ offs += luma_pixels + luma_width * 2;
+ _iv_frame[1].Ybuf = _iv_frame[0].the_buf + offs;
+ offs += (luma_pixels + luma_width);
+ _iv_frame[0].Ubuf = _iv_frame[0].the_buf + offs;
+ offs += (chroma_pixels + chroma_width);
+ _iv_frame[1].Ubuf = _iv_frame[0].the_buf + offs;
+ offs += (chroma_pixels + chroma_width);
+ _iv_frame[0].Vbuf = _iv_frame[0].the_buf + offs;
+ offs += (chroma_pixels + chroma_width);
+ _iv_frame[1].Vbuf = _iv_frame[0].the_buf + offs;
+
+ for (int i = 1; i <= luma_width; i++)
+ _iv_frame[0].Ybuf[-i] = _iv_frame[1].Ybuf[-i] =
+ _iv_frame[0].Ubuf[-i] = 0x80;
+
+ for (int i = 1; i <= chroma_width; i++) {
+ _iv_frame[1].Ubuf[-i] = 0x80;
+ _iv_frame[0].Vbuf[-i] = 0x80;
+ _iv_frame[1].Vbuf[-i] = 0x80;
+ _iv_frame[1].Vbuf[chroma_pixels+i-1] = 0x80;
+ }
+}
+
+bool Indeo3::decompressFrame(byte *inData, uint32 dataLen,
+ byte *outData, uint16 width, uint16 height) {
+
+ // Not Indeo 3? Fail
+ if (!isIndeo3(inData, dataLen))
+ return false;
+
+ assert(outData);
+ assert(_palLUT);
+
+ uint32 frameDataLen = READ_LE_UINT32(inData + 12);
+
+ // Less data than the frame should have? Fail
+ if (dataLen < (frameDataLen - 16))
+ return false;
+
+ Common::MemoryReadStream frame(inData, dataLen);
+
+ frame.skip(16); // Header
+ frame.skip(2); // Unknown
+
+ uint16 flags1 = frame.readUint16LE();
+ uint32 flags3 = frame.readUint32LE();
+ uint8 flags2 = frame.readByte();
+
+ // Finding the reference frame
+ if (flags1 & 0x200) {
+ _cur_frame = _iv_frame + 1;
+ _ref_frame = _iv_frame;
+ } else {
+ _cur_frame = _iv_frame;
+ _ref_frame = _iv_frame + 1;
+ }
+
+ if (flags3 == 0x80)
+ return true;
+
+ frame.skip(3);
+
+ uint16 fHeight = frame.readUint16LE();
+ uint16 fWidth = frame.readUint16LE();
+
+ uint32 chromaHeight = ((fHeight >> 2) + 3) & 0x7FFC;
+ uint32 chromaWidth = ((fWidth >> 2) + 3) & 0x7FFC;
+
+ uint32 offs;
+ uint32 offsY = frame.readUint32LE() + 16;
+ uint32 offsU = frame.readUint32LE() + 16;
+ uint32 offsV = frame.readUint32LE() + 16;
+
+ frame.skip(4);
+
+ uint32 hPos = frame.pos();
+
+ byte *hdr_pos = inData + hPos;
+ byte *buf_pos;
+
+ // Luminance Y
+ frame.seek(offsY);
+ buf_pos = inData + offsY + 4;
+ offs = frame.readUint32LE();
+ decodeChunk(_cur_frame->Ybuf, _ref_frame->Ybuf, fWidth, fHeight,
+ buf_pos + offs * 2, flags2, hdr_pos, buf_pos, MIN<int>(fWidth, 160));
+
+ // Chrominance U
+ frame.seek(offsU);
+ buf_pos = inData + offsU + 4;
+ offs = frame.readUint32LE();
+ decodeChunk(_cur_frame->Vbuf, _ref_frame->Vbuf, chromaWidth, chromaHeight,
+ buf_pos + offs * 2, flags2, hdr_pos, buf_pos, MIN<int>(chromaWidth, 40));
+
+ // Chrominance V
+ frame.seek(offsV);
+ buf_pos = inData + offsV + 4;
+ offs = frame.readUint32LE();
+ decodeChunk(_cur_frame->Ubuf, _ref_frame->Ubuf, chromaWidth, chromaHeight,
+ buf_pos + offs * 2, flags2, hdr_pos, buf_pos, MIN<int>(chromaWidth, 40));
+
+ BlitState blitState;
+
+ blitState.widthY = _cur_frame->y_w;
+ blitState.widthUV = _cur_frame->uv_w;
+ blitState.uwidthUV = chromaWidth;
+ blitState.uwidthOut = fWidth;
+ blitState.heightY = _cur_frame->y_h;
+ blitState.heightUV = _cur_frame->uv_h;
+ blitState.uheightUV = chromaHeight;
+ blitState.uheightOut = fHeight;
+ blitState.scaleWYUV = blitState.widthY / blitState.widthUV;
+ blitState.scaleHYUV = blitState.heightY / blitState.heightUV;
+ blitState.scaleWYOut = blitState.widthY / blitState.uwidthOut;
+ blitState.scaleHYOut = blitState.heightY / blitState.uheightOut;
+ blitState.lineWidthOut = blitState.scaleWYOut * blitState.uwidthOut;
+ blitState.lineHeightOut = blitState.scaleHYOut * blitState.uheightOut;
+ blitState.bufY = _cur_frame->Ybuf;
+ blitState.bufU = _cur_frame->Ubuf;
+ blitState.bufV = _cur_frame->Vbuf;
+ blitState.bufOut = outData;
+
+ blitFrame(blitState);
+
+ return true;
+}
+
+void Indeo3::blitFrame(BlitState &s) {
+ if (_ditherSL)
+ _ditherSL->newFrame();
+
+ for (s.curY = 0; s.curY < s.uheightOut; s.curY++) {
+ if (_dither == kDitherNone)
+ blitLine(s);
+ else
+ blitLineDither(s);
+ }
+}
+
+void Indeo3::blitLine(BlitState &s) {
+ byte *lineU = s.bufU + (s.curY >> 2) * s.uwidthUV;
+ byte *lineV = s.bufV + (s.curY >> 2) * s.uwidthUV;
+
+ for (s.curX = 0; s.curX < s.uwidthOut; s.curX++) {
+ byte dataY = *s.bufY++;
+ byte dataU = lineU[s.curX >> 2];
+ byte dataV = lineV[s.curX >> 2];
+
+ for (int n = 0; n < s.scaleWYOut; n++)
+ *s.bufOut++ = _palLUT->findNearest(dataY, dataU, dataV);
+ }
+
+ byte *lineDest = s.bufOut - s.lineWidthOut;
+ for (int n = 1; n < s.scaleHYOut; n++) {
+ memcpy(s.bufOut, lineDest, s.lineWidthOut);
+ s.bufOut += s.lineWidthOut;
+ }
+}
+
+void Indeo3::blitLineDither(BlitState &s) {
+ byte *lineU = s.bufU + (s.curY >> 2) * s.uwidthUV;
+ byte *lineV = s.bufV + (s.curY >> 2) * s.uwidthUV;
+
+ for (uint16 i = 0; i < s.scaleHYOut; i++) {
+ byte *bufY = s.bufY;
+
+ for (s.curX = 0; s.curX < s.uwidthOut; s.curX++) {
+ byte dataY = *bufY++;
+ byte dataU = lineU[s.curX >> 2];
+ byte dataV = lineV[s.curX >> 2];
+
+ for (int n = 0; n < s.scaleWYOut; n++)
+ *s.bufOut++ = _ditherSL->dither(dataY, dataU, dataV, s.curX * s.scaleWYOut + n);
+
+ }
+
+ _ditherSL->nextLine();
+ }
+
+ s.bufY += s.uwidthOut;
+}
+
+typedef struct {
+ int32 xpos;
+ int32 ypos;
+ int32 width;
+ int32 height;
+ int32 split_flag;
+ int32 split_direction;
+ int32 usl7;
+} ustr_t;
+
+/* ---------------------------------------------------------------------- */
+
+#define LV1_CHECK(buf1,rle_v3,lv1,lp2) \
+ if ((lv1 & 0x80) != 0) { \
+ if (rle_v3 != 0) \
+ rle_v3 = 0; \
+ else { \
+ rle_v3 = 1; \
+ buf1 -= 2; \
+ } \
+ } \
+ lp2 = 4;
+
+
+#define RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3) \
+ if (rle_v3 == 0) { \
+ rle_v2 = *buf1; \
+ rle_v1 = 1; \
+ if (rle_v2 > 32) { \
+ rle_v2 -= 32; \
+ rle_v1 = 0; \
+ } \
+ rle_v3 = 1; \
+ } \
+ buf1--;
+
+
+#define LP2_CHECK(buf1,rle_v3,lp2) \
+ if (lp2 == 0 && rle_v3 != 0) \
+ rle_v3 = 0; \
+ else { \
+ buf1--; \
+ rle_v3 = 1; \
+ }
+
+
+#define RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2) \
+ rle_v2--; \
+ if (rle_v2 == 0) { \
+ rle_v3 = 0; \
+ buf1 += 2; \
+ } \
+ lp2 = 4;
+
+void Indeo3::decodeChunk(byte *cur, byte *ref, int width, int height,
+ const byte *buf1, uint32 fflags2, const byte *hdr,
+ const byte *buf2, int min_width_160) {
+
+ byte bit_buf;
+ uint32 bit_pos, lv, lv1, lv2;
+ int32 *width_tbl, width_tbl_arr[10];
+ const int8 *ref_vectors;
+ byte *cur_frm_pos, *ref_frm_pos, *cp, *cp2;
+ uint32 *cur_lp, *ref_lp;
+ const uint32 *correction_lp[2], *correctionloworder_lp[2], *correctionhighorder_lp[2];
+ uint16 *correction_type_sp[2];
+ ustr_t strip_tbl[20], *strip;
+ int i, j, k, lp1, lp2, flag1, cmd;
+ int blks_width, blks_height, region_160_width;
+ int rle_v1, rle_v2, rle_v3;
+ uint16 res;
+
+ bit_buf = 0;
+ ref_vectors = NULL;
+
+ width_tbl = width_tbl_arr + 1;
+ i = (width < 0 ? width + 3 : width)/4;
+ for (j = -1; j < 8; j++)
+ width_tbl[j] = i * j;
+
+ strip = strip_tbl;
+
+ for (region_160_width = 0; region_160_width < (width - min_width_160); region_160_width += min_width_160)
+ ;
+
+ strip->ypos = strip->xpos = 0;
+ for (strip->width = min_width_160; width > strip->width; strip->width *= 2)
+ ;
+ strip->height = height;
+ strip->split_direction = 0;
+ strip->split_flag = 0;
+ strip->usl7 = 0;
+
+ bit_pos = 0;
+
+ rle_v1 = rle_v2 = rle_v3 = 0;
+
+ while (strip >= strip_tbl) {
+ if (bit_pos <= 0) {
+ bit_pos = 8;
+ bit_buf = *buf1++;
+ }
+
+ bit_pos -= 2;
+ cmd = (bit_buf >> bit_pos) & 0x03;
+
+ if (cmd == 0) {
+ strip++;
+ memcpy(strip, strip-1, sizeof(ustr_t));
+ strip->split_flag = 1;
+ strip->split_direction = 0;
+ strip->height = (strip->height > 8 ? ((strip->height+8)>>4)<<3 : 4);
+ continue;
+ } else if (cmd == 1) {
+ strip++;
+ memcpy(strip, strip-1, sizeof(ustr_t));
+ strip->split_flag = 1;
+ strip->split_direction = 1;
+ strip->width = (strip->width > 8 ? ((strip->width+8)>>4)<<3 : 4);
+ continue;
+ } else if (cmd == 2) {
+ if (strip->usl7 == 0) {
+ strip->usl7 = 1;
+ ref_vectors = NULL;
+ continue;
+ }
+ } else if (cmd == 3) {
+ if (strip->usl7 == 0) {
+ strip->usl7 = 1;
+ ref_vectors = (const signed char*)buf2 + (*buf1 * 2);
+ buf1++;
+ continue;
+ }
+ }
+
+ cur_frm_pos = cur + width * strip->ypos + strip->xpos;
+
+ if ((blks_width = strip->width) < 0)
+ blks_width += 3;
+ blks_width >>= 2;
+ blks_height = strip->height;
+
+ if (ref_vectors != NULL) {
+ ref_frm_pos = ref + (ref_vectors[0] + strip->ypos) * width +
+ ref_vectors[1] + strip->xpos;
+ } else
+ ref_frm_pos = cur_frm_pos - width_tbl[4];
+
+ if (cmd == 2) {
+ if (bit_pos <= 0) {
+ bit_pos = 8;
+ bit_buf = *buf1++;
+ }
+
+ bit_pos -= 2;
+ cmd = (bit_buf >> bit_pos) & 0x03;
+
+ if (cmd == 0 || ref_vectors != NULL) {
+ for (lp1 = 0; lp1 < blks_width; lp1++) {
+ for (i = 0, j = 0; i < blks_height; i++, j += width_tbl[1])
+ ((uint32 *)cur_frm_pos)[j] = ((uint32 *)ref_frm_pos)[j];
+ cur_frm_pos += 4;
+ ref_frm_pos += 4;
+ }
+ } else if (cmd != 1)
+ return;
+ } else {
+ k = *buf1 >> 4;
+ j = *buf1 & 0x0f;
+ buf1++;
+ lv = j + fflags2;
+
+ if ((lv - 8) <= 7 && (k == 0 || k == 3 || k == 10)) {
+ cp2 = _ModPred + ((lv - 8) << 7);
+ cp = ref_frm_pos;
+ for (i = 0; i < blks_width << 2; i++) {
+ int v = *cp >> 1;
+ *(cp++) = cp2[v];
+ }
+ }
+
+ if (k == 1 || k == 4) {
+ lv = (hdr[j] & 0xf) + fflags2;
+ correction_type_sp[0] = _corrector_type + (lv << 8);
+ correction_lp[0] = correction + (lv << 8);
+ lv = (hdr[j] >> 4) + fflags2;
+ correction_lp[1] = correction + (lv << 8);
+ correction_type_sp[1] = _corrector_type + (lv << 8);
+ } else {
+ correctionloworder_lp[0] = correctionloworder_lp[1] = correctionloworder + (lv << 8);
+ correctionhighorder_lp[0] = correctionhighorder_lp[1] = correctionhighorder + (lv << 8);
+ correction_type_sp[0] = correction_type_sp[1] = _corrector_type + (lv << 8);
+ correction_lp[0] = correction_lp[1] = correction + (lv << 8);
+ }
+
+ switch(k) {
+ case 1:
+ case 0: /********** CASE 0 **********/
+ for ( ; blks_height > 0; blks_height -= 4) {
+ for (lp1 = 0; lp1 < blks_width; lp1++) {
+ for (lp2 = 0; lp2 < 4; ) {
+ k = *buf1++;
+ cur_lp = ((uint32 *)cur_frm_pos) + width_tbl[lp2];
+ ref_lp = ((uint32 *)ref_frm_pos) + width_tbl[lp2];
+
+ switch(correction_type_sp[0][k]) {
+ case 0:
+ *cur_lp = FROM_LE_32(((FROM_LE_32(*ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1);
+ lp2++;
+ break;
+ case 1:
+ res = ((FROM_LE_16(((uint16 *)(ref_lp))[0]) >> 1) + correction_lp[lp2 & 0x01][*buf1]) << 1;
+ ((uint16 *)cur_lp)[0] = FROM_LE_16(res);
+ res = ((FROM_LE_16(((uint16 *)(ref_lp))[1]) >> 1) + correction_lp[lp2 & 0x01][k]) << 1;
+ ((uint16 *)cur_lp)[1] = FROM_LE_16(res);
+ buf1++;
+ lp2++;
+ break;
+ case 2:
+ if (lp2 == 0) {
+ for (i = 0, j = 0; i < 2; i++, j += width_tbl[1])
+ cur_lp[j] = ref_lp[j];
+ lp2 += 2;
+ }
+ break;
+ case 3:
+ if (lp2 < 2) {
+ for (i = 0, j = 0; i < (3 - lp2); i++, j += width_tbl[1])
+ cur_lp[j] = ref_lp[j];
+ lp2 = 3;
+ }
+ break;
+ case 8:
+ if (lp2 == 0) {
+ RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)
+
+ if (rle_v1 == 1 || ref_vectors != NULL) {
+ for (i = 0, j = 0; i < 4; i++, j += width_tbl[1])
+ cur_lp[j] = ref_lp[j];
+ }
+
+ RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2)
+ break;
+ } else {
+ rle_v1 = 1;
+ rle_v2 = *buf1 - 1;
+ }
+ case 5:
+ LP2_CHECK(buf1,rle_v3,lp2)
+ case 4:
+ for (i = 0, j = 0; i < (4 - lp2); i++, j += width_tbl[1])
+ cur_lp[j] = ref_lp[j];
+ lp2 = 4;
+ break;
+
+ case 7:
+ if (rle_v3 != 0)
+ rle_v3 = 0;
+ else {
+ buf1--;
+ rle_v3 = 1;
+ }
+ case 6:
+ if (ref_vectors != NULL) {
+ for (i = 0, j = 0; i < 4; i++, j += width_tbl[1])
+ cur_lp[j] = ref_lp[j];
+ }
+ lp2 = 4;
+ break;
+
+ case 9:
+ lv1 = *buf1++;
+ lv = (lv1 & 0x7F) << 1;
+ lv += (lv << 8);
+ lv += (lv << 16);
+ for (i = 0, j = 0; i < 4; i++, j += width_tbl[1])
+ cur_lp[j] = lv;
+
+ LV1_CHECK(buf1,rle_v3,lv1,lp2)
+ break;
+ default:
+ return;
+ }
+ }
+
+ cur_frm_pos += 4;
+ ref_frm_pos += 4;
+ }
+
+ cur_frm_pos += ((width - blks_width) * 4);
+ ref_frm_pos += ((width - blks_width) * 4);
+ }
+ break;
+
+ case 4:
+ case 3: /********** CASE 3 **********/
+ if (ref_vectors != NULL)
+ return;
+ flag1 = 1;
+
+ for ( ; blks_height > 0; blks_height -= 8) {
+ for (lp1 = 0; lp1 < blks_width; lp1++) {
+ for (lp2 = 0; lp2 < 4; ) {
+ k = *buf1++;
+
+ cur_lp = ((uint32 *)cur_frm_pos) + width_tbl[lp2 * 2];
+ ref_lp = ((uint32 *)cur_frm_pos) + width_tbl[(lp2 * 2) - 1];
+
+ switch(correction_type_sp[lp2 & 0x01][k]) {
+ case 0:
+ cur_lp[width_tbl[1]] = FROM_LE_32(((FROM_LE_32(*ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1);
+ if (lp2 > 0 || flag1 == 0 || strip->ypos != 0)
+ cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
+ else
+ cur_lp[0] = FROM_LE_32(((FROM_LE_32(*ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1);
+ lp2++;
+ break;
+
+ case 1:
+ res = ((FROM_LE_16(((uint16 *)ref_lp)[0]) >> 1) + correction_lp[lp2 & 0x01][*buf1]) << 1;
+ ((uint16 *)cur_lp)[width_tbl[2]] = FROM_LE_16(res);
+ res = ((FROM_LE_16(((uint16 *)ref_lp)[1]) >> 1) + correction_lp[lp2 & 0x01][k]) << 1;
+ ((uint16 *)cur_lp)[width_tbl[2]+1] = FROM_LE_16(res);
+
+ if (lp2 > 0 || flag1 == 0 || strip->ypos != 0)
+ cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
+ else
+ cur_lp[0] = cur_lp[width_tbl[1]];
+ buf1++;
+ lp2++;
+ break;
+
+ case 2:
+ if (lp2 == 0) {
+ for (i = 0, j = 0; i < 4; i++, j += width_tbl[1])
+ cur_lp[j] = *ref_lp;
+ lp2 += 2;
+ }
+ break;
+
+ case 3:
+ if (lp2 < 2) {
+ for (i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1])
+ cur_lp[j] = *ref_lp;
+ lp2 = 3;
+ }
+ break;
+
+ case 6:
+ lp2 = 4;
+ break;
+
+ case 7:
+ if (rle_v3 != 0)
+ rle_v3 = 0;
+ else {
+ buf1--;
+ rle_v3 = 1;
+ }
+ lp2 = 4;
+ break;
+
+ case 8:
+ if (lp2 == 0) {
+ RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)
+
+ if (rle_v1 == 1) {
+ for (i = 0, j = 0; i < 8; i++, j += width_tbl[1])
+ cur_lp[j] = ref_lp[j];
+ }
+
+ RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2)
+ break;
+ } else {
+ rle_v2 = (*buf1) - 1;
+ rle_v1 = 1;
+ }
+ case 5:
+ LP2_CHECK(buf1,rle_v3,lp2)
+ case 4:
+ for (i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1])
+ cur_lp[j] = *ref_lp;
+ lp2 = 4;
+ break;
+
+ case 9:
+ warning("Indeo3::decodeChunk: Untested (1)");
+ lv1 = *buf1++;
+ lv = (lv1 & 0x7F) << 1;
+ lv += (lv << 8);
+ lv += (lv << 16);
+
+ for (i = 0, j = 0; i < 4; i++, j += width_tbl[1])
+ cur_lp[j] = lv;
+
+ LV1_CHECK(buf1,rle_v3,lv1,lp2)
+ break;
+
+ default:
+ return;
+ }
+ }
+
+ cur_frm_pos += 4;
+ }
+
+ cur_frm_pos += (((width * 2) - blks_width) * 4);
+ flag1 = 0;
+ }
+ break;
+
+ case 10: /********** CASE 10 **********/
+ if (ref_vectors == NULL) {
+ flag1 = 1;
+
+ for ( ; blks_height > 0; blks_height -= 8) {
+ for (lp1 = 0; lp1 < blks_width; lp1 += 2) {
+ for (lp2 = 0; lp2 < 4; ) {
+ k = *buf1++;
+ cur_lp = ((uint32 *)cur_frm_pos) + width_tbl[lp2 * 2];
+ ref_lp = ((uint32 *)cur_frm_pos) + width_tbl[(lp2 * 2) - 1];
+ lv1 = ref_lp[0];
+ lv2 = ref_lp[1];
+ if (lp2 == 0 && flag1 != 0) {
+#if defined(SCUMM_BIG_ENDIAN)
+ lv1 = lv1 & 0xFF00FF00;
+ lv1 = (lv1 >> 8) | lv1;
+ lv2 = lv2 & 0xFF00FF00;
+ lv2 = (lv2 >> 8) | lv2;
+#else
+ lv1 = lv1 & 0x00FF00FF;
+ lv1 = (lv1 << 8) | lv1;
+ lv2 = lv2 & 0x00FF00FF;
+ lv2 = (lv2 << 8) | lv2;
+#endif
+ }
+
+ switch(correction_type_sp[lp2 & 0x01][k]) {
+ case 0:
+ cur_lp[width_tbl[1]] = FROM_LE_32(((FROM_LE_32(lv1) >> 1) + correctionloworder_lp[lp2 & 0x01][k]) << 1);
+ cur_lp[width_tbl[1]+1] = FROM_LE_32(((FROM_LE_32(lv2) >> 1) + correctionhighorder_lp[lp2 & 0x01][k]) << 1);
+ if (lp2 > 0 || strip->ypos != 0 || flag1 == 0) {
+ cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
+ cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
+ } else {
+ cur_lp[0] = cur_lp[width_tbl[1]];
+ cur_lp[1] = cur_lp[width_tbl[1]+1];
+ }
+ lp2++;
+ break;
+
+ case 1:
+ cur_lp[width_tbl[1]] = FROM_LE_32(((FROM_LE_32(lv1) >> 1) + correctionloworder_lp[lp2 & 0x01][*buf1]) << 1);
+ cur_lp[width_tbl[1]+1] = FROM_LE_32(((FROM_LE_32(lv2) >> 1) + correctionloworder_lp[lp2 & 0x01][k]) << 1);
+ if (lp2 > 0 || strip->ypos != 0 || flag1 == 0) {
+ cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
+ cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
+ } else {
+ cur_lp[0] = cur_lp[width_tbl[1]];
+ cur_lp[1] = cur_lp[width_tbl[1]+1];
+ }
+ buf1++;
+ lp2++;
+ break;
+
+ case 2:
+ if (lp2 == 0) {
+ if (flag1 != 0) {
+ for (i = 0, j = width_tbl[1]; i < 3; i++, j += width_tbl[1]) {
+ cur_lp[j] = lv1;
+ cur_lp[j+1] = lv2;
+ }
+ cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
+ cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
+ } else {
+ for (i = 0, j = 0; i < 4; i++, j += width_tbl[1]) {
+ cur_lp[j] = lv1;
+ cur_lp[j+1] = lv2;
+ }
+ }
+ lp2 += 2;
+ }
+ break;
+
+ case 3:
+ if (lp2 < 2) {
+ if (lp2 == 0 && flag1 != 0) {
+ for (i = 0, j = width_tbl[1]; i < 5; i++, j += width_tbl[1]) {
+ cur_lp[j] = lv1;
+ cur_lp[j+1] = lv2;
+ }
+ cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
+ cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
+ } else {
+ for (i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1]) {
+ cur_lp[j] = lv1;
+ cur_lp[j+1] = lv2;
+ }
+ }
+ lp2 = 3;
+ }
+ break;
+
+ case 8:
+ if (lp2 == 0) {
+ RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)
+ if (rle_v1 == 1) {
+ if (flag1 != 0) {
+ for (i = 0, j = width_tbl[1]; i < 7; i++, j += width_tbl[1]) {
+ cur_lp[j] = lv1;
+ cur_lp[j+1] = lv2;
+ }
+ cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
+ cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
+ } else {
+ for (i = 0, j = 0; i < 8; i++, j += width_tbl[1]) {
+ cur_lp[j] = lv1;
+ cur_lp[j+1] = lv2;
+ }
+ }
+ }
+ RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2)
+ break;
+ } else {
+ rle_v1 = 1;
+ rle_v2 = (*buf1) - 1;
+ }
+ case 5:
+ LP2_CHECK(buf1,rle_v3,lp2)
+ case 4:
+ if (lp2 == 0 && flag1 != 0) {
+ for (i = 0, j = width_tbl[1]; i < 7; i++, j += width_tbl[1]) {
+ cur_lp[j] = lv1;
+ cur_lp[j+1] = lv2;
+ }
+ cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
+ cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
+ } else {
+ for (i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1]) {
+ cur_lp[j] = lv1;
+ cur_lp[j+1] = lv2;
+ }
+ }
+ lp2 = 4;
+ break;
+
+ case 6:
+ lp2 = 4;
+ break;
+
+ case 7:
+ if (lp2 == 0) {
+ if (rle_v3 != 0)
+ rle_v3 = 0;
+ else {
+ buf1--;
+ rle_v3 = 1;
+ }
+ lp2 = 4;
+ }
+ break;
+
+ case 9:
+ warning("Indeo3::decodeChunk: Untested (2)");
+ lv1 = *buf1;
+ lv = (lv1 & 0x7F) << 1;
+ lv += (lv << 8);
+ lv += (lv << 16);
+ for (i = 0, j = 0; i < 8; i++, j += width_tbl[1])
+ cur_lp[j] = lv;
+ LV1_CHECK(buf1,rle_v3,lv1,lp2)
+ break;
+
+ default:
+ return;
+ }
+ }
+
+ cur_frm_pos += 8;
+ }
+
+ cur_frm_pos += (((width * 2) - blks_width) * 4);
+ flag1 = 0;
+ }
+ } else {
+ for ( ; blks_height > 0; blks_height -= 8) {
+ for (lp1 = 0; lp1 < blks_width; lp1 += 2) {
+ for (lp2 = 0; lp2 < 4; ) {
+ k = *buf1++;
+ cur_lp = ((uint32 *)cur_frm_pos) + width_tbl[lp2 * 2];
+ ref_lp = ((uint32 *)ref_frm_pos) + width_tbl[lp2 * 2];
+
+ switch(correction_type_sp[lp2 & 0x01][k]) {
+ case 0:
+ lv1 = correctionloworder_lp[lp2 & 0x01][k];
+ lv2 = correctionhighorder_lp[lp2 & 0x01][k];
+ cur_lp[0] = FROM_LE_32(((FROM_LE_32(ref_lp[0]) >> 1) + lv1) << 1);
+ cur_lp[1] = FROM_LE_32(((FROM_LE_32(ref_lp[1]) >> 1) + lv2) << 1);
+ cur_lp[width_tbl[1]] = FROM_LE_32(((FROM_LE_32(ref_lp[width_tbl[1]]) >> 1) + lv1) << 1);
+ cur_lp[width_tbl[1]+1] = FROM_LE_32(((FROM_LE_32(ref_lp[width_tbl[1]+1]) >> 1) + lv2) << 1);
+ lp2++;
+ break;
+
+ case 1:
+ lv1 = correctionloworder_lp[lp2 & 0x01][*buf1++];
+ lv2 = correctionloworder_lp[lp2 & 0x01][k];
+ cur_lp[0] = FROM_LE_32(((FROM_LE_32(ref_lp[0]) >> 1) + lv1) << 1);
+ cur_lp[1] = FROM_LE_32(((FROM_LE_32(ref_lp[1]) >> 1) + lv2) << 1);
+ cur_lp[width_tbl[1]] = FROM_LE_32(((FROM_LE_32(ref_lp[width_tbl[1]]) >> 1) + lv1) << 1);
+ cur_lp[width_tbl[1]+1] = FROM_LE_32(((FROM_LE_32(ref_lp[width_tbl[1]+1]) >> 1) + lv2) << 1);
+ lp2++;
+ break;
+
+ case 2:
+ if (lp2 == 0) {
+ for (i = 0, j = 0; i < 4; i++, j += width_tbl[1]) {
+ cur_lp[j] = ref_lp[j];
+ cur_lp[j+1] = ref_lp[j+1];
+ }
+ lp2 += 2;
+ }
+ break;
+
+ case 3:
+ if (lp2 < 2) {
+ for (i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1]) {
+ cur_lp[j] = ref_lp[j];
+ cur_lp[j+1] = ref_lp[j+1];
+ }
+ lp2 = 3;
+ }
+ break;
+
+ case 8:
+ if (lp2 == 0) {
+ RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)
+ for (i = 0, j = 0; i < 8; i++, j += width_tbl[1]) {
+ ((uint32 *)cur_frm_pos)[j] = ((uint32 *)ref_frm_pos)[j];
+ ((uint32 *)cur_frm_pos)[j+1] = ((uint32 *)ref_frm_pos)[j+1];
+ }
+ RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2)
+ break;
+ } else {
+ rle_v1 = 1;
+ rle_v2 = (*buf1) - 1;
+ }
+ case 5:
+ case 7:
+ LP2_CHECK(buf1,rle_v3,lp2)
+ case 6:
+ case 4:
+ for (i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1]) {
+ cur_lp[j] = ref_lp[j];
+ cur_lp[j+1] = ref_lp[j+1];
+ }
+ lp2 = 4;
+ break;
+
+ case 9:
+ warning("Indeo3::decodeChunk: Untested (3)");
+ lv1 = *buf1;
+ lv = (lv1 & 0x7F) << 1;
+ lv += (lv << 8);
+ lv += (lv << 16);
+ for (i = 0, j = 0; i < 8; i++, j += width_tbl[1])
+ ((uint32 *)cur_frm_pos)[j] = ((uint32 *)cur_frm_pos)[j+1] = lv;
+ LV1_CHECK(buf1,rle_v3,lv1,lp2)
+ break;
+
+ default:
+ return;
+ }
+ }
+
+ cur_frm_pos += 8;
+ ref_frm_pos += 8;
+ }
+
+ cur_frm_pos += (((width * 2) - blks_width) * 4);
+ ref_frm_pos += (((width * 2) - blks_width) * 4);
+ }
+ }
+ break;
+
+ case 11: /********** CASE 11 **********/
+ if (ref_vectors == NULL)
+ return;
+
+ for ( ; blks_height > 0; blks_height -= 8) {
+ for (lp1 = 0; lp1 < blks_width; lp1++) {
+ for (lp2 = 0; lp2 < 4; ) {
+ k = *buf1++;
+ cur_lp = ((uint32 *)cur_frm_pos) + width_tbl[lp2 * 2];
+ ref_lp = ((uint32 *)ref_frm_pos) + width_tbl[lp2 * 2];
+
+ switch(correction_type_sp[lp2 & 0x01][k]) {
+ case 0:
+ cur_lp[0] = FROM_LE_32(((FROM_LE_32(*ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1);
+ cur_lp[width_tbl[1]] = FROM_LE_32(((FROM_LE_32(ref_lp[width_tbl[1]]) >> 1) + correction_lp[lp2 & 0x01][k]) << 1);
+ lp2++;
+ break;
+
+ case 1:
+ lv1 = (uint16)(correction_lp[lp2 & 0x01][*buf1++]);
+ lv2 = (uint16)(correction_lp[lp2 & 0x01][k]);
+ res = (uint16)(((FROM_LE_16(((uint16 *)ref_lp)[0]) >> 1) + lv1) << 1);
+ ((uint16 *)cur_lp)[0] = FROM_LE_16(res);
+ res = (uint16)(((FROM_LE_16(((uint16 *)ref_lp)[1]) >> 1) + lv2) << 1);
+ ((uint16 *)cur_lp)[1] = FROM_LE_16(res);
+ res = (uint16)(((FROM_LE_16(((uint16 *)ref_lp)[width_tbl[2]]) >> 1) + lv1) << 1);
+ ((uint16 *)cur_lp)[width_tbl[2]] = FROM_LE_16(res);
+ res = (uint16)(((FROM_LE_16(((uint16 *)ref_lp)[width_tbl[2]+1]) >> 1) + lv2) << 1);
+ ((uint16 *)cur_lp)[width_tbl[2]+1] = FROM_LE_16(res);
+ lp2++;
+ break;
+
+ case 2:
+ if (lp2 == 0) {
+ for (i = 0, j = 0; i < 4; i++, j += width_tbl[1])
+ cur_lp[j] = ref_lp[j];
+ lp2 += 2;
+ }
+ break;
+
+ case 3:
+ if (lp2 < 2) {
+ for (i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1])
+ cur_lp[j] = ref_lp[j];
+ lp2 = 3;
+ }
+ break;
+
+ case 8:
+ if (lp2 == 0) {
+ RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)
+
+ for (i = 0, j = 0; i < 8; i++, j += width_tbl[1])
+ cur_lp[j] = ref_lp[j];
+
+ RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2)
+ break;
+ } else {
+ rle_v1 = 1;
+ rle_v2 = (*buf1) - 1;
+ }
+ case 5:
+ case 7:
+ LP2_CHECK(buf1,rle_v3,lp2)
+ case 4:
+ case 6:
+ for (i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1])
+ cur_lp[j] = ref_lp[j];
+ lp2 = 4;
+ break;
+
+ case 9:
+ warning("Indeo3::decodeChunk: Untested (4)");
+ lv1 = *buf1++;
+ lv = (lv1 & 0x7F) << 1;
+ lv += (lv << 8);
+ lv += (lv << 16);
+ for (i = 0, j = 0; i < 4; i++, j += width_tbl[1])
+ cur_lp[j] = lv;
+ LV1_CHECK(buf1,rle_v3,lv1,lp2)
+ break;
+
+ default:
+ return;
+ }
+ }
+
+ cur_frm_pos += 4;
+ ref_frm_pos += 4;
+ }
+
+ cur_frm_pos += (((width * 2) - blks_width) * 4);
+ ref_frm_pos += (((width * 2) - blks_width) * 4);
+ }
+ break;
+
+ default:
+ // FIXME: I've seen case 12 and 13 happen in Urban
+ // Runner. Perhaps it uses a more recent form of
+ // Indeo 3? There appears to have been several.
+ warning("Indeo3::decodeChunk: Unknown case %d", k);
+ return;
+ }
+ }
+
+ if (strip < strip_tbl)
+ return;
+
+ for ( ; strip >= strip_tbl; strip--) {
+ if (strip->split_flag != 0) {
+ strip->split_flag = 0;
+ strip->usl7 = (strip-1)->usl7;
+
+ if (strip->split_direction) {
+ strip->xpos += strip->width;
+ strip->width = (strip-1)->width - strip->width;
+ if (region_160_width <= strip->xpos && width < strip->width + strip->xpos)
+ strip->width = width - strip->xpos;
+ } else {
+ strip->ypos += strip->height;
+ strip->height = (strip-1)->height - strip->height;
+ }
+ break;
+ }
+ }
+ }
+}
+
+} // End of namespace Graphics
Property changes on: scummvm/trunk/graphics/video/coktelvideo/indeo3.cpp
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:mergeinfo
+
Added: svn:eol-style
+ native
Copied: scummvm/trunk/graphics/video/coktelvideo/indeo3.h (from rev 40752, scummvm/trunk/graphics/video/indeo3.h)
===================================================================
--- scummvm/trunk/graphics/video/coktelvideo/indeo3.h (rev 0)
+++ scummvm/trunk/graphics/video/coktelvideo/indeo3.h 2009-05-21 10:48:03 UTC (rev 40755)
@@ -0,0 +1,120 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+/* Intel Indeo 3 decompressor, derived from ffmpeg.
+ *
+ * Original copyright note:
+ * Intel Indeo 3 (IV31, IV32, etc.) video decoder for ffmpeg
+ * written, produced, and directed by Alan Smithee
+ */
+
+#ifndef GRAPHICS_VIDEO_INDEO3_H
+#define GRAPHICS_VIDEO_INDEO3_H
+
+#include "common/stream.h"
+
+namespace Graphics {
+ class PaletteLUT;
+ class SierraLight;
+}
+
+namespace Graphics {
+
+class Indeo3 {
+public:
+ enum DitherAlgorithm {
+ kDitherNone = 0,
+ kDitherSierraLight
+ };
+
+ Indeo3(int16 width, int16 height, Graphics::PaletteLUT *palLUT);
+ ~Indeo3();
+
+ static bool isIndeo3(byte *data, uint32 dataLen);
+
+ void setDither(DitherAlgorithm dither);
+
+ bool decompressFrame(byte *inData, uint32 dataLen,
+ byte *outData, uint16 width, uint16 height);
+
+private:
+ static const int _corrector_type_0[24];
+ static const int _corrector_type_2[8];
+ static const uint32 correction[];
+ static const uint32 correctionloworder[];
+ static const uint32 correctionhighorder[];
+
+ struct YUVBufs {
+ byte *Ybuf;
+ byte *Ubuf;
+ byte *Vbuf;
+ byte *the_buf;
+ uint32 the_buf_size;
+ uint16 y_w, y_h;
+ uint16 uv_w, uv_h;
+ };
+
+ int16 _width;
+ int16 _height;
+ YUVBufs _iv_frame[2];
+ YUVBufs *_cur_frame;
+ YUVBufs *_ref_frame;
+
+ byte *_ModPred;
+ uint16 *_corrector_type;
+
+ Graphics::PaletteLUT *_palLUT;
+
+ DitherAlgorithm _dither;
+ Graphics::SierraLight *_ditherSL;
+
+ struct BlitState {
+ uint32 curX, curY;
+ uint16 widthY, widthUV;
+ uint16 heightY, heightUV;
+ uint16 uwidthUV, uwidthOut;
+ uint16 uheightUV, uheightOut;
+ uint16 scaleWYUV, scaleWYOut;
+ uint16 scaleHYUV, scaleHYOut;
+ uint16 lineWidthOut, lineHeightOut;
+ byte *bufY, *bufU, *bufV, *bufOut;
+ };
+
+ void buildModPred();
+ void allocFrames();
+
+ void decodeChunk(byte *cur, byte *ref, int width, int height,
+ const byte *buf1, uint32 fflags2, const byte *hdr,
+ const byte *buf2, int min_width_160);
+
+ void blitFrame(BlitState &s);
+
+ void blitLine(BlitState &s);
+ void blitLineDither(BlitState &s);
+};
+
+} // End of namespace Graphics
+
+#endif // GRAPHICS_VIDEO_INDEO3_H
Property changes on: scummvm/trunk/graphics/video/coktelvideo/indeo3.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:mergeinfo
+
Added: svn:eol-style
+ native
Copied: scummvm/trunk/graphics/video/coktelvideo/indeo3data.h (from rev 40752, scummvm/trunk/graphics/video/indeo3data.h)
===================================================================
--- scummvm/trunk/graphics/video/coktelvideo/indeo3data.h (rev 0)
+++ scummvm/trunk/graphics/video/coktelvideo/indeo3data.h 2009-05-21 10:48:03 UTC (rev 40755)
@@ -0,0 +1,2358 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+/* Intel Indeo 3 decompressor, derived from ffmpeg.
+ *
+ * Original copyright note:
+ * Intel Indeo 3 (IV31, IV32, etc.) video decoder for ffmpeg
+ * written, produced, and directed by Alan Smithee
+ */
+
+namespace Graphics {
+
+const int Indeo3::_corrector_type_0[24] = {
+ 195, 159, 133, 115, 101, 93, 87, 77,
+ 195, 159, 133, 115, 101, 93, 87, 77,
+ 128, 79, 79, 79, 79, 79, 79, 79
+};
+
+const int Indeo3::_corrector_type_2[8] = { 9, 7, 6, 8, 5, 4, 3, 2 };
+
+const uint32 Indeo3::correction[] = {
+ 0x00000000, 0x00000202, 0xfffffdfe, 0x000002ff, 0xfffffd01, 0xffffff03, 0x000000fd, 0x00000404,
+ 0xfffffbfc, 0x00000501, 0xfffffaff, 0x00000105, 0xfffffefb, 0x000003fc, 0xfffffc04, 0x000005fe,
+ 0xfffffa02, 0xfffffe06, 0x000001fa, 0x00000904, 0xfffff6fc, 0x00000409, 0xfffffbf7, 0x00000909,
+ 0xfffff6f7, 0x00000a01, 0xfffff5ff, 0x0000010a, 0xfffffef6, 0x000007fb, 0xfffff805, 0xfffffb08,
+ 0x000004f8, 0x00000f09, 0xfffff0f7, 0x0000090f, 0xfffff6f1, 0x00000bfd, 0xfffff403, 0xfffffd0c,
+ 0x000002f4, 0x00001004, 0xffffeffc, 0x00000410, 0xfffffbf0, 0x00001010, 0xffffeff0, 0x00001200,
+ 0xffffee00, 0x00000012, 0xffffffee, 0x00000bf4, 0xfffff40c, 0x00000ff7, 0xfffff009, 0xfffff710,
+ 0x000008f0, 0x00001b0b, 0xffffe4f5, 0x00000b1b, 0xfffff4e5, 0x00001c13, 0xffffe3ed, 0x0000131c,
+ 0xffffece4, 0x000015fa, 0xffffea06, 0xfffffa16, 0x000005ea, 0x00001d04, 0xffffe2fc, 0x0000041d,
+ 0xfffffbe3, 0x00001e1e, 0xffffe1e2, 0x000020fe, 0xffffdf02, 0xfffffe21, 0x000001df, 0x000016ee,
+ 0xffffe912, 0xffffee17, 0x000011e9, 0x00001df1, 0xffffe20f, 0xfffff11e, 0x00000ee2, 0x00002e16,
+ 0xffffd1ea, 0x0000162e, 0xffffe9d2, 0x00002f0d, 0xffffd0f3, 0x00000d2f, 0xfffff2d1, 0x00003123,
+ 0xffffcedd, 0x00002331, 0xffffdccf, 0x000028f5, 0xffffd70b, 0xfffff529, 0x00000ad7, 0x00003304,
+ 0xffffccfc, 0x00000433, 0xfffffbcd, 0x00003636, 0xffffc9ca, 0x000021de, 0xffffde22, 0x000029e3,
+ 0xffffd61d, 0xffffe32a, 0x00001cd6, 0x00003bfa, 0xffffc406, 0xfffffa3c, 0x000005c4, 0x00004c1b,
+ 0xffffb3e5, 0x00001b4c, 0xffffe4b4, 0x00004d2b, 0xffffb2d5, 0x00002b4d, 0xffffd4b3, 0x000036e8,
+ 0xffffc918, 0xffffe837, 0x000017c9, 0x00004f0e, 0xffffb0f2, 0x00000e4f, 0xfffff1b1, 0x0000533f,
+ 0xffffacc1, 0x00003f53, 0xffffc0ad, 0x000049ec, 0xffffb614, 0xffffec4a, 0x000013b6, 0x00005802,
+ 0xffffa7fe, 0x00000258, 0xfffffda8, 0x00005d5d, 0xffffa2a3, 0x00003ccc, 0xffffc334, 0xffffcc3d,
+ 0x000033c3, 0x00007834, 0xffff87cc, 0x00003478, 0xffffcb88, 0x00004ad3, 0xffffb52d, 0xffffd34b,
+ 0x00002cb5, 0x00007d4b, 0xffff82b5, 0x00004b7d, 0xffffb483, 0x00007a21, 0xffff85df, 0x0000217a,
+ 0xffffde86, 0x000066f3, 0xffff990d, 0xfffff367, 0x00000c99, 0x00005fd8, 0xffffa028, 0xffffd860,
+ 0x000027a0, 0x00007ede, 0xffff8122, 0xffffde7f, 0x00002181, 0x000058a7, 0xffffa759, 0x000068b2,
+ 0xffff974e, 0xffffb269, 0x00004d97, 0x00000c0c, 0xfffff3f4, 0x00001717, 0xffffe8e9, 0x00002a2a,
+ 0xffffd5d6, 0x00004949, 0xffffb6b7, 0x00000000, 0x02020000, 0xfdfe0000, 0x02ff0000, 0xfd010000,
+ 0xff030000, 0x00fd0000, 0x00000202, 0x02020202, 0xfdfe0202, 0x02ff0202, 0xfd010202, 0xff030202,
+ 0x00fd0202, 0xfffffdfe, 0x0201fdfe, 0xfdfdfdfe, 0x02fefdfe, 0xfd00fdfe, 0xff02fdfe, 0x00fcfdfe,
+ 0x000002ff, 0x020202ff, 0xfdfe02ff, 0x02ff02ff, 0xfd0102ff, 0xff0302ff, 0x00fd02ff, 0xfffffd01,
+ 0x0201fd01, 0xfdfdfd01, 0x02fefd01, 0xfd00fd01, 0xff02fd01, 0x00fcfd01, 0xffffff03, 0x0201ff03,
+ 0xfdfdff03, 0x02feff03, 0xfd00ff03, 0xff02ff03, 0x00fcff03, 0x000000fd, 0x020200fd, 0xfdfe00fd,
+ 0x02ff00fd, 0xfd0100fd, 0xff0300fd, 0x00fd00fd, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
+ 0x00000000, 0x00000303, 0xfffffcfd, 0x000003ff, 0xfffffc01, 0xffffff04, 0x000000fc, 0x00000707,
+ 0xfffff8f9, 0x00000802, 0xfffff7fe, 0x00000208, 0xfffffdf8, 0x000008fe, 0xfffff702, 0xfffffe09,
+ 0x000001f7, 0x000005fa, 0xfffffa06, 0x00000d06, 0xfffff2fa, 0x0000060d, 0xfffff9f3, 0x00000d0d,
@@ Diff output truncated at 100000 characters. @@
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list