From 92c509edf09775ecc93965a298b0f26de817ba26 Mon Sep 17 00:00:00 2001 From: hkc Date: Fri, 5 Jul 2024 14:27:51 +0300 Subject: [PATCH] Fixed endianness and renamed some functions --- async-bot.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/async-bot.py b/async-bot.py index 497f7b8..bf8c269 100644 --- a/async-bot.py +++ b/async-bot.py @@ -48,12 +48,12 @@ class AsyncBotManager: l, a = im.getpixel((x, y)) # type: ignore index = x + ox + (y + oy) * 1000 if a: - self.put_index(index, l > 0) + self.put_bit(index, l > 0) def put_pixel(self, x: int, y: int, val: bool): - self.put_index(x + y * 1000, val) + self.put_bit(x + y * 1000, val) - def put_index(self, index: int, value: bool): + def put_bit(self, index: int, value: bool): if index not in self.avoid: self.difference[index] = value @@ -227,9 +227,9 @@ async def amain() -> None: continue start_ndx = (x + ox + (y + oy) * 577) * 3 - mgr.put_index(start_ndx, r > 128) - mgr.put_index(start_ndx + 1, g > 128) - mgr.put_index(start_ndx + 2, b > 128) + mgr.put_bit(start_ndx, r > 128) + mgr.put_bit(start_ndx + 1, g > 128) + mgr.put_bit(start_ndx + 2, b > 128) elif elem["type"] == "rgb565": ox, oy = elem["x"], elem["y"] with Image.open(elem["path"]).convert("RGBA") as im: @@ -241,16 +241,15 @@ async def amain() -> None: offset: int = (x + ox + (y + oy) * 250) * 16 + # pack rgb888 to rgb565 rgb: int = (r >> 3) << 11 rgb |= (g >> 2) << 5 rgb |= (b >> 3) - color: int = (rgb & 0xFF) << 8 - color |= (rgb >> 8) - + # write to a bitstream for i in range(16): - mgr.put_index( - offset + i, ((color << i) & 0x8000) > 0 + mgr.put_bit( + offset + i, ((rgb << i) & 0x8000) > 0 ) elif elem["type"] == "rect": for y in range(elem["y"], elem["y"] + elem["h"]): @@ -268,7 +267,7 @@ async def amain() -> None: for i in range(8): if written > length: break - mgr.put_index(offset, bool((byte >> (7 - i)) & 1)) + mgr.put_bit(offset, bool((byte >> (7 - i)) & 1)) written += 1 offset += 1