|
11 | 11 |
|
12 | 12 | from google.protobuf.message import DecodeError |
13 | 13 | 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 |
15 | 15 | from vacuum_map_parser_base.config.drawable import Drawable |
16 | 16 | from vacuum_map_parser_base.config.image_config import ImageConfig |
17 | 17 | from vacuum_map_parser_base.map_data import ImageData, MapData, Path, Point, Room |
@@ -295,26 +295,34 @@ def _render_occupancy_image( |
295 | 295 | ) -> Image.Image: |
296 | 296 | """Render the B01 occupancy grid with per-room colors.""" |
297 | 297 |
|
| 298 | + colors = ColorsPalette() |
298 | 299 | room_colors = { |
299 | 300 | room_id: tuple(color[:3]) + (255,) |
300 | 301 | 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 |
302 | 303 | ).items() |
303 | 304 | } |
304 | 305 |
|
305 | 306 | # The observed occupancy grid contains only: |
306 | 307 | # - 0: outside/unknown |
307 | 308 | # - 127: floor/free |
308 | 309 | # - 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 | + } |
311 | 319 |
|
312 | 320 | rgba = bytearray() |
313 | 321 | for index, value in enumerate(grid): |
314 | 322 | 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)) |
316 | 324 | else: |
317 | | - rgba.extend(base_colors.get(value, fallback)) |
| 325 | + rgba.extend(base_colors.get(value, floor)) |
318 | 326 |
|
319 | 327 | # RGBA so the shared V1 ImageGenerator can alpha-composite overlay glyphs. |
320 | 328 | img = Image.frombytes("RGBA", (size_x, size_y), bytes(rgba)) |
|
0 commit comments