Skip to content

Instantly share code, notes, and snippets.

@Suudy
Forked from mtvee/txt2xp.py
Last active August 5, 2020 18:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Suudy/fca725e2c8529b3e2e498b9ef11c40eb to your computer and use it in GitHub Desktop.
Save Suudy/fca725e2c8529b3e2e498b9ef11c40eb to your computer and use it in GitHub Desktop.
Convert plain text to XP format used by REXPaint
#
# 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