-
-
Save Suudy/fca725e2c8529b3e2e498b9ef11c40eb to your computer and use it in GitHub Desktop.
Convert plain text to XP format used by REXPaint
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
# | |
# translate a plain text file into the REXPaint file format | |
import argparse | |
import sys | |
import struct | |
import gzip | |
def doit(INFILE, OUTFILE): | |
fp = open(INFILE) | |
lines = fp.readlines() | |
fp.close() | |
lines = [list(l.rstrip()) for l in lines] | |
width = len(lines[0]) | |
height = len(lines) | |
with gzip.open(OUTFILE, 'wb') as fp: | |
fp.write(struct.pack('i', 1)) | |
fp.write(struct.pack('i', 1)) | |
fp.write(struct.pack('i', width)) | |
fp.write(struct.pack('i', height)) | |
for j in range(width): | |
for i in range(height): | |
ch = lines[i][j] | |
fp.write(struct.pack('i', ord(ch))) | |
fp.write(struct.pack('BBBBBB', 255,255,255,0,0,0)) | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser(description="Convert text file to REXpaint") | |
parser.add_argument('infile', help='Input text file') | |
parser.add_argument('outfile', help='Output xp file') | |
args = parser.parse_args() | |
doit(args.infile, args.outfile) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment