chunky_png 1.3.7 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/ruby.yml +35 -0
- data/.standard.yml +16 -0
- data/.yardopts +1 -1
- data/CHANGELOG.rdoc +20 -4
- data/CONTRIBUTING.rdoc +17 -8
- data/Gemfile +12 -4
- data/LICENSE +1 -1
- data/README.md +15 -9
- data/Rakefile +5 -3
- data/benchmarks/decoding_benchmark.rb +17 -17
- data/benchmarks/encoding_benchmark.rb +22 -19
- data/benchmarks/filesize_benchmark.rb +6 -6
- data/bin/rake +29 -0
- data/bin/standardrb +29 -0
- data/chunky_png.gemspec +21 -13
- data/docs/.gitignore +3 -0
- data/docs/CNAME +1 -0
- data/docs/_config.yml +9 -0
- data/docs/_posts/2010-01-14-memory-efficiency-when-using-ruby.md +136 -0
- data/docs/_posts/2010-01-17-ode-to-array-pack-and-string-unpack.md +82 -0
- data/docs/_posts/2014-11-07-the-value-of-a-pure-ruby-library.md +61 -0
- data/docs/index.md +88 -0
- data/lib/chunky_png/canvas/adam7_interlacing.rb +16 -10
- data/lib/chunky_png/canvas/data_url_exporting.rb +3 -3
- data/lib/chunky_png/canvas/data_url_importing.rb +3 -3
- data/lib/chunky_png/canvas/drawing.rb +30 -43
- data/lib/chunky_png/canvas/masking.rb +14 -14
- data/lib/chunky_png/canvas/operations.rb +28 -24
- data/lib/chunky_png/canvas/png_decoding.rb +39 -33
- data/lib/chunky_png/canvas/png_encoding.rb +111 -103
- data/lib/chunky_png/canvas/resampling.rb +27 -32
- data/lib/chunky_png/canvas/stream_exporting.rb +8 -8
- data/lib/chunky_png/canvas/stream_importing.rb +8 -8
- data/lib/chunky_png/canvas.rb +31 -28
- data/lib/chunky_png/chunk.rb +170 -55
- data/lib/chunky_png/color.rb +218 -212
- data/lib/chunky_png/datastream.rb +29 -29
- data/lib/chunky_png/dimension.rb +18 -11
- data/lib/chunky_png/image.rb +11 -11
- data/lib/chunky_png/palette.rb +13 -14
- data/lib/chunky_png/point.rb +27 -26
- data/lib/chunky_png/rmagick.rb +10 -10
- data/lib/chunky_png/vector.rb +28 -29
- data/lib/chunky_png/version.rb +3 -1
- data/lib/chunky_png.rb +49 -43
- data/spec/chunky_png/canvas/adam7_interlacing_spec.rb +20 -21
- data/spec/chunky_png/canvas/data_url_exporting_spec.rb +8 -5
- data/spec/chunky_png/canvas/data_url_importing_spec.rb +5 -6
- data/spec/chunky_png/canvas/drawing_spec.rb +46 -38
- data/spec/chunky_png/canvas/masking_spec.rb +15 -16
- data/spec/chunky_png/canvas/operations_spec.rb +68 -67
- data/spec/chunky_png/canvas/png_decoding_spec.rb +37 -38
- data/spec/chunky_png/canvas/png_encoding_spec.rb +59 -50
- data/spec/chunky_png/canvas/resampling_spec.rb +19 -21
- data/spec/chunky_png/canvas/stream_exporting_spec.rb +47 -27
- data/spec/chunky_png/canvas/stream_importing_spec.rb +10 -11
- data/spec/chunky_png/canvas_spec.rb +63 -52
- data/spec/chunky_png/color_spec.rb +115 -114
- data/spec/chunky_png/datastream_spec.rb +110 -13
- data/spec/chunky_png/dimension_spec.rb +10 -10
- data/spec/chunky_png/image_spec.rb +11 -14
- data/spec/chunky_png/point_spec.rb +21 -23
- data/spec/chunky_png/rmagick_spec.rb +7 -8
- data/spec/chunky_png/vector_spec.rb +21 -17
- data/spec/chunky_png_spec.rb +2 -2
- data/spec/png_suite_spec.rb +35 -40
- data/spec/resources/itxt_chunk.png +0 -0
- data/spec/spec_helper.rb +15 -9
- data/tasks/benchmarks.rake +7 -8
- metadata +65 -25
- data/.travis.yml +0 -16
- data/lib/chunky_png/compatibility.rb +0 -15
@@ -1,31 +1,28 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe ChunkyPNG::Image do
|
4
|
-
describe
|
5
|
-
|
4
|
+
describe "#metadata" do
|
6
5
|
it "should load metadata from an existing file" do
|
7
|
-
image = ChunkyPNG::Image.from_file(resource_file(
|
8
|
-
expect(image.metadata[
|
9
|
-
expect(image.metadata[
|
6
|
+
image = ChunkyPNG::Image.from_file(resource_file("text_chunk.png"))
|
7
|
+
expect(image.metadata["Title"]).to eql "My amazing icon!"
|
8
|
+
expect(image.metadata["Author"]).to eql "Willem van Bergen"
|
10
9
|
end
|
11
10
|
|
12
11
|
it "should write metadata to the file correctly" do
|
13
|
-
filename = resource_file(
|
12
|
+
filename = resource_file("_metadata.png")
|
14
13
|
|
15
14
|
image = ChunkyPNG::Image.new(10, 10)
|
16
|
-
image.metadata[
|
17
|
-
image.metadata[
|
15
|
+
image.metadata["Title"] = "My amazing icon!"
|
16
|
+
image.metadata["Author"] = "Willem van Bergen"
|
18
17
|
image.save(filename)
|
19
18
|
|
20
19
|
metadata = ChunkyPNG::Datastream.from_file(filename).metadata
|
21
|
-
expect(metadata[
|
22
|
-
expect(metadata[
|
20
|
+
expect(metadata["Title"]).to eql "My amazing icon!"
|
21
|
+
expect(metadata["Author"]).to eql "Willem van Bergen"
|
23
22
|
end
|
24
23
|
|
25
24
|
it "should load empty images correctly" do
|
26
|
-
expect
|
27
|
-
ChunkyPNG::Image.from_file(resource_file('empty.png'))
|
28
|
-
end.to_not raise_error
|
25
|
+
expect { ChunkyPNG::Image.from_file(resource_file("empty.png")) }.to_not raise_error
|
29
26
|
end
|
30
27
|
end
|
31
28
|
end
|
@@ -1,58 +1,56 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe ChunkyPNG::Point do
|
4
|
-
|
5
4
|
subject { ChunkyPNG::Point.new(1, 2) }
|
6
5
|
|
7
6
|
it { should respond_to(:x) }
|
8
7
|
it { should respond_to(:y) }
|
9
8
|
|
10
|
-
describe
|
9
|
+
describe "#within_bounds?" do
|
11
10
|
it { should be_within_bounds(2, 3) }
|
12
|
-
it { should_not be_within_bounds(
|
11
|
+
it { should_not be_within_bounds("1x3") }
|
13
12
|
it { should_not be_within_bounds(2, 2) }
|
14
|
-
it { should_not be_within_bounds(
|
13
|
+
it { should_not be_within_bounds("[1 2]") }
|
15
14
|
end
|
16
15
|
|
17
|
-
describe
|
16
|
+
describe "#<=>" do
|
18
17
|
it "should return 0 if the coordinates are identical" do
|
19
|
-
expect((subject <=> ChunkyPNG::Point.new(1, 2))).to eql
|
18
|
+
expect((subject <=> ChunkyPNG::Point.new(1, 2))).to eql(0)
|
20
19
|
end
|
21
20
|
|
22
21
|
it "should return -1 if the y coordinate is smaller than the other one" do
|
23
|
-
expect((subject <=> ChunkyPNG::Point.new(1, 3))).to eql
|
24
|
-
expect((subject <=> ChunkyPNG::Point.new(0, 3))).to eql
|
25
|
-
expect((subject <=> ChunkyPNG::Point.new(2, 3))).to eql
|
22
|
+
expect((subject <=> ChunkyPNG::Point.new(1, 3))).to eql(-1)
|
23
|
+
expect((subject <=> ChunkyPNG::Point.new(0, 3))).to eql(-1) # x doesn't matter
|
24
|
+
expect((subject <=> ChunkyPNG::Point.new(2, 3))).to eql(-1) # x doesn't matter
|
26
25
|
end
|
27
26
|
|
28
27
|
it "should return 1 if the y coordinate is larger than the other one" do
|
29
|
-
expect((subject <=> ChunkyPNG::Point.new(1, 0))).to eql
|
30
|
-
expect((subject <=> ChunkyPNG::Point.new(0, 0))).to eql
|
31
|
-
expect((subject <=> ChunkyPNG::Point.new(2, 0))).to eql
|
28
|
+
expect((subject <=> ChunkyPNG::Point.new(1, 0))).to eql(1)
|
29
|
+
expect((subject <=> ChunkyPNG::Point.new(0, 0))).to eql(1) # x doesn't matter
|
30
|
+
expect((subject <=> ChunkyPNG::Point.new(2, 0))).to eql(1) # x doesn't matter
|
32
31
|
end
|
33
32
|
|
34
33
|
it "should return -1 if the x coordinate is smaller and y is the same" do
|
35
|
-
expect((subject <=> ChunkyPNG::Point.new(2, 2))).to eql
|
34
|
+
expect((subject <=> ChunkyPNG::Point.new(2, 2))).to eql(-1)
|
36
35
|
end
|
37
36
|
|
38
37
|
it "should return 1 if the x coordinate is larger and y is the same" do
|
39
|
-
expect((subject <=> ChunkyPNG::Point.new(0, 2))).to eql
|
38
|
+
expect((subject <=> ChunkyPNG::Point.new(0, 2))).to eql(1)
|
40
39
|
end
|
41
40
|
end
|
42
41
|
end
|
43
42
|
|
44
|
-
describe
|
43
|
+
describe "ChunkyPNG.Point" do
|
45
44
|
subject { ChunkyPNG::Point.new(1, 2) }
|
46
45
|
|
47
|
-
|
48
46
|
it "should create a point from a 2-item array" do
|
49
47
|
expect(ChunkyPNG::Point([1, 2])).to eql subject
|
50
|
-
expect(ChunkyPNG::Point([
|
48
|
+
expect(ChunkyPNG::Point(["1", "2"])).to eql subject
|
51
49
|
end
|
52
50
|
|
53
51
|
it "should create a point from a hash with x and y keys" do
|
54
|
-
expect(ChunkyPNG::Point(:
|
55
|
-
expect(ChunkyPNG::Point(
|
52
|
+
expect(ChunkyPNG::Point(x: 1, y: 2)).to eql subject
|
53
|
+
expect(ChunkyPNG::Point("x" => "1", "y" => "2")).to eql subject
|
56
54
|
end
|
57
55
|
|
58
56
|
it "should create a point from a ChunkyPNG::Dimension object" do
|
@@ -62,9 +60,9 @@ describe 'ChunkyPNG.Point' do
|
|
62
60
|
|
63
61
|
it "should create a point from a point-like string" do
|
64
62
|
[
|
65
|
-
ChunkyPNG::Point(
|
66
|
-
ChunkyPNG::Point(
|
67
|
-
ChunkyPNG::Point(
|
63
|
+
ChunkyPNG::Point("1,2"),
|
64
|
+
ChunkyPNG::Point("1 2"),
|
65
|
+
ChunkyPNG::Point("(1 , 2)"),
|
68
66
|
ChunkyPNG::Point("{1,\t2}"),
|
69
67
|
ChunkyPNG::Point("[1 2}"),
|
70
68
|
].all? { |point| point == subject }
|
@@ -1,23 +1,22 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
begin
|
4
|
-
require
|
4
|
+
require "chunky_png/rmagick"
|
5
5
|
|
6
6
|
describe ChunkyPNG::RMagick do
|
7
|
-
|
8
7
|
it "should import an image from RMagick correctly" do
|
9
|
-
image = Magick::Image.read(resource_file(
|
8
|
+
image = Magick::Image.read(resource_file("composited.png")).first
|
10
9
|
canvas = ChunkyPNG::RMagick.import(image)
|
11
|
-
expect(canvas).to eql reference_canvas(
|
10
|
+
expect(canvas).to eql reference_canvas("composited")
|
12
11
|
end
|
13
12
|
|
14
13
|
it "should export an image to RMagick correctly" do
|
15
|
-
canvas = reference_canvas(
|
14
|
+
canvas = reference_canvas("composited")
|
16
15
|
image = ChunkyPNG::RMagick.export(canvas)
|
17
|
-
image.format =
|
16
|
+
image.format = "PNG32"
|
18
17
|
expect(canvas).to eql ChunkyPNG::Canvas.from_blob(image.to_blob)
|
19
18
|
end
|
20
19
|
end
|
21
|
-
rescue LoadError
|
20
|
+
rescue LoadError
|
22
21
|
# skipping RMagick tests
|
23
22
|
end
|
@@ -1,17 +1,17 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
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
|
8
|
+
describe "#length" do
|
9
9
|
it "shopuld have 3 items" do
|
10
10
|
expect(subject.length).to eql(3)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
describe
|
14
|
+
describe "#x_range" do
|
15
15
|
it "should get the right range of x values" do
|
16
16
|
expect(subject.x_range).to eql(1..4)
|
17
17
|
end
|
@@ -29,7 +29,7 @@ describe ChunkyPNG::Vector do
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
describe
|
32
|
+
describe "#y_range" do
|
33
33
|
it "should get the right range of y values" do
|
34
34
|
expect(subject.y_range).to eql(3..6)
|
35
35
|
end
|
@@ -47,7 +47,7 @@ describe ChunkyPNG::Vector do
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
describe
|
50
|
+
describe "#offset" do
|
51
51
|
it "should return a ChunkyPNG::Point" do
|
52
52
|
expect(subject.offset).to be_kind_of(ChunkyPNG::Point)
|
53
53
|
end
|
@@ -58,7 +58,7 @@ describe ChunkyPNG::Vector do
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
describe
|
61
|
+
describe "#dimension" do
|
62
62
|
it "should return a ChunkyPNG::Dimension" do
|
63
63
|
expect(subject.dimension).to be_kind_of(ChunkyPNG::Dimension)
|
64
64
|
end
|
@@ -69,26 +69,30 @@ describe ChunkyPNG::Vector do
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
|
-
describe
|
72
|
+
describe "#edges" do
|
73
73
|
it "should get three edges when closing the path" do
|
74
|
-
expect(subject.edges(true).to_a).to eql [
|
75
|
-
|
76
|
-
|
74
|
+
expect(subject.edges(true).to_a).to eql [
|
75
|
+
[ChunkyPNG::Point.new(2, 5), ChunkyPNG::Point.new(1, 3)],
|
76
|
+
[ChunkyPNG::Point.new(1, 3), ChunkyPNG::Point.new(4, 6)],
|
77
|
+
[ChunkyPNG::Point.new(4, 6), ChunkyPNG::Point.new(2, 5)],
|
78
|
+
]
|
77
79
|
end
|
78
80
|
|
79
81
|
it "should get two edges when not closing the path" do
|
80
|
-
expect(subject.edges(false).to_a).to eql [
|
81
|
-
|
82
|
+
expect(subject.edges(false).to_a).to eql [
|
83
|
+
[ChunkyPNG::Point.new(2, 5), ChunkyPNG::Point.new(1, 3)],
|
84
|
+
[ChunkyPNG::Point.new(1, 3), ChunkyPNG::Point.new(4, 6)],
|
85
|
+
]
|
82
86
|
end
|
83
87
|
end
|
84
88
|
end
|
85
89
|
|
86
|
-
describe
|
90
|
+
describe "ChunkyPNG.Vector" do
|
87
91
|
let(:example) { ChunkyPNG::Vector.new([ChunkyPNG::Point.new(2, 4), ChunkyPNG::Point.new(1, 2), ChunkyPNG::Point.new(3, 6)]) }
|
88
92
|
|
89
93
|
it "should return an empty vector when given an empty array" do
|
90
94
|
expect(ChunkyPNG::Vector()).to eql ChunkyPNG::Vector.new([])
|
91
|
-
expect(ChunkyPNG::Vector(*[])).to eql ChunkyPNG::Vector.new([])
|
95
|
+
expect(ChunkyPNG::Vector(*[])).to eql ChunkyPNG::Vector.new([]) # rubocop:disable Lint/UnneededSplatExpansion
|
92
96
|
end
|
93
97
|
|
94
98
|
it "should raise an error when an odd number of numerics is given" do
|
@@ -96,14 +100,14 @@ describe 'ChunkyPNG.Vector' do
|
|
96
100
|
end
|
97
101
|
|
98
102
|
it "should create a vector from a string" do
|
99
|
-
expect(ChunkyPNG::Vector(
|
103
|
+
expect(ChunkyPNG::Vector("(2,4) (1,2) (3,6)")).to eql example
|
100
104
|
end
|
101
105
|
|
102
106
|
it "should create a vector from a flat array" do
|
103
|
-
expect(ChunkyPNG::Vector(2,4,1,2,3,6)).to eql example
|
107
|
+
expect(ChunkyPNG::Vector(2, 4, 1, 2, 3, 6)).to eql example
|
104
108
|
end
|
105
109
|
|
106
110
|
it "should create a vector from a nested array" do
|
107
|
-
expect(ChunkyPNG::Vector(
|
111
|
+
expect(ChunkyPNG::Vector("(2,4)", [1, 2], x: 3, y: 6)).to eql example
|
108
112
|
end
|
109
113
|
end
|
data/spec/chunky_png_spec.rb
CHANGED
data/spec/png_suite_spec.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
|
-
describe
|
4
|
-
|
5
|
-
context 'Decoding broken images' do
|
3
|
+
describe "PNG testuite" do
|
4
|
+
context "Decoding broken images" do
|
6
5
|
png_suite_files(:broken).each do |file|
|
7
6
|
it "should report #{File.basename(file)} as broken" do
|
8
7
|
expect { ChunkyPNG::Image.from_file(file) }.to raise_error(ChunkyPNG::Exception)
|
@@ -10,24 +9,22 @@ describe 'PNG testuite' do
|
|
10
9
|
end
|
11
10
|
end
|
12
11
|
|
13
|
-
context
|
14
|
-
png_suite_files(:basic,
|
15
|
-
|
16
|
-
reference = file.sub(/\.png$/, '.rgba')
|
12
|
+
context "Decoding supported images" do
|
13
|
+
png_suite_files(:basic, "*.png").each do |file|
|
14
|
+
reference = file.sub(/\.png$/, ".rgba")
|
17
15
|
color_mode = file.match(/[in](\d)[apgc](\d\d)\.png$/)[1].to_i
|
18
16
|
bit_depth = file.match(/[in](\d)[apgc](\d\d)\.png$/)[2].to_i
|
19
17
|
|
20
18
|
it "should decode #{File.basename(file)} (color mode: #{color_mode}, bit depth: #{bit_depth}) exactly the same as the reference image" do
|
21
19
|
decoded = ChunkyPNG::Canvas.from_file(file)
|
22
|
-
|
20
|
+
expect(decoded.to_rgba_stream).to eql(File.read(reference, mode: "rb"))
|
23
21
|
end
|
24
22
|
end
|
25
23
|
end
|
26
24
|
|
27
|
-
context
|
28
|
-
|
25
|
+
context "Decoding text chunks" do
|
29
26
|
it "should not find metadata in a file without text chunks" do
|
30
|
-
image = ChunkyPNG::Image.from_file(png_suite_file(:metadata,
|
27
|
+
image = ChunkyPNG::Image.from_file(png_suite_file(:metadata, "cm0n0g04.png"))
|
31
28
|
expect(image.metadata).to be_empty
|
32
29
|
end
|
33
30
|
|
@@ -42,10 +39,9 @@ describe 'PNG testuite' do
|
|
42
39
|
# end
|
43
40
|
end
|
44
41
|
|
45
|
-
context
|
46
|
-
png_suite_files(:filtering,
|
47
|
-
|
48
|
-
file = reference_file.sub(/_reference\.png$/, '.png')
|
42
|
+
context "Decoding filter methods" do
|
43
|
+
png_suite_files(:filtering, "*_reference.png").each do |reference_file|
|
44
|
+
file = reference_file.sub(/_reference\.png$/, ".png")
|
49
45
|
filter_method = file.match(/f(\d\d)[a-z0-9]+\.png/)[1].to_i
|
50
46
|
|
51
47
|
it "should decode #{File.basename(file)} (filter method: #{filter_method}) exactly the same as the reference image" do
|
@@ -56,54 +52,53 @@ describe 'PNG testuite' do
|
|
56
52
|
end
|
57
53
|
end
|
58
54
|
|
59
|
-
context
|
55
|
+
context "Decoding different chunk splits" do
|
60
56
|
it "should decode grayscale images successfully regardless of the data chunk ordering and splitting" do
|
61
|
-
reference = ChunkyPNG::Datastream.from_file(png_suite_file(:chunk_ordering,
|
62
|
-
expect(ChunkyPNG::Datastream.from_file(png_suite_file(:chunk_ordering,
|
63
|
-
expect(ChunkyPNG::Datastream.from_file(png_suite_file(:chunk_ordering,
|
64
|
-
expect(ChunkyPNG::Datastream.from_file(png_suite_file(:chunk_ordering,
|
57
|
+
reference = ChunkyPNG::Datastream.from_file(png_suite_file(:chunk_ordering, "oi1n0g16.png")).imagedata
|
58
|
+
expect(ChunkyPNG::Datastream.from_file(png_suite_file(:chunk_ordering, "oi2n0g16.png")).imagedata).to eql reference
|
59
|
+
expect(ChunkyPNG::Datastream.from_file(png_suite_file(:chunk_ordering, "oi4n0g16.png")).imagedata).to eql reference
|
60
|
+
expect(ChunkyPNG::Datastream.from_file(png_suite_file(:chunk_ordering, "oi9n0g16.png")).imagedata).to eql reference
|
65
61
|
end
|
66
62
|
|
67
63
|
it "should decode color images successfully regardless of the data chunk ordering and splitting" do
|
68
|
-
reference = ChunkyPNG::Datastream.from_file(png_suite_file(:chunk_ordering,
|
69
|
-
expect(ChunkyPNG::Datastream.from_file(png_suite_file(:chunk_ordering,
|
70
|
-
expect(ChunkyPNG::Datastream.from_file(png_suite_file(:chunk_ordering,
|
71
|
-
expect(ChunkyPNG::Datastream.from_file(png_suite_file(:chunk_ordering,
|
64
|
+
reference = ChunkyPNG::Datastream.from_file(png_suite_file(:chunk_ordering, "oi1n2c16.png")).imagedata
|
65
|
+
expect(ChunkyPNG::Datastream.from_file(png_suite_file(:chunk_ordering, "oi2n2c16.png")).imagedata).to eql reference
|
66
|
+
expect(ChunkyPNG::Datastream.from_file(png_suite_file(:chunk_ordering, "oi4n2c16.png")).imagedata).to eql reference
|
67
|
+
expect(ChunkyPNG::Datastream.from_file(png_suite_file(:chunk_ordering, "oi9n2c16.png")).imagedata).to eql reference
|
72
68
|
end
|
73
69
|
end
|
74
70
|
|
75
|
-
context
|
71
|
+
context "Decoding different compression levels" do
|
76
72
|
it "should decode the image successfully regardless of the compression level" do
|
77
|
-
reference = ChunkyPNG::Datastream.from_file(png_suite_file(:compression_levels,
|
78
|
-
expect(ChunkyPNG::Datastream.from_file(png_suite_file(:compression_levels,
|
79
|
-
expect(ChunkyPNG::Datastream.from_file(png_suite_file(:compression_levels,
|
80
|
-
expect(ChunkyPNG::Datastream.from_file(png_suite_file(:compression_levels,
|
73
|
+
reference = ChunkyPNG::Datastream.from_file(png_suite_file(:compression_levels, "z00n2c08.png")).imagedata
|
74
|
+
expect(ChunkyPNG::Datastream.from_file(png_suite_file(:compression_levels, "z03n2c08.png")).imagedata).to eql reference
|
75
|
+
expect(ChunkyPNG::Datastream.from_file(png_suite_file(:compression_levels, "z06n2c08.png")).imagedata).to eql reference
|
76
|
+
expect(ChunkyPNG::Datastream.from_file(png_suite_file(:compression_levels, "z09n2c08.png")).imagedata).to eql reference
|
81
77
|
end
|
82
78
|
end
|
83
79
|
|
84
|
-
context
|
85
|
-
png_suite_files(:transparency,
|
80
|
+
context "Decoding transparency" do
|
81
|
+
png_suite_files(:transparency, "tp0*.png").each do |file|
|
86
82
|
it "should not have transparency in #{File.basename(file)}" do
|
87
|
-
expect(ChunkyPNG::Color.a(ChunkyPNG::Image.from_file(file)[0,0])).to eql 255
|
83
|
+
expect(ChunkyPNG::Color.a(ChunkyPNG::Image.from_file(file)[0, 0])).to eql 255
|
88
84
|
end
|
89
85
|
end
|
90
86
|
|
91
|
-
png_suite_files(:transparency,
|
87
|
+
png_suite_files(:transparency, "tp1*.png").each do |file|
|
92
88
|
it "should have transparency in #{File.basename(file)}" do
|
93
|
-
expect(ChunkyPNG::Color.a(ChunkyPNG::Image.from_file(file)[0,0])).to eql 0
|
89
|
+
expect(ChunkyPNG::Color.a(ChunkyPNG::Image.from_file(file)[0, 0])).to eql 0
|
94
90
|
end
|
95
91
|
end
|
96
92
|
|
97
|
-
png_suite_files(:transparency,
|
93
|
+
png_suite_files(:transparency, "tb*.png").each do |file|
|
98
94
|
it "should have transparency in #{File.basename(file)}" do
|
99
|
-
expect(ChunkyPNG::Color.a(ChunkyPNG::Image.from_file(file)[0,0])).to eql 0
|
95
|
+
expect(ChunkyPNG::Color.a(ChunkyPNG::Image.from_file(file)[0, 0])).to eql 0
|
100
96
|
end
|
101
97
|
end
|
102
98
|
end
|
103
99
|
|
104
|
-
context
|
105
|
-
|
106
|
-
png_suite_files(:sizes, '*n*.png').each do |file|
|
100
|
+
context "Decoding different sizes" do
|
101
|
+
png_suite_files(:sizes, "*n*.png").each do |file|
|
107
102
|
dimension = file.match(/s(\d\d)n\dp\d\d/)[1].to_i
|
108
103
|
|
109
104
|
it "should create a canvas with a #{dimension}x#{dimension} size" do
|
Binary file
|
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "rubygems"
|
2
|
+
require "bundler/setup"
|
3
|
+
require "chunky_png"
|
4
4
|
|
5
5
|
module PNGSuite
|
6
|
-
|
7
6
|
def png_suite_file(kind, file)
|
8
7
|
File.join(png_suite_dir(kind), file)
|
9
8
|
end
|
@@ -12,21 +11,19 @@ module PNGSuite
|
|
12
11
|
File.expand_path("./png_suite/#{kind}", File.dirname(__FILE__))
|
13
12
|
end
|
14
13
|
|
15
|
-
def png_suite_files(kind, pattern =
|
14
|
+
def png_suite_files(kind, pattern = "*.png")
|
16
15
|
Dir[File.join(png_suite_dir(kind), pattern)]
|
17
16
|
end
|
18
17
|
end
|
19
18
|
|
20
|
-
|
21
19
|
module ResourceFileHelper
|
22
|
-
|
23
20
|
def resource_file(name)
|
24
21
|
File.expand_path("./resources/#{name}", File.dirname(__FILE__))
|
25
22
|
end
|
26
23
|
|
27
24
|
def resource_data(name)
|
28
25
|
data = nil
|
29
|
-
File.open(resource_file(name),
|
26
|
+
File.open(resource_file(name), "rb") { |f| data = f.read }
|
30
27
|
data
|
31
28
|
end
|
32
29
|
|
@@ -39,16 +36,25 @@ module ResourceFileHelper
|
|
39
36
|
end
|
40
37
|
|
41
38
|
def display(png)
|
42
|
-
filename = resource_file(
|
39
|
+
filename = resource_file("_tmp.png")
|
43
40
|
png.save(filename)
|
44
41
|
`open #{filename}`
|
45
42
|
end
|
46
43
|
end
|
47
44
|
|
45
|
+
module ChunkOperationsHelper
|
46
|
+
def serialized_chunk(chunk)
|
47
|
+
chunk.write(stream = StringIO.new)
|
48
|
+
stream.rewind
|
49
|
+
ChunkyPNG::Chunk.read(stream)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
48
53
|
RSpec.configure do |config|
|
49
54
|
config.extend PNGSuite
|
50
55
|
config.include PNGSuite
|
51
56
|
config.include ResourceFileHelper
|
57
|
+
config.include ChunkOperationsHelper
|
52
58
|
|
53
59
|
config.expect_with :rspec do |c|
|
54
60
|
c.syntax = [:should, :expect]
|
data/tasks/benchmarks.rake
CHANGED
@@ -1,24 +1,23 @@
|
|
1
1
|
all_benchamrk_tasks = []
|
2
2
|
|
3
3
|
namespace(:benchmark) do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
Dir[File.join(File.dirname(__FILE__), "..", "benchmarks", "*_benchmark.rb")]. each do |benchmark_file|
|
5
|
+
task_name = File.basename(benchmark_file, "_benchmark.rb").to_sym
|
6
|
+
|
8
7
|
desc "Run the #{task_name} benchmark."
|
9
8
|
task(task_name, :n) do |task, args|
|
10
|
-
ENV[
|
9
|
+
ENV["N"] = args[:n] if args[:n]
|
11
10
|
load(File.expand_path(benchmark_file))
|
12
11
|
end
|
13
|
-
|
12
|
+
|
14
13
|
all_benchamrk_tasks << "benchmark:#{task_name}"
|
15
14
|
end
|
16
15
|
end
|
17
16
|
|
18
17
|
unless all_benchamrk_tasks.empty?
|
19
|
-
desc
|
18
|
+
desc "Run the whole benchmark suite"
|
20
19
|
task(:benchmark, :n) do |task, args|
|
21
|
-
all_benchamrk_tasks.each do |t|
|
20
|
+
all_benchamrk_tasks.each do |t|
|
22
21
|
task(t).invoke(args[:n])
|
23
22
|
puts
|
24
23
|
end
|