summaryrefslogtreecommitdiff
path: root/scripts/py/gen_rgb_cpp.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/py/gen_rgb_cpp.py')
-rw-r--r--scripts/py/gen_rgb_cpp.py43
1 files changed, 31 insertions, 12 deletions
diff --git a/scripts/py/gen_rgb_cpp.py b/scripts/py/gen_rgb_cpp.py
index e1c93bb..f1200e6 100644
--- a/scripts/py/gen_rgb_cpp.py
+++ b/scripts/py/gen_rgb_cpp.py
@@ -1,4 +1,4 @@
-# SPDX-FileCopyrightText: Copyright 2021-2023 Arm Limited and/or its affiliates <open-source-office@arm.com>
+# SPDX-FileCopyrightText: Copyright 2021-2024 Arm Limited and/or its affiliates <open-source-office@arm.com>
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,6 +18,7 @@ Utility script to convert a set of RGB images in a given location into
corresponding cpp files and a single hpp file referencing the vectors
from the cpp files.
"""
+import argparse
import glob
import math
import typing
@@ -60,6 +61,13 @@ parser.add_argument(
)
parser.add_argument(
+ "--generate_file_paths",
+ type=bool,
+ action=argparse.BooleanOptionalAction,
+ help="Generate an array of file paths to the images as well as the images themselves."
+)
+
+parser.add_argument(
"--license_template",
type=str,
help="Header template file",
@@ -85,11 +93,12 @@ class ImagesParams:
image_filenames: typing.List[str]
-def write_hpp_file(
+def write_metadata_files(
images_params: ImagesParams,
header_file_path: Path,
cc_file_path: Path,
header_template_file: str,
+ source_directory: str = None
):
"""
Write Images.hpp and Images.cc
@@ -98,6 +107,7 @@ def write_hpp_file(
@param header_file_path: Images.hpp path
@param cc_file_path: Images.cc path
@param header_template_file: Header template file name
+ @param source_directory: Optional source directory of images
"""
print(f"++ Generating {header_file_path}")
hdr = GenUtils.gen_header(env, header_template_file)
@@ -109,14 +119,16 @@ def write_hpp_file(
.stream(common_template_header=hdr,
imgs_count=images_params.num_images,
img_size=image_size,
- var_names=images_params.image_array_names) \
+ var_names=images_params.image_array_names,
+ source_directory=source_directory) \
.dump(str(header_file_path))
env \
.get_template('Images.cc.template') \
.stream(common_template_header=hdr,
var_names=images_params.image_array_names,
- img_names=images_params.image_filenames) \
+ img_names=images_params.image_filenames,
+ source_directory=source_directory) \
.dump(str(cc_file_path))
@@ -196,9 +208,13 @@ def main(args):
image_filenames = []
image_array_names = []
- if Path(args.image_path).is_dir():
+ image_path = Path(args.image_path)
+
+ if image_path.is_dir():
+ image_directory = image_path
filepaths = sorted(glob.glob(str(Path(args.image_path) / '**/*.*'), recursive=True))
- elif Path(args.image_path).is_file():
+ elif image_path.is_file():
+ image_directory = image_path.parent
filepaths = [args.image_path]
else:
raise OSError("Directory or file does not exist.")
@@ -228,13 +244,16 @@ def main(args):
# Increment image index
image_idx = image_idx + 1
- header_filepath = Path(args.header_folder_path) / "InputFiles.hpp"
- common_cc_filepath = Path(args.source_folder_path) / "InputFiles.cc"
-
- images_params = ImagesParams(image_idx, args.image_size, image_array_names, image_filenames)
-
if len(image_filenames) > 0:
- write_hpp_file(images_params, header_filepath, common_cc_filepath, args.license_template)
+ images_params = ImagesParams(image_idx, args.image_size, image_array_names, image_filenames)
+
+ write_metadata_files(
+ images_params,
+ header_file_path=Path(args.header_folder_path) / "InputFiles.hpp",
+ cc_file_path=Path(args.source_folder_path) / "InputFiles.cc",
+ header_template_file=args.license_template,
+ source_directory=image_directory if args.generate_file_paths else None
+ )
else:
raise FileNotFoundError("No valid images found.")