brother_escp 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/brother_escp.gemspec +1 -1
- data/lib/brother_escp/image_converter.rb +19 -9
- data/lib/brother_escp/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d8f1c2289adb405f2657967cd33f5949a144b52
|
4
|
+
data.tar.gz: 35cf9202fe9882c89b69c329f8cb2cc41b1e1af7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b7fbd2cdc9d0a38ed3a052f8442ed8e665ca656fba7be7172db05d5cd541d931157a584975d0bc3ba7b3986579e46022233841780c737e3fff0f471db75fc9c
|
7
|
+
data.tar.gz: f49972c117511694e02e9b7fbc20b9aad472101a459daf3b224be6ece55402486dca57abf59e42660f8da7bfd0fdd6698804dd518e6bacc97cb7485772b05ce5
|
data/README.md
CHANGED
data/brother_escp.gemspec
CHANGED
@@ -34,7 +34,7 @@ Gem::Specification.new do |spec|
|
|
34
34
|
spec.add_development_dependency 'bundler', '~> 1.13'
|
35
35
|
spec.add_development_dependency 'rake', '~> 10.0'
|
36
36
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
37
|
-
|
37
|
+
spec.add_development_dependency 'simplecov'
|
38
38
|
|
39
39
|
spec.add_dependency 'chunky_png'
|
40
40
|
end
|
@@ -34,13 +34,13 @@ module BrotherEscp
|
|
34
34
|
# @param image [ChunkyPNG::Image] Image to convert
|
35
35
|
# @return [Array] return an array of array, one array for each line, with one element for each byte
|
36
36
|
def convert(image:)
|
37
|
-
|
38
|
-
|
39
|
-
line_count =
|
40
|
-
# BrotherEscp.logger.debug "convert, line_count = #{line_count}"
|
37
|
+
lines = []
|
38
|
+
line_count = line_count(image: image)
|
39
|
+
BrotherEscp.logger.debug "convert, line_count = #{line_count}"
|
41
40
|
0.upto(line_count - 1) do |line_index|
|
42
41
|
lines << create_line(image: image, line_index: line_index)
|
43
42
|
end
|
43
|
+
BrotherEscp.logger.debug "convert, size by line: #{lines.map(&:size)}, total: #{lines.map(&:size).inject(:+)}"
|
44
44
|
lines
|
45
45
|
end
|
46
46
|
|
@@ -57,12 +57,14 @@ module BrotherEscp
|
|
57
57
|
|
58
58
|
private
|
59
59
|
|
60
|
-
def
|
61
|
-
|
62
|
-
|
60
|
+
def line_count(image:)
|
61
|
+
line_count = (image.height / line_height_in_pixels)
|
62
|
+
line_count += 1 if (image.height % line_height_in_pixels).nonzero?
|
63
|
+
line_count
|
63
64
|
end
|
64
65
|
|
65
66
|
def create_line(image:, line_index:)
|
67
|
+
BrotherEscp.logger.debug "create_line: #{line_index}"
|
66
68
|
line = []
|
67
69
|
0.upto(image.width - 1) do |x|
|
68
70
|
0.upto(line_height_in_bytes - 1) do |byte_offset|
|
@@ -76,13 +78,21 @@ module BrotherEscp
|
|
76
78
|
bits = String.new('')
|
77
79
|
0.upto(7) do |y_offset|
|
78
80
|
y = (line_index * line_height_in_pixels) + (byte_offset * 8) + y_offset
|
79
|
-
bit =
|
81
|
+
bit = convert_point(image: image, x: x, y: y)
|
80
82
|
# BrotherEscp.logger.debug "convert, line = #{line_index}, byte_offset = #{byte_offset}, x = #{x}, y = #{y}, bit: #{bit}"
|
81
83
|
bits << bit
|
82
84
|
end
|
83
85
|
bits.to_i(2)
|
84
86
|
end
|
85
87
|
|
88
|
+
def convert_point(image:, x:, y:)
|
89
|
+
if y >= image.height
|
90
|
+
'0'
|
91
|
+
else
|
92
|
+
convert_pixel_to_bw(image[x, y])
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
86
96
|
def convert_pixel_to_bw(pixel)
|
87
97
|
r = ChunkyPNG::Color.r(pixel)
|
88
98
|
g = ChunkyPNG::Color.g(pixel)
|
@@ -92,7 +102,7 @@ module BrotherEscp
|
|
92
102
|
# BrotherEscp.logger.debug "convert_pixel_to_bw: #{[r, g, b, a]}, px = #{px}"
|
93
103
|
BrotherEscp.logger.warn 'PNG images with alpha are not supported.' unless a == 255
|
94
104
|
|
95
|
-
px >
|
105
|
+
px > 230 ? '0' : '1'
|
96
106
|
end
|
97
107
|
end
|
98
108
|
end
|
data/lib/brother_escp/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: brother_escp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Bourguignon
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: chunky_png
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|