from PIL import Image
import numpy as np

power = np.array([1 << i for i in range(23, -1, -1)], dtype=np.uint32)

with Image.open("./Tour_Eiffel.bmp", mode='r') as im:
    ar = np.array(im)[2:, :-7]

ar = np.reshape(ar, (1780, 24)).astype(np.uint32)

colors = np.reshape(ar@power, (20, 89))

t = '<table class="colormatrix"><tbody>'
for row in colors:
    t += '<tr>'
    for c in row:
        if c and (c-1) & c:
            code = hex(c)[2:].rjust(6, "0")
            if code[0] == code[1] and code[2] == code[3] and code[4] == code[5]:
                code = code[0]+code[2]+code[4]
            t += f'<td style="background:#{code}"></td>'
        else:
            t += '<td></td>'
    t += "</tr>"
t += "</tbody></table>"

with open("../../src/effiel.txt", "w") as f:
    f.write(t)
print("done")
