Patch Detail
Show a patch.
GET /api/1.1/patches/3108/?format=api
{ "id": 3108, "url": "https://patchwork.libcamera.org/api/1.1/patches/3108/?format=api", "web_url": "https://patchwork.libcamera.org/patch/3108/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/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": "<20200316024036.2474307-5-niklas.soderlund@ragnatech.se>", "date": "2020-03-16T02:40:36", "name": "[libcamera-devel,4/4] libcamera: PixelFormat: Turn into a class", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "8b6a9c7ce04232a50bd25cd56ae9096c5da88f64", "submitter": { "id": 5, "url": "https://patchwork.libcamera.org/api/1.1/people/5/?format=api", "name": "Niklas Söderlund", "email": "niklas.soderlund@ragnatech.se" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/3108/mbox/", "series": [ { "id": 721, "url": "https://patchwork.libcamera.org/api/1.1/series/721/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=721", "date": "2020-03-16T02:40:32", "name": "libcamera: PixelFormat: Turn into a class", "version": 1, "mbox": "https://patchwork.libcamera.org/series/721/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/3108/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/3108/checks/", "tags": {}, "headers": { "Return-Path": "<niklas.soderlund@ragnatech.se>", "Received": [ "from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net\n\t[195.74.38.228])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4438762928\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 16 Mar 2020 03:41:37 +0100 (CET)", "from bismarck.berto.se (p4fca2392.dip0.t-ipconnect.de\n\t[79.202.35.146]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA\n\tid 9569ddcc-672f-11ea-9f40-0050569116f7;\n\tMon, 16 Mar 2020 03:41:05 +0100 (CET)" ], "X-Halon-ID": "9569ddcc-672f-11ea-9f40-0050569116f7", "Authorized-sender": "niklas@soderlund.pp.se", "From": "=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Mon, 16 Mar 2020 03:40:36 +0100", "Message-Id": "<20200316024036.2474307-5-niklas.soderlund@ragnatech.se>", "X-Mailer": "git-send-email 2.25.1", "In-Reply-To": "<20200316024036.2474307-1-niklas.soderlund@ragnatech.se>", "References": "<20200316024036.2474307-1-niklas.soderlund@ragnatech.se>", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=UTF-8", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH 4/4] libcamera: PixelFormat: Turn into a\n\tclass", "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": "Mon, 16 Mar 2020 02:41:37 -0000" }, "content": "Create a class to represent a pixel formats. This is done to add support\nfor modifiers for the formats. So far no formats are added by any\npipeline handler, all plumbing to deal with them is however in place.\n\nPipelines that adds modifiers will come when support for RAW capture is\nadded.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n* Changes since RFC\n- Drop table of translation from V4L2 to DRM fourcc and turn PixelFormat\n into a more basic data container class.\n---\n include/libcamera/pixelformats.h | 24 +++++-\n src/cam/main.cpp | 6 +-\n src/gstreamer/gstlibcamera-utils.cpp | 8 +-\n src/libcamera/pipeline/rkisp1/rkisp1.cpp | 2 +-\n src/libcamera/pipeline/uvcvideo.cpp | 5 +-\n src/libcamera/pixelformats.cpp | 101 +++++++++++++++++++++--\n src/libcamera/stream.cpp | 2 +-\n src/libcamera/v4l2_videodevice.cpp | 5 +-\n src/qcam/format_converter.cpp | 2 +-\n src/v4l2/v4l2_camera_proxy.cpp | 4 +-\n 10 files changed, 136 insertions(+), 23 deletions(-)", "diff": "diff --git a/include/libcamera/pixelformats.h b/include/libcamera/pixelformats.h\nindex 6e25b8d8b76e5961..ce8f9f93b767ec23 100644\n--- a/include/libcamera/pixelformats.h\n+++ b/include/libcamera/pixelformats.h\n@@ -7,11 +7,33 @@\n #ifndef __LIBCAMERA_PIXEL_FORMATS_H__\n #define __LIBCAMERA_PIXEL_FORMATS_H__\n \n+#include <set>\n #include <stdint.h>\n+#include <string>\n \n namespace libcamera {\n \n-using PixelFormat = uint32_t;\n+class PixelFormat\n+{\n+public:\n+\tPixelFormat();\n+\tPixelFormat(uint32_t fourcc, const std::set<uint64_t> &modifiers = {});\n+\n+\tPixelFormat(const PixelFormat &other);\n+\tPixelFormat &operator=(const PixelFormat &other);\n+\n+\tuint32_t fourcc() const { return fourcc_; }\n+\tconst std::set<uint64_t> &modifiers() const { return modifiers_; }\n+\tstd::string toString() const;\n+\n+private:\n+\tuint32_t fourcc_;\n+\tstd::set<uint64_t> modifiers_;\n+};\n+\n+bool operator==(const PixelFormat &lhs, const PixelFormat &rhs);\n+bool operator!=(const PixelFormat &lhs, const PixelFormat &rhs);\n+bool operator<(const PixelFormat &lhs, const PixelFormat &rhs);\n \n } /* namespace libcamera */\n \ndiff --git a/src/cam/main.cpp b/src/cam/main.cpp\nindex af516f1cbf23974a..f73e77f381779853 100644\n--- a/src/cam/main.cpp\n+++ b/src/cam/main.cpp\n@@ -253,7 +253,7 @@ int CamApp::prepareConfig()\n \n \t\t\t/* TODO: Translate 4CC string to ID. */\n \t\t\tif (opt.isSet(\"pixelformat\"))\n-\t\t\t\tcfg.pixelFormat = opt[\"pixelformat\"];\n+\t\t\t\tcfg.pixelFormat = PixelFormat(opt[\"pixelformat\"]);\n \t\t}\n \t}\n \n@@ -304,8 +304,8 @@ int CamApp::infoConfiguration()\n \n \t\tconst StreamFormats &formats = cfg.formats();\n \t\tfor (PixelFormat pixelformat : formats.pixelformats()) {\n-\t\t\tstd::cout << \" * Pixelformat: 0x\" << std::hex\n-\t\t\t\t << std::setw(8) << pixelformat << \" \"\n+\t\t\tstd::cout << \" * Pixelformat: \"\n+\t\t\t\t << pixelformat.toString() << \" \"\n \t\t\t\t << formats.range(pixelformat).toString()\n \t\t\t\t << std::endl;\n \ndiff --git a/src/gstreamer/gstlibcamera-utils.cpp b/src/gstreamer/gstlibcamera-utils.cpp\nindex 3b3973bcea3dc759..f21e94c3eef92737 100644\n--- a/src/gstreamer/gstlibcamera-utils.cpp\n+++ b/src/gstreamer/gstlibcamera-utils.cpp\n@@ -80,11 +80,11 @@ gst_libcamera_stream_formats_to_caps(const StreamFormats &formats)\n \tGstCaps *caps = gst_caps_new_empty();\n \n \tfor (PixelFormat pixelformat : formats.pixelformats()) {\n-\t\tg_autoptr(GstStructure) bare_s = bare_structure_from_fourcc(pixelformat);\n+\t\tg_autoptr(GstStructure) bare_s = bare_structure_from_fourcc(pixelformat.fourcc());\n \n \t\tif (!bare_s) {\n \t\t\tGST_WARNING(\"Unsupported DRM format %\" GST_FOURCC_FORMAT,\n-\t\t\t\t GST_FOURCC_ARGS(pixelformat));\n+\t\t\t\t GST_FOURCC_ARGS(pixelformat.fourcc()));\n \t\t\tcontinue;\n \t\t}\n \n@@ -120,7 +120,7 @@ GstCaps *\n gst_libcamera_stream_configuration_to_caps(const StreamConfiguration &stream_cfg)\n {\n \tGstCaps *caps = gst_caps_new_empty();\n-\tGstStructure *s = bare_structure_from_fourcc(stream_cfg.pixelFormat);\n+\tGstStructure *s = bare_structure_from_fourcc(stream_cfg.pixelFormat.fourcc());\n \n \tgst_structure_set(s,\n \t\t\t \"width\", G_TYPE_INT, stream_cfg.size.width,\n@@ -135,7 +135,7 @@ void\n gst_libcamera_configure_stream_from_caps(StreamConfiguration &stream_cfg,\n \t\t\t\t\t GstCaps *caps)\n {\n-\tGstVideoFormat gst_format = drm_to_gst_format(stream_cfg.pixelFormat);\n+\tGstVideoFormat gst_format = drm_to_gst_format(stream_cfg.pixelFormat.fourcc());\n \n \t/* First fixate the caps using default configuration value. */\n \tg_assert(gst_caps_is_writable(caps));\ndiff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\nindex 01977ad697a91a44..8223b82c4a9c773c 100644\n--- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n+++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n@@ -790,7 +790,7 @@ int PipelineHandlerRkISP1::start(Camera *camera)\n \t/* Inform IPA of stream configuration and sensor controls. */\n \tstd::map<unsigned int, IPAStream> streamConfig;\n \tstreamConfig[0] = {\n-\t\t.pixelFormat = data->stream_.configuration().pixelFormat,\n+\t\t.pixelFormat = data->stream_.configuration().pixelFormat.fourcc(),\n \t\t.size = data->stream_.configuration().size,\n \t};\n \ndiff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp\nindex b5f98a96a14fe348..d1954c429cb300e8 100644\n--- a/src/libcamera/pipeline/uvcvideo.cpp\n+++ b/src/libcamera/pipeline/uvcvideo.cpp\n@@ -113,8 +113,9 @@ CameraConfiguration::Status UVCCameraConfiguration::validate()\n \tif (iter == pixelFormats.end()) {\n \t\tcfg.pixelFormat = pixelFormats.front();\n \t\tLOG(UVC, Debug)\n-\t\t\t<< \"Adjusting pixel format from \" << pixelFormat\n-\t\t\t<< \" to \" << cfg.pixelFormat;\n+\t\t\t<< \"Adjusting pixel format from \"\n+\t\t\t<< pixelFormat.toString() << \" to \"\n+\t\t\t<< cfg.pixelFormat.toString();\n \t\tstatus = Adjusted;\n \t}\n \ndiff --git a/src/libcamera/pixelformats.cpp b/src/libcamera/pixelformats.cpp\nindex c03335400b709d9b..46f2e3883989f522 100644\n--- a/src/libcamera/pixelformats.cpp\n+++ b/src/libcamera/pixelformats.cpp\n@@ -7,6 +7,8 @@\n \n #include <libcamera/pixelformats.h>\n \n+#include \"log.h\"\n+\n /**\n * \\file pixelformats.h\n * \\brief libcamera pixel formats\n@@ -14,15 +16,104 @@\n \n namespace libcamera {\n \n+LOG_DEFINE_CATEGORY(PixelFormats)\n+\n /**\n- * \\typedef PixelFormat\n+ * \\class PixelFormat\n * \\brief libcamera image pixel format\n *\n * The PixelFormat type describes the format of images in the public libcamera\n- * API. It stores a FourCC value as a 32-bit unsigned integer. The values are\n- * defined in the Linux kernel DRM/KMS API (see linux/drm_fourcc.h).\n- *\n- * \\todo Add support for format modifiers\n+ * API. It stores a FourCC value as a 32-bit unsigned integer and a set of\n+ * modifiers. The values are defined in the Linux kernel DRM/KMS API (see\n+ * linux/drm_fourcc.h).\n */\n \n+PixelFormat::PixelFormat()\n+\t: fourcc_(0)\n+{\n+}\n+\n+/**\n+ * \\brief Construct a PixelFormat from a DRM fourcc and a set of modifiers\n+ * \\param[in] fourcc A DRM fourcc\n+ * \\param[in] modifiers A set of DRM fourcc modifiers\n+ */\n+PixelFormat::PixelFormat(uint32_t fourcc, const std::set<uint64_t> &modifiers)\n+\t: fourcc_(fourcc), modifiers_(modifiers)\n+{\n+}\n+\n+/**\n+ * \\brief Construct a PixelFormat from \\a other\n+ * \\param[in] other Other PixelFormat\n+ */\n+PixelFormat::PixelFormat(const PixelFormat &other)\n+\t: PixelFormat(other.fourcc_, other.modifiers_)\n+{\n+}\n+\n+/**\n+ * \\brief Copy assignment operator, copy the pixel format from \\a other\n+ * \\param[in] other Other PixelFormat\n+ */\n+PixelFormat &PixelFormat::operator=(const PixelFormat &other)\n+{\n+\tfourcc_ = other.fourcc_;\n+\tmodifiers_ = other.modifiers_;\n+\n+\treturn *this;\n+}\n+\n+/**\n+ * \\fn PixelFormat::fourcc() const\n+ * \\brief Retrive the pixel formats fourcc\n+ * \\return DRM fourcc code\n+ */\n+\n+/**\n+ * \\fn PixelFormat::modifiers() const\n+ * \\brief Retrive the pixel formats modifiers\n+ * \\return Set of DRM modifiers\n+ */\n+\n+/**\n+ * \\brief Assemble and return a string describing the pixel format\n+ * \\return A string describing the pixel format\n+ */\n+std::string PixelFormat::toString() const\n+{\n+\tstd::stringstream ss;\n+\tss << utils::hex(fourcc_, 8);\n+\treturn ss.str();\n+}\n+\n+/**\n+ * \\brief Compare pixel formats for equality\n+ * \\return True if the two pixel formats are equal, false otherwise\n+ */\n+bool operator==(const PixelFormat &lhs, const PixelFormat &rhs)\n+{\n+\treturn lhs.fourcc() == rhs.fourcc() &&\n+\t\tlhs.modifiers() == rhs.modifiers();\n+}\n+\n+/**\n+ * \\brief Compare pixel formats for inequality\n+ * \\return True if the two pixel formats are not equal, false otherwise\n+ */\n+bool operator!=(const PixelFormat &lhs, const PixelFormat &rhs)\n+{\n+\treturn !(lhs == rhs);\n+}\n+\n+/**\n+ * \\brief Compare pixel formats for smaller than order\n+ * \\todo Take modifiers into account if \\a lhs == \\a rhs.\n+ * \\return True if \\a lhs is smaller than \\a rhs, false otherwise\n+ */\n+bool operator<(const PixelFormat &lhs, const PixelFormat &rhs)\n+{\n+\treturn lhs.fourcc() < rhs.fourcc();\n+}\n+\n } /* namespace libcamera */\ndiff --git a/src/libcamera/stream.cpp b/src/libcamera/stream.cpp\nindex 13789e9eb344f95c..f34ea08de03b744e 100644\n--- a/src/libcamera/stream.cpp\n+++ b/src/libcamera/stream.cpp\n@@ -348,7 +348,7 @@ StreamConfiguration::StreamConfiguration(const StreamFormats &formats)\n std::string StreamConfiguration::toString() const\n {\n \tstd::stringstream ss;\n-\tss << size.toString() << \"-\" << utils::hex(pixelFormat);\n+\tss << size.toString() << \"-\" << pixelFormat.toString();\n \treturn ss.str();\n }\n \ndiff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\nindex f9c59d5e3fb65737..66f7347dc2e4f7fd 100644\n--- a/src/libcamera/v4l2_videodevice.cpp\n+++ b/src/libcamera/v4l2_videodevice.cpp\n@@ -1643,7 +1643,7 @@ uint32_t V4L2VideoDevice::toV4L2Fourcc(PixelFormat pixelFormat)\n */\n uint32_t V4L2VideoDevice::toV4L2Fourcc(PixelFormat pixelFormat, bool multiplanar)\n {\n-\tswitch (pixelFormat) {\n+\tswitch (pixelFormat.fourcc()) {\n \t/* RGB formats. */\n \tcase DRM_FORMAT_BGR888:\n \t\treturn V4L2_PIX_FMT_RGB24;\n@@ -1687,8 +1687,7 @@ uint32_t V4L2VideoDevice::toV4L2Fourcc(PixelFormat pixelFormat, bool multiplanar\n \t * class. Until we fix the logger, work around it.\n \t */\n \tlibcamera::_log(__FILE__, __LINE__, _LOG_CATEGORY(V4L2)(), LogError).stream()\n-\t\t<< \"Unsupported V4L2 pixel format \"\n-\t\t<< utils::hex(pixelFormat);\n+\t\t<< \"Unsupported V4L2 pixel format \" << pixelFormat.toString();\n \treturn 0;\n }\n \ndiff --git a/src/qcam/format_converter.cpp b/src/qcam/format_converter.cpp\nindex 368cb43fbf17ae4d..c071ea9b4022750c 100644\n--- a/src/qcam/format_converter.cpp\n+++ b/src/qcam/format_converter.cpp\n@@ -30,7 +30,7 @@\n int FormatConverter::configure(libcamera::PixelFormat format, unsigned int width,\n \t\t\t unsigned int height)\n {\n-\tswitch (format) {\n+\tswitch (format.fourcc()) {\n \tcase DRM_FORMAT_NV12:\n \t\tformatFamily_ = NV;\n \t\thorzSubSample_ = 2;\ndiff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp\nindex b620f236499cf77d..3bbbbf79cdb475db 100644\n--- a/src/v4l2/v4l2_camera_proxy.cpp\n+++ b/src/v4l2/v4l2_camera_proxy.cpp\n@@ -534,7 +534,7 @@ struct PixelFormatInfo {\n \n namespace {\n \n-constexpr std::array<PixelFormatInfo, 13> pixelFormatInfo = {{\n+static const std::array<PixelFormatInfo, 13> pixelFormatInfo = {{\n \t/* RGB formats. */\n \t{ DRM_FORMAT_RGB888,\tV4L2_PIX_FMT_BGR24,\t1, {{ { 24, 1, 1 }, { 0, 0, 0 }, { 0, 0, 0 } }} },\n \t{ DRM_FORMAT_BGR888,\tV4L2_PIX_FMT_RGB24,\t1, {{ { 24, 1, 1 }, { 0, 0, 0 }, { 0, 0, 0 } }} },\n@@ -606,7 +606,7 @@ uint32_t V4L2CameraProxy::drmToV4L2(PixelFormat format)\n \t\t\t\t\t return info.format == format;\n \t\t\t\t });\n \tif (info == pixelFormatInfo.end())\n-\t\treturn format;\n+\t\treturn format.fourcc();\n \n \treturn info->v4l2Format;\n }\n", "prefixes": [ "libcamera-devel", "4/4" ] }