zpng 0.4.3 → 0.4.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2cceb23c5330f39f49baad1cb807e023e79e27cfdf6c9bb9afca1def11d43556
4
- data.tar.gz: 3985fed46171d58778e3d6ad8fe06e8c2e1e94dde884554dfde9495fe737d6da
3
+ metadata.gz: 6b35d6d1f87f6a32f1de261d07be9a5670cad8892fdf8033a46c6189ac60c6c5
4
+ data.tar.gz: 584811c71db552f0b07f701f324b3e359d101c7650c975280f6c529cc8ecb246
5
5
  SHA512:
6
- metadata.gz: 7e35dbd0d0f09a8aad7c8a0fce43f9a46ca9fa1c8a64d1ca1b20452e1273018bc01deb1dba00e4ec07ff0b8d27b80510b27078eeaf017a78224a1fce620cd12b
7
- data.tar.gz: 965d3ace9f810ccb433b6574c27b409168103d81f5f86cadab8450d012f4c81ce3fa44c19309d99d01ddde36fa14ff4b18bd345e59ab60616f3aa010c100bbe1
6
+ metadata.gz: e22d560929ca762532c078ac6ab7732788032ec58e86d20156c35169f0ebf44c498b69069adcb563b70ab8f770aa20116c5c5da4e9bd2847a716c504bc164c5f
7
+ data.tar.gz: b34d79aa9ca9b1c4bfa8770ca59c463eff6155687e27891f143b19fc142e07c914e1d7412f51446bacb6ba637b3879c9e662c06cb0003b51fff4d102b2ec5d8c
data/Gemfile.lock CHANGED
@@ -30,7 +30,8 @@ GEM
30
30
  faraday-patron (1.0.0)
31
31
  faraday-rack (1.0.0)
32
32
  faraday-retry (1.0.3)
33
- git (1.11.0)
33
+ git (1.13.1)
34
+ addressable (~> 2.8)
34
35
  rchardet (~> 1.8)
35
36
  github_api (0.19.0)
36
37
  addressable (~> 2.4)
@@ -55,24 +56,24 @@ GEM
55
56
  jwt (2.4.1)
56
57
  kamelcase (0.0.2)
57
58
  semver2 (~> 3)
58
- mini_portile2 (2.8.0)
59
+ mini_portile2 (2.8.1)
59
60
  multi_json (1.15.0)
60
61
  multi_xml (0.6.0)
61
62
  multipart-post (2.2.3)
62
- nokogiri (1.13.6)
63
+ nokogiri (1.14.2)
63
64
  mini_portile2 (~> 2.8.0)
64
65
  racc (~> 1.4)
65
- oauth2 (1.4.9)
66
+ oauth2 (1.4.11)
66
67
  faraday (>= 0.17.3, < 3.0)
67
68
  jwt (>= 1.0, < 3.0)
68
69
  multi_json (~> 1.3)
69
70
  multi_xml (~> 0.5)
70
- rack (>= 1.2, < 3)
71
+ rack (>= 1.2, < 4)
71
72
  psych (4.0.4)
72
73
  stringio
73
74
  public_suffix (4.0.7)
74
- racc (1.6.0)
75
- rack (2.2.3.1)
75
+ racc (1.6.2)
76
+ rack (3.0.4.1)
76
77
  rainbow (3.1.1)
77
78
  rake (13.0.6)
78
79
  rchardet (1.8.0)
data/Rakefile CHANGED
@@ -23,6 +23,7 @@ Juwelier::Tasks.new do |gem|
23
23
  gem.authors = ["Andrey \"Zed\" Zaikin"]
24
24
  gem.executables = %w'zpng'
25
25
  gem.files.include "lib/**/*.rb"
26
+ gem.files.exclude "samples/**/*"
26
27
  # dependencies defined in Gemfile
27
28
  end
28
29
  Juwelier::RubygemsDotOrgTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.3
1
+ 0.4.4
@@ -1,19 +1,20 @@
1
1
  module ZPNG
2
2
  class Adam7Decoder
