Make interpolators available in python

hotfix/mipmap-alpha-fix
Andrew Cassidy 3 years ago
parent d39e0c06f7
commit 64919ab55a

@ -17,6 +17,7 @@ file(GLOB SOURCE_FILES
"quicktex/s3tc/bc3/*.cpp"
"quicktex/s3tc/bc4/*.cpp"
"quicktex/s3tc/bc5/*.cpp"
"quicktex/s3tc/interpolator/*.cpp"
)
file(GLOB HEADER_FILES
@ -26,6 +27,7 @@ file(GLOB HEADER_FILES
"quicktex/s3tc/bc3/*.h"
"quicktex/s3tc/bc4/*.h"
"quicktex/s3tc/bc5/*.h"
"quicktex/s3tc/interpolator/*.h"
)
file(GLOB TEST_FILES "tests/*.cpp")

@ -1,81 +1,11 @@
.. py:currentmodule:: quicktex.s3tc
.. py:module:: quicktex.s3tc
s3tc module
===========
.. pybind handles enums in a really weird way that doesnt play nice with Sphinx,
so the docs are rewritten here.
.. py:class:: InterpolatorType
An enum representing various methods for interpolating colors, used by the BC1 and BC3 encoders/decoders.
Vendor-specific interpolation modes should only be used when the result will only be used on that type of GPU.
For most applications, :py:attr:`~quicktex.s3tc.InterpolatorType.Ideal` should be used.
.. py:data:: Ideal
The default mode, with no rounding for colors 2 and 3. This matches the D3D10 docs on BC1.
.. py:data:: IdealRound
Round colors 2 and 3. Matches the AMD Compressonator tool and the D3D9 docs on DXT1.
.. py:data:: Nvidia
Nvidia GPU mode.
.. py:data:: AMD
AMD GPU mode.
bc1 module
----------
.. automodule:: quicktex.s3tc.bc1
.. autoclass:: BC1Encoder
:members:
:undoc-members:
.. autoclass:: BC1Decoder
:members:
:undoc-members:
bc3 module
----------
.. automodule:: quicktex.s3tc.bc3
.. autoclass:: BC3Encoder
:members:
:undoc-members:
.. autoclass:: BC3Decoder
:members:
:undoc-members:
bc4 module
----------
.. automodule:: quicktex.s3tc.bc4
.. autoclass:: BC4Encoder
:members:
:undoc-members:
.. autoclass:: BC4Decoder
:members:
:undoc-members:
bc5 module
----------
.. automodule:: quicktex.s3tc.bc5
.. autoclass:: BC5Encoder
:members:
:undoc-members:
.. autoclass:: BC5Decoder
:members:
:undoc-members:
:members:
:undoc-members:

@ -19,7 +19,7 @@
#include <pybind11/pybind11.h>
#include "Interpolator.h"
#include "interpolator/Interpolator.h"
namespace py = pybind11;
namespace quicktex::bindings {
@ -27,6 +27,7 @@ namespace quicktex::bindings {
using namespace quicktex;
using namespace quicktex::s3tc;
void InitInterpolator(py::module_ &s3tc);
void InitBC1(py::module_ &s3tc);
void InitBC3(py::module_ &s3tc);
void InitBC4(py::module_ &s3tc);
@ -35,7 +36,7 @@ void InitBC5(py::module_ &s3tc);
void InitS3TC(py::module_ &m) {
py::module_ s3tc = m.def_submodule("_s3tc", "s3tc compression library based on rgbcx.h written by Richard Goldreich");
using IType = Interpolator::Type;
/* using IType = Interpolator::Type;
auto interpolator_type = py::enum_<IType>(s3tc, "InterpolatorType", R"pbdoc(
An enum representing various methods for interpolating colors, used by the BC1 and BC3 encoders/decoders.
Vendor-specific interpolation modes should only be used when the result will only be used on that type of GPU.
@ -45,8 +46,9 @@ For most applications, :py:attr:`~quicktex.s3tc.InterpolatorType.Ideal` should b
interpolator_type.value("Ideal", IType::Ideal, "The default mode, with no rounding for colors 2 and 3. This matches the D3D10 docs on BC1.");
interpolator_type.value("IdealRound", IType::IdealRound, "Round colors 2 and 3. Matches the AMD Compressonator tool and the D3D9 docs on DXT1.");
interpolator_type.value("Nvidia", IType::Nvidia, "Nvidia GPU mode.");
interpolator_type.value("AMD", IType::AMD, "AMD GPU mode.");
interpolator_type.value("AMD", IType::AMD, "AMD GPU mode.");*/
InitInterpolator(s3tc);
InitBC1(s3tc);
InitBC3(s3tc);
InitBC4(s3tc);

@ -25,15 +25,15 @@
#include "../../BlockDecoder.h"
#include "../../BlockView.h"
#include "../../ndebug.h"
#include "../Interpolator.h"
#include "../interpolator/Interpolator.h"
#include "BC1Block.h"
namespace quicktex::s3tc {
namespace quicktex::s3tc {
class BC1Decoder final : public BlockDecoderTemplate<BC1Block, 4, 4> {
public:
using InterpolatorPtr = std::shared_ptr<Interpolator>;
BC1Decoder(Interpolator::Type type = Interpolator::Type::Ideal, bool write_alpha = false)
: write_alpha(write_alpha), _interpolator(Interpolator::MakeInterpolator(type)) {}
BC1Decoder(InterpolatorPtr interpolator = std::make_shared<Interpolator>(), bool write_alpha = false)
: write_alpha(write_alpha), _interpolator(interpolator) {}
void DecodeBlock(Color4x4 dest, BC1Block *const block) const noexcept(ndebug) override;

@ -34,7 +34,7 @@
#include "../../Vector4Int.h"
#include "../../bitwiseEnums.h"
#include "../../util.h"
#include "../Interpolator.h"
#include "../interpolator/Interpolator.h"
#include "Histogram.h"
#include "OrderTable.h"
#include "SingleColorTable.h"
@ -43,8 +43,8 @@ namespace quicktex::s3tc {
// constructors
BC1Encoder::BC1Encoder(Interpolator::Type type, unsigned int level, bool allow_3color, bool allow_3color_black)
: _interpolator(Interpolator::MakeInterpolator(type)) {
BC1Encoder::BC1Encoder(InterpolatorPtr interpolator, unsigned int level, bool allow_3color, bool allow_3color_black)
: _interpolator(interpolator) {
OrderTable<3>::Generate();
OrderTable<4>::Generate();

@ -29,7 +29,7 @@
#include "../../BlockEncoder.h"
#include "../../BlockView.h"
#include "../../Color.h"
#include "../Interpolator.h"
#include "../interpolator/Interpolator.h"
#include "BC1Block.h"
#include "SingleColorTable.h"
@ -111,7 +111,7 @@ class BC1Encoder final : public BlockEncoderTemplate<BC1Block, 4, 4> {
PCA
};
BC1Encoder(Interpolator::Type type = Interpolator::Type::Ideal, unsigned level = 5, bool allow_3color = true, bool allow_3color_black = true);
BC1Encoder(InterpolatorPtr interpolator = std::make_shared<Interpolator>(), unsigned level = 5, bool allow_3color = true, bool allow_3color_black = true);
Interpolator::Type GetInterpolatorType() const { return _interpolator->GetType(); }

@ -24,7 +24,7 @@
#include <memory>
#include "../../util.h"
#include "../Interpolator.h"
#include "../interpolator/Interpolator.h"
namespace quicktex::s3tc {

@ -27,7 +27,7 @@
#include "../../BlockDecoder.h"
#include "../../BlockEncoder.h"
#include "../Interpolator.h"
#include "../interpolator/Interpolator.h"
#include "BC1Decoder.h"
#include "BC1Encoder.h"
@ -35,7 +35,7 @@ namespace py = pybind11;
namespace quicktex::bindings {
using namespace quicktex::s3tc;
using namespace quicktex::s3tc ;
using InterpolatorPtr = std::shared_ptr<Interpolator>;
void InitBC1(py::module_ &s3tc) {
auto bc1 = s3tc.def_submodule("_bc1", "BC1 encoding/decoding module");
@ -45,7 +45,7 @@ void InitBC1(py::module_ &s3tc) {
// BC1Encoder
py::class_<BC1Encoder> bc1_encoder(bc1, "BC1Encoder", block_encoder);
bc1_encoder.def(py::init<Interpolator::Type, unsigned, bool, bool>(), py::arg("interpolator") = Interpolator::Type::Ideal, py::arg("level") = 5,
bc1_encoder.def(py::init<InterpolatorPtr, unsigned, bool, bool>(), py::arg("interpolator") = std::make_shared<Interpolator>(), py::arg("level") = 5,
py::arg("use_3color") = true, py::arg("use_3color_black") = true);
bc1_encoder.def("set_level", &BC1Encoder::SetLevel);
bc1_encoder.def_property_readonly("interpolator_type", &BC1Encoder::GetInterpolatorType);
@ -89,7 +89,7 @@ void InitBC1(py::module_ &s3tc) {
// BC1Decoder
py::class_<BC1Decoder> bc1_decoder(bc1, "BC1Decoder", block_decoder);
bc1_decoder.def(py::init<Interpolator::Type, bool>(), py::arg("interpolator") = Interpolator::Type::Ideal, py::arg("write_alpha") = false);
bc1_decoder.def(py::init<InterpolatorPtr, bool>(), py::arg("interpolator") = std::make_shared<Interpolator>(), py::arg("write_alpha") = false);
bc1_decoder.def_property_readonly("interpolator_type", &BC1Decoder::GetInterpolatorType);
bc1_decoder.def_readwrite("write_alpha", &BC1Decoder::write_alpha);
}

@ -24,9 +24,9 @@
#include "../../BlockDecoder.h"
#include "../../BlockView.h"
#include "../../ndebug.h"
#include "../Interpolator.h"
#include "../bc1/BC1Decoder.h"
#include "../bc4/BC4Decoder.h"
#include "../interpolator/Interpolator.h"
#include "BC3Block.h"
namespace quicktex::s3tc {
@ -35,8 +35,9 @@ class BC3Decoder : public BlockDecoderTemplate<BC3Block, 4, 4> {
public:
using BC1DecoderPtr = std::shared_ptr<BC1Decoder>;
using BC4DecoderPtr = std::shared_ptr<BC4Decoder>;
using InterpolatorPtr = std::shared_ptr<Interpolator>;
BC3Decoder(Interpolator::Type type = Interpolator::Type::Ideal) : BC3Decoder(std::make_shared<BC1Decoder>(type), std::make_shared<BC4Decoder>(3)) {}
BC3Decoder(InterpolatorPtr interpolator = std::make_shared<Interpolator>()) : BC3Decoder(std::make_shared<BC1Decoder>(interpolator), 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;

@ -23,9 +23,9 @@
#include "../../BlockEncoder.h"
#include "../../BlockView.h"
#include "../Interpolator.h"
#include "../bc1/BC1Encoder.h"
#include "../bc4/BC4Encoder.h"
#include "../interpolator/Interpolator.h"
#include "BC3Block.h"
namespace quicktex::s3tc {
@ -34,9 +34,10 @@ class BC3Encoder : public BlockEncoderTemplate<BC3Block, 4, 4> {
public:
using BC1EncoderPtr = std::shared_ptr<BC1Encoder>;
using BC4EncoderPtr = std::shared_ptr<BC4Encoder>;
using InterpolatorPtr = std::shared_ptr<Interpolator>;
BC3Encoder(Interpolator::Type type = Interpolator::Type::Ideal, unsigned level = 5, bool allow_3color = true, bool allow_3color_black = true)
: _bc1_encoder(std::make_shared<BC1Encoder>(type, level, allow_3color, allow_3color_black)), _bc4_encoder(std::make_shared<BC4Encoder>(3)) {}
BC3Encoder(InterpolatorPtr interpolator = std::make_shared<Interpolator>(), unsigned level = 5, bool allow_3color = true, bool allow_3color_black = true)
: _bc1_encoder(std::make_shared<BC1Encoder>(interpolator, level, allow_3color, allow_3color_black)), _bc4_encoder(std::make_shared<BC4Encoder>(3)) {}
void EncodeBlock(Color4x4 pixels, BC3Block *dest) const override;

@ -27,7 +27,7 @@
#include "../../BlockDecoder.h"
#include "../../BlockEncoder.h"
#include "../Interpolator.h"
#include "../interpolator/Interpolator.h"
#include "BC3Decoder.h"
#include "BC3Encoder.h"
@ -35,7 +35,7 @@ namespace py = pybind11;
namespace quicktex::bindings {
using namespace quicktex::s3tc;
using namespace quicktex::s3tc ;
using InterpolatorPtr = std::shared_ptr<Interpolator>;
void InitBC3(py::module_ &s3tc) {
auto bc3 = s3tc.def_submodule("_bc3", "BC3 encoding/decoding module");
@ -45,7 +45,7 @@ void InitBC3(py::module_ &s3tc) {
// BC3Encoder
py::class_<BC3Encoder> bc3_encoder(bc3, "BC3Encoder", block_encoder);
bc3_encoder.def(py::init<Interpolator::Type, unsigned, bool, bool>(), py::arg("interpolator") = Interpolator::Type::Ideal, py::arg("level") = 5,
bc3_encoder.def(py::init<InterpolatorPtr, unsigned, bool, bool>(), py::arg("interpolator") = std::make_shared<Interpolator>(), py::arg("level") = 5,
py::arg("use_3color") = true, py::arg("use_3color_black") = true);
bc3_encoder.def_property_readonly("bc1_encoder", &BC3Encoder::GetBC1Encoder);
bc3_encoder.def_property_readonly("bc4_encoder", &BC3Encoder::GetBC4Encoder);
@ -53,7 +53,7 @@ void InitBC3(py::module_ &s3tc) {
// BC3Decoder
py::class_<BC3Decoder> bc3_decoder(bc3, "BC3Decoder", block_decoder);
bc3_decoder.def(py::init<Interpolator::Type>(), py::arg("type") = Interpolator::Type::Ideal);
bc3_decoder.def(py::init<InterpolatorPtr>(), py::arg("interpolator") = std::make_shared<Interpolator>());
bc3_decoder.def_property_readonly("bc1_decoder", &BC3Decoder::GetBC1Decoder);
bc3_decoder.def_property_readonly("bc4_decoder", &BC3Decoder::GetBC4Decoder);
};

@ -24,7 +24,7 @@
#include <cstdint>
#include <stdexcept>
#include "../util.h"
#include "../../util.h"
namespace quicktex::s3tc {

@ -22,7 +22,7 @@
#include <cstdint> // for uint8_t, uint16_t
#include <memory> // for unique_ptr
#include "../Color.h" // for Color
#include "../../Color.h" // for Color
namespace quicktex::s3tc {

@ -0,0 +1 @@
# from _quicktex._s3tc._interpolator import *

@ -0,0 +1,50 @@
/* Python-rgbcx Texture Compression Library
Copyright (C) 2021 Andrew Cassidy <drewcassidy@me.com>
Partially derived from rgbcx.h written by Richard Geldreich <richgel99@gmail.com>
and licenced under the public domain
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <pybind11/pybind11.h>
#include <array>
#include "Interpolator.h"
namespace py = pybind11;
namespace quicktex::bindings {
using namespace quicktex::s3tc;
using InterpolatorPtr = std::shared_ptr<Interpolator>;
void InitInterpolator(py::module_ &s3tc) {
auto interpolator = s3tc.def_submodule("_interpolator", "Classes defining various methods of interpolating colors in BC1 and BC3 textures");
// Interpolator
py::class_<Interpolator> ideal(
interpolator, "Interpolator",
"Interpolator base class representing the default mode, with no rounding for colors 2 and 3. This matches the D3D10 docs on BC1.");
// InterpolatorRound
py::class_<InterpolatorRound> round(interpolator, "InterpolatorRound", ideal,
"Round colors 2 and 3. Matches the AMD Compressonator tool and the D3D9 docs on DXT1.");
// InterpolatorNvidia
py::class_<InterpolatorNvidia> nvidia(interpolator, "InterpolatorNvidia", ideal, "Nvidia GPU mode.");
// InterpolatorAMD
py::class_<InterpolatorAMD> amd(interpolator, "InterpolatorAMD", ideal, "AMD GPU mode.");
}
} // namespace quicktex::bindings
Loading…
Cancel
Save