Skip to content

Commit

Permalink
standard.rb: Consistently use double quotes for strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
wvanbergen committed Apr 15, 2019
1 parent c6ac130 commit ef47fb4
Show file tree
Hide file tree
Showing 46 changed files with 663 additions and 663 deletions.
6 changes: 3 additions & 3 deletions Gemfile
@@ -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
4 changes: 2 additions & 2 deletions Rakefile
@@ -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]
34 changes: 17 additions & 17 deletions benchmarks/decoding_benchmark.rb
@@ -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
34 changes: 17 additions & 17 deletions benchmarks/encoding_benchmark.rb
@@ -1,8 +1,8 @@
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)

Expand All @@ -14,30 +14,30 @@
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
12 changes: 6 additions & 6 deletions benchmarks/filesize_benchmark.rb
@@ -1,10 +1,10 @@
require 'rubygems'
require 'bundler/setup'
require "rubygems"
require "bundler/setup"

require 'benchmark'
require 'chunky_png'
require "benchmark"
require "chunky_png"

files = ['pixelstream_reference.png', 'operations.png', 'clock.png']
files = ["pixelstream_reference.png", "operations.png", "clock.png"]

def encode_png(image, constraints = {})
filesize = nil
Expand All @@ -13,7 +13,7 @@ def encode_png(image, constraints = {})
end

files.each do |file|
filename = File.join(File.dirname(__FILE__), '..', 'spec', 'resources', file)
filename = File.join(File.dirname(__FILE__), "..", "spec", "resources", file)
image = ChunkyPNG::Canvas.from_file(filename)

puts "#{file}: #{image.width}x#{image.height} - #{image.palette.size} colors"
Expand Down
26 changes: 13 additions & 13 deletions chunky_png.gemspec
@@ -1,9 +1,9 @@
lib = File.expand_path('../lib', __FILE__)
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'chunky_png/version'
require "chunky_png/version"

Gem::Specification.new do |s|
s.name = 'chunky_png'
s.name = "chunky_png"

# Do not change the version and date fields by hand. This will be done
# automatically by the gem release script.
Expand All @@ -29,22 +29,22 @@ Gem::Specification.new do |s|
provides a massive speed boost to encoding and decoding.
EOT

s.authors = ['Willem van Bergen']
s.email = ['willem@railsdoctors.com']
s.homepage = 'https://github.com/wvanbergen/chunky_png/wiki'
s.license = 'MIT'
s.authors = ["Willem van Bergen"]
s.email = ["willem@railsdoctors.com"]
s.homepage = "https://github.com/wvanbergen/chunky_png/wiki"
s.license = "MIT"
s.metadata = {
"source_code_uri" => "https://github.com/wvanbergen/chunky_png",
"wiki_uri" => "https://github.com/wvanbergen/chunky_png/wiki",
}

s.add_development_dependency('rake')
s.add_development_dependency('standard')
s.add_development_dependency('yard', '~> 0.9')
s.add_development_dependency('rspec', '~> 3')
s.add_development_dependency("rake")
s.add_development_dependency("standard")
s.add_development_dependency("yard", "~> 0.9")
s.add_development_dependency("rspec", "~> 3")

s.rdoc_options << '--title' << s.name << '--main' << 'README.rdoc' << '--line-numbers' << '--inline-source'
s.extra_rdoc_files = ['README.md', 'BENCHMARKING.rdoc', 'CONTRIBUTING.rdoc', 'CHANGELOG.rdoc']
s.rdoc_options << "--title" << s.name << "--main" << "README.rdoc" << "--line-numbers" << "--inline-source"
s.extra_rdoc_files = ["README.md", "BENCHMARKING.rdoc", "CONTRIBUTING.rdoc", "CHANGELOG.rdoc"]

s.files = `git ls-files`.split($/)
s.test_files = s.files.grep(%r{^(test|spec|features)/})
Expand Down
26 changes: 13 additions & 13 deletions lib/chunky_png.rb
@@ -1,7 +1,7 @@
# Basic requirements from standard library
require 'set'
require 'zlib'
require 'stringio'
require "set"
require "zlib"
require "stringio"

# ChunkyPNG - the pure ruby library to access PNG files.
#
Expand Down Expand Up @@ -150,21 +150,21 @@ class UnitsUnknown < ChunkyPNG::Exception
EXTRA_BYTE = "\0".force_encoding(Encoding::BINARY).freeze
end

require 'chunky_png/version'
require "chunky_png/version"

# PNG file structure
require 'chunky_png/datastream'
require 'chunky_png/chunk'
require "chunky_png/datastream"
require "chunky_png/chunk"

# Colors
require 'chunky_png/palette'
require 'chunky_png/color'
require "chunky_png/palette"
require "chunky_png/color"

# Geometry
require 'chunky_png/point'
require 'chunky_png/vector'
require 'chunky_png/dimension'
require "chunky_png/point"
require "chunky_png/vector"
require "chunky_png/dimension"

