quicktex/quicktex/s3tc/bc3/_bindings.cpp

106 lines
4.3 KiB
C++
Raw Normal View History

2021-03-14 08:59:16 +00:00
/* 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/>.
*/
2021-04-01 23:37:15 +00:00
#include "../../_bindings.h"
2021-03-14 08:59:16 +00:00
#include <pybind11/pybind11.h>
#include <array>
#include <cstddef>
#include <cstdint>
#include <stdexcept>
#include <string>
2021-03-28 09:36:47 +00:00
#include "../../Decoder.h"
#include "../../Encoder.h"
2021-03-16 02:01:42 +00:00
#include "../interpolator/Interpolator.h"
2021-03-14 08:59:16 +00:00
#include "BC3Decoder.h"
#include "BC3Encoder.h"
namespace py = pybind11;
namespace quicktex::bindings {
using namespace quicktex::s3tc;
2021-03-17 08:13:11 +00:00
using namespace pybind11::literals;
2021-03-16 02:01:42 +00:00
using InterpolatorPtr = std::shared_ptr<Interpolator>;
2021-03-17 08:13:11 +00:00
using BC1EncoderPtr = std::shared_ptr<BC1Encoder>;
using BC1DecoderPtr = std::shared_ptr<BC1Decoder>;
2021-03-14 08:59:16 +00:00
void InitBC3(py::module_ &s3tc) {
2021-03-21 04:19:23 +00:00
auto bc3 = s3tc.def_submodule("_bc3", "internal bc3 module");
py::options options;
options.disable_function_signatures();
2021-03-14 08:59:16 +00:00
2021-04-01 23:37:15 +00:00
// region BC3Block
auto bc3_block = BindBlock<BC3Block>(bc3, "BC3Block");
bc3_block.def(py::init<>());
bc3_block.def(py::init<BC4Block, BC1Block>(), "alpha_block"_a, "color_block"_a);
bc3_block.def_readwrite("alpha_block", &BC3Block::alpha_block);
bc3_block.def_readwrite("color_block", &BC3Block::color_block);
// endregion
// region BC3Encoder
2021-03-28 09:36:47 +00:00
py::class_<BC3Encoder> bc3_encoder(bc3, "BC3Encoder", R"doc(
2021-03-22 03:36:26 +00:00
Base: :py:class:`~quicktex.BlockEncoder`
Encodes RGBA textures to BC3
)doc");
2021-03-14 08:59:16 +00:00
bc3_encoder.def(py::init<unsigned>(), "level"_a = 5);
2021-03-21 04:19:23 +00:00
bc3_encoder.def(py::init<unsigned, InterpolatorPtr>(), "level"_a, "interpolator"_a, R"doc(
__init__(self, level: int = 5, interpolator=Interpolator()) -> None
2021-03-17 08:13:11 +00:00
2021-03-21 04:19:23 +00:00
Create a new BC3 encoder with the specified preset level and interpolator.
:param int level: The preset level of the resulting encoder, between 0 and 18 inclusive.
See :py:meth:`~quicktex.s3tc.bc1.BC1Encoder.set_level` for more information. Default: 5.
:param Interpolator interpolator: The interpolation mode to use for encoding. Default: :py:class:`~quicktex.s3tc.interpolator.Interpolator`.
)doc");
bc3_encoder.def_property_readonly("bc1_encoder", &BC3Encoder::GetBC1Encoder,
"Internal :py:class:`~quicktex.s3tc.bc1.BC1Encoder` used for RGB data. Readonly.");
bc3_encoder.def_property_readonly("bc4_encoder", &BC3Encoder::GetBC4Encoder,
"Internal :py:class:`~quicktex.s3tc.bc4.BC4Encoder` used for alpha data. Readonly.");
2021-04-01 23:37:15 +00:00
// endregion
2021-03-14 08:59:16 +00:00
2021-04-01 23:37:15 +00:00
// region BC3Decoder
2021-03-28 09:36:47 +00:00
py::class_<BC3Decoder> bc3_decoder(bc3, "BC3Decoder", R"doc(
2021-03-22 03:36:26 +00:00
Base: :py:class:`~quicktex.BlockDecoder`
Decodes BC3 textures to RGBA
)doc");
2021-03-14 08:59:16 +00:00
2021-03-17 08:13:11 +00:00
bc3_decoder.def(py::init<>());
2021-03-21 04:19:23 +00:00
bc3_decoder.def(py::init<InterpolatorPtr>(), "interpolator"_a, R"doc(
__init__(interpolator = Interpolator()) -> None
Create a new BC3 decoder with the specified interpolator.
:param Interpolator interpolator: The interpolation mode to use for decoding. Default: :py:class:`~quicktex.s3tc.interpolator.Interpolator`.
)doc");
2021-03-17 08:13:11 +00:00
2021-03-21 04:19:23 +00:00
bc3_decoder.def_property_readonly("bc1_decoder", &BC3Decoder::GetBC1Decoder,
"Internal :py:class:`~quicktex.s3tc.bc1.BC1Decoder` used for RGB data. Readonly.");
bc3_decoder.def_property_readonly("bc4_decoder", &BC3Decoder::GetBC4Decoder,
"Internal :py:class:`~quicktex.s3tc.bc4.BC4Decoder` used for alpha data. Readonly.");
2021-04-01 23:37:15 +00:00
// endregion
2021-03-14 08:59:16 +00:00
};
} // namespace quicktex::bindings