from PIL import Image

image_path = 'ice-base.png'
pixel_data = None

compressdict = {}


with Image.open(image_path) as image:
    pixel_data = image.load()
    
    char_count = 1
    rawdata = ''
    bitpack_string = ''

    # bitpack spec - 4-bit values encoded to hex
    width, height = image.size
    for y in range(height):
        for x in range(0, width-4, 4):
            px = int(pixel_data[(x, y)])
            bitpack_string += hex(pixel_data[(x, y)] << 12 | pixel_data[(x+1, y)] << 8 | pixel_data[(x+2, y)] << 4 | pixel_data[(x+3, y)]).replace('0x','') + " "
            rawdata += str(px)
    
    print(bitpack_string)
    # print("\nvs\n")
    # print(rawdata)