From patchwork Fri Apr 5 14:53:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 19859 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 54FC2C32C9 for ; Fri, 5 Apr 2024 14:53:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 629CB63367; Fri, 5 Apr 2024 16:53:56 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="nc6rmt/l"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5BCD763360 for ; Fri, 5 Apr 2024 16:53:52 +0200 (CEST) Received: from pyrite.hamster-moth.ts.net (h175-177-049-156.catv02.itscom.jp [175.177.49.156]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 9A1EAC8A; Fri, 5 Apr 2024 16:53:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1712328793; bh=WlEblNyqFiTKnAv2U4pHvcqgYkOcud2LwqO0qLrNoRc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nc6rmt/lna9MoSNlZH8evaP6vy8PMGRNm+ZhwuN+blWyDSbmUzMELc6eP7Ug+T99W PTJYZ/lakqTiqlKmBMx5F19sfA1Z+w8u8Yua3eYUrwhae03K8Jte352sYi6EMymTkV Jeko33TTnYH57F8JsvRNrXEcS9Nh+1ynTpJO0Nm0= From: Paul Elder To: libcamera-devel@lists.libcamera.org Cc: Paul Elder Subject: [PATCH 3/5] utils: libtuning: modules: Add skeletal CCM module Date: Fri, 5 Apr 2024 23:53:33 +0900 Message-Id: <20240405145335.3010479-4-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240405145335.3010479-1-paul.elder@ideasonboard.com> References: <20240405145335.3010479-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a skeletal CCM module just so that we can have some CCM tuning values that we can use to test during development of CCM in the IPAs. As rkisp1 is the main target, we only add support for rkisp1 for now. The parameters are mostly copied from the hardcoded values in ctt, except for the metering modes. As CCM is called CTK (for crosstalk) in rkisp1, that is the name that will be used for rkisp1. Signed-off-by: Paul Elder --- .../tuning/libtuning/modules/ccm/__init__.py | 6 ++ utils/tuning/libtuning/modules/ccm/ccm.py | 22 ++++++ utils/tuning/libtuning/modules/ccm/rkisp1.py | 75 +++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 utils/tuning/libtuning/modules/ccm/__init__.py create mode 100644 utils/tuning/libtuning/modules/ccm/ccm.py create mode 100644 utils/tuning/libtuning/modules/ccm/rkisp1.py diff --git a/utils/tuning/libtuning/modules/ccm/__init__.py b/utils/tuning/libtuning/modules/ccm/__init__.py new file mode 100644 index 00000000..a06c356c --- /dev/null +++ b/utils/tuning/libtuning/modules/ccm/__init__.py @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Copyright (C) 2024, Paul Elder + +from libtuning.modules.ccm.ccm import CCM +from libtuning.modules.ccm.rkisp1 import CTKRkISP1 diff --git a/utils/tuning/libtuning/modules/ccm/ccm.py b/utils/tuning/libtuning/modules/ccm/ccm.py new file mode 100644 index 00000000..7ddf0a8c --- /dev/null +++ b/utils/tuning/libtuning/modules/ccm/ccm.py @@ -0,0 +1,22 @@ +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (C) 2019, Raspberry Pi Ltd +# Copyright (C) 2024, Paul Elder + +from ..module import Module + +import libtuning as lt +import libtuning.utils as utils + +import numpy as np + +class CCM(Module): + type = 'ccm' + hr_name = 'CCM (Base)' + out_name = 'GenericCCM' + + def __init__(self, *, + debug: list): + super().__init__() + + self.debug = debug diff --git a/utils/tuning/libtuning/modules/ccm/rkisp1.py b/utils/tuning/libtuning/modules/ccm/rkisp1.py new file mode 100644 index 00000000..5a6caea8 --- /dev/null +++ b/utils/tuning/libtuning/modules/ccm/rkisp1.py @@ -0,0 +1,75 @@ +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (C) 2019, Raspberry Pi Ltd +# Copyright (C) 2024, Paul Elder +# +# rkisp1.py - Ctk module for tuning rkisp1 + +from .ccm import CCM + +import libtuning as lt +import libtuning.utils as utils + +from numbers import Number +import numpy as np + +class CTKRkISP1(CCM): + hr_name = 'Crosstalk Correction (RkISP1)' + out_name = 'Ctk' + # \todo Not sure if this is useful. Probably will remove later. + compatible = ['rkisp1'] + + def __init__(self, **kwargs): + super().__init__(**kwargs) + + # We don't actually need anything from the config file + def validate_config(self, config: dict) -> bool: + return True + + def _float_to_fixed_4_7(self, d): + mask = 0xf + whole = int(d) & mask + + fractional = d % 1 + frac = 0 + for i in range(0, 7): + fractional *= 2 + frac <<= 1 + frac |= int(fractional) & 0x1 + + return (whole << 7) | frac + + def _generate_ctms(self) -> dict: + ctms = { + '2860': [ 2.12089, -0.52461, -0.59629, + -0.85342, 2.80445, -0.95103, + -0.26897, -1.14788, 2.41685 ], + '2960': [ 2.26962, -0.54174, -0.72789, + -0.77008, 2.60271, -0.83262, + -0.26036, -1.51254, 2.77289 ], + '3603': [ 2.18644, -0.66148, -0.52496, + -0.77828, 2.69474, -0.91645, + -0.25239, -0.83059, 2.08298 ], + '4650': [ 2.18174, -0.70887, -0.47287, + -0.70196, 2.76426, -1.06231, + -0.25157, -0.71978, 1.97135 ], + '5858': [ 2.32392, -0.88421, -0.43971, + -0.63821, 2.58348, -0.94527, + -0.28541, -0.54112, 1.82653 ], + '7580': [ 2.21175, -0.53242, -0.67933, + -0.57875, 3.07922, -1.50047, + -0.27709, -0.73338, 2.01048 ], + } + + ret = {} + for ct in ctms: + ret[ct] = [self._float_to_fixed_4_7(weight) for weight in ctms[ct]] + return ret + + def process(self, config: dict, images: list, outputs: dict) -> dict: + output = {} + + output['ctms'] = self._generate_ctms() + # \todo Debug functionality + + return output