3
- attr_accessor :image
3
+ attr_accessor :bpp
4
4
  attr_reader :scanlines_count
5
5
 
6
6
  # http://en.wikipedia.org/wiki/Adam7_algorithm#Passes
7
- def initialize img
8
- @image = img
7
+ def initialize width, height, bpp
8
+ @bpp = bpp
9
+ raise "Invalid BPP #{@bpp.inspect}" if @bpp.to_i == 0
9
10
  @widths = [
10
- [(img.width/8.0).ceil] * (img.height/8.0).ceil, # pass1
11
- [((img.width-4)/8.0).ceil] * (img.height/8.0).ceil, # pass2
12
- [(img.width/4.0).ceil] * ((img.height-4)/8.0).ceil, # pass3
13
- [((img.width-2)/4.0).ceil] * (img.height/4.0).ceil, # pass4
14
- [(img.width/2.0).ceil] * ((img.height-2)/4.0).ceil, # pass5
15
- [((img.width-1)/2.0).ceil] * (img.height/2.0).ceil, # pass6
16
- [img.width] * ((img.height-1)/2.0).ceil # pass7
11
+ [(width/8.0).ceil] * (height/8.0).ceil, # pass1
12
+ [((width-4)/8.0).ceil] * (height/8.0).ceil, # pass2
13
+ [(width/4.0).ceil] * ((height-4)/8.0).ceil, # pass3
14
+ [((width-2)/4.0).ceil] * (height/4.0).ceil, # pass4
15
+ [(width/2.0).ceil] * ((height-2)/4.0).ceil, # pass5
16
+ [((width-1)/2.0).ceil] * (height/2.0).ceil, # pass6
17
+ [width] * ((height-1)/2.0).ceil # pass7
17
18
  ].map{ |x| x == [0] ? [] : x }
18
19
  @scanlines_count = 0
19
20
  # two leading zeroes added specially for convert_coords() code readability
@@ -28,7 +29,7 @@ module ZPNG
28
29
 
29
30
  # scanline size in bytes, INCLUDING leading filter byte
30
31
  def scanline_size idx
31
- (scanline_width(idx) * image.bpp / 8.0).ceil + 1
32
+ (scanline_width(idx) * bpp / 8.0).ceil + 1
32
33
  end
33
34
 
34
35
  # scanline offset in imagedata
data/lib/zpng/chunk.rb CHANGED
@@ -51,10 +51,10 @@ module ZPNG
51
51
  end
52
52
  end
53
53
 
54
- def export
54
+ def export( fix_crc: true )
55
55
  @data = self.export_data # virtual
56
56
  @size = @data.size # XXX hmm.. is it always is?
57
- fix_crc!
57
+ fix_crc! if fix_crc
58
58
  [@size,@type].pack('Na4') + @data + [@crc].pack('N')
59
59
  end
60
60
 
@@ -98,6 +98,9 @@ module ZPNG
98
98
  class IHDR < Chunk
99
99
  attr_accessor :width, :height, :depth, :color, :compression, :filter, :interlace
100
100
 
101
+ SIZE = 13
102
+ FORMAT = 'NNC5'
103
+
101
104
  PALETTE_USED = 1
102
105
  COLOR_USED = 2
103
106
  ALPHA_USED = 4
@@ -130,8 +133,6 @@ module ZPNG
130
133
  COLOR_RGBA => [ 8, 16 ],
131
134
  }
132
135
 
133
- FORMAT = 'NNC5'
134
-
135
136
  def initialize x
136
137
  super
137
138
  vars = %w'width height depth color compression filter interlace' # order is important
@@ -173,7 +174,7 @@ module ZPNG
173
174
  @filter ||= 0
174
175
  @interlace ||= 0
175
176
 
176
- unless ALLOWED_DEPTHS[@color].include?(@depth)
177
+ unless ALLOWED_DEPTHS[@color]&.include?(@depth)
177
178
  raise "[!] invalid color mode (#{@color.inspect}) / bit depth (#{@depth.inspect}) combination"
178
179
  end
179
180
  end
@@ -190,7 +191,8 @@ module ZPNG
190
191
 
191
192
  # bits per pixel
192
193
  def bpp
193
- SAMPLES_PER_COLOR[@color] * depth
194
+ spc = SAMPLES_PER_COLOR[@color]
195
+ spc ? spc * depth : nil
194
196
  end
195
197
 
196
198
  def color_used?
@@ -275,8 +277,32 @@ module ZPNG
275
277
  alias :<< :find_or_add
276
278
  end
277
279
 
280
+ class CHRM < Chunk
281
+ SIZE = 32
282
+ end
283
+
284
+ class GAMA < Chunk
285
+ SIZE = 4
286
+ end
287
+
278
288
  class IDAT < Chunk; end
279
- class IEND < Chunk; end
289
+
290
+ class TIME < Chunk
291
+ SIZE = 7
292
+ end
293
+
294
+ class IEND < Chunk
295
+ SIZE = 4
296
+ end
297
+
298
+ class PHYS < Chunk
299
+ SIZE = 9
300
+ end
301
+
302
+ class SRGB < Chunk
303
+ SIZE = 1
304
+ end
305
+
280
306
  class TRNS < Chunk; end
281
307
 
282
308
  end
data/lib/zpng/cli.rb CHANGED
@@ -179,13 +179,15 @@ module ZPNG
179
179
  color = %w'COLOR_GRAYSCALE COLOR_RGB COLOR_INDEXED COLOR_GRAY_ALPHA COLOR_RGBA'.find do |k|
180
180
  @img.hdr.color == ZPNG.const_get(k)
181
181
  end
182
- puts "[.] image size #{@img.width || '?'}x#{@img.height || '?'}, #{@img.bpp}bpp, #{color}"
182
+ puts "[.] image size #{@img.width || '?'}x#{@img.height || '?'}, #{@img.bpp || '?'}bpp, #{color}"
183
183
  puts "[.] palette = #{@img.palette}" if @img.palette
184
- puts "[.] uncompressed imagedata size = #{@img.imagedata_size} bytes"
184
+ puts "[.] uncompressed imagedata size = #{@img.imagedata_size || '?'} bytes"
185
185
  _conditional_hexdump(@img.imagedata, 3) if @options[:verbose] > 0
186
186
  end
187
187
 
188
188
  def _conditional_hexdump data, v2 = 2
189
+ return unless data
190
+
189
191
  if @options[:verbose] <= 0
190
192
  # do nothing
191
193
  elsif @options[:verbose] < v2
@@ -221,7 +223,11 @@ module ZPNG
221
223
  end
222
224
  puts "[.] #{chunk.inspect(@options[:verbose]).sub(chunk.type, colored_type)} #{colored_crc}"
223
225
 
224
- _conditional_hexdump(chunk.data) unless chunk.size == 0
226
+ if @options[:verbose] >= 3
227
+ _conditional_hexdump(chunk.export(fix_crc: false))
228
+ else
229
+ _conditional_hexdump(chunk.data)
230
+ end
225
231
  end
226
232
  end
227
233
 
data/lib/zpng/image.rb CHANGED
@@ -62,7 +62,7 @@ module ZPNG
62
62
  end
63
63
 
64
64
  def adam7
65
- @adam7 ||= Adam7Decoder.new(self)
65
+ @adam7 ||= Adam7Decoder.new(width, height, bpp)
66
66
  end
67
67
 
68
68
  class << self
@@ -119,7 +119,7 @@ module ZPNG
119
119
  io.seek(chunk.offset+delta, IO::SEEK_SET)
120
120
  potential_chunk = Chunk.new(io)
121
121
  if potential_chunk.valid?
122
- STDERR.puts "[!] heuristics: found invalid chunk at offset #{chunk.offset}, but valid one at #{chunk.offset+delta}. using latter".red
122
+ STDERR.puts "[!] heuristics: found invalid #{chunk.type.inspect} chunk at offset #{chunk.offset}, but valid #{potential_chunk.type.inspect} at #{chunk.offset+delta}. using latter".red
123
123
  if delta > 0
124
124
  io.seek(chunk.offset, IO::SEEK_SET)
125
125
  data = io.read(delta)
@@ -330,7 +330,7 @@ module ZPNG
330
330
  if new_image?
331
331
  @scanlines.map(&:size).inject(&:+)
332
332
  else
333
- imagedata.size
333
+ imagedata&.size
334
334
  end
335
335
  end
336
336
 
data/spec/adam7_spec.rb CHANGED
@@ -13,9 +13,7 @@ describe ZPNG::Adam7Decoder do
13
13
  }.each do |dims, slw|
14
14
  it "should be right for #{dims} image" do
15
15
  w,h = dims.split('x').map(&:to_i)
16
- img = Object.new
17
- allow(img).to receive_messages(:width => w, :height => h)
18
- adam7 = ZPNG::Adam7Decoder.new(img)
16
+ adam7 = ZPNG::Adam7Decoder.new(w, h, 8)
19
17
  slw.size.times.map{ |i| adam7.scanline_width(i) }.should == slw
20
18
  end
21
19
  end
@@ -34,9 +32,7 @@ describe ZPNG::Adam7Decoder do
34
32
  }.each do |dims, n|
35
33
  it "should be right for #{dims} image" do
36
34
  w,h = dims.split('x').map(&:to_i)
37
- img = Object.new
38
- allow(img).to receive_messages(:width => w, :height => h)
39
- adam7 = ZPNG::Adam7Decoder.new(img)
35
+ adam7 = ZPNG::Adam7Decoder.new(w, h, 8)
40
36
  adam7.scanlines_count.should == n
41
37
  end
42
38
  end
@@ -54,9 +50,7 @@ describe ZPNG::Adam7Decoder do
54
50
  }.each do |dims, pst|
55
51
  it "should be right for #{dims} image" do
56
52
  w,h = dims.split('x').map(&:to_i)
57
- img = Object.new
58
- allow(img).to receive_messages(:width => w, :height => h)
59
- adam7 = ZPNG::Adam7Decoder.new(img)
53
+ adam7 = ZPNG::Adam7Decoder.new(w, h, 8)
60
54
  adam7.instance_variable_get("@pass_starts").should == pst
61
55
  end
62
56
  end
@@ -15,6 +15,7 @@ each_sample("bad/*.png") do |fname|
15
15
  end
16
16
 
17
17
  it "should access 1st pixel" do
18
+ skip "no BPP" unless @img.bpp
18
19
  @img[0,0].should be_instance_of(ZPNG::Color)
19
20
  end
20
21
 
@@ -31,6 +32,7 @@ each_sample("bad/*.png") do |fname|
31
32
  end
32
33
 
33
34
  it "shows scanlines" do
35
+ skip "no BPP" unless @img.bpp
34
36
  orig_stdout, out = $stdout, ""
35
37
  begin
36
38
  $stdout = StringIO.new(out)
@@ -1,5 +1,5 @@
1
1
  module PNGSuite
2
- PNG_SUITE_URL = "http://www.schaik.com/pngsuite/PngSuite-2011apr25.tgz"
2
+ PNG_SUITE_URL = "http://www.schaik.com/pngsuite/PngSuite-2017jul19.tgz"
3
3
 
4
4
  class << self
5
5
  attr_accessor :dir
data/zpng.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: zpng 0.4.3 ruby lib
5
+ # stub: zpng 0.4.4 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "zpng".freeze
9
- s.version = "0.4.3"
9
+ s.version = "0.4.4"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["Andrey \"Zed\" Zaikin".freeze]
14
- s.date = "2022-06-30"
14
+ s.date = "2023-02-14"
15
15
  s.email = "zed.0xff@gmail.com".freeze
16
16
  s.executables = ["zpng".freeze]
