[PATCH] libcamera: formats: Silence warning when creating a PixelFormatInfo from a null format

Stefan Klug stefan.klug at ideasonboard.com
Wed Feb 12 12:29:42 CET 2025


Calling PixelFormat().toString() correctly returns "0x0-<INVALID>" but it
also produces the following, possibly confusing, warning:

WARN Formats formats.cpp:1006 Unsupported pixel format 0x00000000

Silence the warning in PixelFormatInfo::info() in case the format is
invalid.

While at it, remove code duplication by using
PixelFormatInfo::info(const PixelFormat &format) to implement
PixelFormatInfo::info(const V4L2PixelFormat &format).

Signed-off-by: Stefan Klug <stefan.klug at ideasonboard.com>
---

Hi all,

The attached patch has one noteworthy side effect: If
info(V4L2PixelFormat &format) is called with a valid but unsupported (by
libcamera) format, we now get the same warning as in the
info(PixelFormat &format) case. I believe that is sensible but maybe the
warning was left off in the V4L2 case on purpose.

Best regards,
Stefan

 src/libcamera/formats.cpp | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp
index bfcdfc08960d..df7413f58ba8 100644
--- a/src/libcamera/formats.cpp
+++ b/src/libcamera/formats.cpp
@@ -1001,6 +1001,9 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
  */
 const PixelFormatInfo &PixelFormatInfo::info(const PixelFormat &format)
 {
+	if (!format.isValid())
+		return pixelFormatInfoInvalid;
+
 	const auto iter = pixelFormatInfo.find(format);
 	if (iter == pixelFormatInfo.end()) {
 		LOG(Formats, Warning)
@@ -1021,14 +1024,7 @@ const PixelFormatInfo &PixelFormatInfo::info(const PixelFormat &format)
 const PixelFormatInfo &PixelFormatInfo::info(const V4L2PixelFormat &format)
 {
 	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;
+	return info(pixelFormat);
 }
 
 /**
-- 
2.43.0



More information about the libcamera-devel mailing list