From patchwork Fri Jun 14 11:40:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 20321 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 8C597BD87C for ; Fri, 14 Jun 2024 11:40:31 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E944765491; Fri, 14 Jun 2024 13:40:28 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="MDpkOGPh"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5511465461 for ; Fri, 14 Jun 2024 13:40:27 +0200 (CEST) Received: from neptunite.hamster-moth.ts.net (h175-177-049-156.catv02.itscom.jp [175.177.49.156]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 9A306397; Fri, 14 Jun 2024 13:40:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1718365212; bh=qTalvP1c38DjhyBGH9AGwHx+vIoJu7MvpD06BBa/+VQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MDpkOGPhmPC4YELHEc343yQsL58U5vMcc/lNfpQgdMZtr80E2zX/AgzXEMTgEM1NP v8w0qpqq4zmYQJLCopOs6xvw6YOhBYj6KXm+K8NcvBO34RLuiq41Q+KufIplbjdcWK Zhr9/l/EqtRrLG+FJp0wFtk6vzEO/0kAtpMy206Y= From: Paul Elder To: libcamera-devel@lists.libcamera.org Cc: Paul Elder , Stefan Klug Subject: [PATCH v4 1/2] utils: libtuning: modules: Add skeletal AGC module Date: Fri, 14 Jun 2024 20:40:15 +0900 Message-Id: <20240614114016.116620-2-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240614114016.116620-1-paul.elder@ideasonboard.com> References: <20240614114016.116620-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 AGC module just so that we can have some AGC tuning values that we can use to test during development of AGC 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. Signed-off-by: Paul Elder Reviewed-by: Stefan Klug Reviewed-by: Kieran Bingham --- Changes in v4: - remove support for both v10 and v12, and only support v10 - remove piecewise linear function luminance targets Changes in v3: - remove unused compatible string - make gain start from 2 in the exposure modes Changes in v2: - remove unneccessary imports - add support for both v10 and v12 --- .../tuning/libtuning/modules/agc/__init__.py | 6 ++ utils/tuning/libtuning/modules/agc/agc.py | 21 +++++ utils/tuning/libtuning/modules/agc/rkisp1.py | 79 +++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 utils/tuning/libtuning/modules/agc/__init__.py create mode 100644 utils/tuning/libtuning/modules/agc/agc.py create mode 100644 utils/tuning/libtuning/modules/agc/rkisp1.py diff --git a/utils/tuning/libtuning/modules/agc/__init__.py b/utils/tuning/libtuning/modules/agc/__init__.py new file mode 100644 index 000000000000..4db9ca371c68 --- /dev/null +++ b/utils/tuning/libtuning/modules/agc/__init__.py @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Copyright (C) 2024, Paul Elder + +from libtuning.modules.agc.agc import AGC +from libtuning.modules.agc.rkisp1 import AGCRkISP1 diff --git a/utils/tuning/libtuning/modules/agc/agc.py b/utils/tuning/libtuning/modules/agc/agc.py new file mode 100644 index 000000000000..9c8899badc79 --- /dev/null +++ b/utils/tuning/libtuning/modules/agc/agc.py @@ -0,0 +1,21 @@ +# 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 + + +class AGC(Module): + type = 'agc' + hr_name = 'AGC (Base)' + out_name = 'GenericAGC' + + # \todo Add sector shapes and stuff just like lsc + def __init__(self, *, + debug: list): + super().__init__() + + self.debug = debug diff --git a/utils/tuning/libtuning/modules/agc/rkisp1.py b/utils/tuning/libtuning/modules/agc/rkisp1.py new file mode 100644 index 000000000000..babb441a8300 --- /dev/null +++ b/utils/tuning/libtuning/modules/agc/rkisp1.py @@ -0,0 +1,79 @@ +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (C) 2019, Raspberry Pi Ltd +# Copyright (C) 2024, Paul Elder +# +# rkisp1.py - AGC module for tuning rkisp1 + +from .agc import AGC + +import libtuning as lt + + +class AGCRkISP1(AGC): + hr_name = 'AGC (RkISP1)' + out_name = 'Agc' + + 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 _generate_metering_modes(self) -> dict: + centre_weighted = [ + 0, 0, 0, 0, 0, + 0, 6, 8, 6, 0, + 0, 8, 16, 8, 0, + 0, 6, 8, 6, 0, + 0, 0, 0, 0, 0 + ] + + spot = [ + 0, 0, 0, 0, 0, + 0, 2, 4, 2, 0, + 0, 4, 16, 4, 0, + 0, 2, 4, 2, 0, + 0, 0, 0, 0, 0 + ] + + matrix = [1 for i in range(0, 25)] + + return { + 'MeteringCentreWeighted': centre_weighted, + 'MeteringSpot': spot, + 'MeteringMatrix': matrix + } + + def _generate_exposure_modes(self) -> dict: + normal = { 'shutter': [100, 10000, 30000, 60000, 120000], + 'gain': [2.0, 4.0, 6.0, 6.0, 6.0]} + short = { 'shutter': [100, 5000, 10000, 20000, 120000], + 'gain': [2.0, 4.0, 6.0, 6.0, 6.0]} + + return { 'ExposureNormal': normal, 'ExposureShort': short } + + def _generate_constraint_modes(self) -> dict: + normal = { 'lower': { 'qLo': 0.98, 'qHi': 1.0, 'yTarget': 0.5 } } + highlight = { + 'lower': { 'qLo': 0.98, 'qHi': 1.0, 'yTarget': 0.5 }, + 'upper': { 'qLo': 0.98, 'qHi': 1.0, 'yTarget': 0.8 } + } + + return { 'ConstraintNormal': normal, 'ConstraintHighlight': highlight } + + def _generate_y_target(self) -> list: + return 0.16 + + def process(self, config: dict, images: list, outputs: dict) -> dict: + output = {} + + output['AeMeteringMode'] = self._generate_metering_modes() + output['AeExposureMode'] = self._generate_exposure_modes() + output['AeConstraintMode'] = self._generate_constraint_modes() + output['relativeLuminanceTarget'] = self._generate_y_target() + + # \todo Debug functionality + + return output From patchwork Fri Jun 14 11:40:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 20322 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 87888C3293 for ; Fri, 14 Jun 2024 11:40:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0011565498; Fri, 14 Jun 2024 13:40:31 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="HKG2QyBU"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CA6D765494 for ; Fri, 14 Jun 2024 13:40:29 +0200 (CEST) Received: from neptunite.hamster-moth.ts.net (h175-177-049-156.catv02.itscom.jp [175.177.49.156]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 4F8A8397; Fri, 14 Jun 2024 13:40:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1718365214; bh=XpSkAmVVRFeeo1bF6gk1/p/zqihXvojPeDcevIgTNjk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HKG2QyBUgNxnV/ltEM12JAlFvEMVsXO5tEFML8MtZDlmE1usHGej71eKSGEULDkRU I92YX/59kVJgRfv1wl6kf7o8KdGBYZ82UQi9F8eHJs2YYX7rDbtmr2Wsl5rXWNboJ3 qmg0P+7r+ofvVnBThdSzXmTqsVh9mXm3wJFcmV+U= From: Paul Elder To: libcamera-devel@lists.libcamera.org Cc: Paul Elder , Stefan Klug , Daniel Scally Subject: [PATCH v4 2/2] utils: tuning: rkisp1: Add skeletal AGC to the rkisp1 tuning script Date: Fri, 14 Jun 2024 20:40:16 +0900 Message-Id: <20240614114016.116620-3-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240614114016.116620-1-paul.elder@ideasonboard.com> References: <20240614114016.116620-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 the skeletal AGC module to the rkisp1 tuning script. For now it just spits out hardcoded values. Signed-off-by: Paul Elder Reviewed-by: Stefan Klug Reviewed-by: Daniel Scally --- No change in v4 No change in v3 Changes in v2: - remove hw_rev parameter from the rkisp1 agc tuning module, as the tuning file should support both hardware revisions simultaneously --- utils/tuning/rkisp1.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/utils/tuning/rkisp1.py b/utils/tuning/rkisp1.py index 517c791e6ffa..d0ce15d5ed7a 100755 --- a/utils/tuning/rkisp1.py +++ b/utils/tuning/rkisp1.py @@ -11,6 +11,7 @@ import libtuning as lt from libtuning.parsers import YamlParser from libtuning.generators import YamlOutput from libtuning.modules.lsc import LSCRkISP1 +from libtuning.modules.agc import AGCRkISP1 tuner = lt.Tuner('RkISP1') tuner.add(LSCRkISP1( @@ -32,9 +33,10 @@ tuner.add(LSCRkISP1( # values. This can also be a custom function. smoothing_function=lt.smoothing.MedianBlur(3), )) +tuner.add(AGCRkISP1(debug=[lt.Debug.Plot])) tuner.set_input_parser(YamlParser()) tuner.set_output_formatter(YamlOutput()) -tuner.set_output_order([LSCRkISP1]) +tuner.set_output_order([AGCRkISP1, LSCRkISP1]) if __name__ == '__main__': sys.exit(tuner.run(sys.argv))