From 83e434b2dccbcc3c9653767dce000052e1e52297 Mon Sep 17 00:00:00 2001 From: Sebastian Fricke Date: Tue, 26 Jan 2021 19:48:50 +0100 Subject: libcamera: bayer_format: Add the fromV4L2PixelFormat function Add a static member function to get the corresponding BayerFormat from a given V4L2PixelFormat. The motivation behind this patch is to align the overall structure of the BayerFormat class with other parts of the code base, such as the V4L2PixelFormat class. The downside of this change is a slightly worse time complexity, but the upside is a smaller codebase and lower memory consumption. As the function is probably not used very frequently, I tend to favor the mentioned upsides. Reviewed-by: Laurent Pinchart Signed-off-by: Sebastian Fricke Signed-off-by: Laurent Pinchart --- src/libcamera/bayer_format.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/libcamera/bayer_format.cpp') diff --git a/src/libcamera/bayer_format.cpp b/src/libcamera/bayer_format.cpp index a6a40be0..9eb83898 100644 --- a/src/libcamera/bayer_format.cpp +++ b/src/libcamera/bayer_format.cpp @@ -7,6 +7,7 @@ #include "libcamera/internal/bayer_format.h" +#include #include #include @@ -272,6 +273,23 @@ V4L2PixelFormat BayerFormat::toV4L2PixelFormat() const return V4L2PixelFormat(); } +/** + * \brief Convert \a v4l2Format to the corresponding BayerFormat + * \param[in] v4l2Format The raw format to convert into a BayerFormat + * \return The BayerFormat corresponding to \a v4l2Format + */ +BayerFormat BayerFormat::fromV4L2PixelFormat(V4L2PixelFormat v4l2Format) +{ + 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(); +} + /** * \brief Apply a transform to this BayerFormat * \param[in] t The transform to apply -- cgit v1.2.1