Skip to content

Commit abfe88f

Browse files
committed
alpha support
1 parent 740af7f commit abfe88f

9 files changed

+28
-9
lines changed
Binary file not shown.
Binary file not shown.
231 KB
Binary file not shown.
Binary file not shown.

example_bins/lang_ovg.bin

850 Bytes
Binary file not shown.

example_bins/ops_ovg.bin

231 KB
Binary file not shown.

ovg_to_png.py

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

1212
# variables; adjust me
13-
filename = "example_bins/mex_ovg.bin"
14-
width = 39
15-
height = 39
13+
filename = "example_bins/ops_ovg.bin"
14+
width = 172
15+
# height automatically calculated
1616

1717
# First, deal with RLE compression as defined by the NXP PDF above
1818

@@ -61,8 +61,26 @@
6161
# Read next command block
6262
cmd = file.read(1)
6363

64+
totalPixels = int(len(bytesOut) / 4)
65+
print(f"Image data contains {totalPixels} pixels")
66+
height = int(totalPixels / width)
67+
print(f"Calculated as {width}x{height}")
68+
6469
# Cast RGBX byte stream to image using Pillow
65-
image = Image.frombytes('RGB', (width, height), bytes(bytesOut), 'raw', 'RGBX')
66-
output = "logo.png"
70+
image = Image.frombytes('RGBA', (width, height), bytes(bytesOut), 'raw', 'RGBA')
71+
72+
output = "ovg.png"
6773
image.save(output)
6874
print(output + ' saved')
75+
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 (True):
79+
80+
for autoWidth in range(440, 500, 1):
81+
# Generate at given width
82+
autoHeight = int(totalPixels / autoWidth)
83+
image = Image.frombytes('RGBA', (autoWidth, autoHeight), bytes(bytesOut), 'raw', 'RGBA')
84+
output = "ovg.png"
85+
image.save(output)
86+
input(f"Saved at {autoWidth} x {autoHeight} - press enter to continue...")

png_to_rcd.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
chksumGreen = functools.reduce(operator.xor, np.array([g]).transpose().flatten())
2121
# and red
2222
chksumRed = functools.reduce(operator.xor, np.array([r]).transpose().flatten())
23+
# and alpha
24+
chksumAlpha = functools.reduce(operator.xor, np.array([a]).transpose().flatten())
2325

2426
# img output
2527
data = np.array([b, g, r, a])
@@ -29,12 +31,11 @@
2931
f = open('./output.bin', 'wb')
3032
# B G R A ordered data
3133
f.write(bgrArray)
32-
# pixel colour checksums
34+
# pixel checksums
3335
f.write(chksumBlue)
3436
f.write(chksumGreen)
3537
f.write(chksumRed)
36-
# 1 byte of empty padding
37-
f.write(bytes(1))
38+
f.write(chksumAlpha)
3839
f.close()
3940

4041
print('output.bin saved')

rcd_to_png.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# let's go!
1212
in_file = open(filename, "rb") # opening for [r]eading as [b]inary
1313
data = in_file.read()
14-
img = Image.frombytes('RGB', (width, height), data, 'raw', 'BGRX')
14+
img = Image.frombytes('RGBA', (width, height), data, 'raw', 'BGRA')
1515
output = "logo.png"
1616
img.save(output)
1717
print(output + ' saved')

0 commit comments

Comments
 (0)