# Canvas / Image classes
require 'chunky_png/canvas'
require 'chunky_png/image'
require "chunky_png/canvas"
require "chunky_png/image"
28 changes: 14 additions & 14 deletions lib/chunky_png/canvas.rb
@@ -1,14 +1,14 @@
require 'chunky_png/canvas/png_encoding'
require 'chunky_png/canvas/png_decoding'
require 'chunky_png/canvas/adam7_interlacing'
require 'chunky_png/canvas/stream_exporting'
require 'chunky_png/canvas/stream_importing'
require 'chunky_png/canvas/data_url_exporting'
require 'chunky_png/canvas/data_url_importing'
require 'chunky_png/canvas/operations'
require 'chunky_png/canvas/drawing'
require 'chunky_png/canvas/resampling'
require 'chunky_png/canvas/masking'
require "chunky_png/canvas/png_encoding"
require "chunky_png/canvas/png_decoding"
require "chunky_png/canvas/adam7_interlacing"
require "chunky_png/canvas/stream_exporting"
require "chunky_png/canvas/stream_importing"
require "chunky_png/canvas/data_url_exporting"
require "chunky_png/canvas/data_url_importing"
require "chunky_png/canvas/operations"
require "chunky_png/canvas/drawing"
require "chunky_png/canvas/resampling"
require "chunky_png/canvas/masking"

module ChunkyPNG
# The ChunkyPNG::Canvas class represents a raster image as a matrix of
Expand Down Expand Up @@ -297,7 +297,7 @@ def to_image
def inspect
inspected = "<#{self.class.name} #{width}x#{height} ["
for y in 0...height
inspected << "\n\t[" << row(y).map { |p| ChunkyPNG::Color.to_hex(p) }.join(' ') << ']'
inspected << "\n\t[" << row(y).map { |p| ChunkyPNG::Color.to_hex(p) }.join(" ") << "]"
end
inspected << "\n]>"
end
Expand Down Expand Up @@ -361,11 +361,11 @@ def assert_width!(vector_length)
def assert_size!(matrix_width, matrix_height)
if width != matrix_width
raise ChunkyPNG::ExpectationFailed,
'The width of the matrix does not match the canvas width!'
"The width of the matrix does not match the canvas width!"
end
if height != matrix_height
raise ChunkyPNG::ExpectationFailed,
'The height of the matrix does not match the canvas height!'
"The height of the matrix does not match the canvas height!"
end
true
end
Expand Down
2 changes: 1 addition & 1 deletion lib/chunky_png/canvas/data_url_exporting.rb
Expand Up @@ -6,7 +6,7 @@ module DataUrlExporting
# easily be used inline in CSS or HTML.
# @return [String] The canvas formatted as a data URL string.
def to_data_url
['data:image/png;base64,', to_blob].pack('A*m').delete("\n")
["data:image/png;base64,", to_blob].pack("A*m").delete("\n")
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/chunky_png/canvas/data_url_importing.rb
Expand Up @@ -9,7 +9,7 @@ module DataUrlImporting
# formatted PNG data URL (i.e. it should start with "data:image/png;base64,")
def from_data_url(string)
if string =~ %r[^data:image/png;base64,((?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?)$]
from_blob($1.unpack('m').first)
from_blob($1.unpack("m").first)
else
raise SignatureMismatch, "The string was not a properly formatted data URL for a PNG image."
end
Expand Down
2 changes: 1 addition & 1 deletion lib/chunky_png/canvas/drawing.rb
Expand Up @@ -164,7 +164,7 @@ def line_xiaolin_wu(x0, y0, x1, y1, stroke_color, inclusive = true)
def polygon(path, stroke_color = ChunkyPNG::Color::BLACK, fill_color = ChunkyPNG::Color::TRANSPARENT)
vector = ChunkyPNG::Vector(*path)
if path.length < 3
raise ArgumentError, 'A polygon requires at least 3 points'
raise ArgumentError, "A polygon requires at least 3 points"
end

stroke_color = ChunkyPNG::Color.parse(stroke_color)
Expand Down
8 changes: 4 additions & 4 deletions lib/chunky_png/canvas/operations.rb
Expand Up @@ -172,10 +172,10 @@ def crop(x, y, crop_width, crop_height)
# coordinates are bigger then the original image.
def crop!(x, y, crop_width, crop_height)
if crop_width + x > width
raise ChunkyPNG::OutOfBounds, 'Original image width is too small!'
raise ChunkyPNG::OutOfBounds, "Original image width is too small!"
end
if crop_height + y > height
raise ChunkyPNG::OutOfBounds, 'Original image height is too small!'
raise ChunkyPNG::OutOfBounds, "Original image height is too small!"
end

if crop_width == width && x == 0
Expand Down Expand Up @@ -392,10 +392,10 @@ def border!(size, color = ChunkyPNG::Color::BLACK)
# @raise [ChunkyPNG::OutOfBounds] when the other image doesn't fit.
def check_size_constraints!(other, offset_x, offset_y)
if width < other.width + offset_x
raise ChunkyPNG::OutOfBounds, 'Background image width is too small!'
raise ChunkyPNG::OutOfBounds, "Background image width is too small!"
end
if height < other.height + offset_y
raise ChunkyPNG::OutOfBounds, 'Background image height is too small!'
raise ChunkyPNG::OutOfBounds, "Background image height is too small!"
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/chunky_png/canvas/png_decoding.rb
Expand Up @@ -270,7 +270,7 @@ def decode_png_pixels_from_scanline_truecolor_alpha_16bit(stream, pos, width, _d
# @params (see #decode_png_pixels_from_scanline_indexed_1bit)
# @return (see #decode_png_pixels_from_scanline_indexed_1bit)
def decode_png_pixels_from_scanline_truecolor_8bit(stream, pos, width, _decoding_palette)
stream.unpack("@#{pos + 1}" << ('NX' * width)).map { |c| c | 0x000000ff }
stream.unpack("@#{pos + 1}" << ("NX" * width)).map { |c| c | 0x000000ff }
end

# Decodes a scanline of a 16-bit, true color image into a row of pixels.
Expand Down

0 comments on commit ef47fb4

Please sign in to comment.