chunky_png 1.3.8 → 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 +16 -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 +142 -69
- data/lib/chunky_png/color.rb +218 -212
- data/lib/chunky_png/datastream.rb +24 -30
- 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 +46 -45
- 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 +98 -19
- 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,59 +1,79 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe ChunkyPNG::Canvas do
|
4
|
-
|
5
|
-
describe '#to_rgba_stream' do
|
4
|
+
describe "#to_rgba_stream" do
|
6
5
|
it "should export a sample canvas to an RGBA stream correctly" do
|
7
|
-
canvas = ChunkyPNG::Canvas.new(2, 2, [
|
8
|
-
|
6
|
+
canvas = ChunkyPNG::Canvas.new(2, 2, [
|
7
|
+
ChunkyPNG::Color.rgba(1, 2, 3, 4),
|
8
|
+
ChunkyPNG::Color.rgba(5, 6, 7, 8),
|
9
|
+
ChunkyPNG::Color.rgba(4, 3, 2, 1),
|
10
|
+
ChunkyPNG::Color.rgba(8, 7, 6, 5),
|
11
|
+
])
|
9
12
|
|
10
|
-
expect(canvas.to_rgba_stream).to eql
|
13
|
+
expect(canvas.to_rgba_stream).to eql [1, 2, 3, 4, 5, 6, 7, 8, 4, 3, 2, 1, 8, 7, 6, 5].pack("C16")
|
11
14
|
end
|
12
15
|
|
13
16
|
it "should export an image to an RGBA datastream correctly" do
|
14
|
-
expect(reference_canvas(
|
17
|
+
expect(reference_canvas("pixelstream_reference").to_rgba_stream).to eql resource_data("pixelstream.rgba")
|
15
18
|
end
|
16
19
|
end
|
17
20
|
|
18
|
-
describe
|
21
|
+
describe "#to_rgb_stream" do
|
19
22
|
it "should export a sample canvas to an RGBA stream correctly" do
|
20
|
-
canvas = ChunkyPNG::Canvas.new(2, 2, [
|
21
|
-
|
23
|
+
canvas = ChunkyPNG::Canvas.new(2, 2, [
|
24
|
+
ChunkyPNG::Color.rgba(1, 2, 3, 4),
|
25
|
+
ChunkyPNG::Color.rgba(5, 6, 7, 8),
|
26
|
+
ChunkyPNG::Color.rgba(4, 3, 2, 1),
|
27
|
+
ChunkyPNG::Color.rgba(8, 7, 6, 5),
|
28
|
+
])
|
22
29
|
|
23
|
-
expect(canvas.to_rgb_stream).to eql [1,2,3,5,6,7,4,3,2,8,7,6].pack(
|
30
|
+
expect(canvas.to_rgb_stream).to eql [1, 2, 3, 5, 6, 7, 4, 3, 2, 8, 7, 6].pack("C12")
|
24
31
|
end
|
25
32
|
|
26
33
|
it "should export an image to an RGB datastream correctly" do
|
27
|
-
expect(reference_canvas(
|
34
|
+
expect(reference_canvas("pixelstream_reference").to_rgb_stream).to eql resource_data("pixelstream.rgb")
|
28
35
|
end
|
29
36
|
end
|
30
37
|
|
31
|
-
describe
|
32
|
-
|
38
|
+
describe "#to_grayscale_stream" do
|
33
39
|
it "should export a grayscale image to a grayscale datastream correctly" do
|
34
|
-
canvas = ChunkyPNG::Canvas.new(2, 2, [
|
35
|
-
|
36
|
-
|
37
|
-
|
40
|
+
canvas = ChunkyPNG::Canvas.new(2, 2, [
|
41
|
+
ChunkyPNG::Color.grayscale(1),
|
42
|
+
ChunkyPNG::Color.grayscale(2),
|
43
|
+
ChunkyPNG::Color.grayscale(3),
|
44
|
+
ChunkyPNG::Color.grayscale(4),
|
45
|
+
])
|
38
46
|
|
47
|
+
expect(canvas.to_grayscale_stream).to eql [1, 2, 3, 4].pack("C4")
|
48
|
+
end
|
39
49
|
|
40
50
|
it "should export a color image to a grayscale datastream, using B values" do
|
41
|
-
canvas = ChunkyPNG::Canvas.new(2, 2, [
|
42
|
-
|
43
|
-
|
51
|
+
canvas = ChunkyPNG::Canvas.new(2, 2, [
|
52
|
+
ChunkyPNG::Color.rgba(1, 2, 3, 4),
|
53
|
+
ChunkyPNG::Color.rgba(5, 6, 7, 8),
|
54
|
+
ChunkyPNG::Color.rgba(4, 3, 2, 1),
|
55
|
+
ChunkyPNG::Color.rgba(8, 7, 6, 5),
|
56
|
+
])
|
57
|
+
|
58
|
+
expect(canvas.to_grayscale_stream).to eql [3, 7, 2, 6].pack("C4")
|
44
59
|
end
|
45
60
|
end
|
46
61
|
|
47
|
-
describe
|
62
|
+
describe "#to_alpha_channel_stream" do
|
48
63
|
it "should export an opaque image to an alpha channel datastream correctly" do
|
49
|
-
grayscale_array = Array.new(reference_canvas(
|
50
|
-
expect(reference_canvas(
|
64
|
+
grayscale_array = Array.new(reference_canvas("pixelstream_reference").pixels.length, 255)
|
65
|
+
expect(reference_canvas("pixelstream_reference").to_alpha_channel_stream).to eql grayscale_array.pack("C*")
|
51
66
|
end
|
52
67
|
|
53
68
|
it "should export a transparent image to an alpha channel datastream correctly" do
|
54
|
-
canvas = ChunkyPNG::Canvas.new(2, 2, [
|
55
|
-
|
56
|
-
|
69
|
+
canvas = ChunkyPNG::Canvas.new(2, 2, [
|
70
|
+
ChunkyPNG::Color.rgba(1, 2, 3, 4),
|
71
|
+
ChunkyPNG::Color.rgba(5, 6, 7, 8),
|
72
|
+
ChunkyPNG::Color.rgba(4, 3, 2, 1),
|
73
|
+
ChunkyPNG::Color.rgba(8, 7, 6, 5),
|
74
|
+
])
|
75
|
+
|
76
|
+
expect(canvas.to_alpha_channel_stream).to eql [4, 8, 1, 5].pack("C4")
|
57
77
|
end
|
58
78
|
end
|
59
79
|
end
|
@@ -1,30 +1,29 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe ChunkyPNG::Canvas do
|
4
|
-
|
5
|
-
describe '.from_rgb_stream' do
|
4
|
+
describe ".from_rgb_stream" do
|
6
5
|
it "should load an image correctly from a datastream" do
|
7
|
-
File.open(resource_file(
|
6
|
+
File.open(resource_file("pixelstream.rgb")) do |stream|
|
8
7
|
matrix = ChunkyPNG::Canvas.from_rgb_stream(240, 180, stream)
|
9
|
-
expect(matrix).to eql reference_canvas(
|
8
|
+
expect(matrix).to eql reference_canvas("pixelstream_reference")
|
10
9
|
end
|
11
10
|
end
|
12
11
|
end
|
13
12
|
|
14
|
-
describe
|
13
|
+
describe ".from_bgr_stream" do
|
15
14
|
it "should load an image correctly from a datastream" do
|
16
|
-
File.open(resource_file(
|
15
|
+
File.open(resource_file("pixelstream.bgr")) do |stream|
|
17
16
|
matrix = ChunkyPNG::Canvas.from_bgr_stream(240, 180, stream)
|
18
|
-
expect(matrix).to eql reference_canvas(
|
17
|
+
expect(matrix).to eql reference_canvas("pixelstream_reference")
|
19
18
|
end
|
20
19
|
end
|
21
20
|
end
|
22
21
|
|
23
|
-
describe
|
22
|
+
describe ".from_rgba_stream" do
|
24
23
|
it "should load an image correctly from a datastream" do
|
25
|
-
File.open(resource_file(
|
24
|
+
File.open(resource_file("pixelstream.rgba")) do |stream|
|
26
25
|
matrix = ChunkyPNG::Canvas.from_rgba_stream(240, 180, stream)
|
27
|
-
expect(matrix).to eql reference_canvas(
|
26
|
+
expect(matrix).to eql reference_canvas("pixelstream_reference")
|
28
27
|
end
|
29
28
|
end
|
30
29
|
end
|
@@ -1,17 +1,16 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe ChunkyPNG::Canvas do
|
4
|
-
|
5
4
|
subject { ChunkyPNG::Canvas.new(1, 1, ChunkyPNG::Color::WHITE) }
|
6
5
|
|
7
6
|
it { should respond_to(:width) }
|
8
7
|
it { should respond_to(:height) }
|
9
8
|
it { should respond_to(:pixels) }
|
10
9
|
|
11
|
-
describe
|
10
|
+
describe "#initialize" do
|
12
11
|
it "should accept a single color value as background color" do
|
13
|
-
canvas = ChunkyPNG::Canvas.new(2, 2,
|
14
|
-
expect(canvas[1, 0]).to eql ChunkyPNG::Color.parse(
|
12
|
+
canvas = ChunkyPNG::Canvas.new(2, 2, "red @ 0.8")
|
13
|
+
expect(canvas[1, 0]).to eql ChunkyPNG::Color.parse("red @ 0.8")
|
15
14
|
end
|
16
15
|
|
17
16
|
it "should raise an error if the color value is not understood" do
|
@@ -19,7 +18,7 @@ describe ChunkyPNG::Canvas do
|
|
19
18
|
end
|
20
19
|
|
21
20
|
it "should accept an array as initial pixel values" do
|
22
|
-
canvas = ChunkyPNG::Canvas.new(2, 2, [1,2,3,4])
|
21
|
+
canvas = ChunkyPNG::Canvas.new(2, 2, [1, 2, 3, 4])
|
23
22
|
expect(canvas[0, 0]).to eql 1
|
24
23
|
expect(canvas[1, 0]).to eql 2
|
25
24
|
expect(canvas[0, 1]).to eql 3
|
@@ -27,32 +26,32 @@ describe ChunkyPNG::Canvas do
|
|
27
26
|
end
|
28
27
|
|
29
28
|
it "should raise an ArgumentError if the initial array does not have the correct number of elements" do
|
30
|
-
expect { ChunkyPNG::Canvas.new(2, 2, [1,2,3]) }.to raise_error(ArgumentError)
|
31
|
-
expect { ChunkyPNG::Canvas.new(2, 2, [1,2,3,4,5]) }.to raise_error(ArgumentError)
|
29
|
+
expect { ChunkyPNG::Canvas.new(2, 2, [1, 2, 3]) }.to raise_error(ArgumentError)
|
30
|
+
expect { ChunkyPNG::Canvas.new(2, 2, [1, 2, 3, 4, 5]) }.to raise_error(ArgumentError)
|
32
31
|
end
|
33
32
|
|
34
33
|
it "should use a transparent background by default" do
|
35
34
|
canvas = ChunkyPNG::Canvas.new(1, 1)
|
36
|
-
expect(canvas[0,0]).to eql ChunkyPNG::Color::TRANSPARENT
|
35
|
+
expect(canvas[0, 0]).to eql ChunkyPNG::Color::TRANSPARENT
|
37
36
|
end
|
38
37
|
end
|
39
38
|
|
40
|
-
describe
|
39
|
+
describe "#dimension" do
|
41
40
|
it "should return the dimensions as a Dimension instance" do
|
42
|
-
expect(subject.dimension).to eql ChunkyPNG::Dimension(
|
41
|
+
expect(subject.dimension).to eql ChunkyPNG::Dimension("1x1")
|
43
42
|
end
|
44
43
|
end
|
45
44
|
|
46
|
-
describe
|
45
|
+
describe "#area" do
|
47
46
|
it "should return the dimensions as two-item array" do
|
48
|
-
expect(subject.area).to eql ChunkyPNG::Dimension(
|
47
|
+
expect(subject.area).to eql ChunkyPNG::Dimension("1x1").area
|
49
48
|
end
|
50
49
|
end
|
51
50
|
|
52
|
-
describe
|
51
|
+
describe "#include?" do
|
53
52
|
it "should return true if the coordinates are within bounds, false otherwise" do
|
53
|
+
# rubocop:disable Layout/SpaceInsideParens
|
54
54
|
expect(subject.include_xy?( 0, 0)).to eql true
|
55
|
-
|
56
55
|
expect(subject.include_xy?(-1, 0)).to eql false
|
57
56
|
expect(subject.include_xy?( 1, 0)).to eql false
|
58
57
|
expect(subject.include_xy?( 0, -1)).to eql false
|
@@ -61,37 +60,38 @@ describe ChunkyPNG::Canvas do
|
|
61
60
|
expect(subject.include_xy?(-1, 1)).to eql false
|
62
61
|
expect(subject.include_xy?( 1, -1)).to eql false
|
63
62
|
expect(subject.include_xy?( 1, 1)).to eql false
|
63
|
+
# rubocop:enable Layout/SpaceInsideParens
|
64
64
|
end
|
65
65
|
|
66
66
|
it "should accept strings, arrays, hashes and points as well" do
|
67
|
-
expect(subject).to
|
68
|
-
subject.
|
69
|
-
expect(subject).to
|
70
|
-
subject.
|
71
|
-
expect(subject).to
|
72
|
-
subject.
|
73
|
-
expect(subject).to
|
74
|
-
subject.
|
67
|
+
expect(subject).to include("0, 0")
|
68
|
+
expect(subject).to_not include("0, 1")
|
69
|
+
expect(subject).to include([0, 0])
|
70
|
+
expect(subject).to_not include([0, 1])
|
71
|
+
expect(subject).to include(y: 0, x: 0)
|
72
|
+
expect(subject).to_not include(y: 1, x: 0)
|
73
|
+
expect(subject).to include(ChunkyPNG::Point.new(0, 0))
|
74
|
+
expect(subject).to_not include(ChunkyPNG::Point.new(0, 1))
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
|
-
describe
|
78
|
+
describe "#include_x?" do
|
79
79
|
it "should return true if the x-coordinate is within bounds, false otherwise" do
|
80
|
-
expect(subject.include_x?(
|
80
|
+
expect(subject.include_x?(0)).to eql true
|
81
81
|
expect(subject.include_x?(-1)).to eql false
|
82
|
-
expect(subject.include_x?(
|
82
|
+
expect(subject.include_x?(1)).to eql false
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
-
describe
|
86
|
+
describe "#include_y?" do
|
87
87
|
it "should return true if the y-coordinate is within bounds, false otherwise" do
|
88
|
-
expect(subject.include_y?(
|
88
|
+
expect(subject.include_y?(0)).to eql true
|
89
89
|
expect(subject.include_y?(-1)).to eql false
|
90
|
-
expect(subject.include_y?(
|
90
|
+
expect(subject.include_y?(1)).to eql false
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
94
|
-
describe
|
94
|
+
describe "#assert_xy!" do
|
95
95
|
it "should not raise an exception if the coordinates are within bounds" do
|
96
96
|
expect(subject).to receive(:include_xy?).with(0, 0).and_return(true)
|
97
97
|
expect { subject.send(:assert_xy!, 0, 0) }.to_not raise_error
|
@@ -103,7 +103,7 @@ describe ChunkyPNG::Canvas do
|
|
103
103
|
end
|
104
104
|
end
|
105
105
|
|
106
|
-
describe
|
106
|
+
describe "#assert_x!" do
|
107
107
|
it "should not raise an exception if the x-coordinate is within bounds" do
|
108
108
|
expect(subject).to receive(:include_x?).with(0).and_return(true)
|
109
109
|
expect { subject.send(:assert_x!, 0) }.to_not raise_error
|
@@ -115,7 +115,7 @@ describe ChunkyPNG::Canvas do
|
|
115
115
|
end
|
116
116
|
end
|
117
117
|
|
118
|
-
describe
|
118
|
+
describe "#[]" do
|
119
119
|
it "should return the pixel value if the coordinates are within bounds" do
|
120
120
|
expect(subject[0, 0]).to eql ChunkyPNG::Color::WHITE
|
121
121
|
end
|
@@ -126,7 +126,7 @@ describe ChunkyPNG::Canvas do
|
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
129
|
-
describe
|
129
|
+
describe "#get_pixel" do
|
130
130
|
it "should return the pixel value if the coordinates are within bounds" do
|
131
131
|
expect(subject.get_pixel(0, 0)).to eql ChunkyPNG::Color::WHITE
|
132
132
|
end
|
@@ -138,10 +138,11 @@ describe ChunkyPNG::Canvas do
|
|
138
138
|
end
|
139
139
|
end
|
140
140
|
|
141
|
-
describe
|
141
|
+
describe "#[]=" do
|
142
142
|
it "should change the pixel's color value" do
|
143
|
-
expect { subject[0, 0] = ChunkyPNG::Color::BLACK }.to change { subject[0, 0] }
|
144
|
-
from(ChunkyPNG::Color::WHITE)
|
143
|
+
expect { subject[0, 0] = ChunkyPNG::Color::BLACK }.to change { subject[0, 0] }
|
144
|
+
.from(ChunkyPNG::Color::WHITE)
|
145
|
+
.to(ChunkyPNG::Color::BLACK)
|
145
146
|
end
|
146
147
|
|
147
148
|
it "should assert the bounds of the image" do
|
@@ -150,10 +151,11 @@ describe ChunkyPNG::Canvas do
|
|
150
151
|
end
|
151
152
|
end
|
152
153
|
|
153
|
-
describe
|
154
|
+
describe "set_pixel" do
|
154
155
|
it "should change the pixel's color value" do
|
155
|
-
expect { subject.set_pixel(0, 0, ChunkyPNG::Color::BLACK) }.to change { subject[0, 0] }
|
156
|
-
|
156
|
+
expect { subject.set_pixel(0, 0, ChunkyPNG::Color::BLACK) }.to change { subject[0, 0] }
|
157
|
+
.from(ChunkyPNG::Color::WHITE)
|
158
|
+
.to(ChunkyPNG::Color::BLACK)
|
157
159
|
end
|
158
160
|
|
159
161
|
it "should not assert or check the bounds of the image" do
|
@@ -163,10 +165,11 @@ describe ChunkyPNG::Canvas do
|
|
163
165
|
end
|
164
166
|
end
|
165
167
|
|
166
|
-
describe
|
168
|
+
describe "#set_pixel_if_within_bounds" do
|
167
169
|
it "should change the pixel's color value" do
|
168
|
-
expect { subject.set_pixel_if_within_bounds(0, 0, ChunkyPNG::Color::BLACK) }.to change { subject[0, 0] }
|
169
|
-
|
170
|
+
expect { subject.set_pixel_if_within_bounds(0, 0, ChunkyPNG::Color::BLACK) }.to change { subject[0, 0] }
|
171
|
+
.from(ChunkyPNG::Color::WHITE)
|
172
|
+
.to(ChunkyPNG::Color::BLACK)
|
170
173
|
end
|
171
174
|
|
172
175
|
it "should not assert, but only check the coordinates" do
|
@@ -181,8 +184,8 @@ describe ChunkyPNG::Canvas do
|
|
181
184
|
end
|
182
185
|
end
|
183
186
|
|
184
|
-
describe
|
185
|
-
before { @canvas = reference_canvas(
|
187
|
+
describe "#row" do
|
188
|
+
before { @canvas = reference_canvas("operations") }
|
186
189
|
|
187
190
|
it "should give an out of bounds exception when y-coordinate is out of bounds" do
|
188
191
|
expect { @canvas.row(-1) }.to raise_error(ChunkyPNG::OutOfBounds)
|
@@ -196,8 +199,8 @@ describe ChunkyPNG::Canvas do
|
|
196
199
|
end
|
197
200
|
end
|
198
201
|
|
199
|
-
describe
|
200
|
-
before { @canvas = reference_canvas(
|
202
|
+
describe "#column" do
|
203
|
+
before { @canvas = reference_canvas("operations") }
|
201
204
|
|
202
205
|
it "should give an out of bounds exception when x-coordinate is out of bounds" do
|
203
206
|
expect { @canvas.column(-1) }.to raise_error(ChunkyPNG::OutOfBounds)
|
@@ -211,19 +214,27 @@ describe ChunkyPNG::Canvas do
|
|
211
214
|
end
|
212
215
|
end
|
213
216
|
|
214
|
-
describe
|
217
|
+
describe "#replace_canvas" do
|
215
218
|
it "should change the dimension of the canvas" do
|
216
|
-
expect { subject.send(:replace_canvas!, 2, 2, [1,2,3,4]) }.to change { subject.dimension }
|
217
|
-
|
219
|
+
expect { subject.send(:replace_canvas!, 2, 2, [1, 2, 3, 4]) }.to change { subject.dimension }
|
220
|
+
.from(ChunkyPNG::Dimension("1x1"))
|
221
|
+
.to(ChunkyPNG::Dimension("2x2"))
|
218
222
|
end
|
219
223
|
|
220
224
|
it "should change the pixel array" do
|
221
|
-
expect { subject.send(:replace_canvas!, 2, 2, [1,2,3,4]) }.to change { subject.pixels }
|
222
|
-
|
225
|
+
expect { subject.send(:replace_canvas!, 2, 2, [1, 2, 3, 4]) }.to change { subject.pixels }
|
226
|
+
.from([ChunkyPNG::Color("white")])
|
227
|
+
.to([1, 2, 3, 4])
|
223
228
|
end
|
224
229
|
|
225
230
|
it "should return itself" do
|
226
|
-
expect(subject.send(:replace_canvas!, 2, 2, [1,2,3,4])).to equal(subject)
|
231
|
+
expect(subject.send(:replace_canvas!, 2, 2, [1, 2, 3, 4])).to equal(subject)
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
describe "#inspect" do
|
236
|
+
it "should give a string description of the canvas" do
|
237
|
+
expect(subject.inspect).to eql "<ChunkyPNG::Canvas 1x1 [\n\t[#ffffffff]\n]>"
|
227
238
|
end
|
228
239
|
end
|
229
240
|
end
|