Skip to content

Commit

Permalink
1.0.3rc3
Browse files Browse the repository at this point in the history
add QOI support for new Prusa Buddy Firmware, #114
  • Loading branch information
jneilliii committed Sep 27, 2023
1 parent 99f2bda commit 5751017
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 15 additions & 0 deletions octoprint_prusaslicerthumbnails/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,15 @@ 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
use_weedo = False
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
Expand Down Expand Up @@ -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
Expand All @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 5751017

Please sign in to comment.