[libcamera-devel] [PATCH 0/2] Improve BayerFormat class
Sebastian Fricke
sebastian.fricke.linux at gmail.com
Mon Dec 28 08:05:28 CET 2020
On 26.12.2020 00:06, Laurent Pinchart wrote:
>Hi Sebastian,
Hey Laurent,
>
>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).
Which probably boils down to the question: 'How often do we expect to
use this function?'.
Can you recall from the current code bases if there are cases, where the
constructor is used frequently in a row? I would suspect that the
constructor/static function should be used quite seldomly.
>
>> 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