chunky_png 1.3.7 → 1.3.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +5 -5
  2. data/.standard.yml +16 -0
  3. data/.travis.yml +8 -6
  4. data/.yardopts +1 -1
  5. data/CHANGELOG.rdoc +17 -1
  6. data/CONTRIBUTING.rdoc +17 -8
  7. data/Gemfile +3 -3
  8. data/LICENSE +1 -1
  9. data/README.md +6 -1
  10. data/Rakefile +3 -3
  11. data/benchmarks/decoding_benchmark.rb +17 -17
  12. data/benchmarks/encoding_benchmark.rb +22 -19
  13. data/benchmarks/filesize_benchmark.rb +6 -6
  14. data/bin/rake +29 -0
  15. data/bin/standardrb +29 -0
  16. data/chunky_png.gemspec +19 -15
  17. data/lib/chunky_png.rb +49 -39
  18. data/lib/chunky_png/canvas.rb +28 -27
  19. data/lib/chunky_png/canvas/adam7_interlacing.rb +14 -10
  20. data/lib/chunky_png/canvas/data_url_exporting.rb +1 -3
  21. data/lib/chunky_png/canvas/data_url_importing.rb +1 -3
  22. data/lib/chunky_png/canvas/drawing.rb +28 -43
  23. data/lib/chunky_png/canvas/masking.rb +12 -14
  24. data/lib/chunky_png/canvas/operations.rb +26 -24
  25. data/lib/chunky_png/canvas/png_decoding.rb +36 -32
  26. data/lib/chunky_png/canvas/png_encoding.rb +106 -100
  27. data/lib/chunky_png/canvas/resampling.rb +26 -33
  28. data/lib/chunky_png/canvas/stream_exporting.rb +6 -8
  29. data/lib/chunky_png/canvas/stream_importing.rb +6 -8
  30. data/lib/chunky_png/chunk.rb +141 -52
  31. data/lib/chunky_png/color.rb +211 -206
  32. data/lib/chunky_png/datastream.rb +27 -23
  33. data/lib/chunky_png/dimension.rb +16 -11
  34. data/lib/chunky_png/image.rb +9 -11
  35. data/lib/chunky_png/palette.rb +4 -9
  36. data/lib/chunky_png/point.rb +25 -26
  37. data/lib/chunky_png/rmagick.rb +8 -10
  38. data/lib/chunky_png/vector.rb +26 -29
  39. data/lib/chunky_png/version.rb +1 -1
  40. data/spec/chunky_png/canvas/adam7_interlacing_spec.rb +20 -21
  41. data/spec/chunky_png/canvas/data_url_exporting_spec.rb +8 -5
  42. data/spec/chunky_png/canvas/data_url_importing_spec.rb +5 -6
  43. data/spec/chunky_png/canvas/drawing_spec.rb +46 -38
  44. data/spec/chunky_png/canvas/masking_spec.rb +15 -16
  45. data/spec/chunky_png/canvas/operations_spec.rb +68 -67
  46. data/spec/chunky_png/canvas/png_decoding_spec.rb +37 -38
  47. data/spec/chunky_png/canvas/png_encoding_spec.rb +59 -50
  48. data/spec/chunky_png/canvas/resampling_spec.rb +19 -21
  49. data/spec/chunky_png/canvas/stream_exporting_spec.rb +47 -27
  50. data/spec/chunky_png/canvas/stream_importing_spec.rb +10 -11
  51. data/spec/chunky_png/canvas_spec.rb +57 -52
  52. data/spec/chunky_png/color_spec.rb +115 -114
  53. data/spec/chunky_png/datastream_spec.rb +110 -13
  54. data/spec/chunky_png/dimension_spec.rb +10 -10
  55. data/spec/chunky_png/image_spec.rb +11 -14
  56. data/spec/chunky_png/point_spec.rb +21 -23
  57. data/spec/chunky_png/rmagick_spec.rb +7 -8
  58. data/spec/chunky_png/vector_spec.rb +21 -17
  59. data/spec/chunky_png_spec.rb +2 -2
  60. data/spec/png_suite_spec.rb +35 -40
  61. data/spec/resources/itxt_chunk.png +0 -0
  62. data/spec/spec_helper.rb +15 -9
  63. data/tasks/benchmarks.rake +7 -8
  64. metadata +53 -20
  65. data/lib/chunky_png/compatibility.rb +0 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 2774ecc9f2d9e0bb09588d857ec1bf66fe0161e2
