From 91bd175c8f43bf66a039f9979ed89103808aef0b Mon Sep 17 00:00:00 2001 From: Naushir Patuck Date: Mon, 1 Nov 2021 09:15:06 +0000 Subject: libcamera: bayer_format: Add PixelFormat conversion helpers to BayerFormat class Add BayerFormat::toPixelFormat() and BayerFormat::fromPixelFormat() helper functions to convert between BayerFormat and PixelFormat types. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart [Kieran: Minor checkstyle fix] Signed-off-by: Kieran Bingham --- src/libcamera/bayer_format.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/libcamera/bayer_format.cpp') diff --git a/src/libcamera/bayer_format.cpp b/src/libcamera/bayer_format.cpp index 8665a025..9aaec0bc 100644 --- a/src/libcamera/bayer_format.cpp +++ b/src/libcamera/bayer_format.cpp @@ -307,6 +307,35 @@ BayerFormat BayerFormat::fromV4L2PixelFormat(V4L2PixelFormat v4l2Format) return BayerFormat(); } +/** + * \brief Convert a BayerFormat into the corresponding PixelFormat + * \return The PixelFormat corresponding to this BayerFormat + */ +PixelFormat BayerFormat::toPixelFormat() const +{ + const auto it = bayerToFormat.find(*this); + if (it != bayerToFormat.end()) + return it->second.pixelFormat; + + return PixelFormat(); +} + +/** + * \brief Convert a PixelFormat into the corresponding BayerFormat + * \return The BayerFormat corresponding to this PixelFormat + */ +BayerFormat BayerFormat::fromPixelFormat(PixelFormat format) +{ + const auto it = std::find_if(bayerToFormat.begin(), bayerToFormat.end(), + [format](const auto &i) { + return i.second.pixelFormat == format; + }); + if (it != bayerToFormat.end()) + return it->first; + + return BayerFormat(); +} + /** * \brief Apply a transform to this BayerFormat * \param[in] t The transform to apply -- cgit v1.2.1