diff options
-rw-r--r-- | include/libcamera/internal/v4l2_pixelformat.h | 2 | ||||
-rw-r--r-- | src/libcamera/formats.cpp | 10 | ||||
-rw-r--r-- | src/libcamera/v4l2_pixelformat.cpp | 16 |
3 files changed, 22 insertions, 6 deletions
diff --git a/include/libcamera/internal/v4l2_pixelformat.h b/include/libcamera/internal/v4l2_pixelformat.h index 34d283db..44439fff 100644 --- a/include/libcamera/internal/v4l2_pixelformat.h +++ b/include/libcamera/internal/v4l2_pixelformat.h @@ -45,7 +45,7 @@ public: std::string toString() const; const char *description() const; - PixelFormat toPixelFormat() const; + PixelFormat toPixelFormat(bool warn = true) const; static const std::vector<V4L2PixelFormat> & fromPixelFormat(const PixelFormat &pixelFormat); diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp index 0bd0e09a..f5769c48 100644 --- a/src/libcamera/formats.cpp +++ b/src/libcamera/formats.cpp @@ -852,7 +852,15 @@ const PixelFormatInfo &PixelFormatInfo::info(const PixelFormat &format) */ const PixelFormatInfo &PixelFormatInfo::info(const V4L2PixelFormat &format) { - return info(format.toPixelFormat()); + PixelFormat pixelFormat = format.toPixelFormat(false); + if (!pixelFormat.isValid()) + return pixelFormatInfoInvalid; + + const auto iter = pixelFormatInfo.find(pixelFormat); + if (iter == pixelFormatInfo.end()) + return pixelFormatInfoInvalid; + + return iter->second; } /** diff --git a/src/libcamera/v4l2_pixelformat.cpp b/src/libcamera/v4l2_pixelformat.cpp index 3590fb73..d87665a4 100644 --- a/src/libcamera/v4l2_pixelformat.cpp +++ b/src/libcamera/v4l2_pixelformat.cpp @@ -294,15 +294,23 @@ const char *V4L2PixelFormat::description() const /** * \brief Convert the V4L2 pixel format to the corresponding PixelFormat + * \param[in] warn When true, log a warning message if the V4L2 pixel format + * isn't known + * + * Users of this function might try to convert a V4L2PixelFormat to a + * PixelFormat just to check if the format is supported or not. In that case, + * they can suppress the warning message by setting the \a warn argument to + * false to not pollute the log with unnecessary messages. + * * \return The PixelFormat corresponding to the V4L2 pixel format */ -PixelFormat V4L2PixelFormat::toPixelFormat() const +PixelFormat V4L2PixelFormat::toPixelFormat(bool warn) const { const auto iter = vpf2pf.find(*this); if (iter == vpf2pf.end()) { - LOG(V4L2, Warning) - << "Unsupported V4L2 pixel format " - << toString(); + if (warn) + LOG(V4L2, Warning) << "Unsupported V4L2 pixel format " + << toString(); return PixelFormat(); } |