Message ID | 20220505104104.70841-11-tomi.valkeinen@ideasonboard.com |
---|---|
State | Superseded |
Headers | show |
Series |
|
Related | show |
Hi Tomi and David, Thank you for the patch. On Thu, May 05, 2022 at 01:41:01PM +0300, Tomi Valkeinen wrote: > From: David Plowman <david.plowman@raspberrypi.com> > > Add binding for ColorSpace. > > Original version by David Plowman <david.plowman@raspberrypi.com>. > > Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> > --- > src/py/libcamera/pymain.cpp | 52 ++++++++++++++++++++++++++++++++++++- > 1 file changed, 51 insertions(+), 1 deletion(-) > > diff --git a/src/py/libcamera/pymain.cpp b/src/py/libcamera/pymain.cpp > index 3d2393ab..c442ad50 100644 > --- a/src/py/libcamera/pymain.cpp > +++ b/src/py/libcamera/pymain.cpp > @@ -153,6 +153,11 @@ PYBIND11_MODULE(_libcamera, m) > auto pyRequest = py::class_<Request>(m, "Request"); > auto pyFrameMetadata = py::class_<FrameMetadata>(m, "FrameMetadata"); > auto pyTransform = py::class_<Transform>(m, "Transform"); > + auto pyColorSpace = py::class_<ColorSpace>(m, "ColorSpace"); > + auto pyColorSpacePrimaries = py::enum_<ColorSpace::Primaries>(pyColorSpace, "Primaries"); > + auto pyColorSpaceTransferFunction = py::enum_<ColorSpace::TransferFunction>(pyColorSpace, "TransferFunction"); > + auto pyColorSpaceYcbcrEncoding = py::enum_<ColorSpace::YcbcrEncoding>(pyColorSpace, "YcbcrEncoding"); > + auto pyColorSpaceRange = py::enum_<ColorSpace::Range>(pyColorSpace, "Range"); I think the enums should go to pyenums.cpp. Same for the related code below. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > > /* Global functions */ > m.def("logSetLevel", &logSetLevel); > @@ -360,7 +365,8 @@ PYBIND11_MODULE(_libcamera, m) > .def_readwrite("stride", &StreamConfiguration::stride) > .def_readwrite("frameSize", &StreamConfiguration::frameSize) > .def_readwrite("bufferCount", &StreamConfiguration::bufferCount) > - .def_property_readonly("formats", &StreamConfiguration::formats, py::return_value_policy::reference_internal); > + .def_property_readonly("formats", &StreamConfiguration::formats, py::return_value_policy::reference_internal) > + .def_readwrite("colorSpace", &StreamConfiguration::colorSpace); > > pyStreamFormats > .def_property_readonly("pixelFormats", [](StreamFormats &self) { > @@ -523,4 +529,48 @@ PYBIND11_MODULE(_libcamera, m) > .def("compose", [](Transform &self, Transform &other) { > self = self * other; > }); > + > + pyColorSpace > + .def(py::init([](ColorSpace::Primaries primaries, > + ColorSpace::TransferFunction transferFunction, > + ColorSpace::YcbcrEncoding ycbcrEncoding, > + ColorSpace::Range range) { > + return ColorSpace(primaries, transferFunction, ycbcrEncoding, range); > + }), py::arg("primaries"), py::arg("transferFunction"), > + py::arg("ycbcrEncoding"), py::arg("range")) > + .def(py::init([](ColorSpace &other) { return other; })) > + .def("__repr__", [](ColorSpace &self) { > + return "<libcamera.ColorSpace '" + self.toString() + "'>"; > + }) > + .def_readwrite("primaries", &ColorSpace::primaries) > + .def_readwrite("transferFunction", &ColorSpace::transferFunction) > + .def_readwrite("ycbcrEncoding", &ColorSpace::ycbcrEncoding) > + .def_readwrite("range", &ColorSpace::range) > + .def_static("Raw", []() { return ColorSpace::Raw; }) > + .def_static("Jpeg", []() { return ColorSpace::Jpeg; }) > + .def_static("Srgb", []() { return ColorSpace::Srgb; }) > + .def_static("Smpte170m", []() { return ColorSpace::Smpte170m; }) > + .def_static("Rec709", []() { return ColorSpace::Rec709; }) > + .def_static("Rec2020", []() { return ColorSpace::Rec2020; }); > + > + pyColorSpacePrimaries > + .value("Raw", ColorSpace::Primaries::Raw) > + .value("Smpte170m", ColorSpace::Primaries::Smpte170m) > + .value("Rec709", ColorSpace::Primaries::Rec709) > + .value("Rec2020", ColorSpace::Primaries::Rec2020); > + > + pyColorSpaceTransferFunction > + .value("Linear", ColorSpace::TransferFunction::Linear) > + .value("Srgb", ColorSpace::TransferFunction::Srgb) > + .value("Rec709", ColorSpace::TransferFunction::Rec709); > + > + pyColorSpaceYcbcrEncoding > + .value("Null", ColorSpace::YcbcrEncoding::None) > + .value("Rec601", ColorSpace::YcbcrEncoding::Rec601) > + .value("Rec709", ColorSpace::YcbcrEncoding::Rec709) > + .value("Rec2020", ColorSpace::YcbcrEncoding::Rec2020); > + > + pyColorSpaceRange > + .value("Full", ColorSpace::Range::Full) > + .value("Limited", ColorSpace::Range::Limited); > }
On 05/05/2022 21:01, Laurent Pinchart wrote: > Hi Tomi and David, > > Thank you for the patch. > > On Thu, May 05, 2022 at 01:41:01PM +0300, Tomi Valkeinen wrote: >> From: David Plowman <david.plowman@raspberrypi.com> >> >> Add binding for ColorSpace. >> >> Original version by David Plowman <david.plowman@raspberrypi.com>. >> >> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> >> --- >> src/py/libcamera/pymain.cpp | 52 ++++++++++++++++++++++++++++++++++++- >> 1 file changed, 51 insertions(+), 1 deletion(-) >> >> diff --git a/src/py/libcamera/pymain.cpp b/src/py/libcamera/pymain.cpp >> index 3d2393ab..c442ad50 100644 >> --- a/src/py/libcamera/pymain.cpp >> +++ b/src/py/libcamera/pymain.cpp >> @@ -153,6 +153,11 @@ PYBIND11_MODULE(_libcamera, m) >> auto pyRequest = py::class_<Request>(m, "Request"); >> auto pyFrameMetadata = py::class_<FrameMetadata>(m, "FrameMetadata"); >> auto pyTransform = py::class_<Transform>(m, "Transform"); >> + auto pyColorSpace = py::class_<ColorSpace>(m, "ColorSpace"); >> + auto pyColorSpacePrimaries = py::enum_<ColorSpace::Primaries>(pyColorSpace, "Primaries"); >> + auto pyColorSpaceTransferFunction = py::enum_<ColorSpace::TransferFunction>(pyColorSpace, "TransferFunction"); >> + auto pyColorSpaceYcbcrEncoding = py::enum_<ColorSpace::YcbcrEncoding>(pyColorSpace, "YcbcrEncoding"); >> + auto pyColorSpaceRange = py::enum_<ColorSpace::Range>(pyColorSpace, "Range"); > > I think the enums should go to pyenums.cpp. Same for the related code > below. They depend on pyColorSpace, which is not an enum. Tomi
On Fri, May 06, 2022 at 04:02:08PM +0300, Tomi Valkeinen wrote: > On 05/05/2022 21:01, Laurent Pinchart wrote: > > Hi Tomi and David, > > > > Thank you for the patch. > > > > On Thu, May 05, 2022 at 01:41:01PM +0300, Tomi Valkeinen wrote: > >> From: David Plowman <david.plowman@raspberrypi.com> > >> > >> Add binding for ColorSpace. > >> > >> Original version by David Plowman <david.plowman@raspberrypi.com>. > >> > >> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> > >> --- > >> src/py/libcamera/pymain.cpp | 52 ++++++++++++++++++++++++++++++++++++- > >> 1 file changed, 51 insertions(+), 1 deletion(-) > >> > >> diff --git a/src/py/libcamera/pymain.cpp b/src/py/libcamera/pymain.cpp > >> index 3d2393ab..c442ad50 100644 > >> --- a/src/py/libcamera/pymain.cpp > >> +++ b/src/py/libcamera/pymain.cpp > >> @@ -153,6 +153,11 @@ PYBIND11_MODULE(_libcamera, m) > >> auto pyRequest = py::class_<Request>(m, "Request"); > >> auto pyFrameMetadata = py::class_<FrameMetadata>(m, "FrameMetadata"); > >> auto pyTransform = py::class_<Transform>(m, "Transform"); > >> + auto pyColorSpace = py::class_<ColorSpace>(m, "ColorSpace"); > >> + auto pyColorSpacePrimaries = py::enum_<ColorSpace::Primaries>(pyColorSpace, "Primaries"); > >> + auto pyColorSpaceTransferFunction = py::enum_<ColorSpace::TransferFunction>(pyColorSpace, "TransferFunction"); > >> + auto pyColorSpaceYcbcrEncoding = py::enum_<ColorSpace::YcbcrEncoding>(pyColorSpace, "YcbcrEncoding"); > >> + auto pyColorSpaceRange = py::enum_<ColorSpace::Range>(pyColorSpace, "Range"); > > > > I think the enums should go to pyenums.cpp. Same for the related code > > below. > > They depend on pyColorSpace, which is not an enum. Ah indeed. Would be nice to figure out a way to better organize these, but that's not required for now.
diff --git a/src/py/libcamera/pymain.cpp b/src/py/libcamera/pymain.cpp index 3d2393ab..c442ad50 100644 --- a/src/py/libcamera/pymain.cpp +++ b/src/py/libcamera/pymain.cpp @@ -153,6 +153,11 @@ PYBIND11_MODULE(_libcamera, m) auto pyRequest = py::class_<Request>(m, "Request"); auto pyFrameMetadata = py::class_<FrameMetadata>(m, "FrameMetadata"); auto pyTransform = py::class_<Transform>(m, "Transform"); + auto pyColorSpace = py::class_<ColorSpace>(m, "ColorSpace"); + auto pyColorSpacePrimaries = py::enum_<ColorSpace::Primaries>(pyColorSpace, "Primaries"); + auto pyColorSpaceTransferFunction = py::enum_<ColorSpace::TransferFunction>(pyColorSpace, "TransferFunction"); + auto pyColorSpaceYcbcrEncoding = py::enum_<ColorSpace::YcbcrEncoding>(pyColorSpace, "YcbcrEncoding"); + auto pyColorSpaceRange = py::enum_<ColorSpace::Range>(pyColorSpace, "Range"); /* Global functions */ m.def("logSetLevel", &logSetLevel); @@ -360,7 +365,8 @@ PYBIND11_MODULE(_libcamera, m) .def_readwrite("stride", &StreamConfiguration::stride) .def_readwrite("frameSize", &StreamConfiguration::frameSize) .def_readwrite("bufferCount", &StreamConfiguration::bufferCount) - .def_property_readonly("formats", &StreamConfiguration::formats, py::return_value_policy::reference_internal); + .def_property_readonly("formats", &StreamConfiguration::formats, py::return_value_policy::reference_internal) + .def_readwrite("colorSpace", &StreamConfiguration::colorSpace); pyStreamFormats .def_property_readonly("pixelFormats", [](StreamFormats &self) { @@ -523,4 +529,48 @@ PYBIND11_MODULE(_libcamera, m) .def("compose", [](Transform &self, Transform &other) { self = self * other; }); + + pyColorSpace + .def(py::init([](ColorSpace::Primaries primaries, + ColorSpace::TransferFunction transferFunction, + ColorSpace::YcbcrEncoding ycbcrEncoding, + ColorSpace::Range range) { + return ColorSpace(primaries, transferFunction, ycbcrEncoding, range); + }), py::arg("primaries"), py::arg("transferFunction"), + py::arg("ycbcrEncoding"), py::arg("range")) + .def(py::init([](ColorSpace &other) { return other; })) + .def("__repr__", [](ColorSpace &self) { + return "<libcamera.ColorSpace '" + self.toString() + "'>"; + }) + .def_readwrite("primaries", &ColorSpace::primaries) + .def_readwrite("transferFunction", &ColorSpace::transferFunction) + .def_readwrite("ycbcrEncoding", &ColorSpace::ycbcrEncoding) + .def_readwrite("range", &ColorSpace::range) + .def_static("Raw", []() { return ColorSpace::Raw; }) + .def_static("Jpeg", []() { return ColorSpace::Jpeg; }) + .def_static("Srgb", []() { return ColorSpace::Srgb; }) + .def_static("Smpte170m", []() { return ColorSpace::Smpte170m; }) + .def_static("Rec709", []() { return ColorSpace::Rec709; }) + .def_static("Rec2020", []() { return ColorSpace::Rec2020; }); + + pyColorSpacePrimaries + .value("Raw", ColorSpace::Primaries::Raw) + .value("Smpte170m", ColorSpace::Primaries::Smpte170m) + .value("Rec709", ColorSpace::Primaries::Rec709) + .value("Rec2020", ColorSpace::Primaries::Rec2020); + + pyColorSpaceTransferFunction + .value("Linear", ColorSpace::TransferFunction::Linear) + .value("Srgb", ColorSpace::TransferFunction::Srgb) + .value("Rec709", ColorSpace::TransferFunction::Rec709); + + pyColorSpaceYcbcrEncoding + .value("Null", ColorSpace::YcbcrEncoding::None) + .value("Rec601", ColorSpace::YcbcrEncoding::Rec601) + .value("Rec709", ColorSpace::YcbcrEncoding::Rec709) + .value("Rec2020", ColorSpace::YcbcrEncoding::Rec2020); + + pyColorSpaceRange + .value("Full", ColorSpace::Range::Full) + .value("Limited", ColorSpace::Range::Limited); }