#!/usr/bin/python

from PIL import Image

imageOriginal = Image.open("medium_64_original.png")
imageFake     = Image.open("medium-64_decompressed.png")

pixOriginal   = imageOriginal.load()
pixFake       = imageFake.load()

if imageOriginal.size != imageFake.size:
    print("Images differ in Size")
    exit()

diffs = []

Size = imageOriginal.size
for y in range(Size[0]):
    for x in range(Size[1]):
        if pixOriginal[x,y] != pixFake[x,y]:
            diffs.append([x,y])

x0 = min([diff[0] for diff in diffs])
x1 = max([diff[0] for diff in diffs])
y0 = min([diff[1] for diff in diffs])
y1 = max([diff[1] for diff in diffs])

imageNew = Image.new('RGB', Size, "white")
pix = imageNew.load()

for x in range(x0, x1+1):
    for y in range(y0, y1+1):
        pix[x,y] = (0,0,0,255)

for diff in diffs:
    pix[diff[0], diff[1]] = (255,255,255,255)

imageNew.save("decoded.png")