17
17
  s.extra_rdoc_files = [
@@ -51,25 +51,6 @@ Gem::Specification.new do |s|
51
51
  "lib/zpng/text_chunk.rb",
52
52
  "misc/chars.png",
53
53
  "misc/gen_ascii_map.rb",
54
- "samples/bad/000000.png",
55
- "samples/bad/149511457-47db5096-662d-4221-84f9-1c2a0e20e323.png",
56
- "samples/bad/b1.png",
57
- "samples/captcha_4bpp.png",
58
- "samples/cats.png",
59
- "samples/itxt.png",
60
- "samples/modify.rb",
61
- "samples/mouse.bmp",
62
- "samples/mouse.png",
63
- "samples/mouse17.bmp",
64
- "samples/mouse17.png",
65
- "samples/qr_aux_chunks.png",
66
- "samples/qr_bw.png",
67
- "samples/qr_gray_alpha.png",
68
- "samples/qr_grayscale.png",
69
- "samples/qr_plte.png",
70
- "samples/qr_plte_bw.png",
71
- "samples/qr_rgb.png",
72
- "samples/qr_rgba.png",
73
54
  "spec/adam7_spec.rb",
74
55
  "spec/alpha_spec.rb",
75
56
  "spec/ascii_spec.rb",
@@ -95,7 +76,7 @@ Gem::Specification.new do |s|
95
76
  ]
96
77
  s.homepage = "http://github.com/zed-0xff/zpng".freeze
97
78
  s.licenses = ["MIT".freeze]
98
- s.rubygems_version = "3.1.6".freeze
79
+ s.rubygems_version = "3.3.7".freeze
99
80
  s.summary = "pure ruby PNG file manipulation & validation".freeze
100
81
 
101
82
  if s.respond_to? :specification_version then
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zpng
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey "Zed" Zaikin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-30 00:00:00.000000000 Z
11
+ date: 2023-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rainbow
@@ -107,25 +107,6 @@ files:
107
107
  - lib/zpng/text_chunk.rb
108
108
  - misc/chars.png
109
109
  - misc/gen_ascii_map.rb
110
- - samples/bad/000000.png
111
- - samples/bad/149511457-47db5096-662d-4221-84f9-1c2a0e20e323.png
112
- - samples/bad/b1.png
113
- - samples/captcha_4bpp.png
114
- - samples/cats.png
115
- - samples/itxt.png
116
- - samples/modify.rb
117
- - samples/mouse.bmp
118
- - samples/mouse.png
119
- - samples/mouse17.bmp
120
- - samples/mouse17.png
121
- - samples/qr_aux_chunks.png
122
- - samples/qr_bw.png
123
- - samples/qr_gray_alpha.png
124
- - samples/qr_grayscale.png
125
- - samples/qr_plte.png
126
- - samples/qr_plte_bw.png
127
- - samples/qr_rgb.png
128
- - samples/qr_rgba.png
129
110
  - spec/adam7_spec.rb
130
111
  - spec/alpha_spec.rb
131
112
  - spec/ascii_spec.rb
@@ -167,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
148
  - !ruby/object:Gem::Version
168
149
  version: '0'
169
150
  requirements: []
170
- rubygems_version: 3.1.6
151
+ rubygems_version: 3.3.7
171
152
  signing_key:
172
153
  specification_version: 4
173
154
  summary: pure ruby PNG file manipulation & validation
Binary file
data/samples/bad/b1.png DELETED
Binary file
Binary file
data/samples/cats.png DELETED
Binary file
data/samples/itxt.png DELETED
Binary file
data/samples/modify.rb DELETED
@@ -1,20 +0,0 @@
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
data/samples/mouse.bmp DELETED
Binary file
data/samples/mouse.png DELETED
Binary file
data/samples/mouse17.bmp DELETED
Binary file
data/samples/mouse17.png DELETED
Binary file
Binary file
data/samples/qr_bw.png DELETED
Binary file
Binary file
Binary file
data/samples/qr_plte.png DELETED
Binary file
Binary file
data/samples/qr_rgb.png DELETED
Binary file
data/samples/qr_rgba.png DELETED
Binary file