mirror of
https://github.com/drewcassidy/quicktex.git
synced 2024-09-13 06:37:34 +00:00
Decoder APIs refinement
This commit is contained in:
parent
18544645a2
commit
b77a5acfb6
@ -36,11 +36,14 @@ class BC3Decoder : public BlockDecoderTemplate<BC3Block, 4, 4> {
|
||||
using BC1DecoderPtr = std::shared_ptr<BC1Decoder>;
|
||||
using BC4DecoderPtr = std::shared_ptr<BC4Decoder>;
|
||||
|
||||
BC3Decoder(Interpolator::Type type = Interpolator::Type::Ideal) : BC3Decoder(std::make_shared<BC1Decoder>(type)) {}
|
||||
BC3Decoder(Interpolator::Type type = Interpolator::Type::Ideal) : BC3Decoder(std::make_shared<BC1Decoder>(type), std::make_shared<BC4Decoder>(3)) {}
|
||||
BC3Decoder(BC1DecoderPtr bc1_decoder, BC4DecoderPtr bc4_decoder = std::make_shared<BC4Decoder>()) : _bc1_decoder(bc1_decoder), _bc4_decoder(bc4_decoder) {}
|
||||
|
||||
void DecodeBlock(Color4x4 dest, BC3Block *const block) const noexcept(ndebug) override;
|
||||
|
||||
BC1DecoderPtr GetBC1Decoder() const { return _bc1_decoder; }
|
||||
BC4DecoderPtr GetBC4Decoder() const { return _bc4_decoder; }
|
||||
|
||||
private:
|
||||
const BC1DecoderPtr _bc1_decoder;
|
||||
const BC4DecoderPtr _bc4_decoder;
|
||||
|
@ -26,7 +26,7 @@
|
||||
namespace rgbcx {
|
||||
|
||||
void BC5Decoder::DecodeBlock(Color4x4 dest, BC5Block *const block) const noexcept(ndebug) {
|
||||
_bc4_decoder->DecodeBlock(dest, &block->chan0_block, _chan0);
|
||||
_bc4_decoder->DecodeBlock(dest, &block->chan1_block, _chan1);
|
||||
_chan0_decoder->DecodeBlock(dest, &block->chan0_block);
|
||||
_chan1_decoder->DecodeBlock(dest, &block->chan1_block);
|
||||
}
|
||||
} // namespace rgbcx
|
@ -22,8 +22,8 @@
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <tuple>
|
||||
#include <memory>
|
||||
#include <tuple>
|
||||
|
||||
#include "../BC4/BC4Decoder.h"
|
||||
#include "../BlockDecoder.h"
|
||||
@ -36,31 +36,23 @@ class BC5Decoder : public BlockDecoderTemplate<BC5Block, 4, 4> {
|
||||
public:
|
||||
using ChannelPair = std::tuple<uint8_t, uint8_t>;
|
||||
using BC4DecoderPtr = std::shared_ptr<BC4Decoder>;
|
||||
using BC4DecoderPair = std::tuple<BC4DecoderPtr, BC4DecoderPtr>;
|
||||
|
||||
BC5Decoder(uint8_t chan0 = 0, uint8_t chan1 = 1) : BC5Decoder(std::make_shared<BC4Decoder>(), chan0, chan1) {}
|
||||
BC5Decoder(BC4DecoderPtr bc4_decoder, uint8_t chan0 = 0, uint8_t chan1 = 1) : _bc4_decoder(bc4_decoder), _chan0(chan0), _chan1(chan1) {
|
||||
assert(chan0 < 4U);
|
||||
assert(chan1 < 4U);
|
||||
assert(chan0 != chan1);
|
||||
}
|
||||
BC5Decoder(uint8_t chan0 = 0, uint8_t chan1 = 1) : BC5Decoder(std::make_shared<BC4Decoder>(chan0), std::make_shared<BC4Decoder>(chan1)) {}
|
||||
BC5Decoder(BC4DecoderPtr chan0_decoder, BC4DecoderPtr chan1_decoder) : _chan0_decoder(chan0_decoder), _chan1_decoder(chan1_decoder) {}
|
||||
|
||||
void DecodeBlock(Color4x4 dest, BC5Block *const block) const noexcept(ndebug) override;
|
||||
|
||||
constexpr size_t GetChannel0() const { return _chan0; }
|
||||
constexpr size_t GetChannel1() const { return _chan1; }
|
||||
|
||||
ChannelPair GetChannels() const { return ChannelPair(_chan0, _chan1); }
|
||||
ChannelPair GetChannels() const { return ChannelPair(_chan0_decoder->GetChannel(), _chan1_decoder->GetChannel()); }
|
||||
void SetChannels(ChannelPair channels) {
|
||||
if (std::get<0>(channels) >= 4) throw std::invalid_argument("Channel 0 out of range");
|
||||
if (std::get<1>(channels) >= 4) throw std::invalid_argument("Channel 1 out of range");
|
||||
_chan0 = std::get<0>(channels);
|
||||
_chan1 = std::get<1>(channels);
|
||||
_chan0_decoder->SetChannel(std::get<0>(channels));
|
||||
_chan1_decoder->SetChannel(std::get<1>(channels));
|
||||
}
|
||||
|
||||
BC4DecoderPair GetBC4Decoders() const { return BC4DecoderPair(_chan0_decoder, _chan1_decoder); }
|
||||
|
||||
private:
|
||||
const BC4DecoderPtr _bc4_decoder;
|
||||
uint8_t _chan0;
|
||||
uint8_t _chan1;
|
||||
const BC4DecoderPtr _chan0_decoder;
|
||||
const BC4DecoderPtr _chan1_decoder;
|
||||
};
|
||||
} // namespace rgbcx
|
||||
|
@ -28,9 +28,6 @@
|
||||
#include "../BlockDecoder.h"
|
||||
#include "../bitwiseEnums.h"
|
||||
|
||||
#define STRINGIFY(x) #x
|
||||
#define MACRO_STRINGIFY(x) STRINGIFY(x)
|
||||
|
||||
namespace py = pybind11;
|
||||
namespace rgbcx::bindings {
|
||||
|
||||
@ -46,7 +43,7 @@ py::bytes DecodeImage(const BlockDecoder &self, py::bytes encoded, unsigned imag
|
||||
std::string encoded_str = (std::string)encoded; // encoded data is copied here, unfortunately
|
||||
std::string decoded_str = std::string(color_size, 0);
|
||||
|
||||
if (decoded_str.size() != color_size) throw std::invalid_argument("Incompatible data: image width and height do not match the size of the decoded image");
|
||||
if (encoded_str.size() != block_size) throw std::invalid_argument("Incompatible data: image width and height do not match the size of the encoded image");
|
||||
|
||||
self.DecodeImage(reinterpret_cast<uint8_t *>(encoded_str.data()), reinterpret_cast<Color *>(decoded_str.data()), image_width, image_height);
|
||||
|
||||
@ -74,7 +71,9 @@ void InitDecoders(py::module_ &m) {
|
||||
// BC3Decoder
|
||||
py::class_<BC3Decoder> bc3_decoder(m, "BC3Decoder", block_decoder);
|
||||
|
||||
bc3_decoder.def(py::init<Interpolator::Type>(), py::arg("interpolator") = Interpolator::Type::Ideal);
|
||||
bc3_decoder.def(py::init<Interpolator::Type>(), py::arg("type") = Interpolator::Type::Ideal);
|
||||
bc3_decoder.def_property_readonly("bc1_decoder", &BC3Decoder::GetBC1Decoder);
|
||||
bc3_decoder.def_property_readonly("bc4_decoder", &BC3Decoder::GetBC4Decoder);
|
||||
|
||||
// BC4Decoder
|
||||
py::class_<BC4Decoder> bc4_decoder(m, "BC4Decoder", block_decoder);
|
||||
@ -87,6 +86,7 @@ void InitDecoders(py::module_ &m) {
|
||||
|
||||
bc5_decoder.def(py::init<uint8_t, uint8_t>(), py::arg("chan0") = 0, py::arg("chan1") = 1);
|
||||
bc5_decoder.def_property("channels", &BC5Decoder::GetChannels, &BC5Decoder::SetChannels);
|
||||
bc5_decoder.def_property_readonly("bc4_decoders", &BC5Decoder::GetBC4Decoders);
|
||||
}
|
||||
|
||||
} // namespace rgbcx::bindings
|
Loading…
Reference in New Issue
Block a user