[libcamera-devel] [PATCH 0/2] Improve BayerFormat class

Laurent Pinchart laurent.pinchart at ideasonboard.com
Fri Dec 25 23:06:05 CET 2020


Hi Sebastian,

On Wed, Dec 23, 2020 at 01:10:53PM +0100, Sebastian Fricke wrote:
> This patch series adds unit-tests and the `fromV4L2PixelFormat` method
> to the BayerFormat class.
> 
> I also wanted to discuss one alternative that I played around with.
> We could maybe drop one of the two mapping tables and use the following
> logic to get the map key from a mapped value.
> 
> ```
> #include <algorithm>
> ...
> BayerFormat BayerFormat::fromV4L2PixelFormat(V4L2PixelFormat v4l2Format) const
> {
>     auto it = std::find_if(
>         bayerToV4l2.begin(),
>         bayerToV4l2.end(),
>         [v4l2Format](const auto& i) { return i->second == v4l2Format; }
>     );
>     if (it != bayerToV4l2.end())
>         return it->first;
> 
>     return BayerFormat();
> }
> ```

This would certainly work. The question is whether we can to optimize
the memory consumption (dropping the second lookup table), or the
execution time (a lookup operation for a map has a O(log(n)) complexity,
compared to O(n) for the code above).

> Sebastian Fricke (2):
>   libcamera: Add the fromV4L2PixelFormat method
>   test: Add unit tests for the BayerFormat class
> 
>  include/libcamera/internal/bayer_format.h |   1 +
>  src/libcamera/bayer_format.cpp            |  14 ++
>  test/bayer_format.cpp                     | 154 ++++++++++++++++++++++
>  test/meson.build                          |   1 +
>  4 files changed, 170 insertions(+)
>  create mode 100644 test/bayer_format.cpp
> 

-- 
Regards,

Laurent Pinchart


More information about the libcamera-devel mailing list