27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/qrio/image_dumper.rb', line 27
def save_to_image(matrix, filename, options={})
png = ChunkyPNG::Image.new(
matrix.width,
matrix.height,
ChunkyPNG::Color::WHITE
)
(0..(matrix.width - 1)).to_a.each do |x|
(0..(matrix.height - 1)).to_a.each do |y|
png[x, y] = ChunkyPNG::Color::BLACK if matrix[x, y]
end
end
if options[:annotate].include?(:candidates)
@features[:candidates][:horizontal].each do |hmatch|
png.rect(*hmatch.to_coordinates, color(:green))
end
@features[:candidates][:vertical].each do |vmatch|
png.rect(*vmatch.to_coordinates, color(:magenta))
end
end
if options[:annotate].include?(:matches)
@features[:matches][:horizontal].each do |hmatch|
png.rect(*hmatch.to_coordinates, color(:green))
end
@features[:matches][:vertical].each do |vmatch|
png.rect(*vmatch.to_coordinates, color(:magenta))
end
end
if options[:annotate].include?(:finder_patterns)
@features[:finder_patterns].each do |finder_pattern|
png.rect(*finder_pattern.to_coordinates, color(:red))
end
end
if options[:annotate].include?(:angles)
@sampling_grid.angles[0, 100].each do |angle|
png.line_xiaolin_wu(*angle.to_coordinates, color(:cyan))
end
end
if options[:annotate].include?(:alignment_patterns)
png.rect(*@alignment_pattern.to_coordinates, color(:magenta))
end
if options[:annotate].include?(:extracted_pixels)
@sampling_grid. do |x, y|
png.circle(x, y, 1, color(:cyan))
end
end
png = png.crop(*@qr_bounds.to_point_size) if options[:crop]
png.save(filename, :fast_rgba)
end
|