Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
laser-gcode-exporter-inkscape-plugin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
machinery
laser-gcode-exporter-inkscape-plugin
Commits
88cb9879
Commit
88cb9879
authored
May 17, 2016
by
nextime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add option to enable dithering
parent
ba27a8ba
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
31 deletions
+33
-31
turnkeylaser.py
turnkeylaser.py
+33
-31
No files found.
turnkeylaser.py
View file @
88cb9879
...
@@ -420,11 +420,12 @@ def parse_layer_name(txt):
...
@@ -420,11 +420,12 @@ def parse_layer_name(txt):
(
field
,
value
)
=
arg
.
split
(
"="
)
(
field
,
value
)
=
arg
.
split
(
"="
)
except
:
except
:
raise
ValueError
(
"Invalid argument in layer '
%
s'"
%
layerName
)
raise
ValueError
(
"Invalid argument in layer '
%
s'"
%
layerName
)
if
(
field
==
"feed"
or
field
==
"ppm"
):
if
(
field
==
"feed"
or
field
==
"ppm"
or
field
=
"dither"
):
try
:
try
:
value
=
float
(
value
)
value
=
float
(
value
)
except
:
except
:
raise
ValueError
(
"Invalid layer name '
%
s'"
%
value
)
raise
ValueError
(
"Invalid layer name '
%
s'"
%
value
)
params
[
field
]
=
value
params
[
field
]
=
value
logger
.
write
(
"
%
s ==
%
s"
%
(
field
,
value
))
logger
.
write
(
"
%
s ==
%
s"
%
(
field
,
value
))
...
@@ -951,7 +952,7 @@ class Gcode_tools(inkex.Effect):
...
@@ -951,7 +952,7 @@ class Gcode_tools(inkex.Effect):
self
.
skipped
=
0
self
.
skipped
=
0
def
compile_paths
(
parent
,
node
,
trans
,
laserPower
=
100
):
def
compile_paths
(
parent
,
node
,
trans
,
laserPower
=
100
,
altdither
=
False
):
# Apply the object transform, along with the parent transformation
# Apply the object transform, along with the parent transformation
mat
=
node
.
get
(
'transform'
,
None
)
mat
=
node
.
get
(
'transform'
,
None
)
path
=
{}
path
=
{}
...
@@ -1019,32 +1020,32 @@ class Gcode_tools(inkex.Effect):
...
@@ -1019,32 +1020,32 @@ class Gcode_tools(inkex.Effect):
#Get the image size
#Get the image size
imageDataWidth
,
imageDataheight
=
img
.
size
imageDataWidth
,
imageDataheight
=
img
.
size
# dithering image and compile the pixels
if
altdither
:
inkex
.
errormsg
(
"start dithering."
)
# dithering image and compile the pixels
palette
=
list
(
set
(
img
.
convert
(
"P"
,
palette
=
Image
.
ADAPTIVE
,
colors
=
laserPower
-
1
)
.
getpalette
()))
inkex
.
errormsg
(
"start dithering."
)
inkex
.
errormsg
(
"dither for "
+
str
(
len
(
palette
))
+
" colors palette..."
)
palette
=
list
(
set
(
img
.
convert
(
"P"
,
palette
=
Image
.
ADAPTIVE
,
colors
=
laserPower
-
1
)
.
getpalette
()))
pixel
=
img
.
load
()
inkex
.
errormsg
(
"dither for "
+
str
(
len
(
palette
))
+
" colors palette..."
)
pixels
=
[]
pixel
=
img
.
load
()
for
line
in
range
(
0
,
imageDataheight
):
pixels
=
[]
r
=
[]
for
line
in
range
(
0
,
imageDataheight
):
for
row
in
range
(
0
,
imageDataWidth
):
r
=
[]
oldpix
=
pixel
[
row
,
line
]
for
row
in
range
(
0
,
imageDataWidth
):
newpix
=
min
(
palette
,
key
=
lambda
p
:
abs
(
p
-
oldpix
))
oldpix
=
pixel
[
row
,
line
]
quant_error
=
oldpix
-
newpix
newpix
=
min
(
palette
,
key
=
lambda
p
:
abs
(
p
-
oldpix
))
try
:
quant_error
=
oldpix
-
newpix
pixel
[
row
+
1
,
line
]
=
pixel
[
row
+
1
,
line
]
+
quant_error
*
7
/
16
try
:
pixel
[
row
-
1
,
line
+
1
]
=
pixel
[
row
-
1
,
line
+
1
]
+
quant_error
*
3
/
16
pixel
[
row
+
1
,
line
]
=
pixel
[
row
+
1
,
line
]
+
quant_error
*
7
/
16
pixel
[
row
,
line
+
1
]
=
pixel
[
row
,
line
+
1
]
+
quant_error
*
5
/
16
pixel
[
row
-
1
,
line
+
1
]
=
pixel
[
row
-
1
,
line
+
1
]
+
quant_error
*
3
/
16
pixel
[
row
+
1
,
line
+
1
]
=
pixel
[
row
+
1
,
line
+
1
]
+
quant_error
*
1
/
16
pixel
[
row
,
line
+
1
]
=
pixel
[
row
,
line
+
1
]
+
quant_error
*
5
/
16
except
:
pixel
[
row
+
1
,
line
+
1
]
=
pixel
[
row
+
1
,
line
+
1
]
+
quant_error
*
1
/
16
pass
except
:
pass
pixels
=
[[
pixel
[
r
,
l
]
for
r
in
xrange
(
imageDataWidth
)]
for
l
in
xrange
(
imageDataheight
)]
pixels
=
[[
pixel
[
r
,
l
]
for
r
in
xrange
(
imageDataWidth
)]
for
l
in
xrange
(
imageDataheight
)]
#Compile the pixels.
else
:
#pixels = list(img.getdata())
#Compile the pixels.
#pixels = [pixels[i * (imageDataWidth):(i + 1) * (imageDataWidth)] for i in xrange(imageDataheight)]
pixels
=
list
(
img
.
getdata
())
pixels
=
[
pixels
[
i
*
(
imageDataWidth
):(
i
+
1
)
*
(
imageDataWidth
)]
for
i
in
xrange
(
imageDataheight
)]
path
[
'type'
]
=
"raster"
path
[
'type'
]
=
"raster"
path
[
'width'
]
=
imageDataWidth
path
[
'width'
]
=
imageDataWidth
...
@@ -1191,6 +1192,7 @@ class Gcode_tools(inkex.Effect):
...
@@ -1191,6 +1192,7 @@ class Gcode_tools(inkex.Effect):
# Check if the layer specifies an alternative (from the default) feed rate
# Check if the layer specifies an alternative (from the default) feed rate
altfeed
=
layerParams
.
get
(
"feed"
,
self
.
options
.
feed
)
altfeed
=
layerParams
.
get
(
"feed"
,
self
.
options
.
feed
)
altppm
=
layerParams
.
get
(
"ppm"
,
None
)
altppm
=
layerParams
.
get
(
"ppm"
,
None
)
altdither
=
layerParams
.
get
(
"dither"
,
False
)
logger
.
write
(
"layer
%
s"
%
layerName
)
logger
.
write
(
"layer
%
s"
%
layerName
)
if
(
layerParams
):
if
(
layerParams
):
...
@@ -1224,12 +1226,12 @@ class Gcode_tools(inkex.Effect):
...
@@ -1224,12 +1226,12 @@ class Gcode_tools(inkex.Effect):
selected
.
remove
(
node
)
selected
.
remove
(
node
)
try
:
try
:
newPath
=
compile_paths
(
self
,
node
,
trans
,
laserPower
)
.
copy
();
newPath
=
compile_paths
(
self
,
node
,
trans
,
laserPower
,
altdither
)
.
copy
();
pathList
.
append
(
newPath
)
pathList
.
append
(
newPath
)
inkex
.
errormsg
(
"Built gcode for "
+
str
(
node
.
get
(
"id"
))
+
" - will be cut as
%
s."
%
(
newPath
[
'type'
])
)
inkex
.
errormsg
(
"Built gcode for "
+
str
(
node
.
get
(
"id"
))
+
" - will be cut as
%
s."
%
(
newPath
[
'type'
])
)
except
:
except
:
messageOnce
=
True
messageOnce
=
True
for
objectData
in
compile_paths
(
self
,
node
,
trans
,
laserPower
):
for
objectData
in
compile_paths
(
self
,
node
,
trans
,
laserPower
,
altdither
):
#if (messageOnce):
#if (messageOnce):
inkex
.
errormsg
(
"Built gcode for group "
+
str
(
node
.
get
(
"id"
))
+
", item
%
s - will be cut as
%
s."
%
(
objectData
[
'id'
],
objectData
[
'type'
])
)
inkex
.
errormsg
(
"Built gcode for group "
+
str
(
node
.
get
(
"id"
))
+
", item
%
s - will be cut as
%
s."
%
(
objectData
[
'id'
],
objectData
[
'type'
])
)
#messageOnce = False
#messageOnce = False
...
@@ -1294,12 +1296,12 @@ class Gcode_tools(inkex.Effect):
...
@@ -1294,12 +1296,12 @@ class Gcode_tools(inkex.Effect):
trans
=
simpletransform
.
parseTransform
(
""
)
trans
=
simpletransform
.
parseTransform
(
""
)
for
node
in
selected
:
for
node
in
selected
:
try
:
try
:
newPath
=
compile_paths
(
self
,
node
,
trans
,
laserPower
)
.
copy
();
newPath
=
compile_paths
(
self
,
node
,
trans
,
laserPower
,
altdither
)
.
copy
();
pathList
.
append
(
newPath
)
pathList
.
append
(
newPath
)
inkex
.
errormsg
(
"Built gcode for "
+
str
(
node
.
get
(
"id"
))
+
" - will be cut as
%
s."
%
(
newPath
[
'type'
])
)
inkex
.
errormsg
(
"Built gcode for "
+
str
(
node
.
get
(
"id"
))
+
" - will be cut as
%
s."
%
(
newPath
[
'type'
])
)
except
:
except
:
messageOnce
=
True
messageOnce
=
True
for
objectData
in
compile_paths
(
self
,
node
,
trans
,
laserPower
):
for
objectData
in
compile_paths
(
self
,
node
,
trans
,
laserPower
,
altdither
):
#if (messageOnce):
#if (messageOnce):
inkex
.
errormsg
(
"Built gcode for group "
+
str
(
node
.
get
(
"id"
))
+
", item
%
s - will be cut as
%
s."
%
(
objectData
[
'id'
],
objectData
[
'type'
])
)
inkex
.
errormsg
(
"Built gcode for group "
+
str
(
node
.
get
(
"id"
))
+
", item
%
s - will be cut as
%
s."
%
(
objectData
[
'id'
],
objectData
[
'type'
])
)
#messageOnce = False
#messageOnce = False
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment