pnm 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d7322d852ff78a5d37b2b0b15dcecc9780cec7ed
4
- data.tar.gz: 0583fe925b357baed8eb99f57d3a202340f839fe
3
+ metadata.gz: 6a67b8402e945e8d27962981006428433aa2bf5d
4
+ data.tar.gz: adc0238ba64a48028c43c4a2daa60d94e3074297
5
5
  SHA512:
6
- metadata.gz: cf955fa0db64c7b42676f332a37f65b72cc6049fb28d7cba270a08fbf1c62a234508cd9ee8e01bd0bfb27d937235dd54b83c1d7b3ed9bad5f98387abde622fc2
7
- data.tar.gz: b603ee0e3e53392553af4e121ff1cd62160116600fc037ad7016effbcab0c4a4c8635daf71dfb67de2840babab9005a7caf30904a71f682b941b1aaacbaa4284
6
+ metadata.gz: 3ac2f0cf568b65fe2d70e6b9665db5c88c8011003446bea7858a74c2367bbc71d6af34c855b669dc7c1e2682aef15d7571a0c24ce73312c09c4c84882143ef7f
7
+ data.tar.gz: 3501103cd58fa19bf20ef47e9f482ed4d1243c9bc2acf8b4e1b270e5a1a46cb94d4162b4efd6d32547f251bace34e21a0c385766bd41f62780cd3562b93002b8
data/README.md CHANGED
@@ -91,7 +91,7 @@ Requirements
91
91
 
92
92
  - PNM has been tested with
93
93
 
94
- - Ruby 2.1.3,
94
+ - Ruby 2.1.5,
95
95
  - Ruby 2.0.0 on Linux and on Windows,
96
96
  - Ruby 1.9.3,
97
97
  - JRuby 1.7.16,
data/lib/pnm/image.rb CHANGED
@@ -47,6 +47,8 @@ module PNM
47
47
  # By explicitly setting +type+, PGM images can be
48
48
  # created from bilevel pixel data, and PPM images can be
49
49
  # created from bilevel or gray pixel data.
50
+ # String values (<tt>"pbm"</tt>, <tt>"pgm"</tt>,
51
+ # or <tt>"ppm"</tt>) are also accepted.
50
52
  # +maxgray+:: The maximum gray or color value.
51
53
  # For PGM and PPM, +maxgray+ must be less or equal 255
52
54
  # (the default value).
@@ -61,6 +63,8 @@ module PNM
61
63
  @comment = options[:comment]
62
64
  @pixels = pixels.dup
63
65
 
66
+ @type = @type.to_sym if @type && String === @type
67
+
64
68
  assert_valid_type if @type
65
69
  assert_valid_maxgray if @maxgray
66
70
  assert_valid_comment if @comment
@@ -124,7 +128,7 @@ module PNM
124
128
 
125
129
  private
126
130
 
127
- def type_string
131
+ def type_string # :nodoc:
128
132
  case type
129
133
  when :pbm
130
134
  'Bilevel'
@@ -135,7 +139,7 @@ module PNM
135
139
  end
136
140
  end
137
141
 
138
- def detect_type(pixels, maxgray)
142
+ def detect_type(pixels, maxgray) # :nodoc:
139
143
  if pixels.first.first.kind_of?(Array)
140
144
  :ppm
141
145
  elsif (maxgray && maxgray > 1) || pixels.flatten.max > 1
@@ -145,7 +149,7 @@ module PNM
145
149
  end
146
150
  end
147
151
 
148
- def assert_valid_array
152
+ def assert_valid_array # :nodoc:
149
153
  msg = "invalid pixel data: Array expected"
150
154
  raise PNM::ArgumentError, msg unless Array === pixels
151
155
 
@@ -166,14 +170,14 @@ module PNM
166
170
  end
167
171
  end
168
172
 
169
- def assert_valid_pixel(pixel)
173
+ def assert_valid_pixel(pixel) # :nodoc:
170
174
  unless Fixnum === pixel
171
175
  msg = "invalid pixel value: Fixnum expected - #{pixel.inspect}"
172
176
  raise PNM::DataError, msg
173
177
  end
174
178
  end
175
179
 
176
- def assert_valid_color_pixel(pixel)
180
+ def assert_valid_color_pixel(pixel) # :nodoc:
177
181
  unless Array === pixel && pixel.map(&:class) == [Fixnum, Fixnum, Fixnum]
178
182
  msg = "invalid pixel value: "
179
183
  msg << "Array of 3 Fixnums expected - #{pixel.inspect}"
@@ -182,33 +186,33 @@ module PNM
182
186
  end
183
187
  end
184
188
 
185
- def assert_valid_type
189
+ def assert_valid_type # :nodoc:
186
190
  unless [:pbm, :pgm, :ppm].include?(type)
187
191
  msg = "invalid image type - #{type.inspect}"
188
192
  raise PNM::ArgumentError, msg
189
193
  end
190
194
  end
191
195
 
192
- def assert_matching_type_and_data
196
+ def assert_matching_type_and_data # :nodoc:
193
197
  if Array === pixels.first.first && [:pbm, :pgm].include?(type)
194
198
  msg = "specified type does not match data - #{type.inspect}"
195
199
  raise PNM::DataError, msg
196
200
  end
197
201
  end
198
202
 
199
- def assert_valid_maxgray
203
+ def assert_valid_maxgray # :nodoc:
200
204
  unless Fixnum === maxgray && maxgray > 0 && maxgray <= 255
201
205
  raise PNM::ArgumentError, "invalid maxgray value - #{maxgray.inspect}"
202
206
  end
203
207
  end
204
208
 
205
- def assert_valid_comment
209
+ def assert_valid_comment # :nodoc:
206
210
  unless String === comment
207
211
  raise PNM::ArgumentError, "invalid comment value - #{comment.inspect}"
208
212
  end
209
213
  end
210
214
 
211
- def assert_valid_pixel_values
215
+ def assert_valid_pixel_values # :nodoc:
212
216
  unless pixels.flatten.max <= maxgray
213
217
  raise PNM::DataError, "invalid data: value(s) greater than maxgray"
214
218
  end
@@ -217,7 +221,7 @@ module PNM
217
221
  end
218
222
  end
219
223
 
220
- def header(encoding)
224
+ def header(encoding) # :nodoc:
221
225
  header = "#{PNM.magic_number[type][encoding]}\n"
222
226
  comment_lines.each do |line|
223
227
  header << (line.empty? ? "#\n" : "# #{line}\n")
@@ -228,7 +232,7 @@ module PNM
228
232
  header
229
233
  end
230
234
 
231
- def comment_lines
235
+ def comment_lines # :nodoc:
232
236
  return [] unless comment
233
237
  return [''] if comment.empty?
234
238
 
@@ -236,19 +240,19 @@ module PNM
236
240
  comment.split(/\n/, keep_trailing_null_fields)
237
241
  end
238
242
 
239
- def to_ascii
243
+ def to_ascii # :nodoc:
240
244
  data_string = Converter.array2ascii(pixels)
241
245
 
242
246
  header(:ascii) << data_string
243
247
  end
244
248
 
245
- def to_binary
249
+ def to_binary # :nodoc:
246
250
  data_string = Converter.array2binary(type, pixels)
247
251
 
248
252
  header(:binary) << data_string
249
253
  end
250
254
 
251
- def gray_to_rgb(gray_value)
255
+ def gray_to_rgb(gray_value) # :nodoc:
252
256
  Array.new(3, gray_value)
253
257
  end
254
258
  end
data/lib/pnm/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module PNM
2
- VERSION = '0.3.3'
3
- DATE = '2014-11-20'
2
+ VERSION = '0.3.4'
3
+ DATE = '2014-11-21'
4
4
  end
@@ -14,9 +14,9 @@ describe 'PNM::Image.new' do
14
14
  lambda { PNM::Image.new(data) }.must_raise PNM::ArgumentError
15
15
  end
16
16
 
17
- it 'raises an exception for invalid type (String)' do
17
+ it 'raises an exception for invalid type' do
18
18
  data = [[0, 0], [0, 0]]
19
- lambda { PNM::Image.new(data, :type => 'pbm') }.must_raise PNM::ArgumentError
19
+ lambda { PNM::Image.new(data, :type => :abc) }.must_raise PNM::ArgumentError
20
20
  end
21
21
 
22
22
  it 'raises an exception for invalid maxgray (String)' do
data/test/test_image.rb CHANGED
@@ -81,6 +81,11 @@ describe PNM::Image do
81
81
  image.maxgray.must_equal 255
82
82
  end
83
83
 
84
+ it 'also accepts types given as string instead of symbol' do
85
+ image = PNM::Image.new([[0,1,0], [1,0,1]], {:type => "pgm"})
86
+ image.type.must_equal :pgm
87
+ end
88
+
84
89
  it 'can create a grayscale image from bilevel values (using maxgray)' do
85
90
  image = PNM::Image.new([[0,1,0], [1,0,1]], {:maxgray => 2})
86
91
  image.type.must_equal :pgm
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pnm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcus Stollsteimer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-20 00:00:00.000000000 Z
11
+ date: 2014-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake