From patchwork Wed Jul 27 02:38:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16823 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 E4409C3275 for ; Wed, 27 Jul 2022 02:38:37 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A149263338; Wed, 27 Jul 2022 04:38:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1658889517; bh=cZ8ZW3TILG8iG0Q7OpVXjjnpdnp8LxUDS3KQLfUofXA=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=lrzinnu7OnH7mI9D9vN6azatlTjTfNu5FdT3l1LDGPfmGND+le+/tdnvD2rWizjV5 gWyJDG/Rfa9m6oBmUyvaWqTCSpVJSI3g01P6adYZ6mTQAmX77G2eiUp1fg1rhehhPZ g8uOczsCy4wwjhLtIgpZM8hlJBuHg0oUVQmEzOLbYsC7726KfWdUl2tf9EAqrnKzcp OPfVis+sN+MUGQjo5uH7lY/anX1ls4TkiHwklsiV3j4P9gaI+Tw1Pg2jAjcOtvcb2f 2STH6XKSR50WgVyaGNwKmsuk8if2nGF5EZp8TWatDMkVil4be+NSPKI18PdskOq41r Rf+t/okE5s7jA== 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 0BC5C63316 for ; Wed, 27 Jul 2022 04:38:31 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="lOku6J9Y"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 9A8BB56D; Wed, 27 Jul 2022 04:38:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1658889510; bh=cZ8ZW3TILG8iG0Q7OpVXjjnpdnp8LxUDS3KQLfUofXA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lOku6J9YfCugly9Gn73vA5dpUvtAfQg4CM9kD1yMebJO9SM+tuH7s4SkIL5V1oKJR 3C0mtSRuwNCBNSjKvZyff8VC+Qjk+kkmW7hSHnZzlDq6XSz/prmbcjE2Dl7xgvNmXt vSRn/zrye4Ut8brKM7vU3vjWT8B2NdrkJPzPwgQk= To: libcamera-devel@lists.libcamera.org Date: Wed, 27 Jul 2022 05:38:13 +0300 Message-Id: <20220727023816.30008-12-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220727023816.30008-1-laurent.pinchart@ideasonboard.com> References: <20220727023816.30008-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v7 11/14] utils: raspberrypi: Add tuning file conversion script 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: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Naushir Patuck Add a script to convert the Raspberry Pi camera tuning file format from version 1.0 to 2.0. This script also adds a root level version key set to 2.0 to the config file, allowing the controller to distinguish between the two formats. Signed-off-by: Naushir Patuck Reviewed-by: Laurent Pinchart Signed-off-by: Laurent Pinchart --- utils/raspberrypi/ctt/convert_tuning.py | 46 +++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 utils/raspberrypi/ctt/convert_tuning.py diff --git a/utils/raspberrypi/ctt/convert_tuning.py b/utils/raspberrypi/ctt/convert_tuning.py new file mode 100755 index 000000000000..a84dfa83b3b6 --- /dev/null +++ b/utils/raspberrypi/ctt/convert_tuning.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python3 +# +# SPDX-License-Identifier: BSD-2-Clause +# +# Script to convert version 1.0 Raspberry Pi camera tuning files to version 2.0. +# +# Copyright 2022 Raspberry Pi Ltd. + +import argparse +import json +import sys + +from ctt_pretty_print_json import pretty_print + + +def convert_v2(in_json: dict) -> str: + + if 'version' in in_json.keys() and in_json['version'] != 1.0: + print(f'The JSON config reports version {in_json["version"]} that is incompatible with this tool.') + sys.exit(-1) + + converted = { + 'version': 2.0, + 'target': 'bcm2835', + 'algorithms': [{algo: config} for algo, config in in_json.items()] + } + + return pretty_print(converted) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter, description= + 'Convert the format of the Raspberry Pi camera tuning file from v1.0 to v2.0.\n') + parser.add_argument('input', type=str, help='Input tuning file.') + parser.add_argument('output', type=str, nargs='?', + help='Output converted tuning file. If not provided, the input file will be updated in-place.', + default=None) + args = parser.parse_args() + + with open(args.input, 'r') as f: + in_json = json.load(f) + + out_json = convert_v2(in_json) + + with open(args.output if args.output is not None else args.input, 'w') as f: + f.write(out_json)