Skip to content

Commit

Permalink
Flip image before adding to svg
Browse files Browse the repository at this point in the history
  • Loading branch information
edenhaus committed Dec 23, 2023
1 parent 6acf437 commit 94dd06e
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions deebot_client/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from typing import Any, Final, NamedTuple
import zlib

from PIL import Image, ImageColor, ImagePalette
from PIL import Image, ImageColor, ImageOps, ImagePalette
import svg

from deebot_client.events.map import MapChangedEvent
Expand Down Expand Up @@ -74,9 +74,6 @@ def _as_str(cls, val: Any) -> str:
_OFFSET = 400
_TRACE_MAP = "trace_map"
_COLORS = {
0x01: "#badaff", # floor
0x02: "#4e96e2", # wall
0x03: "#1a81ed", # carpet
_TRACE_MAP: "#FFFFFF",
MapSetType.VIRTUAL_WALLS: "#FF0000",
MapSetType.NO_MOP_ZONES: "#FFA500",
Expand Down Expand Up @@ -472,7 +469,7 @@ def get_svg_map(self, width: int | None = None) -> str:
)

_LOGGER.debug("[get_svg_map] Crop Image")
cropped = image.crop(image_box)
cropped = ImageOps.flip(image.crop(image_box))

Check warning on line 472 in deebot_client/map.py

View check run for this annotation

Codecov / codecov/patch

deebot_client/map.py#L472

Added line #L472 was not covered by tests
del image

_LOGGER.debug(
Expand All @@ -489,12 +486,10 @@ def get_svg_map(self, width: int | None = None) -> str:
base64_bg = base64.b64encode(buffered.getvalue())

# Build the SVG elements

# Elements of the SVG Map to vertically flip
svg_map_group_elements: list[svg.Element] = []
svg_map.elements = [_SVG_DEFS]

Check warning on line 489 in deebot_client/map.py

View check run for this annotation

Codecov / codecov/patch

deebot_client/map.py#L489

Added line #L489 was not covered by tests

# Map background.
svg_map_group_elements.append(
svg_map.elements.append(

Check warning on line 492 in deebot_client/map.py

View check run for this annotation

Codecov / codecov/patch

deebot_client/map.py#L492

Added line #L492 was not covered by tests
svg.Image(
x=image_box[0],
y=image_box[1],
Expand All @@ -505,6 +500,9 @@ def get_svg_map(self, width: int | None = None) -> str:
)
)

# Elements of the SVG Map to vertically flip
svg_map_group_elements: list[svg.Element] = []

Check warning on line 504 in deebot_client/map.py

View check run for this annotation

Codecov / codecov/patch

deebot_client/map.py#L504

Added line #L504 was not covered by tests

# Additional subsets (VirtualWalls and NoMopZones)
svg_map_group_elements.extend(
[
Expand All @@ -531,15 +529,14 @@ def get_svg_map(self, width: int | None = None) -> str:
)

# Add all elements to the SVG map
svg_map.elements = [
_SVG_DEFS,
svg_map.elements.append(

Check warning on line 532 in deebot_client/map.py

View check run for this annotation

Codecov / codecov/patch

deebot_client/map.py#L532

Added line #L532 was not covered by tests
# Elements to vertically flip
svg.G(
transform_origin=f"{image_box_center[0]} {image_box_center[1]}",
transform=[svg.Scale(1, -1)],
elements=svg_map_group_elements,
),
]
)
)

str_svg_map = str(svg_map)

Expand Down Expand Up @@ -601,8 +598,6 @@ def update_points(self, base64_data: str) -> None:

if self.in_use:
im = Image.frombytes("P", (100, 100), decoded, "raw", "P", 0, -1)
im.putpalette(_MAP_BACKGROUND_IMAGE_PALETTE)
im.info["transparency"] = 0
self._image = im.rotate(-90)

Check warning on line 601 in deebot_client/map.py

View check run for this annotation

Codecov / codecov/patch

deebot_client/map.py#L600-L601

Added lines #L600 - L601 were not covered by tests
else:
self._image = None

Check warning on line 603 in deebot_client/map.py

View check run for this annotation

Codecov / codecov/patch

deebot_client/map.py#L603

Added line #L603 was not covered by tests
Expand Down

0 comments on commit 94dd06e

Please sign in to comment.