Last active
February 3, 2023 22:56
-
-
Save bbbradsmith/734842ac83eea64d3c5cfe6ccfc45382 to your computer and use it in GitHub Desktop.
Capstone Chess DOS image dumper
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
import PIL.Image | |
import os | |
def decode_file(filename): | |
print(filename) | |
f = open(filename,"rb").read() | |
print("Header: %02X %02X" % (f[0],f[1])) | |
pal = f[2:2+(16*3)] | |
offset = 2 + (16*3) | |
count = 0 | |
while offset < len(f): | |
w = f[offset+0] | |
h = f[offset+2] | |
print("%06X %2d: %3d x %3d" % (offset,count,w,h)) | |
if (w%8): w += 8 - (w%8) # pad to 8 | |
offset += 4 | |
img = PIL.Image.new("P",(w,h),255) | |
img.putpalette(pal) | |
planes = 4 | |
if filename in ["HUMAN2.EGA","MONSTER2.EGA","STAN2.EGA"] and count >= 12: | |
planes = 1 # 1bpp masks | |
for y in range(h): | |
for x in range(w): | |
p = (x // 8) | |
b = 7 - (x % 8) | |
v = 0 | |
for i in range(planes): | |
v |= ((f[offset+p+(i*(w//8))] >> b) & 1) << 4 | |
v >>= 1 | |
img.putpixel((x,y),v) | |
offset += (w * planes) // 8 | |
fo = "%s.%02d.png" % (filename,count) | |
print(" %-30s" % fo) | |
img.save("dumpega\\"+fo) | |
count += 1 | |
print("done.") | |
#decode_file("HUMAN3.EGA") | |
for (root,dirs,files) in os.walk("."): | |
for f in files: | |
if f.upper().endswith(".EGA"): | |
decode_file(f) |
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
import PIL.Image | |
import os | |
def decode_file(filename): | |
print(filename) | |
f = open(filename,"rb").read() | |
print("Header: %02X %02X" % (f[0],f[1])) | |
pal = f[2:2+(256*3)] | |
offset = 2 + (256*3) | |
count = 0 | |
while offset < len(f): | |
h = f[offset+0] | |
w = f[offset+1] | |
print("%06X %2d: %3d x %3d" % (offset,count,w,h)) | |
offset += 2 | |
img = PIL.Image.new("P",(w,h),255) | |
img.putpalette(pal) | |
for y in range(h): | |
for x in range(w): | |
img.putpixel((x,y),f[offset]) | |
offset += 1 | |
fo = "%s.%02d.png" % (filename,count) | |
print(" %-30s" % fo) | |
img.save("dumpsga\\"+fo) | |
count += 1 | |
print("done.") | |
#decode_file("HUMAN3.SGA") | |
for (root,dirs,files) in os.walk("."): | |
for f in files: | |
if f.upper().endswith(".SGA"): | |
decode_file(f) |
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
import PIL.Image | |
import os | |
def decode_file(filename): | |
print(filename) | |
f = open(filename,"rb").read() | |
print("Header: %02X %02X" % (f[0],f[1])) | |
pal = f[2:2+(16*3)] | |
offset = 2 + (16*3) | |
count = 0 | |
while offset < len(f): | |
w = f[offset+0] | |
h = f[offset+2] | |
print("%06X %2d: %3d x %3d" % (offset,count,w,h)) | |
if (w%8): w += 8 - (w%8) # pad to 8 | |
offset += 4 | |
img = PIL.Image.new("P",(w,h),255) | |
img.putpalette(pal) | |
planes = 4 | |
if filename in ["HUMAN2.VGA","MONSTER2.VGA","STAN2.VGA"] and count >= 12: | |
planes = 1 # 1bpp masks | |
for y in range(h): | |
for x in range(w): | |
p = (x // 8) | |
b = 7 - (x % 8) | |
v = 0 | |
for i in range(planes): | |
v |= ((f[offset+p+(i*(w//8))] >> b) & 1) << 4 | |
v >>= 1 | |
img.putpixel((x,y),v) | |
offset += (w * planes) // 8 | |
fo = "%s.%02d.png" % (filename,count) | |
print(" %-30s" % fo) | |
img.save("dumpvga\\"+fo) | |
count += 1 | |
print("done.") | |
#decode_file("HUMAN3.VGA") | |
for (root,dirs,files) in os.walk("."): | |
for f in files: | |
if f.upper().endswith(".VGA"): | |
decode_file(f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment