@@ -47,6 +47,7 @@ public:
}
static const BayerFormat &fromMbusCode(unsigned int mbusCode);
+ unsigned int toMbusCode(bool &valid) const;
bool isValid() const { return bitDepth != 0; }
std::string toString() const;
@@ -226,6 +226,18 @@ const BayerFormat &BayerFormat::fromMbusCode(unsigned int mbusCode)
return it->second;
}
+/**
+ * \brief Retrieve the media bus code corresponding this this BayerFormat
+ * \param[out] valid Set to true if a matching media bus code was found, else false
+ */
+unsigned int BayerFormat::toMbusCode(bool &valid) const
+{
+ auto it = std::find_if(mbusCodeToBayer.begin(), mbusCodeToBayer.end(),
+ [this](const auto &i) { return i.second == *this; });
+ valid = it != mbusCodeToBayer.end();
+ return valid ? it->first : 0;
+}
+
/**
* \fn BayerFormat::isValid()
* \brief Return whether a BayerFormat is valid
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 <david.plowman@raspberrypi.com> --- include/libcamera/internal/bayer_format.h | 1 + src/libcamera/bayer_format.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+)