@@ -73,13 +73,15 @@ def _extract_thumbnail(self, gcode_filename, thumbnail_filename):
73
73
regex_luban = re .compile (';thumbnail: data:image/png;base64,(.*)[\r \n ]' , re .DOTALL )
74
74
regex_qidi = re .compile ('M4010.*\' (.*)\' ' , re .DOTALL )
75
75
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)"
76
77
lineNum = 0
77
78
collectedString = ""
78
79
use_mks = False
79
80
use_weedo = False
80
81
use_qidi = False
81
82
use_flashprint = False
82
83
use_creality = False
84
+ use_buddy = False
83
85
with open (gcode_filename , "rb" ) as gcode_file :
84
86
for line in gcode_file :
85
87
lineNum += 1
@@ -127,6 +129,11 @@ def _extract_thumbnail(self, gcode_filename, thumbnail_filename):
127
129
if len (matches ) > 0 :
128
130
self ._logger .debug ("Found creality thumbnail." )
129
131
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
130
137
if len (matches ) > 0 :
131
138
maxlen = 0
132
139
choosen = - 1
@@ -149,9 +156,17 @@ def _extract_thumbnail(self, gcode_filename, thumbnail_filename):
149
156
self ._logger .debug (matches )
150
157
elif use_flashprint :
151
158
png_file .write (self ._extract_flashprint_thumbnail (matches ))
159
+ elif use_buddy :
160
+ png_file .write (self ._extract_buddy_thumbnail (matches [choosen ].replace ("; " , "" )))
152
161
else :
153
162
png_file .write (base64 .b64decode (matches [choosen ].replace ("; " , "" ).encode ()))
154
163
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
+
155
170
# Extracts a thumbnail from hex binary data usd by FlashPrint slicer
156
171
def _extract_flashprint_thumbnail (self , gcode_encoded_images ):
157
172
encoded_image = gcode_encoded_images [0 ]
0 commit comments