From patchwork Thu Jan 30 21:38:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 2761 X-Patchwork-Delegate: kieran.bingham@ideasonboard.com Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 73D57607F3 for ; Thu, 30 Jan 2020 22:38:13 +0100 (CET) Received: from localhost.localdomain (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D2B5E504; Thu, 30 Jan 2020 22:38:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1580420293; bh=LFok/jECaW2TFXlQoOEFZIs+yQnexYMVqh5SM4UAbYg=; h=From:To:Cc:Subject:Date:From; b=Z2ZxlnYa1iFNO8BZATEoO70bizdt/P2g19AX0xjBf8vitRgzyyFkZC07JgyQ8HK07 1iQ+7SEhOcippvjXa2/sZOx4veg+hTJXJ2OpC/0w7eBnJXzHlJMRPPUKnuTE1+Y2zB iUkUntnzxh5BC8RzMDmZGBXp4EFQXKKwzMSNWQZM= From: Kieran Bingham To: LibCamera Devel Date: Thu, 30 Jan 2020 21:38:09 +0000 Message-Id: <20200130213809.16564-1-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] libcamera: PixelFormat: Define a FourCC output helper X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Jan 2020 21:38:13 -0000 Provide a helper to print the FourCC string representation, and utilise it to improve the readability of the StreamConfiguration. Signed-off-by: Kieran Bingham --- This changes the output of the line: [159:34:26.262068766] [16497] INFO Camera camera.cpp:784 configuring streams: (0) 1920x1080-0x47504a4d to read: [159:34:26.262068766] [16497] INFO Camera camera.cpp:784 configuring streams: (0) 1920x1080-0x47504a4d MJPG include/libcamera/pixelformats.h | 3 +++ src/libcamera/pixelformats.cpp | 20 ++++++++++++++++++++ src/libcamera/stream.cpp | 3 ++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/include/libcamera/pixelformats.h b/include/libcamera/pixelformats.h index 6e25b8d8b76e..32cff083cdf9 100644 --- a/include/libcamera/pixelformats.h +++ b/include/libcamera/pixelformats.h @@ -8,11 +8,14 @@ #define __LIBCAMERA_PIXEL_FORMATS_H__ #include +#include namespace libcamera { using PixelFormat = uint32_t; +std::string FourCC(const PixelFormat &p); + } /* namespace libcamera */ #endif /* __LIBCAMERA_PIXEL_FORMATS_H__ */ diff --git a/src/libcamera/pixelformats.cpp b/src/libcamera/pixelformats.cpp index c03335400b70..d6b2c6a3dba5 100644 --- a/src/libcamera/pixelformats.cpp +++ b/src/libcamera/pixelformats.cpp @@ -7,6 +7,8 @@ #include +#include + /** * \file pixelformats.h * \brief libcamera pixel formats @@ -25,4 +27,22 @@ namespace libcamera { * \todo Add support for format modifiers */ +/** + * \brief Return a PixelFormat as a FourCC string representation + */ +std::string FourCC(const PixelFormat &p) +{ + std::stringstream ss; + + ss << static_cast(p & 0x7f) + << static_cast((p >> 8) & 0x7f) + << static_cast((p >> 16) & 0x7f) + << static_cast((p >> 24) & 0x7f); + + if (p & (1 << 31)) + ss << "-BE"; + + return ss.str(); +} + } /* namespace libcamera */ diff --git a/src/libcamera/stream.cpp b/src/libcamera/stream.cpp index 13789e9eb344..4efe4385326f 100644 --- a/src/libcamera/stream.cpp +++ b/src/libcamera/stream.cpp @@ -348,7 +348,8 @@ StreamConfiguration::StreamConfiguration(const StreamFormats &formats) std::string StreamConfiguration::toString() const { std::stringstream ss; - ss << size.toString() << "-" << utils::hex(pixelFormat); + ss << size.toString() << "-" << utils::hex(pixelFormat) + << " " << FourCC(pixelFormat); return ss.str(); }