quicktex/quicktex/_bindings.cpp

65 lines
2.2 KiB
C++
Raw Normal View History

2021-03-10 11:42:31 +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-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
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-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-03-28 09:36:47 +00:00
texture.def_property_readonly("size", &Texture::Size);
texture.def_property_readonly("dimensions", &Texture::Dimensions);
texture.def_property_readonly("width", &Texture::Width);
texture.def_property_readonly("height", &Texture::Height);
2021-03-10 11:49:06 +00:00
2021-03-30 02:58:46 +00:00
texture.def_buffer([](Texture &t) { return py::buffer_info(t.Data(), t.Size()); });
2021-03-30 05:15:53 +00:00
texture.def("tobytes", [](const Texture &t) { return py::bytes(reinterpret_cast<const char *>(t.Data()), t.Size()); });
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-03-28 09:36:47 +00:00
py::class_<RawTexture> raw_texture(m, "RawTexture", texture);
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
DefSubscript2D(raw_texture, &RawTexture::GetPixel, &RawTexture::SetPixel, &RawTexture::Dimensions);
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