[{"id":29201,"web_url":"https://patchwork.libcamera.org/comment/29201/","msgid":"<20240412080217.xiqmnuzoqfq4mdk2@macbook-air.speedport.ip>","date":"2024-04-12T08:02:17","subject":"Re: [PATCH 3/5] utils: libtuning: modules: Add skeletal CCM module","submitter":{"id":184,"url":"https://patchwork.libcamera.org/api/people/184/","name":"Stefan Klug","email":"stefan.klug@ideasonboard.com"},"content":"Hi Paul,\n\nthanks fo the patch.\n\nOn Fri, Apr 05, 2024 at 11:53:33PM +0900, Paul Elder wrote:\n> Add a skeletal CCM module just so that we can have some CCM tuning\n> values that we can use to test during development of CCM in the IPAs. As\n> rkisp1 is the main target, we only add support for rkisp1 for now.\n> \n> The parameters are mostly copied from the hardcoded values in ctt,\n> except for the metering modes.\n> \n> As CCM is called CTK (for crosstalk) in rkisp1, that is the name that\n> will be used for rkisp1.\n> \n> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>\n> ---\n>  .../tuning/libtuning/modules/ccm/__init__.py  |  6 ++\n>  utils/tuning/libtuning/modules/ccm/ccm.py     | 22 ++++++\n>  utils/tuning/libtuning/modules/ccm/rkisp1.py  | 75 +++++++++++++++++++\n>  3 files changed, 103 insertions(+)\n>  create mode 100644 utils/tuning/libtuning/modules/ccm/__init__.py\n>  create mode 100644 utils/tuning/libtuning/modules/ccm/ccm.py\n>  create mode 100644 utils/tuning/libtuning/modules/ccm/rkisp1.py\n> \n> diff --git a/utils/tuning/libtuning/modules/ccm/__init__.py b/utils/tuning/libtuning/modules/ccm/__init__.py\n> new file mode 100644\n> index 00000000..a06c356c\n> --- /dev/null\n> +++ b/utils/tuning/libtuning/modules/ccm/__init__.py\n> @@ -0,0 +1,6 @@\n> +# SPDX-License-Identifier: GPL-2.0-or-later\n> +#\n> +# Copyright (C) 2024, Paul Elder <paul.elder@ideasonboard.com>\n> +\n> +from libtuning.modules.ccm.ccm import CCM\n> +from libtuning.modules.ccm.rkisp1 import CTKRkISP1\n> diff --git a/utils/tuning/libtuning/modules/ccm/ccm.py b/utils/tuning/libtuning/modules/ccm/ccm.py\n> new file mode 100644\n> index 00000000..7ddf0a8c\n> --- /dev/null\n> +++ b/utils/tuning/libtuning/modules/ccm/ccm.py\n> @@ -0,0 +1,22 @@\n> +# SPDX-License-Identifier: BSD-2-Clause\n> +#\n> +# Copyright (C) 2019, Raspberry Pi Ltd\n> +# Copyright (C) 2024, Paul Elder <paul.elder@ideasonboard.com>\n> +\n> +from ..module import Module\n> +\n> +import libtuning as lt\n> +import libtuning.utils as utils\n> +\n> +import numpy as np\n> +\n> +class CCM(Module):\n> +    type = 'ccm'\n> +    hr_name = 'CCM (Base)'\n> +    out_name = 'GenericCCM'\n> +\n> +    def __init__(self, *,\n> +                 debug: list):\n> +        super().__init__()\n> +\n> +        self.debug = debug\n> diff --git a/utils/tuning/libtuning/modules/ccm/rkisp1.py b/utils/tuning/libtuning/modules/ccm/rkisp1.py\n> new file mode 100644\n> index 00000000..5a6caea8\n> --- /dev/null\n> +++ b/utils/tuning/libtuning/modules/ccm/rkisp1.py\n> @@ -0,0 +1,75 @@\n> +# SPDX-License-Identifier: BSD-2-Clause\n> +#\n> +# Copyright (C) 2019, Raspberry Pi Ltd\n> +# Copyright (C) 2024, Paul Elder <paul.elder@ideasonboard.com>\n> +#\n> +# rkisp1.py - Ctk module for tuning rkisp1\n> +\n> +from .ccm import CCM\n> +\n> +import libtuning as lt\n> +import libtuning.utils as utils\n> +\n> +from numbers import Number\n> +import numpy as np\n> +\n> +class CTKRkISP1(CCM):\n> +    hr_name = 'Crosstalk Correction (RkISP1)'\n> +    out_name = 'Ctk'\n> +    # \\todo Not sure if this is useful. Probably will remove later.\n> +    compatible = ['rkisp1']\n> +\n> +    def __init__(self, **kwargs):\n> +        super().__init__(**kwargs)\n> +\n> +    # We don't actually need anything from the config file\n> +    def validate_config(self, config: dict) -> bool:\n> +        return True\n> +\n> +    def _float_to_fixed_4_7(self, d):\n> +        mask = 0xf\n> +        whole = int(d) & mask\n> +\n> +        fractional = d % 1\n> +        frac = 0\n> +        for i in range(0, 7):\n> +            fractional *= 2\n> +            frac <<= 1\n> +            frac |= int(fractional) & 0x1\n> +\n> +        return (whole << 7) | frac\n\nAs discussed this needs to be moved to the IPA\n\n> +\n> +    def _generate_ctms(self) -> dict:\n> +        ctms = {\n> +                '2860': [ 2.12089, -0.52461, -0.59629,\n> +                         -0.85342,  2.80445, -0.95103,\n> +                         -0.26897, -1.14788,  2.41685 ],\n> +                '2960': [ 2.26962, -0.54174, -0.72789,\n> +                         -0.77008,  2.60271, -0.83262,\n> +                         -0.26036, -1.51254,  2.77289 ],\n> +                '3603': [ 2.18644, -0.66148, -0.52496,\n> +                         -0.77828,  2.69474, -0.91645,\n> +                         -0.25239, -0.83059,  2.08298 ],\n> +                '4650': [ 2.18174, -0.70887, -0.47287,\n> +                         -0.70196,  2.76426, -1.06231,\n> +                         -0.25157, -0.71978,  1.97135 ],\n> +                '5858': [ 2.32392, -0.88421, -0.43971,\n> +                         -0.63821,  2.58348, -0.94527,\n> +                         -0.28541, -0.54112,  1.82653 ],\n> +                '7580': [ 2.21175, -0.53242, -0.67933,\n> +                         -0.57875,  3.07922, -1.50047,\n> +                         -0.27709, -0.73338,  2.01048 ],\n> +                }\n> +\n> +        ret = {}\n> +        for ct in ctms:\n> +            ret[ct] = [self._float_to_fixed_4_7(weight) for weight in ctms[ct]]\n> +        return ret\n> +\n> +    def process(self, config: dict, images: list, outputs: dict) -> dict:\n> +        output = {}\n> +\n> +        output['ctms'] = self._generate_ctms()\n\nWhat about the offset vector? Should we initialize it to 0 here? I\nmissed that on the libipa ctk patch. At least we should zero it out\nthere.\n\n> +        # \\todo Debug functionality\n> +\n> +        return output\n> -- \n> 2.39.2\n>","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 4B1FFC3213\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 12 Apr 2024 08:02:23 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D882A6335E;\n\tFri, 12 Apr 2024 10:02:21 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 829FA6333E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 12 Apr 2024 10:02:20 +0200 (CEST)","from ideasonboard.com\n\t(p200300e0774af4635726ec48835ba9d7.dip0.t-ipconnect.de\n\t[IPv6:2003:e0:774a:f463:5726:ec48:835b:a9d7])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id EE1F4A12;\n\tFri, 12 Apr 2024 10:01:36 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"vIrmb2wy\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1712908897;\n\tbh=L08iwc2mf3MKPDGApKcDzFc1/1NeelKZbBSuu6hZ3OA=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=vIrmb2wyG1BucDebiQsJ0QzU5VVcGV57poQpXbbwmo3Q5d3pRtXy4V7OqRN2TG49u\n\twVL43dgQdnlS5mc8Unvn6hj7ZWauyD88SX2oSuEBhZ7nIlMw9nxyEKZlawBFoGOE9s\n\tAzQyEYRx8Iz9Ns7ZHA9j0IjyRFVQmfSYLYE+xcBc=","Date":"Fri, 12 Apr 2024 10:02:17 +0200","From":"Stefan Klug <stefan.klug@ideasonboard.com>","To":"Paul Elder <paul.elder@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH 3/5] utils: libtuning: modules: Add skeletal CCM module","Message-ID":"<20240412080217.xiqmnuzoqfq4mdk2@macbook-air.speedport.ip>","References":"<20240405145335.3010479-1-paul.elder@ideasonboard.com>\n\t<20240405145335.3010479-4-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20240405145335.3010479-4-paul.elder@ideasonboard.com>","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]