10
10
# Describes command block and RLE routine
11
11
12
12
# variables; adjust me
13
- filename = "example_bins/mex_ovg.bin"
13
+ filename = "mex_ovg"
14
+ calculate_height = True # change to false for calclulating width
14
15
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
+
16
29
17
30
# First, deal with RLE compression as defined by the NXP PDF above
18
31
19
32
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
21
34
# Read out the command block (1 byte)
22
35
cmd = file .read (1 )
23
36
while cmd :
63
76
64
77
totalPixels = int (len (bytesOut ) / 4 )
65
78
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 )
67
83
print (f"Calculated as { width } x{ height } " )
68
84
69
85
# Cast RGBX byte stream to image using Pillow
70
86
image = Image .frombytes ('RGBA' , (width , height ), bytes (bytesOut ), 'raw' , 'RGBA' )
71
87
72
- output = "ovg.png"
73
- image .save (output )
74
- print (output + ' saved' )
88
+ image .save (output_path + filename + ".png" )
89
+ print (filename + '.png saved' )
75
90
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 ):
79
93
80
- for autoWidth in range (440 , 500 , 1 ):
94
+ for autoWidth in range (discovery_width_min , discovery_width_max + 1 , discovery_width_step ):
81
95
# Generate at given width
82
96
autoHeight = int (totalPixels / autoWidth )
83
97
image = Image .frombytes ('RGBA' , (autoWidth , autoHeight ), bytes (bytesOut ), 'raw' , 'RGBA' )
84
98
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