-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated to comply with Prusaslicer 2.4
Prusaslicer 2.4 expects a new behaviour from post-processing scripts in regards to changing the name of the file being modified. I added a modified version of the script that complies with Prusaslicer 2.4.
- Loading branch information
Showing
2 changed files
with
171 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
#!/usr/local/bin/python3 | ||
import base64 | ||
import io, os, shutil | ||
import sys, getopt | ||
try: | ||
from PyQt5.QtCore import QSize,Qt | ||
from PyQt5.QtCore import QFile, QFileInfo, QIODevice,QTextStream | ||
from PyQt5.QtGui import QImage | ||
except: | ||
print ("!!! PyQt5 not installed run pip install PyQt5 !!!") | ||
sys.exit() | ||
|
||
CODEC = "UTF-8" | ||
|
||
def i4b(n): | ||
return [n >> 24 & 0xFF,n >> 16 & 0xFF,n >> 8 & 0xFF,n >> 0 & 0xFF] | ||
|
||
def i2b(n): | ||
return [n >> 8 & 0xFF,n >> 0 & 0xFF] | ||
|
||
def overread(msize,gfile): | ||
moutdata = "" | ||
img = QImage() | ||
img.loadFromData(base64topng(readPSTump(gfile),'')) | ||
img = img.scaled(msize.width(),msize.height(), Qt.IgnoreAspectRatio, Qt.SmoothTransformation) | ||
moutdata += ";"+(hex(msize.width())[2:]).rjust(4,'0')+(hex(msize.height())[2:]).rjust(4,'0')+"\r\n" | ||
pos = QSize(0,0) | ||
for ypos in range(0,img.height()): | ||
qrgb =";" | ||
for xpos in range(0,img.width()): | ||
data = img.pixel(xpos,ypos) | ||
pos.setWidth(pos.width()+1) | ||
dummy = (hex(((data & 0x00F80000) >> 8 ) | ((data & 0x0000FC00) >> 5 ) | ((data & 0x000000F8) >> 3 ))[2:]).rjust(4,'0') | ||
if dummy == "0020" or dummy == "0841" or dummy == "0861": | ||
dummy = "0000" | ||
qrgb = qrgb + dummy | ||
pos.setWidth(0) | ||
pos.setHeight(pos.height()+1) | ||
moutdata = moutdata + qrgb + "\r\n" | ||
return moutdata | ||
|
||
|
||
|
||
def overseek(gfile): | ||
outdatar = "" | ||
outdatar = outdatar + overread(QSize(70,70),gfile) | ||
outdatar = outdatar + overread(QSize(95,80),gfile) | ||
outdatar = outdatar + overread(QSize(95,95),gfile) | ||
outdatar = outdatar + overread(QSize(160,140),gfile) | ||
return outdatar | ||
|
||
def do_convert(gfile): | ||
env_slicer_pp_output_name = str(os.getenv('SLIC3R_PP_OUTPUT_NAME')) | ||
final_name = os.path.splitext(env_slicer_pp_output_name)[0]+"_btt"+os.path.splitext(env_slicer_pp_output_name)[1] | ||
with open(gfile + '.output_name', mode='w', encoding='UTF-8') as fopen: | ||
fopen.write(final_name) | ||
outdata = "" | ||
outdata = overseek(gfile) | ||
outdata = outdata + "; bigtree thumbnail end\r\n\r\n" | ||
fh = QFile(gfile) | ||
fh.open(QIODevice.ReadOnly) | ||
stream = QTextStream(fh) | ||
stream.setCodec(CODEC) | ||
lino = 0 | ||
fg = stream.readAll() + "\r\n" | ||
fh.close() | ||
bigtree3dfile = gfile | ||
fh = QFile(bigtree3dfile) | ||
fh.open(QIODevice.WriteOnly) | ||
stream = QTextStream(fh) | ||
stream.setCodec(CODEC) | ||
stream << outdata | ||
stream << fg | ||
fh.close() | ||
|
||
|
||
## write base64 to png | ||
def base64topng(stringdata,imagepath): | ||
|
||
image = base64.b64decode(stringdata) | ||
|
||
return image | ||
|
||
def readPSTump(infile): | ||
|
||
count = 0 | ||
base64data ='' | ||
started = 0 | ||
ended = 0 | ||
Psfile = open(infile,"r") | ||
while True: | ||
count =count+1 | ||
# Get next line from file | ||
line = Psfile.readline() | ||
if line.find("; thumbnail begin") == 0: | ||
started = 1 | ||
continue | ||
|
||
if line.find("; thumbnail end") == 0: | ||
ended = 1 | ||
|
||
if ended == 1: | ||
break | ||
# if line is empty | ||
# end of file is reached | ||
|
||
if not line: | ||
break | ||
|
||
if started == 0: | ||
continue | ||
|
||
base64data += line[2:] | ||
Psfile.close() | ||
if base64data == '': | ||
print('!!! no thumbnail data found in gcode !!!') | ||
sys.exit() | ||
##with open('base64.txt', 'w') as fh: | ||
## fh.writelines("%s" % line for line in base64data) | ||
return base64data | ||
|
||
def readPSGcode(infile): | ||
gcodedata ='' | ||
started = 0 | ||
|
||
Psfile = open(infile,"r") | ||
while True: | ||
# Get next line from file | ||
line = Psfile.readline() | ||
|
||
if line.find("; thumbnail end") == 0: | ||
started = 1 | ||
continue | ||
|
||
if started == 0: | ||
continue | ||
|
||
# if line is empty | ||
# end of file is reached | ||
if not line: | ||
break | ||
|
||
gcodedata += line | ||
Psfile.close() | ||
return gcodedata | ||
|
||
def main(argv): | ||
|
||
inputfile = '' | ||
outputfile = '' | ||
try: | ||
inputfile = sys.argv[1] | ||
except: | ||
print('./biqu_convert inputfile') | ||
sys.exit() | ||
|
||
do_convert(inputfile) | ||
|
||
|
||
|
||
if __name__ == "__main__": | ||
main(sys.argv[1:]) | ||
|
||
|
||
|
||
|
||
|