[libcamera-devel,v7,11/14] utils: raspberrypi: Add tuning file conversion script
diff mbox series

Message ID 20220727023816.30008-12-laurent.pinchart@ideasonboard.com
State Accepted
Headers show
Series
  • Replace boost JSON parser with libyaml in Raspberry Pi IPA
Related show

Commit Message

Laurent Pinchart July 27, 2022, 2:38 a.m. UTC
From: Naushir Patuck <naush@raspberrypi.com>

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 <naush@raspberrypi.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 utils/raspberrypi/ctt/convert_tuning.py | 46 +++++++++++++++++++++++++
 1 file changed, 46 insertions(+)
 create mode 100755 utils/raspberrypi/ctt/convert_tuning.py

Comments

Naushir Patuck July 28, 2022, 10:16 a.m. UTC | #1
Hi Laurent,


On Wed, 27 Jul 2022 at 03:38, Laurent Pinchart <
laurent.pinchart@ideasonboard.com> wrote:

> From: Naushir Patuck <naush@raspberrypi.com>
>
> 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 <naush@raspberrypi.com>
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  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.
>

Before merging, can you make a quick change here:

s/Raspberry Pi Ltd./Raspberry Pi Ltd/

to be consistent with the reset of our codebase.

Thanks,
Naush


> +
> +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)
> --
> Regards,
>
> Laurent Pinchart
>
>
Laurent Pinchart July 28, 2022, 11:06 a.m. UTC | #2
Hi Naush,

On Thu, Jul 28, 2022 at 11:16:20AM +0100, Naushir Patuck wrote:
> On Wed, 27 Jul 2022 at 03:38, Laurent Pinchart wrote:
> 
> > From: Naushir Patuck <naush@raspberrypi.com>
> >
> > 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 <naush@raspberrypi.com>
> > Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > ---
> >  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.
> 
> Before merging, can you make a quick change here:
> 
> s/Raspberry Pi Ltd./Raspberry Pi Ltd/
> 
> to be consistent with the reset of our codebase.

Updated and pushed.

> > +
> > +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)

Patch
diff mbox series

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)