[{"id":22835,"web_url":"https://patchwork.libcamera.org/comment/22835/","msgid":"<165165476495.4076486.5919789049061344200@Monstersaurus>","date":"2022-05-04T08:59:24","subject":"Re: [libcamera-devel] [PATCH 3/5] libcamera: bayer_format: Add\n\toperator<<()","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Laurent Pinchart via libcamera-devel (2022-04-29 22:23:46)\n> Implement the stream output operator<<() for the BayerFormat class to\n> simplify printing them.\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> ---\n>  include/libcamera/internal/bayer_format.h |  3 ++\n>  src/libcamera/bayer_format.cpp            | 57 ++++++++++++++---------\n>  2 files changed, 39 insertions(+), 21 deletions(-)\n> \n> diff --git a/include/libcamera/internal/bayer_format.h b/include/libcamera/internal/bayer_format.h\n> index cb20bf9bea84..7d3e37c67e9c 100644\n> --- a/include/libcamera/internal/bayer_format.h\n> +++ b/include/libcamera/internal/bayer_format.h\n> @@ -7,6 +7,7 @@\n>  \n>  #pragma once\n>  \n> +#include <ostream>\n>  #include <stdint.h>\n>  #include <string>\n>  \n> @@ -68,4 +69,6 @@ static inline bool operator!=(const BayerFormat &lhs, const BayerFormat &rhs)\n>         return !(lhs == rhs);\n>  }\n>  \n> +std::ostream &operator<<(std::ostream &out, const BayerFormat &f);\n> +\n>  } /* namespace libcamera */\n> diff --git a/src/libcamera/bayer_format.cpp b/src/libcamera/bayer_format.cpp\n> index 9aaec0bce264..4882707e7763 100644\n> --- a/src/libcamera/bayer_format.cpp\n> +++ b/src/libcamera/bayer_format.cpp\n> @@ -9,6 +9,7 @@\n>  \n>  #include <algorithm>\n>  #include <map>\n> +#include <sstream>\n>  #include <unordered_map>\n>  \n>  #include <linux/media-bus-format.h>\n> @@ -236,28 +237,10 @@ const BayerFormat &BayerFormat::fromMbusCode(unsigned int mbusCode)\n>   */\n>  std::string BayerFormat::toString() const\n>  {\n> -       std::string result;\n> +       std::stringstream ss;\n> +       ss << *this;\n>  \n> -       static const char *orderStrings[] = {\n> -               \"BGGR\",\n> -               \"GBRG\",\n> -               \"GRBG\",\n> -               \"RGGB\",\n> -               \"MONO\"\n> -       };\n> -       if (isValid() && order <= MONO)\n> -               result = orderStrings[order];\n> -       else\n> -               return \"INVALID\";\n> -\n> -       result += \"-\" + std::to_string(bitDepth);\n> -\n> -       if (packing == Packing::CSI2)\n> -               result += \"-CSI2P\";\n> -       else if (packing == Packing::IPU3)\n> -               result += \"-IPU3P\";\n> -\n> -       return result;\n> +       return ss.str();\n>  }\n>  \n>  /**\n> @@ -270,6 +253,38 @@ bool operator==(const BayerFormat &lhs, const BayerFormat &rhs)\n>                lhs.packing == rhs.packing;\n>  }\n>  \n> +/**\n> + * \\brief Insert a text representation of a BayerFormats into an output stream\n> + * \\param[in] out The output stream\n> + * \\param[in] f The BayerFormat\n> + * \\return The output stream \\a out\n> + */\n> +std::ostream &operator<<(std::ostream &out, const BayerFormat &f)\n> +{\n> +       static const char *orderStrings[] = {\n> +               \"BGGR-\",\n> +               \"GBRG-\",\n> +               \"GRBG-\",\n> +               \"RGGB-\",\n> +               \"MONO-\"\n> +       };\n> +\n> +       if (!f.isValid() || f.order > BayerFormat::MONO) {\n> +               out << \"INVALID\";\n> +               return out;\n> +       }\n> +\n> +       /* The cast is required to avoid bitDepth being interpreted as a char. */\n> +       out << orderStrings[f.order] << static_cast<unsigned int>(f.bitDepth);\n> +\n> +       if (f.packing == BayerFormat::Packing::CSI2)\n> +               out << \"-CSI2P\";\n> +       else if (f.packing == BayerFormat::Packing::IPU3)\n> +               out << \"-IPU3P\";\n> +\n> +       return out;\n> +}\n> +\n>  /**\n>   * \\fn bool operator!=(const BayerFormat &lhs, const BayerFormat &rhs)\n>   * \\brief Compare two BayerFormats for inequality\n> -- \n> Regards,\n> \n> Laurent Pinchart\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 5194EC3256\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  4 May 2022 08:59:29 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B65C1604A3;\n\tWed,  4 May 2022 10:59:28 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id AAA62604A3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  4 May 2022 10:59:27 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 3CADD4A8;\n\tWed,  4 May 2022 10:59:27 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1651654768;\n\tbh=dyFtnjCITwejFwnrZx4+Bg9QfKSskg6MtjZ/5s3+ZUs=;\n\th=In-Reply-To:References:To:Date:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=bEXvH60rKziWH6E7mI4xobL8dzMn2jYu1/CX1drqglU+Xif/n/kMeYYLLEvGQ8WkY\n\tr4LNFOzxJH5Ohuc29NZ0IWX37KLfPIxSeDG8sSRrmbuWdSaqhmgXwS5KfFoVaAMF32\n\tcX+5msSaGYH9xXlUJuidXDuguvaMWUpc8+UXGfeAZkYK0G5+p4uKUCmLVwuVJ8YN1v\n\tFCerGbFEvY1OZwhkU5D/wuTv8DM9jV8DGb+FSvbqAARmFEFIteioz7TdiCFGPqc1IQ\n\t0US/17S+PSHEQVgexAkyyOv8zfTrlAmNmQUPtJjqvz9TJeYJyShGAXyLtawGlWlnGn\n\tI/i1nrDqaJaeQ==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1651654767;\n\tbh=dyFtnjCITwejFwnrZx4+Bg9QfKSskg6MtjZ/5s3+ZUs=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=YxuI/pkU9HRsnsJfnfqHSZ58/cm8YQ/a5nMQE6/7Mc76MGcw6fSoeailvZl99BHfk\n\toTcBcKwTJqVlI5KLtBLXZDAua8Lk/VF/CmcI2GriwTsmkUISdfSJTgcxzM/lcG+rsv\n\taUZQWuNlbnXUu6wH2EQxP3dLUKZpbx3kCw0tqmBo="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"YxuI/pkU\"; dkim-atps=neutral","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20220429212348.18063-4-laurent.pinchart@ideasonboard.com>","References":"<20220429212348.18063-1-laurent.pinchart@ideasonboard.com>\n\t<20220429212348.18063-4-laurent.pinchart@ideasonboard.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Wed, 04 May 2022 09:59:24 +0100","Message-ID":"<165165476495.4076486.5919789049061344200@Monstersaurus>","User-Agent":"alot/0.10","Subject":"Re: [libcamera-devel] [PATCH 3/5] libcamera: bayer_format: Add\n\toperator<<()","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"Kieran Bingham via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]