4
- data.tar.gz: 0144ec4242f3bf5c180a8ef5a1bb51fd3e42ca65
2
+ SHA256:
3
+ metadata.gz: e3886829e15fc95fe5233136b1f7ecd373b6996aa7d272ea23a7118b2f686da9
4
+ data.tar.gz: f43c2996448bce3e0dd614b19e228ead043be3f1fbc60ca128d7a242f4f74692
5
5
  SHA512:
6
- metadata.gz: ea93bfb789b22f4158605984c46fdc333a6e2a83d4f0cf2165b739be6da12383128fd61d89558bed9cef213d8546010c482b1244ccc3aa2423eb1943a0df3c34
7
- data.tar.gz: baa158877d3f95359219b5a4c1d31e517a9853a947567a3e5bb4d27c5d9ab876be7321b5e7087d5e56f7895b0e5d515f0d2c44c2d3acb35ba32e92ab7cc9d00a
6
+ metadata.gz: 610eacb3d1e369c824bd4b7e9305358790be1837281be84f44ff12e4020bced6fd9ef44b10391578eb74b50a0e28b24595ac0aa64b82433477a05b43a37bd491
7
+ data.tar.gz: e4857a8bb6217e5416b93bcd125dd7e99a90f0bb2714628016d6e44af9b34a03230913e30955a4f72ff2005fb9b9e6f50d1087d6cb89d9370cc735288d98193b
@@ -0,0 +1,16 @@
1
+ # ChunkyPNG uses and enforces standard.rb as code style (see https://github.com/testdouble/standard).
2
+ # For backwards compatilibity and idiosyncratic preferences of the main author,
3
+ # there are some minor differences listed in here.
4
+
5
+ ruby_version: 2.2
6
+
7
+ ignore:
8
+ - lib/chunky_png/**/*.rb:
9
+ # We allow `for` loops in the codebase, especially in hot paths,
10
+ # because they perform better than `each` blocks.
11
+ - "Style/For"
12
+
13
+ - spec/chunky_png/**/*.rb:
14
+ # In RSpec, having to follow this rule will cause expectations to
15
+ # be less readable, specifically blocks for the `change` matcher.
16
+ - "Lint/AmbiguousBlockAssociation"
@@ -1,16 +1,18 @@
1
1
  language: ruby
2
- script: bundle exec rake
3
- sudo: false
2
+
3
+ script:
4
+ - bin/rake
5
+ - bin/standardrb
4
6
 
5
7
  rvm:
6
- - "2.0"
7
- - "2.1"
8
8
  - "2.2"
9
+ - "2.3"
10
+ - "2.4"
11
+ - "2.5"
12
+ - "2.6"
9
13
  - ruby-head
10
- - rbx-19mode
11
14
  - jruby-19mode
12
15
 
13
16
  matrix:
14
17
  allow_failures:
15
- - rvm: rbx-19mode
16
18
  - rvm: ruby-head
data/.yardopts CHANGED
@@ -1,5 +1,5 @@
1
1
  --title "ChunkyPNG - The pure Ruby PNG library"
2
2
  lib/**/*.rb -
3
- BENCHMARKS.rdoc
3
+ BENCHMARKING.rdoc
4
4
  --no-private
5
5
  --hide-void-return
@@ -7,7 +7,23 @@ The file documents the changes to this library over the different versions.
7
7
 
8
8
  === Unreleased changes
9
9
 
