kmsvnc/test1.py
2023-04-25 21:02:11 +08:00

21 lines
536 B
Python

import PIL.Image
im = PIL.Image.open("/tmp/1.png")
im = im.convert("RGB")
c = 0
mapping = {}
mapping1 = {}
for y in range(1080):
for x in range(1920):
r, g, b = im.getpixel((x, y))
rc = (r << 16) + (g << 8) + b
#assert c == rc, f"c={c:#08x} rc={rc:#08x} {r=} {g=} {b=}"
assert type(rc) == int
mapping[rc] = c
mapping1[c] = rc
c += 1
import json
with open("/tmp/map.json", "w") as f:
json.dump(mapping, f)
with open("/tmp/map1.json", "w") as f:
json.dump(mapping1, f)