Skip to content

Commit 5751017

Browse files
committed
1.0.3rc3
add QOI support for new Prusa Buddy Firmware, #114
1 parent 99f2bda commit 5751017

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

octoprint_prusaslicerthumbnails/__init__.py

+15
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,15 @@ def _extract_thumbnail(self, gcode_filename, thumbnail_filename):
7373
regex_luban = re.compile(';thumbnail: data:image/png;base64,(.*)[\r\n]', re.DOTALL)
7474
regex_qidi = re.compile('M4010.*\'(.*)\'', re.DOTALL)
7575
regex_creality = r"(?:^; jpg begin .*)(?:\n|\r\n?)((?:.+(?:\n|\r\n?))+?)(?:^; jpg end)"
76+
regex_buddy = r"(?:^; thumbnail(?:_QOI)* begin \d+[x ]\d+ \d+)(?:\n|\r\n?)((?:.+(?:\n|\r\n?))+?)(?:^; thumbnail(?:_QOI)* end)"
7677
lineNum = 0
7778
collectedString = ""
7879
use_mks = False
7980
use_weedo = False
8081
use_qidi = False
8182
use_flashprint = False
8283
use_creality = False
84+
use_buddy = False
8385
with open(gcode_filename, "rb") as gcode_file:
8486
for line in gcode_file:
8587
lineNum += 1
@@ -127,6 +129,11 @@ def _extract_thumbnail(self, gcode_filename, thumbnail_filename):
127129
if len(matches) > 0:
128130
self._logger.debug("Found creality thumbnail.")
129131
use_creality = True
132+
if len(matches) == 0: # Prusa buddy fallback
133+
matches = re.findall(regex_buddy, test_str, re.MULTILINE)
134+
if len(matches) > 0:
135+
self._logger.debug("Found Prusa Buddy QOI thumbnail.")
136+
use_buddy = True
130137
if len(matches) > 0:
131138
maxlen=0
132139
choosen=-1
@@ -149,9 +156,17 @@ def _extract_thumbnail(self, gcode_filename, thumbnail_filename):
149156
self._logger.debug(matches)
150157
elif use_flashprint:
151158
png_file.write(self._extract_flashprint_thumbnail(matches))
159+
elif use_buddy:
160+
png_file.write(self._extract_buddy_thumbnail(matches[choosen].replace("; ", "")))
152161
else:
153162
png_file.write(base64.b64decode(matches[choosen].replace("; ", "").encode()))
154163

164+
# Extracts a thumbnail from QOI embedded image in new Prusa Firmware
165+
def _extract_buddy_thumbnail(self, match):
166+
encoded_image = base64.b64decode(match)
167+
image = Image.open(io.BytesIO(encoded_image), formats=["QOI"])
168+
return self._imageToPng(image)
169+
155170
# Extracts a thumbnail from hex binary data usd by FlashPrint slicer
156171
def _extract_flashprint_thumbnail(self, gcode_encoded_images):
157172
encoded_image = gcode_encoded_images[0]

setup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
plugin_name = "Slicer Thumbnails"
1515

1616
# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
17-
plugin_version = "1.0.3rc2"
17+
plugin_version = "1.0.3rc3"
1818

1919
# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
2020
# module
@@ -33,7 +33,7 @@
3333
plugin_license = "AGPLv3"
3434

3535
# Any additional requirements besides OctoPrint should be listed here
36-
plugin_requires = ["Pillow"]
36+
plugin_requires = ["Pillow>=9.5.0"]
3737

3838
### --------------------------------------------------------------------------------------------------------------------
3939
### More advanced options that you usually shouldn't have to touch follow after this point

0 commit comments

Comments
 (0)