untitled paste

unlisted ⁨1⁩ ⁨file⁩ 2022-02-02 19:09:25 UTC

PICT Tool (Transparency Compression)

Raw
# ImageBuilder PICT tool (Transparency compression version) by Raccoon Sam
# Be sure to have Pillow for Python installed!

def getB(number=1):
    return int.from_bytes(rom.read(number), byteorder='big')

import struct
from PIL import Image

# Change the file directories to whatever necessary
filelist = ["/Users/Foobar/EXAMPLE_FILE1.PICT",
"/Users/Foobar/EXAMPLE_FILE2.PICT",
"/Users/Foobar/EXAMPLE_FILE3.PICT"]

for n in range(0, len(filelist)):
    currentfilename = filelist[n]
    
    with open(currentfilename, "rb") as rom:
        rom.seek(0)
        insPtr = getB(2)
        amount = ((insPtr-2) >> 1) & 0xFFFFFFFE
        height = amount >> 1
        rom.seek(0)
        
        insPtrList = struct.unpack(">{:d}H".format(height), rom.read(height<<1))
        datPtrList = list(struct.unpack(">{:d}H".format(height), rom.read(height<<1)))
        eof = getB(2)
        inslist = []
        for x in range(0, len(insPtrList)-1):
            rom.seek(insPtrList[x])
            lenval = insPtrList[x+1]-insPtrList[x]
            inslist.append(list(struct.unpack("{:d}B".format(lenval), rom.read(lenval))))
        
        rowcount = 0
        master_pixel_array = []
        
        canvas = Image.new("RGBA", (sum(inslist[0]),height))
        while inslist:
            que = inslist.pop(0)
            rgba_root = datPtrList[rowcount]
            rom.seek(rgba_root)
            
            z = True
            while que:
                pixlen = que.pop(0)
                if z:
                    for pix in range(0, pixlen):
                        master_pixel_array.append((0, 0, 0, 0))
                    z = not z
                    continue
                for pix in range(0, pixlen):
                    _a, _r, _g, _b = getB(), getB(), getB(), getB()
                    master_pixel_array.append((_r, _g, _b, 255-_a))
                z = not z
            rowcount += 1
        
        canvas.putdata(master_pixel_array)
        canvas.save(currentfilename+".png")