sugar_png 0.0.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -1
- data/Gemfile.lock +4 -4
- data/README.md +105 -0
- data/README.md.tpl +99 -0
- data/Rakefile +41 -6
- data/VERSION +1 -1
- data/data/1-dump-hex.rb +22 -0
- data/data/2-marshal-test.rb +22 -0
- data/data/3-hex2marshal.rb +71 -0
- data/data/font/00 +0 -0
- data/data/font/01 +0 -0
- data/data/font/02 +0 -0
- data/data/font/03 +0 -0
- data/data/font/04 +0 -0
- data/data/font/05 +0 -0
- data/data/font/06 +0 -0
- data/data/font/07 +0 -0
- data/data/font/09 +0 -0
- data/data/font/0a +0 -0
- data/data/font/0b +0 -0
- data/data/font/0c +0 -0
- data/data/font/0d +0 -0
- data/data/font/0e +0 -0
- data/data/font/0f +0 -0
- data/data/font/10 +0 -0
- data/data/font/11 +0 -0
- data/data/font/12 +0 -0
- data/data/font/13 +0 -0
- data/data/font/14 +0 -0
- data/data/font/15 +0 -0
- data/data/font/16 +0 -0
- data/data/font/17 +0 -0
- data/data/font/18 +0 -0
- data/data/font/19 +0 -0
- data/data/font/1a +0 -0
- data/data/font/1b +0 -0
- data/data/font/1c +0 -0
- data/data/font/1d +0 -0
- data/data/font/1e +0 -0
- data/data/font/1f +0 -0
- data/data/font/20 +0 -0
- data/data/font/21 +0 -0
- data/data/font/22 +0 -0
- data/data/font/23 +0 -0
- data/data/font/24 +0 -0
- data/data/font/25 +0 -0
- data/data/font/26 +0 -0
- data/data/font/27 +0 -0
- data/data/font/28 +0 -0
- data/data/font/29 +0 -0
- data/data/font/2a +0 -0
- data/data/font/2b +0 -0
- data/data/font/2c +0 -0
- data/data/font/2d +0 -0
- data/data/font/2e +0 -0
- data/data/font/2f +0 -0
- data/data/font/30 +0 -0
- data/data/font/31 +0 -0
- data/data/font/32 +0 -0
- data/data/font/33 +0 -0
- data/data/font/34 +0 -0
- data/data/font/35 +0 -0
- data/data/font/36 +0 -0
- data/data/font/37 +0 -0
- data/data/font/38 +0 -0
- data/data/font/39 +0 -0
- data/data/font/3a +0 -0
- data/data/font/3b +0 -0
- data/data/font/3c +0 -0
- data/data/font/3d +0 -0
- data/data/font/3e +0 -0
- data/data/font/3f +0 -0
- data/data/font/40 +0 -0
- data/data/font/41 +0 -0
- data/data/font/42 +0 -0
- data/data/font/43 +0 -0
- data/data/font/44 +0 -0
- data/data/font/45 +0 -0
- data/data/font/46 +0 -0
- data/data/font/47 +0 -0
- data/data/font/48 +0 -0
- data/data/font/49 +0 -0
- data/data/font/4a +0 -0
- data/data/font/4b +0 -0
- data/data/font/4c +0 -0
- data/data/font/4d +0 -0
- data/data/font/4e +0 -0
- data/data/font/4f +0 -0
- data/data/font/50 +0 -0
- data/data/font/51 +0 -0
- data/data/font/52 +0 -0
- data/data/font/53 +0 -0
- data/data/font/54 +0 -0
- data/data/font/55 +0 -0
- data/data/font/56 +0 -0
- data/data/font/57 +0 -0
- data/data/font/58 +0 -0
- data/data/font/59 +0 -0
- data/data/font/5a +0 -0
- data/data/font/5b +0 -0
- data/data/font/5c +0 -0
- data/data/font/5d +0 -0
- data/data/font/5e +0 -0
- data/data/font/5f +0 -0
- data/data/font/60 +0 -0
- data/data/font/61 +0 -0
- data/data/font/62 +0 -0
- data/data/font/63 +0 -0
- data/data/font/64 +0 -0
- data/data/font/65 +0 -0
- data/data/font/66 +0 -0
- data/data/font/67 +0 -0
- data/data/font/68 +0 -0
- data/data/font/69 +0 -0
- data/data/font/6a +0 -0
- data/data/font/6b +0 -0
- data/data/font/6c +0 -0
- data/data/font/6d +0 -0
- data/data/font/6e +0 -0
- data/data/font/6f +0 -0
- data/data/font/70 +0 -0
- data/data/font/71 +0 -0
- data/data/font/72 +0 -0
- data/data/font/73 +0 -0
- data/data/font/74 +0 -0
- data/data/font/75 +0 -0
- data/data/font/76 +0 -0
- data/data/font/77 +0 -0
- data/data/font/78 +0 -0
- data/data/font/79 +0 -0
- data/data/font/7a +0 -0
- data/data/font/7b +0 -0
- data/data/font/7c +0 -0
- data/data/font/7d +0 -0
- data/data/font/7e +0 -0
- data/data/font/7f +0 -0
- data/data/font/80 +0 -0
- data/data/font/81 +0 -0
- data/data/font/82 +0 -0
- data/data/font/83 +0 -0
- data/data/font/84 +0 -0
- data/data/font/85 +0 -0
- data/data/font/86 +0 -0
- data/data/font/87 +0 -0
- data/data/font/88 +0 -0
- data/data/font/89 +0 -0
- data/data/font/8a +0 -0
- data/data/font/8b +0 -0
- data/data/font/8c +0 -0
- data/data/font/8d +0 -0
- data/data/font/8e +0 -0
- data/data/font/8f +0 -0
- data/data/font/90 +0 -0
- data/data/font/91 +0 -0
- data/data/font/92 +0 -0
- data/data/font/93 +0 -0
- data/data/font/94 +0 -0
- data/data/font/95 +0 -0
- data/data/font/96 +0 -0
- data/data/font/97 +0 -0
- data/data/font/98 +0 -0
- data/data/font/99 +0 -0
- data/data/font/9a +0 -0
- data/data/font/9b +0 -0
- data/data/font/9c +0 -0
- data/data/font/9d +0 -0
- data/data/font/9e +0 -0
- data/data/font/9f +0 -0
- data/data/font/a0 +0 -0
- data/data/font/a1 +0 -0
- data/data/font/a2 +0 -0
- data/data/font/a3 +0 -0
- data/data/font/a4 +0 -0
- data/data/font/a5 +0 -0
- data/data/font/a6 +0 -0
- data/data/font/a7 +0 -0
- data/data/font/a8 +0 -0
- data/data/font/a9 +0 -0
- data/data/font/aa +0 -0
- data/data/font/ac +0 -0
- data/data/font/ad +0 -0
- data/data/font/ae +0 -0
- data/data/font/af +0 -0
- data/data/font/b0 +0 -0
- data/data/font/b1 +0 -0
- data/data/font/b2 +0 -0
- data/data/font/b3 +0 -0
- data/data/font/b4 +0 -0
- data/data/font/b5 +0 -0
- data/data/font/b6 +0 -0
- data/data/font/b7 +0 -0
- data/data/font/b8 +0 -0
- data/data/font/b9 +0 -0
- data/data/font/ba +0 -0
- data/data/font/bb +0 -0
- data/data/font/bc +0 -0
- data/data/font/bd +0 -0
- data/data/font/be +0 -0
- data/data/font/bf +0 -0
- data/data/font/c0 +0 -0
- data/data/font/c1 +0 -0
- data/data/font/c2 +0 -0
- data/data/font/c3 +0 -0
- data/data/font/c4 +0 -0
- data/data/font/c5 +0 -0
- data/data/font/c6 +0 -0
- data/data/font/c7 +0 -0
- data/data/font/c8 +0 -0
- data/data/font/c9 +0 -0
- data/data/font/ca +0 -0
- data/data/font/cb +0 -0
- data/data/font/cc +0 -0
- data/data/font/cd +0 -0
- data/data/font/ce +0 -0
- data/data/font/cf +0 -0
- data/data/font/d0 +0 -0
- data/data/font/d1 +0 -0
- data/data/font/d2 +0 -0
- data/data/font/d3 +0 -0
- data/data/font/d4 +0 -0
- data/data/font/d5 +0 -0
- data/data/font/d6 +0 -0
- data/data/font/d7 +0 -0
- data/data/font/f9 +0 -0
- data/data/font/fa +0 -0
- data/data/font/fb +0 -0
- data/data/font/fc +0 -0
- data/data/font/fd +0 -0
- data/data/font/fe +0 -0
- data/data/font/ff +0 -0
- data/data/unifont-5.1.20080820.7z +0 -0
- data/data/unused-4-read-tar.rb +49 -0
- data/lib/sugar_png.rb +164 -2
- data/lib/sugar_png/border.rb +20 -0
- data/lib/sugar_png/color.rb +118 -0
- data/lib/sugar_png/datastream.rb +2 -17
- data/lib/sugar_png/dyn_accessor.rb +28 -0
- data/lib/sugar_png/font.rb +44 -0
- data/lib/sugar_png/glyph.rb +36 -0
- data/lib/sugar_png/image.rb +104 -0
- data/samples/damaged_chunk.png +0 -0
- data/samples/png_suite/f00n0g08_reference.png +0 -0
- data/samples/png_suite/f00n2c08_reference.png +0 -0
- data/samples/png_suite/f01n0g08_reference.png +0 -0
- data/samples/png_suite/f01n2c08_reference.png +0 -0
- data/samples/png_suite/f02n0g08_reference.png +0 -0
- data/samples/png_suite/f02n2c08_reference.png +0 -0
- data/samples/png_suite/f03n0g08_reference.png +0 -0
- data/samples/png_suite/f03n2c08_reference.png +0 -0
- data/samples/png_suite/f04n0g08_reference.png +0 -0
- data/samples/png_suite/f04n2c08_reference.png +0 -0
- data/samples/readme/explicit_image_dimensions_bg_color.png +0 -0
- data/samples/readme/hello_world.png +0 -0
- data/samples/readme/japanese_text_with_rainbow_borders_zoomed_4x.png +0 -0
- data/samples/readme/pixels_can_be_set_using_ranges_enumerators_arrays.png +0 -0
- data/samples/readme/playing_with_transparency_16_bit_color_depth.png +0 -0
- data/samples/readme/white_noise.png +0 -0
- data/samples/rgba.tar.bz2 +0 -0
- data/samples/text_chunk.png +0 -0
- data/samples/ztxt_chunk.png +0 -0
- data/spec/color_spec.rb +81 -0
- data/spec/font_spec.rb +82 -0
- data/spec/magic/border_spec.rb +49 -0
- data/spec/magic/create_spec.rb +42 -0
- data/spec/magic/pixels_spec.rb +73 -0
- data/spec/magic/text_spec.rb +113 -0
- data/spec/magic/zoom_spec.rb +38 -0
- data/spec/png_suite_spec.rb +145 -0
- data/spec/spec_helper.rb +43 -1
- data/spec/sugar_png/datastream_spec.rb +32 -0
- data/spec/support/png_suite.rb +43 -0
- data/sugar_png.gemspec +275 -6
- metadata +287 -5
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SugarPNG do
|
4
|
+
describe "zoom" do
|
5
|
+
it "zooms 1x1 => 2x2" do
|
6
|
+
SugarPNG.new do |img|
|
7
|
+
img[0,0] = ZPNG::Color::RED
|
8
|
+
img.zoom = 2
|
9
|
+
|
10
|
+
img = ZPNG::Image.new(img.to_s)
|
11
|
+
img.width.should == 2
|
12
|
+
img.height.should == 2
|
13
|
+
img.pixels.each do |c|
|
14
|
+
c.should == ZPNG::Color::RED
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it "zooms 2x1 => 4x2" do
|
20
|
+
SugarPNG.new do |img|
|
21
|
+
img[0,0] = ZPNG::Color::RED
|
22
|
+
img[1,0] = ZPNG::Color::GREEN
|
23
|
+
img.zoom = 2
|
24
|
+
|
25
|
+
img = ZPNG::Image.new(img.to_s)
|
26
|
+
img.width.should == 4
|
27
|
+
img.height.should == 2
|
28
|
+
img.each_pixel do |c,x,y|
|
29
|
+
if x < 2
|
30
|
+
c.should == ZPNG::Color::RED
|
31
|
+
else
|
32
|
+
c.should == ZPNG::Color::GREEN
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'PNG testsuite' do
|
4
|
+
|
5
|
+
# context 'Decoding broken images' do
|
6
|
+
# png_suite_files(:broken).each do |fname|
|
7
|
+
# it "should report #{File.basename(fname)} as broken" do
|
8
|
+
# lambda { SugarPNG::Image.from_file(fname) }.should raise_error(SugarPNG::Exception)
|
9
|
+
# end
|
10
|
+
#
|
11
|
+
# it "should not report #{File.basename(fname)} as unsupported" do
|
12
|
+
# lambda { SugarPNG::Image.from_file(fname) }.should_not raise_error(SugarPNG::NotSupported)
|
13
|
+
# end
|
14
|
+
# end
|
15
|
+
# end
|
16
|
+
|
17
|
+
context 'Decoding supported images' do
|
18
|
+
png_suite_files(:basic, '*.png').each do |fname|
|
19
|
+
|
20
|
+
reference = rgba_for(fname)
|
21
|
+
if fname =~ /[in](\d)[apgc](\d\d)\.png$/
|
22
|
+
color_mode, bit_depth = $1.to_i, $2.to_i
|
23
|
+
else
|
24
|
+
next
|
25
|
+
end
|
26
|
+
|
27
|
+
it "decodes #{File.basename(fname)} (color mode: #{color_mode}, bit depth: #{bit_depth}) exactly the same as the reference image" do
|
28
|
+
decoded = SugarPNG::Canvas.from_file(fname)
|
29
|
+
File.open(reference, 'rb') do |f|
|
30
|
+
if decoded.to_rgba_stream != f.read
|
31
|
+
File.open(reference+".my", 'wb') { |fo| fo<<decoded.to_rgba_stream }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
File.open(reference, 'rb') { |f| decoded.to_rgba_stream.should == f.read }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'Decoding text chunks' do
|
40
|
+
|
41
|
+
it "should not find metadata in a file without text chunks" do
|
42
|
+
image = SugarPNG::Image.from_file(png_suite_file(:metadata, 'cm0n0g04.png'))
|
43
|
+
image.metadata.should be_empty
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should find metadata in a file with uncompressed text chunks" do
|
47
|
+
image = SugarPNG::Image.from_file(png_suite_file(:metadata, 'ct1n0g04.png'))
|
48
|
+
image.metadata.should_not be_empty
|
49
|
+
image.metadata.size.should == 6 # zzz
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should find metadata in a file with compressed text chunks" do
|
53
|
+
image = SugarPNG::Image.from_file(png_suite_file(:metadata, 'ctzn0g04.png'))
|
54
|
+
image.metadata.should_not be_empty
|
55
|
+
image.metadata.size.should == 6 # zzz
|
56
|
+
end
|
57
|
+
|
58
|
+
%w'cten0g04.png ctfn0g04.png ctgn0g04.png cthn0g04.png ctjn0g04.png'.each do |fname|
|
59
|
+
it "should find metadata in a file with intl text chunks (#{fname})" do
|
60
|
+
image = SugarPNG::Image.from_file(png_suite_file(:metadata, fname))
|
61
|
+
image.metadata.should_not be_empty
|
62
|
+
image.metadata.size.should == 6 # zzz
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'Decoding filter methods' do
|
68
|
+
png_suite_files(:filtering, '*_reference.png').each do |reference_file|
|
69
|
+
fname = reference_file.sub(/_reference\.png$/, '.png')
|
70
|
+
filter_method = fname.match(/f(\d\d)[a-z0-9]+\.png/)[1].to_i
|
71
|
+
|
72
|
+
it "should decode #{File.basename(fname)} (filter method: #{filter_method}) exactly the same as the reference image" do
|
73
|
+
decoded = SugarPNG::Canvas.from_file(fname)
|
74
|
+
reference = SugarPNG::Canvas.from_file(reference_file)
|
75
|
+
decoded.should == reference
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context 'Decoding different chunk splits' do
|
81
|
+
it "should decode grayscale images successfully regardless of the data chunk ordering and splitting" do
|
82
|
+
reference = SugarPNG::Datastream.from_file(png_suite_file(:chunk_ordering, 'oi1n0g16.png')).imagedata
|
83
|
+
SugarPNG::Datastream.from_file(png_suite_file(:chunk_ordering, 'oi2n0g16.png')).imagedata.should == reference
|
84
|
+
SugarPNG::Datastream.from_file(png_suite_file(:chunk_ordering, 'oi4n0g16.png')).imagedata.should == reference
|
85
|
+
SugarPNG::Datastream.from_file(png_suite_file(:chunk_ordering, 'oi9n0g16.png')).imagedata.should == reference
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should decode color images successfully regardless of the data chunk ordering and splitting" do
|
89
|
+
reference = SugarPNG::Datastream.from_file(png_suite_file(:chunk_ordering, 'oi1n2c16.png')).imagedata
|
90
|
+
SugarPNG::Datastream.from_file(png_suite_file(:chunk_ordering, 'oi2n2c16.png')).imagedata.should == reference
|
91
|
+
SugarPNG::Datastream.from_file(png_suite_file(:chunk_ordering, 'oi4n2c16.png')).imagedata.should == reference
|
92
|
+
SugarPNG::Datastream.from_file(png_suite_file(:chunk_ordering, 'oi9n2c16.png')).imagedata.should == reference
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'Decoding different compression levels' do
|
97
|
+
it "should decode the image successfully regardless of the compression level" do
|
98
|
+
reference = SugarPNG::Datastream.from_file(png_suite_file(:compression_levels, 'z00n2c08.png')).imagedata
|
99
|
+
SugarPNG::Datastream.from_file(png_suite_file(:compression_levels, 'z03n2c08.png')).imagedata.should == reference
|
100
|
+
SugarPNG::Datastream.from_file(png_suite_file(:compression_levels, 'z06n2c08.png')).imagedata.should == reference
|
101
|
+
SugarPNG::Datastream.from_file(png_suite_file(:compression_levels, 'z09n2c08.png')).imagedata.should == reference
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context 'Decoding transparency' do
|
106
|
+
png_suite_files(:transparency, 'tp0*.png').each do |file|
|
107
|
+
it "should not have transparency in #{File.basename(file)}" do
|
108
|
+
SugarPNG::Color.a(SugarPNG::Image.from_file(file)[0,0]).should == 255
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
png_suite_files(:transparency, 'tp1*.png').each do |file|
|
113
|
+
it "should have transparency in #{File.basename(file)}" do
|
114
|
+
SugarPNG::Color.a(SugarPNG::Image.from_file(file)[0,0]).should == 0
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
png_suite_files(:transparency, 'tb*.png').each do |file|
|
119
|
+
it "should have transparency in #{File.basename(file)}" do
|
120
|
+
SugarPNG::Color.a(SugarPNG::Image.from_file(file)[0,0]).should == 0
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
context 'Decoding different sizes' do
|
126
|
+
png_suite_files(:sizes, '*n*.png').each do |fname|
|
127
|
+
if fname =~ /s(\d\d)n\dp\d\d/
|
128
|
+
dimension = $1.to_i
|
129
|
+
else
|
130
|
+
next
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should create a canvas with a #{dimension}x#{dimension} size" do
|
134
|
+
canvas = SugarPNG::Image.from_file(fname)
|
135
|
+
canvas.width.should == dimension
|
136
|
+
canvas.height.should == dimension
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should decode the #{dimension}x#{dimension} interlaced image exactly the same the non-interlaced version" do
|
140
|
+
interlaced_file = fname.sub(/n3p(\d\d)\.png$/, 'i3p\\1.png')
|
141
|
+
SugarPNG::Image.from_file(interlaced_file).should == SugarPNG::Image.from_file(fname)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -2,14 +2,54 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
2
2
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
3
|
require 'rspec'
|
4
4
|
require 'sugar_png'
|
5
|
+
require 'awesome_print'
|
5
6
|
|
6
7
|
# Requires supporting files with custom matchers and macros, etc,
|
7
8
|
# in ./support/ and its subdirectories.
|
8
9
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
10
|
|
11
|
+
SAMPLES_DIR = File.expand_path("../samples", File.dirname(__FILE__))
|
12
|
+
|
13
|
+
SAMPLES =
|
14
|
+
if ENV['SAMPLES']
|
15
|
+
ENV['SAMPLES'].split(' ')
|
16
|
+
else
|
17
|
+
Dir[File.join(SAMPLES_DIR,'qr_*.png')]
|
18
|
+
end
|
19
|
+
|
20
|
+
PNGSuite.init( File.join(SAMPLES_DIR, "png_suite") )
|
21
|
+
|
22
|
+
def png_suite_file(kind, file)
|
23
|
+
File.join(PNGSuite.dir, file)
|
24
|
+
end
|
25
|
+
|
26
|
+
def rgba_for fname
|
27
|
+
dir = File.expand_path "../samples/rgba", File.dirname(__FILE__)
|
28
|
+
unless Dir.exist?(dir)
|
29
|
+
system "tar", "xjf", dir+".tar.bz2", "-C", File.dirname(dir)
|
30
|
+
end
|
31
|
+
File.join( dir, File.basename(fname, ".png")) + ".rgba"
|
32
|
+
end
|
33
|
+
|
34
|
+
def png_suite_files(kind, pattern = "*.png")
|
35
|
+
kinds = {
|
36
|
+
:broken => "x*",
|
37
|
+
:basic => "bas*",
|
38
|
+
:filtering => "f*",
|
39
|
+
:transparency => "t[bp]*",
|
40
|
+
:sizes => "s*"
|
41
|
+
}
|
42
|
+
kind = kinds[kind] || raise("unknown kind: #{kind}")
|
43
|
+
|
44
|
+
a = Dir[File.join(PNGSuite.dir, pattern)]
|
45
|
+
a.keep_if{ |fname| File.fnmatch?(kind, File.basename(fname)) }
|
46
|
+
puts "[?] png_suite_files: no files for #{[kind, pattern].inspect}".yellow if a.empty?
|
47
|
+
a
|
48
|
+
end
|
49
|
+
|
10
50
|
module ResourceFileHelper
|
11
51
|
def resource_file(name)
|
12
|
-
File.expand_path("
|
52
|
+
File.expand_path("../samples/#{name}", File.dirname(__FILE__))
|
13
53
|
end
|
14
54
|
|
15
55
|
def resource_data(name)
|
@@ -20,5 +60,7 @@ module ResourceFileHelper
|
|
20
60
|
end
|
21
61
|
|
22
62
|
RSpec.configure do |config|
|
63
|
+
config.extend PNGSuite
|
64
|
+
config.include PNGSuite
|
23
65
|
config.include ResourceFileHelper
|
24
66
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SugarPNG::Datastream do
|
4
|
+
|
5
|
+
describe '.from_io'do
|
6
|
+
it "should raise an error when loading a file with a bad signature" do
|
7
|
+
filename = resource_file('damaged_signature.png')
|
8
|
+
lambda { SugarPNG::Datastream.from_file(filename) }.should raise_error
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should NOT raise an error if the CRC of a chunk is incorrect" do
|
12
|
+
filename = resource_file('damaged_chunk.png')
|
13
|
+
lambda { SugarPNG::Datastream.from_file(filename) }.should_not raise_error
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#metadata' do
|
18
|
+
it "should load uncompressed tXTt chunks correctly" do
|
19
|
+
filename = resource_file('text_chunk.png')
|
20
|
+
ds = SugarPNG::Datastream.from_file(filename)
|
21
|
+
ds.metadata['Title'].should == 'My amazing icon!'
|
22
|
+
ds.metadata['Author'].should == "Willem van Bergen"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should load compressed zTXt chunks correctly" do
|
26
|
+
filename = resource_file('ztxt_chunk.png')
|
27
|
+
ds = SugarPNG::Datastream.from_file(filename)
|
28
|
+
ds.metadata['Title'].should == 'PngSuite'
|
29
|
+
ds.metadata['Copyright'].should == "Copyright Willem van Schaik, Singapore 1995-96"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module PNGSuite
|
2
|
+
PNG_SUITE_URL = "http://www.schaik.com/pngsuite/PngSuite-2011apr25.tgz"
|
3
|
+
|
4
|
+
class << self
|
5
|
+
attr_accessor :dir
|
6
|
+
|
7
|
+
def init dir
|
8
|
+
@dir = dir
|
9
|
+
if Dir.exist?(dir)
|
10
|
+
if Dir[File.join(dir, "*.png")].size > 100
|
11
|
+
# already fetched and unpacked
|
12
|
+
return
|
13
|
+
end
|
14
|
+
else
|
15
|
+
Dir.mkdir(dir)
|
16
|
+
end
|
17
|
+
require 'open-uri'
|
18
|
+
puts "[.] fetching PNG test-suite from #{PNG_SUITE_URL} .. "
|
19
|
+
data = open(PNG_SUITE_URL).read
|
20
|
+
|
21
|
+
fname = File.join(dir, "png_suite.tgz")
|
22
|
+
File.open(fname, "wb"){ |f| f<<data }
|
23
|
+
puts "[.] unpacking .. "
|
24
|
+
system "tar", "xzf", fname, "-C", dir
|
25
|
+
end
|
26
|
+
|
27
|
+
def each *prefixes
|
28
|
+
Dir[File.join(dir,"*.png")].each do |fname|
|
29
|
+
if prefixes.empty?
|
30
|
+
yield fname
|
31
|
+
elsif prefixes.any?{ |p| p[/[*?\[]/] ? File.fnmatch(p, File.basename(fname)) : File.basename(fname).start_with?(p) }
|
32
|
+
yield fname
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def each_good
|
38
|
+
Dir[File.join(dir,"[^x]*.png")].each do |fname|
|
39
|
+
yield fname
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/sugar_png.gemspec
CHANGED
@@ -5,14 +5,16 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "sugar_png"
|
8
|
-
s.version = "0.0
|
8
|
+
s.version = "0.4.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Andrey \"Zed\" Zaikin"]
|
12
|
-
s.date = "
|
12
|
+
s.date = "2013-01-02"
|
13
13
|
s.email = "zed.0xff@gmail.com"
|
14
14
|
s.extra_rdoc_files = [
|
15
|
-
"LICENSE.txt"
|
15
|
+
"LICENSE.txt",
|
16
|
+
"README.md",
|
17
|
+
"README.md.tpl"
|
16
18
|
]
|
17
19
|
s.files = [
|
18
20
|
".document",
|
@@ -20,11 +22,275 @@ Gem::Specification.new do |s|
|
|
20
22
|
"Gemfile",
|
21
23
|
"Gemfile.lock",
|
22
24
|
"LICENSE.txt",
|
25
|
+
"README.md",
|
26
|
+
"README.md.tpl",
|
23
27
|
"Rakefile",
|
24
28
|
"VERSION",
|
29
|
+
"data/1-dump-hex.rb",
|
30
|
+
"data/2-marshal-test.rb",
|
31
|
+
"data/3-hex2marshal.rb",
|
32
|
+
"data/font/00",
|
33
|
+
"data/font/01",
|
34
|
+
"data/font/02",
|
35
|
+
"data/font/03",
|
36
|
+
"data/font/04",
|
37
|
+
"data/font/05",
|
38
|
+
"data/font/06",
|
39
|
+
"data/font/07",
|
40
|
+
"data/font/09",
|
41
|
+
"data/font/0a",
|
42
|
+
"data/font/0b",
|
43
|
+
"data/font/0c",
|
44
|
+
"data/font/0d",
|
45
|
+
"data/font/0e",
|
46
|
+
"data/font/0f",
|
47
|
+
"data/font/10",
|
48
|
+
"data/font/11",
|
49
|
+
"data/font/12",
|
50
|
+
"data/font/13",
|
51
|
+
"data/font/14",
|
52
|
+
"data/font/15",
|
53
|
+
"data/font/16",
|
54
|
+
"data/font/17",
|
55
|
+
"data/font/18",
|
56
|
+
"data/font/19",
|
57
|
+
"data/font/1a",
|
58
|
+
"data/font/1b",
|
59
|
+
"data/font/1c",
|
60
|
+
"data/font/1d",
|
61
|
+
"data/font/1e",
|
62
|
+
"data/font/1f",
|
63
|
+
"data/font/20",
|
64
|
+
"data/font/21",
|
65
|
+
"data/font/22",
|
66
|
+
"data/font/23",
|
67
|
+
"data/font/24",
|
68
|
+
"data/font/25",
|
69
|
+
"data/font/26",
|
70
|
+
"data/font/27",
|
71
|
+
"data/font/28",
|
72
|
+
"data/font/29",
|
73
|
+
"data/font/2a",
|
74
|
+
"data/font/2b",
|
75
|
+
"data/font/2c",
|
76
|
+
"data/font/2d",
|
77
|
+
"data/font/2e",
|
78
|
+
"data/font/2f",
|
79
|
+
"data/font/30",
|
80
|
+
"data/font/31",
|
81
|
+
"data/font/32",
|
82
|
+
"data/font/33",
|
83
|
+
"data/font/34",
|
84
|
+
"data/font/35",
|
85
|
+
"data/font/36",
|
86
|
+
"data/font/37",
|
87
|
+
"data/font/38",
|
88
|
+
"data/font/39",
|
89
|
+
"data/font/3a",
|
90
|
+
"data/font/3b",
|
91
|
+
"data/font/3c",
|
92
|
+
"data/font/3d",
|
93
|
+
"data/font/3e",
|
94
|
+
"data/font/3f",
|
95
|
+
"data/font/40",
|
96
|
+
"data/font/41",
|
97
|
+
"data/font/42",
|
98
|
+
"data/font/43",
|
99
|
+
"data/font/44",
|
100
|
+
"data/font/45",
|
101
|
+
"data/font/46",
|
102
|
+
"data/font/47",
|
103
|
+
"data/font/48",
|
104
|
+
"data/font/49",
|
105
|
+
"data/font/4a",
|
106
|
+
"data/font/4b",
|
107
|
+
"data/font/4c",
|
108
|
+
"data/font/4d",
|
109
|
+
"data/font/4e",
|
110
|
+
"data/font/4f",
|
111
|
+
"data/font/50",
|
112
|
+
"data/font/51",
|
113
|
+
"data/font/52",
|
114
|
+
"data/font/53",
|
115
|
+
"data/font/54",
|
116
|
+
"data/font/55",
|
117
|
+
"data/font/56",
|
118
|
+
"data/font/57",
|
119
|
+
"data/font/58",
|
120
|
+
"data/font/59",
|
121
|
+
"data/font/5a",
|
122
|
+
"data/font/5b",
|
123
|
+
"data/font/5c",
|
124
|
+
"data/font/5d",
|
125
|
+
"data/font/5e",
|
126
|
+
"data/font/5f",
|
127
|
+
"data/font/60",
|
128
|
+
"data/font/61",
|
129
|
+
"data/font/62",
|
130
|
+
"data/font/63",
|
131
|
+
"data/font/64",
|
132
|
+
"data/font/65",
|
133
|
+
"data/font/66",
|
134
|
+
"data/font/67",
|
135
|
+
"data/font/68",
|
136
|
+
"data/font/69",
|
137
|
+
"data/font/6a",
|
138
|
+
"data/font/6b",
|
139
|
+
"data/font/6c",
|
140
|
+
"data/font/6d",
|
141
|
+
"data/font/6e",
|
142
|
+
"data/font/6f",
|
143
|
+
"data/font/70",
|
144
|
+
"data/font/71",
|
145
|
+
"data/font/72",
|
146
|
+
"data/font/73",
|
147
|
+
"data/font/74",
|
148
|
+
"data/font/75",
|
149
|
+
"data/font/76",
|
150
|
+
"data/font/77",
|
151
|
+
"data/font/78",
|
152
|
+
"data/font/79",
|
153
|
+
"data/font/7a",
|
154
|
+
"data/font/7b",
|
155
|
+
"data/font/7c",
|
156
|
+
"data/font/7d",
|
157
|
+
"data/font/7e",
|
158
|
+
"data/font/7f",
|
159
|
+
"data/font/80",
|
160
|
+
"data/font/81",
|
161
|
+
"data/font/82",
|
162
|
+
"data/font/83",
|
163
|
+
"data/font/84",
|
164
|
+
"data/font/85",
|
165
|
+
"data/font/86",
|
166
|
+
"data/font/87",
|
167
|
+
"data/font/88",
|
168
|
+
"data/font/89",
|
169
|
+
"data/font/8a",
|
170
|
+
"data/font/8b",
|
171
|
+
"data/font/8c",
|
172
|
+
"data/font/8d",
|
173
|
+
"data/font/8e",
|
174
|
+
"data/font/8f",
|
175
|
+
"data/font/90",
|
176
|
+
"data/font/91",
|
177
|
+
"data/font/92",
|
178
|
+
"data/font/93",
|
179
|
+
"data/font/94",
|
180
|
+
"data/font/95",
|
181
|
+
"data/font/96",
|
182
|
+
"data/font/97",
|
183
|
+
"data/font/98",
|
184
|
+
"data/font/99",
|
185
|
+
"data/font/9a",
|
186
|
+
"data/font/9b",
|
187
|
+
"data/font/9c",
|
188
|
+
"data/font/9d",
|
189
|
+
"data/font/9e",
|
190
|
+
"data/font/9f",
|
191
|
+
"data/font/a0",
|
192
|
+
"data/font/a1",
|
193
|
+
"data/font/a2",
|
194
|
+
"data/font/a3",
|
195
|
+
"data/font/a4",
|
196
|
+
"data/font/a5",
|
197
|
+
"data/font/a6",
|
198
|
+
"data/font/a7",
|
199
|
+
"data/font/a8",
|
200
|
+
"data/font/a9",
|
201
|
+
"data/font/aa",
|
202
|
+
"data/font/ac",
|
203
|
+
"data/font/ad",
|
204
|
+
"data/font/ae",
|
205
|
+
"data/font/af",
|
206
|
+
"data/font/b0",
|
207
|
+
"data/font/b1",
|
208
|
+
"data/font/b2",
|
209
|
+
"data/font/b3",
|
210
|
+
"data/font/b4",
|
211
|
+
"data/font/b5",
|
212
|
+
"data/font/b6",
|
213
|
+
"data/font/b7",
|
214
|
+
"data/font/b8",
|
215
|
+
"data/font/b9",
|
216
|
+
"data/font/ba",
|
217
|
+
"data/font/bb",
|
218
|
+
"data/font/bc",
|
219
|
+
"data/font/bd",
|
220
|
+
"data/font/be",
|
221
|
+
"data/font/bf",
|
222
|
+
"data/font/c0",
|
223
|
+
"data/font/c1",
|
224
|
+
"data/font/c2",
|
225
|
+
"data/font/c3",
|
226
|
+
"data/font/c4",
|
227
|
+
"data/font/c5",
|
228
|
+
"data/font/c6",
|
229
|
+
"data/font/c7",
|
230
|
+
"data/font/c8",
|
231
|
+
"data/font/c9",
|
232
|
+
"data/font/ca",
|
233
|
+
"data/font/cb",
|
234
|
+
"data/font/cc",
|
235
|
+
"data/font/cd",
|
236
|
+
"data/font/ce",
|
237
|
+
"data/font/cf",
|
238
|
+
"data/font/d0",
|
239
|
+
"data/font/d1",
|
240
|
+
"data/font/d2",
|
241
|
+
"data/font/d3",
|
242
|
+
"data/font/d4",
|
243
|
+
"data/font/d5",
|
244
|
+
"data/font/d6",
|
245
|
+
"data/font/d7",
|
246
|
+
"data/font/f9",
|
247
|
+
"data/font/fa",
|
248
|
+
"data/font/fb",
|
249
|
+
"data/font/fc",
|
250
|
+
"data/font/fd",
|
251
|
+
"data/font/fe",
|
252
|
+
"data/font/ff",
|
253
|
+
"data/unifont-5.1.20080820.7z",
|
254
|
+
"data/unused-4-read-tar.rb",
|
25
255
|
"lib/sugar_png.rb",
|
256
|
+
"lib/sugar_png/border.rb",
|
257
|
+
"lib/sugar_png/color.rb",
|
26
258
|
"lib/sugar_png/datastream.rb",
|
259
|
+
"lib/sugar_png/dyn_accessor.rb",
|
260
|
+
"lib/sugar_png/font.rb",
|
261
|
+
"lib/sugar_png/glyph.rb",
|
262
|
+
"lib/sugar_png/image.rb",
|
263
|
+
"samples/damaged_chunk.png",
|
264
|
+
"samples/png_suite/f00n0g08_reference.png",
|
265
|
+
"samples/png_suite/f00n2c08_reference.png",
|
266
|
+
"samples/png_suite/f01n0g08_reference.png",
|
267
|
+
"samples/png_suite/f01n2c08_reference.png",
|
268
|
+
"samples/png_suite/f02n0g08_reference.png",
|
269
|
+
"samples/png_suite/f02n2c08_reference.png",
|
270
|
+
"samples/png_suite/f03n0g08_reference.png",
|
271
|
+
"samples/png_suite/f03n2c08_reference.png",
|
272
|
+
"samples/png_suite/f04n0g08_reference.png",
|
273
|
+
"samples/png_suite/f04n2c08_reference.png",
|
274
|
+
"samples/readme/explicit_image_dimensions_bg_color.png",
|
275
|
+
"samples/readme/hello_world.png",
|
276
|
+
"samples/readme/japanese_text_with_rainbow_borders_zoomed_4x.png",
|
277
|
+
"samples/readme/pixels_can_be_set_using_ranges_enumerators_arrays.png",
|
278
|
+
"samples/readme/playing_with_transparency_16_bit_color_depth.png",
|
279
|
+
"samples/readme/white_noise.png",
|
280
|
+
"samples/rgba.tar.bz2",
|
281
|
+
"samples/text_chunk.png",
|
282
|
+
"samples/ztxt_chunk.png",
|
283
|
+
"spec/color_spec.rb",
|
284
|
+
"spec/font_spec.rb",
|
285
|
+
"spec/magic/border_spec.rb",
|
286
|
+
"spec/magic/create_spec.rb",
|
287
|
+
"spec/magic/pixels_spec.rb",
|
288
|
+
"spec/magic/text_spec.rb",
|
289
|
+
"spec/magic/zoom_spec.rb",
|
290
|
+
"spec/png_suite_spec.rb",
|
27
291
|
"spec/spec_helper.rb",
|
292
|
+
"spec/sugar_png/datastream_spec.rb",
|
293
|
+
"spec/support/png_suite.rb",
|
28
294
|
"sugar_png.gemspec"
|
29
295
|
]
|
30
296
|
s.homepage = "http://github.com/zed-0xff/sugar_png"
|
@@ -37,21 +303,24 @@ Gem::Specification.new do |s|
|
|
37
303
|
s.specification_version = 3
|
38
304
|
|
39
305
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
40
|
-
s.add_runtime_dependency(%q<zpng>, [">= 0.2.
|
306
|
+
s.add_runtime_dependency(%q<zpng>, [">= 0.2.1"])
|
41
307
|
s.add_development_dependency(%q<rspec>, [">= 2.8.0"])
|
42
308
|
s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
|
43
309
|
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
310
|
+
s.add_development_dependency(%q<awesome_print>, [">= 0"])
|
44
311
|
else
|
45
|
-
s.add_dependency(%q<zpng>, [">= 0.2.
|
312
|
+
s.add_dependency(%q<zpng>, [">= 0.2.1"])
|
46
313
|
s.add_dependency(%q<rspec>, [">= 2.8.0"])
|
47
314
|
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
48
315
|
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
316
|
+
s.add_dependency(%q<awesome_print>, [">= 0"])
|
49
317
|
end
|
50
318
|
else
|
51
|
-
s.add_dependency(%q<zpng>, [">= 0.2.
|
319
|
+
s.add_dependency(%q<zpng>, [">= 0.2.1"])
|
52
320
|
s.add_dependency(%q<rspec>, [">= 2.8.0"])
|
53
321
|
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
54
322
|
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
323
|
+
s.add_dependency(%q<awesome_print>, [">= 0"])
|
55
324
|
end
|
56
325
|
end
|
57
326
|
|