pnm 0.3.0 → 0.3.1

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: ef19db0d86c0c55bca6a6b6c3f9a5d4eaaac62f6
4
- data.tar.gz: ffa665ee3688f90f201045230818b97dd5c11b22
3
+ metadata.gz: 41d0847dab61302cfee794dd2547bc4a2f05df11
4
+ data.tar.gz: 76a61a9dbeea6ade821e0a1beeb45207b74fa673
5
5
  SHA512:
6
- metadata.gz: b8ff711e119c0950b4d249c9171735b0baf8e5c9401e10e8160e047def08df4d53f1db203be41a7220bd5e6a09945e56e308141fa23877b059b4242097916be7
7
- data.tar.gz: 18d891b4969653b32f4d7d5c253a673479c14fcc3b53ea918b282528737a108714463538150552886d39ee61ae777f99c9950a23333869564262c26ca3e43212
6
+ metadata.gz: b19271212932a8f0e0a6ee573076cd119468fb885bd481f10c45eb9ad15f7ceee75ad0f81be925aec05ab7366ef6a3e87267489a55402673c1b4703744122939
7
+ data.tar.gz: 473810c88249b863763ff8f7e8733e0352c24765ff5d07b5372ffb8fbb136c6a05c79093193f4f983fc39cf08f5764ec37e2f05f5d68324a1933c194f9aaca4b
data/README.md CHANGED
@@ -8,6 +8,12 @@ and writing of `PNM` image files (Portable Anymap):
8
8
  - `PGM` (Portable Graymap), and
9
9
  - `PPM` (Portable Pixmap).
10
10
 
11
+ It is a portable and lightweight utility for exporting or importing
12
+ of raw pixel data to or from an image file format that can be processed
13
+ by most image manipulation programs.
14
+
15
+ PNM comes without any dependencies on other gems or native libraries.
16
+
11
17
  Examples
12
18
  --------
13
19
 
@@ -32,6 +38,10 @@ image.width # => 3
32
38
  image.height # => 2
