pnm 0.3.2 → 0.3.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e52a4e6c563756871e2e3da51503fcaad0afda14
4
- data.tar.gz: 62cc1dc3452e1fa8678c918fc12cbd9c66288d6d
3
+ metadata.gz: d7322d852ff78a5d37b2b0b15dcecc9780cec7ed
4
+ data.tar.gz: 0583fe925b357baed8eb99f57d3a202340f839fe
5
5
  SHA512:
6
- metadata.gz: 331134341d9a7fe5264c5e1fb4504dc6c5886ee63cf5648cad7f4958a8a15a14b03e59a0d6fb5b2b7b176553172b2d7397536bd8d16232437cc6de85c39947a4
7
- data.tar.gz: 5808baad06957ebd956fa4dbe2c58898376427598c942634a63d2ae7a25aa1b9423c1afce226db31c9b883c51968aa089200f99d81018dfa74be2ce307b272bd
6
+ metadata.gz: cf955fa0db64c7b42676f332a37f65b72cc6049fb28d7cba270a08fbf1c62a234508cd9ee8e01bd0bfb27d937235dd54b83c1d7b3ed9bad5f98387abde622fc2
7
+ data.tar.gz: b603ee0e3e53392553af4e121ff1cd62160116600fc037ad7016effbcab0c4a4c8635daf71dfb67de2840babab9005a7caf30904a71f682b941b1aaacbaa4284
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --no-private
data/README.md CHANGED
@@ -34,6 +34,7 @@ image = PNM::Image.new(pixels, options)
34
34
 
35
35
  # retrieve some image properties
36
36
  image.info # => "PGM 3x2 Grayscale"
37
+ image.type # => :pgm
37
38
  image.width # => 3
38
39
  image.height # => 2
39
40
  ```
data/lib/pnm.rb CHANGED
@@ -40,6 +40,7 @@ require_relative 'pnm/exceptions'
40
40
  #
41
41
  # # retrieve some image properties
42
42
  # image.info # => "PGM 3x2 Grayscale"
43
+ # image.type # => :pgm
43
44
  # image.width # => 3
44
45
  # image.height # => 2
45
46
  #
@@ -83,28 +84,13 @@ require_relative 'pnm/exceptions'
83
84
  #
84
85
  # License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
85
86
  #
86
- #--
87
- #
88
- # == PNM magic numbers
89
- #
90
- # Magic Number Type Encoding
91
- # ------------ ---------------- -------
92
- # P1 Portable bitmap ASCII
93
- # P2 Portable graymap ASCII
94
- # P3 Portable pixmap ASCII
95
- # P4 Portable bitmap Binary
96
- # P5 Portable graymap Binary
97
- # P6 Portable pixmap Binary
98
- #
99
- #++
100
- #
101
87
  module PNM
102
88
 
103
- LIBNAME = 'pnm' # :nodoc:
104
- HOMEPAGE = 'https://github.com/stomar/pnm' # :nodoc:
105
- TAGLINE = 'create/read/write PNM image files (PBM, PGM, PPM)' # :nodoc:
89
+ LIBNAME = 'pnm'
90
+ HOMEPAGE = 'https://github.com/stomar/pnm'
91
+ TAGLINE = 'create/read/write PNM image files (PBM, PGM, PPM)'
106
92
 
107
- COPYRIGHT = <<-copyright.gsub(/^ +/, '') # :nodoc:
93
+ COPYRIGHT = <<-copyright.gsub(/^ +/, '')
108
94
  Copyright (C) 2013-2014 Marcus Stollsteimer.
109
95
  License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
110
96
  This is free software: you are free to change and redistribute it.
@@ -162,6 +148,7 @@ module PNM
162
148
  Image.new(pixels, options)
163
149
  end
164
150
 
151
+ # @private
165
152
  def self.magic_number # :nodoc:
166
153
  {
167
154
  :pbm => {:ascii => 'P1', :binary => 'P4'},
data/lib/pnm/converter.rb CHANGED
@@ -1,11 +1,12 @@
1
1
  module PNM
2
2
 
3
+ # @private
3
4
  # Converter for pixel data. Only for internal usage.
4
- class Converter
5
+ class Converter # :nodoc:
5
6
 
6
7
  # Returns the number of bytes needed for one row of pixels
7
8
  # (in binary encoding).
8
- def self.byte_width(type, width) # :nodoc:
9
+ def self.byte_width(type, width)
9
10
  case type
10
11
  when :pbm
11
12
  (width - 1) / 8 + 1
@@ -103,7 +104,7 @@ module PNM
103
104
  data_string
104
105
  end
105
106
 
106
- def self.convert_to_integers(data, type) # :nodoc:
107
+ def self.convert_to_integers(data, type)
107
108
  if type == :pbm
108
109
  values_as_string = data.gsub(/[ \t\r\n]+/, '').split('')
109
110
  else
@@ -121,7 +122,7 @@ module PNM
121
122
  end
122
123
  end
123
124
 
124
- def self.assert_data_size(actual, expected) # :nodoc:
125
+ def self.assert_data_size(actual, expected)
125
126
  unless actual == expected
126
127
  raise PNM::DataSizeError, 'data size does not match expected size'
127
128
  end
data/lib/pnm/image.rb CHANGED
@@ -113,9 +113,18 @@ module PNM
113
113
 
114
114
  alias :to_s :info
115
115
 
116
+ # Returns a string representation for debugging.
117
+ def inspect
118
+ if type == :pbm
119
+ "#<%s:0x%x %s>" % [self.class.name, object_id, info]
120
+ else
121
+ "#<%s:0x%x %s, maxgray=%d>" % [self.class.name, object_id, info, maxgray]
122
+ end
123
+ end
124
+
116
125
  private
117
126
 
118
- def type_string # :nodoc:
127
+ def type_string
119
128
  case type
120
129
  when :pbm
121
130
  'Bilevel'
@@ -126,7 +135,7 @@ module PNM
126
135
  end
127
136
  end
128
137
 
129
- def detect_type(pixels, maxgray) # :nodoc:
138
+ def detect_type(pixels, maxgray)
130
139
  if pixels.first.first.kind_of?(Array)
131
140
  :ppm
132
141
  elsif (maxgray && maxgray > 1) || pixels.flatten.max > 1
@@ -136,7 +145,7 @@ module PNM
136
145
  end
137
146
  end
138
147
 
139
- def assert_valid_array # :nodoc:
148
+ def assert_valid_array
140
149
  msg = "invalid pixel data: Array expected"
141
150
  raise PNM::ArgumentError, msg unless Array === pixels
142
151
 
@@ -157,14 +166,14 @@ module PNM
157
166
  end
158
167
  end
159
168
 
160
- def assert_valid_pixel(pixel) # :nodoc:
169
+ def assert_valid_pixel(pixel)
161
170
  unless Fixnum === pixel
162
171
  msg = "invalid pixel value: Fixnum expected - #{pixel.inspect}"
163
172
  raise PNM::DataError, msg
164
173
  end
165
174
  end
166
175
 
167
- def assert_valid_color_pixel(pixel) # :nodoc:
176
+ def assert_valid_color_pixel(pixel)
168
177
  unless Array === pixel && pixel.map(&:class) == [Fixnum, Fixnum, Fixnum]
169
178
  msg = "invalid pixel value: "
170
179
  msg << "Array of 3 Fixnums expected - #{pixel.inspect}"
@@ -173,33 +182,33 @@ module PNM
173
182
  end
174
183
  end
175
184
 
176
- def assert_valid_type # :nodoc:
185
+ def assert_valid_type
177
186
  unless [:pbm, :pgm, :ppm].include?(type)
178
187
  msg = "invalid image type - #{type.inspect}"
179
188
  raise PNM::ArgumentError, msg
180
189
  end
181
190
  end
182
191
 
183
- def assert_matching_type_and_data # :nodoc:
192
+ def assert_matching_type_and_data
184
193
  if Array === pixels.first.first && [:pbm, :pgm].include?(type)
185
194
  msg = "specified type does not match data - #{type.inspect}"
186
195
  raise PNM::DataError, msg
187
196
  end
188
197
  end
189
198
 
190
- def assert_valid_maxgray # :nodoc:
199
+ def assert_valid_maxgray
191
200
  unless Fixnum === maxgray && maxgray > 0 && maxgray <= 255
192
201
  raise PNM::ArgumentError, "invalid maxgray value - #{maxgray.inspect}"
193
202
  end
194
203
  end
195
204
 
196
- def assert_valid_comment # :nodoc:
205
+ def assert_valid_comment
197
206
  unless String === comment
198
207
  raise PNM::ArgumentError, "invalid comment value - #{comment.inspect}"
199
208
  end
200
209
  end
201
210
 
202
- def assert_valid_pixel_values # :nodoc:
211
+ def assert_valid_pixel_values
203
212
  unless pixels.flatten.max <= maxgray
204
213
  raise PNM::DataError, "invalid data: value(s) greater than maxgray"
205
214
  end
@@ -208,7 +217,7 @@ module PNM
208
217
  end
209
218
  end
210
219
 
211
- def header(encoding) # :nodoc:
220
+ def header(encoding)
212
221
  header = "#{PNM.magic_number[type][encoding]}\n"
213
222
  comment_lines.each do |line|
214
223
  header << (line.empty? ? "#\n" : "# #{line}\n")
@@ -219,7 +228,7 @@ module PNM
219
228
  header
220
229
  end
221
230
 
222
- def comment_lines # :nodoc:
231
+ def comment_lines
223
232
  return [] unless comment
224
233
  return [''] if comment.empty?
225
234
 
@@ -227,19 +236,19 @@ module PNM
227
236
  comment.split(/\n/, keep_trailing_null_fields)
228
237
  end
229
238
 
230
- def to_ascii # :nodoc:
239
+ def to_ascii
231
240
  data_string = Converter.array2ascii(pixels)
232
241
 
233
242
  header(:ascii) << data_string
234
243
  end
235
244
 
236
- def to_binary # :nodoc:
245
+ def to_binary
237
246
  data_string = Converter.array2binary(type, pixels)
238
247
 
239
248
  header(:binary) << data_string
240
249
  end
241
250
 
242
- def gray_to_rgb(gray_value) # :nodoc:
251
+ def gray_to_rgb(gray_value)
243
252
  Array.new(3, gray_value)
244
253
  end
245
254
  end
data/lib/pnm/parser.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  module PNM
2
2
 
3
+ # @private
3
4
  # Parser for PNM image files. Only for internal usage.
4
- class Parser
5
+ class Parser # :nodoc:
5
6
 
6
7
  # Parses PNM image data.
7
8
  #
@@ -71,7 +72,7 @@ module PNM
71
72
  result
72
73
  end
73
74
 
74
- def self.token_number # :nodoc:
75
+ def self.token_number
75
76
  {
76
77
  'P1' => 2,
77
78
  'P2' => 3,
@@ -82,7 +83,7 @@ module PNM
82
83
  }
83
84
  end
84
85
 
85
- def self.next_token!(content) # :nodoc:
86
+ def self.next_token!(content)
86
87
  delimiter = if content.start_with?('#')
87
88
  "\n"
88
89
  else
@@ -97,21 +98,21 @@ module PNM
97
98
  token
98
99
  end
99
100
 
100
- def self.assert_valid_magic_number(magic_number) # :nodoc:
101
+ def self.assert_valid_magic_number(magic_number)
101
102
  unless %w{P1 P2 P3 P4 P5 P6}.include?(magic_number)
102
103
  msg = "unknown magic number - `#{magic_number}'"
