summaryrefslogtreecommitdiff
path: root/utils/raspberrypi/ctt/convert_tuning.py
blob: f4504d457b2cf6f39c724fca08adcf34052d8e69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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)
ge::UserMessage }; /** * \class Message * \brief A message that can be posted to a Thread */ /** * \enum Message::Type * \brief The message type * \var Message::None * \brief Invalid message type * \var Message::InvokeMessage * \brief Asynchronous method invocation across threads * \var Message::ThreadMoveMessage * \brief Object is being moved to a different thread * \var Message::DeferredDelete * \brief Object is scheduled for deletion * \var Message::UserMessage * \brief First value available for user-defined messages */ /** * \brief Construct a message object of type \a type * \param[in] type The message type */ Message::Message(Message::Type type) : type_(type) { } Message::~Message() { } /** * \fn Message::type() * \brief Retrieve the message type * \return The message type */ /** * \fn Message::receiver() * \brief Retrieve the message receiver * \return The message receiver */ /** * \brief Reserve and register a custom user-defined message type * * Custom message types use values starting at Message::UserMessage. Assigning * custom types manually may lead to accidental duplicated types. To avoid this * problem, this method reserves and returns the next available user-defined * message type. * * The recommended way to use this method is to subclass Message and provide a * static accessor for the custom message type. * * \code{.cpp} * class MyCustomMessage : public Message * { * public: * MyCustomMessage() : Message(type()) {} * * static Message::Type type() * { * static MessageType type = registerMessageType(); * return type; * } * }; * \endcode * * \return A new unique message type */ Message::Type Message::registerMessageType() { return static_cast<Message::Type>(nextUserType_++); } /** * \class InvokeMessage * \brief A message carrying a method invocation across threads */ /** * \brief Construct an InvokeMessage for method invocation on an Object * \param[in] method The bound method * \param[in] pack The packed method arguments * \param[in] semaphore The semaphore used to signal message delivery * \param[in] deleteMethod True to delete the \a method when the message is * destroyed */ InvokeMessage::InvokeMessage(BoundMethodBase *method, std::shared_ptr<BoundMethodPackBase> pack, Semaphore *semaphore, bool deleteMethod) : Message(Message::InvokeMessage), method_(method), pack_(pack), semaphore_(semaphore), deleteMethod_(deleteMethod) { } InvokeMessage::~InvokeMessage() { if (deleteMethod_) delete method_; } /** * \fn InvokeMessage::semaphore() * \brief Retrieve the message semaphore passed to the constructor * \return The message semaphore */ /** * \brief Invoke the method bound to InvokeMessage::method_ with arguments * InvokeMessage::pack_ */ void InvokeMessage::invoke() { method_->invokePack(pack_.get()); } /** * \var InvokeMessage::method_ * \brief The method to be invoked */ /** * \var InvokeMessage::pack_ * \brief The packed method invocation arguments */ } /* namespace libcamera */