Commit 05205f05 authored by nextime's avatar nextime

Add options to set DPI and color swapping

parent 5b05452e
...@@ -54,7 +54,7 @@ For the latest revision please visit https://github.com/TurnkeyTyranny/laser-gco ...@@ -54,7 +54,7 @@ For the latest revision please visit https://github.com/TurnkeyTyranny/laser-gco
<param name="logging" type="boolean" _gui-text="Log debug output from plugin:">true</param> <param name="logging" type="boolean" _gui-text="Log debug output from plugin:">true</param>
<param name="optimiseraster" type="boolean" _gui-text="Optimise raster horizontal scanning speed:">true</param> <param name="optimiseraster" type="boolean" _gui-text="Optimise raster horizontal scanning speed:">true</param>
<_param name="help" type="description">Will optimise raster paths, may cause slight overburn at the edges of the raster.</_param> <_param name="help" type="description">Will optimise raster paths, may cause slight overburn at the edges of the raster.</_param>
<param name="dpi" type="int" _gui-text="Set exported image DPI">270</param>
</page> </page>
<page name='tab' _gui-text='Preferences'> <page name='tab' _gui-text='Preferences'>
...@@ -81,6 +81,7 @@ For the latest revision please visit https://github.com/TurnkeyTyranny/laser-gco ...@@ -81,6 +81,7 @@ For the latest revision please visit https://github.com/TurnkeyTyranny/laser-gco
<item value="mm">mm</item> <item value="mm">mm</item>
<item value="in">in</item> <item value="in">in</item>
</param> </param>
<param name="invert" type="boolean" _gui-text="Swap colors">true</param>
<param name="dither" type="boolean" _gui-text="Apply dithering">false</param> <param name="dither" type="boolean" _gui-text="Apply dithering">false</param>
<param name="colorspace" type="int" _gui-text="color space. 0 to reduce derived from power">256</param> <param name="colorspace" type="int" _gui-text="color space. 0 to reduce derived from power">256</param>
<param name="showimg" type="boolean" _gui-text="Show generated raster images">false</param> <param name="showimg" type="boolean" _gui-text="Show generated raster images">false</param>
......
...@@ -493,6 +493,8 @@ class Gcode_tools(inkex.Effect): ...@@ -493,6 +493,8 @@ class Gcode_tools(inkex.Effect):
self.OptionParser.add_option("", "--dither", action="store", type="inkbool", dest="dither", default=False, help="Enable Dithering") self.OptionParser.add_option("", "--dither", action="store", type="inkbool", dest="dither", default=False, help="Enable Dithering")
self.OptionParser.add_option("", "--showimg", action="store", type="inkbool", dest="showimg", default=False, help="Show rastered images") self.OptionParser.add_option("", "--showimg", action="store", type="inkbool", dest="showimg", default=False, help="Show rastered images")
self.OptionParser.add_option("", "--colorspace", action="store", type="int", dest="colorspace", default="256", help="reduce colorspace") self.OptionParser.add_option("", "--colorspace", action="store", type="int", dest="colorspace", default="256", help="reduce colorspace")
self.OptionParser.add_option("", "--dpi", action="store", type="int", dest="dpi", default="270", help="set DPI for inkscape export")
self.OptionParser.add_option("", "--invert", action="store", type="inkbool", dest="invert", default=True, help="swap to negative colors")
def parse_curve(self, path): def parse_curve(self, path):
# if self.options.Xscale!=self.options.Yscale: # if self.options.Xscale!=self.options.Yscale:
...@@ -657,8 +659,9 @@ class Gcode_tools(inkex.Effect): ...@@ -657,8 +659,9 @@ class Gcode_tools(inkex.Effect):
#Rasters are exported internally at 270dpi. #Rasters are exported internally at 270dpi.
#So R = 1 / (270 / 25.4) #So R = 1 / (270 / 25.4)
# = 0.09406 # = 0.09406
mmperpix = round(1/(self.option.dpi/25.4), 5)
gcode += '\n\n;Beginning of Raster Image '+str(curve['id'])+' pixel size: '+str(curve['width'])+'x'+str(curve['height'])+'\n' gcode += '\n\n;Beginning of Raster Image '+str(curve['id'])+' pixel size: '+str(curve['width'])+'x'+str(curve['height'])+'\n'
gcode += 'M649 S'+str(laserPower)+' B2 D0 R0.09406\n' gcode += 'M649 S'+str(laserPower)+' B2 D0 R'+str(mmperpix)+'\n'
#Do not remove these two lines, they're important. Will not raster correctly if feedrate is not set prior. #Do not remove these two lines, they're important. Will not raster correctly if feedrate is not set prior.
#Move fast to point, cut at correct speed. #Move fast to point, cut at correct speed.
...@@ -1007,7 +1010,7 @@ class Gcode_tools(inkex.Effect): ...@@ -1007,7 +1010,7 @@ class Gcode_tools(inkex.Effect):
tmp = self.getTmpPath() #OS tmp directory tmp = self.getTmpPath() #OS tmp directory
bgcol = "#ffffff" #White bgcol = "#ffffff" #White
curfile = curfile = self.args[-1] #The current inkscape project we're exporting from. curfile = curfile = self.args[-1] #The current inkscape project we're exporting from.
command="inkscape --export-dpi 270 -i %s --export-id-only -e \"%stmpinkscapeexport.png\" -b \"%s\" %s" % (node.get("id"),tmp,bgcol,curfile) command="inkscape --export-dpi %s -i %s --export-id-only -e \"%stmpinkscapeexport.png\" -b \"%s\" %s" % (self.options.dpi,node.get("id"),tmp,bgcol,curfile)
p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
return_code = p.wait() return_code = p.wait()
...@@ -1022,7 +1025,8 @@ class Gcode_tools(inkex.Effect): ...@@ -1022,7 +1025,8 @@ class Gcode_tools(inkex.Effect):
else: else:
img = Image.open(filename).convert('L') img = Image.open(filename).convert('L')
img = ImageOps.invert(img) if self.options.invert:
img = ImageOps.invert(img)
#Get the image size #Get the image size
imageDataWidth, imageDataheight = img.size imageDataWidth, imageDataheight = img.size
...@@ -1061,7 +1065,8 @@ class Gcode_tools(inkex.Effect): ...@@ -1061,7 +1065,8 @@ class Gcode_tools(inkex.Effect):
showim = img.copy() showim = img.copy()
if (self.options.origin == 'topleft'): if (self.options.origin == 'topleft'):
showim = showim.transpose(Image.FLIP_TOP_BOTTOM) showim = showim.transpose(Image.FLIP_TOP_BOTTOM)
ImageOps.invert(showim).show() if self.options.invert:
ImageOps.invert(showim).show()
showim.show() showim.show()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment