Show a patch.

GET /api/patches/15962/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 15962,
    "url": "https://patchwork.libcamera.org/api/patches/15962/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/15962/",
    "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": "<20220518131329.66994-13-tomi.valkeinen@ideasonboard.com>",
    "date": "2022-05-18T13:13:23",
    "name": "[libcamera-devel,v3,12/18] py: implement PixelFormat class",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "bda583d5d83327161976777e628d2be6044c2c3d",
    "submitter": {
        "id": 109,
        "url": "https://patchwork.libcamera.org/api/people/109/?format=api",
        "name": "Tomi Valkeinen",
        "email": "tomi.valkeinen@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/15962/mbox/",
    "series": [
        {
            "id": 3122,
            "url": "https://patchwork.libcamera.org/api/series/3122/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3122",
            "date": "2022-05-18T13:13:11",
            "name": "Misc Python bindings patches",
            "version": 3,
            "mbox": "https://patchwork.libcamera.org/series/3122/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/15962/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/15962/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 12159C3256\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 18 May 2022 13:14:07 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A204565669;\n\tWed, 18 May 2022 15:14:06 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 962F765659\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 18 May 2022 15:13:52 +0200 (CEST)",
            "from deskari.lan (91-156-85-209.elisa-laajakaista.fi\n\t[91.156.85.209])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id F259F22BA;\n\tWed, 18 May 2022 15:13:51 +0200 (CEST)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1652879646;\n\tbh=gn2amU8VE4PLh6T2oRe1CaqN5cONffQhEBi3RTvwtYI=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=g929QuppXhrWNVvzDa0PUOOn9mkepp1N3PgnbqoHmm82OU1xJGdTkcvbG+owf0oqp\n\tzvVk/jcf0IMjyDSvQMJInvZG5Xv/PumdHnK2NR+m0/K2sR7oN7bJGAHjwLY+RhZoc6\n\tpIAVCNvoU+ONMvEycK1Q4K53n6f9KSwcHQkx8zoSIoe454ZfgTMQ/Qhr7xG/mrvTBA\n\tG7QDIBOY5nv9eWAng6+i1a8wLsGcBTy1EDIEmKp8pzdLpwOSeLBWZW07yZVZZJeyuc\n\tSivvKfG64IT2aQEJBvem03R0ct0s7FONnlxzlW/eGXxPD1qcK0nZHS0D/mwZpdTgX7\n\tnkbjyHUxa/OIA==",
            "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1652879632;\n\tbh=gn2amU8VE4PLh6T2oRe1CaqN5cONffQhEBi3RTvwtYI=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=tqJei5guMG+oN+yR1Ez/Y0iFevD7Jpqc5ZWvJDXISq4hAojjvQx6q/P+CHtm8TAZn\n\tGmMvmmyiMVN0TmqtYPrwpsiuRlyCIWQbnCRynnVgaGhEnbBeDdSnOMB0+kQBPPPhTZ\n\t93ccTP7KDNkl6TPeff8rrn44wCaHrwfIER577rGM="
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"tqJei5gu\"; dkim-atps=neutral",
        "To": "libcamera-devel@lists.libcamera.org,\n\tDavid Plowman <david.plowman@raspberrypi.com>,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tJacopo Mondi <jacopo@jmondi.org>",
        "Date": "Wed, 18 May 2022 16:13:23 +0300",
        "Message-Id": "<20220518131329.66994-13-tomi.valkeinen@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.34.1",
        "In-Reply-To": "<20220518131329.66994-1-tomi.valkeinen@ideasonboard.com>",
        "References": "<20220518131329.66994-1-tomi.valkeinen@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v3 12/18] py: implement PixelFormat class",
        "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": "Tomi Valkeinen via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>",
        "Reply-To": "Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "Implement PixelFormat bindings properly with a PixelFormat class. Change\nthe bindings to use the new class instead of a string.\n\nSigned-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n src/py/cam/cam.py           |  2 +-\n src/py/cam/cam_kms.py       | 10 +--------\n src/py/cam/cam_qt.py        |  4 +++-\n src/py/cam/cam_qtgl.py      | 17 +--------------\n src/py/cam/gl_helpers.py    |  8 -------\n src/py/libcamera/pymain.cpp | 42 ++++++++++++++++++-------------------\n 6 files changed, 27 insertions(+), 56 deletions(-)",
    "diff": "diff --git a/src/py/cam/cam.py b/src/py/cam/cam.py\nindex c7da97d7..001fb9de 100755\n--- a/src/py/cam/cam.py\n+++ b/src/py/cam/cam.py\n@@ -164,7 +164,7 @@ def configure(ctx):\n             stream_config.size = (stream_opts['width'], stream_opts['height'])\n \n         if 'pixelformat' in stream_opts:\n-            stream_config.pixel_format = stream_opts['pixelformat']\n+            stream_config.pixel_format = libcam.PixelFormat(stream_opts['pixelformat'])\n \n     stat = camconfig.validate()\n \ndiff --git a/src/py/cam/cam_kms.py b/src/py/cam/cam_kms.py\nindex d8ff0284..04381da1 100644\n--- a/src/py/cam/cam_kms.py\n+++ b/src/py/cam/cam_kms.py\n@@ -5,14 +5,6 @@ import pykms\n import selectors\n import sys\n \n-FMT_MAP = {\n-    'RGB888': pykms.PixelFormat.RGB888,\n-    'YUYV': pykms.PixelFormat.YUYV,\n-    'ARGB8888': pykms.PixelFormat.ARGB8888,\n-    'XRGB8888': pykms.PixelFormat.XRGB8888,\n-    'NV12': pykms.PixelFormat.NV12,\n-}\n-\n \n class KMSRenderer:\n     def __init__(self, state):\n@@ -120,7 +112,7 @@ class KMSRenderer:\n \n                 cfg = stream.configuration\n                 fmt = cfg.pixel_format\n-                fmt = FMT_MAP[fmt]\n+                fmt = pykms.PixelFormat(fmt.fourcc)\n \n                 plane = self.resman.reserve_generic_plane(self.crtc, fmt)\n                 assert(plane is not None)\ndiff --git a/src/py/cam/cam_qt.py b/src/py/cam/cam_qt.py\nindex fb485b9b..45a30aeb 100644\n--- a/src/py/cam/cam_qt.py\n+++ b/src/py/cam/cam_qt.py\n@@ -87,6 +87,8 @@ def to_rgb(fmt, size, data):\n     w = size[0]\n     h = size[1]\n \n+    fmt = str(fmt)\n+\n     if fmt == 'YUYV':\n         # YUV422\n         yuyv = data.reshape((h, w // 2 * 4))\n@@ -293,7 +295,7 @@ class MainWindow(QtWidgets.QWidget):\n             w, h = cfg.size\n             pitch = cfg.stride\n \n-            if cfg.pixel_format == 'MJPEG':\n+            if str(cfg.pixel_format) == 'MJPEG':\n                 img = Image.open(BytesIO(mfb.planes[0]))\n                 qim = ImageQt(img).copy()\n                 pix = QtGui.QPixmap.fromImage(qim)\ndiff --git a/src/py/cam/cam_qtgl.py b/src/py/cam/cam_qtgl.py\nindex 8a95994e..261accb8 100644\n--- a/src/py/cam/cam_qtgl.py\n+++ b/src/py/cam/cam_qtgl.py\n@@ -30,14 +30,6 @@ from OpenGL.GL import shaders\n \n from gl_helpers import *\n \n-# libcamera format string -> DRM fourcc\n-FMT_MAP = {\n-    'RGB888': 'RG24',\n-    'XRGB8888': 'XR24',\n-    'ARGB8888': 'AR24',\n-    'YUYV': 'YUYV',\n-}\n-\n \n class EglState:\n     def __init__(self):\n@@ -204,12 +196,6 @@ class MainWindow(QtWidgets.QWidget):\n             self.current[ctx['idx']] = []\n \n             for stream in ctx['streams']:\n-                fmt = stream.configuration.pixel_format\n-                size = stream.configuration.size\n-\n-                if fmt not in FMT_MAP:\n-                    raise Exception('Unsupported pixel format: ' + str(fmt))\n-\n                 self.textures[stream] = None\n \n         num_tiles = len(self.textures)\n@@ -281,8 +267,7 @@ class MainWindow(QtWidgets.QWidget):\n \n     def create_texture(self, stream, fb):\n         cfg = stream.configuration\n-        fmt = cfg.pixel_format\n-        fmt = str_to_fourcc(FMT_MAP[fmt])\n+        fmt = cfg.pixel_format.fourcc\n         w, h = cfg.size\n \n         attribs = [\ndiff --git a/src/py/cam/gl_helpers.py b/src/py/cam/gl_helpers.py\nindex ac5e6889..53b3e9df 100644\n--- a/src/py/cam/gl_helpers.py\n+++ b/src/py/cam/gl_helpers.py\n@@ -30,14 +30,6 @@ def getglEGLImageTargetTexture2DOES():\n \n glEGLImageTargetTexture2DOES = getglEGLImageTargetTexture2DOES()\n \n-# \\todo This can be dropped when we have proper PixelFormat bindings\n-def str_to_fourcc(str):\n-    assert(len(str) == 4)\n-    fourcc = 0\n-    for i, v in enumerate([ord(c) for c in str]):\n-        fourcc |= v << (i * 8)\n-    return fourcc\n-\n \n def get_gl_extensions():\n     n = GLint()\ndiff --git a/src/py/libcamera/pymain.cpp b/src/py/libcamera/pymain.cpp\nindex af22205e..97b05903 100644\n--- a/src/py/libcamera/pymain.cpp\n+++ b/src/py/libcamera/pymain.cpp\n@@ -8,7 +8,6 @@\n /*\n  * \\todo Add geometry classes (Point, Rectangle...)\n  * \\todo Add bindings for the ControlInfo class\n- * \\todo Add bindings for the PixelFormat class\n  */\n \n #include <mutex>\n@@ -173,6 +172,7 @@ PYBIND11_MODULE(_libcamera, m)\n \tauto pyColorSpaceTransferFunction = py::enum_<ColorSpace::TransferFunction>(pyColorSpace, \"TransferFunction\");\n \tauto pyColorSpaceYcbcrEncoding = py::enum_<ColorSpace::YcbcrEncoding>(pyColorSpace, \"YcbcrEncoding\");\n \tauto pyColorSpaceRange = py::enum_<ColorSpace::Range>(pyColorSpace, \"Range\");\n+\tauto pyPixelFormat = py::class_<PixelFormat>(m, \"PixelFormat\");\n \n \t/* Global functions */\n \tm.def(\"log_set_level\", &logSetLevel);\n@@ -404,14 +404,7 @@ PYBIND11_MODULE(_libcamera, m)\n \t\t\t\tself.size.width = std::get<0>(size);\n \t\t\t\tself.size.height = std::get<1>(size);\n \t\t\t})\n-\t\t.def_property(\n-\t\t\t\"pixel_format\",\n-\t\t\t[](StreamConfiguration &self) {\n-\t\t\t\treturn self.pixelFormat.toString();\n-\t\t\t},\n-\t\t\t[](StreamConfiguration &self, std::string fmt) {\n-\t\t\t\tself.pixelFormat = PixelFormat::fromString(fmt);\n-\t\t\t})\n+\t\t.def_readwrite(\"pixel_format\", &StreamConfiguration::pixelFormat)\n \t\t.def_readwrite(\"stride\", &StreamConfiguration::stride)\n \t\t.def_readwrite(\"frame_size\", &StreamConfiguration::frameSize)\n \t\t.def_readwrite(\"buffer_count\", &StreamConfiguration::bufferCount)\n@@ -420,22 +413,15 @@ PYBIND11_MODULE(_libcamera, m)\n \t\t.def_readwrite(\"color_space\", &StreamConfiguration::colorSpace);\n \n \tpyStreamFormats\n-\t\t.def_property_readonly(\"pixel_formats\", [](StreamFormats &self) {\n-\t\t\tstd::vector<std::string> fmts;\n-\t\t\tfor (auto &fmt : self.pixelformats())\n-\t\t\t\tfmts.push_back(fmt.toString());\n-\t\t\treturn fmts;\n-\t\t})\n-\t\t.def(\"sizes\", [](StreamFormats &self, const std::string &pixelFormat) {\n-\t\t\tauto fmt = PixelFormat::fromString(pixelFormat);\n+\t\t.def_property_readonly(\"pixel_formats\", &StreamFormats::pixelformats)\n+\t\t.def(\"sizes\", [](StreamFormats &self, const PixelFormat &pixelFormat) {\n \t\t\tstd::vector<std::tuple<uint32_t, uint32_t>> fmts;\n-\t\t\tfor (const auto &s : self.sizes(fmt))\n+\t\t\tfor (const auto &s : self.sizes(pixelFormat))\n \t\t\t\tfmts.push_back(std::make_tuple(s.width, s.height));\n \t\t\treturn fmts;\n \t\t})\n-\t\t.def(\"range\", [](StreamFormats &self, const std::string &pixelFormat) {\n-\t\t\tauto fmt = PixelFormat::fromString(pixelFormat);\n-\t\t\tconst auto &range = self.range(fmt);\n+\t\t.def(\"range\", [](StreamFormats &self, const PixelFormat &pixelFormat) {\n+\t\t\tconst auto &range = self.range(pixelFormat);\n \t\t\treturn make_tuple(std::make_tuple(range.hStep, range.vStep),\n \t\t\t\t\t  std::make_tuple(range.min.width, range.min.height),\n \t\t\t\t\t  std::make_tuple(range.max.width, range.max.height));\n@@ -648,4 +634,18 @@ PYBIND11_MODULE(_libcamera, m)\n \tpyColorSpaceRange\n \t\t.value(\"Full\", ColorSpace::Range::Full)\n \t\t.value(\"Limited\", ColorSpace::Range::Limited);\n+\n+\tpyPixelFormat\n+\t\t.def(py::init<>())\n+\t\t.def(py::init<uint32_t, uint64_t>())\n+\t\t.def(py::init<>([](const std::string &str) {\n+\t\t\treturn PixelFormat::fromString(str);\n+\t\t}))\n+\t\t.def_property_readonly(\"fourcc\", &PixelFormat::fourcc)\n+\t\t.def_property_readonly(\"modifier\", &PixelFormat::modifier)\n+\t\t.def(py::self == py::self)\n+\t\t.def(\"__str__\", &PixelFormat::toString)\n+\t\t.def(\"__repr__\", [](const PixelFormat &self) {\n+\t\t\treturn \"libcamera.PixelFormat('\" + self.toString() + \"')\";\n+\t\t});\n }\n",
    "prefixes": [
        "libcamera-devel",
        "v3",
        "12/18"
    ]
}