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
data/spec/chunky_png_spec.rb
CHANGED
data/spec/png_suite_spec.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
|
-
describe
|
4
|
-
|
5
|
-
context 'Decoding broken images' do
|
3
|
+
describe "PNG testuite" do
|
4
|
+
context "Decoding broken images" do
|
6
5
|
png_suite_files(:broken).each do |file|
|
7
6
|
it "should report #{File.basename(file)} as broken" do
|
8
7
|
expect { ChunkyPNG::Image.from_file(file) }.to raise_error(ChunkyPNG::Exception)
|
@@ -10,24 +9,22 @@ describe 'PNG testuite' do
|
|
10
9
|
end
|
11
10
|
end
|
12
11
|
|
13
|
-
context
|
14
|
-
png_suite_files(:basic,
|
15
|
-
|
16
|
-
reference = file.sub(/\.png$/, '.rgba')
|
12
|
+
context "Decoding supported images" do
|
13
|
+
png_suite_files(:basic, "*.png").each do |file|
|
14
|
+
reference = file.sub(/\.png$/, ".rgba")
|
17
15
|
color_mode = file.match(/[in](\d)[apgc](\d\d)\.png$/)[1].to_i
|
18
16
|
bit_depth = file.match(/[in](\d)[apgc](\d\d)\.png$/)[2].to_i
|
19
17
|
|
20
18
|
it "should decode #{File.basename(file)} (color mode: #{color_mode}, bit depth: #{bit_depth}) exactly the same as the reference image" do
|
21
19
|
decoded = ChunkyPNG::Canvas.from_file(file)
|
22
|
-
|
20
|
+
expect(decoded.to_rgba_stream).to eql(File.read(reference, mode: "rb"))
|
23
21
|
end
|
24
22
|
end
|
25
23
|
end
|
26
24
|
|
27
|
-
context
|
28
|
-
|
25
|
+
context "Decoding text chunks" do
|
29
26
|
it "should not find metadata in a file without text chunks" do
|
30
|
-
image = ChunkyPNG::Image.from_file(png_suite_file(:metadata,
|
27
|
+
image = ChunkyPNG::Image.from_file(png_suite_file(:metadata, "cm0n0g04.png"))
|
31
28
|
expect(image.metadata).to be_empty
|
32
29
|
end
|
33
30
|
|
@@ -42,10 +39,9 @@ describe 'PNG testuite' do
|
|
42
39
|
# end
|
43
40
|
end
|
44
41
|
|
45
|
-
context
|
46
|
-
png_suite_files(:filtering,
|
47
|
-
|
48
|
-
file = reference_file.sub(/_reference\.png$/, '.png')
|
42
|
+
context "Decoding filter methods" do
|
43
|
+
png_suite_files(:filtering, "*_reference.png").each do |reference_file|
|
44
|
+
file = reference_file.sub(/_reference\.png$/, ".png")
|
49
45
|
filter_method = file.match(/f(\d\d)[a-z0-9]+\.png/)[1].to_i
|
50
46
|
|
51
47
|
it "should decode #{File.basename(file)} (filter method: #{filter_method}) exactly the same as the reference image" do
|
@@ -56,54 +52,53 @@ describe 'PNG testuite' do
|
|
56
52
|
end
|
57
53
|
end
|
58
54
|
|
59
|
-
context
|
55
|
+
context "Decoding different chunk splits" do
|
60
56
|
it "should decode grayscale images successfully regardless of the data chunk ordering and splitting" do
|
61
|
-
reference = ChunkyPNG::Datastream.from_file(png_suite_file(:chunk_ordering,
|
62
|
-
expect(ChunkyPNG::Datastream.from_file(png_suite_file(:chunk_ordering,
|
63
|
-
expect(ChunkyPNG::Datastream.from_file(png_suite_file(:chunk_ordering,
|
64
|
-
expect(ChunkyPNG::Datastream.from_file(png_suite_file(:chunk_ordering,
|
57
|
+
reference = ChunkyPNG::Datastream.from_file(png_suite_file(:chunk_ordering, "oi1n0g16.png")).imagedata
|
58
|
+
expect(ChunkyPNG::Datastream.from_file(png_suite_file(:chunk_ordering, "oi2n0g16.png")).imagedata).to eql reference
|
59
|
+
expect(ChunkyPNG::Datastream.from_file(png_suite_file(:chunk_ordering, "oi4n0g16.png")).imagedata).to eql reference
|
60
|
+
expect(ChunkyPNG::Datastream.from_file(png_suite_file(:chunk_ordering, "oi9n0g16.png")).imagedata).to eql reference
|
65
61
|
end
|
66
62
|
|
67
63
|
it "should decode color images successfully regardless of the data chunk ordering and splitting" do
|
68
|
-
reference = ChunkyPNG::Datastream.from_file(png_suite_file(:chunk_ordering,
|
69
|
-
expect(ChunkyPNG::Datastream.from_file(png_suite_file(:chunk_ordering,
|
70
|
-
expect(ChunkyPNG::Datastream.from_file(png_suite_file(:chunk_ordering,
|
71
|
-
expect(ChunkyPNG::Datastream.from_file(png_suite_file(:chunk_ordering,
|
64
|
+
reference = ChunkyPNG::Datastream.from_file(png_suite_file(:chunk_ordering, "oi1n2c16.png")).imagedata
|
65
|
+
expect(ChunkyPNG::Datastream.from_file(png_suite_file(:chunk_ordering, "oi2n2c16.png")).imagedata).to eql reference
|
66
|
+
expect(ChunkyPNG::Datastream.from_file(png_suite_file(:chunk_ordering, "oi4n2c16.png")).imagedata).to eql reference
|
67
|
+
expect(ChunkyPNG::Datastream.from_file(png_suite_file(:chunk_ordering, "oi9n2c16.png")).imagedata).to eql reference
|
72
68
|
end
|
73
69
|
end
|
74
70
|
|
75
|
-
context
|
71
|
+
context "Decoding different compression levels" do
|
76
72
|
it "should decode the image successfully regardless of the compression level" do
|
77
|
-
reference = ChunkyPNG::Datastream.from_file(png_suite_file(:compression_levels,
|
78
|
-
expect(ChunkyPNG::Datastream.from_file(png_suite_file(:compression_levels,
|
79
|
-
expect(ChunkyPNG::Datastream.from_file(png_suite_file(:compression_levels,
|
80
|
-
expect(ChunkyPNG::Datastream.from_file(png_suite_file(:compression_levels,
|
73
|
+
reference = ChunkyPNG::Datastream.from_file(png_suite_file(:compression_levels, "z00n2c08.png")).imagedata
|
74
|
+
expect(ChunkyPNG::Datastream.from_file(png_suite_file(:compression_levels, "z03n2c08.png")).imagedata).to eql reference
|
75
|
+
expect(ChunkyPNG::Datastream.from_file(png_suite_file(:compression_levels, "z06n2c08.png")).imagedata).to eql reference
|
76
|
+
expect(ChunkyPNG::Datastream.from_file(png_suite_file(:compression_levels, "z09n2c08.png")).imagedata).to eql reference
|
81
77
|
end
|
82
78
|
end
|
83
79
|
|
84
|
-
context
|
85
|
-
png_suite_files(:transparency,
|
80
|
+
context "Decoding transparency" do
|
81
|
+
png_suite_files(:transparency, "tp0*.png").each do |file|
|
86
82
|
it "should not have transparency in #{File.basename(file)}" do
|
87
|
-
expect(ChunkyPNG::Color.a(ChunkyPNG::Image.from_file(file)[0,0])).to eql 255
|
83
|
+
expect(ChunkyPNG::Color.a(ChunkyPNG::Image.from_file(file)[0, 0])).to eql 255
|
88
84
|
end
|
89
85
|
end
|
90
86
|
|
91
|
-
png_suite_files(:transparency,
|
87
|
+
png_suite_files(:transparency, "tp1*.png").each do |file|
|
92
88
|
it "should have transparency in #{File.basename(file)}" do
|
93
|
-
expect(ChunkyPNG::Color.a(ChunkyPNG::Image.from_file(file)[0,0])).to eql 0
|
89
|
+
expect(ChunkyPNG::Color.a(ChunkyPNG::Image.from_file(file)[0, 0])).to eql 0
|
94
90
|
end
|
95
91
|
end
|
96
92
|
|
97
|
-
png_suite_files(:transparency,
|
93
|
+
png_suite_files(:transparency, "tb*.png").each do |file|
|
98
94
|
it "should have transparency in #{File.basename(file)}" do
|
99
|
-
expect(ChunkyPNG::Color.a(ChunkyPNG::Image.from_file(file)[0,0])).to eql 0
|
95
|
+
expect(ChunkyPNG::Color.a(ChunkyPNG::Image.from_file(file)[0, 0])).to eql 0
|
100
96
|
end
|
101
97
|
end
|
102
98
|
end
|
103
99
|
|
104
|
-
context
|
105
|
-
|
106
|
-
png_suite_files(:sizes, '*n*.png').each do |file|
|
100
|
+
context "Decoding different sizes" do
|
101
|
+
png_suite_files(:sizes, "*n*.png").each do |file|
|
107
102
|
dimension = file.match(/s(\d\d)n\dp\d\d/)[1].to_i
|
108
103
|
|
109
104
|
it "should create a canvas with a #{dimension}x#{dimension} size" do
|
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "rubygems"
|
2
|
+
require "bundler/setup"
|
3
|
+
require "chunky_png"
|
4
4
|
|
5
5
|
module PNGSuite
|
6
|
-
|
7
6
|
def png_suite_file(kind, file)
|
8
7
|
File.join(png_suite_dir(kind), file)
|
9
8
|
end
|
@@ -12,21 +11,19 @@ module PNGSuite
|
|
12
11
|
File.expand_path("./png_suite/#{kind}", File.dirname(__FILE__))
|
13
12
|
end
|
14
13
|
|
15
|
-
def png_suite_files(kind, pattern =
|
14
|
+
def png_suite_files(kind, pattern = "*.png")
|
16
15
|
Dir[File.join(png_suite_dir(kind), pattern)]
|
17
16
|
end
|
18
17
|
end
|
19
18
|
|
20
|
-
|
21
19
|
module ResourceFileHelper
|
22
|
-
|
23
20
|
def resource_file(name)
|
24
21
|
File.expand_path("./resources/#{name}", File.dirname(__FILE__))
|
25
22
|
end
|
26
23
|
|
27
24
|
def resource_data(name)
|
28
25
|
data = nil
|
29
|
-
File.open(resource_file(name),
|
26
|
+
File.open(resource_file(name), "rb") { |f| data = f.read }
|
30
27
|
data
|
31
28
|
end
|
32
29
|
|
@@ -39,14 +36,13 @@ module ResourceFileHelper
|
|
39
36
|
end
|
40
37
|
|
41
38
|
def display(png)
|
42
|
-
filename = resource_file(
|
39
|
+
filename = resource_file("_tmp.png")
|
43
40
|
png.save(filename)
|
44
41
|
`open #{filename}`
|
45
42
|
end
|
46
43
|
end
|
47
44
|
|
48
45
|
module ChunkOperationsHelper
|
49
|
-
|
50
46
|
def serialized_chunk(chunk)
|
51
47
|
chunk.write(stream = StringIO.new)
|
52
48
|
stream.rewind
|
data/tasks/benchmarks.rake
CHANGED
@@ -1,24 +1,23 @@
|
|
1
1
|
all_benchamrk_tasks = []
|
2
2
|
|
3
3
|
namespace(:benchmark) do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
Dir[File.join(File.dirname(__FILE__), "..", "benchmarks", "*_benchmark.rb")]. each do |benchmark_file|
|
5
|
+
task_name = File.basename(benchmark_file, "_benchmark.rb").to_sym
|
6
|
+
|
8
7
|
desc "Run the #{task_name} benchmark."
|
9
8
|
task(task_name, :n) do |task, args|
|
10
|
-
ENV[
|
9
|
+
ENV["N"] = args[:n] if args[:n]
|
11
10
|
load(File.expand_path(benchmark_file))
|
12
11
|
end
|
13
|
-
|
12
|
+
|
14
13
|
all_benchamrk_tasks << "benchmark:#{task_name}"
|
15
14
|
end
|
16
15
|
end
|
17
16
|
|
18
17
|
unless all_benchamrk_tasks.empty?
|
19
|
-
desc
|
18
|
+
desc "Run the whole benchmark suite"
|
20
19
|
task(:benchmark, :n) do |task, args|
|
21
|
-
all_benchamrk_tasks.each do |t|
|
20
|
+
all_benchamrk_tasks.each do |t|
|
22
21
|
task(t).invoke(args[:n])
|
23
22
|
puts
|
24
23
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chunky_png
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Willem van Bergen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -24,6 +24,34 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: standard
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: yard
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.9'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.9'
|
27
55
|
- !ruby/object:Gem::Dependency
|
28
56
|
name: rspec
|
29
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +94,7 @@ extra_rdoc_files:
|
|
66
94
|
- CHANGELOG.rdoc
|
67
95
|
files:
|
68
96
|
- ".gitignore"
|
97
|
+
- ".standard.yml"
|
69
98
|
- ".travis.yml"
|
70
99
|
- ".yardopts"
|
71
100
|
- BENCHMARKING.rdoc
|
@@ -78,6 +107,8 @@ files:
|
|
78
107
|
- benchmarks/decoding_benchmark.rb
|
79
108
|
- benchmarks/encoding_benchmark.rb
|
80
109
|
- benchmarks/filesize_benchmark.rb
|
110
|
+
- bin/rake
|
111
|
+
- bin/standardrb
|
81
112
|
- chunky_png.gemspec
|
82
113
|
- lib/chunky_png.rb
|
83
114
|
- lib/chunky_png/canvas.rb
|
@@ -94,7 +125,6 @@ files:
|
|
94
125
|
- lib/chunky_png/canvas/stream_importing.rb
|
95
126
|
- lib/chunky_png/chunk.rb
|
96
127
|
- lib/chunky_png/color.rb
|
97
|
-
- lib/chunky_png/compatibility.rb
|
98
128
|
- lib/chunky_png/datastream.rb
|
99
129
|
- lib/chunky_png/dimension.rb
|
100
130
|
- lib/chunky_png/image.rb
|
@@ -416,8 +446,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
416
446
|
- !ruby/object:Gem::Version
|
417
447
|
version: '0'
|
418
448
|
requirements: []
|
419
|
-
|
420
|
-
rubygems_version: 2.5.2.3
|
449
|
+
rubygems_version: 3.0.3
|
421
450
|
signing_key:
|
422
451
|
specification_version: 4
|
423
452
|
summary: Pure ruby library for read/write, chunk-level access to PNG files
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# Define the byte-operators on a string if they're not defined (Ruby 1.8)
|
2
|
-
|
3
|
-
class String
|
4
|
-
alias_method :getbyte, :[] unless method_defined?(:getbyte)
|
5
|
-
alias_method :setbyte, :[]= unless method_defined?(:setbyte)
|
6
|
-
alias_method :bytesize, :size unless method_defined?(:bytesize)
|
7
|
-
end
|
8
|
-
|
9
|
-
module Enumerable
|
10
|
-
unless method_defined?(:minmax)
|
11
|
-
def minmax
|
12
|
-
[min, max]
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|