zpng 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -0
- data/README.md.tpl +2 -0
- data/VERSION +1 -1
- data/lib/zpng/chunk.rb +22 -2
- data/lib/zpng/cli.rb +22 -1
- data/lib/zpng/image.rb +1 -0
- data/zpng.gemspec +86 -0
- metadata +16 -15
data/README.md
CHANGED
data/README.md.tpl
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/lib/zpng/chunk.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module ZPNG
|
2
2
|
class Chunk
|
3
|
-
attr_accessor :size, :type, :data, :crc
|
3
|
+
attr_accessor :size, :type, :data, :crc, :idx
|
4
4
|
|
5
5
|
def self.from_stream io
|
6
6
|
size, type = io.read(8).unpack('Na4')
|
@@ -39,7 +39,7 @@ module ZPNG
|
|
39
39
|
size = @size ? sprintf("%5d",@size) : sprintf("%5s","???")
|
40
40
|
crc = @crc ? sprintf("%08x",@crc) : sprintf("%8s","???")
|
41
41
|
type = @type.to_s.gsub(/[^0-9a-z]/i){ |x| sprintf("\\x%02X",x.ord) }
|
42
|
-
sprintf
|
42
|
+
sprintf "<Chunk #%02d %4s size=%s, crc=%s >", idx.to_i, type, size, crc
|
43
43
|
end
|
44
44
|
|
45
45
|
def crc_ok?
|
@@ -129,5 +129,25 @@ module ZPNG
|
|
129
129
|
|
130
130
|
class IEND < Chunk
|
131
131
|
end
|
132
|
+
|
133
|
+
class ZTXT < Chunk
|
134
|
+
attr_accessor :keyword, :comp_method, :text
|
135
|
+
def initialize *args
|
136
|
+
super
|
137
|
+
@keyword,@comp_method,@text = data.unpack('Z*Ca*')
|
138
|
+
if @text
|
139
|
+
@text = Zlib::Inflate.inflate(@text)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
def inspect
|
143
|
+
super.sub(/ *>$/,'') + ", " +
|
144
|
+
(instance_variables-[:@type, :@crc, :@data, :@size]).
|
145
|
+
map do |var|
|
146
|
+
t = instance_variable_get(var).to_s
|
147
|
+
t = t[0..10] + "..." if t.size > 10
|
148
|
+
"#{var.to_s.tr('@','')}=#{t}"
|
149
|
+
end.join(", ") + ">"
|
150
|
+
end
|
151
|
+
end
|
132
152
|
end
|
133
153
|
end
|
data/lib/zpng/cli.rb
CHANGED
@@ -34,6 +34,10 @@ class ZPNG::CLI
|
|
34
34
|
ACTIONS.each do |t,desc|
|
35
35
|
opts.on *[ "-#{t[0].upcase}", "--#{t}", desc, eval("lambda{ |_| @actions << :#{t} }") ]
|
36
36
|
end
|
37
|
+
|
38
|
+
opts.on "-E", "--extract-chunk id" do |id|
|
39
|
+
@actions << [:extract_chunk, id.to_i]
|
40
|
+
end
|
37
41
|
end
|
38
42
|
|
39
43
|
if (argv = optparser.parse(@argv)).empty?
|
@@ -51,7 +55,11 @@ class ZPNG::CLI
|
|
51
55
|
@zpng = load_file fname
|
52
56
|
|
53
57
|
@actions.each do |action|
|
54
|
-
|
58
|
+
if action.is_a?(Array)
|
59
|
+
self.send(*action) if self.respond_to?(action.first)
|
60
|
+
else
|
61
|
+
self.send(action) if self.respond_to?(action)
|
62
|
+
end
|
55
63
|
end
|
56
64
|
end
|
57
65
|
rescue Errno::EPIPE
|
@@ -59,6 +67,19 @@ class ZPNG::CLI
|
|
59
67
|
# prevents a 'Broken pipe - <STDOUT> (Errno::EPIPE)' message
|
60
68
|
end
|
61
69
|
|
70
|
+
def extract_chunk id
|
71
|
+
@img.chunks.each do |chunk|
|
72
|
+
if chunk.idx == id
|
73
|
+
case chunk
|
74
|
+
when ZPNG::Chunk::ZTXT
|
75
|
+
print chunk.text
|
76
|
+
else
|
77
|
+
print chunk.data
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
62
83
|
def load_file fname
|
63
84
|
@img = ZPNG::Image.new fname
|
64
85
|
end
|
data/lib/zpng/image.rb
CHANGED
data/zpng.gemspec
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "zpng"
|
8
|
+
s.version = "0.0.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Andrey \"Zed\" Zaikin"]
|
12
|
+
s.date = "2012-03-18"
|
13
|
+
s.email = "zed.0xff@gmail.com"
|
14
|
+
s.executables = ["zpng"]
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.md",
|
18
|
+
"README.md.tpl"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".document",
|
22
|
+
".rspec",
|
23
|
+
"Gemfile",
|
24
|
+
"Gemfile.lock",
|
25
|
+
"LICENSE.txt",
|
26
|
+
"README.md",
|
27
|
+
"README.md.tpl",
|
28
|
+
"Rakefile",
|
29
|
+
"VERSION",
|
30
|
+
"bin/zpng",
|
31
|
+
"lib/zpng.rb",
|
32
|
+
"lib/zpng/block.rb",
|
33
|
+
"lib/zpng/chunk.rb",
|
34
|
+
"lib/zpng/cli.rb",
|
35
|
+
"lib/zpng/color.rb",
|
36
|
+
"lib/zpng/image.rb",
|
37
|
+
"lib/zpng/scan_line.rb",
|
38
|
+
"samples/modify.rb",
|
39
|
+
"samples/qr_aux_chunks.png",
|
40
|
+
"samples/qr_bw.png",
|
41
|
+
"samples/qr_gray_alpha.png",
|
42
|
+
"samples/qr_grayscale.png",
|
43
|
+
"samples/qr_plte.png",
|
44
|
+
"samples/qr_plte_bw.png",
|
45
|
+
"samples/qr_rgb.png",
|
46
|
+
"samples/qr_rgba.png",
|
47
|
+
"spec/ascii_spec.rb",
|
48
|
+
"spec/modify_spec.rb",
|
49
|
+
"spec/spec_helper.rb",
|
50
|
+
"spec/zpng_spec.rb",
|
51
|
+
"zpng.gemspec"
|
52
|
+
]
|
53
|
+
s.homepage = "http://github.com/zed-0xff/zpng"
|
54
|
+
s.licenses = ["MIT"]
|
55
|
+
s.require_paths = ["lib"]
|
56
|
+
s.rubygems_version = "1.8.10"
|
57
|
+
s.summary = "pure ruby PNG file manipulation & validation"
|
58
|
+
|
59
|
+
if s.respond_to? :specification_version then
|
60
|
+
s.specification_version = 3
|
61
|
+
|
62
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
63
|
+
s.add_runtime_dependency(%q<colorize>, [">= 0"])
|
64
|
+
s.add_runtime_dependency(%q<hexdump>, [">= 0"])
|
65
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
|
66
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
67
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
68
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
69
|
+
else
|
70
|
+
s.add_dependency(%q<colorize>, [">= 0"])
|
71
|
+
s.add_dependency(%q<hexdump>, [">= 0"])
|
72
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
73
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
74
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
75
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
76
|
+
end
|
77
|
+
else
|
78
|
+
s.add_dependency(%q<colorize>, [">= 0"])
|
79
|
+
s.add_dependency(%q<hexdump>, [">= 0"])
|
80
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
81
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
82
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
83
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zpng
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-03-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: colorize
|
16
|
-
requirement: &
|
16
|
+
requirement: &70231152732120 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70231152732120
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: hexdump
|
27
|
-
requirement: &
|
27
|
+
requirement: &70231152731280 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70231152731280
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &70231152746560 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 2.8.0
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70231152746560
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: bundler
|
49
|
-
requirement: &
|
49
|
+
requirement: &70231152745500 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 1.0.0
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70231152745500
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: jeweler
|
60
|
-
requirement: &
|
60
|
+
requirement: &70231152744400 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 1.6.4
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70231152744400
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rcov
|
71
|
-
requirement: &
|
71
|
+
requirement: &70231152742060 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70231152742060
|
80
80
|
description:
|
81
81
|
email: zed.0xff@gmail.com
|
82
82
|
executables:
|
@@ -117,6 +117,7 @@ files:
|
|
117
117
|
- spec/modify_spec.rb
|
118
118
|
- spec/spec_helper.rb
|
119
119
|
- spec/zpng_spec.rb
|
120
|
+
- zpng.gemspec
|
120
121
|
homepage: http://github.com/zed-0xff/zpng
|
121
122
|
licenses:
|
122
123
|
- MIT
|
@@ -132,7 +133,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
132
133
|
version: '0'
|
133
134
|
segments:
|
134
135
|
- 0
|
135
|
-
hash:
|
136
|
+
hash: -893836760864101821
|
136
137
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
138
|
none: false
|
138
139
|
requirements:
|