graster
graster copied to clipboard
render_tiled_image is broken
The iterator is wrong, you can't do (0...@tiled_rows) because @tiled_rows is an array. You should iterate over the indexes of @tiled_rows. spans then is the current index.
(Maybe there is a smarter way to iterate over an array, but actually I don't know anything about ruby)
- (0...@tiled_rows.size).each do |spans|
- replace all occurences of spans by @tiled_rows[spans]
like this:
render a complete tiled image to gcode and gmask streams
def render_tiled_image gcode, gmask debug "rendering tiled image" job_id = job_hash hyst = -@scale[0]/2 gcode.comment "raster gcode for job #{job_id}" gcode.comment "image: #{@image.filename} #{@image.size.inspect}" gcode.comment "config: #{@config.inspect}"
gcode.preamble :feed => @config[:feed], :mask => true
gmask.preamble
@config[:repeat][1].times do |ytile|
debug "begin tile row #{ytile}"
ypix = 0
(0...@tiled_rows.size).each do |spans|
debug "pixel row #{ypix} is empty" if @tiled_rows[spans].empty?
unless @tiled_rows[spans].empty?
yinches = y_inches(ytile, ypix)
forward = @tiled_rows[spans][0][0] < @tiled_rows[spans][-1][1]
dir = forward ? 1 : -1
debug "pixel row #{ypix} at #{yinches} inches going #{forward ? 'forward' : 'backward'} with #{@tiled_rows[spans].size} spans"
gcode.g0 :x => @tiled_rows[spans][0][0] - dir*@config[:overshoot], :y => yinches
gcode.g1 :x => @tiled_rows[spans][-1][1] + dir*@config[:overshoot], :y => yinches
gmask.begin_row forward
@tiled_rows[spans].each {|span| gmask.span forward, span[0]+hyst, span[1]+hyst }
end # unless spans.empty?
ypix += 1
end # @image.each_row
debug "end tile row #{ytile}"
end # @config[:repeat][i].times
gcode.epilogue
end # def render_tiled_image
I have put this into a patch, and sent as a pull request to jebediah.