Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #141 from wvanbergen/standardrb
Make sure codebase conforms to standard.rb style guide
- Loading branch information
Showing
52 changed files
with
969 additions
and
969 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# ChunkyPNG uses and enforces standard.rb as code style (see https://github.com/testdouble/standard). | ||
# For backwards compatilibity and idiosyncratic preferences of the main author, | ||
# there are some minor differences listed in here. | ||
|
||
ignore: | ||
- lib/chunky_png/**/*.rb: | ||
# We allow `for` loops in the codebase, especially in hot paths, | ||
# because they perform better than `each` blocks. | ||
- "Style/For" | ||
|
||
- spec/chunky_png/**/*.rb: | ||
# In RSpec, having to follow this rule will cause expectations to | ||
# be less readable, specifically blocks for the `change` matcher. | ||
- "Lint/AmbiguousBlockAssociation" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
source 'https://rubygems.org' | ||
source "https://rubygems.org" | ||
gemspec | ||
|
||
platforms :jruby do | ||
gem 'jruby-openssl' | ||
gem "jruby-openssl" | ||
end | ||
|
||
platform :rbx do | ||
gem 'rubysl' | ||
gem "rubysl" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
require "bundler/gem_tasks" | ||
require "rspec/core/rake_task" | ||
|
||
Dir['tasks/*.rake'].each { |file| load(file) } | ||
Dir["tasks/*.rake"].each { |file| load(file) } | ||
|
||
RSpec::Core::RakeTask.new(:spec) do |task| | ||
task.pattern = "./spec/**/*_spec.rb" | ||
task.rspec_opts = ['--color'] | ||
task.rspec_opts = ["--color"] | ||
end | ||
|
||
task default: [:spec] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,36 @@ | ||
require 'rubygems' | ||
require 'bundler/setup' | ||
require "rubygems" | ||
require "bundler/setup" | ||
|
||
require 'benchmark' | ||
require 'chunky_png' | ||
require "benchmark" | ||
require "chunky_png" | ||
|
||
def image_file(name) | ||
File.join(File.dirname(__FILE__), '..', 'spec', 'resources', name) | ||
File.join(File.dirname(__FILE__), "..", "spec", "resources", name) | ||
end | ||
|
||
def image_data(name) | ||
data = nil | ||
File.open(image_file(name), 'rb') { |f| data = f.read } | ||
File.open(image_file(name), "rb") { |f| data = f.read } | ||
data | ||
end | ||
|
||
no_filtering_stream = image_data('pixelstream_fast_rgba.png') | ||
up_filtering_stream = image_data('pixelstream_reference.png') | ||
paeth_filtering_stream = image_data('pixelstream_best_compression.png') | ||
rgba_pixelstream = image_data('pixelstream.rgba') | ||
rgb_pixelstream = image_data('pixelstream.rgb') | ||
no_filtering_stream = image_data("pixelstream_fast_rgba.png") | ||
up_filtering_stream = image_data("pixelstream_reference.png") | ||
paeth_filtering_stream = image_data("pixelstream_best_compression.png") | ||
rgba_pixelstream = image_data("pixelstream.rgba") | ||
rgb_pixelstream = image_data("pixelstream.rgb") | ||
|
||
n = (ENV['N'] || '5').to_i | ||
n = (ENV["N"] || "5").to_i | ||
|
||
puts "---------------------------------------------" | ||
puts "ChunkyPNG (#{ChunkyPNG::VERSION}) decoding benchmark (n=#{n})" | ||
puts "---------------------------------------------" | ||
puts | ||
|
||
Benchmark.bmbm do |x| | ||
x.report('PNG - no filtering') { n.times { ChunkyPNG::Image.from_blob(no_filtering_stream) } } | ||
x.report('PNG - UP filtering') { n.times { ChunkyPNG::Image.from_blob(up_filtering_stream) } } | ||
x.report('PNG - PAETH filtering') { n.times { ChunkyPNG::Image.from_blob(paeth_filtering_stream) } } | ||
x.report('From RGBA pixelstream') { n.times { ChunkyPNG::Image.from_rgba_stream(240, 180, rgba_pixelstream) } } | ||
x.report('From RGB pixelstream') { n.times { ChunkyPNG::Image.from_rgb_stream(240, 180, rgb_pixelstream) } } | ||
x.report("PNG - no filtering") { n.times { ChunkyPNG::Image.from_blob(no_filtering_stream) } } | ||
x.report("PNG - UP filtering") { n.times { ChunkyPNG::Image.from_blob(up_filtering_stream) } } | ||
x.report("PNG - PAETH filtering") { n.times { ChunkyPNG::Image.from_blob(paeth_filtering_stream) } } | ||
x.report("From RGBA pixelstream") { n.times { ChunkyPNG::Image.from_rgba_stream(240, 180, rgba_pixelstream) } } | ||
x.report("From RGB pixelstream") { n.times { ChunkyPNG::Image.from_rgb_stream(240, 180, rgb_pixelstream) } } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,43 @@ | ||
require 'rubygems' | ||
require 'bundler/setup' | ||
require "rubygems" | ||
require "bundler/setup" | ||
|
||
require 'benchmark' | ||
require 'chunky_png' | ||
require "benchmark" | ||
require "chunky_png" | ||
|
||
image = ChunkyPNG::Image.new(240, 180, ChunkyPNG::Color::TRANSPARENT) | ||
|
||
# set some random pixels | ||
|
||
# rubocop:disable Layout/ExtraSpacing, Layout/SpaceInsideParens | ||
image[10, 20] = ChunkyPNG::Color.rgba(255, 0, 0, 255) | ||
image[50, 87] = ChunkyPNG::Color.rgba( 0, 255, 0, 255) | ||
image[33, 99] = ChunkyPNG::Color.rgba( 0, 0, 255, 255) | ||
# rubocop:enable Layout/ExtraSpacing, Layout/SpaceInsideParens | ||
|
||
n = (ENV['N'] || '5').to_i | ||
n = (ENV["N"] || "5").to_i | ||
|
||
puts "---------------------------------------------" | ||
puts "ChunkyPNG (#{ChunkyPNG::VERSION}) encoding benchmark (n=#{n})" | ||
puts "---------------------------------------------" | ||
puts | ||
|
||
Benchmark.bmbm do |x| | ||
x.report('Autodetect (indexed)') { n.times { image.to_blob } } | ||
x.report("Autodetect (indexed)") { n.times { image.to_blob } } | ||
|
||
# Presets | ||
x.report(':no_compression') { n.times { image.to_blob(:no_compression) } } | ||
x.report(':fast_rgba') { n.times { image.to_blob(:fast_rgba) } } | ||
x.report(':fast_rgb') { n.times { image.to_blob(:fast_rgb) } } | ||
x.report(':good_compression') { n.times { image.to_blob(:good_compression) } } | ||
x.report(':best_compression') { n.times { image.to_blob(:best_compression) } } | ||
x.report(":no_compression") { n.times { image.to_blob(:no_compression) } } | ||
x.report(":fast_rgba") { n.times { image.to_blob(:fast_rgba) } } | ||
x.report(":fast_rgb") { n.times { image.to_blob(:fast_rgb) } } | ||
x.report(":good_compression") { n.times { image.to_blob(:good_compression) } } | ||
x.report(":best_compression") { n.times { image.to_blob(:best_compression) } } | ||
|
||
# Some options | ||
x.report(':rgb') { n.times { image.to_blob(color_mode: ChunkyPNG::COLOR_TRUECOLOR) } } | ||
x.report(':rgba') { n.times { image.to_blob(color_mode: ChunkyPNG::COLOR_TRUECOLOR_ALPHA) } } | ||
x.report(':indexed') { n.times { image.to_blob(color_mode: ChunkyPNG::COLOR_INDEXED) } } | ||
x.report(':interlaced') { n.times { image.to_blob(interlaced: true) } } | ||
x.report(":rgb") { n.times { image.to_blob(color_mode: ChunkyPNG::COLOR_TRUECOLOR) } } | ||
x.report(":rgba") { n.times { image.to_blob(color_mode: ChunkyPNG::COLOR_TRUECOLOR_ALPHA) } } | ||
x.report(":indexed") { n.times { image.to_blob(color_mode: ChunkyPNG::COLOR_INDEXED) } } | ||
x.report(":interlaced") { n.times { image.to_blob(interlaced: true) } } | ||
|
||
# Exports | ||
x.report('to RGBA pixelstream') { n.times { image.to_rgba_stream } } | ||
x.report('to RGB pixelstream') { n.times { image.to_rgb_stream } } | ||
x.report("to RGBA pixelstream") { n.times { image.to_rgba_stream } } | ||
x.report("to RGB pixelstream") { n.times { image.to_rgb_stream } } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.