2015-01-03 09:57:52 +01:00
|
|
|
/* ResidualVM - A 3D game interpreter
|
|
|
|
*
|
|
|
|
* ResidualVM is the legal property of its developers, whose names
|
2015-02-21 06:58:05 +01:00
|
|
|
* are too numerous to list here. Please refer to the AUTHORS
|
2015-01-03 09:57:52 +01:00
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
2015-02-21 06:58:05 +01:00
|
|
|
* 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,
|
2015-01-03 09:57:52 +01:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-02-21 06:58:05 +01:00
|
|
|
* 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.
|
2015-01-03 09:57:52 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "engines/stark/visual/smacker.h"
|
|
|
|
|
|
|
|
#include "engines/stark/gfx/driver.h"
|
2015-12-24 18:09:04 +01:00
|
|
|
#include "engines/stark/gfx/surfacerenderer.h"
|
2015-02-14 11:50:55 +01:00
|
|
|
#include "engines/stark/gfx/texture.h"
|
2015-02-08 09:17:51 +01:00
|
|
|
#include "engines/stark/scene.h"
|
|
|
|
#include "engines/stark/services/services.h"
|
2019-01-15 20:54:01 +01:00
|
|
|
#include "engines/stark/services/settings.h"
|
2015-01-03 09:57:52 +01:00
|
|
|
|
|
|
|
#include "common/str.h"
|
|
|
|
#include "common/archive.h"
|
|
|
|
|
2019-01-16 20:53:37 +01:00
|
|
|
#include "video/bink_decoder.h"
|
2015-01-03 09:57:52 +01:00
|
|
|
#include "video/smk_decoder.h"
|
|
|
|
|
|
|
|
namespace Stark {
|
|
|
|
|
2015-02-14 11:50:55 +01:00
|
|
|
VisualSmacker::VisualSmacker(Gfx::Driver *gfx) :
|
|
|
|
Visual(TYPE),
|
|
|
|
_gfx(gfx),
|
2015-08-01 15:27:09 +02:00
|
|
|
_surface(nullptr),
|
2015-02-14 11:50:55 +01:00
|
|
|
_texture(nullptr),
|
2019-01-16 20:53:37 +01:00
|
|
|
_decoder(nullptr),
|
2016-04-16 08:47:46 +02:00
|
|
|
_position(0, 0),
|
2019-01-16 20:53:37 +01:00
|
|
|
_originalWidth(0),
|
|
|
|
_originalHeight(0),
|
2016-04-16 08:47:46 +02:00
|
|
|
_overridenFramerate(-1) {
|
2015-12-24 18:09:04 +01:00
|
|
|
_surfaceRenderer = _gfx->createSurfaceRenderer();
|
2015-01-03 09:57:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
VisualSmacker::~VisualSmacker() {
|
2015-02-14 11:50:55 +01:00
|
|
|
delete _texture;
|
2019-01-16 20:53:37 +01:00
|
|
|
delete _decoder;
|
2015-12-24 18:09:04 +01:00
|
|
|
delete _surfaceRenderer;
|
2015-01-03 09:57:52 +01:00
|
|
|
}
|
|
|
|
|
2019-01-16 20:53:37 +01:00
|
|
|
void VisualSmacker::loadSmacker(Common::SeekableReadStream *stream) {
|
2015-02-14 11:50:55 +01:00
|
|
|
delete _texture;
|
2019-01-16 20:53:37 +01:00
|
|
|
delete _decoder;
|
2015-02-14 11:50:55 +01:00
|
|
|
|
2019-01-16 20:53:37 +01:00
|
|
|
_decoder = new Video::SmackerDecoder();
|
|
|
|
_decoder->setSoundType(Audio::Mixer::kSFXSoundType);
|
|
|
|
_decoder->loadStream(stream);
|
|
|
|
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
void VisualSmacker::loadBink(Common::SeekableReadStream *stream) {
|
|
|
|
delete _texture;
|
|
|
|
delete _decoder;
|
|
|
|
|
|
|
|
_decoder = new Video::BinkDecoder();
|
|
|
|
_decoder->setSoundType(Audio::Mixer::kSFXSoundType);
|
|
|
|
_decoder->setDefaultHighColorFormat(Gfx::Driver::getRGBAPixelFormat());
|
|
|
|
_decoder->loadStream(stream);
|
|
|
|
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
void VisualSmacker::init() {
|
|
|
|
_originalWidth = _decoder->getWidth();
|
|
|
|
_originalHeight = _decoder->getHeight();
|
2017-09-03 15:50:38 +02:00
|
|
|
|
2016-04-16 08:47:46 +02:00
|
|
|
rewind();
|
2015-02-14 11:50:55 +01:00
|
|
|
|
|
|
|
_texture = _gfx->createTexture();
|
2019-01-15 20:54:01 +01:00
|
|
|
_texture->setSamplingFilter(StarkSettings->getImageSamplingFilter());
|
2015-02-14 11:50:55 +01:00
|
|
|
|
2015-08-01 15:00:26 +02:00
|
|
|
update();
|
2015-01-03 09:57:52 +01:00
|
|
|
}
|
|
|
|
|
2019-01-16 20:53:37 +01:00
|
|
|
void VisualSmacker::readOriginalSize(Common::SeekableReadStream *stream) {
|
|
|
|
Video::SmackerDecoder smacker;
|
|
|
|
smacker.loadStream(stream);
|
|
|
|
|
|
|
|
_originalWidth = smacker.getWidth();
|
|
|
|
_originalHeight = smacker.getHeight();
|
|
|
|
}
|
|
|
|
|
2015-02-14 11:50:55 +01:00
|
|
|
void VisualSmacker::render(const Common::Point &position) {
|
2019-01-24 11:56:29 +01:00
|
|
|
assert(_decoder->getCurFrame() >= 0);
|
2019-01-05 16:51:47 +01:00
|
|
|
|
2015-08-01 11:17:52 +02:00
|
|
|
// The position argument contains the scroll offset
|
2019-01-16 20:53:37 +01:00
|
|
|
_surfaceRenderer->render(_texture, _position - position, _originalWidth, _originalHeight);
|
2015-01-03 09:57:52 +01:00
|
|
|
}
|
|
|
|
|
2015-08-01 15:00:26 +02:00
|
|
|
void VisualSmacker::update() {
|
2019-01-16 20:53:37 +01:00
|
|
|
if (_decoder->needsUpdate()) {
|
|
|
|
_surface = _decoder->decodeNextFrame();
|
|
|
|
const byte *palette = _decoder->getPalette();
|
|
|
|
|
|
|
|
if (palette) {
|
|
|
|
// Convert the surface to RGBA
|
|
|
|
Graphics::Surface convertedSurface;
|
|
|
|
convertedSurface.create(_surface->w, _surface->h, Gfx::Driver::getRGBAPixelFormat());
|
|
|
|
|
|
|
|
for (int y = 0; y < _surface->h; y++) {
|
|
|
|
const byte *srcRow = (const byte *)_surface->getBasePtr(0, y);
|
|
|
|
byte *dstRow = (byte *)convertedSurface.getBasePtr(0, y);
|
|
|
|
|
|
|
|
for (int x = 0; x < _surface->w; x++) {
|
|
|
|
byte index = *srcRow++;
|
|
|
|
|
|
|
|
byte r = palette[index * 3];
|
|
|
|
byte g = palette[index * 3 + 1];
|
|
|
|
byte b = palette[index * 3 + 2];
|
|
|
|
|
|
|
|
if (r != 0 || g != 255 || b != 255) {
|
|
|
|
*dstRow++ = r;
|
|
|
|
*dstRow++ = g;
|
|
|
|
*dstRow++ = b;
|
|
|
|
*dstRow++ = 0xFF;
|
|
|
|
} else {
|
|
|
|
// Cyan is the transparent color
|
|
|
|
*dstRow++ = 0;
|
|
|
|
*dstRow++ = 0;
|
|
|
|
*dstRow++ = 0;
|
|
|
|
*dstRow++ = 0;
|
|
|
|
}
|
2015-02-15 11:14:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-16 20:53:37 +01:00
|
|
|
_texture->update(&convertedSurface);
|
2015-02-15 11:14:16 +01:00
|
|
|
|
2019-01-16 20:53:37 +01:00
|
|
|
convertedSurface.free();
|
|
|
|
} else {
|
|
|
|
_texture->update(_surface);
|
|
|
|
}
|
2015-08-01 15:27:09 +02:00
|
|
|
}
|
|
|
|
}
|
2015-02-15 11:14:16 +01:00
|
|
|
|
2015-08-01 15:27:09 +02:00
|
|
|
bool VisualSmacker::isPointSolid(const Common::Point &point) const {
|
2019-01-16 20:53:37 +01:00
|
|
|
if (!_decoder || !_surface) {
|
2015-08-01 15:27:09 +02:00
|
|
|
return false;
|
2015-01-03 09:57:52 +01:00
|
|
|
}
|
2015-08-01 15:27:09 +02:00
|
|
|
|
2019-01-16 20:53:37 +01:00
|
|
|
Common::Point scaledPoint;
|
|
|
|
scaledPoint.x = point.x * _surface->w / _originalWidth;
|
|
|
|
scaledPoint.y = point.y * _surface->h / _originalHeight;
|
|
|
|
scaledPoint.x = CLIP<uint16>(scaledPoint.x, 0, _surface->w);
|
|
|
|
scaledPoint.y = CLIP<uint16>(scaledPoint.y, 0, _surface->h);
|
|
|
|
|
|
|
|
const byte *ptr = (const byte *)_surface->getBasePtr(scaledPoint.x, scaledPoint.y);
|
|
|
|
const byte *palette = _decoder->getPalette();
|
|
|
|
if (palette) {
|
|
|
|
byte r = palette[*ptr * 3];
|
|
|
|
byte g = palette[*ptr * 3 + 1];
|
|
|
|
byte b = palette[*ptr * 3 + 2];
|
|
|
|
|
|
|
|
// Cyan is the transparent color
|
|
|
|
return r != 0x00 || g != 0xFF || b != 0xFF;
|
|
|
|
} else {
|
|
|
|
// Maybe implement this method in some other way to avoid having to keep the surface in memory
|
|
|
|
return *(ptr + 3) == 0xFF;
|
|
|
|
}
|
2015-01-03 09:57:52 +01:00
|
|
|
}
|
|
|
|
|
2015-03-01 00:23:55 +01:00
|
|
|
int VisualSmacker::getFrameNumber() const {
|
2019-01-16 20:53:37 +01:00
|
|
|
if (_decoder && _decoder->isPlaying()) {
|
|
|
|
return _decoder->getCurFrame();
|
2015-03-01 00:23:55 +01:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-01-03 09:57:52 +01:00
|
|
|
bool VisualSmacker::isDone() {
|
2017-05-29 19:04:51 +02:00
|
|
|
return getCurrentTime() >= getDuration();
|
2015-01-03 09:57:52 +01:00
|
|
|
}
|
|
|
|
|
2015-04-05 18:33:18 +02:00
|
|
|
int VisualSmacker::getWidth() const {
|
2019-01-16 20:53:37 +01:00
|
|
|
return _originalWidth;
|
2015-04-05 18:33:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int VisualSmacker::getHeight() const {
|
2019-01-16 20:53:37 +01:00
|
|
|
return _originalHeight;
|
2015-04-05 18:33:18 +02:00
|
|
|
}
|
|
|
|
|
2015-08-31 15:53:55 +02:00
|
|
|
uint32 VisualSmacker::getDuration() const {
|
2019-01-16 20:53:37 +01:00
|
|
|
return (_decoder->getRate().getInverse() * _decoder->getDuration().msecs()).toInt();
|
2015-08-31 15:53:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void VisualSmacker::rewind() {
|
2019-01-16 20:53:37 +01:00
|
|
|
_decoder->rewind();
|
|
|
|
_decoder->start();
|
2016-04-16 08:47:46 +02:00
|
|
|
|
|
|
|
if (_overridenFramerate != -1) {
|
2019-01-16 20:53:37 +01:00
|
|
|
Common::Rational originalFrameRate;
|
|
|
|
|
|
|
|
Video::SmackerDecoder *smacker = dynamic_cast<Video::SmackerDecoder *>(_decoder);
|
|
|
|
if (smacker) {
|
|
|
|
originalFrameRate = smacker->getFrameRate();
|
|
|
|
}
|
|
|
|
|
|
|
|
Video::BinkDecoder *bink = dynamic_cast<Video::BinkDecoder *>(_decoder);
|
|
|
|
if (bink) {
|
|
|
|
originalFrameRate = bink->getFrameRate();
|
|
|
|
}
|
|
|
|
|
2016-04-16 08:47:46 +02:00
|
|
|
Common::Rational playbackRate = _overridenFramerate / originalFrameRate;
|
2019-01-16 20:53:37 +01:00
|
|
|
_decoder->setRate(playbackRate);
|
2016-04-16 08:47:46 +02:00
|
|
|
}
|
2015-08-31 15:53:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32 VisualSmacker::getCurrentTime() const {
|
2019-01-16 20:53:37 +01:00
|
|
|
return (_decoder->getRate().getInverse() * _decoder->getTime()).toInt();
|
2015-08-31 15:53:55 +02:00
|
|
|
}
|
|
|
|
|
2016-04-16 08:47:46 +02:00
|
|
|
void VisualSmacker::overrideFrameRate(int32 framerate) {
|
|
|
|
_overridenFramerate = framerate;
|
|
|
|
}
|
2017-05-25 18:27:35 +02:00
|
|
|
|
|
|
|
void VisualSmacker::pause(bool pause) {
|
2019-01-16 20:53:37 +01:00
|
|
|
_decoder->pauseVideo(pause);
|
2017-05-25 18:27:35 +02:00
|
|
|
}
|
|
|
|
|
2015-01-03 09:57:52 +01:00
|
|
|
} // End of namespace Stark
|