10
- - Nothing yet!
10
+ - Implemented <tt>ChunkyPNG::Dimension#hash</tt> to fix some specs after a behavior change in RSpec.
11
+
12
+ === 1.3.11 - 2018-11-21
13
+
14
+ - Updated project metadata as published on Rubygems.org
15
+
16
+ === 1.3.10 - 2018-01-23
17
+
18
+ - Fixed a regression in Datastream#metadata, which was not able to deal with iTXt chunks.
19
+
20
+ === 1.3.9 - 2018-01-23
21
+
22
+ - Add support for reading and writing an international textual data (iTXt chunks).
23
+
24
+ === 1.3.8 - 2016-08-31
25
+
26
+ - Add support for reading and writing an image's physical dimension (pHYs chunks).
11
27
 
12
28
  === 1.3.7 - 2016-08-31
13
29
 
@@ -1,21 +1,30 @@
1
1
  = Contributing to ChunkyPNG
2
2
 
3
- I will gladly accept any contributions from anybody to improve this library. However, I like to keep
4
- the scope and complexity of this project relatively small. This way, with the limited amount of time I
5
- dedicate to this project, this library remains a solid piece of software that many people rely on in
6
- their workflow.
3
+ I will gladly accept any contributions from anybody to improve this library. However, this is a
4
+ personal open source project, without an active community around it. As a result I am the only
5
+ maintainer, and I’d like to keep the scope and complexity of this project small.
6
+ This way, with the limited amount of time I dedicate to this project, this library remains a
7
+ solid piece of software that many people rely on in their workflow.
7
8
 
8
9
 
9
10
  == Project scope
10
11
 
11
12
  The scope of this library is defined as:
12
13
 
13
- 1. Reading and writing any PNG image that conforms to the spec, with proper handling of images that do not.
14
+ 1. Reading and writing any PNG image that conforms to the spec, with proper error handling of
15
+ images that do not conform to the spec.
14
16
  2. Basic canvas drawing and compositing operations to create new or edit existing images.
17
+ However, I will generally be hesitant to add new drawing and compositing methods, because
18
+ the list could be endless to support every niche use case.
15
19
  3. Remain compatible with Ruby versions that are widely used.
16
20
 
17
- I will close issues and pull requests that go beyond this scope. If you want to work on something,
18
- but are not sure if it will be in scope, feel free to reach out to me!
21
+ I generally consider this gem to be feature complete based on this scope. I will close issues
22
+ and pull requests that go beyond this scope. If you want to work on something, but are not sure
23
+ if it will be accepted, feel free to reach out to me by opening an issue before committing your time.
24
+
25
+ For functionality that goes beyond the scope, I would suggest making it available as a separate
26
+ “plugin” gem (e.g. chunky_png-<my-feature>). If anything in the gem needs to be refactored
27
+ to support this kind of extensibility, I am happy to accept PRs for that.
19
28
 
20
29
 
21
30
  == Reporting bugs
@@ -38,7 +47,7 @@ Title and description:
38
47
  Code:
39
48
 
40
49
  - Don't break backwards compatibility.
41
- - Follow code conventions. They are not defined, so look at the code around you.
50
+ - Follow code conventions. They are enforced through Rubocop.
42
51
  - Add Yardoc comments as documentation.
43
52
 
44
53
  Specs:
data/Gemfile CHANGED
@@ -1,10 +1,10 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
  gemspec
3
3
 
4
4
  platforms :jruby do
5
- gem 'jruby-openssl'
5
+ gem "jruby-openssl"
6
6
  end
7
7
 
8
8
  platform :rbx do
9
- gem 'rubysl'
9
+ gem "rubysl"
10
10
  end
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2015 Willem van Bergen
1
+ Copyright (c) 2010-2019 Willem van Bergen
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -80,7 +80,12 @@ background processing library.
80
80
 
81
81
  The library is written by Willem van Bergen for Floorplanner.com, and released
82
82
  under the MIT license (see LICENSE). Please contact me for questions or
83
- remarks. Patches are greatly appreciated!
83
+ remarks.
84
+
85
+ I generally consider this library to be feature complete. I will gladly accept
86
+ patches to fix bugs and improve performance, but I will generally be hesitant
87
+ to accept new features or API endpoints. Before contributing, please read
88
+ [CONTRIBUTING.rdoc](CONTRIBUTING.rdoc) that explains this in more detail.
84
89
 
85
90
  Please check out CHANGELOG.rdoc to see what changed in all versions.
86
91
 
data/Rakefile CHANGED
@@ -1,11 +1,11 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
3
 
4
- Dir['tasks/*.rake'].each { |file| load(file) }
4
+ Dir["tasks/*.rake"].each { |file| load(file) }
5
5
 
6
6
  RSpec::Core::RakeTask.new(:spec) do |task|
7
7
  task.pattern = "./spec/**/*_spec.rb"
8
- task.rspec_opts = ['--color']
8
+ task.rspec_opts = ["--color"]
9
9
  end
10
10
 
11
- task :default => [:spec]
11
+ task default: [:spec]
@@ -1,26 +1,26 @@
1
- require 'rubygems'
2
- require 'bundler/setup'
1
+ require "rubygems"
2
+ require "bundler/setup"
3
3
 
4
- require 'benchmark'
5
- require 'chunky_png'
4
+ require "benchmark"
5
+ require "chunky_png"
6
6
 
7
7
  def image_file(name)
8
- File.join(File.dirname(__FILE__), '..', 'spec', 'resources', name)
8
+ File.join(File.dirname(__FILE__), "..", "spec", "resources", name)
9
9
  end
10
10
 
11
11
  def image_data(name)
12
12
  data = nil
13
- File.open(image_file(name), 'rb') { |f| data = f.read }
13
+ File.open(image_file(name), "rb") { |f| data = f.read }
14
14
  data
15
15
  end
16
16
 
17
- no_filtering_stream = image_data('pixelstream_fast_rgba.png')
18
- up_filtering_stream = image_data('pixelstream_reference.png')
19
- paeth_filtering_stream = image_data('pixelstream_best_compression.png')
20
- rgba_pixelstream = image_data('pixelstream.rgba')
21
- rgb_pixelstream = image_data('pixelstream.rgb')
17
+ no_filtering_stream = image_data("pixelstream_fast_rgba.png")
18
+ up_filtering_stream = image_data("pixelstream_reference.png")
19
+ paeth_filtering_stream = image_data("pixelstream_best_compression.png")
20
+ rgba_pixelstream = image_data("pixelstream.rgba")
21
+ rgb_pixelstream = image_data("pixelstream.rgb")
22
22
 
23
- n = (ENV['N'] || '5').to_i
23
+ n = (ENV["N"] || "5").to_i
24
24
 
25
25
  puts "---------------------------------------------"
26
26
  puts "ChunkyPNG (#{ChunkyPNG::VERSION}) decoding benchmark (n=#{n})"
@@ -28,9 +28,9 @@ puts "---------------------------------------------"
28
28
  puts
29
29
 
30
30
  Benchmark.bmbm do |x|
31
- x.report('PNG - no filtering') { n.times { ChunkyPNG::Image.from_blob(no_filtering_stream) } }
32
- x.report('PNG - UP filtering') { n.times { ChunkyPNG::Image.from_blob(up_filtering_stream) } }
33
- x.report('PNG - PAETH filtering') { n.times { ChunkyPNG::Image.from_blob(paeth_filtering_stream) } }
34
- x.report('From RGBA pixelstream') { n.times { ChunkyPNG::Image.from_rgba_stream(240, 180, rgba_pixelstream) } }
35
- x.report('From RGB pixelstream') { n.times { ChunkyPNG::Image.from_rgb_stream(240, 180, rgb_pixelstream) } }
31
+ x.report("PNG - no filtering") { n.times { ChunkyPNG::Image.from_blob(no_filtering_stream) } }
32
+ x.report("PNG - UP filtering") { n.times { ChunkyPNG::Image.from_blob(up_filtering_stream) } }
33
+ x.report("PNG - PAETH filtering") { n.times { ChunkyPNG::Image.from_blob(paeth_filtering_stream) } }
34
+ x.report("From RGBA pixelstream") { n.times { ChunkyPNG::Image.from_rgba_stream(240, 180, rgba_pixelstream) } }
35
+ x.report("From RGB pixelstream") { n.times { ChunkyPNG::Image.from_rgb_stream(240, 180, rgb_pixelstream) } }
36
36
  end
