Patch Detail
Show a patch.
GET /api/patches/15961/?format=api
{ "id": 15961, "url": "https://patchwork.libcamera.org/api/patches/15961/?format=api", "web_url": "https://patchwork.libcamera.org/patch/15961/", "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-12-tomi.valkeinen@ideasonboard.com>", "date": "2022-05-18T13:13:22", "name": "[libcamera-devel,v3,11/18] py: cam_qt: cosmetic cleanups", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "f8d4915c89ce6ff02e3356269dd80b3e0739556f", "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/15961/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/15961/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/15961/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 79B70C3272\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 18 May 2022 13:14:06 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E7DA165678;\n\tWed, 18 May 2022 15:14:05 +0200 (CEST)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 00B1E6566D\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 726D71027;\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=el4gJmeSP+tx4hhxqvl52vgOFMAHhzI5MxrWGRX1n1M=;\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=gXYO9UfAjT61PfJMn2/FFrHoG2vonv2Pw+ZEZ6caOChdJDJRuZthK2B+/+zzfMCuZ\n\tFuGO3Tfhsqc1N08xCqY0OrCOE5tclytj7fp93YluQ2ZUkvOacpjUYcRQjkgZP5n1uV\n\thex5UOANGbx9IM3YZ3Yn329OLhMORhO6fVZ2gIEo+NU+H8j4p6u/+ysTxiXH8x4Fco\n\tgE1RdF6smTF2UTDJ8NBoWabwRxTBsyDBWX8c7fxcxVYbEzOci4wH8VYF6EAeNOPEiO\n\tGr/ECtw39OJXeRRqd8emOLT5SuNDIrSixql4R69fVr8jaum+acqdU/scmkY4iCyRJD\n\toHOtofOcpS9mA==", "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1652879631;\n\tbh=el4gJmeSP+tx4hhxqvl52vgOFMAHhzI5MxrWGRX1n1M=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=ZL/FTaAyzF/EA+2QMlIYfISp/xXPS3azC3AT1kdhY1i9LAOuagmNSHsePGW6jFCG+\n\t217TtLQMJgHVVT7j37ADCkCbaTsOkQsOjQ8x5TG+jWY/szqQSPQb77if/F4RZDGWIu\n\tyUtE9Ej/K5UKRrV1eimjEZKRvSPVn3zrejxMF6cs=" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"ZL/FTaAy\"; 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:22 +0300", "Message-Id": "<20220518131329.66994-12-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 11/18] py: cam_qt: cosmetic cleanups", "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": "Drop irrelevant or wrong comments, merge separate_components() into\ndemosaic(), and add mfb_to_rgb().\n\nNo functional changes.\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_qt.py | 64 +++++++++-----------------------------------\n 1 file changed, 13 insertions(+), 51 deletions(-)", "diff": "diff --git a/src/py/cam/cam_qt.py b/src/py/cam/cam_qt.py\nindex 5753f0b2..fb485b9b 100644\n--- a/src/py/cam/cam_qt.py\n+++ b/src/py/cam/cam_qt.py\n@@ -19,19 +19,8 @@ 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+def demosaic(data, r0, g0, g1, b0):\n+ # Separate the components from the Bayer data to RGB planes\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@@ -39,17 +28,9 @@ def separate_components(data, r0, g0, g1, b0):\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+ # surrounding it. The weighting is provided by a byte representation of\n # the Bayer filter which we construct first:\n \n bayer = np.zeros(rgb.shape, dtype=np.uint8)\n@@ -69,29 +50,6 @@ def demosaic(rgb, r0, g0, g1, b0):\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@@ -168,7 +126,7 @@ def to_rgb(fmt, size, data):\n bayer_pattern = fmt[1:5]\n bitspp = int(fmt[5:])\n \n- # TODO: shifting leaves the lowest bits 0\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@@ -195,8 +153,7 @@ def to_rgb(fmt, size, data):\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 = demosaic(data, r0, g0, g1, b0)\n rgb = (rgb >> 8).astype(np.uint8)\n \n else:\n@@ -205,6 +162,13 @@ def to_rgb(fmt, size, data):\n return rgb\n \n \n+# A naive format conversion to 24-bit RGB\n+def mfb_to_rgb(mfb, cfg):\n+ data = np.array(mfb.planes[0], dtype=np.uint8)\n+ rgb = to_rgb(cfg.pixel_format, cfg.size, data)\n+ return rgb\n+\n+\n class QtRenderer:\n def __init__(self, state):\n self.state = state\n@@ -334,9 +298,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-\n+ rgb = mfb_to_rgb(mfb, cfg)\n if rgb is None:\n raise Exception('Format not supported: ' + cfg.pixel_format)\n \n", "prefixes": [ "libcamera-devel", "v3", "11/18" ] }