Show a patch.

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

{
    "id": 15914,
    "url": "https://patchwork.libcamera.org/api/patches/15914/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/15914/",
    "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": "<20220516141022.96327-9-tomi.valkeinen@ideasonboard.com>",
    "date": "2022-05-16T14:10:16",
    "name": "[libcamera-devel,08/14] py: move conversion funcs to libcamera.utils",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "ec008db53b579c90d9aba2ad9e19180e95ca1cff",
    "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/15914/mbox/",
    "series": [
        {
            "id": 3113,
            "url": "https://patchwork.libcamera.org/api/series/3113/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3113",
            "date": "2022-05-16T14:10:08",
            "name": "Misc Python bindings patches",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/3113/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/15914/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/15914/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 BD17EC3256\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 16 May 2022 14:11:00 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6959C65682;\n\tMon, 16 May 2022 16:11:00 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0A2D265654\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 16 May 2022 16:10: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 68F8F576;\n\tMon, 16 May 2022 16:10:51 +0200 (CEST)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1652710260;\n\tbh=wMmphrOaD0hpFNdcY8kGUJbvzPlXmXi/e5RnIjxNttM=;\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=qUa2NjDRN74fGY/f1pS9vROXDUJkj/R5OsxIEItP2V6E+5Sw2mwoownWml22tWxLA\n\tQ2zhzn0sAa3dM+xFyQgRgDf1BO3rfrgBQnW04h5zDLsOsZTCpqW57LeF5ePXGeTQf8\n\tLQgrj0yWII5GlSuW1sojuoLW96QQjLRNOHfH+G/yp5T0EfZuNxdxbfvXJ4il7OYJeA\n\tz+IR2ZLdu+IM6BDjokk0yaBdsFZNj2QIREMGjcOijqFZrRK/5KbEWi0ynzD/O6deA6\n\tOs7x05XI5WpAQXEqNQObr8Lw/IYSewiMTt5Aail+UyigzLpuCciIOKHQ2nrwGjIjwy\n\ts+mjpeyHlcYPw==",
            "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1652710251;\n\tbh=wMmphrOaD0hpFNdcY8kGUJbvzPlXmXi/e5RnIjxNttM=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=VGbhxW0iy4zt20bj2ekxIA6VnIXiYujAdMGhSr4WJUad/9KS6C2fJdpJOUXI0XwTy\n\t/WkimP8LuJ6N/xHZjoZfV3+veDOzo3PL23jhrkH1lmtxBQhLvs2256f7XShaHtr67w\n\t0Lhw4ta409D4ih+rD9YNIxszlPC/M/HFjFACEFzY="
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"VGbhxW0i\"; 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": "Mon, 16 May 2022 17:10:16 +0300",
        "Message-Id": "<20220516141022.96327-9-tomi.valkeinen@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.34.1",
        "In-Reply-To": "<20220516141022.96327-1-tomi.valkeinen@ideasonboard.com>",
        "References": "<20220516141022.96327-1-tomi.valkeinen@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH 08/14] py: move conversion funcs to\n\tlibcamera.utils",
        "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": "cam_qt.py has a bunch of utility functions for pixel format conversions.\nCreate a new libcamera submodule for these.\n\nAlso create a symlink from the build dir to the source dir for those new\nsubmodule, so that we can run the bindings directly from the build dir.\n\nSigned-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>\n---\n src/py/cam/cam_qt.py                          | 195 +-----------------\n src/py/libcamera/meson.build                  |   6 +\n src/py/libcamera/utils/__init__.py            |   4 +\n .../cam_qt.py => libcamera/utils/conv.py}     | 164 +--------------\n 4 files changed, 17 insertions(+), 352 deletions(-)\n create mode 100644 src/py/libcamera/utils/__init__.py\n copy src/py/{cam/cam_qt.py => libcamera/utils/conv.py} (58%)",
    "diff": "diff --git a/src/py/cam/cam_qt.py b/src/py/cam/cam_qt.py\nindex 5753f0b2..dc5219eb 100644\n--- a/src/py/cam/cam_qt.py\n+++ b/src/py/cam/cam_qt.py\n@@ -1,17 +1,13 @@\n # SPDX-License-Identifier: GPL-2.0-or-later\n # Copyright (C) 2022, Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>\n-#\n-# Debayering code from PiCamera documentation\n \n from io import BytesIO\n-from numpy.lib.stride_tricks import as_strided\n from PIL import Image\n from PIL.ImageQt import ImageQt\n from PyQt5 import QtCore, QtGui, QtWidgets\n-import numpy as np\n+import libcamera.utils as camutils\n import sys\n \n-\n def rgb_to_pix(rgb):\n     img = Image.frombuffer('RGB', (rgb.shape[1], rgb.shape[0]), rgb)\n     qim = ImageQt(img).copy()\n@@ -19,192 +15,6 @@ def rgb_to_pix(rgb):\n     return pix\n \n \n-def separate_components(data, r0, g0, g1, b0):\n-    # Now to split the data up into its red, green, and blue components. The\n-    # Bayer pattern of the OV5647 sensor is BGGR. In other words the first\n-    # row contains alternating green/blue elements, the second row contains\n-    # alternating red/green elements, and so on as illustrated below:\n-    #\n-    # GBGBGBGBGBGBGB\n-    # RGRGRGRGRGRGRG\n-    # GBGBGBGBGBGBGB\n-    # RGRGRGRGRGRGRG\n-    #\n-    # Please note that if you use vflip or hflip to change the orientation\n-    # of the capture, you must flip the Bayer pattern accordingly\n-\n-    rgb = np.zeros(data.shape + (3,), dtype=data.dtype)\n-    rgb[r0[1]::2, r0[0]::2, 0] = data[r0[1]::2, r0[0]::2]  # Red\n-    rgb[g0[1]::2, g0[0]::2, 1] = data[g0[1]::2, g0[0]::2]  # Green\n-    rgb[g1[1]::2, g1[0]::2, 1] = data[g1[1]::2, g1[0]::2]  # Green\n-    rgb[b0[1]::2, b0[0]::2, 2] = data[b0[1]::2, b0[0]::2]  # Blue\n-\n-    return rgb\n-\n-\n-def demosaic(rgb, r0, g0, g1, b0):\n-    # At this point we now have the raw Bayer data with the correct values\n-    # and colors but the data still requires de-mosaicing and\n-    # post-processing. If you wish to do this yourself, end the script here!\n-    #\n-    # Below we present a fairly naive de-mosaic method that simply\n-    # calculates the weighted average of a pixel based on the pixels\n-    # surrounding it. The weighting is provided b0[1] a b0[1]te representation of\n-    # the Bayer filter which we construct first:\n-\n-    bayer = np.zeros(rgb.shape, dtype=np.uint8)\n-    bayer[r0[1]::2, r0[0]::2, 0] = 1  # Red\n-    bayer[g0[1]::2, g0[0]::2, 1] = 1  # Green\n-    bayer[g1[1]::2, g1[0]::2, 1] = 1  # Green\n-    bayer[b0[1]::2, b0[0]::2, 2] = 1  # Blue\n-\n-    # Allocate an array to hold our output with the same shape as the input\n-    # data. After this we define the size of window that will be used to\n-    # calculate each weighted average (3x3). Then we pad out the rgb and\n-    # bayer arrays, adding blank pixels at their edges to compensate for the\n-    # size of the window when calculating averages for edge pixels.\n-\n-    output = np.empty(rgb.shape, dtype=rgb.dtype)\n-    window = (3, 3)\n-    borders = (window[0] - 1, window[1] - 1)\n-    border = (borders[0] // 2, borders[1] // 2)\n-\n-    # rgb_pad = np.zeros((\n-    #    rgb.shape[0] + borders[0],\n-    #    rgb.shape[1] + borders[1],\n-    #    rgb.shape[2]), dtype=rgb.dtype)\n-    # rgb_pad[\n-    #    border[0]:rgb_pad.shape[0] - border[0],\n-    #    border[1]:rgb_pad.shape[1] - border[1],\n-    #    :] = rgb\n-    # rgb = rgb_pad\n-    #\n-    # bayer_pad = np.zeros((\n-    #    bayer.shape[0] + borders[0],\n-    #    bayer.shape[1] + borders[1],\n-    #    bayer.shape[2]), dtype=bayer.dtype)\n-    # bayer_pad[\n-    #    border[0]:bayer_pad.shape[0] - border[0],\n-    #    border[1]:bayer_pad.shape[1] - border[1],\n-    #    :] = bayer\n-    # bayer = bayer_pad\n-\n-    # In numpy >=1.7.0 just use np.pad (version in Raspbian is 1.6.2 at the\n-    # time of writing...)\n-    #\n-    rgb = np.pad(rgb, [\n-        (border[0], border[0]),\n-        (border[1], border[1]),\n-        (0, 0),\n-    ], 'constant')\n-    bayer = np.pad(bayer, [\n-        (border[0], border[0]),\n-        (border[1], border[1]),\n-        (0, 0),\n-    ], 'constant')\n-\n-    # For each plane in the RGB data, we use a nifty numpy trick\n-    # (as_strided) to construct a view over the plane of 3x3 matrices. We do\n-    # the same for the bayer array, then use Einstein summation on each\n-    # (np.sum is simpler, but copies the data so it's slower), and divide\n-    # the results to get our weighted average:\n-\n-    for plane in range(3):\n-        p = rgb[..., plane]\n-        b = bayer[..., plane]\n-        pview = as_strided(p, shape=(\n-            p.shape[0] - borders[0],\n-            p.shape[1] - borders[1]) + window, strides=p.strides * 2)\n-        bview = as_strided(b, shape=(\n-            b.shape[0] - borders[0],\n-            b.shape[1] - borders[1]) + window, strides=b.strides * 2)\n-        psum = np.einsum('ijkl->ij', pview)\n-        bsum = np.einsum('ijkl->ij', bview)\n-        output[..., plane] = psum // bsum\n-\n-    return output\n-\n-\n-def to_rgb(fmt, size, data):\n-    w = size[0]\n-    h = size[1]\n-\n-    if fmt == 'YUYV':\n-        # YUV422\n-        yuyv = data.reshape((h, w // 2 * 4))\n-\n-        # YUV444\n-        yuv = np.empty((h, w, 3), dtype=np.uint8)\n-        yuv[:, :, 0] = yuyv[:, 0::2]                    # Y\n-        yuv[:, :, 1] = yuyv[:, 1::4].repeat(2, axis=1)  # U\n-        yuv[:, :, 2] = yuyv[:, 3::4].repeat(2, axis=1)  # V\n-\n-        m = np.array([\n-            [1.0, 1.0, 1.0],\n-            [-0.000007154783816076815, -0.3441331386566162, 1.7720025777816772],\n-            [1.4019975662231445, -0.7141380310058594, 0.00001542569043522235]\n-        ])\n-\n-        rgb = np.dot(yuv, m)\n-        rgb[:, :, 0] -= 179.45477266423404\n-        rgb[:, :, 1] += 135.45870971679688\n-        rgb[:, :, 2] -= 226.8183044444304\n-        rgb = rgb.astype(np.uint8)\n-\n-    elif fmt == 'RGB888':\n-        rgb = data.reshape((h, w, 3))\n-        rgb[:, :, [0, 1, 2]] = rgb[:, :, [2, 1, 0]]\n-\n-    elif fmt == 'BGR888':\n-        rgb = data.reshape((h, w, 3))\n-\n-    elif fmt in ['ARGB8888', 'XRGB8888']:\n-        rgb = data.reshape((h, w, 4))\n-        rgb = np.flip(rgb, axis=2)\n-        # drop alpha component\n-        rgb = np.delete(rgb, np.s_[0::4], axis=2)\n-\n-    elif fmt.startswith('S'):\n-        bayer_pattern = fmt[1:5]\n-        bitspp = int(fmt[5:])\n-\n-        # TODO: shifting leaves the lowest bits 0\n-        if bitspp == 8:\n-            data = data.reshape((h, w))\n-            data = data.astype(np.uint16) << 8\n-        elif bitspp in [10, 12]:\n-            data = data.view(np.uint16)\n-            data = data.reshape((h, w))\n-            data = data << (16 - bitspp)\n-        else:\n-            raise Exception('Bad bitspp:' + str(bitspp))\n-\n-        idx = bayer_pattern.find('R')\n-        assert(idx != -1)\n-        r0 = (idx % 2, idx // 2)\n-\n-        idx = bayer_pattern.find('G')\n-        assert(idx != -1)\n-        g0 = (idx % 2, idx // 2)\n-\n-        idx = bayer_pattern.find('G', idx + 1)\n-        assert(idx != -1)\n-        g1 = (idx % 2, idx // 2)\n-\n-        idx = bayer_pattern.find('B')\n-        assert(idx != -1)\n-        b0 = (idx % 2, idx // 2)\n-\n-        rgb = separate_components(data, r0, g0, g1, b0)\n-        rgb = demosaic(rgb, r0, g0, g1, b0)\n-        rgb = (rgb >> 8).astype(np.uint8)\n-\n-    else:\n-        rgb = None\n-\n-    return rgb\n-\n-\n class QtRenderer:\n     def __init__(self, state):\n         self.state = state\n@@ -334,8 +144,7 @@ class MainWindow(QtWidgets.QWidget):\n                 qim = ImageQt(img).copy()\n                 pix = QtGui.QPixmap.fromImage(qim)\n             else:\n-                data = np.array(mfb.planes[0], dtype=np.uint8)\n-                rgb = to_rgb(cfg.pixel_format, cfg.size, data)\n+                rgb = camutils.mfb_to_rgb(mfb, cfg)\n \n                 if rgb is None:\n                     raise Exception('Format not supported: ' + cfg.pixel_format)\ndiff --git a/src/py/libcamera/meson.build b/src/py/libcamera/meson.build\nindex fbd33139..af8ba6a5 100644\n--- a/src/py/libcamera/meson.build\n+++ b/src/py/libcamera/meson.build\n@@ -54,10 +54,16 @@ pycamera = shared_module('_libcamera',\n                          dependencies : pycamera_deps,\n                          cpp_args : pycamera_args)\n \n+# Generate symlinks so that we can use the module from the build dir\n+\n run_command('ln', '-fsT', '../../../../src/py/libcamera/__init__.py',\n             meson.current_build_dir() / '__init__.py',\n             check: true)\n \n+run_command('ln', '-fsT', '../../../../src/py/libcamera/utils',\n+            meson.current_build_dir() / 'utils',\n+            check: true)\n+\n install_data(['__init__.py'], install_dir : destdir)\n \n # \\todo Generate stubs when building, and install them.\ndiff --git a/src/py/libcamera/utils/__init__.py b/src/py/libcamera/utils/__init__.py\nnew file mode 100644\nindex 00000000..5fa884ca\n--- /dev/null\n+++ b/src/py/libcamera/utils/__init__.py\n@@ -0,0 +1,4 @@\n+# SPDX-License-Identifier: GPL-2.0-or-later\n+# Copyright (C) 2022, Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>\n+\n+from .conv import *\ndiff --git a/src/py/cam/cam_qt.py b/src/py/libcamera/utils/conv.py\nsimilarity index 58%\ncopy from src/py/cam/cam_qt.py\ncopy to src/py/libcamera/utils/conv.py\nindex 5753f0b2..71270671 100644\n--- a/src/py/cam/cam_qt.py\n+++ b/src/py/libcamera/utils/conv.py\n@@ -3,20 +3,9 @@\n #\n # Debayering code from PiCamera documentation\n \n-from io import BytesIO\n+from libcamera import MappedFrameBuffer, StreamConfiguration\n from numpy.lib.stride_tricks import as_strided\n-from PIL import Image\n-from PIL.ImageQt import ImageQt\n-from PyQt5 import QtCore, QtGui, QtWidgets\n import numpy as np\n-import sys\n-\n-\n-def rgb_to_pix(rgb):\n-    img = Image.frombuffer('RGB', (rgb.shape[1], rgb.shape[0]), rgb)\n-    qim = ImageQt(img).copy()\n-    pix = QtGui.QPixmap.fromImage(qim)\n-    return pix\n \n \n def separate_components(data, r0, g0, g1, b0):\n@@ -205,150 +194,7 @@ def to_rgb(fmt, size, data):\n     return rgb\n \n \n-class QtRenderer:\n-    def __init__(self, state):\n-        self.state = state\n-\n-        self.cm = state['cm']\n-        self.contexts = state['contexts']\n-\n-    def setup(self):\n-        self.app = QtWidgets.QApplication([])\n-\n-        windows = []\n-\n-        for ctx in self.contexts:\n-            camera = ctx['camera']\n-\n-            for stream in ctx['streams']:\n-                fmt = stream.configuration.pixel_format\n-                size = stream.configuration.size\n-\n-                window = MainWindow(ctx, stream)\n-                window.setAttribute(QtCore.Qt.WA_ShowWithoutActivating)\n-                window.show()\n-                windows.append(window)\n-\n-        self.windows = windows\n-\n-    def run(self):\n-        camnotif = QtCore.QSocketNotifier(self.cm.efd, QtCore.QSocketNotifier.Read)\n-        camnotif.activated.connect(lambda x: self.readcam())\n-\n-        keynotif = QtCore.QSocketNotifier(sys.stdin.fileno(), QtCore.QSocketNotifier.Read)\n-        keynotif.activated.connect(lambda x: self.readkey())\n-\n-        print('Capturing...')\n-\n-        self.app.exec()\n-\n-        print('Exiting...')\n-\n-    def readcam(self):\n-        running = self.state['event_handler'](self.state)\n-\n-        if not running:\n-            self.app.quit()\n-\n-    def readkey(self):\n-        sys.stdin.readline()\n-        self.app.quit()\n-\n-    def request_handler(self, ctx, req):\n-        buffers = req.buffers\n-\n-        for stream, fb in buffers.items():\n-            wnd = next(wnd for wnd in self.windows if wnd.stream == stream)\n-\n-            wnd.handle_request(stream, fb)\n-\n-        self.state['request_prcessed'](ctx, req)\n-\n-    def cleanup(self):\n-        for w in self.windows:\n-            w.close()\n-\n-\n-class MainWindow(QtWidgets.QWidget):\n-    def __init__(self, ctx, stream):\n-        super().__init__()\n-\n-        self.ctx = ctx\n-        self.stream = stream\n-\n-        self.label = QtWidgets.QLabel()\n-\n-        windowLayout = QtWidgets.QHBoxLayout()\n-        self.setLayout(windowLayout)\n-\n-        windowLayout.addWidget(self.label)\n-\n-        controlsLayout = QtWidgets.QVBoxLayout()\n-        windowLayout.addLayout(controlsLayout)\n-\n-        windowLayout.addStretch()\n-\n-        group = QtWidgets.QGroupBox('Info')\n-        groupLayout = QtWidgets.QVBoxLayout()\n-        group.setLayout(groupLayout)\n-        controlsLayout.addWidget(group)\n-\n-        lab = QtWidgets.QLabel(ctx['id'])\n-        groupLayout.addWidget(lab)\n-\n-        self.frameLabel = QtWidgets.QLabel()\n-        groupLayout.addWidget(self.frameLabel)\n-\n-        group = QtWidgets.QGroupBox('Properties')\n-        groupLayout = QtWidgets.QVBoxLayout()\n-        group.setLayout(groupLayout)\n-        controlsLayout.addWidget(group)\n-\n-        camera = ctx['camera']\n-\n-        for k, v in camera.properties.items():\n-            lab = QtWidgets.QLabel()\n-            lab.setText(k + ' = ' + str(v))\n-            groupLayout.addWidget(lab)\n-\n-        group = QtWidgets.QGroupBox('Controls')\n-        groupLayout = QtWidgets.QVBoxLayout()\n-        group.setLayout(groupLayout)\n-        controlsLayout.addWidget(group)\n-\n-        for k, (min, max, default) in camera.controls.items():\n-            lab = QtWidgets.QLabel()\n-            lab.setText('{} = {}/{}/{}'.format(k, min, max, default))\n-            groupLayout.addWidget(lab)\n-\n-        controlsLayout.addStretch()\n-\n-    def buf_to_qpixmap(self, stream, fb):\n-        with fb.mmap() as mfb:\n-            cfg = stream.configuration\n-            w, h = cfg.size\n-            pitch = cfg.stride\n-\n-            if cfg.pixel_format == 'MJPEG':\n-                img = Image.open(BytesIO(mfb.planes[0]))\n-                qim = ImageQt(img).copy()\n-                pix = QtGui.QPixmap.fromImage(qim)\n-            else:\n-                data = np.array(mfb.planes[0], dtype=np.uint8)\n-                rgb = to_rgb(cfg.pixel_format, cfg.size, data)\n-\n-                if rgb is None:\n-                    raise Exception('Format not supported: ' + cfg.pixel_format)\n-\n-                pix = rgb_to_pix(rgb)\n-\n-        return pix\n-\n-    def handle_request(self, stream, fb):\n-        ctx = self.ctx\n-\n-        pix = self.buf_to_qpixmap(stream, fb)\n-        self.label.setPixmap(pix)\n-\n-        self.frameLabel.setText('Queued: {}\\nDone: {}\\nFps: {:.2f}'\n-                                .format(ctx['reqs-queued'], ctx['reqs-completed'], ctx['fps']))\n+def mfb_to_rgb(mfb:MappedFrameBuffer, cfg:StreamConfiguration):\n+    data = np.array(mfb.planes[0], dtype=np.uint8)\n+    rgb = to_rgb(cfg.pixel_format, cfg.size, data)\n+    return rgb\n",
    "prefixes": [
        "libcamera-devel",
        "08/14"
    ]
}