chunky_png 1.3.4 → 1.3.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 00c6b5bf5c682e05964783d8d05f964582c5f7aa
4
- data.tar.gz: 8552180cbcd29adacd71df55a253d8a69a499e8e
3
+ metadata.gz: 1395efeb7e88472e7540738a53c3741b73fca724
4
+ data.tar.gz: 47a55fd705b53d3c55df1d3c172e49c5890f29c5
5
5
  SHA512:
6
- metadata.gz: d8ef6769e7d848d4fb526b2fa23710edc122c0ce67e9a4cabea9504faed8124cb1a667318ee61139282f91eb928c3aa7e745ba51308985f7713f050460ffa914
7
- data.tar.gz: b04f411542d0bacf557ea6449abfa0a0d99406b8c26bb73b2b55fb7d275460c3b616c5a372e0a97dcb12eb44229a60a1bedbb260dedca77b216c261e0c374eee
6
+ metadata.gz: aff023ebfaa594917ac6b46b6fa39725a66cb81e3430f05b0c9fa7fab421eeaa2844bf6617ec12958087655211d435a3ed873e76789b9be1bea910234cdeac6b
7
+ data.tar.gz: 440d1f499da4349fab1c47b912fbf26347f304a33470c7420c4bb5b96511ac80f6bd677544e974116ed90669dea75197089043da6d4c852a63687ea2cdfd1546
@@ -3,17 +3,14 @@ script: bundle exec rake
3
3
  sudo: false
4
4
 
5
5
  rvm:
6
- - "1.8"
7
- - "1.9"
8
6
  - "2.0"
9
7
  - "2.1"
10
8
  - "2.2"
11
9
  - ruby-head
12
- - rbx
13
- - jruby-18mode
10
+ - rbx-19mode
14
11
  - jruby-19mode
15
12
 
16
13
  matrix:
17
14
  allow_failures:
18
- - rvm: rbx
15
+ - rvm: rbx-19mode
19
16
  - rvm: ruby-head
