Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # decodes the A8 files in
- # Microsoft Windows NT 4.0 SDK (1996)
- # MSTOOLS\SAMPLES\OPENGL\SCRSAVE\MAZE
- import struct
- def a8decompress(d):
- # defines
- ESCAPE = 0
- ESC_ENDLINE = 0
- ESC_ENDBITMAP = 1
- ESC_DELTA = 2
- ESC_RANDOM = 3
- def RANDOM_COUNT(c):
- return c - (ESC_RANDOM-1)
- # HwuRld
- s = 0
- o = []
- while True:
- run = d[s+0]
- esc = d[s+1]
- s += 2
- if run == ESCAPE:
- if esc == ESC_ENDBITMAP:
- break
- elif esc == ESC_DELTA:
- ln = struct.unpack(">H",d[s:s+2])[0]
- s += 2
- while ln > 0:
- o.append(0)
- ln -= 1
- elif esc >= ESC_RANDOM:
- ln = RANDOM_COUNT(esc)
- while ln > 0:
- o.append(d[s])
- s += 1
- ln -= 1
- else:
- while run > 0:
- o.append(esc)
- run -= 1
- return o
- def a8_to_tga(filea8,filetga=None):
- if filetga == None:
- filetga = filea8 + ".TGA"
- filea8 = filea8 + ".A8"
- a8 = open(filea8,"rb").read()
- (a8tag,w,h,a8bpp,a8compress,a8compsize) = struct.unpack("<LLLLLL",a8[0:24])
- a8pal = a8[24:24+(256*4) ]
- a8pix = a8[ 24+(256*4):]
- tga = bytearray()
- tga.append(0) # idlength
- tga.append(0) # colourmap = none
- tga.append(2) # datatypecode = RGB
- tga += bytes([0,0,0,0,0]) # colourmap specification ignored
- tga += bytes(struct.pack("<H",0)) # x origin
- tga += bytes(struct.pack("<H",0)) # y origin
- tga += bytes(struct.pack("<H",w)) # width
- tga += bytes(struct.pack("<H",h)) # height
- tga.append(32) # bits per pixel
- tga.append(0x18) # image descriptor: 8 bit alpha, top left origin
- pal = []
- for i in range(256):
- pal.append(a8pal[i*4:i*4+4])
- if (a8compress != 0):
- a8pix = a8decompress(a8pix)
- for i in range(w*h):
- a8idx = a8pix[i]
- rgba = pal[a8idx]
- tga.append(rgba[2]) # B
- tga.append(rgba[1]) # G
- tga.append(rgba[0]) # R
- tga.append(rgba[3]) # A
- open(filetga,"wb").write(tga)
- print (filea8 + " > " + filetga + " (%d x %d)" % (w,h))
- a8_to_tga("BHOLE")
- a8_to_tga("CURL4")
- a8_to_tga("HAPPY")
- a8_to_tga("LETTERS")
- a8_to_tga("RAT")
- a8_to_tga("SNOWFLAK")
- a8_to_tga("START")
- a8_to_tga("SWIRLX4")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement