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.
Files changed (73) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ruby.yml +35 -0
  3. data/.standard.yml +16 -0
  4. data/.yardopts +1 -1
  5. data/CHANGELOG.rdoc +20 -4
  6. data/CONTRIBUTING.rdoc +17 -8
  7. data/Gemfile +12 -4
  8. data/LICENSE +1 -1
  9. data/README.md +15 -9
  10. data/Rakefile +5 -3
  11. data/benchmarks/decoding_benchmark.rb +17 -17
  12. data/benchmarks/encoding_benchmark.rb +22 -19
  13. data/benchmarks/filesize_benchmark.rb +6 -6
  14. data/bin/rake +29 -0
  15. data/bin/standardrb +29 -0
  16. data/chunky_png.gemspec +21 -13
  17. data/docs/.gitignore +3 -0
  18. data/docs/CNAME +1 -0
  19. data/docs/_config.yml +9 -0
  20. data/docs/_posts/2010-01-14-memory-efficiency-when-using-ruby.md +136 -0
  21. data/docs/_posts/2010-01-17-ode-to-array-pack-and-string-unpack.md +82 -0
  22. data/docs/_posts/2014-11-07-the-value-of-a-pure-ruby-library.md +61 -0
  23. data/docs/index.md +88 -0
  24. data/lib/chunky_png/canvas/adam7_interlacing.rb +16 -10
  25. data/lib/chunky_png/canvas/data_url_exporting.rb +3 -3
  26. data/lib/chunky_png/canvas/data_url_importing.rb +3 -3
  27. data/lib/chunky_png/canvas/drawing.rb +30 -43
  28. data/lib/chunky_png/canvas/masking.rb +14 -14
  29. data/lib/chunky_png/canvas/operations.rb +28 -24
  30. data/lib/chunky_png/canvas/png_decoding.rb +39 -33
  31. data/lib/chunky_png/canvas/png_encoding.rb +111 -103
  32. data/lib/chunky_png/canvas/resampling.rb +27 -32
  33. data/lib/chunky_png/canvas/stream_exporting.rb +8 -8
  34. data/lib/chunky_png/canvas/stream_importing.rb +8 -8
  35. data/lib/chunky_png/canvas.rb +31 -28
  36. data/lib/chunky_png/chunk.rb +170 -55
  37. data/lib/chunky_png/color.rb +218 -212
  38. data/lib/chunky_png/datastream.rb +29 -29
  39. data/lib/chunky_png/dimension.rb +18 -11
  40. data/lib/chunky_png/image.rb +11 -11
  41. data/lib/chunky_png/palette.rb +13 -14
  42. data/lib/chunky_png/point.rb +27 -26
  43. data/lib/chunky_png/rmagick.rb +10 -10
  44. data/lib/chunky_png/vector.rb +28 -29
  45. data/lib/chunky_png/version.rb +3 -1
  46. data/lib/chunky_png.rb +49 -43
  47. data/spec/chunky_png/canvas/adam7_interlacing_spec.rb +20 -21
  48. data/spec/chunky_png/canvas/data_url_exporting_spec.rb +8 -5
  49. data/spec/chunky_png/canvas/data_url_importing_spec.rb +5 -6
  50. data/spec/chunky_png/canvas/drawing_spec.rb +46 -38
  51. data/spec/chunky_png/canvas/masking_spec.rb +15 -16
  52. data/spec/chunky_png/canvas/operations_spec.rb +68 -67
  53. data/spec/chunky_png/canvas/png_decoding_spec.rb +37 -38
  54. data/spec/chunky_png/canvas/png_encoding_spec.rb +59 -50
  55. data/spec/chunky_png/canvas/resampling_spec.rb +19 -21
  56. data/spec/chunky_png/canvas/stream_exporting_spec.rb +47 -27
  57. data/spec/chunky_png/canvas/stream_importing_spec.rb +10 -11
  58. data/spec/chunky_png/canvas_spec.rb +63 -52
  59. data/spec/chunky_png/color_spec.rb +115 -114
  60. data/spec/chunky_png/datastream_spec.rb +110 -13
  61. data/spec/chunky_png/dimension_spec.rb +10 -10
  62. data/spec/chunky_png/image_spec.rb +11 -14
  63. data/spec/chunky_png/point_spec.rb +21 -23
  64. data/spec/chunky_png/rmagick_spec.rb +7 -8
  65. data/spec/chunky_png/vector_spec.rb +21 -17
  66. data/spec/chunky_png_spec.rb +2 -2
  67. data/spec/png_suite_spec.rb +35 -40
  68. data/spec/resources/itxt_chunk.png +0 -0
  69. data/spec/spec_helper.rb +15 -9
  70. data/tasks/benchmarks.rake +7 -8
  71. metadata +65 -25
  72. data/.travis.yml +0 -16
  73. data/lib/chunky_png/compatibility.rb +0 -15
@@ -1,31 +1,28 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe ChunkyPNG::Image do
4
- describe '#metadata' do
5
-
4
+ describe "#metadata" do
6
5
  it "should load metadata from an existing file" do
