{"id":3526,"url":"https://patchwork.libcamera.org/api/1.1/patches/3526/?format=json","web_url":"https://patchwork.libcamera.org/patch/3526/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20200424215304.558317-9-jacopo@jmondi.org>","date":"2020-04-24T21:52:59","name":"[libcamera-devel,v3,08/13] libcamera: v4l2_subdevice: Add format information","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"12e7b4b5b002a97ee63c32553afb198cf9f169bd","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/1.1/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/3526/mbox/","series":[{"id":822,"url":"https://patchwork.libcamera.org/api/1.1/series/822/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=822","date":"2020-04-24T21:52:51","name":"libcamera: Add CameraSensorInfo","version":3,"mbox":"https://patchwork.libcamera.org/series/822/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/3526/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/3526/checks/","tags":{},"headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net\n\t[217.70.183.195])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1EACC62E67\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 24 Apr 2020 23:50:12 +0200 (CEST)","from uno.homenet.telecomitalia.it\n\t(host240-55-dynamic.3-87-r.retail.telecomitalia.it [87.3.55.240])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 5D7D160002;\n\tFri, 24 Apr 2020 21:50:11 +0000 (UTC)"],"X-Originating-IP":"87.3.55.240","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Fri, 24 Apr 2020 23:52:59 +0200","Message-Id":"<20200424215304.558317-9-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.26.1","In-Reply-To":"<20200424215304.558317-1-jacopo@jmondi.org>","References":"<20200424215304.558317-1-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v3 08/13] libcamera: v4l2_subdevice: Add\n\tformat information","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>","X-List-Received-Date":"Fri, 24 Apr 2020 21:50:12 -0000"},"content":"Define a map of static information associated with a media bus code.\nStart by reporting the bits-per-pixel for each media bus code defined by\nthe V4L2 kernel API, to later expand it when necessary.\n\nAdd to the V4L2SubdeviceFormat class a method to return the bits per\npixel, retrieved by inspecting the static map of format information.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/libcamera/include/v4l2_subdevice.h |   3 +\n src/libcamera/v4l2_subdevice.cpp       | 113 +++++++++++++++++++++++++\n 2 files changed, 116 insertions(+)","diff":"diff --git a/src/libcamera/include/v4l2_subdevice.h b/src/libcamera/include/v4l2_subdevice.h\nindex 763ffadb61fb..43953a0a5a6c 100644\n--- a/src/libcamera/include/v4l2_subdevice.h\n+++ b/src/libcamera/include/v4l2_subdevice.h\n@@ -23,10 +23,13 @@ namespace libcamera {\n class MediaDevice;\n \n struct V4L2SubdeviceFormat {\n+\tusing infoMap = std::map<uint32_t, uint8_t>;\n+\n \tuint32_t mbus_code;\n \tSize size;\n \n \tconst std::string toString() const;\n+\tuint8_t bitsPerPixel() const;\n };\n \n class V4L2Subdevice : public V4L2Device\ndiff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp\nindex 4dcf8ce48754..6f72c363fc7f 100644\n--- a/src/libcamera/v4l2_subdevice.cpp\n+++ b/src/libcamera/v4l2_subdevice.cpp\n@@ -14,6 +14,7 @@\n #include <sys/ioctl.h>\n #include <unistd.h>\n \n+#include <linux/media-bus-format.h>\n #include <linux/v4l2-subdev.h>\n \n #include <libcamera/geometry.h>\n@@ -32,6 +33,92 @@ namespace libcamera {\n \n LOG_DECLARE_CATEGORY(V4L2)\n \n+namespace {\n+\n+/*\n+ * \\var formatInfoMap\n+ * \\brief A map that associates information to V4L2 media bus codes\n+ */\n+const V4L2SubdeviceFormat::infoMap formatInfoMap = {\n+\t{ V4L2_MBUS_FMT_RGB444_2X8_PADHI_BE, 16 },\n+\t{ V4L2_MBUS_FMT_RGB444_2X8_PADHI_LE, 16 },\n+\t{ V4L2_MBUS_FMT_RGB555_2X8_PADHI_BE, 16 },\n+\t{ V4L2_MBUS_FMT_RGB555_2X8_PADHI_LE, 16 },\n+\t{ V4L2_MBUS_FMT_BGR565_2X8_BE, 16 },\n+\t{ V4L2_MBUS_FMT_BGR565_2X8_LE, 16 },\n+\t{ V4L2_MBUS_FMT_RGB565_2X8_BE, 16 },\n+\t{ V4L2_MBUS_FMT_RGB565_2X8_LE, 16 },\n+\t{ V4L2_MBUS_FMT_RGB666_1X18, 18 },\n+\t{ V4L2_MBUS_FMT_RGB888_1X24, 24 },\n+\t{ V4L2_MBUS_FMT_RGB888_2X12_BE, 24 },\n+\t{ V4L2_MBUS_FMT_RGB888_2X12_LE, 24 },\n+\t{ V4L2_MBUS_FMT_ARGB8888_1X32, 32 },\n+\t{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_1X12, 24 },\n+\t{ V4L2_MBUS_FMT_SGBRG12_1X12, 24 },\n+\t{ V4L2_MBUS_FMT_SGRBG12_1X12, 24 },\n+\t{ V4L2_MBUS_FMT_SRGGB12_1X12, 24 },\n+\t{ V4L2_MBUS_FMT_JPEG_1X8, 8 },\n+\t{ V4L2_MBUS_FMT_S5C_UYVY_JPEG_1X8, 8 },\n+\t{ V4L2_MBUS_FMT_AHSV8888_1X32, 32 },\n+};\n+\n+}; /* namespace */\n+\n /**\n  * \\struct V4L2SubdeviceFormat\n  * \\brief The V4L2 sub-device image format and sizes\n@@ -60,6 +147,14 @@ LOG_DECLARE_CATEGORY(V4L2)\n  * Section 4.15.3.1 of the above mentioned Linux kernel documentation section.\n  */\n \n+/**\n+ * \\typedef V4L2SubdeviceFormat::infoMap\n+ * \\brief Map of static information associated with a V4L2 subdevice format\n+ *\n+ * \\todo Expand with additional information. At the moment only the\n+ * bits-per-pixel information is reported.\n+ */\n+\n /**\n  * \\var V4L2SubdeviceFormat::mbus_code\n  * \\brief The image format bus code\n@@ -81,6 +176,24 @@ const std::string V4L2SubdeviceFormat::toString() const\n \treturn ss.str();\n }\n \n+/**\n+ * \\brief Retrieve the number of bits per pixel for the V4L2 subdevice format\n+ * \\return The number of bits per pixel for the format, or default it to 8 if\n+ * the format's mbus code is not supported\n+ */\n+uint8_t V4L2SubdeviceFormat::bitsPerPixel() const\n+{\n+\tconst auto it = formatInfoMap.find(mbus_code);\n+\tif (it == formatInfoMap.end()) {\n+\t\tLOG(V4L2, Error) << \"No information available for format: '\"\n+\t\t\t\t << toString() << \"'\";\n+\t\t/* Return 8 to avoid divisions by 0. */\n+\t\treturn 8;\n+\t}\n+\n+\treturn it->second;\n+}\n+\n /**\n  * \\class V4L2Subdevice\n  * \\brief A V4L2 subdevice as exposed by the Linux kernel\n","prefixes":["libcamera-devel","v3","08/13"]}