zpng 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +32 -0
- data/LICENSE.txt +20 -0
- data/README.md +161 -0
- data/README.md.tpl +65 -0
- data/Rakefile +74 -0
- data/VERSION +1 -0
- data/bin/zpng +7 -0
- data/lib/zpng.rb +41 -0
- data/lib/zpng/block.rb +41 -0
- data/lib/zpng/chunk.rb +133 -0
- data/lib/zpng/cli.rb +90 -0
- data/lib/zpng/color.rb +25 -0
- data/lib/zpng/image.rb +130 -0
- data/lib/zpng/scan_line.rb +222 -0
- data/samples/modify.rb +20 -0
- data/samples/qr_aux_chunks.png +0 -0
- data/samples/qr_bw.png +0 -0
- data/samples/qr_gray_alpha.png +0 -0
- data/samples/qr_grayscale.png +0 -0
- data/samples/qr_plte.png +0 -0
- data/samples/qr_plte_bw.png +0 -0
- data/samples/qr_rgb.png +0 -0
- data/samples/qr_rgba.png +0 -0
- data/spec/ascii_spec.rb +52 -0
- data/spec/modify_spec.rb +63 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/zpng_spec.rb +7 -0
- metadata +148 -0
data/samples/modify.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'zpng'
|
3
|
+
include ZPNG
|
4
|
+
|
5
|
+
img = Image.new(File.join(File.dirname(__FILE__),"http.png"))
|
6
|
+
|
7
|
+
puts "[.] original:"
|
8
|
+
puts img.to_s
|
9
|
+
puts
|
10
|
+
|
11
|
+
img.width.times do |x|
|
12
|
+
img[x,0] = (x % 2 == 0) ? Color::WHITE : Color::BLACK
|
13
|
+
end
|
14
|
+
|
15
|
+
puts "[.] modified:"
|
16
|
+
puts img.to_s
|
17
|
+
|
18
|
+
File.open("http-modified.png","wb") do |f|
|
19
|
+
f << img.export
|
20
|
+
end
|
Binary file
|
data/samples/qr_bw.png
ADDED
Binary file
|
Binary file
|
Binary file
|
data/samples/qr_plte.png
ADDED
Binary file
|
Binary file
|
data/samples/qr_rgb.png
ADDED
Binary file
|
data/samples/qr_rgba.png
ADDED
Binary file
|
data/spec/ascii_spec.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
ASCII_QR = <<EOF
|
4
|
+
...................................
|
5
|
+
.#######.##.....##.#.##....#######.
|
6
|
+
.#.....#.......##.#.##.....#.....#.
|
7
|
+
.#.###.#.#..#####..#.#..##.#.###.#.
|
8
|
+
.#.###.#.##.#....#.####.##.#.###.#.
|
9
|
+
.#.###.#.####.#....#.####..#.###.#.
|
10
|
+
.#.....#..#..#.#..#####....#.....#.
|
11
|
+
.#######.#.#.#.#.#.#.#.#.#.#######.
|
12
|
+
..........#.#.##.....##.##.........
|
13
|
+
.####..#.#....##.#.##....##..###.#.
|
14
|
+
..#.##...##.....##.#.##.#.###...##.
|
15
|
+
.#.###.##......##.#.##..##.#.###.#.
|
16
|
+
....###.#...#####..#.#...##.#...#..
|
17
|
+
.##.##.#..#.#....#.####..##.##.....
|
18
|
+
...#..#.##.##.#....#.###.##....##..
|
19
|
+
.#.######.##.#.#..#####..#######...
|
20
|
+
.#.####..###.##.#.##....#...##.#...
|
21
|
+
...##.##..###.....##.#.##.########.
|
22
|
+
.....#..###..##.....##.#########.#.
|
23
|
+
.####.#####.##.....##.#...#...#.#..
|
24
|
+
..##.#..#..#.#..#####..#.#..##...#.
|
25
|
+
...######.#####.#....#.##......#...
|
26
|
+
..###.....#..####.#....###.#...###.
|
27
|
+
.###..####.####..#.#..#######...##.
|
28
|
+
.#.#.##.##.#.....##.#.##.######.#..
|
29
|
+
..#.#######..#.##.....##.#####...#.
|
30
|
+
.........#.###.#.##.....##...#.#...
|
31
|
+
.#######....#.#.##.....###.#.#.....
|
32
|
+
.#.....#..###..#.#..######...###.#.
|
33
|
+
.#.###.#.....#.####.#...########...
|
34
|
+
.#.###.#.###...#.####.#.#.#........
|
35
|
+
.#.###.#.###..#####..#.##..#..#....
|
36
|
+
.#.....#.####.##.....##.###......#.
|
37
|
+
.#######.#.#..##.#.##...#.##...#...
|
38
|
+
...................................
|
39
|
+
EOF
|
40
|
+
|
41
|
+
describe "ZPNG png2ascii" do
|
42
|
+
it "should have QR examples" do
|
43
|
+
Dir[File.join(SAMPLES_DIR,'qr_*.png')].should_not be_empty
|
44
|
+
end
|
45
|
+
Dir[File.join(SAMPLES_DIR,'qr_*.png')].each do |fname|
|
46
|
+
describe fname do
|
47
|
+
it "generates a nice ascii img" do
|
48
|
+
ZPNG::Image.new(fname).to_s(:white => '.', :black => '#').strip.should == ASCII_QR.strip
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/spec/modify_spec.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
ASCII_MODIFIED_QR = <<EOF
|
4
|
+
.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.
|
5
|
+
.#######.##.....##.#.##....#######.
|
6
|
+
.#.....#.......##.#.##.....#.....#.
|
7
|
+
.#.###.#.#..#####..#.#..##.#.###.#.
|
8
|
+
.#.###.#.##.#....#.####.##.#.###.#.
|
9
|
+
.#.###.#.####.#....#.####..#.###.#.
|
10
|
+
.#.....#..#..#.#..#####....#.....#.
|
11
|
+
.#######.#.#.#.#.#.#.#.#.#.#######.
|
12
|
+
..........#.#.##.....##.##.........
|
13
|
+
.####..#.#....##.#.##....##..###.#.
|
14
|
+
..#.##...##.....##.#.##.#.###...##.
|
15
|
+
.#.###.##......##.#.##..##.#.###.#.
|
16
|
+
....###.#...#####..#.#...##.#...#..
|
17
|
+
.##.##.#..#.#....#.####..##.##.....
|
18
|
+
...#..#.##.##.#....#.###.##....##..
|
19
|
+
.#.######.##.#.#..#####..#######...
|
20
|
+
.#.####..###.##.#.##....#...##.#...
|
21
|
+
...##.##..###.....##.#.##.########.
|
22
|
+
.....#..###..##.....##.#########.#.
|
23
|
+
.####.#####.##.....##.#...#...#.#..
|
24
|
+
..##.#..#..#.#..#####..#.#..##...#.
|
25
|
+
...######.#####.#....#.##......#...
|
26
|
+
..###.....#..####.#....###.#...###.
|
27
|
+
.###..####.####..#.#..#######...##.
|
28
|
+
.#.#.##.##.#.....##.#.##.######.#..
|
29
|
+
..#.#######..#.##.....##.#####...#.
|
30
|
+
.........#.###.#.##.....##...#.#...
|
31
|
+
.#######....#.#.##.....###.#.#.....
|
32
|
+
.#.....#..###..#.#..######...###.#.
|
33
|
+
.#.###.#.....#.####.#...########...
|
34
|
+
.#.###.#.###...#.####.#.#.#........
|
35
|
+
.#.###.#.###..#####..#.##..#..#....
|
36
|
+
.#.....#.####.##.....##.###......#.
|
37
|
+
.#######.#.#..##.#.##...#.##...#...
|
38
|
+
...................................
|
39
|
+
EOF
|
40
|
+
|
41
|
+
samples =
|
42
|
+
if ENV['SAMPLES']
|
43
|
+
ENV['SAMPLES'].split(' ')
|
44
|
+
else
|
45
|
+
Dir[File.join(SAMPLES_DIR,'qr_*.png')]
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "ZPNG modify" do
|
49
|
+
it "should have QR examples" do
|
50
|
+
samples.should_not be_empty
|
51
|
+
end
|
52
|
+
samples.each do |fname|
|
53
|
+
describe fname.sub(File.dirname(SAMPLES_DIR)+'/','') do
|
54
|
+
img = ZPNG::Image.new(fname)
|
55
|
+
it "modifies img - color=#{img.hdr.color}, depth=#{img.hdr.depth}, bpp=#{img.hdr.bpp}" do
|
56
|
+
img.width.times do |x|
|
57
|
+
img[x,0] = (x%2==0) ? ZPNG::Color::WHITE : ZPNG::Color::BLACK
|
58
|
+
end
|
59
|
+
img.to_s(:white => '.', :black => '#').strip.should == ASCII_MODIFIED_QR.strip
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'zpng'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
SAMPLES_DIR = File.join(
|
15
|
+
File.dirname(
|
16
|
+
File.dirname(
|
17
|
+
File.expand_path(__FILE__))),
|
18
|
+
"samples")
|
data/spec/zpng_spec.rb
ADDED
metadata
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: zpng
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Andrey "Zed" Zaikin
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-20 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: colorize
|
16
|
+
requirement: &70359178912700 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70359178912700
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: hexdump
|
27
|
+
requirement: &70359178930900 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70359178930900
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec
|
38
|
+
requirement: &70359178930200 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 2.8.0
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70359178930200
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: bundler
|
49
|
+
requirement: &70359178929280 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.0.0
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70359178929280
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: jeweler
|
60
|
+
requirement: &70359178928180 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ~>
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 1.6.4
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70359178928180
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rcov
|
71
|
+
requirement: &70359178927440 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70359178927440
|
80
|
+
description:
|
81
|
+
email: zed.0xff@gmail.com
|
82
|
+
executables:
|
83
|
+
- zpng
|
84
|
+
extensions: []
|
85
|
+
extra_rdoc_files:
|
86
|
+
- LICENSE.txt
|
87
|
+
- README.md
|
88
|
+
- README.md.tpl
|
89
|
+
files:
|
90
|
+
- .document
|
91
|
+
- .rspec
|
92
|
+
- Gemfile
|
93
|
+
- Gemfile.lock
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- README.md.tpl
|
97
|
+
- Rakefile
|
98
|
+
- VERSION
|
99
|
+
- bin/zpng
|
100
|
+
- lib/zpng.rb
|
101
|
+
- lib/zpng/block.rb
|
102
|
+
- lib/zpng/chunk.rb
|
103
|
+
- lib/zpng/cli.rb
|
104
|
+
- lib/zpng/color.rb
|
105
|
+
- lib/zpng/image.rb
|
106
|
+
- lib/zpng/scan_line.rb
|
107
|
+
- samples/modify.rb
|
108
|
+
- samples/qr_aux_chunks.png
|
109
|
+
- samples/qr_bw.png
|
110
|
+
- samples/qr_gray_alpha.png
|
111
|
+
- samples/qr_grayscale.png
|
112
|
+
- samples/qr_plte.png
|
113
|
+
- samples/qr_plte_bw.png
|
114
|
+
- samples/qr_rgb.png
|
115
|
+
- samples/qr_rgba.png
|
116
|
+
- spec/ascii_spec.rb
|
117
|
+
- spec/modify_spec.rb
|
118
|
+
- spec/spec_helper.rb
|
119
|
+
- spec/zpng_spec.rb
|
120
|
+
homepage: http://github.com/zed-0xff/zpng
|
121
|
+
licenses:
|
122
|
+
- MIT
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
none: false
|
129
|
+
requirements:
|
130
|
+
- - ! '>='
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
segments:
|
134
|
+
- 0
|
135
|
+
hash: 958619003383702064
|
136
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
requirements: []
|
143
|
+
rubyforge_project:
|
144
|
+
rubygems_version: 1.8.10
|
145
|
+
signing_key:
|
146
|
+
specification_version: 3
|
147
|
+
summary: pure ruby PNG file manipulation & validation
|
148
|
+
test_files: []
|