7
- image = ChunkyPNG::Image.from_file(resource_file('text_chunk.png'))
8
- expect(image.metadata['Title']).to eql 'My amazing icon!'
9
- expect(image.metadata['Author']).to eql 'Willem van Bergen'
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('_metadata.png')
12
+ filename = resource_file("_metadata.png")
14
13
 
15
14
  image = ChunkyPNG::Image.new(10, 10)
16
- image.metadata['Title'] = 'My amazing icon!'
17
- image.metadata['Author'] = 'Willem van Bergen'
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['Title']).to eql 'My amazing icon!'
22
- expect(metadata['Author']).to eql 'Willem van Bergen'
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 do
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 'spec_helper'
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 '#within_bounds?' do
9
+ describe "#within_bounds?" do
11
10
  it { should be_within_bounds(2, 3) }
12
- it { should_not be_within_bounds('1x3') }
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('[1 2]') }
13
+ it { should_not be_within_bounds("[1 2]") }
15
14
  end
16
15
 
17
- describe '#<=>' do
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 0
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 -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
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 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
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 -1
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 1
38
+ expect((subject <=> ChunkyPNG::Point.new(0, 2))).to eql(1)
40
39
  end
41
40
  end
42
41
  end
43
42
 
44
- describe 'ChunkyPNG.Point' do
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(['1', '2'])).to eql subject
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(:x => 1, :y => 2)).to eql subject
55
- expect(ChunkyPNG::Point('x' => '1', 'y' => '2')).to eql subject
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('1,2'),
66
- ChunkyPNG::Point('1 2'),
67
- ChunkyPNG::Point('(1 , 2)'),
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 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  begin
4
- require 'chunky_png/rmagick'
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('composited.png')).first
8
+ image = Magick::Image.read(resource_file("composited.png")).first
10
9
  canvas = ChunkyPNG::RMagick.import(image)
11
- expect(canvas).to eql reference_canvas('composited')
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('composited')
14
+ canvas = reference_canvas("composited")
16
15
  image = ChunkyPNG::RMagick.export(canvas)
17
- image.format = 'PNG32'
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 => e
20
+ rescue LoadError
22
21
  # skipping RMagick tests
23
22
  end
@@ -1,17 +1,17 @@
1
- require 'spec_helper'
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 '#length' do
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 '#x_range' do
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 '#y_range' do
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 '#offset' do
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 '#dimension' do
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 '#edges' do
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 [[ChunkyPNG::Point.new(2, 5), ChunkyPNG::Point.new(1, 3)],
75
- [ChunkyPNG::Point.new(1, 3), ChunkyPNG::Point.new(4, 6)],
76
- [ChunkyPNG::Point.new(4, 6), ChunkyPNG::Point.new(2, 5)]]
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 [[ChunkyPNG::Point.new(2, 5), ChunkyPNG::Point.new(1, 3)],
81
- [ChunkyPNG::Point.new(1, 3), ChunkyPNG::Point.new(4, 6)]]
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 'ChunkyPNG.Vector' do
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('(2,4) (1,2) (3,6)')).to eql example
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('(2,4)', [1, 2], :x => 3, :y => 6)).to eql example
111
+ expect(ChunkyPNG::Vector("(2,4)", [1, 2], x: 3, y: 6)).to eql example
108
112
  end
109
113
  end
@@ -1,7 +1,7 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe ChunkyPNG do
4
4
  it "should have a VERSION constant" do
5
- expect(ChunkyPNG.const_defined?('VERSION')).to eql true
5
+ expect(ChunkyPNG.const_defined?("VERSION")).to be_truthy
6
6
  end
7
7
  end
@@ -1,8 +1,7 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
- describe 'PNG testuite' do
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 'Decoding supported images' do
14
- png_suite_files(:basic, '*.png').each do |file|
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
- File.open(reference, 'rb') { |f| expect(decoded.to_rgba_stream).to eql f.read }
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 'Decoding text chunks' do
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, 'cm0n0g04.png'))
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 'Decoding filter methods' do
46
- png_suite_files(:filtering, '*_reference.png').each do |reference_file|
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 'Decoding different chunk splits' do
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, 'oi1n0g16.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
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, 'oi1n2c16.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
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 'Decoding different compression levels' do
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, 'z00n2c08.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
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 'Decoding transparency' do
85
- png_suite_files(:transparency, 'tp0*.png').each do |file|
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, 'tp1*.png').each do |file|
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, 'tb*.png').each do |file|
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 'Decoding different sizes' do
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 'rubygems'
2
- require 'bundler/setup'
3
- require 'chunky_png'
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 = '*.png')
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), 'rb') { |f| data = f.read }
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('_tmp.png')
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]
@@ -1,24 +1,23 @@
1
1
  all_benchamrk_tasks = []
2
2
 
3
3
  namespace(:benchmark) do
4
-
5
- Dir[File.join(File.dirname(__FILE__), '..', 'benchmarks', '*_benchmark.rb')]. each do |benchmark_file|
6
- task_name = File.basename(benchmark_file, '_benchmark.rb').to_sym
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['N'] = args[:n] if args[:n]
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 'Run the whole benchmark suite'
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