Skip to content

Commit de0bf45

Browse files
authored
Merge pull request #1 from Niklas04/master
Some changes made for/during mass conversion
2 parents 222aff9 + de2f695 commit de0bf45

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

ovg_to_png.py

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,27 @@
1010
# Describes command block and RLE routine
1111

1212
# variables; adjust me
13-
filename = "example_bins/mex_ovg.bin"
13+
filename = "mex_ovg"
14+
calculate_height = True # change to false for calclulating width
1415
width = 39
15-
# height automatically calculated
16+
height = 39 # height automatically calculated, when calculate_height = True
17+
18+
# Set image_size_discovery to True, to do fast image size discovery; tweak the range
19+
# Open the image in an auto refreshing viewer and hit enter until it looks coherent
20+
image_size_discovery = False
21+
discovery_width_min = 35
22+
discovery_width_max = 45
23+
discovery_width_step = 1
24+
25+
# folders
26+
source_path = "example_bins/" # e.g. "sourcefolder/"
27+
output_path = "" # e.g. "outputfolder/"
28+
1629

1730
# First, deal with RLE compression as defined by the NXP PDF above
1831

1932
bytesOut = bytearray()
20-
file = open(filename, "rb") # opening for [r]eading as [b]inary
33+
file = open(source_path+filename+".bin", "rb") # opening for [r]eading as [b]inary
2134
# Read out the command block (1 byte)
2235
cmd = file.read(1)
2336
while cmd:
@@ -63,24 +76,25 @@
6376

6477
totalPixels = int(len(bytesOut) / 4)
6578
print(f"Image data contains {totalPixels} pixels")
66-
height = int(totalPixels / width)
79+
if (calculate_height):
80+
height = int(totalPixels / width)
81+
else:
82+
width = int(totalPixels / height)
6783
print(f"Calculated as {width}x{height}")
6884

6985
# Cast RGBX byte stream to image using Pillow
7086
image = Image.frombytes('RGBA', (width, height), bytes(bytesOut), 'raw', 'RGBA')
7187

72-
output = "ovg.png"
73-
image.save(output)
74-
print(output + ' saved')
88+
image.save(output_path+filename+".png")
89+
print(filename + '.png saved')
7590

76-
# Enable the block below to do fast image size discovery; tweak the range
77-
# Open the image in an auto refreshing viewer and hit enter until it looks coherent
78-
if (False):
91+
# fast image size discovery
92+
if (image_size_discovery):
7993

80-
for autoWidth in range(440, 500, 1):
94+
for autoWidth in range(discovery_width_min, discovery_width_max+1, discovery_width_step):
8195
# Generate at given width
8296
autoHeight = int(totalPixels / autoWidth)
8397
image = Image.frombytes('RGBA', (autoWidth, autoHeight), bytes(bytesOut), 'raw', 'RGBA')
8498
output = "ovg.png"
85-
image.save(output)
86-
input(f"Saved at {autoWidth} x {autoHeight} - press enter to continue...")
99+
image.save(output_path+filename+".png")
100+
input(f"Saved at {autoWidth} x {autoHeight} - press enter to continue...")

0 commit comments

Comments
 (0)