pnm 0.4.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +25 -20
- data/Rakefile +11 -10
- data/benchmark/bm_converter.rb +21 -17
- data/lib/pnm.rb +54 -54
- data/lib/pnm/converter.rb +44 -47
- data/lib/pnm/exceptions.rb +2 -0
- data/lib/pnm/image.rb +81 -54
- data/lib/pnm/parser.rb +48 -39
- data/lib/pnm/version.rb +4 -2
- data/pnm.gemspec +23 -19
- data/test/backports.rb +19 -0
- data/test/test_converter.rb +85 -80
- data/test/test_exceptions.rb +124 -120
- data/test/test_image.rb +198 -122
- data/test/test_parser.rb +57 -53
- data/test/test_pnm.rb +58 -54
- metadata +17 -16
data/test/test_pnm.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# test_pnm.rb: Unit tests for the PNM library.
|
2
4
|
#
|
3
|
-
# Copyright (C) 2013-
|
5
|
+
# Copyright (C) 2013-2020 Marcus Stollsteimer
|
6
|
+
|
7
|
+
require "minitest/autorun"
|
8
|
+
require "pnm"
|
4
9
|
|
5
|
-
|
6
|
-
require 'pnm'
|
10
|
+
require_relative "backports"
|
7
11
|
|
8
12
|
|
9
13
|
describe PNM do
|
@@ -12,93 +16,93 @@ describe PNM do
|
|
12
16
|
@srcpath = File.dirname(__FILE__)
|
13
17
|
end
|
14
18
|
|
15
|
-
it
|
19
|
+
it "can read an ASCII encoded PBM file" do
|
16
20
|
file = File.expand_path("#{@srcpath}/bilevel_ascii.pbm")
|
17
21
|
image = PNM.read(file)
|
18
22
|
|
19
|
-
image.info.
|
20
|
-
image.maxgray.must_equal 1
|
21
|
-
image.comment.must_equal
|
22
|
-
image.pixels.must_equal [[0,0,0,0,0],
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
_(image.info).must_equal "PBM 5x6 Bilevel"
|
24
|
+
_(image.maxgray).must_equal 1
|
25
|
+
_(image.comment).must_equal "Bilevel"
|
26
|
+
_(image.pixels).must_equal [[0, 0, 0, 0, 0],
|
27
|
+
[0, 1, 1, 1, 0],
|
28
|
+
[0, 0, 1, 0, 0],
|
29
|
+
[0, 0, 1, 0, 0],
|
30
|
+
[0, 0, 1, 0, 0],
|
31
|
+
[0, 0, 0, 0, 0]]
|
28
32
|
end
|
29
33
|
|
30
|
-
it
|
34
|
+
it "can read an ASCII encoded PGM file" do
|
31
35
|
file = File.expand_path("#{@srcpath}/grayscale_ascii.pgm")
|
32
36
|
image = PNM.read(file)
|
33
37
|
|
34
|
-
image.info.
|
35
|
-
image.maxgray.must_equal 250
|
36
|
-
image.comment.must_equal "Grayscale\n(with multiline comment)"
|
37
|
-
image.pixels.must_equal [[ 0,
|
38
|
-
|
39
|
-
|
38
|
+
_(image.info).must_equal "PGM 4x3 Grayscale"
|
39
|
+
_(image.maxgray).must_equal 250
|
40
|
+
_(image.comment).must_equal "Grayscale\n(with multiline comment)"
|
41
|
+
_(image.pixels).must_equal [[ 0, 50, 100, 150],
|
42
|
+
[ 50, 100, 150, 200],
|
43
|
+
[100, 150, 200, 250]]
|
40
44
|
end
|
41
45
|
|
42
|
-
it
|
46
|
+
it "can read an ASCII encoded PPM file" do
|
43
47
|
file = File.expand_path("#{@srcpath}/color_ascii.ppm")
|
44
48
|
image = PNM.read(file)
|
45
49
|
|
46
|
-
image.info.
|
47
|
-
image.maxgray.must_equal 6
|
48
|
-
image.pixels.must_equal [[[0,6,0], [1,5,1], [2,4,2], [3,3,4], [4,2,6]],
|
49
|
-
|
50
|
-
|
50
|
+
_(image.info).must_equal "PPM 5x3 Color"
|
51
|
+
_(image.maxgray).must_equal 6
|
52
|
+
_(image.pixels).must_equal [[[0, 6, 0], [1, 5, 1], [2, 4, 2], [3, 3, 4], [4, 2, 6]],
|
53
|
+
[[1, 5, 2], [2, 4, 2], [3, 3, 2], [4, 2, 2], [5, 1, 2]],
|
54
|
+
[[2, 4, 6], [3, 3, 4], [4, 2, 2], [5, 1, 1], [6, 0, 0]]]
|
51
55
|
end
|
52
56
|
|
53
|
-
it
|
57
|
+
it "can read a binary encoded PBM file" do
|
54
58
|
file = File.expand_path("#{@srcpath}/bilevel_binary.pbm")
|
55
59
|
image = PNM.read(file)
|
56
60
|
|
57
|
-
image.info.
|
58
|
-
image.maxgray.must_equal 1
|
59
|
-
image.comment.must_equal
|
60
|
-
image.pixels.must_equal [[0,0,0,0,0],
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
61
|
+
_(image.info).must_equal "PBM 5x6 Bilevel"
|
62
|
+
_(image.maxgray).must_equal 1
|
63
|
+
_(image.comment).must_equal "Bilevel"
|
64
|
+
_(image.pixels).must_equal [[0, 0, 0, 0, 0],
|
65
|
+
[0, 1, 1, 1, 0],
|
66
|
+
[0, 0, 1, 0, 0],
|
67
|
+
[0, 0, 1, 0, 0],
|
68
|
+
[0, 0, 1, 0, 0],
|
69
|
+
[0, 0, 0, 0, 0]]
|
66
70
|
end
|
67
71
|
|
68
|
-
it
|
72
|
+
it "can read a binary encoded PGM file" do
|
69
73
|
file = File.expand_path("#{@srcpath}/grayscale_binary.pgm")
|
70
74
|
image = PNM.read(file)
|
71
75
|
|
72
|
-
image.info.
|
73
|
-
image.maxgray.must_equal 250
|
74
|
-
image.comment.must_equal "Grayscale\n(with multiline comment)"
|
75
|
-
image.pixels.must_equal [[ 0,
|
76
|
-
|
77
|
-
|
76
|
+
_(image.info).must_equal "PGM 4x3 Grayscale"
|
77
|
+
_(image.maxgray).must_equal 250
|
78
|
+
_(image.comment).must_equal "Grayscale\n(with multiline comment)"
|
79
|
+
_(image.pixels).must_equal [[ 0, 50, 100, 150],
|
80
|
+
[ 50, 100, 150, 200],
|
81
|
+
[100, 150, 200, 250]]
|
78
82
|
end
|
79
83
|
|
80
|
-
it
|
84
|
+
it "can read a binary encoded PPM file" do
|
81
85
|
file = File.expand_path("#{@srcpath}/color_binary.ppm")
|
82
86
|
image = PNM.read(file)
|
83
87
|
|
84
|
-
image.info.
|
85
|
-
image.maxgray.must_equal 6
|
86
|
-
image.pixels.must_equal [[[0,6,0], [1,5,1], [2,4,2], [3,3,4], [4,2,6]],
|
87
|
-
|
88
|
-
|
88
|
+
_(image.info).must_equal "PPM 5x3 Color"
|
89
|
+
_(image.maxgray).must_equal 6
|
90
|
+
_(image.pixels).must_equal [[[0, 6, 0], [1, 5, 1], [2, 4, 2], [3, 3, 4], [4, 2, 6]],
|
91
|
+
[[1, 5, 2], [2, 4, 2], [3, 3, 2], [4, 2, 2], [5, 1, 2]],
|
92
|
+
[[2, 4, 6], [3, 3, 4], [4, 2, 2], [5, 1, 1], [6, 0, 0]]]
|
89
93
|
end
|
90
94
|
|
91
|
-
it
|
95
|
+
it "can read binary data containing CRLF" do
|
92
96
|
file = File.expand_path("#{@srcpath}/grayscale_binary_crlf.pgm")
|
93
97
|
|
94
98
|
image = PNM.read(file)
|
95
|
-
image.pixels.must_equal [[65,66], [13,10], [65,66]]
|
99
|
+
_(image.pixels).must_equal [[65, 66], [13, 10], [65, 66]]
|
96
100
|
end
|
97
101
|
|
98
|
-
it
|
102
|
+
it "can read binary data containing CRLF from an I/O stream" do
|
99
103
|
file = File.expand_path("#{@srcpath}/grayscale_binary_crlf.pgm")
|
100
104
|
|
101
|
-
image = File.open(file,
|
102
|
-
image.pixels.must_equal [[65,66], [13,10], [65,66]]
|
105
|
+
image = File.open(file, "r") {|f| PNM.read(f) }
|
106
|
+
_(image.pixels).must_equal [[65, 66], [13, 10], [65, 66]]
|
103
107
|
end
|
104
108
|
end
|
metadata
CHANGED
@@ -1,50 +1,51 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pnm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcus Stollsteimer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: minitest
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '5.0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '5.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '10.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '10.0'
|
41
41
|
description: 'PNM is a pure Ruby library for creating, reading, and writing of PNM
|
42
42
|
image files (Portable Anymap): PBM (Portable Bitmap), PGM (Portable Graymap), and
|
43
43
|
PPM (Portable Pixmap).'
|
44
44
|
email: sto.mar@web.de
|
45
45
|
executables: []
|
46
46
|
extensions: []
|
47
|
-
extra_rdoc_files:
|
47
|
+
extra_rdoc_files:
|
48
|
+
- README.md
|
48
49
|
files:
|
49
50
|
- ".yardopts"
|
50
51
|
- README.md
|
@@ -60,6 +61,7 @@ files:
|
|
60
61
|
- lib/pnm/parser.rb
|
61
62
|
- lib/pnm/version.rb
|
62
63
|
- pnm.gemspec
|
64
|
+
- test/backports.rb
|
63
65
|
- test/bilevel_2_binary.pbm
|
64
66
|
- test/bilevel_ascii.pbm
|
65
67
|
- test/bilevel_binary.pbm
|
@@ -75,33 +77,32 @@ files:
|
|
75
77
|
- test/test_pnm.rb
|
76
78
|
homepage: https://github.com/stomar/pnm
|
77
79
|
licenses:
|
78
|
-
- GPL-3
|
80
|
+
- GPL-3.0
|
79
81
|
metadata: {}
|
80
82
|
post_install_message:
|
81
83
|
rdoc_options:
|
82
84
|
- "--charset=UTF-8"
|
85
|
+
- "--main=README.md"
|
83
86
|
require_paths:
|
84
87
|
- lib
|
85
88
|
required_ruby_version: !ruby/object:Gem::Requirement
|
86
89
|
requirements:
|
87
90
|
- - ">="
|
88
91
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
92
|
+
version: 2.0.0
|
90
93
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
94
|
requirements:
|
92
95
|
- - ">="
|
93
96
|
- !ruby/object:Gem::Version
|
94
97
|
version: '0'
|
95
98
|
requirements: []
|
96
|
-
|
97
|
-
rubygems_version: 2.4.5
|
99
|
+
rubygems_version: 3.1.2
|
98
100
|
signing_key:
|
99
101
|
specification_version: 4
|
100
102
|
summary: PNM - create/read/write PNM image files (PBM, PGM, PPM)
|
101
103
|
test_files:
|
102
|
-
- test/test_image.rb
|
103
104
|
- test/test_exceptions.rb
|
104
|
-
- test/test_parser.rb
|
105
105
|
- test/test_converter.rb
|
106
106
|
- test/test_pnm.rb
|
107
|
-
|
107
|
+
- test/test_image.rb
|
108
|
+
- test/test_parser.rb
|