mirror of
https://github.com/scummvm/scummvm.git
synced 2026-05-21 05:40:43 +00:00
IMAGE: Add codec accuracy options
This commit is contained in:
committed by
Filippos Karapetis
parent
e2fccfe581
commit
64a95c3b43
@@ -0,0 +1,35 @@
|
||||
/* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef IMAGE_CODEC_OPTIONS_H
|
||||
#define IMAGE_CODEC_OPTIONS_H
|
||||
|
||||
namespace Image {
|
||||
|
||||
enum class CodecAccuracy {
|
||||
Fast,
|
||||
Default,
|
||||
Accurate,
|
||||
};
|
||||
|
||||
} // End of namespace Image
|
||||
|
||||
#endif
|
||||
@@ -25,6 +25,8 @@
|
||||
#include "graphics/surface.h"
|
||||
#include "graphics/pixelformat.h"
|
||||
|
||||
#include "image/codec-options.h"
|
||||
|
||||
namespace Common {
|
||||
class SeekableReadStream;
|
||||
}
|
||||
@@ -116,6 +118,11 @@ public:
|
||||
*/
|
||||
virtual void setDither(DitherType type, const byte *palette) {}
|
||||
|
||||
/**
|
||||
* Set the decoding accuracy of the codec, if supported
|
||||
*/
|
||||
virtual void setCodecAccuracy(CodecAccuracy accuracy) {}
|
||||
|
||||
/**
|
||||
* Create a dither table, as used by QuickTime codecs.
|
||||
*/
|
||||
|
||||
@@ -46,6 +46,7 @@ MJPEGDecoder::MJPEGDecoder() : Codec() {
|
||||
_pixelFormat = Graphics::PixelFormat(4, 8, 8, 8, 8, 8, 16, 24, 0);
|
||||
|
||||
_surface = 0;
|
||||
_accuracy = CodecAccuracy::Default;
|
||||
}
|
||||
|
||||
MJPEGDecoder::~MJPEGDecoder() {
|
||||
@@ -204,6 +205,7 @@ const Graphics::Surface *MJPEGDecoder::decodeFrame(Common::SeekableReadStream &s
|
||||
|
||||
Common::MemoryReadStream convertedStream(data, outputSize, DisposeAfterUse::YES);
|
||||
JPEGDecoder jpeg;
|
||||
jpeg.setCodecAccuracy(_accuracy);
|
||||
jpeg.setOutputPixelFormat(_pixelFormat);
|
||||
|
||||
if (!jpeg.loadStream(convertedStream)) {
|
||||
@@ -224,4 +226,8 @@ const Graphics::Surface *MJPEGDecoder::decodeFrame(Common::SeekableReadStream &s
|
||||
return _surface;
|
||||
}
|
||||
|
||||
void MJPEGDecoder::setCodecAccuracy(CodecAccuracy accuracy) {
|
||||
_accuracy = accuracy;
|
||||
}
|
||||
|
||||
} // End of namespace Image
|
||||
|
||||
@@ -46,12 +46,14 @@ public:
|
||||
~MJPEGDecoder() override;
|
||||
|
||||
const Graphics::Surface *decodeFrame(Common::SeekableReadStream &stream) override;
|
||||
void setCodecAccuracy(CodecAccuracy accuracy) override;
|
||||
Graphics::PixelFormat getPixelFormat() const override { return _pixelFormat; }
|
||||
bool setOutputPixelFormat(const Graphics::PixelFormat &format) override { _pixelFormat = format; return true; }
|
||||
|
||||
private:
|
||||
Graphics::PixelFormat _pixelFormat;
|
||||
Graphics::Surface *_surface;
|
||||
CodecAccuracy _accuracy;
|
||||
};
|
||||
|
||||
} // End of namespace Image
|
||||
|
||||
@@ -47,6 +47,7 @@ namespace Image {
|
||||
JPEGDecoder::JPEGDecoder() :
|
||||
_surface(),
|
||||
_colorSpace(kColorSpaceRGB),
|
||||
_accuracy(CodecAccuracy::Default),
|
||||
_requestedPixelFormat(getByteOrderRgbPixelFormat()) {
|
||||
}
|
||||
|
||||
@@ -77,6 +78,10 @@ const Graphics::Surface *JPEGDecoder::decodeFrame(Common::SeekableReadStream &st
|
||||
return getSurface();
|
||||
}
|
||||
|
||||
void JPEGDecoder::setCodecAccuracy(CodecAccuracy accuracy) {
|
||||
_accuracy = accuracy;
|
||||
}
|
||||
|
||||
Graphics::PixelFormat JPEGDecoder::getPixelFormat() const {
|
||||
return _surface.format;
|
||||
}
|
||||
@@ -243,6 +248,11 @@ bool JPEGDecoder::loadStream(Common::SeekableReadStream &stream) {
|
||||
// Initialize the decompression structure
|
||||
jpeg_create_decompress(&cinfo);
|
||||
|
||||
if (_accuracy <= CodecAccuracy::Fast)
|
||||
cinfo.dct_method = JDCT_FASTEST;
|
||||
else if (_accuracy >= CodecAccuracy::Accurate)
|
||||
cinfo.dct_method = JDCT_ISLOW;
|
||||
|
||||
// Initialize our buffer handling
|
||||
jpeg_scummvm_src(&cinfo, &stream);
|
||||
|
||||
|
||||
@@ -58,6 +58,7 @@ public:
|
||||
|
||||
// Codec API
|
||||
const Graphics::Surface *decodeFrame(Common::SeekableReadStream &stream) override;
|
||||
void setCodecAccuracy(CodecAccuracy accuracy) override;
|
||||
Graphics::PixelFormat getPixelFormat() const override;
|
||||
bool setOutputPixelFormat(const Graphics::PixelFormat &format) override { _requestedPixelFormat = format; return true; }
|
||||
|
||||
@@ -100,6 +101,7 @@ private:
|
||||
Graphics::Surface _surface;
|
||||
ColorSpace _colorSpace;
|
||||
Graphics::PixelFormat _requestedPixelFormat;
|
||||
CodecAccuracy _accuracy;
|
||||
|
||||
Graphics::PixelFormat getByteOrderRgbPixelFormat() const;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user