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,16 +1,14 @@
|
|
1
|
-
|
2
|
-
require 'spec_helper'
|
1
|
+
require "spec_helper"
|
3
2
|
|
4
3
|
describe ChunkyPNG::Datastream do
|
5
|
-
|
6
|
-
describe '.from_io'do
|
4
|
+
describe ".from_io" do
|
7
5
|
it "should raise an error when loading a file with a bad signature" do
|
8
|
-
filename = resource_file(
|
6
|
+
filename = resource_file("damaged_signature.png")
|
9
7
|
expect { ChunkyPNG::Datastream.from_file(filename) }.to raise_error(ChunkyPNG::SignatureMismatch)
|
10
8
|
end
|
11
9
|
|
12
10
|
it "should raise an error if the CRC of a chunk is incorrect" do
|
13
|
-
filename = resource_file(
|
11
|
+
filename = resource_file("damaged_chunk.png")
|
14
12
|
expect { ChunkyPNG::Datastream.from_file(filename) }.to raise_error(ChunkyPNG::CRCMismatch)
|
15
13
|
end
|
16
14
|
|
@@ -20,37 +18,37 @@ describe ChunkyPNG::Datastream do
|
|
20
18
|
end
|
21
19
|
|
22
20
|
it "should read a stream with trailing data without failing" do
|
23
|
-
filename = resource_file(
|
21
|
+
filename = resource_file("trailing_bytes_after_iend_chunk.png")
|
24
22
|
image = ChunkyPNG::Datastream.from_file(filename)
|
25
23
|
expect(image).to be_instance_of(ChunkyPNG::Datastream)
|
26
24
|
end
|
27
25
|
end
|
28
26
|
|
29
|
-
describe
|
27
|
+
describe "#metadata" do
|
30
28
|
it "should load uncompressed tXTt chunks correctly" do
|
31
|
-
filename = resource_file(
|
29
|
+
filename = resource_file("text_chunk.png")
|
32
30
|
ds = ChunkyPNG::Datastream.from_file(filename)
|
33
|
-
expect(ds.metadata[
|
34
|
-
expect(ds.metadata[
|
31
|
+
expect(ds.metadata["Title"]).to eql "My amazing icon!"
|
32
|
+
expect(ds.metadata["Author"]).to eql "Willem van Bergen"
|
35
33
|
end
|
36
34
|
|
37
35
|
it "should load compressed zTXt chunks correctly" do
|
38
|
-
filename = resource_file(
|
36
|
+
filename = resource_file("ztxt_chunk.png")
|
39
37
|
ds = ChunkyPNG::Datastream.from_file(filename)
|
40
|
-
expect(ds.metadata[
|
41
|
-
expect(ds.metadata[
|
38
|
+
expect(ds.metadata["Title"]).to eql "PngSuite"
|
39
|
+
expect(ds.metadata["Copyright"]).to eql "Copyright Willem van Schaik, Singapore 1995-96"
|
42
40
|
end
|
43
41
|
|
44
42
|
it "ignores iTXt chunks" do
|
45
|
-
filename = resource_file(
|
43
|
+
filename = resource_file("itxt_chunk.png")
|
46
44
|
ds = ChunkyPNG::Datastream.from_file(filename)
|
47
45
|
expect(ds.metadata).to be_empty
|
48
46
|
end
|
49
47
|
end
|
50
48
|
|
51
|
-
describe
|
52
|
-
it
|
53
|
-
filename = resource_file(
|
49
|
+
describe "#physical_chunk" do
|
50
|
+
it "should read and write pHYs chunks correctly" do
|
51
|
+
filename = resource_file("clock.png")
|
54
52
|
ds = ChunkyPNG::Datastream.from_file(filename)
|
55
53
|
expect(ds.physical_chunk.unit).to eql :meters
|
56
54
|
expect(ds.physical_chunk.dpix.round).to eql 72
|
@@ -59,83 +57,83 @@ describe ChunkyPNG::Datastream do
|
|
59
57
|
expect(ds.physical_chunk).not_to be_nil
|
60
58
|
end
|
61
59
|
|
62
|
-
it
|
60
|
+
it "should raise ChunkyPNG::UnitsUnknown if we request dpi but the units are unknown" do
|
63
61
|
physical_chunk = ChunkyPNG::Chunk::Physical.new(2835, 2835, :unknown)
|
64
|
-
expect{physical_chunk.dpix}.to raise_error(ChunkyPNG::UnitsUnknown)
|
65
|
-
expect{physical_chunk.dpiy}.to raise_error(ChunkyPNG::UnitsUnknown)
|
62
|
+
expect { physical_chunk.dpix }.to raise_error(ChunkyPNG::UnitsUnknown)
|
63
|
+
expect { physical_chunk.dpiy }.to raise_error(ChunkyPNG::UnitsUnknown)
|
66
64
|
end
|
67
65
|
end
|
68
66
|
|
69
|
-
describe
|
70
|
-
it
|
71
|
-
filename = resource_file(
|
67
|
+
describe "#iTXt_chunk" do
|
68
|
+
it "should read iTXt chunks correctly" do
|
69
|
+
filename = resource_file("itxt_chunk.png")
|
72
70
|
ds = ChunkyPNG::Datastream.from_file(filename)
|
73
71
|
int_text_chunks = ds.chunks.select { |chunk| chunk.is_a?(ChunkyPNG::Chunk::InternationalText) }
|
74
72
|
expect(int_text_chunks.length).to eq(2)
|
75
73
|
|
76
|
-
coach_uk = int_text_chunks.find { |chunk| chunk.language_tag ==
|
77
|
-
coach_us = int_text_chunks.find { |chunk| chunk.language_tag ==
|
74
|
+
coach_uk = int_text_chunks.find { |chunk| chunk.language_tag == "en-gb" }
|
75
|
+
coach_us = int_text_chunks.find { |chunk| chunk.language_tag == "en-us" }
|
78
76
|
expect(coach_uk).to_not be_nil
|
79
77
|
expect(coach_us).to_not be_nil
|
80
78
|
|
81
|
-
expect(coach_uk.keyword).to eq(
|
82
|
-
expect(coach_uk.text).to eq(
|
83
|
-
expect(coach_uk.translated_keyword).to eq(
|
79
|
+
expect(coach_uk.keyword).to eq("coach")
|
80
|
+
expect(coach_uk.text).to eq("bus with of higher standard of comfort, usually chartered or used for longer journeys")
|
81
|
+
expect(coach_uk.translated_keyword).to eq("bus")
|
84
82
|
expect(coach_uk.compressed).to eq(ChunkyPNG::UNCOMPRESSED_CONTENT)
|
85
83
|
expect(coach_uk.compression).to eq(ChunkyPNG::COMPRESSION_DEFAULT)
|
86
84
|
|
87
|
-
expect(coach_us.keyword).to eq(
|
88
|
-
expect(coach_us.text).to eq(
|
89
|
-
expect(coach_us.translated_keyword).to eq(
|
85
|
+
expect(coach_us.keyword).to eq("coach")
|
86
|
+
expect(coach_us.text).to eq("US extracurricular sports teacher at a school (UK: PE teacher) lowest class on a passenger aircraft (UK: economy)")
|
87
|
+
expect(coach_us.translated_keyword).to eq("trainer")
|
90
88
|
expect(coach_us.compressed).to eq(ChunkyPNG::COMPRESSED_CONTENT)
|
91
89
|
expect(coach_us.compression).to eq(ChunkyPNG::COMPRESSION_DEFAULT)
|
92
90
|
end
|
93
91
|
|
94
|
-
it
|
95
|
-
expected_hex = %w
|
92
|
+
it "should write iTXt chunks correctly" do
|
93
|
+
expected_hex = %w[0000 001d 6954 5874 436f 6d6d 656e 7400 0000 0000 4372 6561 7465 6420 7769 7468 2047 494d 5064 2e65 07].join("")
|
96
94
|
stream = StringIO.new
|
97
|
-
itext = ChunkyPNG::Chunk::InternationalText.new(
|
95
|
+
itext = ChunkyPNG::Chunk::InternationalText.new("Comment", "Created with GIMP")
|
98
96
|
itext.write(stream)
|
99
|
-
generated_hex = stream.string.unpack(
|
97
|
+
generated_hex = stream.string.unpack("H*").join("")
|
100
98
|
|
101
99
|
expect(generated_hex).to eq(expected_hex)
|
102
100
|
end
|
103
101
|
|
104
|
-
it
|
105
|
-
incorrect_text_encoding = [0, 0, 0, 14, 105, 84, 88, 116, 67, 111, 109, 109, 101, 110, 116, 0, 0, 0, 0, 0, 195, 40, 17, 87, 97, 213].pack(
|
106
|
-
incorrect_translated_keyword_encoding = [0, 0, 0, 19, 105, 84, 88, 116, 67, 111, 109, 109, 101, 110, 116, 0, 0, 0, 0, 226, 130, 40, 0, 116, 101, 115, 116, 228, 53, 113, 182].pack(
|
102
|
+
it "should handle incorrect UTF-8 encoding in iTXt chunks" do
|
103
|
+
incorrect_text_encoding = [0, 0, 0, 14, 105, 84, 88, 116, 67, 111, 109, 109, 101, 110, 116, 0, 0, 0, 0, 0, 195, 40, 17, 87, 97, 213].pack("C*")
|
104
|
+
incorrect_translated_keyword_encoding = [0, 0, 0, 19, 105, 84, 88, 116, 67, 111, 109, 109, 101, 110, 116, 0, 0, 0, 0, 226, 130, 40, 0, 116, 101, 115, 116, 228, 53, 113, 182].pack("C*")
|
107
105
|
|
108
106
|
expect { ChunkyPNG::Chunk.read(StringIO.new(incorrect_text_encoding)) }.to raise_error(ChunkyPNG::InvalidUTF8)
|
109
107
|
expect { ChunkyPNG::Chunk.read(StringIO.new(incorrect_translated_keyword_encoding)) }.to raise_error(ChunkyPNG::InvalidUTF8)
|
110
108
|
end
|
111
109
|
|
112
|
-
it
|
113
|
-
parsed = serialized_chunk(ChunkyPNG::Chunk::InternationalText.new(
|
110
|
+
it "should handle UTF-8 in iTXt compressed chunks correctly" do
|
111
|
+
parsed = serialized_chunk(ChunkyPNG::Chunk::InternationalText.new("Comment", "✨", "", "💩", ChunkyPNG::COMPRESSED_CONTENT))
|
114
112
|
|
115
|
-
expect(parsed.text).to eq(
|
113
|
+
expect(parsed.text).to eq("✨")
|
116
114
|
expect(parsed.text.encoding).to eq(Encoding::UTF_8)
|
117
115
|
|
118
|
-
expect(parsed.translated_keyword).to eq(
|
116
|
+
expect(parsed.translated_keyword).to eq("💩")
|
119
117
|
expect(parsed.translated_keyword.encoding).to eq(Encoding::UTF_8)
|
120
118
|
end
|
121
119
|
|
122
|
-
it
|
123
|
-
parsed = serialized_chunk(ChunkyPNG::Chunk::InternationalText.new(
|
120
|
+
it "should handle UTF-8 in iTXt chunks correctly" do
|
121
|
+
parsed = serialized_chunk(ChunkyPNG::Chunk::InternationalText.new("Comment", "✨", "", "💩"))
|
124
122
|
|
125
|
-
expect(parsed.text).to eq(
|
123
|
+
expect(parsed.text).to eq("✨")
|
126
124
|
expect(parsed.text.encoding).to eq(Encoding::UTF_8)
|
127
125
|
|
128
|
-
expect(parsed.translated_keyword).to eq(
|
126
|
+
expect(parsed.translated_keyword).to eq("💩")
|
129
127
|
expect(parsed.translated_keyword.encoding).to eq(Encoding::UTF_8)
|
130
128
|
end
|
131
129
|
|
132
|
-
it
|
133
|
-
parsed = serialized_chunk(ChunkyPNG::Chunk::InternationalText.new(
|
130
|
+
it "should transform non UTF-8 iTXt fields to UTF-8 on write" do
|
131
|
+
parsed = serialized_chunk(ChunkyPNG::Chunk::InternationalText.new("Comment", "®".encode("Windows-1252"), "", "ƒ".encode("Windows-1252")))
|
134
132
|
|
135
|
-
expect(parsed.text).to eq(
|
133
|
+
expect(parsed.text).to eq("®")
|
136
134
|
expect(parsed.text.encoding).to eq(Encoding::UTF_8)
|
137
135
|
|
138
|
-
expect(parsed.translated_keyword).to eq(
|
136
|
+
expect(parsed.translated_keyword).to eq("ƒ")
|
139
137
|
expect(parsed.translated_keyword.encoding).to eq(Encoding::UTF_8)
|
140
138
|
end
|
141
139
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe ChunkyPNG::Dimension do
|
4
4
|
subject { ChunkyPNG::Dimension.new(2, 3) }
|
@@ -6,31 +6,31 @@ describe ChunkyPNG::Dimension do
|
|
6
6
|
it { should respond_to(:width) }
|
7
7
|
it { should respond_to(:height) }
|
8
8
|
|
9
|
-
describe
|
9
|
+
describe "#area" do
|
10
10
|
it "should calculate the area correctly" do
|
11
11
|
expect(subject.area).to eql 6
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
describe
|
16
|
+
describe "ChunkyPNG.Dimension" do
|
17
17
|
subject { ChunkyPNG::Dimension.new(1, 2) }
|
18
18
|
|
19
19
|
it "should create a dimension from a 2-item array" do
|
20
20
|
expect(ChunkyPNG::Dimension([1, 2])).to eql subject
|
21
|
-
expect(ChunkyPNG::Dimension([
|
21
|
+
expect(ChunkyPNG::Dimension(["1", "2"])).to eql subject
|
22
22
|
end
|
23
23
|
|
24
|
-
it "should create a dimension from a hash with
|
25
|
-
expect(ChunkyPNG::Dimension(:
|
26
|
-
expect(ChunkyPNG::Dimension(
|
24
|
+
it "should create a dimension from a hash with width and height keys" do
|
25
|
+
expect(ChunkyPNG::Dimension(width: 1, height: 2)).to eql subject
|
26
|
+
expect(ChunkyPNG::Dimension("width" => "1", "height" => "2")).to eql subject
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should create a dimension from a point-like string" do
|
30
30
|
[
|
31
|
-
ChunkyPNG::Dimension(
|
32
|
-
ChunkyPNG::Dimension(
|
33
|
-
ChunkyPNG::Dimension(
|
31
|
+
ChunkyPNG::Dimension("1,2"),
|
32
|
+
ChunkyPNG::Dimension("1 2"),
|
33
|
+
ChunkyPNG::Dimension("(1 , 2)"),
|
34
34
|
ChunkyPNG::Dimension("{1x2}"),
|
35
35
|
ChunkyPNG::Dimension("[1\t2}"),
|
36
36
|
].all? { |point| point == subject }
|
@@ -1,31 +1,28 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe ChunkyPNG::Image do
|
4
|
-
describe
|
5
|
-
|
4
|
+
describe "#metadata" do
|
6
5
|
it "should load metadata from an existing file" do
|
7
|
-
image = ChunkyPNG::Image.from_file(resource_file(
|
8
|
-
expect(image.metadata[
|
9
|
-
expect(image.metadata[
|
6
|
+
image = ChunkyPNG::Image.from_file(resource_file("text_chunk.png"))
|
7
|
+
expect(image.metadata["Title"]).to eql "My amazing icon!"
|
8
|
+
expect(image.metadata["Author"]).to eql "Willem van Bergen"
|
10
9
|
end
|
11
10
|
|
12
11
|
it "should write metadata to the file correctly" do
|
13
|
-
filename = resource_file(
|
12
|
+
filename = resource_file("_metadata.png")
|
14
13
|
|
15
14
|
image = ChunkyPNG::Image.new(10, 10)
|
16
|
-
image.metadata[
|
17
|
-
image.metadata[
|
15
|
+
image.metadata["Title"] = "My amazing icon!"
|
16
|
+
image.metadata["Author"] = "Willem van Bergen"
|
18
17
|
image.save(filename)
|
19
18
|
|
20
19
|
metadata = ChunkyPNG::Datastream.from_file(filename).metadata
|
21
|
-
expect(metadata[
|
22
|
-
expect(metadata[
|
20
|
+
expect(metadata["Title"]).to eql "My amazing icon!"
|
21
|
+
expect(metadata["Author"]).to eql "Willem van Bergen"
|
23
22
|
end
|
24
23
|
|
25
24
|
it "should load empty images correctly" do
|
26
|
-
expect
|
27
|
-
ChunkyPNG::Image.from_file(resource_file('empty.png'))
|
28
|
-
end.to_not raise_error
|
25
|
+
expect { ChunkyPNG::Image.from_file(resource_file("empty.png")) }.to_not raise_error
|
29
26
|
end
|
30
27
|
end
|
31
28
|
end
|
@@ -1,58 +1,56 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe ChunkyPNG::Point do
|
4
|
-
|
5
4
|
subject { ChunkyPNG::Point.new(1, 2) }
|
6
5
|
|
7
6
|
it { should respond_to(:x) }
|
8
7
|
it { should respond_to(:y) }
|
9
8
|
|
10
|
-
describe
|
9
|
+
describe "#within_bounds?" do
|
11
10
|
it { should be_within_bounds(2, 3) }
|
12
|
-
it { should_not be_within_bounds(
|
11
|
+
it { should_not be_within_bounds("1x3") }
|
13
12
|
it { should_not be_within_bounds(2, 2) }
|
14
|
-
it { should_not be_within_bounds(
|
13
|
+
it { should_not be_within_bounds("[1 2]") }
|
15
14
|
end
|
16
15
|
|
17
|
-
describe
|
16
|
+
describe "#<=>" do
|
18
17
|
it "should return 0 if the coordinates are identical" do
|
19
|
-
expect((subject <=> ChunkyPNG::Point.new(1, 2))).to eql
|
18
|
+
expect((subject <=> ChunkyPNG::Point.new(1, 2))).to eql(0)
|
20
19
|
end
|
21
20
|
|
22
21
|
it "should return -1 if the y coordinate is smaller than the other one" do
|
23
|
-
expect((subject <=> ChunkyPNG::Point.new(1, 3))).to eql
|
24
|
-
expect((subject <=> ChunkyPNG::Point.new(0, 3))).to eql
|
25
|
-
expect((subject <=> ChunkyPNG::Point.new(2, 3))).to eql
|
22
|
+
expect((subject <=> ChunkyPNG::Point.new(1, 3))).to eql(-1)
|
23
|
+
expect((subject <=> ChunkyPNG::Point.new(0, 3))).to eql(-1) # x doesn't matter
|
24
|
+
expect((subject <=> ChunkyPNG::Point.new(2, 3))).to eql(-1) # x doesn't matter
|
26
25
|
end
|
27
26
|
|
28
27
|
it "should return 1 if the y coordinate is larger than the other one" do
|
29
|
-
expect((subject <=> ChunkyPNG::Point.new(1, 0))).to eql
|
30
|
-
expect((subject <=> ChunkyPNG::Point.new(0, 0))).to eql
|
31
|
-
expect((subject <=> ChunkyPNG::Point.new(2, 0))).to eql
|
28
|
+
expect((subject <=> ChunkyPNG::Point.new(1, 0))).to eql(1)
|
29
|
+
expect((subject <=> ChunkyPNG::Point.new(0, 0))).to eql(1) # x doesn't matter
|
30
|
+
expect((subject <=> ChunkyPNG::Point.new(2, 0))).to eql(1) # x doesn't matter
|
32
31
|
end
|
33
32
|
|
34
33
|
it "should return -1 if the x coordinate is smaller and y is the same" do
|
35
|
-
expect((subject <=> ChunkyPNG::Point.new(2, 2))).to eql
|
34
|
+
expect((subject <=> ChunkyPNG::Point.new(2, 2))).to eql(-1)
|
36
35
|
end
|
37
36
|
|
38
37
|
it "should return 1 if the x coordinate is larger and y is the same" do
|
39
|
-
expect((subject <=> ChunkyPNG::Point.new(0, 2))).to eql
|
38
|
+
expect((subject <=> ChunkyPNG::Point.new(0, 2))).to eql(1)
|
40
39
|
end
|
41
40
|
end
|
42
41
|
end
|
43
42
|
|
44
|
-
describe
|
43
|
+
describe "ChunkyPNG.Point" do
|
45
44
|
subject { ChunkyPNG::Point.new(1, 2) }
|
46
45
|
|
47
|
-
|
48
46
|
it "should create a point from a 2-item array" do
|
49
47
|
expect(ChunkyPNG::Point([1, 2])).to eql subject
|
50
|
-
expect(ChunkyPNG::Point([
|
48
|
+
expect(ChunkyPNG::Point(["1", "2"])).to eql subject
|
51
49
|
end
|
52
50
|
|
53
51
|
it "should create a point from a hash with x and y keys" do
|
54
|
-
expect(ChunkyPNG::Point(:
|
55
|
-
expect(ChunkyPNG::Point(
|
52
|
+
expect(ChunkyPNG::Point(x: 1, y: 2)).to eql subject
|
53
|
+
expect(ChunkyPNG::Point("x" => "1", "y" => "2")).to eql subject
|
56
54
|
end
|
57
55
|
|
58
56
|
it "should create a point from a ChunkyPNG::Dimension object" do
|
@@ -62,9 +60,9 @@ describe 'ChunkyPNG.Point' do
|
|
62
60
|
|
63
61
|
it "should create a point from a point-like string" do
|
64
62
|
[
|
65
|
-
ChunkyPNG::Point(
|
66
|
-
ChunkyPNG::Point(
|
67
|
-
ChunkyPNG::Point(
|
63
|
+
ChunkyPNG::Point("1,2"),
|
64
|
+
ChunkyPNG::Point("1 2"),
|
65
|
+
ChunkyPNG::Point("(1 , 2)"),
|
68
66
|
ChunkyPNG::Point("{1,\t2}"),
|
69
67
|
ChunkyPNG::Point("[1 2}"),
|
70
68
|
].all? { |point| point == subject }
|
@@ -1,23 +1,22 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
begin
|
4
|
-
require
|
4
|
+
require "chunky_png/rmagick"
|
5
5
|
|
6
6
|
describe ChunkyPNG::RMagick do
|
7
|
-
|
8
7
|
it "should import an image from RMagick correctly" do
|
9
|
-
image = Magick::Image.read(resource_file(
|
8
|
+
image = Magick::Image.read(resource_file("composited.png")).first
|
10
9
|
canvas = ChunkyPNG::RMagick.import(image)
|
11
|
-
expect(canvas).to eql reference_canvas(
|
10
|
+
expect(canvas).to eql reference_canvas("composited")
|
12
11
|
end
|
13
12
|
|
14
13
|
it "should export an image to RMagick correctly" do
|
15
|
-
canvas = reference_canvas(
|
14
|
+
canvas = reference_canvas("composited")
|
16
15
|
image = ChunkyPNG::RMagick.export(canvas)
|
17
|
-
image.format =
|
16
|
+
image.format = "PNG32"
|
18
17
|
expect(canvas).to eql ChunkyPNG::Canvas.from_blob(image.to_blob)
|
19
18
|
end
|
20
19
|
end
|
21
|
-
rescue LoadError
|
20
|
+
rescue LoadError
|
22
21
|
# skipping RMagick tests
|
23
22
|
end
|
@@ -1,17 +1,17 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe ChunkyPNG::Vector do
|
4
4
|
subject { ChunkyPNG::Vector.new([ChunkyPNG::Point.new(2, 5), ChunkyPNG::Point.new(1, 3), ChunkyPNG::Point.new(4, 6)]) }
|
5
5
|
|
6
6
|
it { should respond_to(:points) }
|
7
7
|
|
8
|
-
describe
|
8
|
+
describe "#length" do
|
9
9
|
it "shopuld have 3 items" do
|
10
10
|
expect(subject.length).to eql(3)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
describe
|
14
|
+
describe "#x_range" do
|
15
15
|
it "should get the right range of x values" do
|
16
16
|
expect(subject.x_range).to eql(1..4)
|
17
17
|
end
|
@@ -29,7 +29,7 @@ describe ChunkyPNG::Vector do
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
describe
|
32
|
+
describe "#y_range" do
|
33
33
|
it "should get the right range of y values" do
|
34
34
|
expect(subject.y_range).to eql(3..6)
|
35
35
|
end
|
@@ -47,7 +47,7 @@ describe ChunkyPNG::Vector do
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
describe
|
50
|
+
describe "#offset" do
|
51
51
|
it "should return a ChunkyPNG::Point" do
|
52
52
|
expect(subject.offset).to be_kind_of(ChunkyPNG::Point)
|
53
53
|
end
|
@@ -58,7 +58,7 @@ describe ChunkyPNG::Vector do
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
describe
|
61
|
+
describe "#dimension" do
|
62
62
|
it "should return a ChunkyPNG::Dimension" do
|
63
63
|
expect(subject.dimension).to be_kind_of(ChunkyPNG::Dimension)
|
64
64
|
end
|
@@ -69,26 +69,30 @@ describe ChunkyPNG::Vector do
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
|
-
describe
|
72
|
+
describe "#edges" do
|
73
73
|
it "should get three edges when closing the path" do
|
74
|
-
expect(subject.edges(true).to_a).to eql [
|
75
|
-
|
76
|
-
|
74
|
+
expect(subject.edges(true).to_a).to eql [
|
75
|
+
[ChunkyPNG::Point.new(2, 5), ChunkyPNG::Point.new(1, 3)],
|
76
|
+
[ChunkyPNG::Point.new(1, 3), ChunkyPNG::Point.new(4, 6)],
|
77
|
+
[ChunkyPNG::Point.new(4, 6), ChunkyPNG::Point.new(2, 5)],
|
78
|
+
]
|
77
79
|
end
|
78
80
|
|
79
81
|
it "should get two edges when not closing the path" do
|
80
|
-
expect(subject.edges(false).to_a).to eql [
|
81
|
-
|
82
|
+
expect(subject.edges(false).to_a).to eql [
|
83
|
+
[ChunkyPNG::Point.new(2, 5), ChunkyPNG::Point.new(1, 3)],
|
84
|
+
[ChunkyPNG::Point.new(1, 3), ChunkyPNG::Point.new(4, 6)],
|
85
|
+
]
|
82
86
|
end
|
83
87
|
end
|
84
88
|
end
|
85
89
|
|
86
|
-
describe
|
90
|
+
describe "ChunkyPNG.Vector" do
|
87
91
|
let(:example) { ChunkyPNG::Vector.new([ChunkyPNG::Point.new(2, 4), ChunkyPNG::Point.new(1, 2), ChunkyPNG::Point.new(3, 6)]) }
|
88
92
|
|
89
93
|
it "should return an empty vector when given an empty array" do
|
90
94
|
expect(ChunkyPNG::Vector()).to eql ChunkyPNG::Vector.new([])
|
91
|
-
expect(ChunkyPNG::Vector(*[])).to eql ChunkyPNG::Vector.new([])
|
95
|
+
expect(ChunkyPNG::Vector(*[])).to eql ChunkyPNG::Vector.new([]) # rubocop:disable Lint/UnneededSplatExpansion
|
92
96
|
end
|
93
97
|
|
94
98
|
it "should raise an error when an odd number of numerics is given" do
|
@@ -96,14 +100,14 @@ describe 'ChunkyPNG.Vector' do
|
|
96
100
|
end
|
97
101
|
|
98
102
|
it "should create a vector from a string" do
|
99
|
-
expect(ChunkyPNG::Vector(
|
103
|
+
expect(ChunkyPNG::Vector("(2,4) (1,2) (3,6)")).to eql example
|
100
104
|
end
|
101
105
|
|
102
106
|
it "should create a vector from a flat array" do
|
103
|
-
expect(ChunkyPNG::Vector(2,4,1,2,3,6)).to eql example
|
107
|
+
expect(ChunkyPNG::Vector(2, 4, 1, 2, 3, 6)).to eql example
|
104
108
|
end
|
105
109
|
|
106
110
|
it "should create a vector from a nested array" do
|
107
|
-
expect(ChunkyPNG::Vector(
|
111
|
+
expect(ChunkyPNG::Vector("(2,4)", [1, 2], x: 3, y: 6)).to eql example
|
108
112
|
end
|
109
113
|
end
|