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,12 +1,11 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe ChunkyPNG::Canvas::Drawing do
|
4
|
-
|
5
|
-
describe '#compose_pixel' do
|
4
|
+
describe "#compose_pixel" do
|
6
5
|
subject { ChunkyPNG::Canvas.new(1, 1, ChunkyPNG::Color.rgb(200, 150, 100)) }
|
7
6
|
|
8
7
|
it "should compose colors correctly" do
|
9
|
-
subject.compose_pixel(0,0, ChunkyPNG::Color(100, 150, 200, 128))
|
8
|
+
subject.compose_pixel(0, 0, ChunkyPNG::Color(100, 150, 200, 128))
|
10
9
|
expect(subject[0, 0]).to eql ChunkyPNG::Color(150, 150, 150)
|
11
10
|
end
|
12
11
|
|
@@ -20,11 +19,11 @@ describe ChunkyPNG::Canvas::Drawing do
|
|
20
19
|
end
|
21
20
|
end
|
22
21
|
|
23
|
-
describe
|
22
|
+
describe "#line" do
|
24
23
|
it "should draw lines correctly with anti-aliasing" do
|
25
|
-
|
26
24
|
canvas = ChunkyPNG::Canvas.new(31, 31, ChunkyPNG::Color::WHITE)
|
27
25
|
|
26
|
+
# rubocop:disable Layout/SpaceInsideParens # for improved readability
|
28
27
|
canvas.line( 0, 0, 30, 30, ChunkyPNG::Color::BLACK)
|
29
28
|
canvas.line( 0, 30, 30, 0, ChunkyPNG::Color::BLACK)
|
30
29
|
canvas.line(15, 30, 15, 0, ChunkyPNG::Color.rgba(200, 0, 0, 128))
|
@@ -33,13 +32,14 @@ describe ChunkyPNG::Canvas::Drawing do
|
|
33
32
|
canvas.line( 0, 15, 30, 0, ChunkyPNG::Color.rgba( 0, 200, 0, 128))
|
34
33
|
canvas.line( 0, 30, 15, 0, ChunkyPNG::Color.rgba( 0, 0, 200, 128), false)
|
35
34
|
canvas.line(15, 0, 30, 30, ChunkyPNG::Color.rgba( 0, 0, 200, 128))
|
35
|
+
# rubocop:enable Layout/SpaceInsideParens
|
36
36
|
|
37
|
-
expect(canvas).to eql reference_canvas(
|
37
|
+
expect(canvas).to eql reference_canvas("lines")
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should draw partial lines if the coordinates are partially out of bounds" do
|
41
41
|
canvas = ChunkyPNG::Canvas.new(1, 2, ChunkyPNG::Color::WHITE)
|
42
|
-
canvas.line(-5, -5, 0, 0,
|
42
|
+
canvas.line(-5, -5, 0, 0, "#000000")
|
43
43
|
expect(canvas.pixels).to eql [ChunkyPNG::Color::BLACK, ChunkyPNG::Color::WHITE]
|
44
44
|
end
|
45
45
|
|
@@ -47,15 +47,23 @@ describe ChunkyPNG::Canvas::Drawing do
|
|
47
47
|
canvas = ChunkyPNG::Canvas.new(16, 16, ChunkyPNG::Color::WHITE)
|
48
48
|
expect(canvas.line(1, 1, 10, 10, :black)).to equal(canvas)
|
49
49
|
end
|
50
|
+
|
51
|
+
it "should draw a single pixel when the start and end point are the same" do
|
52
|
+
canvas = ChunkyPNG::Canvas.new(5, 5, ChunkyPNG::Color::WHITE)
|
53
|
+
canvas.line(2, 2, 2, 2, ChunkyPNG::Color::BLACK)
|
54
|
+
|
55
|
+
non_white_pixels = canvas.pixels.count { |pixel| pixel != ChunkyPNG::Color::WHITE }
|
56
|
+
expect(non_white_pixels).to eql 1
|
57
|
+
end
|
50
58
|
end
|
51
59
|
|
52
|
-
describe
|
53
|
-
subject { ChunkyPNG::Canvas.new(16, 16,
|
60
|
+
describe "#rect" do
|
61
|
+
subject { ChunkyPNG::Canvas.new(16, 16, "#ffffff") }
|
54
62
|
|
55
63
|
it "should draw a rectangle with the correct colors" do
|
56
|
-
subject.rect(1, 1, 10, 10, ChunkyPNG::Color.rgba(0, 255, 0,
|
64
|
+
subject.rect(1, 1, 10, 10, ChunkyPNG::Color.rgba(0, 255, 0, 80), ChunkyPNG::Color.rgba(255, 0, 0, 100))
|
57
65
|
subject.rect(5, 5, 14, 14, ChunkyPNG::Color.rgba(0, 0, 255, 160), ChunkyPNG::Color.rgba(255, 255, 0, 100))
|
58
|
-
expect(subject).to eql reference_canvas(
|
66
|
+
expect(subject).to eql reference_canvas("rect")
|
59
67
|
end
|
60
68
|
|
61
69
|
it "should return itself to allow chaining" do
|
@@ -73,19 +81,19 @@ describe ChunkyPNG::Canvas::Drawing do
|
|
73
81
|
end
|
74
82
|
end
|
75
83
|
|
76
|
-
describe
|
84
|
+
describe "#circle" do
|
77
85
|
subject { ChunkyPNG::Canvas.new(32, 32, ChunkyPNG::Color.rgba(0, 0, 255, 128)) }
|
78
86
|
|
79
87
|
it "should draw circles" do
|
80
|
-
subject.circle(11, 11, 10, ChunkyPNG::Color(
|
81
|
-
subject.circle(21, 21, 10, ChunkyPNG::Color(
|
82
|
-
expect(subject).to eql reference_canvas(
|
88
|
+
subject.circle(11, 11, 10, ChunkyPNG::Color("red @ 0.5"), ChunkyPNG::Color("white @ 0.2"))
|
89
|
+
subject.circle(21, 21, 10, ChunkyPNG::Color("green @ 0.5"))
|
90
|
+
expect(subject).to eql reference_canvas("circles")
|
83
91
|
end
|
84
92
|
|
85
93
|
it "should draw partial circles when going of the canvas bounds" do
|
86
94
|
subject.circle(0, 0, 10, ChunkyPNG::Color(:red))
|
87
95
|
subject.circle(31, 16, 10, ChunkyPNG::Color(:black), ChunkyPNG::Color(:white, 0xaa))
|
88
|
-
expect(subject).to eql reference_canvas(
|
96
|
+
expect(subject).to eql reference_canvas("partial_circles")
|
89
97
|
end
|
90
98
|
|
91
99
|
it "should return itself to allow chaining" do
|
@@ -93,78 +101,78 @@ describe ChunkyPNG::Canvas::Drawing do
|
|
93
101
|
end
|
94
102
|
end
|
95
103
|
|
96
|
-
describe
|
104
|
+
describe "#polygon" do
|
97
105
|
subject { ChunkyPNG::Canvas.new(22, 22) }
|
98
106
|
|
99
107
|
it "should draw an filled triangle when using 3 control points" do
|
100
|
-
subject.polygon(
|
101
|
-
expect(subject).to eql reference_canvas(
|
108
|
+
subject.polygon("(2,2) (20,5) (5,20)", ChunkyPNG::Color(:black, 0xaa), ChunkyPNG::Color(:red, 0x44))
|
109
|
+
expect(subject).to eql reference_canvas("polygon_triangle_filled")
|
102
110
|
end
|
103
111
|
|
104
112
|
it "should draw a unfilled polygon with 6 control points" do
|
105
|
-
subject.polygon(
|
106
|
-
expect(subject).to eql reference_canvas(
|
113
|
+
subject.polygon("(2,2) (12, 1) (20,5) (18,18) (5,20) (1,12)", ChunkyPNG::Color(:black))
|
114
|
+
expect(subject).to eql reference_canvas("polygon_unfilled")
|
107
115
|
end
|
108
116
|
|
109
117
|
it "should draw a vertically crossed filled polygon with 4 control points" do
|
110
|
-
subject.polygon(
|
111
|
-
expect(subject).to eql reference_canvas(
|
118
|
+
subject.polygon("(2,2) (21,2) (2,21) (21,21)", ChunkyPNG::Color(:black), ChunkyPNG::Color(:red))
|
119
|
+
expect(subject).to eql reference_canvas("polygon_filled_vertical")
|
112
120
|
end
|
113
121
|
|
114
122
|
it "should draw a vertically crossed filled polygon with 4 control points" do
|
115
|
-
subject.polygon(
|
116
|
-
expect(subject).to eql reference_canvas(
|
123
|
+
subject.polygon("(2,2) (2,21) (21,2) (21,21)", ChunkyPNG::Color(:black), ChunkyPNG::Color(:red))
|
124
|
+
expect(subject).to eql reference_canvas("polygon_filled_horizontal")
|
117
125
|
end
|
118
126
|
|
119
127
|
it "should return itself to allow chaining" do
|
120
|
-
expect(subject.polygon(
|
128
|
+
expect(subject.polygon("(2,2) (20,5) (5,20)")).to equal(subject)
|
121
129
|
end
|
122
130
|
end
|
123
131
|
|
124
|
-
describe
|
132
|
+
describe "#bezier_curve" do
|
125
133
|
subject { ChunkyPNG::Canvas.new(24, 24, ChunkyPNG::Color::WHITE) }
|
126
134
|
|
127
135
|
it "should draw a bezier curve starting at the first point" do
|
128
|
-
subject.bezier_curve(
|
136
|
+
subject.bezier_curve("3,20 10,10, 20,20")
|
129
137
|
expect(subject[3, 20]).to eql ChunkyPNG::Color::BLACK
|
130
138
|
end
|
131
139
|
|
132
140
|
it "should draw a bezier curve ending at the last point" do
|
133
|
-
subject.bezier_curve(
|
141
|
+
subject.bezier_curve("3,20 10,10, 20,20")
|
134
142
|
expect(subject[20, 20]).to eql ChunkyPNG::Color::BLACK
|
135
143
|
end
|
136
144
|
|
137
145
|
it "should draw a bezier curve with a color of green" do
|
138
|
-
subject.bezier_curve(
|
146
|
+
subject.bezier_curve("3,20 10,10, 20,20", :green)
|
139
147
|
expect(subject[3, 20]).to eql ChunkyPNG::Color(:green)
|
140
148
|
end
|
141
149
|
|
142
150
|
it "should draw a three point bezier curve" do
|
143
|
-
expect(subject.bezier_curve(
|
151
|
+
expect(subject.bezier_curve("1,23 12,10 23,23")).to eql reference_canvas("bezier_three_point")
|
144
152
|
end
|
145
153
|
|
146
154
|
it "should draw a three point bezier curve flipped" do
|
147
|
-
expect(subject.bezier_curve(
|
155
|
+
expect(subject.bezier_curve("1,1 12,15 23,1")).to eql reference_canvas("bezier_three_point_flipped")
|
148
156
|
end
|
149
157
|
|
150
158
|
it "should draw a four point bezier curve" do
|
151
|
-
expect(subject.bezier_curve(
|
159
|
+
expect(subject.bezier_curve("1,23 1,5 22,5 22,23")).to eql reference_canvas("bezier_four_point")
|
152
160
|
end
|
153
161
|
|
154
162
|
it "should draw a four point bezier curve flipped" do
|
155
|
-
expect(subject.bezier_curve(
|
163
|
+
expect(subject.bezier_curve("1,1 1,19 22,19 22,1")).to eql reference_canvas("bezier_four_point_flipped")
|
156
164
|
end
|
157
165
|
|
158
166
|
it "should draw a four point bezier curve with a shape of an s" do
|
159
|
-
expect(subject.bezier_curve(
|
167
|
+
expect(subject.bezier_curve("1,23 1,5 22,23 22,5")).to eql reference_canvas("bezier_four_point_s")
|
160
168
|
end
|
161
169
|
|
162
170
|
it "should draw a five point bezier curve" do
|
163
|
-
expect(subject.bezier_curve(
|
171
|
+
expect(subject.bezier_curve("10,23 1,10 12,5 23,10 14,23")).to eql reference_canvas("bezier_five_point")
|
164
172
|
end
|
165
173
|
|
166
174
|
it "should draw a six point bezier curve" do
|
167
|
-
expect(subject.bezier_curve(
|
175
|
+
expect(subject.bezier_curve("1,23 4,15 8,20 2,2 23,15 23,1")).to eql reference_canvas("bezier_six_point")
|
168
176
|
end
|
169
177
|
end
|
170
178
|
end
|
@@ -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
|