From d2f9c1f0c344f884a8a4296ee77fc0c47655df7a Mon Sep 17 00:00:00 2001 From: David Plowman Date: Tue, 22 Nov 2022 11:30:48 +0000 Subject: libcamera: bayer_format: Add toMbusCode method This makes it easier to perform transformations on Bayer type mbus codes by converting them to a BayerFormat, doing the transform, and then converting them back again. Signed-off-by: David Plowman Reviewed-by: Jacopo Mondi --- src/libcamera/bayer_format.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src') diff --git a/src/libcamera/bayer_format.cpp b/src/libcamera/bayer_format.cpp index f27cc166..fdbc4af1 100644 --- a/src/libcamera/bayer_format.cpp +++ b/src/libcamera/bayer_format.cpp @@ -226,6 +226,17 @@ const BayerFormat &BayerFormat::fromMbusCode(unsigned int mbusCode) return it->second; } +/** + * \brief Retrieve the media bus code corresponding this this BayerFormat + * \return The corresponding media bus code, or zero if none was found + */ +unsigned int BayerFormat::toMbusCode() const +{ + auto it = std::find_if(mbusCodeToBayer.begin(), mbusCodeToBayer.end(), + [this](const auto &i) { return i.second == *this; }); + return it != mbusCodeToBayer.end() ? it->first : 0; +} + /** * \fn BayerFormat::isValid() * \brief Return whether a BayerFormat is valid -- cgit v1.2.1