@@ -1,17 +1,20 @@
1
- require 'rubygems'
2
- require 'bundler/setup'
1
+ require "rubygems"
2
+ require "bundler/setup"
3
3
 
4
- require 'benchmark'
5
- require 'chunky_png'
4
+ require "benchmark"
5
+ require "chunky_png"
6
6
 
7
7
  image = ChunkyPNG::Image.new(240, 180, ChunkyPNG::Color::TRANSPARENT)
8
8
 
9
9
  # set some random pixels
10
+
11
+ # rubocop:disable Layout/ExtraSpacing, Layout/SpaceInsideParens
10
12
  image[10, 20] = ChunkyPNG::Color.rgba(255, 0, 0, 255)
11
13
  image[50, 87] = ChunkyPNG::Color.rgba( 0, 255, 0, 255)
12
14
  image[33, 99] = ChunkyPNG::Color.rgba( 0, 0, 255, 255)
15
+ # rubocop:enable Layout/ExtraSpacing, Layout/SpaceInsideParens
13
16
 
14
- n = (ENV['N'] || '5').to_i
17
+ n = (ENV["N"] || "5").to_i
15
18
 
16
19
  puts "---------------------------------------------"
17
20
  puts "ChunkyPNG (#{ChunkyPNG::VERSION}) encoding benchmark (n=#{n})"
@@ -19,22 +22,22 @@ puts "---------------------------------------------"
19
22
  puts
20
23
 
21
24
  Benchmark.bmbm do |x|
22
- x.report('Autodetect (indexed)') { n.times { image.to_blob } }
25
+ x.report("Autodetect (indexed)") { n.times { image.to_blob } }
23
26
 
24
27
  # Presets
25
- x.report(':no_compression') { n.times { image.to_blob(:no_compression) } }
26
- x.report(':fast_rgba') { n.times { image.to_blob(:fast_rgba) } }
27
- x.report(':fast_rgb') { n.times { image.to_blob(:fast_rgb) } }
28
- x.report(':good_compression') { n.times { image.to_blob(:good_compression) } }
29
- x.report(':best_compression') { n.times { image.to_blob(:best_compression) } }
30
-
28
+ x.report(":no_compression") { n.times { image.to_blob(:no_compression) } }
29
+ x.report(":fast_rgba") { n.times { image.to_blob(:fast_rgba) } }
30
+ x.report(":fast_rgb") { n.times { image.to_blob(:fast_rgb) } }
31
+ x.report(":good_compression") { n.times { image.to_blob(:good_compression) } }
32
+ x.report(":best_compression") { n.times { image.to_blob(:best_compression) } }
33
+
31
34
  # Some options
32
- x.report(':rgb') { n.times { image.to_blob(:color_mode => ChunkyPNG::COLOR_TRUECOLOR) } }
33
- x.report(':rgba') { n.times { image.to_blob(:color_mode => ChunkyPNG::COLOR_TRUECOLOR_ALPHA) } }
34
- x.report(':indexed') { n.times { image.to_blob(:color_mode => ChunkyPNG::COLOR_INDEXED) } }
35
- x.report(':interlaced') { n.times { image.to_blob(:interlaced => true) } }
36
-
35
+ x.report(":rgb") { n.times { image.to_blob(color_mode: ChunkyPNG::COLOR_TRUECOLOR) } }
36
+ x.report(":rgba") { n.times { image.to_blob(color_mode: ChunkyPNG::COLOR_TRUECOLOR_ALPHA) } }
37
+ x.report(":indexed") { n.times { image.to_blob(color_mode: ChunkyPNG::COLOR_INDEXED) } }
38
+ x.report(":interlaced") { n.times { image.to_blob(interlaced: true) } }
39
+
37
40
  # Exports
