Patch Detail
Show a patch.
GET /api/patches/18382/?format=api
{ "id": 18382, "url": "https://patchwork.libcamera.org/api/patches/18382/?format=api", "web_url": "https://patchwork.libcamera.org/patch/18382/", "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": "<20230313072813.23430-1-tomi.valkeinen@ideasonboard.com>", "date": "2023-03-13T07:28:13", "name": "[libcamera-devel] py: cam: Fix demosaic overflow issue", "commit_ref": "b3cefd4c0e92d96c730410cff5ddb69b28d693fd", "pull_url": null, "state": "accepted", "archived": false, "hash": "e9bb5c18128f5fc2adad34154b3ecd540d0875b4", "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/18382/mbox/", "series": [ { "id": 3802, "url": "https://patchwork.libcamera.org/api/series/3802/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3802", "date": "2023-03-13T07:28:13", "name": "[libcamera-devel] py: cam: Fix demosaic overflow issue", "version": 1, "mbox": "https://patchwork.libcamera.org/series/3802/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/18382/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/18382/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 9DBB5BE080\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 13 Mar 2023 07:28:31 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D32B762709;\n\tMon, 13 Mar 2023 08:28:30 +0100 (CET)", "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 E9DE461ED5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 13 Mar 2023 08:28:29 +0100 (CET)", "from desky.lan (91-154-32-225.elisa-laajakaista.fi [91.154.32.225])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 57411563;\n\tMon, 13 Mar 2023 08:28:29 +0100 (CET)" ], "DKIM-Signature": [ "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1678692510;\n\tbh=aX7LJO80R3TYxYm9J7A2g+bXXr7TNP1FpDI9yH4BQhk=;\n\th=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post:\n\tList-Help:List-Subscribe:From:Reply-To:From;\n\tb=B2Gk5Ty2amqQK/+s74EstNgrV+j/mTDsBRhec0EjqYjmayWfCO3IFviKzcSprQ+z0\n\tbWSSbpQbIUTMB+xmwnMaDZsC70TWHcGwsNi+wrGZpEDcaMfSIhGa0CNJIxCUS2QW0R\n\tRKtH1Prc8lD99vQyOFKCtgUefpG5TkB5HOzAma0fH38iwOvZnF0XGxwRQoq1Bp6UDO\n\tT4lw5OKyRIRJSiwMD51aywGy1lOhzDlW5A7VWjhp8TC6wp9gSGY4NfHYLPbzlrKgw4\n\tTyQt4YRM6IMwkXJCixo7ldA7yS78OsL75uTgYHNiFXaILNRXB+4kB9/XBsxzbQpUWq\n\tGCP6YqOj1KWJQ==", "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1678692509;\n\tbh=aX7LJO80R3TYxYm9J7A2g+bXXr7TNP1FpDI9yH4BQhk=;\n\th=From:To:Cc:Subject:Date:From;\n\tb=sGz7Kmh0IMUEQSzkYS+u5Upc5cMxKCbARqmiyVS1CJ59OHuEVsTlqBm1xiGk7ITnM\n\t4nmAP1lkcfHQGE/5avJFj7Pm8CTWYUariiqGSxyyyu4c/MEjgoND5YrGCJXY7c7TPh\n\tRyVrnUqxa/Ed+nteI8Tc8870x2EbrIMKlgalUkXo=" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"sGz7Kmh0\"; dkim-atps=neutral", "To": "libcamera-devel@lists.libcamera.org", "Date": "Mon, 13 Mar 2023 09:28:13 +0200", "Message-Id": "<20230313072813.23430-1-tomi.valkeinen@ideasonboard.com>", "X-Mailer": "git-send-email 2.34.1", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH] py: cam: Fix demosaic overflow issue", "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": "The demosaic code first expands the buffer datatype to uint16, and then\nshifts the data left so that the 8, 10 and 12 bitspp formats all become\n16 bitspp.\n\nIt then, eventually, uses np.einsum to calculate averages, but this\naveraging sums multiple uint16 values together, and stores them in\nuint16 storage. As in the first step we shifted the values left,\npossibly getting values close to the maximum of uint16 range, we, of\ncourse, overflow when summing them together. This leads to rather bad\nlooking images.\n\nFix this by dropping the original shift. It serves no purpose, and is\nprobably a remnant of some early testing code. This way the largest\nnumbers we are summing together are 12 bit values, and as we use a 3x3\nwindow from which we fetch values, for a single rgb plane, the max\nnumber of 12 bit values is 5 (for green). Sum of 5 12 bit values is well\nbelow the 16 bit maximum.\n\nSigned-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>\n---\n src/py/cam/helpers.py | 6 ++----\n 1 file changed, 2 insertions(+), 4 deletions(-)", "diff": "diff --git a/src/py/cam/helpers.py b/src/py/cam/helpers.py\nindex 6b32a134..2d906667 100644\n--- a/src/py/cam/helpers.py\n+++ b/src/py/cam/helpers.py\n@@ -117,14 +117,12 @@ 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 if bitspp == 8:\n data = data.reshape((h, w))\n- data = data.astype(np.uint16) << 8\n+ data = data.astype(np.uint16)\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@@ -145,7 +143,7 @@ def to_rgb(fmt, size, data):\n b0 = (idx % 2, idx // 2)\n \n rgb = demosaic(data, r0, g0, g1, b0)\n- rgb = (rgb >> 8).astype(np.uint8)\n+ rgb = (rgb >> (bitspp - 8)).astype(np.uint8)\n \n else:\n rgb = None\n", "prefixes": [ "libcamera-devel" ] }