diff options
-rw-r--r-- | include/libcamera/internal/bayer_format.h | 4 | ||||
-rw-r--r-- | src/libcamera/bayer_format.cpp | 29 |
2 files changed, 33 insertions, 0 deletions
diff --git a/include/libcamera/internal/bayer_format.h b/include/libcamera/internal/bayer_format.h index d9a56d74..79a25b52 100644 --- a/include/libcamera/internal/bayer_format.h +++ b/include/libcamera/internal/bayer_format.h @@ -10,6 +10,8 @@ #include <stdint.h> #include <string> +#include <libcamera/pixel_format.h> + #include "libcamera/internal/v4l2_pixelformat.h" namespace libcamera { @@ -50,6 +52,8 @@ public: V4L2PixelFormat toV4L2PixelFormat() const; static BayerFormat fromV4L2PixelFormat(V4L2PixelFormat v4l2Format); + PixelFormat toPixelFormat() const; + static BayerFormat fromPixelFormat(PixelFormat format); BayerFormat transform(Transform t) const; Order order; 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 @@ -308,6 +308,35 @@ BayerFormat BayerFormat::fromV4L2PixelFormat(V4L2PixelFormat v4l2Format) } /** + * \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 * |