def rotate(image: ImageData): if image.dimensions.rotation == 90: image.data = image.data.transpose(Image.ROTATE_90) if image.dimensions.rotation == 180: image.data = image.data.transpose(Image.ROTATE_180) if image.dimensions.rotation == 270: image.data = image.data.transpose(Image.ROTATE_270)
def parse_image( image_raw: bytes, header: MapDataHeader, colors, image_config, additional_data_json, map_data_type: MapDataTypes) -> Tuple[ImageData, Dict[int, Room]]: _LOGGER.debug(f"parse image for map {map_data_type}") image, image_rooms = ImageHandlerDreame.parse(image_raw, header, colors, image_config, map_data_type) room_names = {} if additional_data_json.get("seg_inf"): room_names = { int(k): base64.b64decode(v.get("name")).decode('utf-8') for (k, v) in additional_data_json["seg_inf"].items() if v.get("name") } rooms = { k: Room(k, (v.x0 + header.image_left) * header.image_pixel_size, (v.y0 + header.image_top) * header.image_pixel_size, (v.x1 + header.image_left) * header.image_pixel_size, (v.y1 + header.image_top) * header.image_pixel_size, room_names[k] if room_names.get(k) else str(k)) for (k, v) in image_rooms.items() } return ImageData( header.image_width * header.image_height, header.image_top, header.image_left, header.image_height, header.image_width, image_config, image, lambda p: MapDataParserDreame.map_to_image( p, header.image_pixel_size)), rooms
def parse_image(buf: ParsingBuffer, colors: Colors, image_config: ImageConfig, draw_cleaned_area: bool) \ -> Tuple[ImageData, Dict[int, Room], Set[int]]: buf.skip('unknown1', 0x08) image_top = 0 image_left = 0 image_height = buf.get_uint32('image_height') image_width = buf.get_uint32('image_width') buf.skip('unknown2', 20) image_size = image_height * image_width _LOGGER.debug('width: %d, height: %d', image_width, image_height) if image_width \ - image_width * (image_config[CONF_TRIM][CONF_LEFT] + image_config[CONF_TRIM][CONF_RIGHT]) / 100 \ < MINIMAL_IMAGE_WIDTH: image_config[CONF_TRIM][CONF_LEFT] = 0 image_config[CONF_TRIM][CONF_RIGHT] = 0 if image_height \ - image_height * (image_config[CONF_TRIM][CONF_TOP] + image_config[CONF_TRIM][CONF_BOTTOM]) / 100 \ < MINIMAL_IMAGE_HEIGHT: image_config[CONF_TRIM][CONF_TOP] = 0 image_config[CONF_TRIM][CONF_BOTTOM] = 0 buf.mark_as_image_beginning() image, rooms_raw, cleaned_areas, cleaned_areas_layer = ImageHandlerViomi.parse(buf, image_width, image_height, colors, image_config, draw_cleaned_area) _LOGGER.debug('img: number of rooms: %d, numbers: %s', len(rooms_raw), rooms_raw.keys()) rooms = {} for number, room in rooms_raw.items(): rooms[number] = Room(number, MapDataParserViomi.image_to_map(room[0] + image_left), MapDataParserViomi.image_to_map(room[1] + image_top), MapDataParserViomi.image_to_map(room[2] + image_left), MapDataParserViomi.image_to_map(room[3] + image_top)) return ImageData(image_size, image_top, image_left, image_height, image_width, image_config, image, MapDataParserViomi.map_to_image, additional_layers={DRAWABLE_CLEANED_AREA: cleaned_areas_layer}), rooms, cleaned_areas
def parse_image(map_image: bytes, width: int, height: int, min_x: float, min_y: float, resolution: float, colors: Dict, image_config: Dict, rooms: Dict[int, Room]) -> ImageData: image_top = 0 image_left = 0 room_numbers = list(rooms.keys()) image, rooms_raw = ImageHandlerRoidmi.parse(map_image, width, height, colors, image_config, room_numbers) for number, room in rooms_raw.items(): pf = lambda p: MapDataParserRoidmi.image_to_map(p, resolution, min_x, min_y) p1 = pf(Point(room[0] + image_left, room[1] + image_top)) p2 = pf(Point(room[2] + image_left, room[3] + image_top)) rooms[number].x0 = p1.x rooms[number].y0 = p1.y rooms[number].x1 = p2.x rooms[number].y1 = p2.y return ImageData(width * height, image_top, image_left, height, width, image_config, image, lambda p: MapDataParserRoidmi.map_to_image(p, resolution, min_x, min_y))
def __draw_layer__(image: ImageData, layer: ImageType): image.data = Image.alpha_composite(image.data, layer)
def create_empty(colors) -> MapData: map_data = MapData() empty_map = ImageHandler.create_empty_map_image( colors, "Vacuum not supported") map_data.image = ImageData.create_empty(empty_map) return map_data
def create_empty(colors, text) -> MapData: map_data = MapData() empty_map = ImageHandler.create_empty_map_image(colors, text) map_data.image = ImageData.create_empty(empty_map) return map_data