From c1748aa24ba835f8a681698198eb1d1de810e5b6 Mon Sep 17 00:00:00 2001 From: Sven Killig Date: Thu, 26 Oct 2023 03:14:38 +0200 Subject: [PATCH 1/2] adapt bmp2rgb565.py to rgb888 --- Helper_Scripts/img2rgb888.py | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Helper_Scripts/img2rgb888.py diff --git a/Helper_Scripts/img2rgb888.py b/Helper_Scripts/img2rgb888.py new file mode 100644 index 00000000..2e5f2033 --- /dev/null +++ b/Helper_Scripts/img2rgb888.py @@ -0,0 +1,38 @@ +# Converts an image to a RGB888 array + +import argparse +from PIL import Image + +def rgb_to_rgb888(r, g, b): + return (r << 16) | (g << 8) | (b) + +def convert_bmp_to_rgb888_array(file_path): + # Open image + image = Image.open(file_path) + + # Retrieve pixel data + pixels = list(image.convert("RGB").getdata()) + + # Initialize RGB888 array + rgb888_array = [] + + # Iterate through each pixel and convert to RGB888 + for r, g, b in pixels: + rgb888_value = rgb_to_rgb888(r, g, b) + rgb888_array.append(str(rgb888_value)) + + # Join the array elements into a string with square brackets + return "[" + ", ".join(rgb888_array) + "]" + +# Create argument parser +parser = argparse.ArgumentParser(description="Convert an image to an RGB888 array string.") +parser.add_argument("file_path", help="Path to the BMP file to be converted.") + +# Parse arguments +args = parser.parse_args() + +# Convert the BMP file to an RGB888 array string +rgb888_array_string = convert_bmp_to_rgb888_array(args.file_path) + +# Print the converted string +print(rgb888_array_string) From 889ee4acf48623302d590f74e9ce8bd4504d0bb3 Mon Sep 17 00:00:00 2001 From: Sven Killig Date: Thu, 26 Oct 2023 03:19:22 +0200 Subject: [PATCH 2/2] generalize argument description --- Helper_Scripts/img2rgb888.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Helper_Scripts/img2rgb888.py b/Helper_Scripts/img2rgb888.py index 2e5f2033..7f7391a1 100644 --- a/Helper_Scripts/img2rgb888.py +++ b/Helper_Scripts/img2rgb888.py @@ -26,7 +26,7 @@ def convert_bmp_to_rgb888_array(file_path): # Create argument parser parser = argparse.ArgumentParser(description="Convert an image to an RGB888 array string.") -parser.add_argument("file_path", help="Path to the BMP file to be converted.") +parser.add_argument("file_path", help="Path to the image to be converted.") # Parse arguments args = parser.parse_args()