chunky_png 1.2.4 → 1.2.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,4 +6,5 @@ rvm:
6
6
  - ruby-head
7
7
  - ree
8
8
  - rbx
9
+ - rbx-2.0
9
10
  - jruby
@@ -3,8 +3,8 @@ Gem::Specification.new do |s|
3
3
 
4
4
  # Do not change the version and date fields by hand. This will be done
5
5
  # automatically by the gem release script.
6
- s.version = "1.2.4"
7
- s.date = "2011-09-14"
6
+ s.version = "1.2.5"
7
+ s.date = "2011-09-23"
8
8
 
9
9
  s.summary = "Pure ruby library for read/write, chunk-level access to PNG files"
10
10
  s.description = <<-EOT
@@ -25,7 +25,7 @@ module ChunkyPNG
25
25
 
26
26
  # The current version of ChunkyPNG. This value will be updated
27
27
  # automatically by them <tt>gem:release</tt> rake task.
28
- VERSION = "1.2.4"
28
+ VERSION = "1.2.5"
29
29
 
30
30
  ###################################################
31
31
  # PNG international standard defined constants
@@ -1,12 +1,14 @@
1
1
  module ChunkyPNG
2
2
  class Canvas
3
3
 
4
- # Methods to export a canvas to a PNG data URL.
4
+ # Methods to import a canvas from a PNG data URL.
5
5
  module DataUrlImporting
6
6
 
7
- # Exports the canvas as a data url (e.g. data:image/png;base64,<data>) that can
8
- # easily be used inline in CSS or HTML.
9
- # @return [String] The canvas formatted as a data URL string.
7
+ # Imports a canvas from a PNG data URL.
8
+ # @param [String] string The data URL string to load from.
9
+ # @return [Canvas] The imported canvas.
10
+ # @raise ChunkyPNG::SignatureMismatch if the provides string is not a properly
11
+ # formatted PNG data URL (i.e. it should start with "data:image/png;base64,")
10
12
  def from_data_url(string)
11
13
  if string =~ %r[^data:image/png;base64,((?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=))$]
12
14
  from_blob($1.unpack('m').first)
@@ -20,7 +20,7 @@ module ChunkyPNG
20
20
  #
21
21
  # @param [Integer] old_theme_color The original theme color in this image.
22
22
  # @param [Integer] new_theme_color The color to replace the old theme color with.
23
- # @param [Integer] The background color on which the theme colored pixels are placed.
23
+ # @param [Integer] bg_color The background color on which the theme colored pixels are placed.
24
24
  # @param [Integer] tolerance The tolerance level to use when extracting the mask image. Five is
25
25
  # the default; increase this if the masked image does not extract all the required pixels,
26
26
  # decrease it if too many pixels get extracted.
@@ -422,8 +422,13 @@ module ChunkyPNG
422
422
  # @param [Integer] bg The background color on which the color was composed.
423
423
  # @return [Integer] The decomposed alpha value for the channel.
424
424
  def decompose_alpha_component(channel, color, mask, bg)
425
- ((send(channel, bg) - send(channel, color)).to_f /
426
- (send(channel, bg) - send(channel, mask)).to_f * MAX).round
425
+ cc, mc, bc = send(channel, color), send(channel, mask), send(channel, bg)
426
+
427
+ return 0x00 if bc == cc
428
+ return 0xff if bc == mc
429
+ return 0xff if cc == mc
430
+
431
+ (((bc - cc).to_f / (bc - mc).to_f) * MAX).round
427
432
  end
428
433
 
429
434
  # Decomposes the alpha channels for the r, g and b color channel.
@@ -219,6 +219,18 @@ describe ChunkyPNG::Color do
219
219
  it "should decompose the alpha channel correctly" do
220
220
  decompose_alpha(0x9fc2d6ff, @opaque, @white).should == 0x00000064
221
221
  end
222
+
223
+ it "should return fully transparent if the background channel matches the resulting color" do
224
+ decompose_alpha(0xabcdefff, 0xff000000, 0xabcdefff).should == 0x00
225
+ end
226
+
227
+ it "should return fully opaque if the background channel matches the mask color" do
228
+ decompose_alpha(0xff000000, 0xabcdefff, 0xabcdefff).should == 0xff
229
+ end
230
+
231
+ it "should return fully opaque if the resulting color matches the mask color" do
232
+ decompose_alpha(0xabcdefff, 0xabcdefff, 0xffffffff).should == 255
233
+ end
222
234
  end
223
235
 
224
236
  describe '#blend' do
metadata CHANGED
@@ -1,63 +1,60 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: chunky_png
3
- version: !ruby/object:Gem::Version
4
- hash: 23
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.5
5
5
  prerelease:
6
- segments:
7
- - 1
8
- - 2
9
- - 4
10
- version: 1.2.4
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Willem van Bergen
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-09-14 00:00:00 -04:00
12
+ date: 2011-09-23 00:00:00.000000000 -04:00
19
13
  default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
