From 1d0f0cc1adf2a99c3709241b0bc375fa964b6ff4 Mon Sep 17 00:00:00 2001 From: Allen Porter Date: Mon, 28 Sep 2026 03:28:02 +0000 Subject: [PATCH] perf(map): vectorize Q10 palette rasterization using PIL P-mode --- roborock/map/b01_q10_map_parser.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/roborock/map/b01_q10_map_parser.py b/roborock/map/b01_q10_map_parser.py index ad520b4f..9ea5cb9d 100644 --- a/roborock/map/b01_q10_map_parser.py +++ b/roborock/map/b01_q10_map_parser.py @@ -837,10 +837,10 @@ def parsed_from_packet(self, packet: Q10MapPacket) -> ParsedMapData: def _render(self, packet: Q10MapPacket) -> Image.Image: """Render the Q10 grid with the V1 map palette.""" palette = _build_palette(packet.grid, packet.width) - rgba = bytearray() - for value in packet.grid: - rgba.extend(palette[value]) - img = Image.frombytes("RGBA", (packet.width, packet.height), bytes(rgba)) + flat_palette = [channel for color in palette for channel in color] + p_img = Image.frombytes("P", (packet.width, packet.height), packet.grid) + p_img.putpalette(flat_palette, rawmode="RGBA") + img = p_img.convert("RGBA") # The ss07 grid is stored top-down (row 0 = top of the home), so it is # rendered as-is -- unlike the V1/Q7 convention, no vertical flip. scale = self._config.map_scale