From 0eade805673bfdda2f132f147d2698aa56a6b751 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 13 Feb 2022 12:37:23 +0100 Subject: [PATCH] python: expose RGB<->XYZ conversion utilities. I just needed to calculate expected output for a doc snippet, that's all. --- doc/python/pages/changelog.rst | 2 ++ src/python/magnum/math.vector.h | 20 +++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/doc/python/pages/changelog.rst b/doc/python/pages/changelog.rst index aaec17e..770089b 100644 --- a/doc/python/pages/changelog.rst +++ b/doc/python/pages/changelog.rst @@ -46,6 +46,8 @@ Changelog :ref:`Matrix3.projection()` - Exposed remaining vector/scalar, exponential and other functions in the :ref:`math ` library +- Exposed :ref:`Color3.from_xyz()`, :ref:`Color3.to_xyz()` and equivalent + APIs on :ref:`Color4` - Exposed :ref:`gl.Context` and its platform-specific subclasses for EGL, WGL and GLX - Exposed :ref:`gl.Framebuffer.attach_texture()` and missing sRGB, depth diff --git a/src/python/magnum/math.vector.h b/src/python/magnum/math.vector.h index ad879f2..8bcd88b 100644 --- a/src/python/magnum/math.vector.h +++ b/src/python/magnum/math.vector.h @@ -575,10 +575,11 @@ template void color3(py::class_, Math::Vector3>& c) .def_static("from_hsv", [](Degd hue, typename Math::Color3::FloatingPointType saturation, typename Math::Color3::FloatingPointType value) { return Math::Color3::fromHsv({Math::Deg(hue), saturation, value}); }, "Create RGB color from HSV representation", py::arg("hue"), py::arg("saturation"), py::arg("value")) - .def_static("from_srgb", [](UnsignedInt srgb) { return Math::Color3::fromSrgb(srgb); }, "Create linear RGB color from 24-bit sRGB representation", py::arg("srgb")) + .def_static("from_xyz", &Color3::fromXyz, + "Create RGB color from CIE XYZ representation", py::arg("xyz")) .def_static("red", &Math::Color3::red, "Red color", py::arg("red") = Math::Implementation::fullChannel()) @@ -594,8 +595,6 @@ template void color3(py::class_, Math::Vector3>& c) "Yellow color", py::arg("blue") = T(0)) /* Accessors */ - .def("to_srgb_int", &Math::Color3::toSrgbInt, - "Convert to 32-bit integral sRGB representation") .def("to_hsv", [](Math::Color3& self) { auto hsv = self.toHsv(); return std::make_tuple(Degd(hsv.hue), hsv.saturation, hsv.value); @@ -604,7 +603,11 @@ template void color3(py::class_, Math::Vector3>& c) return Degd(self.hue()); }, "Hue") .def("saturation", &Math::Color3::saturation, "Saturation") - .def("value", &Math::Color3::value, "Value"); + .def("value", &Math::Color3::value, "Value") + .def("to_srgb_int", &Math::Color3::toSrgbInt, + "Convert to 32-bit integral sRGB representation") + .def("to_xyz", &Math::Color3::toXyz, + "Convert to CIE XYZ representation"); } /* Needs to be separate to make it a priority over buffer protocol */ @@ -638,10 +641,11 @@ template void color4(py::class_, Math::Vector4>& c) .def_static("from_srgb_alpha", [](UnsignedInt srgbAlpha) { return Math::Color4::fromSrgbAlpha(srgbAlpha); }, "Create linear RGBA color from 32-bit sRGB a alpha representation", py::arg("srgb_alpha")) - .def_static("from_srgb", [](UnsignedInt srgb, T a) { return Math::Color4::fromSrgb(srgb, a); }, "Create linear RGBA color from 32-bit sRGB a alpha representation", py::arg("srgb"), py::arg("a") = Math::Implementation::fullChannel()) + .def_static("from_xyz", &Color4::fromXyz, + "Create RGBA color from CIE XYZ representation", py::arg("xyz"), py::arg("a") = Math::Implementation::fullChannel()) .def_static("red", &Math::Color4::red, "Red color", @@ -669,8 +673,6 @@ template void color4(py::class_, Math::Vector4>& c) py::arg("alpha") = Math::Implementation::fullChannel()) /* Accessors */ - .def("to_srgb_alpha_int", &Math::Color4::toSrgbAlphaInt, - "Convert to 32-bit integral sRGB + linear alpha representation") .def("to_hsv", [](Math::Color4& self) { auto hsv = self.toHsv(); return std::make_tuple(Degd(hsv.hue), hsv.saturation, hsv.value); @@ -680,6 +682,10 @@ template void color4(py::class_, Math::Vector4>& c) }, "Hue") .def("saturation", &Math::Color4::saturation, "Saturation") .def("value", &Math::Color4::value, "Value") + .def("to_srgb_alpha_int", &Math::Color4::toSrgbAlphaInt, + "Convert to 32-bit integral sRGB + linear alpha representation") + .def("to_xyz", &Math::Color4::toXyz, + "Convert to CIE XYZ representation") /* Properties */ .def_property("xyz",