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
Show 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):
(
field
,
value
)
=
arg
.
split
(
"="
)
except
:
raise
ValueError
(
"Invalid argument in layer '
%
s'"
%
layerName
)
if
(
field
==
"feed"
or
field
==
"ppm"
):
if
(
field
==
"feed"
or
field
==
"ppm"
or
field
=
"dither"
):
try
:
value
=
float
(
value
)
except
:
raise
ValueError
(
"Invalid layer name '
%
s'"
%
value
)
params
[
field
]
=
value
logger
.
write
(
"
%
s ==
%
s"
%
(
field
,
value
))
...
...
@@ -951,7 +952,7 @@ class Gcode_tools(inkex.Effect):
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
mat
=
node
.
get
(
'transform'
,
None
)
path
=
{}
...
...
@@ -1019,6 +1020,7 @@ class Gcode_tools(inkex.Effect):
#Get the image size
imageDataWidth
,
imageDataheight
=
img
.
size
if
altdither
:
# dithering image and compile the pixels
inkex
.
errormsg
(
"start dithering."
)
palette
=
list
(
set
(
img
.
convert
(
"P"
,
palette
=
Image
.
ADAPTIVE
,
colors
=
laserPower
-
1
)
.
getpalette
()))
...
...
@@ -1040,11 +1042,10 @@ class Gcode_tools(inkex.Effect):
pass
pixels
=
[[
pixel
[
r
,
l
]
for
r
in
xrange
(
imageDataWidth
)]
for
l
in
xrange
(
imageDataheight
)]
else
:
#Compile the pixels.
#
pixels = list(img.getdata())
#
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
[
'width'
]
=
imageDataWidth
...
...
@@ -1191,6 +1192,7 @@ class Gcode_tools(inkex.Effect):
# Check if the layer specifies an alternative (from the default) feed rate
altfeed
=
layerParams
.
get
(
"feed"
,
self
.
options
.
feed
)
altppm
=
layerParams
.
get
(
"ppm"
,
None
)
altdither
=
layerParams
.
get
(
"dither"
,
False
)
logger
.
write
(
"layer
%
s"
%
layerName
)
if
(
layerParams
):
...
...
@@ -1224,12 +1226,12 @@ class Gcode_tools(inkex.Effect):
selected
.
remove
(
node
)
try
:
newPath
=
compile_paths
(
self
,
node
,
trans
,
laserPower
)
.
copy
();
newPath
=
compile_paths
(
self
,
node
,
trans
,
laserPower
,
altdither
)
.
copy
();
pathList
.
append
(
newPath
)
inkex
.
errormsg
(
"Built gcode for "
+
str
(
node
.
get
(
"id"
))
+
" - will be cut as
%
s."
%
(
newPath
[
'type'
])
)
except
:
messageOnce
=
True
for
objectData
in
compile_paths
(
self
,
node
,
trans
,
laserPower
):
for
objectData
in
compile_paths
(
self
,
node
,
trans
,
laserPower
,
altdither
):
#if (messageOnce):
inkex
.
errormsg
(
"Built gcode for group "
+
str
(
node
.
get
(
"id"
))
+
", item
%
s - will be cut as
%
s."
%
(
objectData
[
'id'
],
objectData
[
'type'
])
)
#messageOnce = False
...
...
@@ -1294,12 +1296,12 @@ class Gcode_tools(inkex.Effect):
trans
=
simpletransform
.
parseTransform
(
""
)
for
node
in
selected
:
try
:
newPath
=
compile_paths
(
self
,
node
,
trans
,
laserPower
)
.
copy
();
newPath
=
compile_paths
(
self
,
node
,
trans
,
laserPower
,
altdither
)
.
copy
();
pathList
.
append
(
newPath
)
inkex
.
errormsg
(
"Built gcode for "
+
str
(
node
.
get
(
"id"
))
+
" - will be cut as
%
s."
%
(
newPath
[
'type'
])
)
except
:
messageOnce
=
True
for
objectData
in
compile_paths
(
self
,
node
,
trans
,
laserPower
):
for
objectData
in
compile_paths
(
self
,
node
,
trans
,
laserPower
,
altdither
):
#if (messageOnce):
inkex
.
errormsg
(
"Built gcode for group "
+
str
(
node
.
get
(
"id"
))
+
", item
%
s - will be cut as
%
s."
%
(
objectData
[
'id'
],
objectData
[
'type'
])
)
#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