33
39
  ```
34
40
 
41
+ Note that for PBM bilevel images a pixel value of 0 signifies white
42
+ (and 1 signifies black), whereas for PGM and PPM images a value of 0
43
+ signifies black.
44
+
35
45
  See PNM::Image.new for a more detailed description of pixel data formats
36
46
  and available options.
37
47
 
@@ -80,11 +90,11 @@ Requirements
80
90
 
81
91
  - PNM has been tested with
82
92
 
83
- - Ruby 2.1.0,
93
+ - Ruby 2.1.3,
84
94
  - Ruby 2.0.0 on Linux and on Windows,
85
95
  - Ruby 1.9.3,
86
- - JRuby 1.7.10,
87
- - Rubinius 2.2.4.
96
+ - JRuby 1.7.16,
97
+ - Rubinius 2.2.10.
88
98
 
89
99
  Documentation
90
100
  -------------
data/lib/pnm.rb CHANGED
@@ -16,6 +16,12 @@ require_relative 'pnm/exceptions'
16
16
  # - +PGM+ (Portable Graymap), and
17
17
  # - +PPM+ (Portable Pixmap).
18
18
  #
19
+ # It is a portable and lightweight utility for exporting or importing
20
+ # of raw pixel data to or from an image file format that can be processed
21
+ # by most image manipulation programs.
22
+ #
23
+ # PNM comes without any dependencies on other gems or native libraries.
24
+ #
19
25
  # == Examples
20
26
  #
21
27
  # Create a PGM grayscale image from a two-dimensional array of gray values:
@@ -37,6 +43,10 @@ require_relative 'pnm/exceptions'
37
43
  # image.width # => 3
38
44
  # image.height # => 2
39
45
  #
46
+ # Note that for PBM bilevel images a pixel value of 0 signifies white
47
+ # (and 1 signifies black), whereas for PGM and PPM images a value of 0
48
+ # signifies black.
49
+ #
40
50
  # See PNM::Image.new for a more detailed description of pixel data formats
41
51
  # and available options.
42
52
  #
data/lib/pnm/image.rb CHANGED
@@ -35,12 +35,11 @@ module PNM
35
35
  #
36
36
  # +pixels+:: The pixel data, given as a two-dimensional array of
37
37
  #
38
- # * for PBM: bilevel values (0 or 1),
39
- # * for PGM: gray values between 0 and +maxgray+,
38
+ # * for PBM: bilevel values of 0 (white) or 1 (black),
39
+ # * for PGM: gray values between 0 (black) and +maxgray+ (white),
40
40
  # * for PPM: an array of 3 values between 0 and +maxgray+,
41
- # corresponding to red, green, and blue (RGB).
42
- #
43
- # A value of 0 means that the color is turned off.
41
+ # corresponding to red, green, and blue (RGB);
42
+ # a value of 0 means that the color is turned off.
44
43
  #
45
44
  # Optional settings that can be specified in the +options+ hash:
46
45
  #
@@ -51,8 +50,9 @@ module PNM
51
50
  # +maxgray+:: The maximum gray or color value.
52
51
  # For PGM and PPM, +maxgray+ must be less or equal 255
53
52
  # (the default value).
54
- # For PBM pixel data, setting +maxgray+ implies a conversion
55
- # to +:pgm+. If +type+ is explicitly set to +:pbm+,
53
+ # For bilevel pixel data, setting +maxgray+ to a value
54
+ # greater than 1 implies a type of +:pgm+.
55
+ # When +type+ is explicitly set to +:pbm+,
56
56
  # the +maxgray+ setting is disregarded.
57
57
  # +comment+:: A multiline comment string.
58
58
  def initialize(pixels, options = {})
@@ -129,7 +129,7 @@ module PNM
129
129
  def detect_type(pixels, maxgray) # :nodoc:
130
130
  if pixels.first.first.kind_of?(Array)
131
131
  :ppm
132
- elsif maxgray || pixels.flatten.max > 1
132
+ elsif (maxgray && maxgray > 1) || pixels.flatten.max > 1
133
133
  :pgm
134
134
  else
135
135
  :pbm
data/lib/pnm/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module PNM
2
- VERSION = '0.3.0' # :nodoc:
3
- DATE = '2014-02-08' # :nodoc:
2
+ VERSION = '0.3.1' # :nodoc:
3
+ DATE = '2014-10-10' # :nodoc:
4
4
  end
data/test/test_image.rb CHANGED
@@ -63,7 +63,13 @@ describe PNM::Image do
63
63
  image.maxgray.must_equal 255
64
64
  end
65
65
 
66
- it 'ignores maxgray for bilevel images and sets it to 1' do
66
+ it 'accepts setting of maxgray to 1 for bilevel images' do
67
+ image = PNM::Image.new([[0,1,0], [1,0,1]], {:maxgray => 1})
68
+ image.type.must_equal :pbm
69
+ image.maxgray.must_equal 1
70
+ end
71
+
72
+ it 'ignores invalid maxgray for bilevel images and sets it to 1' do
67
73
  image = PNM::Image.new([[0,1,0], [1,0,1]], {:type => :pbm, :maxgray => 255})
68
74
  image.type.must_equal :pbm
69
75
  image.maxgray.must_equal 1
@@ -77,10 +83,10 @@ describe PNM::Image do
77
83
  end
78
84
 
79
85
  it 'can create a grayscale image from bilevel values (using maxgray)' do
80
- image = PNM::Image.new([[0,1,0], [1,0,1]], {:maxgray => 1})
86
+ image = PNM::Image.new([[0,1,0], [1,0,1]], {:maxgray => 2})
81
87
  image.type.must_equal :pgm
82
88
  image.pixels.must_equal [[0,1,0], [1,0,1]]
83
- image.maxgray.must_equal 1
89
+ image.maxgray.must_equal 2
84
90
  end
85
91
 
86
92
  it 'can create a color image from bilevel values' do
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.0
4
+ version: 0.3.1
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-02-08 00:00:00.000000000 Z
11
+ date: 2014-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  version: '0'
80
80
  requirements: []
81
81
  rubyforge_project:
82
- rubygems_version: 2.2.0
82
+ rubygems_version: 2.2.2
83
83
  signing_key:
84
84
  specification_version: 4
85
85
  summary: PNM - create/read/write PNM image files (PBM, PGM, PPM)