103
104
  raise PNM::ParserError, msg
104
105
  end
105
106
  end
106
107
 
107
- def self.assert_integer(value_string, value_name) # :nodoc:
108
+ def self.assert_integer(value_string, value_name)
108
109
  unless /\A[0-9]+\Z/ === value_string
109
110
  msg = "#{value_name} must be an integer - `#{value_string}'"
110
111
  raise PNM::ParserError, msg
111
112
  end
112
113
  end
113
114
 
114
- def self.assert_value(value, name) # :nodoc:
115
+ def self.assert_value(value, name)
115
116
  unless yield(value)
116
117
  msg = "invalid #{name} value - `#{value}'"
117
118
  raise PNM::ParserError, msg
data/lib/pnm/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module PNM
2
- VERSION = '0.3.2' # :nodoc:
3
- DATE = '2014-10-19' # :nodoc:
2
+ VERSION = '0.3.3'
3
+ DATE = '2014-11-20'
4
4
  end
data/pnm.gemspec CHANGED
@@ -35,6 +35,7 @@ Gem::Specification.new do |s|
35
35
  README.md
36
36
  Rakefile
37
37
  pnm.gemspec
38
+ .yardopts
38
39
  } +
39
40
  Dir.glob('{benchmark,lib,test}/**/*')
40
41
 
data/test/test_image.rb CHANGED
@@ -162,6 +162,12 @@ describe PNM::Image do
162
162
  @color.info.must_equal 'PPM 5x3 Color'
163
163
  end
164
164
 
165
+ it 'can return meaningful debugging information' do
166
+ @bilevel.inspect.must_match %r{^#<PNM::Image:0x\h+ PBM 5x6 Bilevel>$}
167
+ @grayscale.inspect.must_match %r{^#<PNM::Image:0x\h+ PGM 4x3 Grayscale, maxgray=250>$}
168
+ @color.inspect.must_match %r{^#<PNM::Image:0x\h+ PPM 5x3 Color, maxgray=6>$}
169
+ end
170
+
165
171
  it 'can write binary data containing CRLF' do
166
172
  @grayscale_crlf.write(@temp_path, :binary)
167
173
  File.binread(@temp_path).must_equal File.binread("#{@srcpath}/grayscale_binary_crlf.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.2
4
+ version: 0.3.3
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-10-19 00:00:00.000000000 Z
11
+ date: 2014-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -32,6 +32,7 @@ executables: []
32
32
  extensions: []
33
33
  extra_rdoc_files: []
34
34
  files:
35
+ - ".yardopts"
35
36
  - README.md
36
37
  - Rakefile
37
38
  - benchmark/bm_converter.rb
@@ -79,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
80
  version: '0'
80
81
  requirements: []
81
82
  rubyforge_project:
82
- rubygems_version: 2.2.2
83
+ rubygems_version: 2.4.4
83
84
  signing_key:
84
85
  specification_version: 4
85
86
  summary: PNM - create/read/write PNM image files (PBM, PGM, PPM)
@@ -89,3 +90,4 @@ test_files:
89
90
  - test/test_parser.rb
90
91
  - test/test_converter.rb
91
92
  - test/test_pnm.rb
93
+ has_rdoc: