chunky_png 1.3.11 → 1.3.12
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 +5 -5
- data/.standard.yml +16 -0
- data/.travis.yml +5 -5
- data/.yardopts +1 -1
- data/CHANGELOG.rdoc +5 -1
- data/CONTRIBUTING.rdoc +17 -8
- data/Gemfile +3 -3
- data/LICENSE +1 -1
- data/README.md +6 -1
- data/Rakefile +3 -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 +15 -15
- data/lib/chunky_png.rb +16 -25
- data/lib/chunky_png/canvas.rb +28 -27
- data/lib/chunky_png/canvas/adam7_interlacing.rb +14 -10
- data/lib/chunky_png/canvas/data_url_exporting.rb +1 -3
- data/lib/chunky_png/canvas/data_url_importing.rb +1 -3
- data/lib/chunky_png/canvas/drawing.rb +28 -43
- data/lib/chunky_png/canvas/masking.rb +12 -14
- data/lib/chunky_png/canvas/operations.rb +26 -24
- data/lib/chunky_png/canvas/png_decoding.rb +36 -32
- data/lib/chunky_png/canvas/png_encoding.rb +106 -100
- data/lib/chunky_png/canvas/resampling.rb +26 -33
- data/lib/chunky_png/canvas/stream_exporting.rb +6 -8
- data/lib/chunky_png/canvas/stream_importing.rb +6 -8
- data/lib/chunky_png/chunk.rb +69 -60
- data/lib/chunky_png/color.rb +211 -206
- data/lib/chunky_png/datastream.rb +20 -22
- data/lib/chunky_png/dimension.rb +16 -11
- data/lib/chunky_png/image.rb +9 -11
- data/lib/chunky_png/palette.rb +4 -9
- data/lib/chunky_png/point.rb +25 -26
- data/lib/chunky_png/rmagick.rb +8 -10
- data/lib/chunky_png/vector.rb +26 -29
- data/lib/chunky_png/version.rb +1 -1
- 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 +57 -52
- data/spec/chunky_png/color_spec.rb +115 -114
- data/spec/chunky_png/datastream_spec.rb +49 -51
- 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/spec_helper.rb +6 -10
- data/tasks/benchmarks.rake +7 -8
- metadata +34 -5
- data/lib/chunky_png/compatibility.rb +0 -15
@@ -1,41 +1,40 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe ChunkyPNG::Canvas::Masking do
|
4
|
-
|
5
|
-
subject { reference_canvas('clock') }
|
4
|
+
subject { reference_canvas("clock") }
|
6
5
|
|
7
6
|
before(:all) do
|
8
|
-
@theme_color = ChunkyPNG::Color(
|
9
|
-
@new_color = ChunkyPNG::Color(
|
10
|
-
@background_color = ChunkyPNG::Color(
|
7
|
+
@theme_color = ChunkyPNG::Color("#e10f7a")
|
8
|
+
@new_color = ChunkyPNG::Color("#ff0000")
|
9
|
+
@background_color = ChunkyPNG::Color("white")
|
11
10
|
end
|
12
11
|
|
13
|
-
describe
|
12
|
+
describe "#change_theme_color!" do
|
14
13
|
it "should change the theme color correctly" do
|
15
14
|
subject.change_theme_color!(@theme_color, @new_color)
|
16
|
-
expect(subject).to eql reference_canvas(
|
15
|
+
expect(subject).to eql reference_canvas("clock_updated")
|
17
16
|
end
|
18
17
|
end
|
19
18
|
|
20
|
-
describe
|
19
|
+
describe "#extract_mask" do
|
21
20
|
it "should create the correct base and mask image" do
|
22
21
|
base, mask = subject.extract_mask(@theme_color, @background_color)
|
23
|
-
expect(base).to eql reference_canvas(
|
24
|
-
expect(mask).to eql reference_canvas(
|
22
|
+
expect(base).to eql reference_canvas("clock_base")
|
23
|
+
expect(mask).to eql reference_canvas("clock_mask")
|
25
24
|
end
|
26
25
|
|
27
26
|
it "should create a mask image with only one opaque color" do
|
28
|
-
|
27
|
+
_, mask = subject.extract_mask(@theme_color, @background_color)
|
29
28
|
expect(mask.palette.opaque_palette.size).to eql 1
|
30
29
|
end
|
31
30
|
end
|
32
31
|
|
33
|
-
describe
|
34
|
-
before { @mask = reference_canvas(
|
32
|
+
describe "#change_mask_color!" do
|
33
|
+
before { @mask = reference_canvas("clock_mask") }
|
35
34
|
|
36
35
|
it "should replace the mask color correctly" do
|
37
36
|
@mask.change_mask_color!(@new_color)
|
38
|
-
expect(@mask).to eql reference_canvas(
|
37
|
+
expect(@mask).to eql reference_canvas("clock_mask_updated")
|
39
38
|
end
|
40
39
|
|
41
40
|
it "should still only have one opaque color" do
|
@@ -44,7 +43,7 @@ describe ChunkyPNG::Canvas::Masking do
|
|
44
43
|
end
|
45
44
|
|
46
45
|
it "should raise an exception when the mask image has more than once color" do
|
47
|
-
not_a_mask = reference_canvas(
|
46
|
+
not_a_mask = reference_canvas("operations")
|
48
47
|
expect { not_a_mask.change_mask_color!(@new_color) }.to raise_error(ChunkyPNG::ExpectationFailed)
|
49
48
|
end
|
50
49
|
end
|
@@ -1,16 +1,15 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe ChunkyPNG::Canvas::Operations do
|
4
|
+
subject { reference_canvas("operations") }
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
describe '#grayscale' do
|
6
|
+
describe "#grayscale" do
|
8
7
|
it "should not return itself" do
|
9
8
|
subject.grayscale.should_not equal(subject)
|
10
9
|
end
|
11
10
|
|
12
11
|
it "should convert the image correctly" do
|
13
|
-
expect(subject.grayscale).to eql reference_canvas(
|
12
|
+
expect(subject.grayscale).to eql reference_canvas("operations_grayscale")
|
14
13
|
end
|
15
14
|
|
16
15
|
it "should not adjust the current image" do
|
@@ -18,20 +17,20 @@ describe ChunkyPNG::Canvas::Operations do
|
|
18
17
|
end
|
19
18
|
end
|
20
19
|
|
21
|
-
describe
|
20
|
+
describe "#grayscale!" do
|
22
21
|
it "should return itself" do
|
23
22
|
expect(subject.grayscale!).to equal(subject)
|
24
23
|
end
|
25
24
|
|
26
25
|
it "should convert the image correctly" do
|
27
26
|
subject.grayscale!
|
28
|
-
expect(subject).to eql reference_canvas(
|
27
|
+
expect(subject).to eql reference_canvas("operations_grayscale")
|
29
28
|
end
|
30
29
|
end
|
31
30
|
|
32
|
-
describe
|
31
|
+
describe "#crop" do
|
33
32
|
it "should crop the right pixels from the original canvas" do
|
34
|
-
expect(subject.crop(10, 5, 4, 8)).to eql reference_canvas(
|
33
|
+
expect(subject.crop(10, 5, 4, 8)).to eql reference_canvas("cropped")
|
35
34
|
end
|
36
35
|
|
37
36
|
it "should not return itself" do
|
@@ -47,18 +46,19 @@ describe ChunkyPNG::Canvas::Operations do
|
|
47
46
|
end
|
48
47
|
end
|
49
48
|
|
50
|
-
describe
|
51
|
-
context
|
49
|
+
describe "#crop!" do
|
50
|
+
context "when cropping both width and height" do
|
52
51
|
let(:crop_opts) { [10, 5, 4, 8] }
|
53
52
|
|
54
53
|
it "should crop the right pixels from the original canvas" do
|
55
54
|
subject.crop!(*crop_opts)
|
56
|
-
expect(subject).to eql reference_canvas(
|
55
|
+
expect(subject).to eql reference_canvas("cropped")
|
57
56
|
end
|
58
57
|
|
59
58
|
it "should have a new width and height" do
|
60
|
-
expect { subject.crop!(*crop_opts) }.to change { subject.dimension }
|
61
|
-
|
59
|
+
expect { subject.crop!(*crop_opts) }.to change { subject.dimension }
|
60
|
+
.from(ChunkyPNG::Dimension("16x16"))
|
61
|
+
.to(ChunkyPNG::Dimension("4x8"))
|
62
62
|
end
|
63
63
|
|
64
64
|
it "should return itself" do
|
@@ -71,12 +71,13 @@ describe ChunkyPNG::Canvas::Operations do
|
|
71
71
|
|
72
72
|
it "should crop the right pixels from the original canvas" do
|
73
73
|
subject.crop!(*crop_opts)
|
74
|
-
expect(subject).to eql reference_canvas(
|
74
|
+
expect(subject).to eql reference_canvas("cropped_height")
|
75
75
|
end
|
76
76
|
|
77
77
|
it "should have a new width and height" do
|
78
|
-
expect { subject.crop!(*crop_opts) }.to change { subject.dimension }
|
79
|
-
|
78
|
+
expect { subject.crop!(*crop_opts) }.to change { subject.dimension }
|
79
|
+
.from(ChunkyPNG::Dimension("16x16"))
|
80
|
+
.to(ChunkyPNG::Dimension("16x8"))
|
80
81
|
end
|
81
82
|
|
82
83
|
it "should return itself" do
|
@@ -91,91 +92,90 @@ describe ChunkyPNG::Canvas::Operations do
|
|
91
92
|
end
|
92
93
|
end
|
93
94
|
|
94
|
-
describe
|
95
|
+
describe "#compose" do
|
95
96
|
it "should compose pixels correctly" do
|
96
97
|
subcanvas = ChunkyPNG::Canvas.new(4, 8, ChunkyPNG::Color.rgba(0, 0, 0, 75))
|
97
|
-
expect(subject.compose(subcanvas, 8, 4)).to eql reference_canvas(
|
98
|
+
expect(subject.compose(subcanvas, 8, 4)).to eql reference_canvas("composited")
|
98
99
|
end
|
99
100
|
|
100
101
|
it "should leave the original intact" do
|
101
|
-
subject.compose(ChunkyPNG::Canvas.new(1,1))
|
102
|
-
expect(subject).to eql reference_canvas(
|
102
|
+
subject.compose(ChunkyPNG::Canvas.new(1, 1))
|
103
|
+
expect(subject).to eql reference_canvas("operations")
|
103
104
|
end
|
104
105
|
|
105
106
|
it "should not return itself" do
|
106
|
-
subject.compose(ChunkyPNG::Canvas.new(1,1)).should_not equal(subject)
|
107
|
+
subject.compose(ChunkyPNG::Canvas.new(1, 1)).should_not equal(subject)
|
107
108
|
end
|
108
109
|
|
109
110
|
it "should raise an exception when the pixels to compose fall outside the image" do
|
110
|
-
expect { subject.compose(ChunkyPNG::Canvas.new(1,1), 16, 16) }.to raise_error(ChunkyPNG::OutOfBounds)
|
111
|
+
expect { subject.compose(ChunkyPNG::Canvas.new(1, 1), 16, 16) }.to raise_error(ChunkyPNG::OutOfBounds)
|
111
112
|
end
|
112
113
|
end
|
113
114
|
|
114
|
-
describe
|
115
|
+
describe "#compose!" do
|
115
116
|
it "should compose pixels correctly" do
|
116
117
|
subcanvas = ChunkyPNG::Canvas.new(4, 8, ChunkyPNG::Color.rgba(0, 0, 0, 75))
|
117
118
|
subject.compose!(subcanvas, 8, 4)
|
118
|
-
expect(subject).to eql reference_canvas(
|
119
|
+
expect(subject).to eql reference_canvas("composited")
|
119
120
|
end
|
120
121
|
|
121
122
|
it "should return itself" do
|
122
|
-
expect(subject.compose!(ChunkyPNG::Canvas.new(1,1))).to equal(subject)
|
123
|
+
expect(subject.compose!(ChunkyPNG::Canvas.new(1, 1))).to equal(subject)
|
123
124
|
end
|
124
125
|
|
125
126
|
it "should compose a base image and mask correctly" do
|
126
|
-
base = reference_canvas(
|
127
|
-
mask = reference_canvas(
|
127
|
+
base = reference_canvas("clock_base")
|
128
|
+
mask = reference_canvas("clock_mask_updated")
|
128
129
|
base.compose!(mask)
|
129
|
-
expect(base).to eql reference_canvas(
|
130
|
+
expect(base).to eql reference_canvas("clock_updated")
|
130
131
|
end
|
131
132
|
|
132
133
|
it "should raise an exception when the pixels to compose fall outside the image" do
|
133
|
-
expect { subject.compose!(ChunkyPNG::Canvas.new(1,1), 16, 16) }.to raise_error(ChunkyPNG::OutOfBounds)
|
134
|
+
expect { subject.compose!(ChunkyPNG::Canvas.new(1, 1), 16, 16) }.to raise_error(ChunkyPNG::OutOfBounds)
|
134
135
|
end
|
135
136
|
end
|
136
137
|
|
137
|
-
describe
|
138
|
+
describe "#replace" do
|
138
139
|
it "should replace the correct pixels" do
|
139
140
|
subcanvas = ChunkyPNG::Canvas.new(3, 2, ChunkyPNG::Color.rgb(200, 255, 0))
|
140
|
-
expect(subject.replace(subcanvas, 5, 4)).to eql reference_canvas(
|
141
|
+
expect(subject.replace(subcanvas, 5, 4)).to eql reference_canvas("replaced")
|
141
142
|
end
|
142
143
|
|
143
144
|
it "should not return itself" do
|
144
|
-
subject.replace(ChunkyPNG::Canvas.new(1,1)).should_not equal(subject)
|
145
|
+
subject.replace(ChunkyPNG::Canvas.new(1, 1)).should_not equal(subject)
|
145
146
|
end
|
146
147
|
|
147
148
|
it "should leave the original intact" do
|
148
|
-
subject.replace(ChunkyPNG::Canvas.new(1,1))
|
149
|
-
expect(subject).to eql reference_canvas(
|
149
|
+
subject.replace(ChunkyPNG::Canvas.new(1, 1))
|
150
|
+
expect(subject).to eql reference_canvas("operations")
|
150
151
|
end
|
151
152
|
|
152
153
|
it "should raise an exception when the pixels to replace fall outside the image" do
|
153
|
-
expect { subject.replace(ChunkyPNG::Canvas.new(1,1), 16, 16) }.to raise_error(ChunkyPNG::OutOfBounds)
|
154
|
+
expect { subject.replace(ChunkyPNG::Canvas.new(1, 1), 16, 16) }.to raise_error(ChunkyPNG::OutOfBounds)
|
154
155
|
end
|
155
156
|
end
|
156
157
|
|
157
|
-
describe
|
158
|
+
describe "#replace!" do
|
158
159
|
it "should replace the correct pixels" do
|
159
160
|
subcanvas = ChunkyPNG::Canvas.new(3, 2, ChunkyPNG::Color.rgb(200, 255, 0))
|
160
161
|
subject.replace!(subcanvas, 5, 4)
|
161
|
-
expect(subject).to eql reference_canvas(
|
162
|
+
expect(subject).to eql reference_canvas("replaced")
|
162
163
|
end
|
163
164
|
|
164
165
|
it "should return itself" do
|
165
|
-
expect(subject.replace!(ChunkyPNG::Canvas.new(1,1))).to equal(subject)
|
166
|
+
expect(subject.replace!(ChunkyPNG::Canvas.new(1, 1))).to equal(subject)
|
166
167
|
end
|
167
168
|
|
168
169
|
it "should raise an exception when the pixels to replace fall outside the image" do
|
169
|
-
expect { subject.replace!(ChunkyPNG::Canvas.new(1,1), 16, 16) }.to raise_error(ChunkyPNG::OutOfBounds)
|
170
|
+
expect { subject.replace!(ChunkyPNG::Canvas.new(1, 1), 16, 16) }.to raise_error(ChunkyPNG::OutOfBounds)
|
170
171
|
end
|
171
172
|
end
|
172
173
|
end
|
173
174
|
|
174
175
|
describe ChunkyPNG::Canvas::Operations do
|
175
|
-
|
176
176
|
subject { ChunkyPNG::Canvas.new(2, 3, [1, 2, 3, 4, 5, 6]) }
|
177
177
|
|
178
|
-
describe
|
178
|
+
describe "#flip_horizontally!" do
|
179
179
|
it "should flip the pixels horizontally in place" do
|
180
180
|
subject.flip_horizontally!
|
181
181
|
expect(subject).to eql ChunkyPNG::Canvas.new(2, 3, [5, 6, 3, 4, 1, 2])
|
@@ -186,7 +186,7 @@ describe ChunkyPNG::Canvas::Operations do
|
|
186
186
|
end
|
187
187
|
end
|
188
188
|
|
189
|
-
describe
|
189
|
+
describe "#flip_horizontally" do
|
190
190
|
it "should flip the pixels horizontally" do
|
191
191
|
expect(subject.flip_horizontally).to eql ChunkyPNG::Canvas.new(2, 3, [5, 6, 3, 4, 1, 2])
|
192
192
|
end
|
@@ -200,7 +200,7 @@ describe ChunkyPNG::Canvas::Operations do
|
|
200
200
|
end
|
201
201
|
end
|
202
202
|
|
203
|
-
describe
|
203
|
+
describe "#flip_vertically!" do
|
204
204
|
it "should flip the pixels vertically" do
|
205
205
|
subject.flip_vertically!
|
206
206
|
expect(subject).to eql ChunkyPNG::Canvas.new(2, 3, [2, 1, 4, 3, 6, 5])
|
@@ -211,7 +211,7 @@ describe ChunkyPNG::Canvas::Operations do
|
|
211
211
|
end
|
212
212
|
end
|
213
213
|
|
214
|
-
describe
|
214
|
+
describe "#flip_vertically" do
|
215
215
|
it "should flip the pixels vertically" do
|
216
216
|
expect(subject.flip_vertically).to eql ChunkyPNG::Canvas.new(2, 3, [2, 1, 4, 3, 6, 5])
|
217
217
|
end
|
@@ -225,9 +225,9 @@ describe ChunkyPNG::Canvas::Operations do
|
|
225
225
|
end
|
226
226
|
end
|
227
227
|
|
228
|
-
describe
|
228
|
+
describe "#rotate_left" do
|
229
229
|
it "should rotate the pixels 90 degrees counter-clockwise" do
|
230
|
-
expect(subject.rotate_left).to eql ChunkyPNG::Canvas.new(3, 2, [2, 4, 6, 1, 3, 5]
|
230
|
+
expect(subject.rotate_left).to eql ChunkyPNG::Canvas.new(3, 2, [2, 4, 6, 1, 3, 5])
|
231
231
|
end
|
232
232
|
|
233
233
|
it "should not return itself" do
|
@@ -251,10 +251,10 @@ describe ChunkyPNG::Canvas::Operations do
|
|
251
251
|
end
|
252
252
|
end
|
253
253
|
|
254
|
-
describe
|
254
|
+
describe "#rotate_left!" do
|
255
255
|
it "should rotate the pixels 90 degrees clockwise" do
|
256
256
|
subject.rotate_left!
|
257
|
-
expect(subject).to eql ChunkyPNG::Canvas.new(3, 2, [2, 4, 6, 1, 3, 5]
|
257
|
+
expect(subject).to eql ChunkyPNG::Canvas.new(3, 2, [2, 4, 6, 1, 3, 5])
|
258
258
|
end
|
259
259
|
|
260
260
|
it "should return itself" do
|
@@ -262,14 +262,14 @@ describe ChunkyPNG::Canvas::Operations do
|
|
262
262
|
end
|
263
263
|
|
264
264
|
it "should change the image dimensions" do
|
265
|
-
expect { subject.rotate_left! }.to change { subject.dimension }
|
266
|
-
|
265
|
+
expect { subject.rotate_left! }.to change { subject.dimension }
|
266
|
+
.from(ChunkyPNG::Dimension("2x3")).to(ChunkyPNG::Dimension("3x2"))
|
267
267
|
end
|
268
268
|
end
|
269
269
|
|
270
|
-
describe
|
270
|
+
describe "#rotate_right" do
|
271
271
|
it "should rotate the pixels 90 degrees clockwise" do
|
272
|
-
expect(subject.rotate_right).to eql ChunkyPNG::Canvas.new(3, 2, [5, 3, 1, 6, 4, 2]
|
272
|
+
expect(subject.rotate_right).to eql ChunkyPNG::Canvas.new(3, 2, [5, 3, 1, 6, 4, 2])
|
273
273
|
end
|
274
274
|
|
275
275
|
it "should not return itself" do
|
@@ -293,10 +293,10 @@ describe ChunkyPNG::Canvas::Operations do
|
|
293
293
|
end
|
294
294
|
end
|
295
295
|
|
296
|
-
describe
|
296
|
+
describe "#rotate_right!" do
|
297
297
|
it "should rotate the pixels 90 degrees clockwise" do
|
298
298
|
subject.rotate_right!
|
299
|
-
expect(subject).to eql ChunkyPNG::Canvas.new(3, 2, [5, 3, 1, 6, 4, 2]
|
299
|
+
expect(subject).to eql ChunkyPNG::Canvas.new(3, 2, [5, 3, 1, 6, 4, 2])
|
300
300
|
end
|
301
301
|
|
302
302
|
it "should return itself" do
|
@@ -304,12 +304,13 @@ describe ChunkyPNG::Canvas::Operations do
|
|
304
304
|
end
|
305
305
|
|
306
306
|
it "should change the image dimensions" do
|
307
|
-
expect { subject.rotate_right! }.to change { subject.dimension }
|
308
|
-
|
307
|
+
expect { subject.rotate_right! }.to change { subject.dimension }
|
308
|
+
.from(ChunkyPNG::Dimension("2x3"))
|
309
|
+
.to(ChunkyPNG::Dimension("3x2"))
|
309
310
|
end
|
310
311
|
end
|
311
312
|
|
312
|
-
describe
|
313
|
+
describe "#rotate_180" do
|
313
314
|
it "should rotate the pixels 180 degrees" do
|
314
315
|
expect(subject.rotate_180).to eql ChunkyPNG::Canvas.new(2, 3, [6, 5, 4, 3, 2, 1])
|
315
316
|
end
|
@@ -323,7 +324,7 @@ describe ChunkyPNG::Canvas::Operations do
|
|
323
324
|
end
|
324
325
|
end
|
325
326
|
|
326
|
-
describe
|
327
|
+
describe "#rotate_180!" do
|
327
328
|
it "should rotate the pixels 180 degrees" do
|
328
329
|
subject.rotate_180!
|
329
330
|
expect(subject).to eql ChunkyPNG::Canvas.new(2, 3, [6, 5, 4, 3, 2, 1])
|
@@ -336,7 +337,6 @@ describe ChunkyPNG::Canvas::Operations do
|
|
336
337
|
end
|
337
338
|
|
338
339
|
describe ChunkyPNG::Canvas::Operations do
|
339
|
-
|
340
340
|
subject { ChunkyPNG::Canvas.new(4, 4).rect(1, 1, 2, 2, 255, 255) }
|
341
341
|
|
342
342
|
describe "#trim" do
|
@@ -368,19 +368,19 @@ describe ChunkyPNG::Canvas::Operations do
|
|
368
368
|
end
|
369
369
|
|
370
370
|
it "should change the image dimensions" do
|
371
|
-
expect { subject.trim! }.to change { subject.dimension }
|
372
|
-
|
371
|
+
expect { subject.trim! }.to change { subject.dimension }
|
372
|
+
.from(ChunkyPNG::Dimension("4x4"))
|
373
|
+
.to(ChunkyPNG::Dimension("2x2"))
|
373
374
|
end
|
374
375
|
end
|
375
376
|
end
|
376
377
|
|
377
378
|
describe ChunkyPNG::Canvas::Operations do
|
378
|
-
|
379
379
|
subject { ChunkyPNG::Canvas.new(4, 4) }
|
380
380
|
|
381
381
|
describe "#border" do
|
382
382
|
it "should add the border" do
|
383
|
-
expect(subject.border(2)).to eql reference_canvas(
|
383
|
+
expect(subject.border(2)).to eql reference_canvas("operations_border")
|
384
384
|
end
|
385
385
|
|
386
386
|
it "should not return itself" do
|
@@ -395,7 +395,7 @@ describe ChunkyPNG::Canvas::Operations do
|
|
395
395
|
describe "#border!" do
|
396
396
|
it "should add the border" do
|
397
397
|
subject.border!(2)
|
398
|
-
expect(subject).to eql reference_canvas(
|
398
|
+
expect(subject).to eql reference_canvas("operations_border")
|
399
399
|
end
|
400
400
|
|
401
401
|
it "should return itself" do
|
@@ -408,8 +408,9 @@ describe ChunkyPNG::Canvas::Operations do
|
|
408
408
|
end
|
409
409
|
|
410
410
|
it "should change the image dimensions" do
|
411
|
-
expect { subject.border!(1) }.to change { subject.dimension }
|
412
|
-
|
411
|
+
expect { subject.border!(1) }.to change { subject.dimension }
|
412
|
+
.from(ChunkyPNG::Dimension("4x4"))
|
413
|
+
.to(ChunkyPNG::Dimension("6x6"))
|
413
414
|
end
|
414
415
|
end
|
415
416
|
end
|
@@ -1,97 +1,96 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe ChunkyPNG::Canvas::PNGDecoding do
|
4
4
|
include ChunkyPNG::Canvas::PNGDecoding
|
5
5
|
|
6
|
-
describe
|
7
|
-
|
6
|
+
describe "#decode_png_scanline" do
|
8
7
|
it "should decode a line without filtering as is" do
|
9
|
-
stream = [ChunkyPNG::FILTER_NONE, 255, 255, 255, 255, 255, 255, 255, 255, 255].pack(
|
8
|
+
stream = [ChunkyPNG::FILTER_NONE, 255, 255, 255, 255, 255, 255, 255, 255, 255].pack("C*")
|
10
9
|
decode_png_str_scanline(stream, 0, nil, 9, 3)
|
11
|
-
expect(stream.unpack(
|
10
|
+
expect(stream.unpack("@1C*")).to eql [255, 255, 255, 255, 255, 255, 255, 255, 255]
|
12
11
|
end
|
13
12
|
|
14
13
|
it "should decode a line with sub filtering correctly" do
|
15
14
|
# all white pixels
|
16
|
-
stream = [ChunkyPNG::FILTER_SUB, 255, 255, 255, 0, 0, 0, 0, 0, 0].pack(
|
15
|
+
stream = [ChunkyPNG::FILTER_SUB, 255, 255, 255, 0, 0, 0, 0, 0, 0].pack("C*")
|
17
16
|
decode_png_str_scanline(stream, 0, nil, 9, 3)
|
18
|
-
expect(stream.unpack(
|
17
|
+
expect(stream.unpack("@1C*")).to eql [255, 255, 255, 255, 255, 255, 255, 255, 255]
|
19
18
|
|
20
19
|
# all black pixels
|
21
|
-
stream = [ChunkyPNG::FILTER_SUB, 0, 0, 0, 0, 0, 0, 0, 0, 0].pack(
|
20
|
+
stream = [ChunkyPNG::FILTER_SUB, 0, 0, 0, 0, 0, 0, 0, 0, 0].pack("C*")
|
22
21
|
decode_png_str_scanline(stream, 0, nil, 9, 3)
|
23
|
-
expect(stream.unpack(
|
22
|
+
expect(stream.unpack("@1C*")).to eql [0, 0, 0, 0, 0, 0, 0, 0, 0]
|
24
23
|
|
25
24
|
# various colors
|
26
|
-
stream = [ChunkyPNG::FILTER_SUB, 255, 0, 45, 0, 255, 0, 112, 200, 178].pack(
|
25
|
+
stream = [ChunkyPNG::FILTER_SUB, 255, 0, 45, 0, 255, 0, 112, 200, 178].pack("C*")
|
27
26
|
decode_png_str_scanline(stream, 0, nil, 9, 3)
|
28
|
-
expect(stream.unpack(
|
27
|
+
expect(stream.unpack("@1C*")).to eql [255, 0, 45, 255, 255, 45, 111, 199, 223]
|
29
28
|
end
|
30
29
|
|
31
30
|
it "should decode a line with up filtering correctly" do
|
32
31
|
# previous line has various pixels
|
33
32
|
previous = [ChunkyPNG::FILTER_UP, 255, 255, 255, 127, 127, 127, 0, 0, 0]
|
34
33
|
current = [ChunkyPNG::FILTER_UP, 0, 127, 255, 0, 127, 255, 0, 127, 255]
|
35
|
-
stream = (previous + current).pack(
|
34
|
+
stream = (previous + current).pack("C*")
|
36
35
|
decode_png_str_scanline(stream, 10, 0, 9, 3)
|
37
|
-
expect(stream.unpack(
|
36
|
+
expect(stream.unpack("@11C9")).to eql [255, 126, 254, 127, 254, 126, 0, 127, 255]
|
38
37
|
end
|
39
38
|
|
40
39
|
it "should decode a line with average filtering correctly" do
|
41
|
-
previous = [ChunkyPNG::FILTER_AVERAGE, 10, 20, 30, 40, 50, 60, 70, 80, 80, 100, 110, 120]
|
42
|
-
current = [ChunkyPNG::FILTER_AVERAGE, 0, 0, 10, 23, 15, 13, 23, 63, 38, 60, 253, 53]
|
43
|
-
stream = (previous + current).pack(
|
40
|
+
previous = [ChunkyPNG::FILTER_AVERAGE, 10, 20, 30, 40, 50, 60, 70, 80, 80, 100, 110, 120] # rubocop:disable Layout/ExtraSpacing
|
41
|
+
current = [ChunkyPNG::FILTER_AVERAGE, 0, 0, 10, 23, 15, 13, 23, 63, 38, 60, 253, 53] # rubocop:disable Layout/ExtraSpacing
|
42
|
+
stream = (previous + current).pack("C*")
|
44
43
|
decode_png_str_scanline(stream, 13, 0, 12, 3)
|
45
|
-
expect(stream.unpack(
|
44
|
+
expect(stream.unpack("@14C12")).to eql [5, 10, 25, 45, 45, 55, 80, 125, 105, 150, 114, 165]
|
46
45
|
end
|
47
46
|
|
48
47
|
it "should decode a line with paeth filtering correctly" do
|
49
|
-
previous = [ChunkyPNG::FILTER_PAETH, 10, 20, 30, 40, 50, 60, 70, 80, 80, 100, 110, 120]
|
50
|
-
current = [ChunkyPNG::FILTER_PAETH, 0, 0, 10, 20, 10, 0, 0, 40, 10, 20, 190, 0]
|
51
|
-
stream = (previous + current).pack(
|
48
|
+
previous = [ChunkyPNG::FILTER_PAETH, 10, 20, 30, 40, 50, 60, 70, 80, 80, 100, 110, 120] # rubocop:disable Layout/ExtraSpacing
|
49
|
+
current = [ChunkyPNG::FILTER_PAETH, 0, 0, 10, 20, 10, 0, 0, 40, 10, 20, 190, 0] # rubocop:disable Layout/ExtraSpacing
|
50
|
+
stream = (previous + current).pack("C*")
|
52
51
|
decode_png_str_scanline(stream, 13, 0, 12, 3)
|
53
|
-
expect(stream.unpack(
|
52
|
+
expect(stream.unpack("@14C12")).to eql [10, 20, 40, 60, 60, 60, 70, 120, 90, 120, 54, 120]
|
54
53
|
end
|
55
54
|
end
|
56
55
|
|
57
|
-
describe
|
56
|
+
describe "#decode_png_extract_4bit_value" do
|
58
57
|
it "should extract the high bits successfully" do
|
59
|
-
expect(decode_png_extract_4bit_value(
|
58
|
+
expect(decode_png_extract_4bit_value("10010110".to_i(2), 0)).to eql "1001".to_i(2)
|
60
59
|
end
|
61
60
|
|
62
61
|
it "should extract the low bits successfully" do
|
63
|
-
expect(decode_png_extract_4bit_value(
|
62
|
+
expect(decode_png_extract_4bit_value("10010110".to_i(2), 17)).to eql "0110".to_i(2)
|
64
63
|
end
|
65
64
|
end
|
66
65
|
|
67
|
-
describe
|
66
|
+
describe "#decode_png_extract_2bit_value" do
|
68
67
|
it "should extract the first 2 bits successfully" do
|
69
|
-
expect(decode_png_extract_2bit_value(
|
68
|
+
expect(decode_png_extract_2bit_value("10010110".to_i(2), 0)).to eql "10".to_i(2)
|
70
69
|
end
|
71
70
|
|
72
71
|
it "should extract the second 2 bits successfully" do
|
73
|
-
expect(decode_png_extract_2bit_value(
|
72
|
+
expect(decode_png_extract_2bit_value("10010110".to_i(2), 5)).to eql "01".to_i(2)
|
74
73
|
end
|
75
74
|
|
76
75
|
it "should extract the third 2 bits successfully" do
|
77
|
-
expect(decode_png_extract_2bit_value(
|
76
|
+
expect(decode_png_extract_2bit_value("10010110".to_i(2), 2)).to eql "01".to_i(2)
|
78
77
|
end
|
79
78
|
|
80
79
|
it "should extract the low two bits successfully" do
|
81
|
-
expect(decode_png_extract_2bit_value(
|
80
|
+
expect(decode_png_extract_2bit_value("10010110".to_i(2), 7)).to eql "10".to_i(2)
|
82
81
|
end
|
83
82
|
end
|
84
83
|
|
85
|
-
describe
|
84
|
+
describe "#decode_png_extract_1bit_value" do
|
86
85
|
it "should extract all separate bits correctly" do
|
87
|
-
expect(decode_png_extract_1bit_value(
|
88
|
-
expect(decode_png_extract_1bit_value(
|
89
|
-
expect(decode_png_extract_1bit_value(
|
90
|
-
expect(decode_png_extract_1bit_value(
|
91
|
-
expect(decode_png_extract_1bit_value(
|
92
|
-
expect(decode_png_extract_1bit_value(
|
93
|
-
expect(decode_png_extract_1bit_value(
|
94
|
-
expect(decode_png_extract_1bit_value(
|
86
|
+
expect(decode_png_extract_1bit_value("10010110".to_i(2), 0)).to eql 1
|
87
|
+
expect(decode_png_extract_1bit_value("10010110".to_i(2), 1)).to eql 0
|
88
|
+
expect(decode_png_extract_1bit_value("10010110".to_i(2), 2)).to eql 0
|
89
|
+
expect(decode_png_extract_1bit_value("10010110".to_i(2), 3)).to eql 1
|
90
|
+
expect(decode_png_extract_1bit_value("10010110".to_i(2), 4)).to eql 0
|
91
|
+
expect(decode_png_extract_1bit_value("10010110".to_i(2), 5)).to eql 1
|
92
|
+
expect(decode_png_extract_1bit_value("10010110".to_i(2), 6)).to eql 1
|
93
|
+
expect(decode_png_extract_1bit_value("10010110".to_i(2), 7)).to eql 0
|
95
94
|
end
|
96
95
|
end
|
97
96
|
end
|