IMAGE: Add codec accuracy options

This commit is contained in:
elasota
2024-09-04 00:06:03 -04:00
committed by Filippos Karapetis
parent e2fccfe581
commit 64a95c3b43
6 changed files with 62 additions and 0 deletions
+35
View File
@@ -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
+7
View File
@@ -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.
*/
+6
View File
@@ -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
+2
View File
@@ -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
+10
View File
@@ -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);
+2
View File
@@ -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;
};