From patchwork Fri Jun 28 10:47:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 20483 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 82065BD87C for ; Fri, 28 Jun 2024 10:49:48 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4AE156336C; Fri, 28 Jun 2024 12:49:48 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="gwlGGlG4"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2F8BB63364 for ; Fri, 28 Jun 2024 12:49:47 +0200 (CEST) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:82ab:924:d918:cd24]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id A7D4E735; Fri, 28 Jun 2024 12:49:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1719571762; bh=OZynHxtHvtOP2y6/P4KUZDzQfRdZp4JFW6FPmMmpwZA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gwlGGlG4F3pgI0R7+nruzmnUah+2v6pP9GWw4tfx2kRsYnzWuYcrMF/rj3GlOknqZ J6tDO0+topLDIUDflucwsWIFdmC5QyYaToQqj4ykJw2tgIoC+19gc5wc+bsj2o8a+K sStHLcCbNzBoN9IbyrMcm3mXXsA4JaLDwohY/XkM= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug Subject: [PATCH v2 24/25] tuning: rkisp1: Add blc module Date: Fri, 28 Jun 2024 12:47:17 +0200 Message-ID: <20240628104828.2928109-25-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240628104828.2928109-1-stefan.klug@ideasonboard.com> References: <20240628104828.2928109-1-stefan.klug@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" This module simple copies the values from the tuning images into the tuning file. Signed-off-by: Stefan Klug --- .../tuning/libtuning/modules/blc/__init__.py | 5 ++ utils/tuning/libtuning/modules/blc/blc.py | 46 +++++++++++++++++++ utils/tuning/rkisp1.py | 4 +- 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 utils/tuning/libtuning/modules/blc/__init__.py create mode 100644 utils/tuning/libtuning/modules/blc/blc.py diff --git a/utils/tuning/libtuning/modules/blc/__init__.py b/utils/tuning/libtuning/modules/blc/__init__.py new file mode 100644 index 000000000000..33d4936e4cfd --- /dev/null +++ b/utils/tuning/libtuning/modules/blc/__init__.py @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Copyright (C) 2024, Ideas on Board Oy + +from .blc import BLC diff --git a/utils/tuning/libtuning/modules/blc/blc.py b/utils/tuning/libtuning/modules/blc/blc.py new file mode 100644 index 000000000000..8cfb80e53143 --- /dev/null +++ b/utils/tuning/libtuning/modules/blc/blc.py @@ -0,0 +1,46 @@ +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (C) 2024, Ideas on Board Oy + +from ..module import Module +import logging + +logger = logging.getLogger(__name__) + + +class BLC(Module): + type = 'blc' + hr_name = 'BLC (Base)' + out_name = 'BlackLevelCorrection' + + def __init__(self, debug: list): + super().__init__() + + self.debug = debug + + def validate_config(self, config: dict) -> bool: + return True + + def process(self, config: dict, images: list, outputs: dict) -> dict: + output = {} + + blacklevel = None + + for img in images: + if blacklevel is None: + if img.blacklevel_16 > 0: + blacklevel = img.blacklevel_16 + else: + if img.blacklevel_16 > 0 and img.blacklevel_16 != blacklevel: + logger.warnung(f"Blacklevels differ {blacklevel} {img.blacklevel_16}") + + if blacklevel: + output['R'] = blacklevel + output['Gr'] = blacklevel + output['Gb'] = blacklevel + output['B'] = blacklevel + output['referenceBitwidth'] = 16 + return output + + logger.warning("No valid blacklevel found. Skipping blc") + return None diff --git a/utils/tuning/rkisp1.py b/utils/tuning/rkisp1.py index c5036c65557b..7cf3f2f9fbf1 100755 --- a/utils/tuning/rkisp1.py +++ b/utils/tuning/rkisp1.py @@ -14,6 +14,7 @@ from libtuning.parsers import YamlParser from libtuning.generators import YamlOutput from libtuning.modules.lsc import LSCRkISP1 from libtuning.modules.agc import AGCRkISP1 +from libtuning.modules.blc import BLC from libtuning.modules.ccm import CCMRkISP1 from libtuning.modules.static import StaticModule @@ -27,6 +28,7 @@ gamma_out = StaticModule('GammaOutCorrection', {'gamma': 2.2}) tuner = lt.Tuner('RkISP1') tuner.add(AGCRkISP1(debug=[lt.Debug.Plot])) tuner.add(awb) +tuner.add(BLC(debug=[lt.Debug.Plot])) tuner.add(CCMRkISP1(debug=[lt.Debug.Plot])) tuner.add(color_processing) tuner.add(filter) @@ -53,7 +55,7 @@ tuner.add(LSCRkISP1( tuner.set_input_parser(YamlParser()) tuner.set_output_formatter(YamlOutput()) -tuner.set_output_order([AGCRkISP1, awb, CCMRkISP1, color_processing, filter, gamma_out, LSCRkISP1]) +tuner.set_output_order([AGCRkISP1, awb, BLC, CCMRkISP1, color_processing, filter, gamma_out, LSCRkISP1]) if __name__ == '__main__': sys.exit(tuner.run(sys.argv))