pnm 0.5.1 → 0.5.2
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/README.md +4 -7
- data/Rakefile +11 -10
- data/benchmark/bm_converter.rb +21 -17
- data/lib/pnm.rb +35 -39
- data/lib/pnm/converter.rb +45 -48
- data/lib/pnm/exceptions.rb +2 -0
- data/lib/pnm/image.rb +53 -44
- data/lib/pnm/parser.rb +32 -30
- data/lib/pnm/version.rb +4 -2
- data/pnm.gemspec +23 -20
- data/test/test_converter.rb +57 -54
- data/test/test_exceptions.rb +122 -120
- data/test/test_image.rb +110 -108
- data/test/test_parser.rb +45 -43
- data/test/test_pnm.rb +42 -40
- metadata +11 -12
data/lib/pnm/exceptions.rb
CHANGED
data/lib/pnm/image.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PNM
|
2
4
|
|
3
5
|
# Abstract base class for +PBM+, +PGM+, and +PPM+ images.
|
@@ -45,11 +47,11 @@ module PNM
|
|
45
47
|
type ||= detect_type(pixels, options[:maxgray])
|
46
48
|
|
47
49
|
# except for type detection, the maxgray option must be ignored for PBM
|
48
|
-
if type == :pbm
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
50
|
+
maxgray = if type == :pbm
|
51
|
+
nil
|
52
|
+
else
|
53
|
+
options[:maxgray]
|
54
|
+
end
|
53
55
|
|
54
56
|
image_class = case type
|
55
57
|
when :pbm
|
@@ -97,7 +99,7 @@ module PNM
|
|
97
99
|
to_binary
|
98
100
|
end
|
99
101
|
|
100
|
-
if file.
|
102
|
+
if file.is_a?(String)
|
101
103
|
File.binwrite(file, content)
|
102
104
|
else
|
103
105
|
file.binmode
|
@@ -119,7 +121,7 @@ module PNM
|
|
119
121
|
"#{type.to_s.upcase} #{width}x#{height} #{type_string}"
|
120
122
|
end
|
121
123
|
|
122
|
-
alias
|
124
|
+
alias to_s info
|
123
125
|
|
124
126
|
# Returns a string representation for debugging.
|
125
127
|
def inspect
|
@@ -135,28 +137,28 @@ module PNM
|
|
135
137
|
type == other.type && maxgray == other.maxgray && comment == other.comment && pixels == other.pixels
|
136
138
|
end
|
137
139
|
|
138
|
-
private
|
139
|
-
|
140
140
|
def self.assert_valid_array(pixels) # :nodoc:
|
141
141
|
assert_array_dimensions(pixels)
|
142
142
|
assert_pixel_types(pixels)
|
143
143
|
end
|
144
|
+
private_class_method :assert_valid_array
|
144
145
|
|
145
146
|
def self.assert_array_dimensions(pixels) # :nodoc:
|
146
147
|
msg = "invalid pixel data: Array expected"
|
147
|
-
raise PNM::ArgumentError, msg unless Array
|
148
|
+
raise PNM::ArgumentError, msg unless pixels.is_a?(Array)
|
148
149
|
|
149
150
|
msg = "invalid pixel array"
|
150
|
-
|
151
151
|
raise PNM::DataError, msg unless pixels.map(&:class).uniq == [Array]
|
152
|
+
|
152
153
|
width = pixels.first.size
|
153
|
-
raise PNM::DataError, msg if width
|
154
|
+
raise PNM::DataError, msg if width.zero?
|
154
155
|
raise PNM::DataError, msg unless pixels.map(&:size).uniq == [width]
|
155
156
|
end
|
157
|
+
private_class_method :assert_array_dimensions
|
156
158
|
|
157
159
|
def self.assert_pixel_types(pixels) # :nodoc:
|
158
160
|
pixel_values = pixels.flatten(1)
|
159
|
-
is_color =
|
161
|
+
is_color = pixel_values.first.is_a?(Array)
|
160
162
|
|
161
163
|
if is_color
|
162
164
|
pixel_values.each {|pixel| assert_valid_color_pixel(pixel) }
|
@@ -164,43 +166,47 @@ module PNM
|
|
164
166
|
pixel_values.each {|pixel| assert_valid_pixel(pixel) }
|
165
167
|
end
|
166
168
|
end
|
169
|
+
private_class_method :assert_pixel_types
|
167
170
|
|
168
171
|
def self.assert_valid_pixel(pixel) # :nodoc:
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
172
|
+
return if pixel.is_a?(Integer)
|
173
|
+
|
174
|
+
msg = "invalid pixel value: Integer expected - #{pixel.inspect}"
|
175
|
+
raise PNM::DataError, msg
|
173
176
|
end
|
177
|
+
private_class_method :assert_valid_pixel
|
174
178
|
|
175
179
|
def self.assert_valid_color_pixel(pixel) # :nodoc:
|
176
|
-
|
177
|
-
msg = "invalid pixel value: "
|
178
|
-
msg << "Array of 3 Integers expected - #{pixel.inspect}"
|
180
|
+
return if pixel.is_a?(Array) && pixel.size == 3 && pixel.all? {|p| p.is_a?(Integer) }
|
179
181
|
|
180
|
-
|
181
|
-
|
182
|
+
msg = "invalid pixel value: ".dup
|
183
|
+
msg << "Array of 3 Integers expected - #{pixel.inspect}"
|
184
|
+
raise PNM::DataError, msg
|
182
185
|
end
|
186
|
+
private_class_method :assert_valid_color_pixel
|
183
187
|
|
184
188
|
def self.assert_valid_maxgray(maxgray) # :nodoc:
|
185
189
|
return unless maxgray
|
190
|
+
return if maxgray.is_a?(Integer) && maxgray > 0 && maxgray <= 255
|
186
191
|
|
187
|
-
|
188
|
-
|
189
|
-
end
|
192
|
+
msg = "invalid maxgray value - #{maxgray.inspect}"
|
193
|
+
raise PNM::ArgumentError, msg
|
190
194
|
end
|
195
|
+
private_class_method :assert_valid_maxgray
|
191
196
|
|
192
197
|
def self.assert_valid_comment(comment) # :nodoc:
|
193
198
|
return unless comment
|
199
|
+
return if comment.is_a?(String)
|
194
200
|
|
195
|
-
|
196
|
-
|
197
|
-
end
|
201
|
+
msg = "invalid comment value - #{comment.inspect}"
|
202
|
+
raise PNM::ArgumentError, msg
|
198
203
|
end
|
204
|
+
private_class_method :assert_valid_comment
|
199
205
|
|
200
206
|
def self.sanitize_and_assert_valid_type(type) # :nodoc:
|
201
207
|
return unless type
|
202
208
|
|
203
|
-
type = type.to_sym if type.
|
209
|
+
type = type.to_sym if type.is_a?(String)
|
204
210
|
|
205
211
|
unless [:pbm, :pgm, :ppm].include?(type)
|
206
212
|
msg = "invalid image type - #{type.inspect}"
|
@@ -209,9 +215,10 @@ module PNM
|
|
209
215
|
|
210
216
|
type
|
211
217
|
end
|
218
|
+
private_class_method :sanitize_and_assert_valid_type
|
212
219
|
|
213
220
|
def self.detect_type(pixels, maxgray) # :nodoc:
|
214
|
-
if pixels.first.first.
|
221
|
+
if pixels.first.first.is_a?(Array)
|
215
222
|
:ppm
|
216
223
|
elsif (maxgray && maxgray > 1) || pixels.flatten.max > 1
|
217
224
|
:pgm
|
@@ -219,25 +226,27 @@ module PNM
|
|
219
226
|
:pbm
|
220
227
|
end
|
221
228
|
end
|
229
|
+
private_class_method :detect_type
|
230
|
+
|
231
|
+
private
|
222
232
|
|
223
233
|
def assert_grayscale_data # :nodoc:
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
234
|
+
return unless color_pixels?
|
235
|
+
|
236
|
+
msg = "specified type does not match RGB data - #{type.inspect}"
|
237
|
+
raise PNM::DataError, msg
|
228
238
|
end
|
229
239
|
|
230
240
|
def assert_pixel_value_range # :nodoc:
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
end
|
241
|
+
msg = "invalid data: value(s) greater than maxgray"
|
242
|
+
raise PNM::DataError, msg unless pixels.flatten.max <= maxgray
|
243
|
+
|
244
|
+
msg = "invalid data: value(s) less than zero"
|
245
|
+
raise PNM::DataError, msg unless pixels.flatten.min >= 0
|
237
246
|
end
|
238
247
|
|
239
248
|
def header_without_maxgray(encoding) # :nodoc:
|
240
|
-
header =
|
249
|
+
header = "#{PNM.magic_number[type][encoding]}\n".dup
|
241
250
|
comment_lines.each do |line|
|
242
251
|
header << (line.empty? ? "#\n" : "# #{line}\n")
|
243
252
|
end
|
@@ -252,7 +261,7 @@ module PNM
|
|
252
261
|
|
253
262
|
def comment_lines # :nodoc:
|
254
263
|
return [] unless comment
|
255
|
-
return [
|
264
|
+
return [""] if comment.empty?
|
256
265
|
|
257
266
|
keep_trailing_null_fields = -1 # magic value for split limit
|
258
267
|
comment.split(/\n/, keep_trailing_null_fields)
|
@@ -271,11 +280,11 @@ module PNM
|
|
271
280
|
end
|
272
281
|
|
273
282
|
def color_pixels? # :nodoc:
|
274
|
-
|
283
|
+
pixels.first.first.is_a?(Array)
|
275
284
|
end
|
276
285
|
|
277
286
|
def inspect_string_with_maxgray # :nodoc:
|
278
|
-
|
287
|
+
"#<%s:0x%x %s, maxgray=%d>" % [self.class.name, object_id, info, maxgray]
|
279
288
|
end
|
280
289
|
|
281
290
|
def inspect_string_without_maxgray # :nodoc:
|
data/lib/pnm/parser.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PNM
|
2
4
|
|
3
5
|
# @private
|
@@ -26,8 +28,8 @@ module PNM
|
|
26
28
|
until magic_number
|
27
29
|
token = next_token!(content)
|
28
30
|
|
29
|
-
if token.start_with?(
|
30
|
-
comments << token.gsub(/# */,
|
31
|
+
if token.start_with?("#")
|
32
|
+
comments << token.gsub(/# */, "")
|
31
33
|
else
|
32
34
|
magic_number = token
|
33
35
|
end
|
@@ -36,11 +38,11 @@ module PNM
|
|
36
38
|
assert_valid_magic_number(magic_number)
|
37
39
|
|
38
40
|
while tokens.size < token_number[magic_number]
|
39
|
-
content.gsub!(/\A[ \t\r\n]+/,
|
41
|
+
content.gsub!(/\A[ \t\r\n]+/, "")
|
40
42
|
token = next_token!(content)
|
41
43
|
|
42
|
-
if token.start_with?(
|
43
|
-
comments << token.gsub(/# */,
|
44
|
+
if token.start_with?("#")
|
45
|
+
comments << token.gsub(/# */, "")
|
44
46
|
else
|
45
47
|
tokens << token
|
46
48
|
end
|
@@ -61,10 +63,10 @@ module PNM
|
|
61
63
|
assert_value(maxgray, "maxgray") {|x| x > 0 && x <= 255 } if maxgray
|
62
64
|
|
63
65
|
result = {
|
64
|
-
:
|
65
|
-
:
|
66
|
-
:
|
67
|
-
:
|
66
|
+
magic_number: magic_number,
|
67
|
+
width: width,
|
68
|
+
height: height,
|
69
|
+
data: content
|
68
70
|
}
|
69
71
|
result[:maxgray] = maxgray if maxgray
|
70
72
|
result[:comments] = comments unless comments.empty?
|
@@ -74,24 +76,24 @@ module PNM
|
|
74
76
|
|
75
77
|
def self.token_number
|
76
78
|
{
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
79
|
+
"P1" => 2,
|
80
|
+
"P2" => 3,
|
81
|
+
"P3" => 3,
|
82
|
+
"P4" => 2,
|
83
|
+
"P5" => 3,
|
84
|
+
"P6" => 3
|
83
85
|
}
|
84
86
|
end
|
85
87
|
|
86
88
|
def self.next_token!(content)
|
87
|
-
delimiter = if content.start_with?(
|
89
|
+
delimiter = if content.start_with?("#")
|
88
90
|
"\n"
|
89
91
|
else
|
90
|
-
|
92
|
+
/[ \t\r\n]|(?=#)/
|
91
93
|
end
|
92
94
|
|
93
95
|
token, rest = content.split(delimiter, 2)
|
94
|
-
raise PNM::ParserError,
|
96
|
+
raise PNM::ParserError, "not enough tokens in file" unless rest
|
95
97
|
|
96
98
|
content.replace(rest)
|
97
99
|
|
@@ -99,24 +101,24 @@ module PNM
|
|
99
101
|
end
|
100
102
|
|
101
103
|
def self.assert_valid_magic_number(magic_number)
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
104
|
+
return if %w[P1 P2 P3 P4 P5 P6].include?(magic_number)
|
105
|
+
|
106
|
+
msg = "unknown magic number - `#{magic_number}'"
|
107
|
+
raise PNM::ParserError, msg
|
106
108
|
end
|
107
109
|
|
108
110
|
def self.assert_integer(value_string, value_name)
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
111
|
+
return if value_string =~ /\A[0-9]+\Z/
|
112
|
+
|
113
|
+
msg = "#{value_name} must be an integer - `#{value_string}'"
|
114
|
+
raise PNM::ParserError, msg
|
113
115
|
end
|
114
116
|
|
115
117
|
def self.assert_value(value, name)
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
118
|
+
return if yield(value)
|
119
|
+
|
120
|
+
msg = "invalid #{name} value - `#{value}'"
|
121
|
+
raise PNM::ParserError, msg
|
120
122
|
end
|
121
123
|
end
|
122
124
|
end
|
data/lib/pnm/version.rb
CHANGED
data/pnm.gemspec
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "./lib/pnm"
|
2
4
|
|
3
5
|
version = PNM::VERSION
|
4
6
|
date = PNM::DATE
|
@@ -6,40 +8,41 @@ homepage = PNM::HOMEPAGE
|
|
6
8
|
tagline = PNM::TAGLINE
|
7
9
|
|
8
10
|
Gem::Specification.new do |s|
|
9
|
-
s.name =
|
11
|
+
s.name = "pnm"
|
10
12
|
s.version = version
|
11
13
|
s.date = date
|
12
14
|
|
13
|
-
s.description =
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
s.description = "PNM is a pure Ruby library for creating, reading, " \
|
16
|
+
"and writing of PNM image files (Portable Anymap): " \
|
17
|
+
"PBM (Portable Bitmap), " \
|
18
|
+
"PGM (Portable Graymap), and " \
|
19
|
+
"PPM (Portable Pixmap)."
|
18
20
|
s.summary = "PNM - #{tagline}"
|
19
21
|
|
20
|
-
s.authors = [
|
21
|
-
s.email =
|
22
|
+
s.authors = ["Marcus Stollsteimer"]
|
23
|
+
s.email = "sto.mar@web.de"
|
22
24
|
s.homepage = homepage
|
23
25
|
|
24
|
-
s.license =
|
26
|
+
s.license = "GPL-3.0"
|
25
27
|
|
26
|
-
s.required_ruby_version =
|
28
|
+
s.required_ruby_version = ">= 1.9.3"
|
27
29
|
|
28
|
-
s.add_development_dependency
|
29
|
-
s.add_development_dependency
|
30
|
+
s.add_development_dependency "minitest", ">= 5.0"
|
31
|
+
s.add_development_dependency "rake", ">= 10.0"
|
30
32
|
|
31
|
-
s.require_paths = [
|
33
|
+
s.require_paths = ["lib"]
|
32
34
|
|
33
|
-
s.test_files = Dir.glob(
|
35
|
+
s.test_files = Dir.glob("test/**/test_*.rb")
|
34
36
|
|
35
|
-
s.files =
|
37
|
+
s.files =
|
38
|
+
%w[
|
36
39
|
README.md
|
37
40
|
Rakefile
|
38
41
|
pnm.gemspec
|
39
42
|
.yardopts
|
40
|
-
|
41
|
-
Dir.glob(
|
43
|
+
] +
|
44
|
+
Dir.glob("{benchmark,lib,test}/**/*")
|
42
45
|
|
43
|
-
s.extra_rdoc_files = [
|
44
|
-
s.rdoc_options = [
|
46
|
+
s.extra_rdoc_files = ["README.md"]
|
47
|
+
s.rdoc_options = ["--charset=UTF-8", "--main=README.md"]
|
45
48
|
end
|
data/test/test_converter.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# test_converter.rb: Unit tests for the PNM library.
|
2
4
|
#
|
3
|
-
# Copyright (C) 2013-
|
5
|
+
# Copyright (C) 2013-2019 Marcus Stollsteimer
|
4
6
|
|
5
|
-
require
|
6
|
-
require
|
7
|
+
require "minitest/autorun"
|
8
|
+
require "pnm/converter"
|
7
9
|
|
8
10
|
|
9
11
|
describe PNM::Converter do
|
@@ -11,43 +13,44 @@ describe PNM::Converter do
|
|
11
13
|
before do
|
12
14
|
@converter = PNM::Converter
|
13
15
|
|
14
|
-
@pbm6
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
@pbm6 = {
|
17
|
+
width: 6,
|
18
|
+
height: 2,
|
19
|
+
array: [[0, 1, 0, 0, 1, 1], [0, 0, 0, 1, 1, 1]],
|
20
|
+
ascii: "0 1 0 0 1 1\n0 0 0 1 1 1\n",
|
21
|
+
binary: ["4C1C"].pack("H*")
|
22
|
+
}
|
21
23
|
|
22
24
|
@pbm14 = {
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
width: 14,
|
26
|
+
height: 2,
|
27
|
+
array: [[0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0],
|
28
|
+
[0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1]],
|
29
|
+
ascii: "0 0 1 1 1 0 0 0 1 1 0 0 1 0\n0 1 0 1 1 0 1 1 1 0 1 1 1 1\n",
|
30
|
+
binary: ["38C85BBC"].pack("H*")
|
31
|
+
}
|
29
32
|
|
30
33
|
@pbm = @pbm14
|
31
34
|
|
32
|
-
@pgm =
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
@ppm =
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
it
|
35
|
+
@pgm = {
|
36
|
+
width: 4,
|
37
|
+
height: 3,
|
38
|
+
array: [[0, 85, 170, 255], [85, 170, 255, 0], [170, 255, 0, 85]],
|
39
|
+
ascii: "0 85 170 255\n85 170 255 0\n170 255 0 85\n",
|
40
|
+
binary: ["0055AAFF55AAFF00AAFF0055"].pack("H*")
|
41
|
+
}
|
42
|
+
|
43
|
+
@ppm = {
|
44
|
+
width: 3,
|
45
|
+
height: 2,
|
46
|
+
array: [[[0, 128, 255], [128, 255, 0], [255, 0, 128]],
|
47
|
+
[[255, 128, 0], [128, 0, 255], [0, 255, 128]]],
|
48
|
+
ascii: "0 128 255 128 255 0 255 0 128\n255 128 0 128 0 255 0 255 128\n",
|
49
|
+
binary: ["0080FF80FF00FF0080FF80008000FF00FF80"].pack("H*")
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
it "can convert from ASCII encoded PBM data" do
|
51
54
|
width = @pbm[:width]
|
52
55
|
height = @pbm[:height]
|
53
56
|
data = @pbm[:ascii]
|
@@ -56,7 +59,7 @@ describe PNM::Converter do
|
|
56
59
|
@converter.ascii2array(:pbm, width, height, data).must_equal expected
|
57
60
|
end
|
58
61
|
|
59
|
-
it
|
62
|
+
it "can convert from ASCII encoded PGM data" do
|
60
63
|
width = @pgm[:width]
|
61
64
|
height = @pgm[:height]
|
62
65
|
data = @pgm[:ascii]
|
@@ -65,7 +68,7 @@ describe PNM::Converter do
|
|
65
68
|
@converter.ascii2array(:pgm, width, height, data).must_equal expected
|
66
69
|
end
|
67
70
|
|
68
|
-
it
|
71
|
+
it "can convert from ASCII encoded PPM data" do
|
69
72
|
width = @ppm[:width]
|
70
73
|
height = @ppm[:height]
|
71
74
|
data = @ppm[:ascii]
|
@@ -74,7 +77,7 @@ describe PNM::Converter do
|
|
74
77
|
@converter.ascii2array(:ppm, width, height, data).must_equal expected
|
75
78
|
end
|
76
79
|
|
77
|
-
it
|
80
|
+
it "accepts ASCII encoded PBM data with omitted whitespace" do
|
78
81
|
width = 4
|
79
82
|
height = 3
|
80
83
|
data = " 010100\n000110"
|
@@ -83,7 +86,7 @@ describe PNM::Converter do
|
|
83
86
|
@converter.ascii2array(:pbm, width, height, data).must_equal expected
|
84
87
|
end
|
85
88
|
|
86
|
-
it
|
89
|
+
it "accepts ASCII encoded PGM data with arbitrary whitespace" do
|
87
90
|
width = 4
|
88
91
|
height = 3
|
89
92
|
data = " \n 10 90\t170\r250\n90 \t170 250 \t\r\n\t 10\n\n\n170\n250\n10\n90\n"
|
@@ -92,7 +95,7 @@ describe PNM::Converter do
|
|
92
95
|
@converter.ascii2array(:pgm, width, height, data).must_equal expected
|
93
96
|
end
|
94
97
|
|
95
|
-
it
|
98
|
+
it "can convert from binary encoded PBM data (width 6)" do
|
96
99
|
width = @pbm6[:width]
|
97
100
|
height = @pbm6[:height]
|
98
101
|
data = @pbm6[:binary]
|
@@ -101,7 +104,7 @@ describe PNM::Converter do
|
|
101
104
|
@converter.binary2array(:pbm, width, height, data).must_equal expected
|
102
105
|
end
|
103
106
|
|
104
|
-
it
|
107
|
+
it "can convert from binary encoded PBM data (width 14)" do
|
105
108
|
width = @pbm14[:width]
|
106
109
|
height = @pbm14[:height]
|
107
110
|
data = @pbm14[:binary]
|
@@ -110,7 +113,7 @@ describe PNM::Converter do
|
|
110
113
|
@converter.binary2array(:pbm, width, height, data).must_equal expected
|
111
114
|
end
|
112
115
|
|
113
|
-
it
|
116
|
+
it "can convert from binary encoded PGM data" do
|
114
117
|
width = @pgm[:width]
|
115
118
|
height = @pgm[:height]
|
116
119
|
data = @pgm[:binary]
|
@@ -119,7 +122,7 @@ describe PNM::Converter do
|
|
119
122
|
@converter.binary2array(:pgm, width, height, data).must_equal expected
|
120
123
|
end
|
121
124
|
|
122
|
-
it
|
125
|
+
it "can convert from binary encoded PPM data" do
|
123
126
|
width = @ppm[:width]
|
124
127
|
height = @ppm[:height]
|
125
128
|
data = @ppm[:binary]
|
@@ -128,7 +131,7 @@ describe PNM::Converter do
|
|
128
131
|
@converter.binary2array(:ppm, width, height, data).must_equal expected
|
129
132
|
end
|
130
133
|
|
131
|
-
it
|
134
|
+
it "accepts an additional whitespace character for binary encoded data" do
|
132
135
|
width = @pbm14[:width]
|
133
136
|
height = @pbm14[:height]
|
134
137
|
data = @pbm14[:binary] + "\t"
|
@@ -137,56 +140,56 @@ describe PNM::Converter do
|
|
137
140
|
@converter.binary2array(:pbm, width, height, data).must_equal expected
|
138
141
|
end
|
139
142
|
|
140
|
-
it
|
143
|
+
it "can convert to ASCII encoded PBM data" do
|
141
144
|
data = @pbm[:array]
|
142
145
|
expected = @pbm[:ascii]
|
143
146
|
|
144
147
|
@converter.array2ascii(data).must_equal expected
|
145
148
|
end
|
146
149
|
|
147
|
-
it
|
150
|
+
it "can convert to ASCII encoded PGM data" do
|
148
151
|
data = @pgm[:array]
|
149
152
|
expected = @pgm[:ascii]
|
150
153
|
|
151
154
|
@converter.array2ascii(data).must_equal expected
|
152
155
|
end
|
153
156
|
|
154
|
-
it
|
157
|
+
it "can convert to ASCII encoded PPM data" do
|
155
158
|
data = @ppm[:array]
|
156
159
|
expected = @ppm[:ascii]
|
157
160
|
|
158
161
|
@converter.array2ascii(data).must_equal expected
|
159
162
|
end
|
160
163
|
|
161
|
-
it
|
164
|
+
it "can convert to binary encoded PBM data (width 6)" do
|
162
165
|
data = @pbm6[:array]
|
163
166
|
expected = @pbm6[:binary]
|
164
167
|
|
165
168
|
@converter.array2binary(:pbm, data).must_equal expected
|
166
169
|
end
|
167
170
|
|
168
|
-
it
|
171
|
+
it "can convert to binary encoded PBM data (width 14)" do
|
169
172
|
data = @pbm14[:array]
|
170
173
|
expected = @pbm14[:binary]
|
171
174
|
|
172
175
|
@converter.array2binary(:pbm, data).must_equal expected
|
173
176
|
end
|
174
177
|
|
175
|
-
it
|
178
|
+
it "can convert to binary encoded PGM data" do
|
176
179
|
data = @pgm[:array]
|
177
180
|
expected = @pgm[:binary]
|
178
181
|
|
179
182
|
@converter.array2binary(:pgm, data).must_equal expected
|
180
183
|
end
|
181
184
|
|
182
|
-
it
|
185
|
+
it "can convert to binary encoded PPM data" do
|
183
186
|
data = @ppm[:array]
|
184
187
|
expected = @ppm[:binary]
|
185
188
|
|
186
189
|
@converter.array2binary(:ppm, data).must_equal expected
|
187
190
|
end
|
188
191
|
|
189
|
-
it
|
192
|
+
it "can calculate correct byte widths for a PBM image" do
|
190
193
|
@converter.byte_width(:pbm, 0).must_equal 0
|
191
194
|
@converter.byte_width(:pbm, 1).must_equal 1
|
192
195
|
@converter.byte_width(:pbm, 7).must_equal 1
|
@@ -196,11 +199,11 @@ describe PNM::Converter do
|
|
196
199
|
@converter.byte_width(:pbm, 65).must_equal 9
|
197
200
|
end
|
198
201
|
|
199
|
-
it
|
202
|
+
it "can calculate correct byte widths for a PGM image" do
|
200
203
|
@converter.byte_width(:pgm, 13).must_equal 13
|
201
204
|
end
|
202
205
|
|
203
|
-
it
|
206
|
+
it "can calculate correct byte widths for a PPM image" do
|
204
207
|
@converter.byte_width(:ppm, 13).must_equal 39
|
205
208
|
end
|
206
209
|
end
|