imagewriter 0.1.0 → 0.1.1
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 +5 -5
- data/bin/imagewriter +46 -83
- metadata +4 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 445301d5910befd2d411decc7ca6acc868d12d32098d88a32b60a7f9627c0dc2
|
4
|
+
data.tar.gz: 530dbfe53de7beebd221487c819238074d17c244861eab0a14a17c37d1266857
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f9d9e6169dd80b4cc1a21c2c06f72bcdb077d9c4fd7913a49455cea7811d090e1026d3888681a6b0b76beba59f73fb41add2d1ed3220d24223f7a6b55a42d4a
|
7
|
+
data.tar.gz: 46c97c004144add6edf0b38284e1275fcccef2a3423f7b73bf97e97ec60b3b60ff8fb988f660cdea733043952b2c7c638de5250e46351949f1b5e220a78d53b4
|
data/bin/imagewriter
CHANGED
@@ -26,15 +26,43 @@ class ImageWriter
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
+
## Prints an image at double vertical resolution (144 dpi) by
|
30
|
+
## writing interleaved rows in a back-and-forth "double pass".
|
29
31
|
def print!
|
30
32
|
init_printer!
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
## Higher quality is achieved by printing fewer lines at a time,
|
35
|
+
## and dovetailing these lines with the adjacent double-passes
|
36
|
+
dovetail = 2 * (@quality-1)
|
37
|
+
lines_per_double_pass = 16 - dovetail
|
38
|
+
|
39
|
+
## Make bitmasks for first- and second-pass bytes
|
40
|
+
half_dovetail = (dovetail / 2).to_i
|
41
|
+
dovemask1 = 0xff >> half_dovetail
|
42
|
+
dovemask2 = 0xff << half_dovetail
|
43
|
+
|
44
|
+
width = [@hdpi * 8, @img.width].min
|
45
|
+
|
46
|
+
y = -16 # start here to provide any necessary margin for dovetailing
|
47
|
+
|
48
|
+
while (y <= @img.height) do
|
49
|
+
bytes1 = 0.upto(width).map{|x| b1(x, y) & dovemask1}
|
50
|
+
bytes2 = 0.upto(width).map{|x| b2(x, y) & dovemask2}
|
51
|
+
|
52
|
+
printf "\eG%.4d", bytes1.length
|
53
|
+
bytes1.each{|b| print b.chr}
|
54
|
+
printf "\r"
|
55
|
+
|
56
|
+
printf "\x1F1" # one line feed
|
57
|
+
|
58
|
+
printf "\eG%.4d", bytes2.length
|
59
|
+
bytes2.each{|b| print b.chr}
|
60
|
+
printf "\r"
|
61
|
+
|
62
|
+
printf "\x1F%s", LINE_FEEDS[lines_per_double_pass - 1]
|
63
|
+
|
64
|
+
sleep @sleep
|
65
|
+
y += lines_per_double_pass
|
38
66
|
end
|
39
67
|
end
|
40
68
|
|
@@ -71,26 +99,24 @@ class ImageWriter
|
|
71
99
|
15 => "?"
|
72
100
|
}
|
73
101
|
|
74
|
-
QUALITY = ["regular", "enhanced", "best"]
|
75
|
-
|
76
102
|
def parse_argv!(argv)
|
77
103
|
options = {
|
78
104
|
hdpi: 144,
|
79
|
-
quality:
|
105
|
+
quality: 1,
|
80
106
|
sleep: 0.75
|
81
107
|
}
|
82
108
|
|
83
109
|
help = nil
|
84
110
|
OptionParser.new do |parser|
|
85
111
|
parser.banner = <<-EOT
|
86
|
-
Usage: imagewriter [options] filename.png
|
112
|
+
Usage: imagewriter [options] filename.png
|
87
113
|
Vertical resolution is 144 dpi; horizontal resolution is adjustable.
|
88
114
|
Max printable width is 8 inches, or 8 * horizontal DPI pixels.
|
89
115
|
Options:
|
90
116
|
EOT
|
91
117
|
|
92
118
|
dpis = HORIZ_DPI_CODE.keys.join(", ")
|
93
|
-
parser.on('-H', '--horizontal DPI', Integer, "Horizontal DPI
|
119
|
+
parser.on('-H', '--horizontal DPI', Integer, "Horizontal DPI. One of: #{dpis}; default #{options[:hdpi]}") do |n|
|
94
120
|
if HORIZ_DPI_CODE[n]
|
95
121
|
options[:hdpi] = n
|
96
122
|
else
|
@@ -100,17 +126,17 @@ Options:
|
|
100
126
|
end
|
101
127
|
end
|
102
128
|
|
103
|
-
parser.on("-q", "--quality QUALITY", "Print quality (
|
104
|
-
if
|
129
|
+
parser.on("-q", "--quality QUALITY", Integer, "Print quality. 1 (fastest) to 8 (best); default #{options[:quality]}") do |n|
|
130
|
+
if n > 0 && n < 9
|
105
131
|
options[:quality] = n
|
106
132
|
else
|
107
|
-
STDERR.puts "Bad quality setting #{n} (must be
|
133
|
+
STDERR.puts "Bad quality setting #{n} (must be 1-8)"
|
108
134
|
STDERR.puts parser
|
109
135
|
exit 1
|
110
136
|
end
|
111
137
|
end
|
112
138
|
|
113
|
-
parser.on("-s", "--sleep", Float, "Sleep this many seconds between passes
|
139
|
+
parser.on("-s", "--sleep", Float, "Sleep this many seconds between passes. Default #{options[:sleep]}") do |n|
|
114
140
|
options[:sleep] = n
|
115
141
|
end
|
116
142
|
|
@@ -134,34 +160,8 @@ Options:
|
|
134
160
|
end
|
135
161
|
end
|
136
162
|
|
137
|
-
|
138
|
-
|
139
|
-
y = y0
|
140
|
-
width = [@hdpi * 8, @img.width].min
|
141
|
-
|
142
|
-
0.upto(double_passes) do
|
143
|
-
bytes1 = 0.upto(width).map{|x| self.send(b1_fun, x, y)}
|
144
|
-
bytes2 = 0.upto(width).map{|x| self.send(b2_fun, x, y)}
|
145
|
-
|
146
|
-
printf "\eG%.4d", width
|
147
|
-
bytes1.each{|b| print b.chr}
|
148
|
-
printf "\r"
|
149
|
-
|
150
|
-
printf "\x1F%s", LINE_FEEDS[lf1]
|
151
|
-
|
152
|
-
printf "\eG%.4d", width
|
153
|
-
bytes2.each{|b| print b.chr}
|
154
|
-
printf "\r"
|
155
|
-
|
156
|
-
printf "\x1F%s", LINE_FEEDS[lf2]
|
157
|
-
|
158
|
-
sleep @sleep
|
159
|
-
y += lines_per_double_pass
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
### Regular quality: 16 lines per double-pass
|
164
|
-
def b1_v144_regular(x, y)
|
163
|
+
## Returns data byte for first-pass lines
|
164
|
+
def b1(x, y)
|
165
165
|
0 +
|
166
166
|
0b00000001 * get(x, y) +
|
167
167
|
0b00000010 * get(x, y+2) +
|
@@ -173,7 +173,8 @@ Options:
|
|
173
173
|
0b10000000 * get(x, y+14)
|
174
174
|
end
|
175
175
|
|
176
|
-
|
176
|
+
## Returns data byte for second-pass lines
|
177
|
+
def b2(x, y)
|
177
178
|
0 +
|
178
179
|
0b00000001 * get(x, y+1) +
|
179
180
|
0b00000010 * get(x, y+3) +
|
@@ -185,47 +186,9 @@ Options:
|
|
185
186
|
0b10000000 * get(x, y+15)
|
186
187
|
end
|
187
188
|
|
188
|
-
### Enhanced quality: 12 lines per double-pass, 4 dots dovetailed
|
189
|
-
def b1_v144_enhanced(x, y)
|
190
|
-
0 +
|
191
|
-
0b00000001 * get(x, y) +
|
192
|
-
0b00000010 * get(x, y+2) +
|
193
|
-
0b00000100 * get(x, y+4) +
|
194
|
-
0b00001000 * get(x, y+6) +
|
195
|
-
0b00010000 * get(x, y+8) +
|
196
|
-
0b00100000 * get(x, y+10)
|
197
|
-
#0b01000000 * get(x, y+12) +
|
198
|
-
#0b10000000 * get(x, y+14)
|
199
|
-
end
|
200
|
-
|
201
|
-
def b2_v144_enhanced(x, y)
|
202
|
-
0 +
|
203
|
-
#0b00000001 * get(x, y+1) +
|
204
|
-
#0b00000010 * get(x, y+3) +
|
205
|
-
0b00000100 * get(x, y+5) +
|
206
|
-
0b00001000 * get(x, y+7) +
|
207
|
-
0b00010000 * get(x, y+9) +
|
208
|
-
0b00100000 * get(x, y+11) +
|
209
|
-
0b01000000 * get(x, y+13) +
|
210
|
-
0b10000000 * get(x, y+15)
|
211
|
-
end
|
212
|
-
|
213
|
-
### Best quality: 4 lines per double-pass
|
214
|
-
def b1_v144_best(x, y)
|
215
|
-
0 +
|
216
|
-
0b00000001 * get(x, y) +
|
217
|
-
0b00000010 * get(x, y+2)
|
218
|
-
end
|
219
|
-
|
220
|
-
def b2_v144_best(x, y)
|
221
|
-
0 +
|
222
|
-
0b00000001 * get(x, y+1) +
|
223
|
-
0b00000010 * get(x, y+3)
|
224
|
-
end
|
225
|
-
|
226
189
|
## Returns 0 for black pixels that exist, 1 otherwise
|
227
190
|
def get(x, y)
|
228
|
-
x = @img[x, y] & 0xffffff00
|
191
|
+
x = @img[x, y] & 0xffffff00 # strip alpha channel
|
229
192
|
return 0 if x > 0
|
230
193
|
1
|
231
194
|
rescue
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: imagewriter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pete gamache
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-11-
|
11
|
+
date: 2020-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: pete@gamache.org
|
@@ -37,10 +37,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
37
37
|
- !ruby/object:Gem::Version
|
38
38
|
version: '0'
|
39
39
|
requirements: []
|
40
|
-
|
41
|
-
rubygems_version: 2.5.2.3
|
40
|
+
rubygems_version: 3.1.2
|
42
41
|
signing_key:
|
43
42
|
specification_version: 4
|
44
|
-
summary:
|
45
|
-
printer
|
43
|
+
summary: Prints B&W PNG images on an Apple Imagewriter or ImageWriter II printer
|
46
44
|
test_files: []
|