{"id":10684,"url":"https://patchwork.libcamera.org/api/patches/10684/?format=json","web_url":"https://patchwork.libcamera.org/patch/10684/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20201218164754.81422-4-jacopo@jmondi.org>","date":"2020-12-18T16:47:48","name":"[libcamera-devel,v2,3/9] libcamera: bayer_format: Add support for mbus codes","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"d74ba9a77deec931d1408b91a09d8b90aa9e0a93","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":{"id":15,"url":"https://patchwork.libcamera.org/api/users/15/?format=json","username":"jmondi","first_name":"Jacopo","last_name":"Mondi","email":"jacopo@jmondi.org"},"mbox":"https://patchwork.libcamera.org/patch/10684/mbox/","series":[{"id":1538,"url":"https://patchwork.libcamera.org/api/series/1538/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1538","date":"2020-12-18T16:47:45","name":"libcamera: Introduce sensor database","version":2,"mbox":"https://patchwork.libcamera.org/series/1538/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/10684/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/10684/checks/","tags":{},"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 87690C0F1A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 18 Dec 2020 16:47:54 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2B78B61599;\n\tFri, 18 Dec 2020 17:47:54 +0100 (CET)","from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net\n\t[217.70.183.200])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A2DAF61598\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 18 Dec 2020 17:47:50 +0100 (CET)","from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay7-d.mail.gandi.net (Postfix) with ESMTPSA id 63AF220009\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 18 Dec 2020 16:47:50 +0000 (UTC)"],"X-Originating-IP":"93.34.118.233","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Fri, 18 Dec 2020 17:47:48 +0100","Message-Id":"<20201218164754.81422-4-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.29.2","In-Reply-To":"<20201218164754.81422-1-jacopo@jmondi.org>","References":"<20201218164754.81422-1-jacopo@jmondi.org>","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH v2 3/9] libcamera: bayer_format: Add\n\tsupport for mbus codes","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>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"The existing implementation of the BayerFormat class supports\nconverting a V4L2PixelFormat to a BayerFormat and vice-versa.\n\nExpand the class by adding support for converting a media bus code\nto a BayerFormat instance, by providing a conversion table and a\ndedicated constructor.\n\nExpand the number of supported compression and expand the documentation.\n\nDo not provide support for converting a BayerFormat to a media bus code\nas the feature is currently not required.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n include/libcamera/internal/bayer_format.h |  3 ++\n src/libcamera/bayer_format.cpp            | 66 ++++++++++++++++++++++-\n 2 files changed, 68 insertions(+), 1 deletion(-)","diff":"diff --git a/include/libcamera/internal/bayer_format.h b/include/libcamera/internal/bayer_format.h\nindex 4280b76b016f..7d7539e275ff 100644\n--- a/include/libcamera/internal/bayer_format.h\n+++ b/include/libcamera/internal/bayer_format.h\n@@ -30,6 +30,8 @@ public:\n \t\tNone = 0,\n \t\tCSI2Packed = 1,\n \t\tIPU3Packed = 2,\n+\t\tALAW8Compression = 3,\n+\t\tDPCM8Compression = 4,\n \t};\n \n \tconstexpr BayerFormat()\n@@ -43,6 +45,7 @@ public:\n \t}\n \n \texplicit BayerFormat(V4L2PixelFormat v4l2Format);\n+\texplicit BayerFormat(unsigned int mbusCode);\n \tbool isValid() const { return bitDepth != 0; }\n \n \tstd::string toString() const;\ndiff --git a/src/libcamera/bayer_format.cpp b/src/libcamera/bayer_format.cpp\nindex c42792ff1948..a4eba4592bfe 100644\n--- a/src/libcamera/bayer_format.cpp\n+++ b/src/libcamera/bayer_format.cpp\n@@ -8,6 +8,9 @@\n #include \"libcamera/internal/bayer_format.h\"\n \n #include <map>\n+#include <unordered_map>\n+\n+#include <linux/media-bus-format.h>\n \n #include <libcamera/transform.h>\n \n@@ -45,7 +48,8 @@ namespace libcamera {\n \n /**\n  * \\enum BayerFormat::Packing\n- * \\brief Different types of packing that can be applied to a BayerFormat\n+ * \\brief Different types of packing or compressions that can be applied to a\n+ * BayerFormat\n  *\n  * \\var BayerFormat::None\n  * \\brief No packing\n@@ -53,6 +57,10 @@ namespace libcamera {\n  * \\brief Format uses MIPI CSI-2 style packing\n  * \\var BayerFormat::IPU3Packed\n  * \\brief Format uses IPU3 style packing\n+ * \\var BayerFormat::ALAW8Compression\n+ * \\brief Format uses ALAW8 compression\n+ * \\var BayerFormat::DPCM8Compression\n+ * \\brief Format uses DPCM8 compression\n  */\n \n namespace {\n@@ -140,6 +148,41 @@ const std::map<BayerFormat, V4L2PixelFormat, BayerFormatComparator> bayerToV4l2{\n \t{ { BayerFormat::RGGB, 16, BayerFormat::None }, V4L2PixelFormat(V4L2_PIX_FMT_SRGGB16) },\n };\n \n+const std::unordered_map<unsigned int, BayerFormat> mbusCodeToBayer{\n+\t{ MEDIA_BUS_FMT_SBGGR8_1X8, { BayerFormat::BGGR, 8, BayerFormat::None } },\n+\t{ MEDIA_BUS_FMT_SGBRG8_1X8, { BayerFormat::GBRG, 8, BayerFormat::None } },\n+\t{ MEDIA_BUS_FMT_SGRBG8_1X8, { BayerFormat::GRBG, 8, BayerFormat::None } },\n+\t{ MEDIA_BUS_FMT_SRGGB8_1X8, { BayerFormat::RGGB, 8, BayerFormat::None } },\n+\t{ MEDIA_BUS_FMT_SBGGR10_ALAW8_1X8, { BayerFormat::BGGR, 8, BayerFormat::ALAW8Compression } },\n+\t{ MEDIA_BUS_FMT_SGBRG10_ALAW8_1X8, { BayerFormat::GBRG, 8, BayerFormat::ALAW8Compression } },\n+\t{ MEDIA_BUS_FMT_SGRBG10_ALAW8_1X8, { BayerFormat::GRBG, 8, BayerFormat::ALAW8Compression } },\n+\t{ MEDIA_BUS_FMT_SRGGB10_ALAW8_1X8, { BayerFormat::RGGB, 8, BayerFormat::ALAW8Compression } },\n+\t{ MEDIA_BUS_FMT_SBGGR10_DPCM8_1X8, { BayerFormat::BGGR, 8, BayerFormat::DPCM8Compression } },\n+\t{ MEDIA_BUS_FMT_SGBRG10_DPCM8_1X8, { BayerFormat::GBRG, 8, BayerFormat::DPCM8Compression } },\n+\t{ MEDIA_BUS_FMT_SGRBG10_DPCM8_1X8, { BayerFormat::GRBG, 8, BayerFormat::DPCM8Compression } },\n+\t{ MEDIA_BUS_FMT_SRGGB10_DPCM8_1X8, { BayerFormat::RGGB, 8, BayerFormat::DPCM8Compression } },\n+\t{ MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_BE, { BayerFormat::BGGR, 10, BayerFormat::None } },\n+\t{ MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_LE, { BayerFormat::BGGR, 10, BayerFormat::None } },\n+\t{ MEDIA_BUS_FMT_SBGGR10_2X8_PADLO_BE, { BayerFormat::BGGR, 10, BayerFormat::None } },\n+\t{ MEDIA_BUS_FMT_SBGGR10_2X8_PADLO_LE, { BayerFormat::BGGR, 10, BayerFormat::None } },\n+\t{ MEDIA_BUS_FMT_SBGGR10_1X10, { BayerFormat::BGGR, 10, BayerFormat::None } },\n+\t{ MEDIA_BUS_FMT_SGBRG10_1X10, { BayerFormat::GBRG, 10, BayerFormat::None } },\n+\t{ MEDIA_BUS_FMT_SGRBG10_1X10, { BayerFormat::GRBG, 10, BayerFormat::None } },\n+\t{ MEDIA_BUS_FMT_SRGGB10_1X10, { BayerFormat::RGGB, 10, BayerFormat::None } },\n+\t{ MEDIA_BUS_FMT_SBGGR12_1X12, { BayerFormat::BGGR, 12, BayerFormat::None } },\n+\t{ MEDIA_BUS_FMT_SGBRG12_1X12, { BayerFormat::GBRG, 12, BayerFormat::None } },\n+\t{ MEDIA_BUS_FMT_SGRBG12_1X12, { BayerFormat::GRBG, 12, BayerFormat::None } },\n+\t{ MEDIA_BUS_FMT_SRGGB12_1X12, { BayerFormat::RGGB, 12, BayerFormat::None } },\n+\t{ MEDIA_BUS_FMT_SBGGR14_1X14, { BayerFormat::BGGR, 14, BayerFormat::None } },\n+\t{ MEDIA_BUS_FMT_SGBRG14_1X14, { BayerFormat::GBRG, 14, BayerFormat::None } },\n+\t{ MEDIA_BUS_FMT_SGRBG14_1X14, { BayerFormat::GRBG, 14, BayerFormat::None } },\n+\t{ MEDIA_BUS_FMT_SRGGB14_1X14, { BayerFormat::RGGB, 14, BayerFormat::None } },\n+\t{ MEDIA_BUS_FMT_SBGGR16_1X16, { BayerFormat::BGGR, 16, BayerFormat::None } },\n+\t{ MEDIA_BUS_FMT_SGBRG16_1X16, { BayerFormat::GBRG, 16, BayerFormat::None } },\n+\t{ MEDIA_BUS_FMT_SGRBG16_1X16, { BayerFormat::GRBG, 16, BayerFormat::None } },\n+\t{ MEDIA_BUS_FMT_SRGGB16_1X16, { BayerFormat::RGGB, 16, BayerFormat::None } },\n+};\n+\n } /* namespace */\n \n /**\n@@ -169,6 +212,22 @@ BayerFormat::BayerFormat(V4L2PixelFormat v4l2Format)\n \t\t*this = it->second;\n }\n \n+/**\n+ * \\brief Construct a BayerFormat from a media bus code\n+ * \\param[in] mbusCode The media bus code to convert into a BayerFormat\n+ *\n+ * The media bus code numeric identifiers are defined by the V4L2 specification.\n+ */\n+BayerFormat::BayerFormat(unsigned int mbusCode)\n+\t: order(BGGR), packing(None)\n+{\n+\tconst auto it = mbusCodeToBayer.find(mbusCode);\n+\tif (it == mbusCodeToBayer.end())\n+\t\tbitDepth = 0;\n+\telse\n+\t\t*this = it->second;\n+}\n+\n /**\n  * \\fn BayerFormat::isValid()\n  * \\brief Return whether a BayerFormat is valid\n@@ -258,6 +317,11 @@ BayerFormat BayerFormat::transform(Transform t) const\n /**\n  * \\var BayerFormat::bitDepth\n  * \\brief The bit depth of the samples in the Bayer pattern\n+ *\n+ * For formats using compression schemes such as Packing::ALAW8Compression or\n+ * Packing::DPCM8Compression, the bitDepth value refers to the size of the\n+ * sample when transmitted on the wire or stored into memory. The resulting\n+ * images need to be de-compressed to be viewed properly.\n  */\n \n /**\n","prefixes":["libcamera-devel","v2","3/9"]}