@@ -1,4 +1,4 @@
1
- = Chunky PNG {<img src="https://travis-ci.org/wvanbergen/chunky_png.png?branch=master" alt="Build Status" />}[https://travis-ci.org/wvanbergen/chunky_png]
1
+ = Chunky PNG {<img src="https://travis-ci.org/wvanbergen/chunky_png.svg?branch=master" alt="Build Status" />}[https://travis-ci.org/wvanbergen/chunky_png]
2
2
 
3
3
  This library can read and write PNG files. It is written in pure Ruby for
4
4
  maximum portability. Let me rephrase: it does NOT require RMagick or any other
@@ -175,11 +175,18 @@ module ChunkyPNG
175
175
  raise ChunkyPNG::OutOfBounds, 'Original image height is too small!'
176
176
  end
177
177
 
178
- new_pixels = []
179
- for cy in 0...crop_height do
180
- new_pixels.concat pixels.slice((cy + y) * width + x, crop_width)
178
+ if crop_width == width && x == 0
179
+ # We only need to crop off the top and/or bottom, so we can take a
180
+ # shortcut.
181
+ replace_canvas!(crop_width, crop_height,
182
+ pixels.slice(y * width, width * crop_height))
183
+ else
184
+ new_pixels = []
185
+ for cy in 0...crop_height do
186
+ new_pixels.concat pixels.slice((cy + y) * width + x, crop_width)
187
+ end
188
+ replace_canvas!(crop_width, crop_height, new_pixels)
181
189
  end
182
- replace_canvas!(crop_width, crop_height, new_pixels)
183
190
  end
184
191
 
185
192
  # Flips the image horizontally, leaving the original intact.
@@ -245,7 +245,11 @@ module ChunkyPNG
245
245
 
246
246
  class ImageData < Generic
247
247
  def self.combine_chunks(data_chunks)
248
- Zlib::Inflate.inflate(data_chunks.map { |c| c.content }.join(''))
248
+ zstream = Zlib::Inflate.new
249
+ data_chunks.each { |c| zstream << c.content }
250
+ inflated = zstream.finish
251
+ zstream.close
252
+ inflated
249
253
  end
250
254
 
251
255
  def self.split_in_chunks(data, level = Zlib::DEFAULT_COMPRESSION, chunk_size = 2147483647)
@@ -256,7 +256,7 @@ module ChunkyPNG
256
256
  when (2...3); [0, chroma, x]
257
257
  when (3...4); [0, x, chroma]
258
258
  when (4...5); [x, 0, chroma]
259
- when (5...6); [chroma, 0, x]
259
+ when (5..6); [chroma, 0, x]
260
260
  end
261
261
  end
262
262
  private :cylindrical_to_cubic
@@ -131,7 +131,7 @@ module ChunkyPNG
131
131
  def chunks
132
132
  enum_for(:each_chunk)
133
133
  end
134
-
134
+
135
135
  # Returns all the textual metadata key/value pairs as hash.
136
136
  # @return [Hash] A hash containing metadata fields and their values.
137
137
  def metadata
@@ -141,7 +141,7 @@ module ChunkyPNG
141
141
  end
142
142
  metadata
143
143
  end
144
-
144
+
145
145
  # Returns the uncompressed image data, combined from all the IDAT chunks
146
146
  # @return [String] The uncompressed image data for this datastream
147
147
  def imagedata
@@ -175,6 +175,7 @@ module ChunkyPNG
175
175
  # @return [String] The encoded PNG datastream.
176
176
  def to_blob
177
177
  str = StringIO.new
178
+ str.set_encoding('ASCII-8BIT')
178
179
  write(str)
179
180
  return str.string
180
181
  end
@@ -1,4 +1,4 @@
1
- require 'RMagick'
1
+ require 'rmagick'
2
2
 
3
3
  module ChunkyPNG
4
4
 
@@ -1,5 +1,5 @@
1
1
  module ChunkyPNG
2
2
  # The current version of ChunkyPNG.
3
3
  # Set it and commit the change this before running rake release.
4
- VERSION = "1.3.4"
4
+ VERSION = "1.3.5"
5
5
  end
@@ -48,22 +48,46 @@ describe ChunkyPNG::Canvas::Operations do
48
48
  end
49
49
 
50
50
  describe '#crop!' do
51
- it "should crop the right pixels from the original canvas" do
52
- subject.crop!(10, 5, 4, 8)
53
- expect(subject).to eql reference_canvas('cropped')
54
- end
51
+ context 'when cropping both width and height' do
52
+ let(:crop_opts) { [10, 5, 4, 8] }
53
+
54
+ it "should crop the right pixels from the original canvas" do
55
+ subject.crop!(*crop_opts)
56
+ expect(subject).to eql reference_canvas('cropped')
57
+ end
55
58
 
56
- it "should have a new width and height" do
57
- expect { subject.crop!(10, 5, 4, 8) }.to change { subject.dimension }.
58
- from(ChunkyPNG::Dimension('16x16')).to(ChunkyPNG::Dimension('4x8'))
59
+ it "should have a new width and height" do
60
+ expect { subject.crop!(*crop_opts) }.to change { subject.dimension }.
61
+ from(ChunkyPNG::Dimension('16x16')).to(ChunkyPNG::Dimension('4x8'))
62
+ end
63
+
64
+ it "should return itself" do
65
+ expect(subject.crop!(*crop_opts)).to equal(subject)
66
+ end
59
67
  end
60
68
 
61
- it "should raise an exception when the cropped image falls outside the oiginal image" do
62
- expect { subject.crop!(16, 16, 2, 2) }.to raise_error(ChunkyPNG::OutOfBounds)
69
+ context "when cropping just the height" do
70
+ let(:crop_opts) { [0, 5, 16, 8] }
71
+
72
+ it "should crop the right pixels from the original canvas" do
73
+ subject.crop!(*crop_opts)
74
+ expect(subject).to eql reference_canvas('cropped_height')
75
+ end
76
+
77
+ it "should have a new width and height" do
78
+ expect { subject.crop!(*crop_opts) }.to change { subject.dimension }.
79
+ from(ChunkyPNG::Dimension('16x16')).to(ChunkyPNG::Dimension('16x8'))
80
+ end
81
+
82
+ it "should return itself" do
83
+ expect(subject.crop!(*crop_opts)).to equal(subject)
84
+ end
63
85
  end
64
86
 
65
- it "should return itself" do
66
- expect(subject.crop!(10, 5, 4, 8)).to equal(subject)
87
+ context "when the cropped image falls outside the original image" do
88
+ it "should raise an exception" do
89
+ expect { subject.crop!(16, 16, 2, 2) }.to raise_error(ChunkyPNG::OutOfBounds)
90
+ end
67
91
  end
68
92
  end
69
93
 
@@ -129,6 +129,10 @@ describe ChunkyPNG::Color do
129
129
 
130
130
  # And, finally, one random color
131
131
  expect(from_hsv(120, 0.5, 0.80)).to eql 0x66cc66ff
132
+
133
+ # Hue 0 and hue 360 should be equivalent
134
+ expect(from_hsv(0, 0.5, 0.5)).to eql from_hsv(360, 0.5, 0.5)
135
+ expect(from_hsv(0, 0.5, 0.5)).to eql from_hsv(360.0, 0.5, 0.5)
132
136
  end
133
137
 
134
138
  it 'should optionally accept a fourth param for alpha' do
@@ -162,6 +166,10 @@ describe ChunkyPNG::Color do
162
166
  from_hsl(87.27, 0.5, 0.5686) == 0x96c85aff
163
167
  from_hsl(271.83, 0.5399, 0.4176) == 0x6e31a4ff
164
168
  from_hsl(63.6, 0.5984, 0.4882) == 0xbec732ff
169
+
170
+ # Hue 0 and hue 360 should be equivalent
171
+ expect(from_hsl(0, 0.5, 0.5)).to eql from_hsl(360, 0.5, 0.5)
172
+ expect(from_hsl(0, 0.5, 0.5)).to eql from_hsl(360.0, 0.5, 0.5)
165
173
  end
166
174
 
167
175
  it 'should optionally accept a fourth param for alpha' do
@@ -5,12 +5,17 @@ describe ChunkyPNG::Datastream do
5
5
  describe '.from_io'do
6
6
  it "should raise an error when loading a file with a bad signature" do
7
7
  filename = resource_file('damaged_signature.png')
8
- expect { ChunkyPNG::Datastream.from_file(filename) }.to raise_error
8
+ expect { ChunkyPNG::Datastream.from_file(filename) }.to raise_error(ChunkyPNG::SignatureMismatch)
9
9
  end
10
10
 
11
11
  it "should raise an error if the CRC of a chunk is incorrect" do
12
12
  filename = resource_file('damaged_chunk.png')
13
- expect { ChunkyPNG::Datastream.from_file(filename) }.to raise_error
13
+ expect { ChunkyPNG::Datastream.from_file(filename) }.to raise_error(ChunkyPNG::CRCMismatch)
14
+ end
15
+
16
+ it "should raise an error for a stream that is too short" do
17
+ stream = StringIO.new
18
+ expect { ChunkyPNG::Datastream.from_io(stream) }.to raise_error(ChunkyPNG::SignatureMismatch)
14
19
  end
15
20
  end
16
21
 
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chunky_png
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.4
4
+ version: 1.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Willem van Bergen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-16 00:00:00.000000000 Z
11
+ date: 2015-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: '3'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3'
41
41
  description: |2
@@ -65,9 +65,9 @@ extra_rdoc_files:
65
65
  - CONTRIBUTING.rdoc
66
66
  - CHANGELOG.rdoc
67
67
  files:
68
- - ".gitignore"
69
- - ".travis.yml"
70
- - ".yardopts"
68
+ - .gitignore
69
+ - .travis.yml
70
+ - .yardopts
71
71
  - BENCHMARKING.rdoc
72
72
  - CHANGELOG.rdoc
73
73
  - CONTRIBUTING.rdoc
@@ -362,6 +362,7 @@ files:
362
362
  - spec/resources/clock_updated.png
363
363
  - spec/resources/composited.png
364
364
  - spec/resources/cropped.png
365
+ - spec/resources/cropped_height.png
365
366
  - spec/resources/damaged_chunk.png
366
367
  - spec/resources/damaged_signature.png
367
368
  - spec/resources/empty.png
@@ -392,27 +393,27 @@ licenses:
392
393
  metadata: {}
393
394
  post_install_message:
394
395
  rdoc_options:
395
- - "--title"
396
+ - --title
396
397
  - chunky_png
397
- - "--main"
398
+ - --main
398
399
  - README.rdoc
399
- - "--line-numbers"
400
- - "--inline-source"
400
+ - --line-numbers
401
+ - --inline-source
401
402
  require_paths:
402
403
  - lib
403
404
  required_ruby_version: !ruby/object:Gem::Requirement
404
405
  requirements:
405
- - - ">="
406
+ - - '>='
406
407
  - !ruby/object:Gem::Version
407
408
  version: '0'
408
409
  required_rubygems_version: !ruby/object:Gem::Requirement
409
410
  requirements:
410
- - - ">="
411
+ - - '>='
411
412
  - !ruby/object:Gem::Version
412
413
  version: '0'
413
414
  requirements: []
414
415
  rubyforge_project:
415
- rubygems_version: 2.4.5
416
+ rubygems_version: 2.0.14
416
417
  signing_key:
417
418
  specification_version: 4
418
419
  summary: Pure ruby library for read/write, chunk-level access to PNG files
@@ -676,6 +677,7 @@ test_files:
676
677
  - spec/resources/clock_updated.png
677
678
  - spec/resources/composited.png
678
679
  - spec/resources/cropped.png
680
+ - spec/resources/cropped_height.png
679
681
  - spec/resources/damaged_chunk.png
680
682
  - spec/resources/damaged_signature.png
681
683
  - spec/resources/empty.png