diff options
author | RichieSams | 2013-11-01 00:21:08 -0500 |
---|---|---|
committer | RichieSams | 2013-11-01 02:52:57 -0500 |
commit | 5842c5098fbd00c8ab5245ba1d6ca9c2675e3da4 (patch) | |
tree | bdb138d047faae28893bdf37758940916a091a12 /engines/zvision/video | |
parent | 651bf899399de2b5c2d8e62a5bb4964b037950d2 (diff) | |
download | scummvm-rg350-5842c5098fbd00c8ab5245ba1d6ca9c2675e3da4.tar.gz scummvm-rg350-5842c5098fbd00c8ab5245ba1d6ca9c2675e3da4.tar.bz2 scummvm-rg350-5842c5098fbd00c8ab5245ba1d6ca9c2675e3da4.zip |
ZVISION: Create a folder structure for ZVision source files
I personally used filters within my IDE, but since others are now joining the project,
it was brought to my attention that some better organization would be nice.
Diffstat (limited to 'engines/zvision/video')
-rw-r--r-- | engines/zvision/video/video.cpp | 171 | ||||
-rw-r--r-- | engines/zvision/video/zork_avi_decoder.cpp | 53 | ||||
-rw-r--r-- | engines/zvision/video/zork_avi_decoder.h | 60 |
3 files changed, 284 insertions, 0 deletions
diff --git a/engines/zvision/video/video.cpp b/engines/zvision/video/video.cpp new file mode 100644 index 0000000000..894ae3a055 --- /dev/null +++ b/engines/zvision/video/video.cpp @@ -0,0 +1,171 @@ +/* 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. + * + */ + +#include "common/scummsys.h" + +#include "zvision/zvision.h" + +#include "zvision/clock.h" +#include "zvision/render_manager.h" + +#include "common/system.h" + +#include "video/video_decoder.h" + +#include "engines/util.h" + +#include "graphics/surface.h" + + +namespace ZVision { + +// Taken/modified from SCI +void scaleBuffer(const byte *src, byte *dst, uint32 srcWidth, uint32 srcHeight, byte bytesPerPixel, uint scaleAmount) { + assert(bytesPerPixel == 1 || bytesPerPixel == 2); + + const uint32 newWidth = srcWidth * scaleAmount; + const uint32 pitch = newWidth * bytesPerPixel; + const byte *srcPtr = src; + + if (bytesPerPixel == 1) { + for (uint32 y = 0; y < srcHeight; ++y) { + for (uint32 x = 0; x < srcWidth; ++x) { + const byte color = *srcPtr++; + + for (uint i = 0; i < scaleAmount; ++i) { + dst[i] = color; + dst[pitch + i] = color; + } + dst += scaleAmount; + } + dst += pitch; + } + } else if (bytesPerPixel == 2) { + for (uint32 y = 0; y < srcHeight; ++y) { + for (uint32 x = 0; x < srcWidth; ++x) { + const byte color = *srcPtr++; + const byte color2 = *srcPtr++; + + for (uint i = 0; i < scaleAmount; ++i) { + uint index = i *2; + + dst[index] = color; + dst[index + 1] = color2; + dst[pitch + index] = color; + dst[pitch + index + 1] = color2; + } + dst += 2 * scaleAmount; + } + dst += pitch; + } + } +} + +void ZVision::playVideo(Video::VideoDecoder &videoDecoder, const Common::Rect &destRect, bool skippable) { + byte bytesPerPixel = videoDecoder.getPixelFormat().bytesPerPixel; + + uint16 origWidth = videoDecoder.getWidth(); + uint16 origHeight = videoDecoder.getHeight(); + + uint scale = 1; + // If destRect is empty, no specific scaling was requested. However, we may choose to do scaling anyway + if (destRect.isEmpty()) { + // Most videos are very small. Therefore we do a simple 2x scale + if (origWidth * 2 <= 640 && origHeight * 2 <= 480) { + scale = 2; + } + } else { + // Assume bilinear scaling. AKA calculate the scale from just the width. + // Also assume that the scaling is in integral intervals. AKA no 1.5x scaling + // TODO: Test ^these^ assumptions + scale = destRect.width() / origWidth; + + // TODO: Test if we need to support downscale. + } + + uint16 pitch = origWidth * bytesPerPixel; + + uint16 finalWidth = origWidth * scale; + uint16 finalHeight = origHeight * scale; + + byte *scaledVideoFrameBuffer = 0; + if (scale != 1) { + scaledVideoFrameBuffer = new byte[finalWidth * finalHeight * bytesPerPixel]; + } + + uint16 x = ((WINDOW_WIDTH - finalWidth) / 2) + destRect.left; + uint16 y = ((WINDOW_HEIGHT - finalHeight) / 2) + destRect.top; + + _clock.stop(); + videoDecoder.start(); + + // Only continue while the video is still playing + while (!shouldQuit() && !videoDecoder.endOfVideo() && videoDecoder.isPlaying()) { + // Check for engine quit and video stop key presses + while (!videoDecoder.endOfVideo() && videoDecoder.isPlaying() && _eventMan->pollEvent(_event)) { + switch (_event.type) { + case Common::EVENT_KEYDOWN: + switch (_event.kbd.keycode) { + case Common::KEYCODE_q: + if (_event.kbd.hasFlags(Common::KBD_CTRL)) + quitGame(); + break; + case Common::KEYCODE_SPACE: + if (skippable) { + videoDecoder.stop(); + } + break; + default: + break; + } + default: + break; + } + } + + if (videoDecoder.needsUpdate()) { + const Graphics::Surface *frame = videoDecoder.decodeNextFrame(); + + if (frame) { + if (scale != 1) { + scaleBuffer((const byte *)frame->getPixels(), scaledVideoFrameBuffer, origWidth, origHeight, bytesPerPixel, scale); + _system->copyRectToScreen(scaledVideoFrameBuffer, pitch * 2, x, y, finalWidth, finalHeight); + } else { + _system->copyRectToScreen((const byte *)frame->getPixels(), pitch, x, y, finalWidth, finalHeight); + } + } + } + + // Always update the screen so the mouse continues to render + _system->updateScreen(); + + _system->delayMillis(videoDecoder.getTimeToNextFrame()); + } + + _clock.start(); + + if (scale != 1) { + delete[] scaledVideoFrameBuffer; + } +} + +} // End of namespace ZVision diff --git a/engines/zvision/video/zork_avi_decoder.cpp b/engines/zvision/video/zork_avi_decoder.cpp new file mode 100644 index 0000000000..a614f77bb7 --- /dev/null +++ b/engines/zvision/video/zork_avi_decoder.cpp @@ -0,0 +1,53 @@ +/* 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. + * + * + */ + +#include "common/scummsys.h" + +#include "zvision/zork_avi_decoder.h" + +#include "zvision/zork_raw.h" + +#include "common/stream.h" + +#include "audio/audiostream.h" + + +namespace ZVision { + +Video::AVIDecoder::AVIAudioTrack *ZorkAVIDecoder::createAudioTrack(Video::AVIDecoder::AVIStreamHeader sHeader, Video::AVIDecoder::PCMWaveFormat wvInfo) { + ZorkAVIDecoder::ZorkAVIAudioTrack *audioTrack = new ZorkAVIDecoder::ZorkAVIAudioTrack(sHeader, wvInfo, _soundType); + return (Video::AVIDecoder::AVIAudioTrack *)audioTrack; +} + +void ZorkAVIDecoder::ZorkAVIAudioTrack::queueSound(Common::SeekableReadStream *stream) { + if (_audStream) { + if (_wvInfo.tag == kWaveFormatZorkPCM) { + assert(_wvInfo.size == 8); + _audStream->queueAudioStream(makeRawZorkStream(stream, _wvInfo.samplesPerSec, _audStream->isStereo(), DisposeAfterUse::YES), DisposeAfterUse::YES); + } + } else { + delete stream; + } +} + +} // End of namespace ZVision diff --git a/engines/zvision/video/zork_avi_decoder.h b/engines/zvision/video/zork_avi_decoder.h new file mode 100644 index 0000000000..ec2be1bb13 --- /dev/null +++ b/engines/zvision/video/zork_avi_decoder.h @@ -0,0 +1,60 @@ +/* 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. + * + * + */ + +#ifndef ZORK_AVI_DECODER_H +#define ZORK_AVI_DECODER_H + +#include "video/avi_decoder.h" + + +namespace ZVision { + +class ZorkAVIDecoder : public Video::AVIDecoder { +public: + ZorkAVIDecoder(Audio::Mixer::SoundType soundType = Audio::Mixer::kPlainSoundType) : + Video::AVIDecoder(soundType) {} + + virtual ~ZorkAVIDecoder() {} + +private: + class ZorkAVIAudioTrack : public Video::AVIDecoder::AVIAudioTrack { + public: + ZorkAVIAudioTrack(const AVIStreamHeader &streamHeader, const PCMWaveFormat &waveFormat, Audio::Mixer::SoundType soundType) : + Video::AVIDecoder::AVIAudioTrack(streamHeader, waveFormat, soundType) {} + virtual ~ZorkAVIAudioTrack() {} + + void queueSound(Common::SeekableReadStream *stream); + }; + + Video::AVIDecoder::AVIAudioTrack *createAudioTrack(Video::AVIDecoder::AVIStreamHeader sHeader, Video::AVIDecoder::PCMWaveFormat wvInfo); + +private: + // Audio Codecs + enum { + kWaveFormatZorkPCM = 17 // special Zork PCM audio format (clashes with MS IMA ADPCM) + }; +}; + +} // End of namespace ZVision + +#endif |