valetudo-map-parser 0.1.9b26__tar.gz → 0.1.9b27__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (20) hide show
  1. {valetudo_map_parser-0.1.9b26 → valetudo_map_parser-0.1.9b27}/PKG-INFO +1 -1
  2. {valetudo_map_parser-0.1.9b26 → valetudo_map_parser-0.1.9b27}/SCR/valetudo_map_parser/config/auto_crop.py +12 -1
  3. {valetudo_map_parser-0.1.9b26 → valetudo_map_parser-0.1.9b27}/SCR/valetudo_map_parser/config/utils.py +8 -7
  4. {valetudo_map_parser-0.1.9b26 → valetudo_map_parser-0.1.9b27}/SCR/valetudo_map_parser/hypfer_handler.py +1 -0
  5. {valetudo_map_parser-0.1.9b26 → valetudo_map_parser-0.1.9b27}/SCR/valetudo_map_parser/rand25_handler.py +4 -0
  6. {valetudo_map_parser-0.1.9b26 → valetudo_map_parser-0.1.9b27}/pyproject.toml +1 -1
  7. {valetudo_map_parser-0.1.9b26 → valetudo_map_parser-0.1.9b27}/LICENSE +0 -0
  8. {valetudo_map_parser-0.1.9b26 → valetudo_map_parser-0.1.9b27}/NOTICE.txt +0 -0
  9. {valetudo_map_parser-0.1.9b26 → valetudo_map_parser-0.1.9b27}/README.md +0 -0
  10. {valetudo_map_parser-0.1.9b26 → valetudo_map_parser-0.1.9b27}/SCR/valetudo_map_parser/__init__.py +0 -0
  11. {valetudo_map_parser-0.1.9b26 → valetudo_map_parser-0.1.9b27}/SCR/valetudo_map_parser/config/__init__.py +0 -0
  12. {valetudo_map_parser-0.1.9b26 → valetudo_map_parser-0.1.9b27}/SCR/valetudo_map_parser/config/colors.py +0 -0
  13. {valetudo_map_parser-0.1.9b26 → valetudo_map_parser-0.1.9b27}/SCR/valetudo_map_parser/config/drawable.py +0 -0
  14. {valetudo_map_parser-0.1.9b26 → valetudo_map_parser-0.1.9b27}/SCR/valetudo_map_parser/config/rand25_parser.py +0 -0
  15. {valetudo_map_parser-0.1.9b26 → valetudo_map_parser-0.1.9b27}/SCR/valetudo_map_parser/config/shared.py +0 -0
  16. {valetudo_map_parser-0.1.9b26 → valetudo_map_parser-0.1.9b27}/SCR/valetudo_map_parser/config/types.py +0 -0
  17. {valetudo_map_parser-0.1.9b26 → valetudo_map_parser-0.1.9b27}/SCR/valetudo_map_parser/hypfer_draw.py +0 -0
  18. {valetudo_map_parser-0.1.9b26 → valetudo_map_parser-0.1.9b27}/SCR/valetudo_map_parser/map_data.py +0 -0
  19. {valetudo_map_parser-0.1.9b26 → valetudo_map_parser-0.1.9b27}/SCR/valetudo_map_parser/py.typed +0 -0
  20. {valetudo_map_parser-0.1.9b26 → valetudo_map_parser-0.1.9b27}/SCR/valetudo_map_parser/reimg_draw.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: valetudo-map-parser
3
- Version: 0.1.9b26
3
+ Version: 0.1.9b27
4
4
  Summary: A Python library to parse Valetudo map data returning a PIL Image object.
5
5
  License: Apache-2.0
6
6
  Author: Sandro Cantarella
@@ -29,6 +29,14 @@ class AutoCrop:
29
29
  self.imh = image_handler
30
30
  self.file_name = self.imh.file_name
31
31
 
32
+ def validate_crop_dimensions(self, shared):
33
+ """Ensure width and height are valid before processing cropping."""
34
+ if shared.image_ref_width <= 0 or shared.image_ref_height <= 0:
35
+ _LOGGER.warning("Auto-crop failed: Invalid dimensions (width=%s, height=%s). Using original image.",
36
+ shared.image_ref_width, shared.image_ref_height)
37
+ return False
38
+ return True
39
+
32
40
  def check_trim(
33
41
  self, trimmed_height, trimmed_width, margin_size, image_array, file_name, rotate
34
42
  ):
@@ -201,7 +209,10 @@ class AutoCrop:
201
209
  Automatically crops and trims a numpy array and returns the processed image.
202
210
  """
203
211
  try:
204
- await self._init_auto_crop()
212
+ if self.validate_crop_dimensions(self.imh.shared):
213
+ await self._init_auto_crop()
214
+ else:
215
+ return image_array
205
216
  if self.imh.auto_crop is None:
206
217
  _LOGGER.debug("%s: Calculating auto trim box", self.file_name)
207
218
  # Find the coordinates of the first occurrence of a non-background color
@@ -485,8 +485,13 @@ async def async_resize_image(params: ResizeParams):
485
485
  """Resize the image to the given dimensions and aspect ratio."""
486
486
  if params.aspect_ratio:
487
487
  wsf, hsf = [int(x) for x in params.aspect_ratio.split(",")]
488
- if wsf == 0 or hsf == 0:
489
- return params.pil_img
488
+
489
+ if wsf == 0 or hsf == 0 or params.width <= 0 or params.height <= 0:
490
+ _LOGGER.warning(
491
+ "Invalid aspect ratio parameters: width=%s, height=%s, wsf=%s, hsf=%s. Returning original image.",
492
+ params.width, params.height, wsf, hsf)
493
+ return params.pil_img # Return original image if invalid
494
+
490
495
  new_aspect_ratio = wsf / hsf
491
496
  if params.width / params.height > new_aspect_ratio:
492
497
  new_width = int(params.pil_img.height * new_aspect_ratio)
@@ -495,11 +500,7 @@ async def async_resize_image(params: ResizeParams):
495
500
  new_width = params.pil_img.width
496
501
  new_height = int(params.pil_img.width / new_aspect_ratio)
497
502
 
498
- _LOGGER.debug(
499
- "Image Aspect Ratio: %s, %s",
500
- str(wsf),
501
- str(hsf),
502
- )
503
+ _LOGGER.debug("Resizing image to aspect ratio: %s, %s", wsf, hsf)
503
504
 
504
505
  if (params.crop_size is not None) and (params.offset_func is not None):
505
506
  offset = OffsetParams(wsf, hsf, new_width, new_height, params.is_rand)
@@ -43,6 +43,7 @@ class HypferMapImageHandler(BaseHandler):
43
43
  self.active_zones = None # vacuum active zones.
44
44
  self.svg_wait = False # SVG image creation wait.
45
45
  trim_data = self.shared.trims.to_dict() # trims data
46
+ _LOGGER.debug("Trim Data: %s", str(trim_data))
46
47
  self.trim_up = trim_data.get("trim_up", 0) # trim up
47
48
  self.trim_down = trim_data.get("trim_down", 0) # trim down
48
49
  self.trim_left = trim_data.get("trim_left", 0) # trim left
@@ -53,6 +53,7 @@ class ReImageHandler(BaseHandler):
53
53
  self.shared = camera_shared # Shared data
54
54
  self.active_zones = None # Active zones
55
55
  trim_data = self.shared.trims.to_dict() # trims data
56
+ _LOGGER.debug("Trim Data: %s", trim_data)
56
57
  self.trim_up = trim_data.get("trim_up", 0) # trim up
57
58
  self.trim_down = trim_data.get("trim_down", 0) # trim down
58
59
  self.trim_left = trim_data.get("trim_left", 0) # trim left
@@ -258,6 +259,9 @@ class ReImageHandler(BaseHandler):
258
259
  return img_np_array
259
260
 
260
261
  async def _finalize_image(self, pil_img):
262
+ if not self.shared.image_ref_width or not self.shared.image_ref_height:
263
+ _LOGGER.warning("Image finalization failed: Invalid image dimensions. Returning original image.")
264
+ return pil_img
261
265
  if self.check_zoom_and_aspect_ratio():
262
266
  resize_params = prepare_resize_params(self, pil_img, True)
263
267
  pil_img = await self.async_resize_images(resize_params)
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "valetudo-map-parser"
3
- version = "0.1.9.b26"
3
+ version = "0.1.9.b27"
4
4
  description = "A Python library to parse Valetudo map data returning a PIL Image object."
5
5
  authors = ["Sandro Cantarella <gsca075@gmail.com>"]
6
6
  license = "Apache-2.0"