quicktex/quicktex/_bindings.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

74 lines
2.3 KiB
C++
Raw Normal View History

2021-04-08 06:26:28 +00:00
/* Quicktex Texture Compression Library
2022-05-12 03:51:35 +00:00
Copyright (C) 2021-2022 Andrew Cassidy <drewcassidy@me.com>
2021-03-10 11:42:31 +00:00
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-03-28 09:36:47 +00:00
#include "_bindings.h"
2021-03-10 11:42:31 +00:00
#include <pybind11/pybind11.h>
2021-03-21 04:19:23 +00:00
2021-03-28 09:36:47 +00:00
#include "Color.h"
#include "Decoder.h"
#include "Encoder.h"
#include "Texture.h"
#include "_bindings.h"
2021-03-10 11:42:31 +00:00
2021-04-10 19:15:20 +00:00
#define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x)
2021-03-10 11:42:31 +00:00
namespace py = pybind11;
2021-03-28 09:36:47 +00:00
2021-03-13 12:14:04 +00:00
namespace quicktex::bindings {
2021-03-10 11:42:31 +00:00
2021-03-14 08:59:16 +00:00
void InitS3TC(py::module_ &m);
PYBIND11_MODULE(_quicktex, m) {
m.doc() = "More Stuff";
2021-04-10 19:15:20 +00:00
#ifdef VERSION_INFO
m.attr("__version__") = MACRO_STRINGIFY(VERSION_INFO);
#else
m.attr("__version__") = "dev";
#endif
2021-03-19 08:46:33 +00:00
py::options options;
2021-03-30 09:36:27 +00:00
// Texture
2021-03-30 02:58:46 +00:00
py::class_<Texture> texture(m, "Texture", py::buffer_protocol());
2021-03-10 11:42:31 +00:00
2021-04-08 23:04:21 +00:00
texture.def_property_readonly("nbytes", &Texture::NBytes);
2021-03-28 09:36:47 +00:00
texture.def_property_readonly("size", &Texture::Size);
texture.def_property_readonly("width", &Texture::Width);
texture.def_property_readonly("height", &Texture::Height);
2021-03-10 11:49:06 +00:00
2021-04-08 23:04:21 +00:00
texture.def_buffer([](Texture &t) { return py::buffer_info(t.Data(), t.NBytes()); });
texture.def("tobytes", [](const Texture &t) { return py::bytes(reinterpret_cast<const char *>(t.Data()), t.NBytes()); });
2021-03-30 02:38:37 +00:00
2021-04-01 03:26:40 +00:00
// RawTexture
2021-03-30 09:36:27 +00:00
2021-04-05 09:44:56 +00:00
py::class_<RawTexture, Texture> raw_texture(m, "RawTexture");
2021-03-10 12:15:09 +00:00
2021-03-28 09:36:47 +00:00
raw_texture.def(py::init<int, int>(), "width"_a, "height"_a);
2021-04-01 03:26:40 +00:00
raw_texture.def_static("frombytes", &BufferToTexture<RawTexture>, "data"_a, "width"_a, "height"_a);
2021-03-30 09:36:27 +00:00
2021-04-08 23:04:21 +00:00
DefSubscript2D(raw_texture, &RawTexture::GetPixel, &RawTexture::SetPixel, &RawTexture::Size);
2021-03-10 12:15:09 +00:00
2021-04-01 03:26:40 +00:00
InitS3TC(m);
2021-03-10 11:42:31 +00:00
}
2021-03-13 12:14:04 +00:00
} // namespace quicktex::bindings