From patchwork Mon Jul 18 08:16:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 16674 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 5DD41BD1F1 for ; Mon, 18 Jul 2022 08:16:16 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 209736331D; Mon, 18 Jul 2022 10:16:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1658132176; bh=IAXD9sHyO9ZNDqqutgWImcwfBQh84KpJJvIMaEvBlRk=; 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=D23VEfa0x4AArzg2CHUF1GZ+9cJW5R6vIBgkvkpbTw/DzuSkJlc6LLq7XLM6zIdFx bLnhA4XlrEZtunl5Zrgn83x5qRFUZ5cRo+y23wxo036MW5YSY9sVHFXd3pCUJm0/r3 YQOkccv/DmeAYtenAqULJxkh9MpbRJUORjCK02Pvp3Czqdgbz3cq6jAJKa+RuT7QR/ EWzsRavqNc2RyMQWZnyBQDvr/3tlAlF2gXmFQUYppfSu+HSGktgptirTn7MMRtXavm 2FEbKK8nzxaT769EboPQ/aL3BjC6jROzWk+ikZVUg61R4ITHN/xPPOHKWNrvRu6MmE N5X8BCMEkfwUA== Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 49B036331F for ; Mon, 18 Jul 2022 10:16:12 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="pNi2bBkk"; dkim-atps=neutral Received: by mail-wr1-x435.google.com with SMTP id r14so15920769wrg.1 for ; Mon, 18 Jul 2022 01:16:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4QC2vWlF9fBEbUJSEJBWZir/FMVn4k4Vc2vCGcsByeQ=; b=pNi2bBkkBJloaG+OuAhsFxWZju3PRw0N54pr/asAg2mrzxpUFwUZ/PpF2CQrPJ5YHq zl16a7GdD6XAJx9sxn1p2prrgP+YZfa0AIlC9AY9vgxy//rQCqmByKmZsPSepiVIZ7jT Iie+sFnZ/u70eixGyslvNMGx24jFtvqbKYrRztr/Z+G7tDjsPJw1cNq8E/tww33lyliQ cRA4l+ZBODsStJq2DlQt7GDVlgl+HMxTy5hHNw/y9Bp9g+eMn81fojyi/eZXQUsa+Zyz nyCntDpGCdbgd6K4QM8URSfl2Yu/r603t4cPjVwBXOCTZSblEXg/r4ce/WrWMI0Z1FXS mJZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4QC2vWlF9fBEbUJSEJBWZir/FMVn4k4Vc2vCGcsByeQ=; b=cU8TV0l2rqV5zcseC3Nn/mJwINKOcxD4019D6jFGs11NZg55cnX63T+lrUNhlgo87W 9H2R+ClVPdz38E/rfQYx0p+kvXNamCkihYprZ5QTMzYdSfmjeWp9kuSXWRsXcp2GWwkg d/r2J/cfCqv2DvdYPW1iVJwhYYsN6FdEnkAnJxLqf2TtnRmOPKhCopaWK1vMnDmAPDOa VvmSNGPx7yB48KMdN/rj0ggS+Wd2dqyKLLCbAP+pxJwE/rdjWCXN6ttXQ8detkIRBUaX nPORKYwU1BciIOoXl+Uz5RbEwG66NrQhRkdptKGUg8KqdXEBQt/KX+rQMSls3MwD3JbA 7r0w== X-Gm-Message-State: AJIora96DH2eYNuffhnpSOlMuvqsSrfueqyJGzgAaP+5EKe3C3l2aqhh NdFraX8nLcYACHxyrT8H2kNYHOx4kL210g== X-Google-Smtp-Source: AGRyM1shZ6eO/6v/MS/p3OZCekUt0D/OWXTlNN44IZh7SDzULE09B6g2d/rGhsI7tn1OheZBz+kzQw== X-Received: by 2002:a05:6000:1e04:b0:21d:7ec3:fe5a with SMTP id bj4-20020a0560001e0400b0021d7ec3fe5amr22153639wrb.116.1658132171504; Mon, 18 Jul 2022 01:16:11 -0700 (PDT) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id a15-20020adffb8f000000b0021dbac444a7sm10206795wrr.59.2022.07.18.01.16.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jul 2022 01:16:10 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Mon, 18 Jul 2022 09:16:01 +0100 Message-Id: <20220718081602.32535-8-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220718081602.32535-1-naush@raspberrypi.com> References: <20220718081602.32535-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 7/8] 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: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" 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 --- 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)