Implemented avoidance and black'd it

This commit is contained in:
Casey 2024-07-04 16:37:14 +03:00
parent 763373ab17
commit 5f8cda7c8a
Signed by: hkc
GPG Key ID: F0F6CFE11CDB0960
1 changed files with 18 additions and 9 deletions

View File

@ -35,8 +35,13 @@ class AsyncBotManager:
for y in range(im.height):
for x in range(im.width):
l, a = im.getpixel((x, y)) # type: ignore
index = x + ox + (y + oy) * 1000
if a:
self.difference[x + ox + (y + oy) * 1000] = l > 0
self.put_index(index, l > 0)
def put_index(self, index: int, value: bool):
if not any([index in avoid for avoid in self.avoid]):
self.difference[index] = value
def add_avoid_rect(self, sx: int, sy: int, w: int, h: int):
for y in range(sy, sy + h):
@ -128,9 +133,13 @@ async def amain():
mgr.font = ImageFont.truetype(settings["font"], 8)
for avoid in settings["avoid"]:
if avoid["type"] == "rect":
mgr.add_avoid_rect(avoid["x"], avoid["y"], avoid["w"], avoid["h"])
mgr.add_avoid_rect(
avoid["x"], avoid["y"], avoid["w"], avoid["h"]
)
elif avoid["type"] == "range":
mgr.add_avoid_range(avoid["start"], avoid["stop"], avoid["step"])
mgr.add_avoid_range(
avoid["start"], avoid["stop"], avoid["step"]
)
for elem in settings["elements"]:
if elem["type"] == "text":
mgr.put_text(elem["x"], elem["y"], elem["text"])
@ -147,9 +156,9 @@ async def amain():
continue
ndx_start = (x + ox + (y + oy) * 577) * 3
mgr.difference[ndx_start] = r > 128
mgr.difference[ndx_start + 1] = g > 128
mgr.difference[ndx_start + 2] = b > 128
mgr.put_index(ndx_start, r > 128)
mgr.put_index(ndx_start + 1, g > 128)
mgr.put_index(ndx_start + 2, b > 128)
elif elem["type"] == "rgb565":
ox, oy = elem["x"], elem["y"]
with Image.open(elem["path"]).convert("RGBA") as im:
@ -164,9 +173,9 @@ async def amain():
color |= b >> 3
for i in range(16):
mgr.difference[ndx_start + i] = (
(color >> i) & 1
) > 0
mgr.put_index(
ndx_start + i, ((color >> i) & 1) > 0
)
mgr.get_difference_image().save("result.png")
mgr.get_avoid_image().save("avoid.png")