Patch Detail
Show a patch.
GET /api/patches/3630/?format=api
{ "id": 3630, "url": "https://patchwork.libcamera.org/api/patches/3630/?format=api", "web_url": "https://patchwork.libcamera.org/patch/3630/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20200430030723.8908-5-laurent.pinchart@ideasonboard.com>", "date": "2020-04-30T03:07:21", "name": "[libcamera-devel,v2,4/6] libcamera: formats: Expose PixelFormatInfo as an internal API", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "3082c697e7598c7bf91eb56471a9a4609dde5d6b", "submitter": { "id": 2, "url": "https://patchwork.libcamera.org/api/people/2/?format=api", "name": "Laurent Pinchart", "email": "laurent.pinchart@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/3630/mbox/", "series": [ { "id": 858, "url": "https://patchwork.libcamera.org/api/series/858/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=858", "date": "2020-04-30T03:07:17", "name": "libcamera: Improve conversion between DRM and V4L2 formats", "version": 2, "mbox": "https://patchwork.libcamera.org/series/858/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/3630/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/3630/checks/", "tags": {}, "headers": { "Return-Path": "<laurent.pinchart@ideasonboard.com>", "Received": [ "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id BE8AC613F6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 30 Apr 2020 05:07:29 +0200 (CEST)", "from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 1DBEC503\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 30 Apr 2020 05:07:29 +0200 (CEST)" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"RAdiqFJe\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1588216049;\n\tbh=IjCYSCJYvuIdU9TTcvdZO2iIDTHGLKZPr7jhP41Xhzs=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=RAdiqFJeXhtd5jqNrpODWoiErwi/1rTFOd28amnJqKLJ2TkcdvkhV5Br42KvU6VV7\n\tfx8Bh7KWw9/kBmmY2/SNWGbazTwazdC565a6smt4WtZksCZMj0qIzfr2T/u7pdxIv/\n\tq3akpUNyuFMc7Gox5UoNp5jfvkGf3mTOP6vB2K+I=", "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Thu, 30 Apr 2020 06:07:21 +0300", "Message-Id": "<20200430030723.8908-5-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.25.3", "In-Reply-To": "<20200430030723.8908-1-laurent.pinchart@ideasonboard.com>", "References": "<20200430030723.8908-1-laurent.pinchart@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v2 4/6] libcamera: formats: Expose\n\tPixelFormatInfo as an internal API", "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": "Thu, 30 Apr 2020 03:07:31 -0000" }, "content": "To prepare for storing more information about pixel formats in\nPixelFormatInfo, move the class to formats.cpp and document it. The\npixel formats database is moved to the same file, and a new static\nfunction is added to PixelFormatInfo to retrieve a PixelFormatInfo for a\nPixelFormat.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/libcamera/formats.cpp | 126 +++++++++++++++++++++++++++++\n src/libcamera/include/formats.h | 15 ++++\n src/libcamera/v4l2_pixelformat.cpp | 75 +----------------\n 3 files changed, 144 insertions(+), 72 deletions(-)", "diff": "diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp\nindex 5f6552a4e06c..4a351020b0d9 100644\n--- a/src/libcamera/formats.cpp\n+++ b/src/libcamera/formats.cpp\n@@ -9,6 +9,8 @@\n \n #include <errno.h>\n \n+#include \"log.h\"\n+\n /**\n * \\file formats.h\n * \\brief Types and helper methods to handle libcamera image formats\n@@ -16,6 +18,8 @@\n \n namespace libcamera {\n \n+LOG_DEFINE_CATEGORY(Formats)\n+\n /**\n * \\class ImageFormats\n * \\brief Describe V4L2Device and V4L2SubDevice image formats\n@@ -104,4 +108,126 @@ const std::map<unsigned int, std::vector<SizeRange>> &ImageFormats::data() const\n \treturn data_;\n }\n \n+/**\n+ * \\class PixelFormatInfo\n+ * \\brief Information about pixel formats\n+ *\n+ * The PixelFormatInfo class groups together information describing a pixel\n+ * format. It facilitates handling of pixel formats by providing data commonly\n+ * used in pipeline handlers.\n+ *\n+ * \\var PixelFormatInfo::format\n+ * \\brief The PixelFormat described by this instance\n+ *\n+ * \\var PixelFormatInfo::v4l2Format\n+ * \\brief The V4L2 pixel format corresponding to the PixelFormat\n+ */\n+\n+namespace {\n+\n+const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{\n+\t/* RGB formats. */\n+\t{ PixelFormat(DRM_FORMAT_BGR888), {\n+\t\t.format = PixelFormat(DRM_FORMAT_BGR888),\n+\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_RGB24),\n+\t} },\n+\t{ PixelFormat(DRM_FORMAT_RGB888), {\n+\t\t.format = PixelFormat(DRM_FORMAT_RGB888),\n+\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_BGR24),\n+\t} },\n+\t{ PixelFormat(DRM_FORMAT_ABGR8888), {\n+\t\t.format = PixelFormat(DRM_FORMAT_ABGR8888),\n+\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_RGBA32),\n+\t} },\n+\t{ PixelFormat(DRM_FORMAT_ARGB8888), {\n+\t\t.format = PixelFormat(DRM_FORMAT_ARGB8888),\n+\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_ABGR32),\n+\t} },\n+\t{ PixelFormat(DRM_FORMAT_BGRA8888), {\n+\t\t.format = PixelFormat(DRM_FORMAT_BGRA8888),\n+\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_ARGB32),\n+\t} },\n+\t{ PixelFormat(DRM_FORMAT_RGBA8888), {\n+\t\t.format = PixelFormat(DRM_FORMAT_RGBA8888),\n+\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_BGRA32),\n+\t} },\n+\n+\t/* YUV packed formats. */\n+\t{ PixelFormat(DRM_FORMAT_YUYV), {\n+\t\t.format = PixelFormat(DRM_FORMAT_YUYV),\n+\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_YUYV),\n+\t} },\n+\t{ PixelFormat(DRM_FORMAT_YVYU), {\n+\t\t.format = PixelFormat(DRM_FORMAT_YVYU),\n+\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_YVYU),\n+\t} },\n+\t{ PixelFormat(DRM_FORMAT_UYVY), {\n+\t\t.format = PixelFormat(DRM_FORMAT_UYVY),\n+\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_UYVY),\n+\t} },\n+\t{ PixelFormat(DRM_FORMAT_VYUY), {\n+\t\t.format = PixelFormat(DRM_FORMAT_VYUY),\n+\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_VYUY),\n+\t} },\n+\n+\t/* YUV planar formats. */\n+\t{ PixelFormat(DRM_FORMAT_NV16), {\n+\t\t.format = PixelFormat(DRM_FORMAT_NV16),\n+\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_NV16),\n+\t} },\n+\t{ PixelFormat(DRM_FORMAT_NV61), {\n+\t\t.format = PixelFormat(DRM_FORMAT_NV61),\n+\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_NV61),\n+\t} },\n+\t{ PixelFormat(DRM_FORMAT_NV12), {\n+\t\t.format = PixelFormat(DRM_FORMAT_NV12),\n+\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_NV12),\n+\t} },\n+\t{ PixelFormat(DRM_FORMAT_NV21), {\n+\t\t.format = PixelFormat(DRM_FORMAT_NV21),\n+\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_NV21),\n+\t} },\n+\n+\t/* Greyscale formats. */\n+\t{ PixelFormat(DRM_FORMAT_R8), {\n+\t\t.format = PixelFormat(DRM_FORMAT_R8),\n+\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_GREY),\n+\t} },\n+\n+\t/* Compressed formats. */\n+\t{ PixelFormat(DRM_FORMAT_MJPEG), {\n+\t\t.format = PixelFormat(DRM_FORMAT_MJPEG),\n+\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_MJPEG),\n+\t} },\n+};\n+\n+} /* namespace */\n+\n+/**\n+ * \\fn bool PixelFormatInfo::isValid() const\n+ * \\brief Check if the pixel format info is valid\n+ * \\return True if the pixel format info is valid, false otherwise\n+ */\n+\n+/**\n+ * \\brief Retrieve information about a pixel format\n+ * \\param[in] format The pixel format\n+ * \\return The PixelFormatInfo describing the \\a format if known, or an invalid\n+ * PixelFormatInfo otherwise\n+ */\n+const PixelFormatInfo &PixelFormatInfo::info(const PixelFormat &format)\n+{\n+\tstatic const PixelFormatInfo invalid{};\n+\n+\tconst auto iter = pixelFormatInfo.find(format);\n+\tif (iter == pixelFormatInfo.end()) {\n+\t\tLOG(Formats, Warning)\n+\t\t\t<< \"Unsupported pixel format \"\n+\t\t\t<< format.toString();\n+\t\treturn invalid;\n+\t}\n+\n+\treturn iter->second;\n+}\n+\n } /* namespace libcamera */\ndiff --git a/src/libcamera/include/formats.h b/src/libcamera/include/formats.h\nindex f43bc8c004f6..560df07c4451 100644\n--- a/src/libcamera/include/formats.h\n+++ b/src/libcamera/include/formats.h\n@@ -12,6 +12,9 @@\n #include <vector>\n \n #include <libcamera/geometry.h>\n+#include <libcamera/pixelformats.h>\n+\n+#include \"v4l2_pixelformat.h\"\n \n namespace libcamera {\n \n@@ -29,6 +32,18 @@ private:\n \tstd::map<unsigned int, std::vector<SizeRange>> data_;\n };\n \n+class PixelFormatInfo\n+{\n+public:\n+\tbool isValid() const { return format.isValid(); }\n+\n+\tstatic const PixelFormatInfo &info(const PixelFormat &format);\n+\n+\t/* \\todo Add support for non-contiguous memory planes */\n+\tPixelFormat format;\n+\tV4L2PixelFormat v4l2Format;\n+};\n+\n } /* namespace libcamera */\n \n #endif /* __LIBCAMERA_FORMATS_H__ */\ndiff --git a/src/libcamera/v4l2_pixelformat.cpp b/src/libcamera/v4l2_pixelformat.cpp\nindex e1c96b9862c3..580c0fc9d983 100644\n--- a/src/libcamera/v4l2_pixelformat.cpp\n+++ b/src/libcamera/v4l2_pixelformat.cpp\n@@ -16,6 +16,7 @@\n \n #include <libcamera/pixelformats.h>\n \n+#include \"formats.h\"\n #include \"log.h\"\n \n /**\n@@ -43,71 +44,6 @@ LOG_DECLARE_CATEGORY(V4L2)\n \n namespace {\n \n-struct PixelFormatInfo {\n-\t/* \\todo Add support for non-contiguous memory planes */\n-\tV4L2PixelFormat v4l2Format;\n-};\n-\n-const std::map<PixelFormat, PixelFormatInfo> pf2vpf{\n-\t/* RGB formats. */\n-\t{ PixelFormat(DRM_FORMAT_BGR888), {\n-\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_RGB24),\n-\t} },\n-\t{ PixelFormat(DRM_FORMAT_RGB888), {\n-\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_BGR24),\n-\t} },\n-\t{ PixelFormat(DRM_FORMAT_ABGR8888), {\n-\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_RGBA32),\n-\t} },\n-\t{ PixelFormat(DRM_FORMAT_ARGB8888), {\n-\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_ABGR32),\n-\t} },\n-\t{ PixelFormat(DRM_FORMAT_BGRA8888), {\n-\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_ARGB32),\n-\t} },\n-\t{ PixelFormat(DRM_FORMAT_RGBA8888), {\n-\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_BGRA32),\n-\t} },\n-\n-\t/* YUV packed formats. */\n-\t{ PixelFormat(DRM_FORMAT_YUYV), {\n-\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_YUYV),\n-\t} },\n-\t{ PixelFormat(DRM_FORMAT_YVYU), {\n-\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_YVYU),\n-\t} },\n-\t{ PixelFormat(DRM_FORMAT_UYVY), {\n-\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_UYVY),\n-\t} },\n-\t{ PixelFormat(DRM_FORMAT_VYUY), {\n-\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_VYUY),\n-\t} },\n-\n-\t/* YUV planar formats. */\n-\t{ PixelFormat(DRM_FORMAT_NV16), {\n-\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_NV16),\n-\t} },\n-\t{ PixelFormat(DRM_FORMAT_NV61), {\n-\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_NV61),\n-\t} },\n-\t{ PixelFormat(DRM_FORMAT_NV12), {\n-\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_NV12),\n-\t} },\n-\t{ PixelFormat(DRM_FORMAT_NV21), {\n-\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_NV21),\n-\t} },\n-\n-\t/* Greyscale formats. */\n-\t{ PixelFormat(DRM_FORMAT_R8), {\n-\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_GREY),\n-\t} },\n-\n-\t/* Compressed formats. */\n-\t{ PixelFormat(DRM_FORMAT_MJPEG), {\n-\t\t.v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_MJPEG),\n-\t} },\n-};\n-\n const std::map<V4L2PixelFormat, PixelFormat> vpf2pf{\n \t/* RGB formats. */\n \t{ V4L2PixelFormat(V4L2_PIX_FMT_RGB24), PixelFormat(DRM_FORMAT_BGR888) },\n@@ -233,15 +169,10 @@ PixelFormat V4L2PixelFormat::toPixelFormat() const\n V4L2PixelFormat V4L2PixelFormat::fromPixelFormat(const PixelFormat &pixelFormat,\n \t\t\t\t\t\t bool multiplanar)\n {\n-\tconst auto iter = pf2vpf.find(pixelFormat);\n-\tif (iter == pf2vpf.end()) {\n-\t\tLOG(V4L2, Warning)\n-\t\t\t<< \"Unsupported pixel format \"\n-\t\t\t<< pixelFormat.toString();\n+\tconst PixelFormatInfo &info = PixelFormatInfo::info(pixelFormat);\n+\tif (!info.isValid())\n \t\treturn V4L2PixelFormat();\n-\t}\n \n-\tconst PixelFormatInfo &info = iter->second;\n \treturn info.v4l2Format;\n }\n \n", "prefixes": [ "libcamera-devel", "v2", "4/6" ] }