diff --git a/src/rgbcx/BC4/BC4Decoder.h b/src/rgbcx/BC4/BC4Decoder.h index 1ea8a81..c05d285 100644 --- a/src/rgbcx/BC4/BC4Decoder.h +++ b/src/rgbcx/BC4/BC4Decoder.h @@ -21,6 +21,7 @@ #include #include +#include #include "../BlockDecoder.h" #include "../BlockView.h" @@ -36,9 +37,13 @@ class BC4Decoder : public BlockDecoderTemplate { 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); - 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: - const uint8_t _channel; + uint8_t _channel; }; } // namespace rgbcx diff --git a/src/rgbcx/BC5/BC5Decoder.h b/src/rgbcx/BC5/BC5Decoder.h index 15c1207..4ea54e0 100644 --- a/src/rgbcx/BC5/BC5Decoder.h +++ b/src/rgbcx/BC5/BC5Decoder.h @@ -22,6 +22,7 @@ #include #include #include +#include #include #include "../BC4/BC4Decoder.h" @@ -33,6 +34,7 @@ namespace rgbcx { class BC5Decoder : public BlockDecoderTemplate { public: + using ChannelPair = std::tuple; using BC4DecoderPtr = std::shared_ptr; BC5Decoder(uint8_t chan0 = 0, uint8_t chan1 = 1) : BC5Decoder(std::make_shared(), chan0, chan1) {} @@ -47,9 +49,18 @@ class BC5Decoder : public BlockDecoderTemplate { constexpr size_t GetChannel0() const { return _chan0; } 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: const BC4DecoderPtr _bc4_decoder; - const uint8_t _chan0; - const uint8_t _chan1; + uint8_t _chan0; + uint8_t _chan1; }; } // namespace rgbcx diff --git a/src/rgbcx/bindings/Decoders.cpp b/src/rgbcx/bindings/Decoders.cpp index 3931582..b9ce183 100644 --- a/src/rgbcx/bindings/Decoders.cpp +++ b/src/rgbcx/bindings/Decoders.cpp @@ -22,6 +22,9 @@ #include #include "../BC1/BC1Decoder.h" +#include "../BC3/BC3Decoder.h" +#include "../BC4/BC4Decoder.h" +#include "../BC5/BC5Decoder.h" #include "../BlockDecoder.h" #include "../bitwiseEnums.h" @@ -67,6 +70,23 @@ void InitDecoders(py::module_ &m) { bc1_decoder.def(py::init(), py::arg("interpolator") = Interpolator::Type::Ideal, py::arg("write_alpha") = false); bc1_decoder.def_property_readonly("interpolator_type", &BC1Decoder::GetInterpolatorType); bc1_decoder.def_readwrite("write_alpha", &BC1Decoder::write_alpha); + + // BC3Decoder + py::class_ bc3_decoder(m, "BC3Decoder", block_decoder); + + bc3_decoder.def(py::init(), py::arg("interpolator") = Interpolator::Type::Ideal); + + // BC4Decoder + py::class_ bc4_decoder(m, "BC4Decoder", block_decoder); + + bc4_decoder.def(py::init(), py::arg("channel") = 3); + bc4_decoder.def_property("channel", &BC4Decoder::GetChannel, &BC4Decoder::SetChannel); + + // BC5Decoder + py::class_ bc5_decoder(m, "BC5Decoder", block_decoder); + + bc5_decoder.def(py::init(), py::arg("chan0") = 0, py::arg("chan1") = 1); + bc5_decoder.def_property("channels", &BC5Decoder::GetChannels, &BC5Decoder::SetChannels); } } // namespace rgbcx::bindings \ No newline at end of file