[libcamera-devel] [PATCH v3 17/18] py: generate pixel formats list

Laurent Pinchart laurent.pinchart at ideasonboard.com
Wed May 18 17:53:13 CEST 2022


Hi Tomi,

On Wed, May 18, 2022 at 06:00:01PM +0300, Tomi Valkeinen wrote:
> On 18/05/2022 16:54, Laurent Pinchart wrote:
> > On Wed, May 18, 2022 at 04:13:28PM +0300, Tomi Valkeinen wrote:
> >> Generate a list of pixel formats under "libcamera.formats".
> >>
> >> I'm not super happy about this solution, as the user can change the
> >> formats (libcamera.formats.XRGB8888 = None) and, for some reason,
> > 
> > I won't make it a blocker for this patch, but is there a way this could
> > be fixed ?
> 
> Another way would be to:
> 
> class dummy_base {};
> 
> void init_py_formats_generated(py::module& m)
> {
>          py::class_<dummy_base>(m, "formats")
>                  .def_readonly_static("R8", &libcamera::formats::R8)
>                  .def_readonly_static("R10", &libcamera::formats::R10)
>                  .def_readonly_static("R12", &libcamera::formats::R12)
> 		...
> 
> So, we would create a class to hold the formats, and then we can use 
> def_readonly_static. We do need a C++ base class, thus the dummy_base...

The dummy_base class name is internal, not exposed to Python, right ?
I'm then fine with this. We should use a name that would be a bit more
explicit, such as PyFormats for instance.

> If we don't mind changing the API a bit, we could have these readonly 
> statics inside PixelFormat, so:
> 
> libcamera.PixelFormat.MJPEG

If possible I'd like to keep the two APIs as close as possible.

-- 
Regards,

Laurent Pinchart


More information about the libcamera-devel mailing list