38
- x.report('to RGBA pixelstream') { n.times { image.to_rgba_stream } }
39
- x.report('to RGB pixelstream') { n.times { image.to_rgb_stream } }
41
+ x.report("to RGBA pixelstream") { n.times { image.to_rgba_stream } }
42
+ x.report("to RGB pixelstream") { n.times { image.to_rgb_stream } }
40
43
  end
@@ -1,10 +1,10 @@
1
- require 'rubygems'
2
- require 'bundler/setup'
1
+ require "rubygems"
2
+ require "bundler/setup"
3
3
 
4
- require 'benchmark'
5
- require 'chunky_png'
4
+ require "benchmark"
5
+ require "chunky_png"
6
6
 
7
- files = ['pixelstream_reference.png', 'operations.png', 'clock.png']
7
+ files = ["pixelstream_reference.png", "operations.png", "clock.png"]
8
8
 
9
9
  def encode_png(image, constraints = {})
10
10
  filesize = nil
@@ -13,7 +13,7 @@ def encode_png(image, constraints = {})
13
13
  end
14
14
 
15
15
  files.each do |file|
16
- filename = File.join(File.dirname(__FILE__), '..', 'spec', 'resources', file)
16
+ filename = File.join(File.dirname(__FILE__), "..", "spec", "resources", file)
17
17
  image = ChunkyPNG::Canvas.from_file(filename)
18
18
 
19
19
  puts "#{file}: #{image.width}x#{image.height} - #{image.palette.size} colors"
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rake' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rake", "rake")
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'standardrb' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("standard", "standardrb")
@@ -1,11 +1,9 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path("../lib", __FILE__)
4
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require 'chunky_png/version'
3
+ require "chunky_png/version"
6
4
 
7
5
  Gem::Specification.new do |s|
8
- s.name = 'chunky_png'
6
+ s.name = "chunky_png"
9
7
 
10
8
  # Do not change the version and date fields by hand. This will be done
11
9
  # automatically by the gem release script.
@@ -31,16 +29,22 @@ Gem::Specification.new do |s|
31
29
  provides a massive speed boost to encoding and decoding.
32
30
  EOT
33
31
 
34
- s.authors = ['Willem van Bergen']
35
- s.email = ['willem@railsdoctors.com']
36
- s.homepage = 'http://wiki.github.com/wvanbergen/chunky_png'
37
- s.license = 'MIT'
38
-
39
- s.add_development_dependency('rake')
40
- s.add_development_dependency('rspec', '~> 3')
41
-
42
- s.rdoc_options << '--title' << s.name << '--main' << 'README.rdoc' << '--line-numbers' << '--inline-source'
43
- s.extra_rdoc_files = ['README.md', 'BENCHMARKING.rdoc', 'CONTRIBUTING.rdoc', 'CHANGELOG.rdoc']
32
+ s.authors = ["Willem van Bergen"]
33
+ s.email = ["willem@railsdoctors.com"]
34
+ s.homepage = "https://github.com/wvanbergen/chunky_png/wiki"
35
+ s.license = "MIT"
36
+ s.metadata = {
37
+ "source_code_uri" => "https://github.com/wvanbergen/chunky_png",
38
+ "wiki_uri" => "https://github.com/wvanbergen/chunky_png/wiki",
39
+ }
40
+
41
+ s.add_development_dependency("rake")
42
+ s.add_development_dependency("standard")
43
+ s.add_development_dependency("yard", "~> 0.9")
44
+ s.add_development_dependency("rspec", "~> 3")
45
+
46
+ s.rdoc_options << "--title" << s.name << "--main" << "README.rdoc" << "--line-numbers" << "--inline-source"
47
+ s.extra_rdoc_files = ["README.md", "BENCHMARKING.rdoc", "CONTRIBUTING.rdoc", "CHANGELOG.rdoc"]
44
48
 
