chunky_png 1.3.5 → 1.3.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/ruby.yml +35 -0
- data/.standard.yml +16 -0
- data/.yardopts +1 -1
- data/CHANGELOG.rdoc +38 -4
- data/CONTRIBUTING.rdoc +17 -8
- data/Gemfile +12 -4
- data/LICENSE +1 -1
- data/README.md +94 -0
- data/Rakefile +5 -3
- data/benchmarks/decoding_benchmark.rb +17 -17
- data/benchmarks/encoding_benchmark.rb +22 -19
- data/benchmarks/filesize_benchmark.rb +6 -6
- data/bin/rake +29 -0
- data/bin/standardrb +29 -0
- data/chunky_png.gemspec +21 -13
- data/docs/.gitignore +3 -0
- data/docs/CNAME +1 -0
- data/docs/_config.yml +9 -0
- data/docs/_posts/2010-01-14-memory-efficiency-when-using-ruby.md +136 -0
- data/docs/_posts/2010-01-17-ode-to-array-pack-and-string-unpack.md +82 -0
- data/docs/_posts/2014-11-07-the-value-of-a-pure-ruby-library.md +61 -0
- data/{README.rdoc → docs/index.md} +28 -24
- data/lib/chunky_png/canvas/adam7_interlacing.rb +16 -10
- data/lib/chunky_png/canvas/data_url_exporting.rb +3 -3
- data/lib/chunky_png/canvas/data_url_importing.rb +3 -3
- data/lib/chunky_png/canvas/drawing.rb +34 -47
- data/lib/chunky_png/canvas/masking.rb +14 -14
- data/lib/chunky_png/canvas/operations.rb +28 -25
- data/lib/chunky_png/canvas/png_decoding.rb +104 -99
- data/lib/chunky_png/canvas/png_encoding.rb +111 -103
- data/lib/chunky_png/canvas/resampling.rb +27 -32
- data/lib/chunky_png/canvas/stream_exporting.rb +8 -8
- data/lib/chunky_png/canvas/stream_importing.rb +8 -8
- data/lib/chunky_png/canvas.rb +31 -28
- data/lib/chunky_png/chunk.rb +170 -55
- data/lib/chunky_png/color.rb +221 -213
- data/lib/chunky_png/datastream.rb +30 -30
- data/lib/chunky_png/dimension.rb +18 -11
- data/lib/chunky_png/image.rb +11 -11
- data/lib/chunky_png/palette.rb +13 -14
- data/lib/chunky_png/point.rb +27 -26
- data/lib/chunky_png/rmagick.rb +10 -10
- data/lib/chunky_png/vector.rb +28 -29
- data/lib/chunky_png/version.rb +3 -1
- data/lib/chunky_png.rb +49 -43
- data/spec/chunky_png/canvas/adam7_interlacing_spec.rb +20 -21
- data/spec/chunky_png/canvas/data_url_exporting_spec.rb +8 -5
- data/spec/chunky_png/canvas/data_url_importing_spec.rb +5 -6
- data/spec/chunky_png/canvas/drawing_spec.rb +46 -38
- data/spec/chunky_png/canvas/masking_spec.rb +15 -16
- data/spec/chunky_png/canvas/operations_spec.rb +68 -67
- data/spec/chunky_png/canvas/png_decoding_spec.rb +37 -38
- data/spec/chunky_png/canvas/png_encoding_spec.rb +59 -50
- data/spec/chunky_png/canvas/resampling_spec.rb +19 -21
- data/spec/chunky_png/canvas/stream_exporting_spec.rb +47 -27
- data/spec/chunky_png/canvas/stream_importing_spec.rb +10 -11
- data/spec/chunky_png/canvas_spec.rb +63 -52
- data/spec/chunky_png/color_spec.rb +115 -114
- data/spec/chunky_png/datastream_spec.rb +115 -12
- data/spec/chunky_png/dimension_spec.rb +10 -10
- data/spec/chunky_png/image_spec.rb +11 -14
- data/spec/chunky_png/point_spec.rb +21 -23
- data/spec/chunky_png/rmagick_spec.rb +7 -8
- data/spec/chunky_png/vector_spec.rb +21 -17
- data/spec/chunky_png_spec.rb +2 -2
- data/spec/png_suite_spec.rb +35 -40
- data/spec/resources/itxt_chunk.png +0 -0
- data/spec/resources/trailing_bytes_after_iend_chunk.png +0 -0
- data/spec/spec_helper.rb +15 -9
- data/tasks/benchmarks.rake +7 -8
- metadata +69 -27
- data/.travis.yml +0 -16
- data/lib/chunky_png/compatibility.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2e1b3725cfd19b4f97dc6064df132f90f7dd68205a6a1b9dee7d516cbe2add90
|
4
|
+
data.tar.gz: 9f968c18ab17e1b2f66e9613b5368e0c5afdd368de3448384556c8422620efe6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f7ce3e53cf79c7dd34bb6b9c5da6420dd2d0d7814975a3cd35bc563cb95963355a29af0b3823cfa65667408a8d9173e18c1b5f0460b3abdfe5376c1d7cbb932
|
7
|
+
data.tar.gz: 9ecf4c44876ddfa9acc9fbfdc0d074abdeee3fb148c2e96036a9d1722f123664ac20bfa5a29f4a3c551961db69c63e9b4ca70e2d1eed857a8f5842b9548707d3
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Ruby
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: ["master"]
|
13
|
+
pull_request:
|
14
|
+
branches: ["master"]
|
15
|
+
|
16
|
+
jobs:
|
17
|
+
test:
|
18
|
+
runs-on: ubuntu-latest
|
19
|
+
strategy:
|
20
|
+
matrix:
|
21
|
+
ruby: [ '2.5', '2.6', '2.7', 'ruby-head' ]
|
22
|
+
|
23
|
+
steps:
|
24
|
+
- uses: actions/checkout@v2
|
25
|
+
- name: Set up Ruby
|
26
|
+
uses: ruby/setup-ruby@v1
|
27
|
+
with:
|
28
|
+
ruby-version: ${{ matrix.ruby }}
|
29
|
+
- name: Install dependencies
|
30
|
+
run: bundle install
|
31
|
+
- name: Run tests
|
32
|
+
run: bin/rake
|
33
|
+
# Skip the linter for now.
|
34
|
+
# - name: Lint Ruby code
|
35
|
+
# run: bin/standardrb
|
data/.standard.yml
ADDED
@@ -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"
|
data/.yardopts
CHANGED
data/CHANGELOG.rdoc
CHANGED
@@ -7,12 +7,46 @@ The file documents the changes to this library over the different versions.
|
|
7
7
|
|
8
8
|
=== Unreleased changes
|
9
9
|
|
10
|
-
-
|
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).
|
27
|
+
|
28
|
+
=== 1.3.7 - 2016-08-31
|
29
|
+
|
30
|
+
- Performance improvement for <tt>Color.euclidean_distance_rgba</tt>.
|
31
|
+
- Bugfix in decoding transparent pixels when decoding multiple images in a row.
|
32
|
+
|
33
|
+
=== 1.3.6 - 2016-06-19
|
34
|
+
|
35
|
+
- Allow reading images from streams that have trailing data after the IEND chunk.
|
36
|
+
- Add compatibility for Ruby 2.3's frozen string literals.
|
37
|
+
- Documentation updates and small cleanups.
|
38
|
+
|
39
|
+
=== 1.3.5 - 2015-10-28
|
40
|
+
|
41
|
+
- Performance improvements for <tt>Canvas#crop!</tt> and <tt>ImageData.combine_chunks</tt>
|
42
|
+
- Update <tt>chunky_png/rmagick</tt> to work with the latest versions of RMagick.
|
43
|
+
- Bugfix in <tt>Color#from_hsl</tt> and <tt>Color#from_hsv</tt> when hue value is 360.
|
44
|
+
- Fix encoding issue in <tt>Datastream#to_blob</tt>
|
11
45
|
|
12
46
|
=== 1.3.4 - 2015-02-16
|
13
47
|
|
14
48
|
- Assert compatibility with Ruby 2.2
|
15
|
-
- Improved documentation using RDoc, so it is included on
|
49
|
+
- Improved documentation using RDoc, so it is included on https://www.rubydoc.info/gems/chunky_png
|
16
50
|
- Update chunkypng.com website; migrate some stuff from the wiki.
|
17
51
|
|
18
52
|
=== 1.3.3 - 2014-10-24
|
@@ -120,7 +154,7 @@ There are some API changes for this release. If you are using <tt>Canvas#compose
|
|
120
154
|
- Added a list of HTML named colors. Get them by calling <tt>ChunkyPNG::Color(:teal)</tt> or <tt>ChunkyPNG::Color('red @ 0.8')</tt>
|
121
155
|
- Added encoding support for 1-, 2-, and 4-bit grayscale images.
|
122
156
|
- Cleaned up auto-detection of color mode settings. It will now choose 1 bit grayscale mode if an image only contains black and white. (The other low bitrate grayscale modes are never chosen automatically.)
|
123
|
-
- RDoc improvements. See
|
157
|
+
- RDoc improvements. See https://rdoc.info/gems/chunky_png.
|
124
158
|
- ChunkyPNG is now also tested on Ruby 1.8.6.
|
125
159
|
|
126
160
|
=== 0.12.0 - 2010-12-12
|
@@ -180,7 +214,7 @@ There are some API changes for this release. If you are using <tt>Canvas#compose
|
|
180
214
|
|
181
215
|
=== 0.7.3 - 2010-04-28
|
182
216
|
|
183
|
-
- Based on the suggestion of [Dirkjan Bussink](
|
217
|
+
- Based on the suggestion of [Dirkjan Bussink](https://github.com/dbussink), introduced custom exception classes:
|
184
218
|
- <tt>ChunkyPNG::SignatureMismatch</tt> is raised when the PNG signature could not be found. Usually this means the the file is not a PNG image.
|
185
219
|
- <tt>ChunkyPNG::CRCMismatch</tt> is raised when the a CRC check for a chunk in the PNG file fails.
|
186
220
|
- <tt>ChunkyPNG::NotSupported</tt> is raised when the PNG image uses a feature that ChunkyPNG does not support.
|
data/CONTRIBUTING.rdoc
CHANGED
@@ -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,
|
4
|
-
|
5
|
-
|
6
|
-
|
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
|
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
|
18
|
-
|
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
|
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,18 @@
|
|
1
|
-
|
1
|
+
# frozen-string-literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
2
4
|
gemspec
|
3
5
|
|
4
6
|
platforms :jruby do
|
5
|
-
gem
|
7
|
+
gem "jruby-openssl"
|
6
8
|
end
|
7
9
|
|
8
|
-
|
9
|
-
gem
|
10
|
+
group :jekyll do
|
11
|
+
gem "jekyll", "~> 3.3"
|
12
|
+
gem "kramdown-parser-gfm"
|
10
13
|
end
|
14
|
+
|
15
|
+
group :jekyll_plugins do
|
16
|
+
gem "jekyll-commonmark"
|
17
|
+
gem "jekyll-theme-cayman"
|
18
|
+
end
|
data/LICENSE
CHANGED
data/README.md
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
# ChunkyPNG
|
2
|
+
|
3
|
+
This library can read and write PNG files. It is written in pure Ruby for
|
4
|
+
maximum portability. Let me rephrase: it does NOT require RMagick or any other
|
5
|
+
memory leaking image library.
|
6
|
+
|
7
|
+
- [Source code](https://github.com/wvanbergen/chunky_png/tree/master)
|
8
|
+
- [RDoc](https://rdoc.info/gems/chunky_png)
|
9
|
+
- [Wiki](https://github.com/wvanbergen/chunky_png/wiki)
|
10
|
+
- [Issue tracker](https://github.com/wvanbergen/chunky_png/issues)
|
11
|
+
|
12
|
+
## Features
|
13
|
+
|
14
|
+
- Decodes any image that the PNG standard allows. This includes all standard
|
15
|
+
color modes, all bit depths, all transparency, and interlacing and filtering
|
16
|
+
options.
|
17
|
+
- Encodes images supports all color modes (true color, grayscale, and indexed)
|
18
|
+
and transparency for all these color modes. The best color mode will be
|
19
|
+
chosen automatically, based on the amount of used colors.
|
20
|
+
- R/W access to the image's pixels.
|
21
|
+
- R/W access to all image metadata that is stored in chunks.
|
22
|
+
- Memory efficient (uses a Fixnum, i.e. 4 or 8 bytes of memory per pixel,
|
23
|
+
depending on the hardware)
|
24
|
+
- Reasonably fast for Ruby standards, by only using integer math and a highly
|
25
|
+
optimized saving routine.
|
26
|
+
- Works on every currently supported Ruby version (2.5+)
|
27
|
+
- Interoperability with RMagick if you really have to.
|
28
|
+
|
29
|
+
Also, have a look at [OilyPNG](https://github.com/wvanbergen/oily_png) which
|
30
|
+
is a mixin module that implements some of the ChunkyPNG algorithms in C, which
|
31
|
+
provides a massive speed boost to encoding and decoding.
|
32
|
+
|
33
|
+
## Usage
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
require 'chunky_png'
|
37
|
+
|
38
|
+
# Creating an image from scratch, save as an interlaced PNG
|
39
|
+
png = ChunkyPNG::Image.new(16, 16, ChunkyPNG::Color::TRANSPARENT)
|
40
|
+
png[1,1] = ChunkyPNG::Color.rgba(10, 20, 30, 128)
|
41
|
+
png[2,1] = ChunkyPNG::Color('black @ 0.5')
|
42
|
+
png.save('filename.png', :interlace => true)
|
43
|
+
|
44
|
+
# Compose images using alpha blending.
|
45
|
+
avatar = ChunkyPNG::Image.from_file('avatar.png')
|
46
|
+
badge = ChunkyPNG::Image.from_file('no_ie_badge.png')
|
47
|
+
avatar.compose!(badge, 10, 10)
|
48
|
+
avatar.save('composited.png', :fast_rgba) # Force the fast saving routine.
|
49
|
+
|
50
|
+
# Accessing metadata
|
51
|
+
image = ChunkyPNG::Image.from_file('with_metadata.png')
|
52
|
+
puts image.metadata['Title']
|
53
|
+
image.metadata['Author'] = 'Willem van Bergen'
|
54
|
+
image.save('with_metadata.png') # Overwrite file
|
55
|
+
|
56
|
+
# Low level access to PNG chunks
|
57
|
+
png_stream = ChunkyPNG::Datastream.from_file('filename.png')
|
58
|
+
png_stream.each_chunk { |chunk| p chunk.type }
|
59
|
+
```
|
60
|
+
|
61
|
+
Also check out the screencast on the ChunkyPNG homepage by John Davison,
|
62
|
+
which illustrates basic usage of the library on the [ChunkyPNG
|
63
|
+
website](https://chunkypng.com/).
|
64
|
+
|
65
|
+
For more information, see the [project
|
66
|
+
wiki](https://github.com/wvanbergen/chunky_png/wiki) or the [RDOC
|
67
|
+
documentation](https://www.rubydoc.info/gems/chunky_png).
|
68
|
+
|
69
|
+
## Security warning
|
70
|
+
|
71
|
+
ChunkyPNG is vulnerable to decompression bombs, which means that ChunkyPNG is
|
72
|
+
vulnerable to DOS attacks by running out of memory when loading a specifically
|
73
|
+
crafted PNG file. Because of the pure-Ruby nature of the library it is very hard
|
74
|
+
to fix this problem in the library itself.
|
75
|
+
|
76
|
+
In order to safely deal with untrusted images, you should make sure to do the
|
77
|
+
image processing using ChunkyPNG in a separate process, e.g. by using fork or a
|
78
|
+
background processing library.
|
79
|
+
|
80
|
+
## About
|
81
|
+
|
82
|
+
The library is written by Willem van Bergen for Floorplanner.com, and released
|
83
|
+
under the MIT license (see LICENSE). Please contact me for questions or
|
84
|
+
remarks.
|
85
|
+
|
86
|
+
I generally consider this library to be feature complete. I will gladly accept
|
87
|
+
patches to fix bugs and improve performance, but I will generally be hesitant
|
88
|
+
to accept new features or API endpoints. Before contributing, please read
|
89
|
+
[CONTRIBUTING.rdoc](CONTRIBUTING.rdoc) that explains this in more detail.
|
90
|
+
|
91
|
+
Please check out CHANGELOG.rdoc to see what changed in all versions.
|
92
|
+
|
93
|
+
P.S.: The name of this library is intentionally similar to Chunky Bacon and
|
94
|
+
Chunky GIF. Use Google if you want to know _why_. :-)
|
data/Rakefile
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
+
# frozen-string-literal: true
|
2
|
+
|
1
3
|
require "bundler/gem_tasks"
|
2
4
|
require "rspec/core/rake_task"
|
3
5
|
|
4
|
-
Dir[
|
6
|
+
Dir["tasks/*.rake"].each { |file| load(file) }
|
5
7
|
|
6
8
|
RSpec::Core::RakeTask.new(:spec) do |task|
|
7
9
|
task.pattern = "./spec/**/*_spec.rb"
|
8
|
-
task.rspec_opts = [
|
10
|
+
task.rspec_opts = ["--color"]
|
9
11
|
end
|
10
12
|
|
11
|
-
task :
|
13
|
+
task default: [:spec]
|
@@ -1,26 +1,26 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "rubygems"
|
2
|
+
require "bundler/setup"
|
3
3
|
|
4
|
-
require
|
5
|
-
require
|
4
|
+
require "benchmark"
|
5
|
+
require "chunky_png"
|
6
6
|
|
7
7
|
def image_file(name)
|
8
|
-
File.join(File.dirname(__FILE__),
|
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),
|
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(
|
18
|
-
up_filtering_stream = image_data(
|
19
|
-
paeth_filtering_stream = image_data(
|
20
|
-
rgba_pixelstream = image_data(
|
21
|
-
rgb_pixelstream = image_data(
|
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[
|
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(
|
32
|
-
x.report(
|
33
|
-
x.report(
|
34
|
-
x.report(
|
35
|
-
x.report(
|
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
|
2
|
-
require
|
1
|
+
require "rubygems"
|
2
|
+
require "bundler/setup"
|
3
3
|
|
4
|
-
require
|
5
|
-
require
|
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[
|
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(
|
25
|
+
x.report("Autodetect (indexed)") { n.times { image.to_blob } }
|
23
26
|
|
24
27
|
# Presets
|
25
|
-
x.report(
|
26
|
-
x.report(
|
27
|
-
x.report(
|
28
|
-
x.report(
|
29
|
-
x.report(
|
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(
|
33
|
-
x.report(
|
34
|
-
x.report(
|
35
|
-
x.report(
|
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(
|
39
|
-
x.report(
|
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
|
2
|
-
require
|
1
|
+
require "rubygems"
|
2
|
+
require "bundler/setup"
|
3
3
|
|
4
|
-
require
|
5
|
-
require
|
4
|
+
require "benchmark"
|
5
|
+
require "chunky_png"
|
6
6
|
|
7
|
-
files = [
|
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__),
|
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"
|
data/bin/rake
ADDED
@@ -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")
|
data/bin/standardrb
ADDED
@@ -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")
|
data/chunky_png.gemspec
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
#
|
1
|
+
# frozen-string-literal: true
|
2
2
|
|
3
|
-
lib = File.expand_path(
|
3
|
+
lib = File.expand_path("../lib", __FILE__)
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
require
|
5
|
+
require "chunky_png/version"
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
|
-
s.name =
|
8
|
+
s.name = "chunky_png"
|
9
9
|
|
10
10
|
# Do not change the version and date fields by hand. This will be done
|
11
11
|
# automatically by the gem release script.
|
@@ -26,22 +26,30 @@ Gem::Specification.new do |s|
|
|
26
26
|
alpha composition and cropping. Finally, it can import from and export to RMagick for
|
27
27
|
interoperability.
|
28
28
|
|
29
|
-
Also, have a look at OilyPNG at
|
29
|
+
Also, have a look at OilyPNG at https://github.com/wvanbergen/oily_png. OilyPNG is a
|
30
30
|
drop in mixin module that implements some of the ChunkyPNG algorithms in C, which
|
31
31
|
provides a massive speed boost to encoding and decoding.
|
32
32
|
EOT
|
33
33
|
|
34
|
-
s.authors = [
|
35
|
-
s.email = [
|
36
|
-
s.homepage =
|
37
|
-
s.license =
|
34
|
+
s.authors = ["Willem van Bergen"]
|
35
|
+
s.email = ["willem@railsdoctors.com"]
|
36
|
+
s.homepage = "https://github.com/wvanbergen/chunky_png/wiki"
|
37
|
+
s.license = "MIT"
|
38
|
+
s.metadata = {
|
39
|
+
"source_code_uri" => "https://github.com/wvanbergen/chunky_png",
|
40
|
+
"wiki_uri" => "https://github.com/wvanbergen/chunky_png/wiki",
|
41
|
+
}
|
38
42
|
|
39
|
-
s.add_development_dependency(
|
40
|
-
s.add_development_dependency(
|
43
|
+
s.add_development_dependency("rake")
|
44
|
+
s.add_development_dependency("standard")
|
45
|
+
s.add_development_dependency("yard", "~> 0.9")
|
46
|
+
s.add_development_dependency("rspec", "~> 3")
|
41
47
|
|
42
|
-
s.rdoc_options <<
|
43
|
-
s.extra_rdoc_files = [
|
48
|
+
s.rdoc_options << "--title" << s.name << "--main" << "README.rdoc" << "--line-numbers" << "--inline-source"
|
49
|
+
s.extra_rdoc_files = ["README.md", "BENCHMARKING.rdoc", "CONTRIBUTING.rdoc", "CHANGELOG.rdoc"]
|
44
50
|
|
45
51
|
s.files = `git ls-files`.split($/)
|
46
52
|
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
53
|
+
|
54
|
+
s.required_ruby_version = ">= 2.0.0"
|
47
55
|
end
|
data/docs/.gitignore
ADDED
data/docs/CNAME
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
chunkypng.com
|