chunky_png 1.3.2 → 1.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 +4 -4
- data/BENCHMARKING.md +38 -0
- data/CONTRIBUTING.md +50 -0
- data/LICENSE +1 -1
- data/chunky_png.gemspec +12 -12
- data/lib/chunky_png/canvas/operations.rb +1 -1
- data/lib/chunky_png/color.rb +7 -7
- data/lib/chunky_png/dimension.rb +16 -15
- data/lib/chunky_png/version.rb +1 -1
- data/spec/chunky_png/canvas/adam7_interlacing_spec.rb +24 -24
- data/spec/chunky_png/canvas/data_url_exporting_spec.rb +2 -2
- data/spec/chunky_png/canvas/data_url_importing_spec.rb +4 -4
- data/spec/chunky_png/canvas/drawing_spec.rb +60 -60
- data/spec/chunky_png/canvas/masking_spec.rb +15 -15
- data/spec/chunky_png/canvas/operations_spec.rb +69 -66
- data/spec/chunky_png/canvas/png_decoding_spec.rb +26 -26
- data/spec/chunky_png/canvas/png_encoding_spec.rb +74 -74
- data/spec/chunky_png/canvas/resampling_spec.rb +47 -47
- data/spec/chunky_png/canvas/stream_exporting_spec.rb +20 -20
- data/spec/chunky_png/canvas/stream_importing_spec.rb +3 -3
- data/spec/chunky_png/canvas_spec.rb +95 -92
- data/spec/chunky_png/color_spec.rb +151 -151
- data/spec/chunky_png/datastream_spec.rb +6 -6
- data/spec/chunky_png/dimension_spec.rb +15 -15
- data/spec/chunky_png/image_spec.rb +4 -4
- data/spec/chunky_png/point_spec.rb +25 -25
- data/spec/chunky_png/rmagick_spec.rb +4 -4
- data/spec/chunky_png/vector_spec.rb +39 -34
- data/spec/chunky_png_spec.rb +1 -2
- data/spec/png_suite_spec.rb +38 -38
- data/spec/spec_helper.rb +14 -10
- metadata +37 -33
- data/BENCHMARKS.rdoc +0 -31
@@ -5,12 +5,12 @@ describe ChunkyPNG::Datastream do
|
|
5
5
|
describe '.from_io'do
|
6
6
|
it "should raise an error when loading a file with a bad signature" do
|
7
7
|
filename = resource_file('damaged_signature.png')
|
8
|
-
|
8
|
+
expect { ChunkyPNG::Datastream.from_file(filename) }.to raise_error
|
9
9
|
end
|
10
10
|
|
11
11
|
it "should raise an error if the CRC of a chunk is incorrect" do
|
12
12
|
filename = resource_file('damaged_chunk.png')
|
13
|
-
|
13
|
+
expect { ChunkyPNG::Datastream.from_file(filename) }.to raise_error
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -18,15 +18,15 @@ describe ChunkyPNG::Datastream do
|
|
18
18
|
it "should load uncompressed tXTt chunks correctly" do
|
19
19
|
filename = resource_file('text_chunk.png')
|
20
20
|
ds = ChunkyPNG::Datastream.from_file(filename)
|
21
|
-
ds.metadata['Title'].
|
22
|
-
ds.metadata['Author'].
|
21
|
+
expect(ds.metadata['Title']).to eql 'My amazing icon!'
|
22
|
+
expect(ds.metadata['Author']).to eql "Willem van Bergen"
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should load compressed zTXt chunks correctly" do
|
26
26
|
filename = resource_file('ztxt_chunk.png')
|
27
27
|
ds = ChunkyPNG::Datastream.from_file(filename)
|
28
|
-
ds.metadata['Title'].
|
29
|
-
ds.metadata['Copyright'].
|
28
|
+
expect(ds.metadata['Title']).to eql 'PngSuite'
|
29
|
+
expect(ds.metadata['Copyright']).to eql "Copyright Willem van Schaik, Singapore 1995-96"
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
@@ -2,30 +2,30 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe ChunkyPNG::Dimension do
|
4
4
|
subject { ChunkyPNG::Dimension.new(2, 3) }
|
5
|
-
|
5
|
+
|
6
6
|
it { should respond_to(:width) }
|
7
7
|
it { should respond_to(:height) }
|
8
|
-
|
8
|
+
|
9
9
|
describe '#area' do
|
10
10
|
it "should calculate the area correctly" do
|
11
|
-
subject.area.
|
11
|
+
expect(subject.area).to eql 6
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
describe 'ChunkyPNG.Dimension' do
|
17
17
|
subject { ChunkyPNG::Dimension.new(1, 2) }
|
18
|
-
|
18
|
+
|
19
19
|
it "should create a dimension from a 2-item array" do
|
20
|
-
ChunkyPNG::Dimension([1, 2]).
|
21
|
-
ChunkyPNG::Dimension(['1', '2']).
|
20
|
+
expect(ChunkyPNG::Dimension([1, 2])).to eql subject
|
21
|
+
expect(ChunkyPNG::Dimension(['1', '2'])).to eql subject
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
it "should create a dimension from a hash with x and y keys" do
|
25
|
-
ChunkyPNG::Dimension(:width => 1, :height => 2).
|
26
|
-
ChunkyPNG::Dimension('width' => '1', 'height' => '2').
|
25
|
+
expect(ChunkyPNG::Dimension(:width => 1, :height => 2)).to eql subject
|
26
|
+
expect(ChunkyPNG::Dimension('width' => '1', 'height' => '2')).to eql subject
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
it "should create a dimension from a point-like string" do
|
30
30
|
[
|
31
31
|
ChunkyPNG::Dimension('1,2'),
|
@@ -35,14 +35,14 @@ describe 'ChunkyPNG.Dimension' do
|
|
35
35
|
ChunkyPNG::Dimension("[1\t2}"),
|
36
36
|
].all? { |point| point == subject }
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
it "should create a dimension from an object that responds to width and height" do
|
40
40
|
mock_object = Struct.new(:width, :height).new(1, 2)
|
41
|
-
ChunkyPNG::Dimension(mock_object).
|
41
|
+
expect(ChunkyPNG::Dimension(mock_object)).to eql subject
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
it "should raise an exception if the input is not understood" do
|
45
|
-
|
46
|
-
|
45
|
+
expect { ChunkyPNG::Dimension(Object.new) }.to raise_error(ArgumentError)
|
46
|
+
expect { ChunkyPNG::Dimension(1, 2, 3) }.to raise_error(ArgumentError)
|
47
47
|
end
|
48
48
|
end
|
@@ -5,8 +5,8 @@ describe ChunkyPNG::Image do
|
|
5
5
|
|
6
6
|
it "should load metadata from an existing file" do
|
7
7
|
image = ChunkyPNG::Image.from_file(resource_file('text_chunk.png'))
|
8
|
-
image.metadata['Title'].
|
9
|
-
image.metadata['Author'].
|
8
|
+
expect(image.metadata['Title']).to eql 'My amazing icon!'
|
9
|
+
expect(image.metadata['Author']).to eql 'Willem van Bergen'
|
10
10
|
end
|
11
11
|
|
12
12
|
it "should write metadata to the file correctly" do
|
@@ -18,8 +18,8 @@ describe ChunkyPNG::Image do
|
|
18
18
|
image.save(filename)
|
19
19
|
|
20
20
|
metadata = ChunkyPNG::Datastream.from_file(filename).metadata
|
21
|
-
metadata['Title'].
|
22
|
-
metadata['Author'].
|
21
|
+
expect(metadata['Title']).to eql 'My amazing icon!'
|
22
|
+
expect(metadata['Author']).to eql 'Willem van Bergen'
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should load empty images correctly" do
|
@@ -1,42 +1,42 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ChunkyPNG::Point do
|
4
|
-
|
4
|
+
|
5
5
|
subject { ChunkyPNG::Point.new(1, 2) }
|
6
|
-
|
6
|
+
|
7
7
|
it { should respond_to(:x) }
|
8
8
|
it { should respond_to(:y) }
|
9
|
-
|
9
|
+
|
10
10
|
describe '#within_bounds?' do
|
11
11
|
it { should be_within_bounds(2, 3) }
|
12
12
|
it { should_not be_within_bounds('1x3') }
|
13
13
|
it { should_not be_within_bounds(2, 2) }
|
14
14
|
it { should_not be_within_bounds('[1 2]') }
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
describe '#<=>' do
|
18
18
|
it "should return 0 if the coordinates are identical" do
|
19
|
-
(subject <=> ChunkyPNG::Point.new(1, 2)).
|
19
|
+
expect((subject <=> ChunkyPNG::Point.new(1, 2))).to eql 0
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should return -1 if the y coordinate is smaller than the other one" do
|
23
|
-
(subject <=> ChunkyPNG::Point.new(1, 3)).
|
24
|
-
(subject <=> ChunkyPNG::Point.new(0, 3)).
|
25
|
-
(subject <=> ChunkyPNG::Point.new(2, 3)).
|
23
|
+
expect((subject <=> ChunkyPNG::Point.new(1, 3))).to eql -1
|
24
|
+
expect((subject <=> ChunkyPNG::Point.new(0, 3))).to eql -1 # x doesn't matter
|
25
|
+
expect((subject <=> ChunkyPNG::Point.new(2, 3))).to eql -1 # x doesn't matter
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should return 1 if the y coordinate is larger than the other one" do
|
29
|
-
(subject <=> ChunkyPNG::Point.new(1, 0)).
|
30
|
-
(subject <=> ChunkyPNG::Point.new(0, 0)).
|
31
|
-
(subject <=> ChunkyPNG::Point.new(2, 0)).
|
29
|
+
expect((subject <=> ChunkyPNG::Point.new(1, 0))).to eql 1
|
30
|
+
expect((subject <=> ChunkyPNG::Point.new(0, 0))).to eql 1 # x doesn't matter
|
31
|
+
expect((subject <=> ChunkyPNG::Point.new(2, 0))).to eql 1 # x doesn't matter
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should return -1 if the x coordinate is smaller and y is the same" do
|
35
|
-
(subject <=> ChunkyPNG::Point.new(2, 2)).
|
35
|
+
expect((subject <=> ChunkyPNG::Point.new(2, 2))).to eql -1
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should return 1 if the x coordinate is larger and y is the same" do
|
39
|
-
(subject <=> ChunkyPNG::Point.new(0, 2)).
|
39
|
+
expect((subject <=> ChunkyPNG::Point.new(0, 2))).to eql 1
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
@@ -44,22 +44,22 @@ end
|
|
44
44
|
describe 'ChunkyPNG.Point' do
|
45
45
|
subject { ChunkyPNG::Point.new(1, 2) }
|
46
46
|
|
47
|
-
|
47
|
+
|
48
48
|
it "should create a point from a 2-item array" do
|
49
|
-
ChunkyPNG::Point([1, 2]).
|
50
|
-
ChunkyPNG::Point(['1', '2']).
|
49
|
+
expect(ChunkyPNG::Point([1, 2])).to eql subject
|
50
|
+
expect(ChunkyPNG::Point(['1', '2'])).to eql subject
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
it "should create a point from a hash with x and y keys" do
|
54
|
-
ChunkyPNG::Point(:x => 1, :y => 2).
|
55
|
-
ChunkyPNG::Point('x' => '1', 'y' => '2').
|
54
|
+
expect(ChunkyPNG::Point(:x => 1, :y => 2)).to eql subject
|
55
|
+
expect(ChunkyPNG::Point('x' => '1', 'y' => '2')).to eql subject
|
56
56
|
end
|
57
57
|
|
58
58
|
it "should create a point from a ChunkyPNG::Dimension object" do
|
59
59
|
dimension = ChunkyPNG::Dimension.new(1, 2)
|
60
60
|
ChunkyPNG::Point(dimension) == subject
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
63
|
it "should create a point from a point-like string" do
|
64
64
|
[
|
65
65
|
ChunkyPNG::Point('1,2'),
|
@@ -69,14 +69,14 @@ describe 'ChunkyPNG.Point' do
|
|
69
69
|
ChunkyPNG::Point("[1 2}"),
|
70
70
|
].all? { |point| point == subject }
|
71
71
|
end
|
72
|
-
|
72
|
+
|
73
73
|
it "should create a point from an object that responds to x and y" do
|
74
74
|
mock_object = Struct.new(:x, :y).new(1, 2)
|
75
|
-
ChunkyPNG::Point(mock_object).
|
75
|
+
expect(ChunkyPNG::Point(mock_object)).to eql subject
|
76
76
|
end
|
77
|
-
|
77
|
+
|
78
78
|
it "should raise an exception if the input is not understood" do
|
79
|
-
|
80
|
-
|
79
|
+
expect { ChunkyPNG::Point(Object.new) }.to raise_error(ArgumentError)
|
80
|
+
expect { ChunkyPNG::Point(1, 2, 3) }.to raise_error(ArgumentError)
|
81
81
|
end
|
82
82
|
end
|
@@ -4,18 +4,18 @@ begin
|
|
4
4
|
require 'chunky_png/rmagick'
|
5
5
|
|
6
6
|
describe ChunkyPNG::RMagick do
|
7
|
-
|
7
|
+
|
8
8
|
it "should import an image from RMagick correctly" do
|
9
9
|
image = Magick::Image.read(resource_file('composited.png')).first
|
10
10
|
canvas = ChunkyPNG::RMagick.import(image)
|
11
|
-
canvas.
|
11
|
+
expect(canvas).to eql reference_canvas('composited')
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
it "should export an image to RMagick correctly" do
|
15
15
|
canvas = reference_canvas('composited')
|
16
16
|
image = ChunkyPNG::RMagick.export(canvas)
|
17
17
|
image.format = 'PNG32'
|
18
|
-
canvas.
|
18
|
+
expect(canvas).to eql ChunkyPNG::Canvas.from_blob(image.to_blob)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
rescue LoadError => e
|
@@ -4,75 +4,80 @@ describe ChunkyPNG::Vector do
|
|
4
4
|
subject { ChunkyPNG::Vector.new([ChunkyPNG::Point.new(2, 5), ChunkyPNG::Point.new(1, 3), ChunkyPNG::Point.new(4, 6)]) }
|
5
5
|
|
6
6
|
it { should respond_to(:points) }
|
7
|
-
|
7
|
+
|
8
|
+
describe '#length' do
|
9
|
+
it "shopuld have 3 items" do
|
10
|
+
expect(subject.length).to eql 3
|
11
|
+
end
|
12
|
+
end
|
8
13
|
|
9
14
|
describe '#x_range' do
|
10
15
|
it "should get the right range of x values" do
|
11
|
-
subject.x_range.
|
16
|
+
expect(subject.x_range).to eql (1..4)
|
12
17
|
end
|
13
|
-
|
18
|
+
|
14
19
|
it "should find the minimum x-coordinate" do
|
15
|
-
subject.min_x.
|
20
|
+
expect(subject.min_x).to eql 1
|
16
21
|
end
|
17
|
-
|
22
|
+
|
18
23
|
it "should find the maximum x-coordinate" do
|
19
|
-
subject.max_x.
|
24
|
+
expect(subject.max_x).to eql 4
|
20
25
|
end
|
21
|
-
|
26
|
+
|
22
27
|
it "should calculate the width correctly" do
|
23
|
-
subject.width.
|
28
|
+
expect(subject.width).to eql 4
|
24
29
|
end
|
25
30
|
end
|
26
31
|
|
27
32
|
describe '#y_range' do
|
28
33
|
it "should get the right range of y values" do
|
29
|
-
subject.y_range.
|
34
|
+
expect(subject.y_range).to eql (3..6)
|
30
35
|
end
|
31
|
-
|
36
|
+
|
32
37
|
it "should find the minimum x-coordinate" do
|
33
|
-
subject.min_y.
|
38
|
+
expect(subject.min_y).to eql 3
|
34
39
|
end
|
35
|
-
|
40
|
+
|
36
41
|
it "should find the maximum x-coordinate" do
|
37
|
-
subject.max_y.
|
42
|
+
expect(subject.max_y).to eql 6
|
38
43
|
end
|
39
|
-
|
44
|
+
|
40
45
|
it "should calculate the height correctly" do
|
41
|
-
subject.height.
|
46
|
+
expect(subject.height).to eql 4
|
42
47
|
end
|
43
48
|
end
|
44
|
-
|
49
|
+
|
45
50
|
describe '#offset' do
|
46
51
|
it "should return a ChunkyPNG::Point" do
|
47
|
-
subject.offset.
|
52
|
+
expect(subject.offset).to be_kind_of(ChunkyPNG::Point)
|
48
53
|
end
|
49
|
-
|
54
|
+
|
50
55
|
it "should use the mininum x and y coordinates as values for the point" do
|
51
|
-
subject.offset.x.
|
52
|
-
subject.offset.y.
|
56
|
+
expect(subject.offset.x).to eql subject.min_x
|
57
|
+
expect(subject.offset.y).to eql subject.min_y
|
53
58
|
end
|
54
59
|
end
|
55
60
|
|
56
61
|
describe '#dimension' do
|
57
62
|
it "should return a ChunkyPNG::Dimension" do
|
58
|
-
subject.dimension.
|
63
|
+
expect(subject.dimension).to be_kind_of(ChunkyPNG::Dimension)
|
59
64
|
end
|
60
|
-
|
65
|
+
|
61
66
|
it "should use the width and height of the vector for the dimension" do
|
62
|
-
subject.dimension.width.
|
63
|
-
subject.dimension.height.
|
67
|
+
expect(subject.dimension.width).to eql subject.width
|
68
|
+
expect(subject.dimension.height).to eql subject.height
|
64
69
|
end
|
65
70
|
end
|
66
71
|
|
67
72
|
describe '#edges' do
|
68
73
|
it "should get three edges when closing the path" do
|
69
|
-
subject.edges(true).to_a.
|
74
|
+
expect(subject.edges(true).to_a).to eql [[ChunkyPNG::Point.new(2, 5), ChunkyPNG::Point.new(1, 3)],
|
70
75
|
[ChunkyPNG::Point.new(1, 3), ChunkyPNG::Point.new(4, 6)],
|
71
76
|
[ChunkyPNG::Point.new(4, 6), ChunkyPNG::Point.new(2, 5)]]
|
72
77
|
end
|
73
78
|
|
74
79
|
it "should get two edges when not closing the path" do
|
75
|
-
subject.edges(false).to_a.
|
80
|
+
expect(subject.edges(false).to_a).to eql [[ChunkyPNG::Point.new(2, 5), ChunkyPNG::Point.new(1, 3)],
|
76
81
|
[ChunkyPNG::Point.new(1, 3), ChunkyPNG::Point.new(4, 6)]]
|
77
82
|
end
|
78
83
|
end
|
@@ -80,25 +85,25 @@ end
|
|
80
85
|
|
81
86
|
describe 'ChunkyPNG.Vector' do
|
82
87
|
let(:example) { ChunkyPNG::Vector.new([ChunkyPNG::Point.new(2, 4), ChunkyPNG::Point.new(1, 2), ChunkyPNG::Point.new(3, 6)]) }
|
83
|
-
|
88
|
+
|
84
89
|
it "should return an empty vector when given an empty array" do
|
85
|
-
ChunkyPNG::Vector().
|
86
|
-
ChunkyPNG::Vector(*[]).
|
90
|
+
expect(ChunkyPNG::Vector()).to eql ChunkyPNG::Vector.new([])
|
91
|
+
expect(ChunkyPNG::Vector(*[])).to eql ChunkyPNG::Vector.new([])
|
87
92
|
end
|
88
93
|
|
89
94
|
it "should raise an error when an odd number of numerics is given" do
|
90
|
-
|
95
|
+
expect { ChunkyPNG::Vector(1, 2, 3) }.to raise_error(ArgumentError)
|
91
96
|
end
|
92
97
|
|
93
98
|
it "should create a vector from a string" do
|
94
|
-
ChunkyPNG::Vector('(2,4) (1,2) (3,6)').
|
99
|
+
expect(ChunkyPNG::Vector('(2,4) (1,2) (3,6)')).to eql example
|
95
100
|
end
|
96
|
-
|
101
|
+
|
97
102
|
it "should create a vector from a flat array" do
|
98
|
-
ChunkyPNG::Vector(2,4,1,2,3,6).
|
103
|
+
expect(ChunkyPNG::Vector(2,4,1,2,3,6)).to eql example
|
99
104
|
end
|
100
105
|
|
101
106
|
it "should create a vector from a nested array" do
|
102
|
-
ChunkyPNG::Vector('(2,4)', [1, 2], :x => 3, :y => 6).
|
107
|
+
expect(ChunkyPNG::Vector('(2,4)', [1, 2], :x => 3, :y => 6)).to eql example
|
103
108
|
end
|
104
109
|
end
|
data/spec/chunky_png_spec.rb
CHANGED
data/spec/png_suite_spec.rb
CHANGED
@@ -1,120 +1,120 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'PNG testuite' do
|
4
|
-
|
4
|
+
|
5
5
|
context 'Decoding broken images' do
|
6
6
|
png_suite_files(:broken).each do |file|
|
7
7
|
it "should report #{File.basename(file)} as broken" do
|
8
|
-
|
8
|
+
expect { ChunkyPNG::Image.from_file(file) }.to raise_error(ChunkyPNG::Exception)
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
context 'Decoding supported images' do
|
14
14
|
png_suite_files(:basic, '*.png').each do |file|
|
15
15
|
|
16
16
|
reference = file.sub(/\.png$/, '.rgba')
|
17
17
|
color_mode = file.match(/[in](\d)[apgc](\d\d)\.png$/)[1].to_i
|
18
18
|
bit_depth = file.match(/[in](\d)[apgc](\d\d)\.png$/)[2].to_i
|
19
|
-
|
19
|
+
|
20
20
|
it "should decode #{File.basename(file)} (color mode: #{color_mode}, bit depth: #{bit_depth}) exactly the same as the reference image" do
|
21
21
|
decoded = ChunkyPNG::Canvas.from_file(file)
|
22
|
-
File.open(reference, 'rb') { |f| decoded.to_rgba_stream.
|
22
|
+
File.open(reference, 'rb') { |f| expect(decoded.to_rgba_stream).to eql f.read }
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
context 'Decoding text chunks' do
|
28
|
-
|
28
|
+
|
29
29
|
it "should not find metadata in a file without text chunks" do
|
30
30
|
image = ChunkyPNG::Image.from_file(png_suite_file(:metadata, 'cm0n0g04.png'))
|
31
|
-
image.metadata.
|
31
|
+
expect(image.metadata).to be_empty
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
# it "should find metadata in a file with uncompressed text chunks" do
|
35
35
|
# image = ChunkyPNG::Image.from_file(png_suite_file(:metadata, 'cm7n0g04.png'))
|
36
36
|
# image.metadata.should_not be_empty
|
37
37
|
# end
|
38
|
-
#
|
38
|
+
#
|
39
39
|
# it "should find metadata in a file with compressed text chunks" do
|
40
40
|
# image = ChunkyPNG::Image.from_file(png_suite_file(:metadata, 'cm9n0g04.png'))
|
41
41
|
# image.metadata.should_not be_empty
|
42
42
|
# end
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
context 'Decoding filter methods' do
|
46
46
|
png_suite_files(:filtering, '*_reference.png').each do |reference_file|
|
47
47
|
|
48
48
|
file = reference_file.sub(/_reference\.png$/, '.png')
|
49
49
|
filter_method = file.match(/f(\d\d)[a-z0-9]+\.png/)[1].to_i
|
50
|
-
|
50
|
+
|
51
51
|
it "should decode #{File.basename(file)} (filter method: #{filter_method}) exactly the same as the reference image" do
|
52
52
|
decoded = ChunkyPNG::Canvas.from_file(file)
|
53
53
|
reference = ChunkyPNG::Canvas.from_file(reference_file)
|
54
|
-
decoded.
|
54
|
+
expect(decoded).to eql reference
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
context 'Decoding different chunk splits' do
|
60
60
|
it "should decode grayscale images successfully regardless of the data chunk ordering and splitting" do
|
61
61
|
reference = ChunkyPNG::Datastream.from_file(png_suite_file(:chunk_ordering, 'oi1n0g16.png')).imagedata
|
62
|
-
ChunkyPNG::Datastream.from_file(png_suite_file(:chunk_ordering, 'oi2n0g16.png')).imagedata.
|
63
|
-
ChunkyPNG::Datastream.from_file(png_suite_file(:chunk_ordering, 'oi4n0g16.png')).imagedata.
|
64
|
-
ChunkyPNG::Datastream.from_file(png_suite_file(:chunk_ordering, 'oi9n0g16.png')).imagedata.
|
62
|
+
expect(ChunkyPNG::Datastream.from_file(png_suite_file(:chunk_ordering, 'oi2n0g16.png')).imagedata).to eql reference
|
63
|
+
expect(ChunkyPNG::Datastream.from_file(png_suite_file(:chunk_ordering, 'oi4n0g16.png')).imagedata).to eql reference
|
64
|
+
expect(ChunkyPNG::Datastream.from_file(png_suite_file(:chunk_ordering, 'oi9n0g16.png')).imagedata).to eql reference
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
it "should decode color images successfully regardless of the data chunk ordering and splitting" do
|
68
68
|
reference = ChunkyPNG::Datastream.from_file(png_suite_file(:chunk_ordering, 'oi1n2c16.png')).imagedata
|
69
|
-
ChunkyPNG::Datastream.from_file(png_suite_file(:chunk_ordering, 'oi2n2c16.png')).imagedata.
|
70
|
-
ChunkyPNG::Datastream.from_file(png_suite_file(:chunk_ordering, 'oi4n2c16.png')).imagedata.
|
71
|
-
ChunkyPNG::Datastream.from_file(png_suite_file(:chunk_ordering, 'oi9n2c16.png')).imagedata.
|
69
|
+
expect(ChunkyPNG::Datastream.from_file(png_suite_file(:chunk_ordering, 'oi2n2c16.png')).imagedata).to eql reference
|
70
|
+
expect(ChunkyPNG::Datastream.from_file(png_suite_file(:chunk_ordering, 'oi4n2c16.png')).imagedata).to eql reference
|
71
|
+
expect(ChunkyPNG::Datastream.from_file(png_suite_file(:chunk_ordering, 'oi9n2c16.png')).imagedata).to eql reference
|
72
72
|
end
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
context 'Decoding different compression levels' do
|
76
76
|
it "should decode the image successfully regardless of the compression level" do
|
77
77
|
reference = ChunkyPNG::Datastream.from_file(png_suite_file(:compression_levels, 'z00n2c08.png')).imagedata
|
78
|
-
ChunkyPNG::Datastream.from_file(png_suite_file(:compression_levels, 'z03n2c08.png')).imagedata.
|
79
|
-
ChunkyPNG::Datastream.from_file(png_suite_file(:compression_levels, 'z06n2c08.png')).imagedata.
|
80
|
-
ChunkyPNG::Datastream.from_file(png_suite_file(:compression_levels, 'z09n2c08.png')).imagedata.
|
78
|
+
expect(ChunkyPNG::Datastream.from_file(png_suite_file(:compression_levels, 'z03n2c08.png')).imagedata).to eql reference
|
79
|
+
expect(ChunkyPNG::Datastream.from_file(png_suite_file(:compression_levels, 'z06n2c08.png')).imagedata).to eql reference
|
80
|
+
expect(ChunkyPNG::Datastream.from_file(png_suite_file(:compression_levels, 'z09n2c08.png')).imagedata).to eql reference
|
81
81
|
end
|
82
82
|
end
|
83
|
-
|
83
|
+
|
84
84
|
context 'Decoding transparency' do
|
85
85
|
png_suite_files(:transparency, 'tp0*.png').each do |file|
|
86
86
|
it "should not have transparency in #{File.basename(file)}" do
|
87
|
-
ChunkyPNG::Color.a(ChunkyPNG::Image.from_file(file)[0,0]).
|
87
|
+
expect(ChunkyPNG::Color.a(ChunkyPNG::Image.from_file(file)[0,0])).to eql 255
|
88
88
|
end
|
89
89
|
end
|
90
|
-
|
90
|
+
|
91
91
|
png_suite_files(:transparency, 'tp1*.png').each do |file|
|
92
92
|
it "should have transparency in #{File.basename(file)}" do
|
93
|
-
ChunkyPNG::Color.a(ChunkyPNG::Image.from_file(file)[0,0]).
|
93
|
+
expect(ChunkyPNG::Color.a(ChunkyPNG::Image.from_file(file)[0,0])).to eql 0
|
94
94
|
end
|
95
95
|
end
|
96
|
-
|
96
|
+
|
97
97
|
png_suite_files(:transparency, 'tb*.png').each do |file|
|
98
98
|
it "should have transparency in #{File.basename(file)}" do
|
99
|
-
ChunkyPNG::Color.a(ChunkyPNG::Image.from_file(file)[0,0]).
|
99
|
+
expect(ChunkyPNG::Color.a(ChunkyPNG::Image.from_file(file)[0,0])).to eql 0
|
100
100
|
end
|
101
101
|
end
|
102
102
|
end
|
103
|
-
|
103
|
+
|
104
104
|
context 'Decoding different sizes' do
|
105
|
-
|
105
|
+
|
106
106
|
png_suite_files(:sizes, '*n*.png').each do |file|
|
107
107
|
dimension = file.match(/s(\d\d)n\dp\d\d/)[1].to_i
|
108
|
-
|
108
|
+
|
109
109
|
it "should create a canvas with a #{dimension}x#{dimension} size" do
|
110
110
|
canvas = ChunkyPNG::Image.from_file(file)
|
111
|
-
canvas.width.
|
112
|
-
canvas.height.
|
111
|
+
expect(canvas.width).to eql dimension
|
112
|
+
expect(canvas.height).to eql dimension
|
113
113
|
end
|
114
|
-
|
114
|
+
|
115
115
|
it "should decode the #{dimension}x#{dimension} interlaced image exactly the same the non-interlaced version" do
|
116
116
|
interlaced_file = file.sub(/n3p(\d\d)\.png$/, 'i3p\\1.png')
|
117
|
-
ChunkyPNG::Image.from_file(interlaced_file).
|
117
|
+
expect(ChunkyPNG::Image.from_file(interlaced_file)).to eql ChunkyPNG::Image.from_file(file)
|
118
118
|
end
|
119
119
|
end
|
120
120
|
end
|