45
49
  s.files = `git ls-files`.split($/)
46
50
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
@@ -1,13 +1,12 @@
1
1
  # Basic requirements from standard library
2
- require 'set'
3
- require 'zlib'
4
- require 'stringio'
5
- require 'enumerator'
2
+ require "set"
3
+ require "zlib"
4
+ require "stringio"
6
5
 
7
6
  # ChunkyPNG - the pure ruby library to access PNG files.
8
7
  #
9
8
  # The ChunkyPNG module defines some constants that are used in the
10
- # PNG specification, specifies some exception classes, and serves as
9
+ # PNG specification, specifies some exception classes, and serves as
11
10
  # a namespace for all the other modules and classes in this library.
12
11
  #
13
12
  # {ChunkyPNG::Image}:: class to represent PNG images, including metadata.
@@ -22,32 +21,31 @@ require 'enumerator'
22
21
  #
23
22
  # @author Willem van Bergen
24
23
  module ChunkyPNG
25
-
26
24
  ###################################################
27
25
  # PNG international standard defined constants
28
26
  ###################################################
29
27
 
30
- # Indicates that the PNG image uses grayscale colors, i.e. only a
28
+ # Indicates that the PNG image uses grayscale colors, i.e. only a
31
29
  # single teint channel.
32
30
  # @private
33
31
  COLOR_GRAYSCALE = 0
34
-
32
+
35
33
  # Indicates that the PNG image uses true color, composed of a red
36
34
  # green and blue channel.
37
35
  # @private
38
36
  COLOR_TRUECOLOR = 2
39
-
37
+
40
38
  # Indicates that the PNG image uses indexed colors, where the values
41
39
  # point to colors defined on a palette.
42
40
  # @private
43
41
  COLOR_INDEXED = 3
44
-
42
+
45
43
  # Indicates that the PNG image uses grayscale colors with opacity, i.e.
46
44
  # a teint channel with an alpha channel.
47
45
  # @private
48
46
  COLOR_GRAYSCALE_ALPHA = 4
49
-
50
- # Indicates that the PNG image uses true color with opacity, composed of
47
+
48
+ # Indicates that the PNG image uses true color with opacity, composed of
51
49
  # a red, green and blue channel, and an alpha value.
52
50
  # @private
53
51
  COLOR_TRUECOLOR_ALPHA = 6
@@ -57,12 +55,22 @@ module ChunkyPNG
57
55
  # @private
58
56
  COMPRESSION_DEFAULT = 0
59
57
 
58
+ # Indicates that the PNG chunk content is not compressed
59
+ # flag used in iTXt chunk
60
+ # @private
61
+ UNCOMPRESSED_CONTENT = 0
62
+
63
+ # Indicates that the PNG chunk content is compressed
64
+ # flag used in iTXt chunk
65
+ # @private
66
+ COMPRESSED_CONTENT = 1
67
+
60
68
  # Indicates that the image does not use interlacing.
61
69
  # @private
62
70
  INTERLACING_NONE = 0
63
-
71
+
64
72
  # Indicates that the image uses Adam7 interlacing.
65
- # @private
73
+ # @private
66
74
  INTERLACING_ADAM7 = 1
67
75
 
68
76
  ### Filter method constants
@@ -75,19 +83,19 @@ module ChunkyPNG
75
83
  # Indicates that no filtering is used for the scanline.
76
84
  # @private
77
85
  FILTER_NONE = 0
78
-
86
+
79
87
  # Indicates that SUB filtering is used for the scanline.
80
88
  # @private
81
89
  FILTER_SUB = 1
82
-
90
+
83
91
  # Indicates that UP filtering is used for the scanline.
84
92
  # @private
