Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adapt bmp2rgb565.py to rgb888 #365

Merged
merged 2 commits into from
Nov 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions Helper_Scripts/img2rgb888.py
Original file line number Diff line number Diff line change
@@ -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 image 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)