mirror of
https://github.com/drewcassidy/quicktex.git
synced 2024-09-13 06:37:34 +00:00
Bind decoders
This commit is contained in:
parent
83d547dd8e
commit
18544645a2
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
#include "../BlockDecoder.h"
|
#include "../BlockDecoder.h"
|
||||||
#include "../BlockView.h"
|
#include "../BlockView.h"
|
||||||
@ -36,9 +37,13 @@ class BC4Decoder : public BlockDecoderTemplate<BC4Block, 4, 4> {
|
|||||||
void DecodeBlock(Color4x4 dest, BC4Block *const block, uint8_t channel) const noexcept(ndebug) { DecodeBlock(dest.GetChannel(channel), block); }
|
void DecodeBlock(Color4x4 dest, BC4Block *const block, uint8_t channel) const noexcept(ndebug) { DecodeBlock(dest.GetChannel(channel), block); }
|
||||||
void DecodeBlock(Byte4x4 dest, BC4Block *const block) const noexcept(ndebug);
|
void DecodeBlock(Byte4x4 dest, BC4Block *const block) const noexcept(ndebug);
|
||||||
|
|
||||||
constexpr uint8_t GetChannel() const { return _channel; }
|
uint8_t GetChannel() const { return _channel; }
|
||||||
|
void SetChannel(uint8_t channel) {
|
||||||
|
if (channel >= 4) throw std::invalid_argument("Channel out of range");
|
||||||
|
_channel = channel;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const uint8_t _channel;
|
uint8_t _channel;
|
||||||
};
|
};
|
||||||
} // namespace rgbcx
|
} // namespace rgbcx
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <tuple>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "../BC4/BC4Decoder.h"
|
#include "../BC4/BC4Decoder.h"
|
||||||
@ -33,6 +34,7 @@
|
|||||||
namespace rgbcx {
|
namespace rgbcx {
|
||||||
class BC5Decoder : public BlockDecoderTemplate<BC5Block, 4, 4> {
|
class BC5Decoder : public BlockDecoderTemplate<BC5Block, 4, 4> {
|
||||||
public:
|
public:
|
||||||
|
using ChannelPair = std::tuple<uint8_t, uint8_t>;
|
||||||
using BC4DecoderPtr = std::shared_ptr<BC4Decoder>;
|
using BC4DecoderPtr = std::shared_ptr<BC4Decoder>;
|
||||||
|
|
||||||
BC5Decoder(uint8_t chan0 = 0, uint8_t chan1 = 1) : BC5Decoder(std::make_shared<BC4Decoder>(), chan0, chan1) {}
|
BC5Decoder(uint8_t chan0 = 0, uint8_t chan1 = 1) : BC5Decoder(std::make_shared<BC4Decoder>(), chan0, chan1) {}
|
||||||
@ -47,9 +49,18 @@ class BC5Decoder : public BlockDecoderTemplate<BC5Block, 4, 4> {
|
|||||||
constexpr size_t GetChannel0() const { return _chan0; }
|
constexpr size_t GetChannel0() const { return _chan0; }
|
||||||
constexpr size_t GetChannel1() const { return _chan1; }
|
constexpr size_t GetChannel1() const { return _chan1; }
|
||||||
|
|
||||||
|
ChannelPair GetChannels() const { return ChannelPair(_chan0, _chan1); }
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const BC4DecoderPtr _bc4_decoder;
|
const BC4DecoderPtr _bc4_decoder;
|
||||||
const uint8_t _chan0;
|
uint8_t _chan0;
|
||||||
const uint8_t _chan1;
|
uint8_t _chan1;
|
||||||
};
|
};
|
||||||
} // namespace rgbcx
|
} // namespace rgbcx
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
#include "../BC1/BC1Decoder.h"
|
#include "../BC1/BC1Decoder.h"
|
||||||
|
#include "../BC3/BC3Decoder.h"
|
||||||
|
#include "../BC4/BC4Decoder.h"
|
||||||
|
#include "../BC5/BC5Decoder.h"
|
||||||
#include "../BlockDecoder.h"
|
#include "../BlockDecoder.h"
|
||||||
#include "../bitwiseEnums.h"
|
#include "../bitwiseEnums.h"
|
||||||
|
|
||||||
@ -67,6 +70,23 @@ void InitDecoders(py::module_ &m) {
|
|||||||
bc1_decoder.def(py::init<Interpolator::Type, bool>(), py::arg("interpolator") = Interpolator::Type::Ideal, py::arg("write_alpha") = false);
|
bc1_decoder.def(py::init<Interpolator::Type, bool>(), py::arg("interpolator") = Interpolator::Type::Ideal, py::arg("write_alpha") = false);
|
||||||
bc1_decoder.def_property_readonly("interpolator_type", &BC1Decoder::GetInterpolatorType);
|
bc1_decoder.def_property_readonly("interpolator_type", &BC1Decoder::GetInterpolatorType);
|
||||||
bc1_decoder.def_readwrite("write_alpha", &BC1Decoder::write_alpha);
|
bc1_decoder.def_readwrite("write_alpha", &BC1Decoder::write_alpha);
|
||||||
|
|
||||||
|
// BC3Decoder
|
||||||
|
py::class_<BC3Decoder> bc3_decoder(m, "BC3Decoder", block_decoder);
|
||||||
|
|
||||||
|
bc3_decoder.def(py::init<Interpolator::Type>(), py::arg("interpolator") = Interpolator::Type::Ideal);
|
||||||
|
|
||||||
|
// BC4Decoder
|
||||||
|
py::class_<BC4Decoder> bc4_decoder(m, "BC4Decoder", block_decoder);
|
||||||
|
|
||||||
|
bc4_decoder.def(py::init<uint8_t>(), py::arg("channel") = 3);
|
||||||
|
bc4_decoder.def_property("channel", &BC4Decoder::GetChannel, &BC4Decoder::SetChannel);
|
||||||
|
|
||||||
|
// BC5Decoder
|
||||||
|
py::class_<BC5Decoder> bc5_decoder(m, "BC5Decoder", block_decoder);
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace rgbcx::bindings
|
} // namespace rgbcx::bindings
|
Loading…
Reference in New Issue
Block a user