85
93
  FILTER_UP = 2
86
-
94
+
87
95
  # Indicates that AVERAGE filtering is used for the scanline.
88
96
  # @private
89
97
  FILTER_AVERAGE = 3
90
-
98
+
91
99
  # Indicates that PAETH filtering is used for the scanline.
92
100
  # @private
93
101
  FILTER_PAETH = 4
@@ -104,7 +112,7 @@ module ChunkyPNG
104
112
  class NotSupported < ChunkyPNG::Exception
105
113
  end
106
114
 
107
- # Exception that is raised if the PNG signature is not encountered at the
115
+ # Exception that is raised if the PNG signature is not encountered at the
108
116
  # beginning of the file.
109
117
  class SignatureMismatch < ChunkyPNG::Exception
110
118
  end
@@ -113,48 +121,50 @@ module ChunkyPNG
113
121
  class CRCMismatch < ChunkyPNG::Exception
114
122
  end
115
123
 
124
+ # Exception that is raised if an tTXt chunk does not contain valid UTF-8 data.
125
+ class InvalidUTF8 < ChunkyPNG::Exception
126
+ end
127
+
116
128
  # Exception that is raised if an expectation fails.
117
129
  class ExpectationFailed < ChunkyPNG::Exception
118
130
  end
119
131
 
120
- # Exception that is raised if an expectation fails.
132
+ # Exception that when provided coordinates are out of bounds for the canvas
121
133
  class OutOfBounds < ChunkyPNG::ExpectationFailed
122
134
  end
123
135
 
124
- def self.force_binary(str)
125
- str.respond_to?(:force_encoding) ? str.force_encoding('BINARY') : str
136
+ # Exception that is raised when requesting the DPI of a PNG that doesn't
137
+ # specify the units of its physical pixel dimensions.
138
+ class UnitsUnknown < ChunkyPNG::Exception
126
139
  end
127
-
140
+
128
141
  # Empty byte array. This basically is an empty string, but with the encoding
129
142
  # set correctly to ASCII-8BIT (binary) in Ruby 1.9.
130
143
  # @return [String] An empty string, with encoding set to binary in Ruby 1.9
131
144
  # @private
132
- EMPTY_BYTEARRAY = force_binary(String.new).freeze
145
+ EMPTY_BYTEARRAY = "".force_encoding(Encoding::BINARY).freeze
133
146
 
134
147
  # Null-byte, with the encoding set correctly to ASCII-8BIT (binary) in Ruby 1.9.
135
- # @return [String] A binary string, consisting of one NULL-byte.
148
+ # @return [String] A binary string, consisting of one NULL-byte.
136
149
  # @private
137
- EXTRA_BYTE = force_binary(String.new("\0")).freeze
150
+ EXTRA_BYTE = "\0".force_encoding(Encoding::BINARY).freeze
138
151
  end
139
152
 
140
- require 'chunky_png/version'
141
-
142
- # Ruby 1.8 / 1.9 compatibility
143
- require 'chunky_png/compatibility'
153
+ require "chunky_png/version"
144
154
 
145
155
  # PNG file structure
146
- require 'chunky_png/datastream'
147
- require 'chunky_png/chunk'
156
+ require "chunky_png/datastream"
157
+ require "chunky_png/chunk"
148
158
 
149
159
  # Colors
150
- require 'chunky_png/palette'
151
- require 'chunky_png/color'
160
+ require "chunky_png/palette"
161
+ require "chunky_png/color"
152
162
 
153
163
  # Geometry
154
- require 'chunky_png/point'
155
- require 'chunky_png/vector'
156
- require 'chunky_png/dimension'
164
+ require "chunky_png/point"
165
+ require "chunky_png/vector"
166
+ require "chunky_png/dimension"
157
167
 
158
168
  # Canvas / Image classes
159
- require 'chunky_png/canvas'
160
- require 'chunky_png/image'
169
+ require "chunky_png/canvas"
170
+ require "chunky_png/image"