[libcamera-devel] [PATCH] libcamera: v4l2PixelFormat: replace hex with 4CC

Kaaira Gupta kgupta at es.iitr.ac.in
Wed Mar 25 13:28:25 CET 2020


Print 4CC characters instead of the hex value in toString() as they are
more informative.

Signed-off-by: Kaaira Gupta <kgupta at es.iitr.ac.in>
---
 src/libcamera/v4l2_videodevice.cpp | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
index b778181..ea8ee50 100644
--- a/src/libcamera/v4l2_videodevice.cpp
+++ b/src/libcamera/v4l2_videodevice.cpp
@@ -336,9 +336,15 @@ bool V4L2BufferCache::Entry::operator==(const FrameBuffer &buffer) const
  */
 std::string V4L2PixelFormat::toString() const
 {
-	char str[11];
-	snprintf(str, 11, "0x%08x", fourcc_);
-	return str;
+	std::stringstream ss;
+	ss << static_cast<char>(fourcc_ & 0x7f)
+	   << static_cast<char>((fourcc_ >> 8) & 0x7f)
+	   << static_cast<char>((fourcc_ >> 16) & 0x7f)
+	   << static_cast<char>((fourcc_ >> 24) & 0x7f);
+
+	if (fourcc_ & (1 << 31))
+		ss << "-BE";
+	return ss.str();
 }
 
 /**
-- 
2.17.1



More information about the libcamera-devel mailing list