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)
an class="hl opt">, /* bit 5 */ FlashNotPresent = 0x20, /* bit 6 */ RedEye = 0x40, }; enum WhiteBalance { Auto = 0, Manual = 1, }; enum StringEncoding { NoEncoding = 0, ASCII = 1, Unicode = 2, }; void setMake(const std::string &make); void setModel(const std::string &model); void setOrientation(int orientation); void setSize(const libcamera::Size &size); void setThumbnail(std::vector<unsigned char> &&thumbnail, Compression compression); void setTimestamp(time_t timestamp, std::chrono::milliseconds msec); void setGPSDateTimestamp(time_t timestamp); void setGPSLocation(const double *coords); void setGPSMethod(const std::string &method); void setFocalLength(float length); void setExposureTime(uint64_t nsec); void setAperture(float size); void setISO(uint16_t iso); void setFlash(Flash flash); void setWhiteBalance(WhiteBalance wb); libcamera::Span<const uint8_t> data() const { return { exifData_, size_ }; } [[nodiscard]] int generate(); private: ExifEntry *createEntry(ExifIfd ifd, ExifTag tag); ExifEntry *createEntry(ExifIfd ifd, ExifTag tag, ExifFormat format, unsigned long components, unsigned int size); void setByte(ExifIfd ifd, ExifTag tag, uint8_t item); void setShort(ExifIfd ifd, ExifTag tag, uint16_t item); void setLong(ExifIfd ifd, ExifTag tag, uint32_t item); void setString(ExifIfd ifd, ExifTag tag, ExifFormat format, const std::string &item, StringEncoding encoding = NoEncoding); void setRational(ExifIfd ifd, ExifTag tag, ExifRational item); void setRational(ExifIfd ifd, ExifTag tag, libcamera::Span<const ExifRational> items); std::tuple<int, int, int> degreesToDMS(double decimalDegrees); void setGPSDMS(ExifIfd ifd, ExifTag tag, int deg, int min, int sec); std::u16string utf8ToUtf16(const std::string &str); bool valid_; ExifData *data_; ExifMem *mem_; ExifByteOrder order_; unsigned char *exifData_; unsigned int size_; std::vector<unsigned char> thumbnailData_; };