[libcamera-devel] [PATCH] py: Improve print methods for Transform and ColorSpace objects

Laurent Pinchart laurent.pinchart at ideasonboard.com
Wed May 18 12:02:06 CEST 2022


Hi David,

Thank you for the patch.

On Wed, May 18, 2022 at 10:08:01AM +0100, David Plowman via libcamera-devel wrote:
> They should now print out their meaningful string representations
> instead of "object at <address>".
> 
> Signed-off-by: David Plowman <david.plowman at raspberrypi.com>
> ---
>  src/py/libcamera/pymain.cpp | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/src/py/libcamera/pymain.cpp b/src/py/libcamera/pymain.cpp
> index fb89975c..2ba5fcbb 100644
> --- a/src/py/libcamera/pymain.cpp
> +++ b/src/py/libcamera/pymain.cpp
> @@ -567,6 +567,9 @@ PYBIND11_MODULE(_libcamera, m)
>  		.def("__str__", [](Transform &self) {
>  			return "<libcamera.Transform '" + std::string(transformToString(self)) + "'>";
>  		})
> +		.def("__repr__", [](Transform &self) {
> +			return "<libcamera.Transform '" + std::string(transformToString(self)) + "'>";
> +		})

Can we do the same as "[PATCH v2 12/13] py: add geometry classes" and
return a string that would construct an identical Transform object when
run as Python code ? Same below.

>  		.def_property("hflip",
>  			      [](Transform &self) {
>  				      return !!(self & Transform::HFlip);
> @@ -617,6 +620,9 @@ PYBIND11_MODULE(_libcamera, m)
>  		.def("__str__", [](ColorSpace &self) {
>  			return "<libcamera.ColorSpace '" + self.toString() + "'>";
>  		})
> +		.def("__repr__", [](ColorSpace &self) {
> +			return "<libcamera.ColorSpace '" + self.toString() + "'>";
> +		})
>  		.def_readwrite("primaries", &ColorSpace::primaries)
>  		.def_readwrite("transferFunction", &ColorSpace::transferFunction)
>  		.def_readwrite("ycbcrEncoding", &ColorSpace::ycbcrEncoding)

-- 
Regards,

Laurent Pinchart


More information about the libcamera-devel mailing list