zpng 0.2.0 → 0.2.1

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.
@@ -0,0 +1,28 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '/spec_helper'))
2
+ require 'zpng/cli'
3
+
4
+ PNGSuite.each('tb','tp1') do |fname|
5
+ describe fname.sub(%r|\A#{Regexp::escape(Dir.getwd)}/?|, '') do
6
+ it "has its very first pixel transparent" do
7
+ img = ZPNG::Image.load(fname)
8
+ img[0,0].should be_transparent
9
+ end
10
+ it "has its very first pixel NOT opaque" do
11
+ img = ZPNG::Image.load(fname)
12
+ img[0,0].should_not be_opaque
13
+ end
14
+ end
15
+ end
16
+
17
+ PNGSuite.each('tp0') do |fname|
18
+ describe fname.sub(%r|\A#{Regexp::escape(Dir.getwd)}/?|, '') do
19
+ it "has its very first pixel NOT transparent" do
20
+ img = ZPNG::Image.load(fname)
21
+ img[0,0].should_not be_transparent
22
+ end
23
+ it "has its very first pixel opaque" do
24
+ img = ZPNG::Image.load(fname)
25
+ img[0,0].should be_opaque
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,62 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '/spec_helper'))
2
+ require 'zpng/cli'
3
+
4
+ CLI_PATHNAME = File.expand_path(File.join(File.dirname(__FILE__), '/../bin/zpng'))
5
+
6
+ describe "CLI" do
7
+ PNGSuite.each_good do |fname|
8
+ describe fname.sub(%r|\A#{Regexp::escape(Dir.getwd)}/?|, '') do
9
+
10
+ it "works" do
11
+ orig_stdout, out = $stdout, ""
12
+ begin
13
+ $stdout = StringIO.new(out)
14
+ lambda { ZPNG::CLI.new([fname]).run }.should_not raise_error
15
+ ensure
16
+ $stdout = orig_stdout
17
+ end
18
+ end
19
+
20
+ it "works verbosely" do
21
+ orig_stdout, out = $stdout, ""
22
+ begin
23
+ $stdout = StringIO.new(out)
24
+ lambda { ZPNG::CLI.new([fname, "-vvv"]).run }.should_not raise_error
25
+ ensure
26
+ $stdout = orig_stdout
27
+ end
28
+ end
29
+
30
+ it "to ASCII" do
31
+ orig_stdout, out = $stdout, ""
32
+ begin
33
+ $stdout = StringIO.new(out)
34
+ lambda { ZPNG::CLI.new([fname, "-A"]).run }.should_not raise_error
35
+ ensure
36
+ $stdout = orig_stdout
37
+ end
38
+ end
39
+
40
+ it "to ANSI" do
41
+ orig_stdout, out = $stdout, ""
42
+ begin
43
+ $stdout = StringIO.new(out)
44
+ lambda { ZPNG::CLI.new([fname, "-N"]).run }.should_not raise_error
45
+ ensure
46
+ $stdout = orig_stdout
47
+ end
48
+ end
49
+
50
+ it "to ANSI256" do
51
+ orig_stdout, out = $stdout, ""
52
+ begin
53
+ $stdout = StringIO.new(out)
54
+ lambda { ZPNG::CLI.new([fname, "-2"]).run }.should_not raise_error
55
+ ensure
56
+ $stdout = orig_stdout
57
+ end
58
+ end
59
+
60
+ end
61
+ end
62
+ end
@@ -24,8 +24,8 @@ describe ZPNG::Color do
24
24
  c = c.to_depth(8)
25
25
  c.depth.should == 8
26
26
  c.r.should == 0
27
- c.g.should == 0x20
28
- c.b.should == 0x3f
27
+ c.g.should == 2*17
28
+ c.b.should == 3*17
29
29
  end
30
30
 
31
31
  it "keeps color depth" do
@@ -37,4 +37,14 @@ describe ZPNG::Color do
37
37
  c.b.should == 0x33
38
38
  end
39
39
  end
40
+
41
+ it "sorts" do
42
+ c1 = ZPNG::Color.new 0x11, 0x11, 0x11
43
+ c2 = ZPNG::Color.new 0x22, 0x22, 0x22
44
+ c3 = ZPNG::Color.new 0, 0, 0xff
45
+
46
+ [c3,c1,c2].sort.should == [c1,c2,c3]
47
+ [c3,c2,c1].sort.should == [c1,c2,c3]
48
+ [c1,c3,c2].sort.should == [c1,c2,c3]
49
+ end
40
50
  end
@@ -0,0 +1,19 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '/spec_helper'))
2
+ require 'zpng/cli'
3
+
4
+ PNGSuite.each("???i*.png") do |fname|
5
+ describe fname.sub(%r|\A#{Regexp::escape(Dir.getwd)}/?|, '') do
6
+ it "deinterlaced should be pixel-by-pixel-identical to interlaced" do
7
+ interlaced = ZPNG::Image.load(fname)
8
+ deinterlaced = interlaced.deinterlace
9
+ deinterlaced.each_pixel do |color,x,y|
10
+ interlaced[x,y].should == color
11
+ end
12
+ interlaced.each_pixel do |color,x,y|
13
+ deinterlaced[x,y].should == color
14
+ end
15
+
16
+ interlaced.pixels.to_a.should == deinterlaced.pixels.to_a
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,22 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe ZPNG::Metadata do
4
+ # itxt.png contains all possible text chunks
5
+ describe "itxt.png" do
6
+ let!(:metadata){
7
+ ZPNG::Image.load( File.join(SAMPLES_DIR, "itxt.png") ).metadata
8
+ }
9
+ it "should get all values" do
10
+ metadata.size.should == 4
11
+ end
12
+ it "should not find not existing value" do
13
+ metadata['foobar'].should be_nil
14
+ end
15
+ it "should find all existing values" do
16
+ metadata['Title'].should == "PNG"
17
+ metadata['Author'].should == "La plume de ma tante"
18
+ metadata['Warning'].should == "Es is verboten, um diese Datei in das GIF-Bildformat\numzuwandeln. Sie sind gevarnt worden."
19
+ metadata['Description'].should =~ /Since POV-Ray does not direclty support/
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,16 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '/spec_helper'))
2
+ require 'zpng/cli'
3
+
4
+ PNGSuite.each_good do |fname|
5
+ describe fname.sub(%r|\A#{Regexp::escape(Dir.getwd)}/?|, '') do
6
+ it "accessess all pixels" do
7
+ img = ZPNG::Image.load(fname)
8
+ n = 0
9
+ img.each_pixel do |px|
10
+ px.should be_instance_of(ZPNG::Color)
11
+ n += 1
12
+ end
13
+ n.should == img.width*img.height
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,34 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '/spec_helper'))
2
+ require 'zpng/cli'
3
+
4
+ PNGSuite.each_good do |fname|
5
+ describe fname.sub(%r|\A#{Regexp::escape(Dir.getwd)}/?|, '') do
6
+ it "accessess all pixels via enumerator" do
7
+ img = ZPNG::Image.load(fname)
8
+
9
+ first_pixel = img.pixels.first
10
+
11
+ n = 0
12
+ img.pixels.each do |px|
13
+ px.should be_instance_of(ZPNG::Color)
14
+ if n == 0
15
+ px.should == first_pixel
16
+ end
17
+ n += 1
18
+ end
19
+ n.should == img.width*img.height
20
+ end
21
+ end
22
+ end
23
+
24
+ describe "pixels enumerator" do
25
+ describe "#uniq" do
26
+ it "returns only unique pixels" do
27
+ fname = File.join(SAMPLES_DIR, "qr_bw.png")
28
+ img = ZPNG::Image.load(fname)
29
+ a = img.pixels.uniq
30
+ a.size.should == 2
31
+ a.sort.should == [ZPNG::Color::BLACK, ZPNG::Color::WHITE].sort
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,13 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe ZPNG::Image do
4
+ it "creates image" do
5
+ img = ZPNG::Image.new :width => 16, :height => 16
6
+ lambda {
7
+ 10.times do
8
+ img[rand(16),rand(16)] = ZPNG::Color::BLACK
9
+ end
10
+ img.export
11
+ }.should_not raise_error
12
+ end
13
+ end
@@ -20,31 +20,10 @@ SAMPLES =
20
20
  Dir[File.join(SAMPLES_DIR,'qr_*.png')]
21
21
  end
22
22
 
23
- PNG_SUITE_URL = "http://www.schaik.com/pngsuite/PngSuite-2011apr25.tgz"
24
-
25
- def get_png_suite
26
- dir = File.join(SAMPLES_DIR, "png_suite")
27
- if Dir.exist?(dir)
28
- if Dir[File.join(dir, "*.png")].size > 100
29
- # already fetched and unpacked
30
- return
31
- end
32
- else
33
- Dir.mkdir(dir)
34
- end
35
- require 'open-uri'
36
- puts "[.] fetching PNG test-suite from #{PNG_SUITE_URL} .. "
37
- data = open(PNG_SUITE_URL).read
38
-
39
- fname = File.join(dir, "png_suite.tgz")
40
- File.open(fname, "wb"){ |f| f<<data }
41
- puts "[.] unpacking .. "
42
- system "tar", "xzf", fname, "-C", dir
43
- end
23
+ PNGSuite.init( File.join(SAMPLES_DIR, "png_suite") )
44
24
 
45
25
  RSpec.configure do |config|
46
26
  config.before :suite do
47
- get_png_suite
48
27
  end
49
28
  end
50
29
 
@@ -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
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "zpng"
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
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 = "2012-12-23"
12
+ s.date = "2013-01-02"
13
13
  s.email = "zed.0xff@gmail.com"
14
14
  s.executables = ["zpng"]
15
15
  s.extra_rdoc_files = [
@@ -37,12 +37,17 @@ Gem::Specification.new do |s|
37
37
  "lib/zpng/cli.rb",
38
38
  "lib/zpng/color.rb",
39
39
  "lib/zpng/deep_copyable.rb",
40
+ "lib/zpng/hexdump.rb",
40
41
  "lib/zpng/image.rb",
42
+ "lib/zpng/metadata.rb",
43
+ "lib/zpng/pixels.rb",
41
44
  "lib/zpng/scan_line.rb",
42
45
  "lib/zpng/string_ext.rb",
46
+ "lib/zpng/text_chunk.rb",
43
47
  "misc/chars.png",
44
48
  "misc/gen_ascii_map.rb",
45
49
  "samples/captcha_4bpp.png",
50
+ "samples/itxt.png",
46
51
  "samples/modify.rb",
47
52
  "samples/qr_aux_chunks.png",
48
53
  "samples/qr_bw.png",
@@ -53,14 +58,22 @@ Gem::Specification.new do |s|
53
58
  "samples/qr_rgb.png",
54
59
  "samples/qr_rgba.png",
55
60
  "spec/adam7_spec.rb",
61
+ "spec/alpha_spec.rb",
56
62
  "spec/ascii_spec.rb",
63
+ "spec/cli_spec.rb",
57
64
  "spec/color_spec.rb",
58
65
  "spec/create_image_spec.rb",
59
66
  "spec/crop_spec.rb",
67
+ "spec/deinterlace_spec.rb",
60
68
  "spec/image_spec.rb",
69
+ "spec/metadata_spec.rb",
61
70
  "spec/modify_spec.rb",
71
+ "spec/pixel_access_spec.rb",
72
+ "spec/pixels_enumerator_spec.rb",
62
73
  "spec/running_pixel_spec.rb",
74
+ "spec/set_random_pixel_spec.rb",
63
75
  "spec/spec_helper.rb",
76
+ "spec/support/png_suite.rb",
64
77
  "spec/zpng_spec.rb",
65
78
  "zpng.gemspec"
66
79
  ]
@@ -74,20 +87,17 @@ Gem::Specification.new do |s|
74
87
  s.specification_version = 3
75
88
 
76
89
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
77
- s.add_runtime_dependency(%q<hexdump>, [">= 0"])
78
90
  s.add_runtime_dependency(%q<rainbow>, [">= 0"])
79
91
  s.add_development_dependency(%q<rspec>, [">= 2.8.0"])
80
92
  s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
81
93
  s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
82
94
  else
83
- s.add_dependency(%q<hexdump>, [">= 0"])
84
95
  s.add_dependency(%q<rainbow>, [">= 0"])
85
96
  s.add_dependency(%q<rspec>, [">= 2.8.0"])
86
97
  s.add_dependency(%q<bundler>, [">= 1.0.0"])
87
98
  s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
88
99
  end
89
100
  else
90
- s.add_dependency(%q<hexdump>, [">= 0"])
91
101
  s.add_dependency(%q<rainbow>, [">= 0"])
92
102
  s.add_dependency(%q<rspec>, [">= 2.8.0"])
93
103
  s.add_dependency(%q<bundler>, [">= 1.0.0"])
metadata CHANGED
@@ -2,31 +2,15 @@
2
2
  name: zpng
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.0
5
+ version: 0.2.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Andrey "Zed" Zaikin
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-23 00:00:00.000000000 Z
12
+ date: 2013-01-02 00:00:00.000000000 Z
13
13
  dependencies:
14
- - !ruby/object:Gem::Dependency
15
- prerelease: false
16
- type: :runtime
17
- name: hexdump
18
- requirement: !ruby/object:Gem::Requirement
19
- requirements:
20
- - - ! '>='
21
- - !ruby/object:Gem::Version
22
- version: '0'
23
- none: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- requirements:
26
- - - ! '>='
27
- - !ruby/object:Gem::Version
28
- version: '0'
29
- none: false
30
14
  - !ruby/object:Gem::Dependency
31
15
  prerelease: false
32
16
  type: :runtime
@@ -120,12 +104,17 @@ files:
120
104
  - lib/zpng/cli.rb
121
105
  - lib/zpng/color.rb
122
106
  - lib/zpng/deep_copyable.rb
107
+ - lib/zpng/hexdump.rb
123
108
  - lib/zpng/image.rb
109
+ - lib/zpng/metadata.rb
110
+ - lib/zpng/pixels.rb
124
111
  - lib/zpng/scan_line.rb
125
112
  - lib/zpng/string_ext.rb
113
+ - lib/zpng/text_chunk.rb
126
114
  - misc/chars.png
127
115
  - misc/gen_ascii_map.rb
128
116
  - samples/captcha_4bpp.png
117
+ - samples/itxt.png
129
118
  - samples/modify.rb
130
119
  - samples/qr_aux_chunks.png
131
120
  - samples/qr_bw.png
@@ -136,14 +125,22 @@ files:
136
125
  - samples/qr_rgb.png
137
126
  - samples/qr_rgba.png
138
127
  - spec/adam7_spec.rb
128
+ - spec/alpha_spec.rb
139
129
  - spec/ascii_spec.rb
130
+ - spec/cli_spec.rb
140
131
  - spec/color_spec.rb
141
132
  - spec/create_image_spec.rb
142
133
  - spec/crop_spec.rb
134
+ - spec/deinterlace_spec.rb
143
135
  - spec/image_spec.rb
136
+ - spec/metadata_spec.rb
144
137
  - spec/modify_spec.rb
138
+ - spec/pixel_access_spec.rb
139
+ - spec/pixels_enumerator_spec.rb
145
140
  - spec/running_pixel_spec.rb
141
+ - spec/set_random_pixel_spec.rb
146
142
  - spec/spec_helper.rb
143
+ - spec/support/png_suite.rb
147
144
  - spec/zpng_spec.rb
148
145
  - zpng.gemspec
149
146
  homepage: http://github.com/zed-0xff/zpng
@@ -160,7 +157,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
160
157
  version: '0'
161
158
  segments:
162
159
  - 0
163
- hash: -93398394471482814
160
+ hash: -2687381686191062956
164
161
  none: false
165
162
  required_rubygems_version: !ruby/object:Gem::Requirement
166
163
  requirements: