Skip to content

Commit e0dea2a

Browse files
andigclaude
andcommitted
feat: align Q7 map colors with V1
Use the shared V1 palette roles, matching the Q10 renderer and the app look: transparent outside, GREY_WALL for walls and interior obstacles, MAP_INSIDE for floor not assigned to any room. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent e0e0664 commit e0dea2a

2 files changed

Lines changed: 17 additions & 9 deletions

File tree

roborock/map/b01_map_parser.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from google.protobuf.message import DecodeError
1313
from PIL import Image
14-
from vacuum_map_parser_base.config.color import ColorsPalette
14+
from vacuum_map_parser_base.config.color import ColorsPalette, SupportedColor
1515
from vacuum_map_parser_base.config.drawable import Drawable
1616
from vacuum_map_parser_base.config.image_config import ImageConfig
1717
from vacuum_map_parser_base.map_data import ImageData, MapData, Path, Point, Room
@@ -295,26 +295,34 @@ def _render_occupancy_image(
295295
) -> Image.Image:
296296
"""Render the B01 occupancy grid with per-room colors."""
297297

298+
colors = ColorsPalette()
298299
room_colors = {
299300
room_id: tuple(color[:3]) + (255,)
300301
for room_id, color in adjacency_aware_room_colors(
301-
room_pixels, size_x, ColorsPalette(), lambda value: value or None
302+
room_pixels, size_x, colors, lambda value: value or None
302303
).items()
303304
}
304305

305306
# The observed occupancy grid contains only:
306307
# - 0: outside/unknown
307308
# - 127: floor/free
308309
# - 128: wall/obstacle
309-
base_colors = {0: (0, 0, 0, 255), _FLOOR: (180, 180, 180, 255), _WALL: (255, 255, 255, 255)}
310-
fallback = (180, 180, 180, 255)
310+
# Same V1 palette roles as the Q10 renderer: transparent outside, grey
311+
# walls/obstacles, MAP_INSIDE for floor not assigned to any room.
312+
outside = (0, 0, 0, 0)
313+
floor = tuple(colors.get_color(SupportedColor.MAP_INSIDE)[:3]) + (255,)
314+
base_colors = {
315+
0: outside,
316+
_FLOOR: floor,
317+
_WALL: tuple(colors.get_color(SupportedColor.GREY_WALL)[:3]) + (255,),
318+
}
311319

312320
rgba = bytearray()
313321
for index, value in enumerate(grid):
314322
if value == _FLOOR and (room_id := room_pixels[index]):
315-
rgba.extend(room_colors.get(room_id, fallback))
323+
rgba.extend(room_colors.get(room_id, floor))
316324
else:
317-
rgba.extend(base_colors.get(value, fallback))
325+
rgba.extend(base_colors.get(value, floor))
318326

319327
# RGBA so the shared V1 ImageGenerator can alpha-composite overlay glyphs.
320328
img = Image.frombytes("RGBA", (size_x, size_y), bytes(rgba))

tests/map/test_b01_map_parser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,6 @@ def test_b01_map_parser_colors_enclosed_room_pixels() -> None:
262262

263263
# Raw (3, 3) flips to display row 2; scale 4 puts it at (12..15, 8..11).
264264
room_pixel = img.getpixel((13, 9))
265-
assert room_pixel != (180, 180, 180)
266-
# Wall border stays white.
267-
assert img.getpixel((1, 1)) == (255, 255, 255)
265+
assert room_pixel != (32, 115, 185) # not the plain MAP_INSIDE floor color
266+
# Walls/obstacles render with the shared V1 grey wall color.
267+
assert img.getpixel((1, 1)) == (93, 109, 126)

0 commit comments

Comments
 (0)