From 70ebb4301779d93ff8561c79d5d459efa44f438c Mon Sep 17 00:00:00 2001 From: drewcassidy Date: Wed, 17 Mar 2021 01:13:11 -0700 Subject: [PATCH] Refactor and rebind constructors --- quicktex/__init__.py | 1 + quicktex/s3tc/_bindings.cpp | 6 +++--- quicktex/s3tc/bc1/BC1Decoder.h | 8 ++++++-- quicktex/s3tc/bc1/BC1Encoder.cpp | 3 +-- quicktex/s3tc/bc1/BC1Encoder.h | 7 +++++-- quicktex/s3tc/bc1/_bindings.cpp | 11 ++++++++--- quicktex/s3tc/bc3/BC3Decoder.h | 7 ++++--- quicktex/s3tc/bc3/BC3Encoder.h | 11 ++++++++--- quicktex/s3tc/bc3/_bindings.cpp | 15 ++++++++++++--- quicktex/s3tc/interpolator/__init__.py | 2 +- 10 files changed, 49 insertions(+), 22 deletions(-) diff --git a/quicktex/__init__.py b/quicktex/__init__.py index 9ba7e47..3d2492b 100644 --- a/quicktex/__init__.py +++ b/quicktex/__init__.py @@ -1 +1,2 @@ +"""this is my docs""" from _quicktex import * \ No newline at end of file diff --git a/quicktex/s3tc/_bindings.cpp b/quicktex/s3tc/_bindings.cpp index 4e3c31a..4a74f24 100644 --- a/quicktex/s3tc/_bindings.cpp +++ b/quicktex/s3tc/_bindings.cpp @@ -50,8 +50,8 @@ For most applications, :py:attr:`~quicktex.s3tc.InterpolatorType.Ideal` should b InitInterpolator(s3tc); InitBC1(s3tc); - InitBC3(s3tc); - InitBC4(s3tc); - InitBC5(s3tc); +// InitBC3(s3tc); +// InitBC4(s3tc); +// InitBC5(s3tc); } } // namespace quicktex::bindings diff --git a/quicktex/s3tc/bc1/BC1Decoder.h b/quicktex/s3tc/bc1/BC1Decoder.h index f5951f1..e873b01 100644 --- a/quicktex/s3tc/bc1/BC1Decoder.h +++ b/quicktex/s3tc/bc1/BC1Decoder.h @@ -32,8 +32,12 @@ namespace quicktex::s3tc { class BC1Decoder final : public BlockDecoderTemplate { public: using InterpolatorPtr = std::shared_ptr; - BC1Decoder(InterpolatorPtr interpolator = std::make_shared(), bool write_alpha = false) - : write_alpha(write_alpha), _interpolator(interpolator) {} + + BC1Decoder(bool write_alpha, InterpolatorPtr interpolator) : write_alpha(write_alpha), _interpolator(interpolator) {} + + BC1Decoder(bool write_alpha = false) : BC1Decoder(write_alpha, std::make_shared()) {} + + BC1Decoder(InterpolatorPtr interpolator) : BC1Decoder(false, interpolator) {} void DecodeBlock(Color4x4 dest, BC1Block *const block) const noexcept(ndebug) override; diff --git a/quicktex/s3tc/bc1/BC1Encoder.cpp b/quicktex/s3tc/bc1/BC1Encoder.cpp index de62257..e8b97c2 100644 --- a/quicktex/s3tc/bc1/BC1Encoder.cpp +++ b/quicktex/s3tc/bc1/BC1Encoder.cpp @@ -43,8 +43,7 @@ namespace quicktex::s3tc { // constructors -BC1Encoder::BC1Encoder(InterpolatorPtr interpolator, unsigned int level, bool allow_3color, bool allow_3color_black) - : _interpolator(interpolator) { +BC1Encoder::BC1Encoder(unsigned int level, bool allow_3color, bool allow_3color_black, InterpolatorPtr interpolator) : _interpolator(interpolator) { OrderTable<3>::Generate(); OrderTable<4>::Generate(); diff --git a/quicktex/s3tc/bc1/BC1Encoder.h b/quicktex/s3tc/bc1/BC1Encoder.h index e34142f..2f4ec97 100644 --- a/quicktex/s3tc/bc1/BC1Encoder.h +++ b/quicktex/s3tc/bc1/BC1Encoder.h @@ -37,7 +37,7 @@ namespace quicktex { class Vector4; } -namespace quicktex::s3tc { +namespace quicktex::s3tc { class BC1Encoder final : public BlockEncoderTemplate { public: @@ -111,7 +111,10 @@ class BC1Encoder final : public BlockEncoderTemplate { PCA }; - BC1Encoder(InterpolatorPtr interpolator = std::make_shared(), unsigned level = 5, bool allow_3color = true, bool allow_3color_black = true); + BC1Encoder(unsigned level, bool allow_3color, bool allow_3color_black, InterpolatorPtr interpolator); + + BC1Encoder(unsigned int level = 5, bool allow_3color = true, bool allow_3color_black = true) + : BC1Encoder(level, allow_3color, allow_3color_black, std::make_shared()) {} Interpolator::Type GetInterpolatorType() const { return _interpolator->GetType(); } diff --git a/quicktex/s3tc/bc1/_bindings.cpp b/quicktex/s3tc/bc1/_bindings.cpp index 02ccfab..06fe4c2 100644 --- a/quicktex/s3tc/bc1/_bindings.cpp +++ b/quicktex/s3tc/bc1/_bindings.cpp @@ -35,6 +35,8 @@ namespace py = pybind11; namespace quicktex::bindings { using namespace quicktex::s3tc; +using namespace pybind11::literals; + using InterpolatorPtr = std::shared_ptr; void InitBC1(py::module_ &s3tc) { @@ -45,8 +47,9 @@ void InitBC1(py::module_ &s3tc) { // BC1Encoder py::class_ bc1_encoder(bc1, "BC1Encoder", block_encoder); - bc1_encoder.def(py::init(), py::arg("interpolator") = std::make_shared(), py::arg("level") = 5, - py::arg("use_3color") = true, py::arg("use_3color_black") = true); + bc1_encoder.def(py::init(), "level"_a = 5, "use_3color"_a = true, "use_3color_black"_a = true); + bc1_encoder.def(py::init(), "level"_a, "use_3color"_a, "use_3color_black"_a, "interpolator"_a); + bc1_encoder.def("set_level", &BC1Encoder::SetLevel); bc1_encoder.def_property_readonly("interpolator_type", &BC1Encoder::GetInterpolatorType); bc1_encoder.def_property("flags", &BC1Encoder::GetFlags, &BC1Encoder::SetFlags); @@ -89,7 +92,9 @@ void InitBC1(py::module_ &s3tc) { // BC1Decoder py::class_ bc1_decoder(bc1, "BC1Decoder", block_decoder); - bc1_decoder.def(py::init(), py::arg("interpolator") = std::make_shared(), py::arg("write_alpha") = false); + bc1_decoder.def(py::init(), "write_alpha"_a = false); + bc1_decoder.def(py::init(), "write_alpha"_a, "interpolator"_a); + bc1_decoder.def_property_readonly("interpolator_type", &BC1Decoder::GetInterpolatorType); bc1_decoder.def_readwrite("write_alpha", &BC1Decoder::write_alpha); } diff --git a/quicktex/s3tc/bc3/BC3Decoder.h b/quicktex/s3tc/bc3/BC3Decoder.h index 4cfa918..981c8e6 100644 --- a/quicktex/s3tc/bc3/BC3Decoder.h +++ b/quicktex/s3tc/bc3/BC3Decoder.h @@ -29,7 +29,7 @@ #include "../interpolator/Interpolator.h" #include "BC3Block.h" -namespace quicktex::s3tc { +namespace quicktex::s3tc { class BC3Decoder : public BlockDecoderTemplate { public: @@ -37,8 +37,9 @@ class BC3Decoder : public BlockDecoderTemplate { using BC4DecoderPtr = std::shared_ptr; using InterpolatorPtr = std::shared_ptr; - BC3Decoder(InterpolatorPtr interpolator = std::make_shared()) : BC3Decoder(std::make_shared(interpolator), std::make_shared(3)) {} - BC3Decoder(BC1DecoderPtr bc1_decoder, BC4DecoderPtr bc4_decoder = std::make_shared()) : _bc1_decoder(bc1_decoder), _bc4_decoder(bc4_decoder) {} + BC3Decoder(BC1DecoderPtr bc1_decoder) : _bc1_decoder(bc1_decoder), _bc4_decoder(std::make_shared(3)) {} + + BC3Decoder(InterpolatorPtr interpolator = std::make_shared()) : BC3Decoder(std::make_shared(interpolator)) {} void DecodeBlock(Color4x4 dest, BC3Block *const block) const noexcept(ndebug) override; diff --git a/quicktex/s3tc/bc3/BC3Encoder.h b/quicktex/s3tc/bc3/BC3Encoder.h index e2c2b8f..3a47197 100644 --- a/quicktex/s3tc/bc3/BC3Encoder.h +++ b/quicktex/s3tc/bc3/BC3Encoder.h @@ -28,7 +28,7 @@ #include "../interpolator/Interpolator.h" #include "BC3Block.h" -namespace quicktex::s3tc { +namespace quicktex::s3tc { class BC3Encoder : public BlockEncoderTemplate { public: @@ -36,8 +36,13 @@ class BC3Encoder : public BlockEncoderTemplate { using BC4EncoderPtr = std::shared_ptr; using InterpolatorPtr = std::shared_ptr; - BC3Encoder(InterpolatorPtr interpolator = std::make_shared(), unsigned level = 5, bool allow_3color = true, bool allow_3color_black = true) - : _bc1_encoder(std::make_shared(interpolator, level, allow_3color, allow_3color_black)), _bc4_encoder(std::make_shared(3)) {} + BC3Encoder(BC1EncoderPtr bc1_encoder) : _bc1_encoder(bc1_encoder), _bc4_encoder(std::make_shared(3)) {} + + BC3Encoder(unsigned level, bool allow_3color, bool allow_3color_black, InterpolatorPtr interpolator) + : BC3Encoder(std::make_shared(level, allow_3color, allow_3color_black, interpolator)) {} + + BC3Encoder(unsigned level = 5, bool allow_3color = true, bool allow_3color_black = true) + : BC3Encoder(std::make_shared(level, allow_3color, allow_3color_black, std::make_shared())) {} void EncodeBlock(Color4x4 pixels, BC3Block *dest) const override; diff --git a/quicktex/s3tc/bc3/_bindings.cpp b/quicktex/s3tc/bc3/_bindings.cpp index 089c53a..e1a6abf 100644 --- a/quicktex/s3tc/bc3/_bindings.cpp +++ b/quicktex/s3tc/bc3/_bindings.cpp @@ -35,7 +35,11 @@ namespace py = pybind11; namespace quicktex::bindings { using namespace quicktex::s3tc; +using namespace pybind11::literals; using InterpolatorPtr = std::shared_ptr; +using BC1EncoderPtr = std::shared_ptr; +using BC1DecoderPtr = std::shared_ptr; + void InitBC3(py::module_ &s3tc) { auto bc3 = s3tc.def_submodule("_bc3", "BC3 encoding/decoding module"); @@ -45,15 +49,20 @@ void InitBC3(py::module_ &s3tc) { // BC3Encoder py::class_ bc3_encoder(bc3, "BC3Encoder", block_encoder); - bc3_encoder.def(py::init(), py::arg("interpolator") = std::make_shared(), py::arg("level") = 5, - py::arg("use_3color") = true, py::arg("use_3color_black") = true); + bc3_encoder.def(py::init(), "bc1_encoder"_a); + bc3_encoder.def(py::init(), "level"_a = 5, "use_3color"_a = true, "use_3color_black"_a = true); + bc3_encoder.def(py::init(), "level"_a, "use_3color"_a, "use_3color_black"_a, "interpolator"_a); + bc3_encoder.def_property_readonly("bc1_encoder", &BC3Encoder::GetBC1Encoder); bc3_encoder.def_property_readonly("bc4_encoder", &BC3Encoder::GetBC4Encoder); // BC3Decoder py::class_ bc3_decoder(bc3, "BC3Decoder", block_decoder); - bc3_decoder.def(py::init(), py::arg("interpolator") = std::make_shared()); + bc3_decoder.def(py::init<>()); + bc3_decoder.def(py::init(), "bc1_decoder"_a); + bc3_decoder.def(py::init(), "interpolator"_a); + bc3_decoder.def_property_readonly("bc1_decoder", &BC3Decoder::GetBC1Decoder); bc3_decoder.def_property_readonly("bc4_decoder", &BC3Decoder::GetBC4Decoder); }; diff --git a/quicktex/s3tc/interpolator/__init__.py b/quicktex/s3tc/interpolator/__init__.py index 357d87a..d200e1f 100644 --- a/quicktex/s3tc/interpolator/__init__.py +++ b/quicktex/s3tc/interpolator/__init__.py @@ -1 +1 @@ -# from _quicktex._s3tc._interpolator import * \ No newline at end of file +from _quicktex._s3tc._interpolator import * \ No newline at end of file