Created
June 20, 2018 15:49
-
-
Save tattlemuss/70ccc58a96f296361d8008e724d9127b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if __name__ == '__main__': | |
import struct, sys | |
pi1 = open(sys.argv[1], "rb") | |
header = pi1.read(34) # skip the header data | |
pi1_bytes = pi1.read(32000) # We just want the pixeles | |
pi1.close() | |
out_bytes = bytearray(256 * 8) | |
for b in range(0, 256*8): | |
# Work out which character this is from | |
char = b % 256 # Character N | |
row_in_char = b / 256 # Row 0..7 | |
if char < 32: | |
continue | |
# Adjust into "Spiny range" where the source byte | |
# for char 32 is at position 0 | |
spiny_char = char - 32 | |
# Work out where to get the source pixel data from | |
output_x_col = (spiny_char % 40) # range 0-39 | |
output_y_row = ((spiny_char / 40) * 8) + row_in_char | |
# Convert from 0,1,2,3 etc to 0,1,8,9 to look up the correct chunk | |
x_byte_offset = (output_x_col / 2) * 8 + (output_x_col & 1) | |
# Read the value and stick it in the output | |
# NOTE: this reads the first bitplane i.e. value of 1 | |
out_bytes[b] = pi1_bytes[160 * output_y_row + x_byte_offset] | |
out_fh = open(sys.argv[2], "wb") | |
out_fh.write(out_bytes) | |
out_fh.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment