diff --git a/octoprint_prusaslicerthumbnails/__init__.py b/octoprint_prusaslicerthumbnails/__init__.py index 8c05a34..f029e1d 100644 --- a/octoprint_prusaslicerthumbnails/__init__.py +++ b/octoprint_prusaslicerthumbnails/__init__.py @@ -73,6 +73,7 @@ def _extract_thumbnail(self, gcode_filename, thumbnail_filename): regex_luban = re.compile(';thumbnail: data:image/png;base64,(.*)[\r\n]', re.DOTALL) regex_qidi = re.compile('M4010.*\'(.*)\'', re.DOTALL) regex_creality = r"(?:^; jpg begin .*)(?:\n|\r\n?)((?:.+(?:\n|\r\n?))+?)(?:^; jpg end)" + regex_buddy = r"(?:^; thumbnail(?:_QOI)* begin \d+[x ]\d+ \d+)(?:\n|\r\n?)((?:.+(?:\n|\r\n?))+?)(?:^; thumbnail(?:_QOI)* end)" lineNum = 0 collectedString = "" use_mks = False @@ -80,6 +81,7 @@ def _extract_thumbnail(self, gcode_filename, thumbnail_filename): use_qidi = False use_flashprint = False use_creality = False + use_buddy = False with open(gcode_filename, "rb") as gcode_file: for line in gcode_file: lineNum += 1 @@ -127,6 +129,11 @@ def _extract_thumbnail(self, gcode_filename, thumbnail_filename): if len(matches) > 0: self._logger.debug("Found creality thumbnail.") use_creality = True + if len(matches) == 0: # Prusa buddy fallback + matches = re.findall(regex_buddy, test_str, re.MULTILINE) + if len(matches) > 0: + self._logger.debug("Found Prusa Buddy QOI thumbnail.") + use_buddy = True if len(matches) > 0: maxlen=0 choosen=-1 @@ -149,9 +156,17 @@ def _extract_thumbnail(self, gcode_filename, thumbnail_filename): self._logger.debug(matches) elif use_flashprint: png_file.write(self._extract_flashprint_thumbnail(matches)) + elif use_buddy: + png_file.write(self._extract_buddy_thumbnail(matches[choosen].replace("; ", ""))) else: png_file.write(base64.b64decode(matches[choosen].replace("; ", "").encode())) + # Extracts a thumbnail from QOI embedded image in new Prusa Firmware + def _extract_buddy_thumbnail(self, match): + encoded_image = base64.b64decode(match) + image = Image.open(io.BytesIO(encoded_image), formats=["QOI"]) + return self._imageToPng(image) + # Extracts a thumbnail from hex binary data usd by FlashPrint slicer def _extract_flashprint_thumbnail(self, gcode_encoded_images): encoded_image = gcode_encoded_images[0] diff --git a/setup.py b/setup.py index 8a493af..7ddaab3 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ plugin_name = "Slicer Thumbnails" # The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module -plugin_version = "1.0.3rc2" +plugin_version = "1.0.3rc3" # The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin # module @@ -33,7 +33,7 @@ plugin_license = "AGPLv3" # Any additional requirements besides OctoPrint should be listed here -plugin_requires = ["Pillow"] +plugin_requires = ["Pillow>=9.5.0"] ### -------------------------------------------------------------------------------------------------------------------- ### More advanced options that you usually shouldn't have to touch follow after this point