22
16
  name: rake
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &2153017100 !ruby/object:Gem::Requirement
25
18
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
33
23
  type: :development
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: rspec
37
24
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: *2153017100
26
+ - !ruby/object:Gem::Dependency
27
+ name: rspec
28
+ requirement: &2153016480 !ruby/object:Gem::Requirement
39
29
  none: false
40
- requirements:
30
+ requirements:
41
31
  - - ~>
42
- - !ruby/object:Gem::Version
43
- hash: 7
44
- segments:
45
- - 2
46
- - 2
47
- version: "2.2"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.2'
48
34
  type: :development
49
- version_requirements: *id002
50
- description: " This pure Ruby library can read and write PNG images without depending on an external \n image library, like RMagick. It tries to be memory efficient and reasonably fast.\n \n It supports reading and writing all PNG variants that are defined in the specification, \n with one limitation: only 8-bit color depth is supported. It supports all transparency, \n interlacing and filtering options the PNG specifications allows. It can also read and \n write textual metadata from PNG files. Low-level read/write access to PNG chunks is\n also possible.\n \n This library supports simple drawing on the image canvas and simple operations like\n alpha composition and cropping. Finally, it can import from and export to RMagick for \n interoperability.\n \n Also, have a look at OilyPNG at http://github.com/wvanbergen/oily_png. OilyPNG is a \n drop in mixin module that implements some of the ChunkyPNG algorithms in C, which \n provides a massive speed boost to encoding and decoding.\n"
51
- email:
35
+ prerelease: false
36
+ version_requirements: *2153016480
37
+ description: ! " This pure Ruby library can read and write PNG images without depending
38
+ on an external \n image library, like RMagick. It tries to be memory efficient
39
+ and reasonably fast.\n \n It supports reading and writing all PNG variants
40
+ that are defined in the specification, \n with one limitation: only 8-bit color
41
+ depth is supported. It supports all transparency, \n interlacing and filtering
42
+ options the PNG specifications allows. It can also read and \n write textual
43
+ metadata from PNG files. Low-level read/write access to PNG chunks is\n also
44
+ possible.\n \n This library supports simple drawing on the image canvas and
45
+ simple operations like\n alpha composition and cropping. Finally, it can import
46
+ from and export to RMagick for \n interoperability.\n \n Also, have a look
47
+ at OilyPNG at http://github.com/wvanbergen/oily_png. OilyPNG is a \n drop in
48
+ mixin module that implements some of the ChunkyPNG algorithms in C, which \n provides
49
+ a massive speed boost to encoding and decoding.\n"
50
+ email:
52
51
  - willem@railsdoctors.com
53
52
  executables: []
54
-
55
53
  extensions: []
56
-
57
- extra_rdoc_files:
54
+ extra_rdoc_files:
58
55
  - README.rdoc
59
56
  - BENCHMARKS.rdoc
60
- files:
57
+ files:
61
58
  - .gitignore
62
59
  - .infinity_test
63
60
  - .travis.yml
@@ -378,43 +375,35 @@ files:
378
375
  has_rdoc: true
379
376
  homepage: http://wiki.github.com/wvanbergen/chunky_png
380
377
  licenses: []
381
-
382
378
  post_install_message:
383
- rdoc_options:
379
+ rdoc_options:
384
380
  - --title
385
381
  - chunky_png
386
382
  - --main
387
383
  - README.rdoc
388
384
  - --line-numbers
389
385
  - --inline-source
390
- require_paths:
386
+ require_paths:
391
387
  - lib
392
- required_ruby_version: !ruby/object:Gem::Requirement
388
+ required_ruby_version: !ruby/object:Gem::Requirement
393
389
  none: false
394
- requirements:
395
- - - ">="
396
- - !ruby/object:Gem::Version
397
- hash: 3
398
- segments:
399
- - 0
400
- version: "0"
401
- required_rubygems_version: !ruby/object:Gem::Requirement
390
+ requirements:
391
+ - - ! '>='
392
+ - !ruby/object:Gem::Version
393
+ version: '0'
394
+ required_rubygems_version: !ruby/object:Gem::Requirement
402
395
  none: false
403
- requirements:
404
- - - ">="
405
- - !ruby/object:Gem::Version
406
- hash: 3
407
- segments:
408
- - 0
409
- version: "0"
396
+ requirements:
397
+ - - ! '>='
398
+ - !ruby/object:Gem::Version
399
+ version: '0'
410
400
  requirements: []
411
-
412
401
  rubyforge_project:
413
402
  rubygems_version: 1.6.2
414
403
  signing_key:
415
404
  specification_version: 3
416
405
  summary: Pure ruby library for read/write, chunk-level access to PNG files
417
- test_files:
406
+ test_files:
418
407
  - spec/chunky_png/canvas/adam7_interlacing_spec.rb
419
408
  - spec/chunky_png/canvas/data_url_exporting_spec.rb
420
409
  - spec/chunky_png/canvas/data_url_importing_spec.rb