22 lines
536 B
Python
22 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)
|