From 3a39333fd39c94806aee76bc2bba6b4ea1947218 Mon Sep 17 00:00:00 2001 From: Paul Keen <125715+pftg@users.noreply.github.com> Date: Sun, 20 Dec 2020 16:51:08 +0200 Subject: [PATCH] Reformat all code to use one code style * Enabled CI to require linter pass --- .github/workflows/test.yml | 1 - .rubocop.yml | 22 -- .rubocop_todo.yml | 473 --------------------------- .standard.yml | 11 +- Gemfile | 4 +- Rakefile | 23 +- example/annotate.rb | 12 +- example/daltonize8.rb | 12 +- example/draw_lines.rb | 8 +- example/example1.rb | 6 +- example/example2.rb | 12 +- example/example3.rb | 10 +- example/example4.rb | 4 +- example/example5.rb | 8 +- example/inheritance_with_refcount.rb | 71 ++-- example/progress.rb | 6 +- example/thumb.rb | 10 +- example/trim8.rb | 2 +- example/watermark.rb | 4 +- example/wobble.rb | 2 +- lib/ruby-vips.rb | 2 +- lib/vips.rb | 120 +++---- lib/vips/blend_mode.rb | 8 +- lib/vips/connection.rb | 8 +- lib/vips/gobject.rb | 26 +- lib/vips/gvalue.rb | 106 +++--- lib/vips/image.rb | 237 +++++++------- lib/vips/interpolate.rb | 2 +- lib/vips/mutableimage.rb | 29 +- lib/vips/object.rb | 161 +++++---- lib/vips/operation.rb | 171 +++++----- lib/vips/region.rb | 12 +- lib/vips/source.rb | 23 +- lib/vips/sourcecustom.rb | 13 +- lib/vips/target.rb | 25 +- lib/vips/targetcustom.rb | 19 +- ruby-vips.gemspec | 22 +- spec/connection_spec.rb | 83 +++-- spec/image_spec.rb | 197 ++++++----- spec/mutate_spec.rb | 43 ++- spec/region_spec.rb | 8 +- spec/spec_helper.rb | 26 +- spec/vips_spec.rb | 67 ++-- 43 files changed, 794 insertions(+), 1315 deletions(-) delete mode 100644 .rubocop.yml delete mode 100644 .rubocop_todo.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fc076955..0a925c5b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -26,7 +26,6 @@ jobs: - name: Run Standard Ruby linter run: bundle exec standardrb --no-fix --fail-fast - continue-on-error: true test: name: Functional Testing diff --git a/.rubocop.yml b/.rubocop.yml deleted file mode 100644 index 3f513ed8..00000000 --- a/.rubocop.yml +++ /dev/null @@ -1,22 +0,0 @@ -inherit_from: .rubocop_todo.yml - -AllCops: - TargetRubyVersion: 2.6 - -Gemspec/OrderedDependencies: - Enabled: false - -# we have some long kw arg calls -Layout/AlignHash: - EnforcedLastArgumentHashStyle: ignore_implicit - -# methods.rb is autogenerated and we don't expect the doc comments to align -Layout/CommentIndentation: - Exclude: - - 'lib/vips/methods.rb' -Layout/EmptyLinesAroundClassBody: - Exclude: - - 'lib/vips/methods.rb' -Layout/TrailingWhitespace: - Exclude: - - 'lib/vips/methods.rb' diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml deleted file mode 100644 index cc6958b5..00000000 --- a/.rubocop_todo.yml +++ /dev/null @@ -1,473 +0,0 @@ -# This configuration was generated by -# `rubocop --auto-gen-config` -# on 2019-10-02 15:42:13 +0100 using RuboCop version 0.75.0. -# The point is for the user to remove these configuration records -# one by one as the offenses are removed from the code base. -# Note that changes in the inspected code, or installation of new -# versions of RuboCop, may require this file to be generated again. - -# Offense count: 42 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, IndentationWidth. -# SupportedStyles: with_first_argument, with_fixed_indentation -Layout/AlignArguments: - Exclude: - - 'example/inheritance_with_refcount.rb' - - 'lib/vips.rb' - - 'lib/vips/gvalue.rb' - - 'lib/vips/image.rb' - - 'lib/vips/object.rb' - - 'spec/vips_spec.rb' - -# Offense count: 5 -Lint/IneffectiveAccessModifier: - Exclude: - - 'lib/vips/image.rb' - -# Offense count: 7 -# Configuration parameters: ContextCreatingMethods, MethodCreatingMethods. -Lint/UselessAccessModifier: - Exclude: - - 'lib/vips/image.rb' - - 'lib/vips/object.rb' - - 'lib/vips/operation.rb' - -# Offense count: 6 -Lint/UselessComparison: - Exclude: - - 'spec/image_spec.rb' - -# Offense count: 7 -Metrics/AbcSize: - Max: 113 - -# Offense count: 6 -# Configuration parameters: CountComments, ExcludedMethods. -# ExcludedMethods: refine -Metrics/BlockLength: - Max: 508 - -# Offense count: 3 -# Configuration parameters: CountComments. -Metrics/ClassLength: - Max: 515 - -# Offense count: 6 -Metrics/CyclomaticComplexity: - Max: 27 - -# Offense count: 11 -# Configuration parameters: CountComments, ExcludedMethods. -Metrics/MethodLength: - Max: 128 - -# Offense count: 1 -# Configuration parameters: CountComments. -Metrics/ModuleLength: - Max: 131 - -# Offense count: 4 -Metrics/PerceivedComplexity: - Max: 31 - -# Offense count: 9 -Naming/AccessorMethodName: - Exclude: - - 'example/inheritance_with_refcount.rb' - - 'lib/vips.rb' - - 'lib/vips/image.rb' - - 'lib/vips/operation.rb' - -# Offense count: 1 -# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms. -# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS -Naming/FileName: - Exclude: - - 'lib/ruby-vips.rb' - -# Offense count: 1 -# Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist, MethodDefinitionMacros. -# NamePrefix: is_, has_, have_ -# NamePrefixBlacklist: is_, has_, have_ -# NameWhitelist: is_a? -# MethodDefinitionMacros: define_method, define_singleton_method -Naming/PredicateName: - Exclude: - - 'spec/**/*' - - 'lib/vips/image.rb' - -# Offense count: 6 -# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. -# AllowedNames: io, id, to, by, on, in, at, ip, db -Naming/UncommunicativeMethodParamName: - Exclude: - - 'lib/vips.rb' - - 'lib/vips/image.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: prefer_alias, prefer_alias_method -Style/Alias: - Exclude: - - 'lib/vips/image.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: always, conditionals -Style/AndOr: - Exclude: - - 'example/example2.rb' - -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods, AllowBracesOnProceduralOneLiners. -# SupportedStyles: line_count_based, semantic, braces_for_chaining, always_braces -# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object -# FunctionalMethods: let, let!, subject, watch -# IgnoredMethods: lambda, proc, it -Style/BlockDelimiters: - Exclude: - - 'example/inheritance_with_refcount.rb' - - 'lib/vips.rb' - - 'lib/vips/operation.rb' - -# Offense count: 5 -Style/ClassVars: - Exclude: - - 'lib/vips/image.rb' - -# Offense count: 173 -# Cop supports --auto-correct. -Style/ColonMethodCall: - Enabled: false - -# Offense count: 47 -Style/Documentation: - Exclude: - - 'spec/**/*' - - 'test/**/*' - - 'example/inheritance_with_refcount.rb' - - 'example/wobble.rb' - - 'lib/vips.rb' - - 'lib/vips/gobject.rb' - - 'lib/vips/gvalue.rb' - - 'lib/vips/image.rb' - - 'lib/vips/interpolate.rb' - - 'lib/vips/object.rb' - - 'lib/vips/operation.rb' - - 'lib/vips/region.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -Style/Encoding: - Exclude: - - 'Rakefile' - - 'ruby-vips.gemspec' - -# Offense count: 1 -# Cop supports --auto-correct. -Style/EvenOdd: - Exclude: - - 'lib/vips/image.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -Style/ExpandPathArguments: - Exclude: - - 'ruby-vips.gemspec' - - 'spec/spec_helper.rb' - -# Offense count: 51 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: always, never -Style/FrozenStringLiteralComment: - Enabled: false - -# Offense count: 5 -# Configuration parameters: AllowedVariables. -Style/GlobalVars: - Exclude: - - 'example/inheritance_with_refcount.rb' - -# Offense count: 5 -# Configuration parameters: MinBodyLength. -Style/GuardClause: - Exclude: - - 'example/inheritance_with_refcount.rb' - - 'lib/vips.rb' - -# Offense count: 21 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols. -# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys -Style/HashSyntax: - Exclude: - - 'Rakefile' - - 'example/annotate.rb' - - 'example/daltonize8.rb' - - 'example/example3.rb' - - 'example/example5.rb' - - 'spec/image_spec.rb' - - 'spec/spec_helper.rb' - -# Offense count: 30 -# Cop supports --auto-correct. -Style/IfUnlessModifier: - Exclude: - - 'example/daltonize8.rb' - - 'example/example2.rb' - - 'example/example5.rb' - - 'example/inheritance_with_refcount.rb' - - 'lib/vips.rb' - - 'lib/vips/gvalue.rb' - - 'lib/vips/image.rb' - - 'lib/vips/operation.rb' - - 'ruby-vips.gemspec' - -# Offense count: 4 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: call, braces -Style/LambdaCall: - Exclude: - - 'lib/vips/image.rb' - -# Offense count: 9 -# Cop supports --auto-correct. -Style/LineEndConcatenation: - Exclude: - - 'lib/vips/gvalue.rb' - - 'lib/vips/image.rb' - - 'lib/vips/operation.rb' - -# Offense count: 81 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: require_parentheses, require_no_parentheses, require_no_parentheses_except_multiline -Style/MethodDefParentheses: - Exclude: - - 'example/inheritance_with_refcount.rb' - - 'lib/vips.rb' - - 'lib/vips/gobject.rb' - - 'lib/vips/gvalue.rb' - - 'lib/vips/image.rb' - - 'lib/vips/interpolate.rb' - - 'lib/vips/object.rb' - - 'lib/vips/operation.rb' - -# Offense count: 2 -Style/MethodMissingSuper: - Exclude: - - 'lib/vips/image.rb' - -# Offense count: 2 -Style/MissingRespondToMissing: - Exclude: - - 'lib/vips/image.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, Autocorrect. -# SupportedStyles: module_function, extend_self -Style/ModuleFunction: - Exclude: - - 'spec/spec_helper.rb' - -# Offense count: 5 -Style/MultilineTernaryOperator: - Exclude: - - 'lib/vips/image.rb' - -# Offense count: 1 -Style/MultipleComparison: - Exclude: - - 'lib/vips/image.rb' - -# Offense count: 6 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: literals, strict -Style/MutableConstant: - Exclude: - - 'example/inheritance_with_refcount.rb' - - 'lib/vips.rb' - - 'lib/vips/object.rb' - - 'lib/vips/operation.rb' - - 'lib/vips/version.rb' - -# Offense count: 6 -# Cop supports --auto-correct. -# Configuration parameters: Whitelist. -# Whitelist: be, be_a, be_an, be_between, be_falsey, be_kind_of, be_instance_of, be_truthy, be_within, eq, eql, end_with, include, match, raise_error, respond_to, start_with -Style/NestedParenthesizedCalls: - Exclude: - - 'lib/vips/image.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, MinBodyLength. -# SupportedStyles: skip_modifier_ifs, always -Style/Next: - Exclude: - - 'lib/vips/operation.rb' - -# Offense count: 15 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: predicate, comparison -Style/NilComparison: - Exclude: - - 'lib/vips/gvalue.rb' - - 'lib/vips/image.rb' - - 'lib/vips/interpolate.rb' - - 'lib/vips/operation.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: IncludeSemanticChanges. -Style/NonNilCheck: - Exclude: - - 'lib/vips.rb' - - 'lib/vips/operation.rb' - -# Offense count: 4 -# Cop supports --auto-correct. -# Configuration parameters: Strict. -Style/NumericLiterals: - MinDigits: 9 - -# Offense count: 10 -# Cop supports --auto-correct. -# Configuration parameters: AutoCorrect, EnforcedStyle, IgnoredMethods. -# SupportedStyles: predicate, comparison -Style/NumericPredicate: - Exclude: - - 'spec/**/*' - - 'lib/vips/image.rb' - - 'lib/vips/operation.rb' - -# Offense count: 4 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: short, verbose -Style/PreferredHashMethods: - Exclude: - - 'lib/vips/operation.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -Style/Proc: - Exclude: - - 'lib/vips.rb' - - 'lib/vips/operation.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Style/RedundantConditional: - Exclude: - - 'lib/vips/gvalue.rb' - -# Offense count: 13 -# Cop supports --auto-correct. -# Configuration parameters: AllowMultipleReturnValues. -Style/RedundantReturn: - Exclude: - - 'lib/vips/gvalue.rb' - - 'lib/vips/image.rb' - - 'lib/vips/object.rb' - - 'lib/vips/operation.rb' - -# Offense count: 4 -# Cop supports --auto-correct. -Style/RedundantSelf: - Exclude: - - 'example/inheritance_with_refcount.rb' - - 'lib/vips/gobject.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Style/SelfAssignment: - Exclude: - - 'example/daltonize8.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: use_perl_names, use_english_names -Style/SpecialGlobalVars: - Exclude: - - 'example/inheritance_with_refcount.rb' - - 'lib/vips.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -Style/StderrPuts: - Exclude: - - 'Rakefile' - -# Offense count: 192 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline. -# SupportedStyles: single_quotes, double_quotes -Style/StringLiterals: - Exclude: - - 'Rakefile' - - 'example/annotate.rb' - - 'example/example1.rb' - - 'example/example2.rb' - - 'example/example3.rb' - - 'example/example4.rb' - - 'example/inheritance_with_refcount.rb' - - 'lib/vips.rb' - - 'lib/vips/gvalue.rb' - - 'lib/vips/image.rb' - - 'lib/vips/object.rb' - - 'lib/vips/operation.rb' - - 'lib/vips/version.rb' - - 'ruby-vips.gemspec' - - 'spec/vips_spec.rb' - -# Offense count: 15 -# Cop supports --auto-correct. -# Configuration parameters: MinSize. -# SupportedStyles: percent, brackets -Style/SymbolArray: - EnforcedStyle: brackets - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyleForMultiline. -# SupportedStylesForMultiline: comma, consistent_comma, no_comma -Style/TrailingCommaInHashLiteral: - Exclude: - - 'lib/vips/image.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Style/RedundantInterpolation: - Exclude: - - 'lib/vips/image.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: MinSize, WordRegex. -# SupportedStyles: percent, brackets -Style/WordArray: - EnforcedStyle: brackets - -# Offense count: 6 -# Cop supports --auto-correct. -Style/ZeroLengthPredicate: - Exclude: - - 'lib/vips/image.rb' - - 'lib/vips/operation.rb' - -# Offense count: 107 -# Cop supports --auto-correct. -# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. -# URISchemes: http, https -Metrics/LineLength: - Max: 179 diff --git a/.standard.yml b/.standard.yml index 4bf8af6a..38e7548f 100644 --- a/.standard.yml +++ b/.standard.yml @@ -1,8 +1,17 @@ fix: false # default: false parallel: true # default: false format: progress # default: Standard::Formatter -ruby_version: 2.5 # default: RUBY_VERSION +ruby_version: 2.0 # default: RUBY_VERSION default_ignores: false # default: true ignore: # default: [] + - '**/*': + - Standard/SemanticBlocks + - 'lib/vips/methods.rb' + - '{lib,example}/**/*': + - Lint/IneffectiveAccessModifier + - Lint/RescueException + - Style/GlobalVars + - 'spec/**/*': + - Lint/BinaryOperatorWithIdenticalOperands - 'vendor/**/*' diff --git a/Gemfile b/Gemfile index 03e75f05..2442dde9 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ -source 'https://rubygems.org' +source "https://rubygems.org" # all gems are handled by .gemspec (since this repo is for a gem) gemspec -gem 'github-markup' +gem "github-markup" diff --git a/Rakefile b/Rakefile index 17dd8a32..52982115 100644 --- a/Rakefile +++ b/Rakefile @@ -1,27 +1,24 @@ -# encoding: utf-8 - -require 'bundler/gem_tasks' +require "bundler/gem_tasks" begin Bundler.setup(:default, :development) rescue Bundler::BundlerError => e - $stderr.puts e.message - $stderr.puts "Run `bundle install` to install missing gems" + warn e.message + warn "Run `bundle install` to install missing gems" exit e.status_code end -require 'rake' +require "rake" -require 'rspec/core' -require 'rspec/core/rake_task' +require "rspec/core" +require "rspec/core/rake_task" RSpec::Core::RakeTask.new(:spec) do |spec| - spec.pattern = FileList['spec/**/*_spec.rb'] + spec.pattern = FileList["spec/**/*_spec.rb"] end -task :default => :spec +task default: :spec -# -unless RUBY_PLATFORM.include?('java') +unless RUBY_PLATFORM.include?("java") require "github/markup" require "yard" require "yard/rake/yardoc_task" @@ -31,6 +28,6 @@ end # RuboCop requires Ruby >= 2.2 if Gem.ruby_version >= Gem::Version.new("2.2.0") - require 'rubocop/rake_task' + require "rubocop/rake_task" RuboCop::RakeTask.new end diff --git a/example/annotate.rb b/example/annotate.rb index a526711c..319eeced 100755 --- a/example/annotate.rb +++ b/example/annotate.rb @@ -1,17 +1,17 @@ #!/usr/bin/ruby -require 'vips' +require "vips" -im = Vips::Image.new_from_file ARGV[0], :access => :sequential +im = Vips::Image.new_from_file ARGV[0], access: :sequential -left_text = Vips::Image.text "left corner", :dpi => 300 +left_text = Vips::Image.text "left corner", dpi: 300 left = left_text.embed 50, 50, im.width, 150 -right_text = Vips::Image.text "right corner", :dpi => 300 +right_text = Vips::Image.text "right corner", dpi: 300 right = right_text.embed im.width - right_text.width - 50, 50, im.width, 150 -footer = (left | right).ifthenelse(0, [255, 0, 0], :blend => true) +footer = (left | right).ifthenelse(0, [255, 0, 0], blend: true) -im = im.insert footer, 0, im.height, :expand => true +im = im.insert footer, 0, im.height, expand: true im.write_to_file ARGV[1] diff --git a/example/daltonize8.rb b/example/daltonize8.rb index f55b3cef..8b90d4af 100755 --- a/example/daltonize8.rb +++ b/example/daltonize8.rb @@ -7,7 +7,7 @@ # http://libvips.blogspot.co.uk/2013/05/daltonize-in-ruby-vips-carrierwave-and.html # for a discussion of this code -require 'vips' +require "vips" # Vips.set_debug true @@ -29,13 +29,13 @@ alpha = nil if im.bands == 4 alpha = im[3] - im = im.extract_band 0, :n => 3 + im = im.extract_band 0, n: 3 end begin # import to XYZ with lcms # if there's no profile there, we'll fall back to the thing below - xyz = im.icc_import :embedded => true, :pcs => :xyz + xyz = im.icc_import embedded: true, pcs: :xyz rescue Vips::Error # nope .. use the built-in converter instead xyz = im.colourspace :xyz @@ -61,9 +61,9 @@ err = im - rgb # add the error back to other channels to make a compensated image -im = im + err.recomb([[0, 0, 0], - [0.7, 1, 0], - [0.7, 0, 1]]) +im += err.recomb([[0, 0, 0], + [0.7, 1, 0], + [0.7, 0, 1]]) # reattach any alpha we saved above if alpha diff --git a/example/draw_lines.rb b/example/draw_lines.rb index 87560e9f..6990d56f 100755 --- a/example/draw_lines.rb +++ b/example/draw_lines.rb @@ -1,14 +1,14 @@ #!/usr/bin/ruby -require 'vips' +require "vips" # load and stream into memory -image = Vips::Image.new_from_file(ARGV[0], access: :sequential).copy_memory() +image = Vips::Image.new_from_file(ARGV[0], access: :sequential).copy_memory starting = Process.clock_gettime(Process::CLOCK_MONOTONIC) lines = image -(0 .. 1).step 0.01 do |i| +(0..1).step 0.01 do |i| lines = lines.draw_line 255, lines.width * i, 0, 0, lines.height * (1 - i) end @@ -19,7 +19,7 @@ lines = image lines = lines.mutate do |x| - (0 .. 1).step 0.01 do |i| + (0..1).step 0.01 do |i| x.draw_line! 255, x.width * i, 0, 0, x.height * (1 - i) end end diff --git a/example/example1.rb b/example/example1.rb index 47bb27c8..ec59b78a 100755 --- a/example/example1.rb +++ b/example/example1.rb @@ -1,9 +1,9 @@ #!/usr/bin/ruby -require 'logger' -require 'vips' +require "logger" +require "vips" -GLib::logger.level = Logger::DEBUG +GLib.logger.level = Logger::DEBUG Vips::Operation.new "black" diff --git a/example/example2.rb b/example/example2.rb index f58a2b8b..2f4988ce 100755 --- a/example/example2.rb +++ b/example/example2.rb @@ -1,16 +1,16 @@ #!/usr/bin/ruby -require 'logger' -require 'vips' +require "logger" +require "vips" puts "" puts "starting up:" # this makes vips keep a list of all active objects which we can print out -Vips::leak_set true +Vips.leak_set true # disable the operation cache -Vips::cache_set_max 0 +Vips.cache_set_max 0 # GLib::logger.level = Logger::DEBUG @@ -20,7 +20,7 @@ puts "" puts "call #{i} ..." out = Vips::Operation.call "black", [200, 300] - if out.width != 200 or out.height != 300 + if out.width != 200 || out.height != 300 puts "bad image result from black" end end @@ -28,7 +28,7 @@ puts "" puts "after #{n} calls:" GC.start -Vips::Object::print_all +Vips::Object.print_all puts "" puts "shutting down:" diff --git a/example/example3.rb b/example/example3.rb index a41579f2..19b03fbb 100755 --- a/example/example3.rb +++ b/example/example3.rb @@ -1,19 +1,19 @@ #!/usr/bin/ruby -require 'vips' +require "vips" # this makes vips keep a list of all active objects -Vips::leak_set true +Vips.leak_set true # disable the operation cache # Vips::cache_set_max 0 # turn on debug logging -GLib::logger.level = Logger::DEBUG +GLib.logger.level = Logger::DEBUG -1.times do |i| +10.times do |i| puts "loop #{i} ..." im = Vips::Image.new_from_file ARGV[0] - im = im.embed 100, 100, 3000, 3000, :extend => :mirror + im = im.embed 100, 100, 3000, 3000, extend: :mirror im.write_to_file "x.v" end diff --git a/example/example4.rb b/example/example4.rb index 6eac6d2c..9bd23b77 100755 --- a/example/example4.rb +++ b/example/example4.rb @@ -1,9 +1,9 @@ #!/usr/bin/ruby -require 'vips' +require "vips" # this makes vips keep a list of all active objects -Vips::leak_set true +Vips.leak_set true # disable the operation cache # Vips::cache_set_max 0 diff --git a/example/example5.rb b/example/example5.rb index d6344616..0047abdc 100755 --- a/example/example5.rb +++ b/example/example5.rb @@ -1,6 +1,6 @@ #!/usr/bin/ruby -require 'vips' +require "vips" # this makes vips keep a list of all active objects # Vips::leak_set true @@ -15,7 +15,7 @@ raise "usage: #{$PROGRAM_NAME}: input-file output-file" end -im = Vips::Image.new_from_file ARGV[0], :access => :sequential +im = Vips::Image.new_from_file ARGV[0], access: :sequential im *= [1, 2, 1] @@ -23,8 +23,8 @@ # make it ourselves # if you are OK with scale=1, you can just pass the array directly to .conv() mask = Vips::Image.new_from_array [[-1, -1, -1], - [-1, 16, -1], - [-1, -1, -1]], 8 + [-1, 16, -1], + [-1, -1, -1]], 8 im = im.conv mask im.write_to_file ARGV[1] diff --git a/example/inheritance_with_refcount.rb b/example/inheritance_with_refcount.rb index 9fee875d..1702dbfb 100755 --- a/example/inheritance_with_refcount.rb +++ b/example/inheritance_with_refcount.rb @@ -1,7 +1,7 @@ #!/usr/bin/ruby -require 'ffi' -require 'forwardable' +require "ffi" +require "forwardable" # this is really very crude logging @@ -29,7 +29,7 @@ module Libc module GLib extend FFI::Library - ffi_lib 'gobject-2.0' + ffi_lib "gobject-2.0" def self.set_log_domain(_domain) # FIXME: this needs hooking up @@ -68,8 +68,8 @@ module GObjectLayout def self.included(base) base.class_eval do layout :g_type_instance, :pointer, - :ref_count, :uint, - :qdata, :pointer + :ref_count, :uint, + :qdata, :pointer end end end @@ -85,7 +85,7 @@ def initialize(ptr) def self.release(ptr) log "GLib::GObject::ManagedStruct.release: unreffing #{ptr}" - GLib::g_object_unref(ptr) unless ptr.null? + GLib.g_object_unref(ptr) unless ptr.null? end end @@ -116,7 +116,7 @@ def ffi_struct class << self def ffi_struct - self.const_get(:Struct) + const_get(:Struct) end end @@ -127,7 +127,7 @@ def ffi_managed_struct class << self def ffi_managed_struct - self.const_get(:ManagedStruct) + const_get(:ManagedStruct) end end end @@ -138,10 +138,10 @@ def ffi_managed_struct module Vips extend FFI::Library - ffi_lib 'vips' + ffi_lib "vips" LOG_DOMAIN = "VIPS" - GLib::set_log_domain(LOG_DOMAIN) + GLib.set_log_domain(LOG_DOMAIN) # need to repeat this typedef :ulong, :GType @@ -153,19 +153,19 @@ module Vips attach_function :vips_error_clear, [], :void def self.get_error - errstr = Vips::vips_error_buffer - Vips::vips_error_clear + errstr = Vips.vips_error_buffer + Vips.vips_error_clear errstr end - if Vips::vips_init($0) != 0 - puts Vips::get_error + if Vips.vips_init($0) != 0 + puts Vips.get_error exit 1 end - at_exit { - Vips::vips_shutdown - } + at_exit do + Vips.vips_shutdown + end attach_function :vips_object_print_all, [], :void attach_function :vips_leak_set, [:int], :void @@ -188,15 +188,15 @@ def self.included(base) base.class_eval do # don't actually need most of these, remove them later layout :parent, GLib::GObject::Struct, - :constructed, :int, - :static_object, :int, - :argument_table, :pointer, - :nickname, :string, - :description, :string, - :preclose, :int, - :close, :int, - :postclose, :int, - :local_memory, :size_t + :constructed, :int, + :static_object, :int, + :argument_table, :pointer, + :nickname, :string, + :description, :string, + :preclose, :int, + :close, :int, + :postclose, :int, + :local_memory, :size_t end end end @@ -250,7 +250,7 @@ def initialize(ptr) end def self.new_partial - VipsImage.new(Vips::vips_image_new) + VipsImage.new(Vips.vips_image_new) end end @@ -258,12 +258,11 @@ def self.new_partial end puts "creating image" -begin - x = Vips::VipsImage.new_partial - puts "x = #{x}" - puts "" - puts "x[:parent] = #{x[:parent]}" - puts "" - puts "x[:parent][:description] = #{x[:parent][:description]}" - puts "" -end + +x = Vips::VipsImage.new_partial +puts "x = #{x}" +puts "" +puts "x[:parent] = #{x[:parent]}" +puts "" +puts "x[:parent][:description] = #{x[:parent][:description]}" +puts "" diff --git a/example/progress.rb b/example/progress.rb index c8651e18..a6acd4b2 100755 --- a/example/progress.rb +++ b/example/progress.rb @@ -1,6 +1,6 @@ #!/usr/bin/ruby -require 'vips' +require "vips" image = Vips::Image.black 1, 100000 image.set_progress true @@ -12,11 +12,11 @@ def progress_to_s(name, progress) puts " progress.tpels = #{progress[:tpels]}" puts " progress.npels = #{progress[:npels]}" puts " progress.percent = #{progress[:percent]}" -end +end image.signal_connect :preeval do |progress| progress_to_s("preeval", progress) -end +end image.signal_connect :eval do |progress| progress_to_s("eval", progress) diff --git a/example/thumb.rb b/example/thumb.rb index e241a7cc..840f2f53 100755 --- a/example/thumb.rb +++ b/example/thumb.rb @@ -4,22 +4,22 @@ # # this should run in constant memory -- if it doesn't, something has broken -require 'vips' +require "vips" # benchmark thumbnail via a memory buffer def via_memory(filename, thumbnail_width) data = IO.binread(filename) - thumb = Vips::Image.thumbnail_buffer data, thumbnail_width, crop: 'centre' + thumb = Vips::Image.thumbnail_buffer data, thumbnail_width, crop: "centre" - thumb.write_to_buffer '.jpg' + thumb.write_to_buffer ".jpg" end # benchmark thumbnail via files def via_files(filename, thumbnail_width) - thumb = Vips::Image.thumbnail filename, thumbnail_width, crop: 'centre' + thumb = Vips::Image.thumbnail filename, thumbnail_width, crop: "centre" - thumb.write_to_buffer '.jpg' + thumb.write_to_buffer ".jpg" end ARGV.each do |filename| diff --git a/example/trim8.rb b/example/trim8.rb index 40027166..c596bdac 100755 --- a/example/trim8.rb +++ b/example/trim8.rb @@ -7,7 +7,7 @@ # non-zero row or column is the object edge. We make the mask image with an # amount-different-from-background image plus a threshold. -require 'vips' +require "vips" im = Vips::Image.new_from_file ARGV[0] diff --git a/example/watermark.rb b/example/watermark.rb index 70f8c729..48f943e2 100755 --- a/example/watermark.rb +++ b/example/watermark.rb @@ -1,11 +1,11 @@ #!/usr/bin/ruby -require 'vips' +require "vips" im = Vips::Image.new_from_file ARGV[0], access: :sequential # make the text mask -text = Vips::Image.text ARGV[2], width: 200, dpi: 200, font: 'sans bold' +text = Vips::Image.text ARGV[2], width: 200, dpi: 200, font: "sans bold" text = text.rotate(-45) # make the text transparent text = (text * 0.3).cast(:uchar) diff --git a/example/wobble.rb b/example/wobble.rb index 274fcc2c..e7883d41 100755 --- a/example/wobble.rb +++ b/example/wobble.rb @@ -1,6 +1,6 @@ #!/usr/bin/ruby -require 'vips' +require "vips" image = Vips::Image.new_from_file ARGV[0] diff --git a/lib/ruby-vips.rb b/lib/ruby-vips.rb index 0a343ee7..eb58e7f7 100644 --- a/lib/ruby-vips.rb +++ b/lib/ruby-vips.rb @@ -1 +1 @@ -require 'vips' +require "vips" diff --git a/lib/vips.rb b/lib/vips.rb index e94f6962..2815ff2c 100644 --- a/lib/vips.rb +++ b/lib/vips.rb @@ -4,8 +4,8 @@ # Author:: John Cupitt (mailto:jcupitt@gmail.com) # License:: MIT -require 'ffi' -require 'logger' +require "ffi" +require "logger" # This module uses FFI to make a simple layer over the glib and gobject # libraries. @@ -37,12 +37,12 @@ module GLib class << self attr_accessor :logger end - @logger = Logger.new(STDOUT) + @logger = Logger.new($stdout) @logger.level = Logger::WARN extend FFI::Library - ffi_lib library_name('glib-2.0', 0) + ffi_lib library_name("glib-2.0", 0) attach_function :g_malloc, [:size_t], :pointer @@ -52,20 +52,20 @@ class << self callback :g_log_func, [:string, :int, :string, :pointer], :void attach_function :g_log_set_handler, - [:string, :int, :g_log_func, :pointer], :int + [:string, :int, :g_log_func, :pointer], :int attach_function :g_log_remove_handler, [:string, :int], :void # log flags - LOG_FLAG_RECURSION = 1 << 0 - LOG_FLAG_FATAL = 1 << 1 + LOG_FLAG_RECURSION = 1 << 0 + LOG_FLAG_FATAL = 1 << 1 # GLib log levels - LOG_LEVEL_ERROR = 1 << 2 # always fatal - LOG_LEVEL_CRITICAL = 1 << 3 - LOG_LEVEL_WARNING = 1 << 4 - LOG_LEVEL_MESSAGE = 1 << 5 - LOG_LEVEL_INFO = 1 << 6 - LOG_LEVEL_DEBUG = 1 << 7 + LOG_LEVEL_ERROR = 1 << 2 # always fatal + LOG_LEVEL_CRITICAL = 1 << 3 + LOG_LEVEL_WARNING = 1 << 4 + LOG_LEVEL_MESSAGE = 1 << 5 + LOG_LEVEL_INFO = 1 << 6 + LOG_LEVEL_DEBUG = 1 << 7 # map glib levels to Logger::Severity GLIB_TO_SEVERITY = { @@ -83,9 +83,9 @@ class << self @glib_log_handler_id = 0 # module-level, so it's not GCd away - LOG_HANDLER = Proc.new do |domain, level, message, _user_data| + LOG_HANDLER = proc { |domain, level, message, _user_data| @logger.log(GLIB_TO_SEVERITY[level], message, domain) - end + } def self.remove_log_handler if @glib_log_handler_id != 0 && @glib_log_domain @@ -95,7 +95,7 @@ def self.remove_log_handler end def self.set_log_domain domain - GLib::remove_log_handler + GLib.remove_log_handler @glib_log_domain = domain @@ -125,7 +125,7 @@ def self.set_log_domain domain # on shutdown and we don't want LOG_HANDLER to be invoked # after Ruby has gone at_exit { - GLib::remove_log_handler + GLib.remove_log_handler } end end @@ -134,7 +134,7 @@ def self.set_log_domain domain module GObject extend FFI::Library - ffi_lib library_name('gobject-2.0', 0) + ffi_lib library_name("gobject-2.0", 0) # we can't just use ulong, windows has different int sizing rules if FFI::Platform::ADDRESS_SIZE == 64 @@ -162,8 +162,8 @@ module GObject GOBJECT_TYPE = g_type_from_name "GObject" end -require 'vips/gobject' -require 'vips/gvalue' +require "vips/gobject" +require "vips/gvalue" # This module provides a binding for the [libvips image processing # library](https://libvips.github.io/libvips/). @@ -208,9 +208,9 @@ module GObject # for full details # on the various modes available. # -# You can also load formatted images from memory buffers, create images that -# wrap C-style memory arrays, or make images from constants. Use {Source} -# and {Image.new_from_source} to load images from any data source, for +# You can also load formatted images from memory buffers, create images that +# wrap C-style memory arrays, or make images from constants. Use {Source} +# and {Image.new_from_source} to load images from any data source, for # example URIs. # # The next line: @@ -254,7 +254,7 @@ module GObject # suffix. You can also write formatted images to memory buffers, or dump # image data to a raw memory array. # -# Use {Target} and {Image#write_to_target} to write formatted images to +# Use {Target} and {Image#write_to_target} to write formatted images to # any data sink, for example URIs. # # # How it works @@ -407,8 +407,8 @@ module GObject # # # Automatic YARD documentation # -# The bulk of these API docs are generated automatically by {Yard#generate}. -# It examines libvips and writes a summary of each operation and the arguments +# The bulk of these API docs are generated automatically by {Yard#generate}. +# It examines libvips and writes a summary of each operation and the arguments # and options that that operation expects. # # Use the [C API # docs](https://libvips.github.io/libvips/API/current) @@ -423,7 +423,7 @@ module GObject # # Draw operations # # There are two ways of calling the libvips draw operations, like -# {Image#draw_circle} and {Image#draw_line}. +# {Image#draw_circle} and {Image#draw_line}. # # First, you can use them like functions. For example: # @@ -450,8 +450,8 @@ module GObject # end # ``` # -# Now each {Image#draw_line} will directly modify the mutable image, saving -# the copy. This is much faster and needs much less memory. +# Now each {Image#draw_line} will directly modify the mutable image, saving +# the copy. This is much faster and needs much less memory. # # # Metadata read # @@ -493,7 +493,7 @@ module GObject # ```ruby # image = Vips::Image.black 1, 100000 # image.set_progress true -# +# # def progress_to_s(name, progress) # puts "#{name}:" # puts " run = #{progress[:run]}" @@ -502,23 +502,23 @@ module GObject # puts " npels = #{progress[:npels]}" # puts " percent = #{progress[:percent]}" # end -# +# # image.signal_connect :preeval do |progress| # progress_to_s("preeval", progress) # end -# +# # image.signal_connect :eval do |progress| # progress_to_s("eval", progress) # image.set_kill(true) if progress[:percent] > 50 # end -# +# # image.signal_connect :posteval do |progress| # progress_to_s("posteval", progress) # end -# +# # image.avg # ``` -# +# # The `:eval` signal will fire for every tile that is processed. You can stop # progress with {Image#set_kill} and processing will end with an exception. # @@ -570,10 +570,10 @@ module GObject module Vips extend FFI::Library - ffi_lib library_name('vips', 42) + ffi_lib library_name("vips", 42) LOG_DOMAIN = "VIPS" - GLib::set_log_domain LOG_DOMAIN + GLib.set_log_domain LOG_DOMAIN typedef :ulong, :GType @@ -587,9 +587,9 @@ class Error < RuntimeError def initialize msg = nil if msg @details = msg - elsif Vips::vips_error_buffer != "" - @details = Vips::vips_error_buffer - Vips::vips_error_clear + elsif Vips.vips_error_buffer != "" + @details = Vips.vips_error_buffer + Vips.vips_error_clear else @details = nil end @@ -599,7 +599,7 @@ def initialize msg = nil # # @return [String] The error message def to_s - if @details != nil + if !@details.nil? @details else super.to_s @@ -609,8 +609,8 @@ def to_s attach_function :vips_init, [:string], :int - if Vips::vips_init($0) != 0 - throw Vips::get_error + if Vips.vips_init($0) != 0 + throw Vips.get_error end # don't use at_exit to call vips_shutdown, it causes problems with fork, and @@ -674,7 +674,7 @@ def self.vector_set enabled # Don't use this, instead change GLib::logger.level. def self.set_debug debug if debug - GLib::logger.level = Logger::DEBUG + GLib.logger.level = Logger::DEBUG end end @@ -696,37 +696,37 @@ def self.get_suffixes # vips_foreign_get_suffixes() was added in libvips 8.8 return [] unless Vips.respond_to? :vips_foreign_get_suffixes - array = Vips::vips_foreign_get_suffixes + array = Vips.vips_foreign_get_suffixes names = [] p = array until (q = p.read_pointer).null? suff = q.read_string - GLib::g_free q + GLib.g_free q names << suff unless names.include? suff p += FFI::Type::POINTER.size end - GLib::g_free array + GLib.g_free array names end - LIBRARY_VERSION = Vips::version_string + LIBRARY_VERSION = Vips.version_string # libvips has this arbitrary number as a sanity-check upper bound on image # size. It's sometimes useful to know when calculating scale factors. MAX_COORD = 10000000 end -require 'vips/object' -require 'vips/operation' -require 'vips/image' -require 'vips/mutableimage' -require 'vips/interpolate' -require 'vips/region' -require 'vips/version' -require 'vips/connection' -require 'vips/source' -require 'vips/sourcecustom' -require 'vips/target' -require 'vips/targetcustom' +require "vips/object" +require "vips/operation" +require "vips/image" +require "vips/mutableimage" +require "vips/interpolate" +require "vips/region" +require "vips/version" +require "vips/connection" +require "vips/source" +require "vips/sourcecustom" +require "vips/target" +require "vips/targetcustom" diff --git a/lib/vips/blend_mode.rb b/lib/vips/blend_mode.rb index bcd96741..822d5d60 100644 --- a/lib/vips/blend_mode.rb +++ b/lib/vips/blend_mode.rb @@ -3,14 +3,14 @@ module Vips # # * `:clear` where the second object is drawn, the first is removed # * `:source` the second object is drawn as if nothing were below - # * `:over` the image shows what you would expect if you held two + # * `:over` the image shows what you would expect if you held two # semi-transparent slides on top of each other - # * `:in` the first object is removed completely, the second is only + # * `:in` the first object is removed completely, the second is only # drawn where the first was # * `:out` the second is drawn only where the first isn't - # * `:atop` this leaves the first object mostly intact, but mixes both + # * `:atop` this leaves the first object mostly intact, but mixes both # objects in the overlapping area - # * `:dest` leaves the first object untouched, the second is discarded + # * `:dest` leaves the first object untouched, the second is discarded # completely # * `:dest_over` like `:over`, but swaps the arguments # * `:dest_in` like `:in`, but swaps the arguments diff --git a/lib/vips/connection.rb b/lib/vips/connection.rb index cf761780..51b9ba6f 100644 --- a/lib/vips/connection.rb +++ b/lib/vips/connection.rb @@ -4,10 +4,10 @@ # Author:: John Cupitt (mailto:jcupitt@gmail.com) # License:: MIT -require 'ffi' +require "ffi" module Vips - if Vips::at_least_libvips?(8, 9) + if Vips.at_least_libvips?(8, 9) attach_function :vips_connection_filename, [:pointer], :string attach_function :vips_connection_nick, [:pointer], :string end @@ -34,13 +34,13 @@ class ManagedStruct < Vips::Object::ManagedStruct # Get any filename associated with a connection, or nil. def filename - Vips::vips_connection_filename self + Vips.vips_connection_filename self end # Get a nickname (short description) of a connection that could be shown to # the user. def nick - Vips::vips_connection_nick self + Vips.vips_connection_nick self end end end diff --git a/lib/vips/gobject.rb b/lib/vips/gobject.rb index 7dedea28..07005215 100644 --- a/lib/vips/gobject.rb +++ b/lib/vips/gobject.rb @@ -4,8 +4,8 @@ # Author:: John Cupitt (mailto:jcupitt@gmail.com) # License:: MIT -require 'ffi' -require 'forwardable' +require "ffi" +require "forwardable" module GObject # we have a number of things we need to inherit in different ways: @@ -44,8 +44,8 @@ module GObjectLayout def self.included base base.class_eval do layout :g_type_instance, :pointer, - :ref_count, :uint, - :qdata, :pointer + :ref_count, :uint, + :qdata, :pointer end end end @@ -58,7 +58,7 @@ def self.release ptr # GLib::logger.debug("GObject::GObject::ManagedStruct.release") { # "unreffing #{ptr}" # } - ::GObject::g_object_unref ptr + ::GObject.g_object_unref ptr end end @@ -88,13 +88,11 @@ def ffi_struct # get the pointer we were built from ... #to_ptr gets the pointer after we # have wrapped it up with an auto unref - def ptr - @ptr - end + attr_reader :ptr class << self def ffi_struct - self.const_get :Struct + const_get :Struct end end @@ -105,7 +103,7 @@ def ffi_managed_struct class << self def ffi_managed_struct - self.const_get :ManagedStruct + const_get :ManagedStruct end end end @@ -113,10 +111,10 @@ def ffi_managed_struct class GParamSpec < FFI::Struct # the first few public fields layout :g_type_instance, :pointer, - :name, :string, - :flags, :uint, - :value_type, :GType, - :owner_type, :GType + :name, :string, + :flags, :uint, + :value_type, :GType, + :owner_type, :GType end class GParamSpecPtr < FFI::Struct diff --git a/lib/vips/gvalue.rb b/lib/vips/gvalue.rb index dad278f7..c6a1cb8a 100644 --- a/lib/vips/gvalue.rb +++ b/lib/vips/gvalue.rb @@ -3,7 +3,7 @@ # Author:: John Cupitt (mailto:jcupitt@gmail.com) # License:: MIT -require 'ffi' +require "ffi" module GObject # Represent a GValue. Example use: @@ -22,7 +22,7 @@ module GObject class GValue < FFI::ManagedStruct layout :gtype, :GType, - :data, [:ulong_long, 2] + :data, [:ulong_long, 2] # convert an enum value (str/symb/int) into an int ready for libvips def self.from_nick(gtype, value) @@ -31,7 +31,7 @@ def self.from_nick(gtype, value) if value.is_a? String # libvips expects "-" as a separator in enum names, but "_" is more # convenient for ruby, eg. :b_w - value = Vips::vips_enum_from_nick "ruby-vips", gtype, value.tr("_", "-") + value = Vips.vips_enum_from_nick "ruby-vips", gtype, value.tr("_", "-") if value == -1 raise Vips::Error end @@ -42,7 +42,7 @@ def self.from_nick(gtype, value) # convert an int enum back into a symbol def self.to_nick(gtype, enum_value) - enum_name = Vips::vips_enum_nick gtype, enum_value + enum_name = Vips.vips_enum_nick gtype, enum_value if enum_name.nil? raise Vips::Error end @@ -52,7 +52,7 @@ def self.to_nick(gtype, enum_value) def self.release ptr # GLib::logger.debug("GObject::GValue::release") {"ptr = #{ptr}"} - ::GObject::g_value_unset ptr + ::GObject.g_value_unset ptr end # Allocate memory for a GValue and return a class wrapper. Memory will @@ -70,14 +70,14 @@ def self.alloc pointer = FFI::Pointer.new GValue, memory # ... and wrap in a GValue - return GValue.new pointer + GValue.new pointer end # Set the type of thing a gvalue can hold. # # @param gtype [GType] the type of thing this GValue can hold. def init gtype - ::GObject::g_value_init self, gtype + ::GObject.g_value_init self, gtype end # Set the value of a GValue. The value is converted to the type of the @@ -90,76 +90,76 @@ def set value # } gtype = self[:gtype] - fundamental = ::GObject::g_type_fundamental gtype + fundamental = ::GObject.g_type_fundamental gtype case gtype when GBOOL_TYPE - ::GObject::g_value_set_boolean self, (value ? 1 : 0) + ::GObject.g_value_set_boolean self, (value ? 1 : 0) when GINT_TYPE - ::GObject::g_value_set_int self, value + ::GObject.g_value_set_int self, value when GUINT64_TYPE - ::GObject::g_value_set_uint64 self, value + ::GObject.g_value_set_uint64 self, value when GDOUBLE_TYPE - ::GObject::g_value_set_double self, value + ::GObject.g_value_set_double self, value when GSTR_TYPE - ::GObject::g_value_set_string self, value + ::GObject.g_value_set_string self, value when Vips::REFSTR_TYPE - ::Vips::vips_value_set_ref_string self, value + ::Vips.vips_value_set_ref_string self, value when Vips::ARRAY_INT_TYPE value = [value] unless value.is_a? Array - Vips::vips_value_set_array_int self, nil, value.length - ptr = Vips::vips_value_get_array_int self, nil + Vips.vips_value_set_array_int self, nil, value.length + ptr = Vips.vips_value_get_array_int self, nil ptr.write_array_of_int32 value when Vips::ARRAY_DOUBLE_TYPE value = [value] unless value.is_a? Array # this will allocate an array in the gvalue - Vips::vips_value_set_array_double self, nil, value.length + Vips.vips_value_set_array_double self, nil, value.length # pull the array out and fill it - ptr = Vips::vips_value_get_array_double self, nil + ptr = Vips.vips_value_get_array_double self, nil ptr.write_array_of_double value when Vips::ARRAY_IMAGE_TYPE value = [value] unless value.is_a? Array - Vips::vips_value_set_array_image self, value.length - ptr = Vips::vips_value_get_array_image self, nil + Vips.vips_value_set_array_image self, value.length + ptr = Vips.vips_value_get_array_image self, nil ptr.write_array_of_pointer value # the gvalue needs a ref on each of the images - value.each { |image| ::GObject::g_object_ref image } + value.each { |image| ::GObject.g_object_ref image } when Vips::BLOB_TYPE len = value.bytesize - ptr = GLib::g_malloc len - Vips::vips_value_set_blob self, GLib::G_FREE, ptr, len + ptr = GLib.g_malloc len + Vips.vips_value_set_blob self, GLib::G_FREE, ptr, len ptr.write_bytes value else case fundamental when GFLAGS_TYPE - ::GObject::g_value_set_flags self, value + ::GObject.g_value_set_flags self, value when GENUM_TYPE enum_value = GValue.from_nick(self[:gtype], value) - ::GObject::g_value_set_enum self, enum_value + ::GObject.g_value_set_enum self, enum_value when GOBJECT_TYPE - ::GObject::g_value_set_object self, value + ::GObject.g_value_set_object self, value else - raise Vips::Error, "unimplemented gtype for set: " + - "#{::GObject::g_type_name gtype} (#{gtype})" + raise Vips::Error, "unimplemented gtype for set: " \ + "#{::GObject.g_type_name gtype} (#{gtype})" end end end @@ -170,72 +170,72 @@ def set value # @return [Any] the value held by the GValue def get gtype = self[:gtype] - fundamental = ::GObject::g_type_fundamental gtype + fundamental = ::GObject.g_type_fundamental gtype result = nil case gtype when GBOOL_TYPE - result = ::GObject::g_value_get_boolean(self) != 0 ? true : false + result = ::GObject.g_value_get_boolean(self) != 0 when GINT_TYPE - result = ::GObject::g_value_get_int self + result = ::GObject.g_value_get_int self when GUINT64_TYPE - result = ::GObject::g_value_get_uint64 self + result = ::GObject.g_value_get_uint64 self when GDOUBLE_TYPE - result = ::GObject::g_value_get_double self + result = ::GObject.g_value_get_double self when GSTR_TYPE - result = ::GObject::g_value_get_string self + result = ::GObject.g_value_get_string self when Vips::REFSTR_TYPE len = Vips::SizeStruct.new - result = ::Vips::vips_value_get_ref_string self, len + result = ::Vips.vips_value_get_ref_string self, len when Vips::ARRAY_INT_TYPE len = Vips::IntStruct.new - array = Vips::vips_value_get_array_int self, len + array = Vips.vips_value_get_array_int self, len result = array.get_array_of_int32 0, len[:value] when Vips::ARRAY_DOUBLE_TYPE len = Vips::IntStruct.new - array = Vips::vips_value_get_array_double self, len + array = Vips.vips_value_get_array_double self, len result = array.get_array_of_double 0, len[:value] when Vips::ARRAY_IMAGE_TYPE len = Vips::IntStruct.new - array = Vips::vips_value_get_array_image self, len + array = Vips.vips_value_get_array_image self, len result = array.get_array_of_pointer 0, len[:value] result.map! do |pointer| - ::GObject::g_object_ref pointer + ::GObject.g_object_ref pointer Vips::Image.new pointer end when Vips::BLOB_TYPE len = Vips::SizeStruct.new - array = Vips::vips_value_get_blob self, len + array = Vips.vips_value_get_blob self, len result = array.get_bytes 0, len[:value] else case fundamental when GFLAGS_TYPE - result = ::GObject::g_value_get_flags self + result = ::GObject.g_value_get_flags self when GENUM_TYPE - enum_value = ::GObject::g_value_get_enum(self) + enum_value = ::GObject.g_value_get_enum(self) result = GValue.to_nick self[:gtype], enum_value when GOBJECT_TYPE - obj = ::GObject::g_value_get_object self + obj = ::GObject.g_value_get_object self # g_value_get_object() does not add a ref ... we need to add # one to match the unref in gobject release - ::GObject::g_object_ref obj + ::GObject.g_object_ref obj result = Vips::Image.new obj else - raise Vips::Error, "unimplemented gtype for get: " + - "#{::GObject::g_type_name gtype} (#{gtype})" + raise Vips::Error, "unimplemented gtype for get: " \ + "#{::GObject.g_type_name gtype} (#{gtype})" end end @@ -243,15 +243,15 @@ def get # "result = #{result.inspect[0..50]}" # } - return result + result end - # Clear the thing held by a GValue. + # Clear the thing held by a GValue. # - # This happens automatically when a GValue is GCed, but this method can be + # This happens automatically when a GValue is GCed, but this method can be # handy if you need to drop a reference explicitly for some reason. - def unset - ::GObject::g_value_unset self + def unset + ::GObject.g_value_unset self end end @@ -281,7 +281,7 @@ def unset # use :pointer rather than GObject.ptr to avoid casting later attach_function :g_object_set_property, - [:pointer, :string, GValue.ptr], :void + [:pointer, :string, GValue.ptr], :void attach_function :g_object_get_property, - [:pointer, :string, GValue.ptr], :void + [:pointer, :string, GValue.ptr], :void end diff --git a/lib/vips/image.rb b/lib/vips/image.rb index e60721e0..f77366a8 100644 --- a/lib/vips/image.rb +++ b/lib/vips/image.rb @@ -4,13 +4,13 @@ # Author:: John Cupitt (mailto:jcupitt@gmail.com) # License:: MIT -require 'ffi' +require "ffi" module Vips private attach_function :vips_image_new_matrix_from_array, - [:int, :int, :pointer, :int], :pointer + [:int, :int, :pointer, :int], :pointer attach_function :vips_image_copy_memory, [:pointer], :pointer @@ -25,35 +25,35 @@ module Vips attach_function :vips_foreign_find_load_buffer, [:pointer, :size_t], :string attach_function :vips_foreign_find_save_buffer, [:string], :string - if Vips::at_least_libvips?(8, 9) + if Vips.at_least_libvips?(8, 9) attach_function :vips_foreign_find_load_source, [:pointer], :string attach_function :vips_foreign_find_save_target, [:string], :string end attach_function :vips_image_write_to_memory, - [:pointer, SizeStruct.ptr], :pointer + [:pointer, SizeStruct.ptr], :pointer attach_function :vips_image_get_typeof, [:pointer, :string], :GType attach_function :vips_image_get, - [:pointer, :string, GObject::GValue.ptr], :int + [:pointer, :string, GObject::GValue.ptr], :int attach_function :vips_image_get_width, [:pointer], :int attach_function :vips_image_get_height, [:pointer], :int attach_function :vips_image_get_bands, [:pointer], :int - if Vips::at_least_libvips?(8, 5) + if Vips.at_least_libvips?(8, 5) attach_function :vips_image_get_fields, [:pointer], :pointer attach_function :vips_image_hasalpha, [:pointer], :int end - if Vips::at_least_libvips?(8, 6) + if Vips.at_least_libvips?(8, 6) attach_function :vips_addalpha, [:pointer, :pointer, :varargs], :int end # move these three lines to mutableimage when we finally remove set and # remove in this class attach_function :vips_image_set, - [:pointer, :string, GObject::GValue.ptr], :void + [:pointer, :string, GObject::GValue.ptr], :void attach_function :vips_image_remove, [:pointer, :string], :void attach_function :vips_band_format_iscomplex, [:int], :int @@ -105,17 +105,17 @@ class GenericPtr < FFI::Struct # handy for overloads ... want to be able to apply a function to an # array or to a scalar def self.smap x, &block - x.is_a?(Array) ? x.map { |y| smap(y, &block) } : block.(x) + x.is_a?(Array) ? x.map { |y| smap(y, &block) } : block.call(x) end def self.complex? format format_number = GObject::GValue.from_nick BAND_FORMAT_TYPE, format - Vips::vips_band_format_iscomplex(format_number) != 0 + Vips.vips_band_format_iscomplex(format_number) != 0 end def self.float? format format_number = GObject::GValue.from_nick BAND_FORMAT_TYPE, format - Vips::vips_band_format_isfloat(format_number) != 0 + Vips.vips_band_format_isfloat(format_number) != 0 end # run a complex operation on a complex image, or an image with an even @@ -124,12 +124,12 @@ def self.float? format def self.run_cmplx image, &block original_format = image.format - unless Image::complex? image.format + unless Image.complex? image.format if image.bands % 2 != 0 raise Vips::Error, "not an even number of bands" end - unless Image::float? image.format + unless Image.float? image.format image = image.cast :float end @@ -137,9 +137,9 @@ def self.run_cmplx image, &block image = image.copy format: new_format, bands: image.bands / 2 end - image = block.(image) + image = block.call(image) - unless Image::complex? original_format + unless Image.complex? original_format new_format = image.format == :dpcomplex ? :double : :float image = image.copy format: new_format, bands: image.bands * 2 end @@ -203,14 +203,14 @@ def respond_to? name, include_all = false def respond_to_missing? name, include_all = false # respond to all vips operations by nickname - return true if Vips::type_find("VipsOperation", name.to_s) != 0 + return true if Vips.type_find("VipsOperation", name.to_s) != 0 super end def self.respond_to_missing? name, include_all = false # respond to all vips operations by nickname - return true if Vips::type_find("VipsOperation", name.to_s) != 0 + return true if Vips.type_find("VipsOperation", name.to_s) != 0 super end @@ -270,9 +270,9 @@ def self.new_from_file name, **opts # pass this raise Vips::Error, "filename is nil" if name.nil? - filename = Vips::p2str(Vips::vips_filename_get_filename name) - option_string = Vips::p2str(Vips::vips_filename_get_options name) - loader = Vips::vips_foreign_find_load filename + filename = Vips.p2str(Vips.vips_filename_get_filename(name)) + option_string = Vips.p2str(Vips.vips_filename_get_options(name)) + loader = Vips.vips_foreign_find_load filename raise Vips::Error if loader.nil? Operation.call loader, [filename], opts, option_string @@ -310,7 +310,7 @@ def self.new_from_file name, **opts # @macro vips.loadopts # @return [Image] the loaded image def self.new_from_buffer data, option_string, **opts - loader = Vips::vips_foreign_find_load_buffer data, data.bytesize + loader = Vips.vips_foreign_find_load_buffer data, data.bytesize raise Vips::Error if loader.nil? Vips::Operation.call loader, [data], opts, option_string @@ -321,8 +321,8 @@ def self.new_from_buffer data, option_string, **opts # ``` # image = Vips::Image.black(16, 16) + 128 # data = image.write_to_memory - # - # x = Vips::Image.new_from_memory data, + # + # x = Vips::Image.new_from_memory data, # image.width, image.height, image.bands, image.format # ``` # @@ -348,7 +348,7 @@ def self.new_from_memory data, width, height, bands, format end format_number = GObject::GValue.from_nick BAND_FORMAT_TYPE, format - vi = Vips::vips_image_new_from_memory data, size, + vi = Vips.vips_image_new_from_memory data, size, width, height, bands, format_number raise Vips::Error if vi.null? image = new(vi) @@ -373,7 +373,7 @@ def self.new_from_memory data, width, height, bands, format # @return [Image] the loaded image def self.new_from_memory_copy data, width, height, bands, format format_number = GObject::GValue.from_nick BAND_FORMAT_TYPE, format - vi = Vips::vips_image_new_from_memory_copy data, data.bytesize, + vi = Vips.vips_image_new_from_memory_copy data, data.bytesize, width, height, bands, format_number raise Vips::Error if vi.null? new(vi) @@ -404,7 +404,7 @@ def self.new_from_memory_copy data, width, height, bands, format # TIFF images will work. # # Loading is fast: only enough data is read to be able to fill - # out the header. Pixels will only be read and decompressed when they are + # out the header. Pixels will only be read and decompressed when they are # needed. # # @param source [Vips::Source] the source to load from @@ -412,7 +412,7 @@ def self.new_from_memory_copy data, width, height, bands, format # @macro vips.loadopts # @return [Image] the loaded image def self.new_from_source source, option_string, **opts - loader = Vips::vips_foreign_find_load_source source + loader = Vips.vips_foreign_find_load_source source raise Vips::Error if loader.nil? Vips::Operation.call loader, [source], opts, option_string @@ -421,8 +421,8 @@ def self.new_from_source source, option_string, **opts def self.matrix_from_array width, height, array ptr = FFI::MemoryPointer.new :double, array.length ptr.write_array_of_double array - image = Vips::vips_image_new_matrix_from_array width, height, - ptr, array.length + image = Vips.vips_image_new_matrix_from_array width, height, + ptr, array.length Vips::Image.new image end @@ -486,13 +486,11 @@ def self.new_from_array array, scale = 1, offset = 0 image = Vips::Image.matrix_from_array width, height, array raise Vips::Error if image.nil? - image = image.mutate do |mutable| + image.mutate do |mutable| # be careful to set them as double - mutable.set_type! GObject::GDOUBLE_TYPE, 'scale', scale.to_f - mutable.set_type! GObject::GDOUBLE_TYPE, 'offset', offset.to_f + mutable.set_type! GObject::GDOUBLE_TYPE, "scale", scale.to_f + mutable.set_type! GObject::GDOUBLE_TYPE, "offset", offset.to_f end - - return image end # A new image is created with the same width, height, format, @@ -508,7 +506,7 @@ def new_from_image value pixel = (Vips::Image.black(1, 1) + value).cast(format) image = pixel.embed 0, 0, width, height, extend: :copy image.copy interpretation: interpretation, xres: xres, yres: yres, - xoffset: xoffset, yoffset: yoffset + xoffset: xoffset, yoffset: yoffset end # Write this image to a file. Save options may be encoded in the @@ -543,9 +541,9 @@ def new_from_image value def write_to_file name, **opts raise Vips::Error, "filename is nil" if name.nil? - filename = Vips::p2str(Vips::vips_filename_get_filename name) - option_string = Vips::p2str(Vips::vips_filename_get_options name) - saver = Vips::vips_foreign_find_save filename + filename = Vips.p2str(Vips.vips_filename_get_filename(name)) + option_string = Vips.p2str(Vips.vips_filename_get_options(name)) + saver = Vips.vips_foreign_find_save filename raise Vips::Error if saver.nil? Vips::Operation.call saver, [self, filename], opts, option_string @@ -580,9 +578,9 @@ def write_to_file name, **opts # @return [String] the image saved in the specified format def write_to_buffer format_string, **opts raise Vips::Error, "filename is nil" if format_string.nil? - filename = Vips::p2str(Vips::vips_filename_get_filename format_string) - option_string = Vips::p2str(Vips::vips_filename_get_options format_string) - saver = Vips::vips_foreign_find_save_buffer filename + filename = Vips.p2str(Vips.vips_filename_get_filename(format_string)) + option_string = Vips.p2str(Vips.vips_filename_get_options(format_string)) + saver = Vips.vips_foreign_find_save_buffer filename raise Vips::Error if saver.nil? buffer = Vips::Operation.call saver, [self], opts, option_string @@ -590,7 +588,7 @@ def write_to_buffer format_string, **opts write_gc - return buffer + buffer end # Write this image to a target. Save options may be encoded in @@ -621,9 +619,9 @@ def write_to_buffer format_string, **opts # @macro vips.saveopts def write_to_target target, format_string, **opts raise Vips::Error, "filename is nil" if format_string.nil? - filename = Vips::p2str(Vips::vips_filename_get_filename format_string) - option_string = Vips::p2str(Vips::vips_filename_get_options format_string) - saver = Vips::vips_foreign_find_save_target filename + filename = Vips.p2str(Vips.vips_filename_get_filename(format_string)) + option_string = Vips.p2str(Vips.vips_filename_get_options(format_string)) + saver = Vips.vips_foreign_find_save_target filename raise Vips::Error if saver.nil? Vips::Operation.call saver, [self, target], opts, option_string @@ -635,7 +633,7 @@ def write_to_target target, format_string, **opts # @return [String] the pixels as a huge binary string def write_to_memory len = Vips::SizeStruct.new - ptr = Vips::vips_image_write_to_memory self, len + ptr = Vips.vips_image_write_to_memory self, len raise Vips::Error if ptr.nil? # wrap up as an autopointer @@ -644,15 +642,15 @@ def write_to_memory ptr.get_bytes 0, len[:value] end - # Turn progress signalling on and off. + # Turn progress signalling on and off. # # If this is on, the most-downstream image from this image will issue - # progress signals. + # progress signals. # # @see Object#signal_connect # @param state [Boolean] progress signalling state def set_progress state - Vips::vips_image_set_progress self, state + Vips.vips_image_set_progress self, state end # Kill computation of this time. @@ -663,7 +661,7 @@ def set_progress state # @see Object#signal_connect # @param kill [Boolean] stop computation def set_kill kill - Vips::vips_image_set_kill self, kill + Vips.vips_image_set_kill self, kill end # Get the `GType` of a metadata field. The result is 0 if no such field @@ -675,12 +673,12 @@ def set_kill kill def get_typeof name # on libvips before 8.5, property types must be searched first, # since vips_image_get_typeof returned built-in enums as int - unless Vips::at_least_libvips?(8, 5) + unless Vips.at_least_libvips?(8, 5) gtype = parent_get_typeof name return gtype if gtype != 0 end - Vips::vips_image_get_typeof self, name + Vips.vips_image_get_typeof self, name end # Get a metadata item from an image. Ruby types are constructed @@ -699,12 +697,12 @@ def get_typeof name def get name # with old libvips, we must fetch properties (as opposed to # metadata) via VipsObject - unless Vips::at_least_libvips?(8, 5) + unless Vips.at_least_libvips?(8, 5) return super if parent_get_typeof(name) != 0 end gvalue = GObject::GValue.alloc - raise Vips::Error if Vips::vips_image_get(self, name, gvalue) != 0 + raise Vips::Error if Vips.vips_image_get(self, name, gvalue) != 0 result = gvalue.get gvalue.unset @@ -719,22 +717,22 @@ def get_fields # vips_image_get_fields() was added in libvips 8.5 return [] unless Vips.respond_to? :vips_image_get_fields - array = Vips::vips_image_get_fields self + array = Vips.vips_image_get_fields self names = [] p = array until (q = p.read_pointer).null? names << q.read_string - GLib::g_free q + GLib.g_free q p += FFI::Type::POINTER.size end - GLib::g_free array + GLib.g_free array names end - # Mutate an image with a block. Inside the block, you can call methods - # which modify the image, such as setting or removing metadata, or + # Mutate an image with a block. Inside the block, you can call methods + # which modify the image, such as setting or removing metadata, or # modifying pixels. # # For example: @@ -754,29 +752,29 @@ def mutate mutable.image end - # This method is deprecated. + # This method is deprecated. # - # Please use {MutableImage#set_type!} instead. + # Please use {MutableImage#set_type!} instead. def set_type gtype, name, value gvalue = GObject::GValue.alloc gvalue.init gtype gvalue.set value - Vips::vips_image_set self, name, gvalue + Vips.vips_image_set self, name, gvalue gvalue.unset end - # This method is deprecated. + # This method is deprecated. # - # Please use {MutableImage#set!} instead. + # Please use {MutableImage#set!} instead. def set name, value set_type get_typeof(name), name, value end - # This method is deprecated. + # This method is deprecated. # - # Please use {MutableImage#remove!} instead. + # Please use {MutableImage#remove!} instead. def remove name - Vips::vips_image_remove self, name + Vips.vips_image_remove self, name end # compatibility: old name for get @@ -784,9 +782,9 @@ def get_value name get name end - # This method is deprecated. + # This method is deprecated. # - # Please use {MutableImage#set!} instead. + # Please use {MutableImage#set!} instead. def set_value name, value set name, value end @@ -795,21 +793,21 @@ def set_value name, value # # @return [Integer] image width, in pixels def width - Vips::vips_image_get_width self + Vips.vips_image_get_width self end # Get image height, in pixels. # # @return [Integer] image height, in pixels def height - Vips::vips_image_get_height self + Vips.vips_image_get_height self end # Get number of image bands. # # @return [Integer] number of image bands def bands - Vips::vips_image_get_bands self + Vips.vips_image_get_bands self end # Get image format. @@ -893,23 +891,23 @@ def size [width, height] end - if Vips::at_least_libvips?(8, 5) + if Vips.at_least_libvips?(8, 5) # Detect if image has an alpha channel # # @return [Boolean] true if image has an alpha channel. def has_alpha? - return Vips::vips_image_hasalpha(self) != 0 + Vips.vips_image_hasalpha(self) != 0 end end # vips_addalpha was added in libvips 8.6 - if Vips::at_least_libvips?(8, 6) + if Vips.at_least_libvips?(8, 6) # Append an alpha channel to an image. # # @return [Image] new image def add_alpha ptr = GenericPtr.new - result = Vips::vips_addalpha self, ptr + result = Vips.vips_addalpha self, ptr raise Vips::Error if result != 0 Vips::Image.new ptr[:value] @@ -924,7 +922,7 @@ def add_alpha # # @return [Image] new memory image def copy_memory - new_image = Vips::vips_image_copy_memory self + new_image = Vips.vips_image_copy_memory self Vips::Image.new new_image end @@ -952,7 +950,7 @@ def + other # @return [Image] result of subtraction def - other other.is_a?(Vips::Image) ? - subtract(other) : linear(1, Image::smap(other) { |x| x * -1 }) + subtract(other) : linear(1, Image.smap(other) { |x| x * -1 }) end # Multiply an image, constant or array. @@ -970,7 +968,7 @@ def * other # @return [Image] result of division def / other other.is_a?(Vips::Image) ? - divide(other) : linear(Image::smap(other) { |x| 1.0 / x }, 0) + divide(other) : linear(Image.smap(other) { |x| 1.0 / x }, 0) end # Remainder after integer division with an image, constant or array. @@ -1141,17 +1139,17 @@ def to_a # make the template for unpack template = { - char: 'c', - uchar: 'C', - short: 's_', - ushort: 'S_', - int: 'i_', - uint: 'I_', - float: 'f', - double: 'd', - complex: 'f', - dpcomplex: 'd' - }[format] + '*' + char: "c", + uchar: "C", + short: "s_", + ushort: "S_", + int: "i_", + uint: "I_", + float: "f", + double: "d", + complex: "f", + dpcomplex: "d" + }[format] + "*" # and unpack into something like [1, 2, 3, 4 ..] array = memory.unpack(template) @@ -1160,9 +1158,7 @@ def to_a pixel_array = array.each_slice(bands).to_a # build rows - row_array = pixel_array.each_slice(width).to_a - - return row_array + pixel_array.each_slice(width).to_a end # Return the largest integral value not greater than the argument. @@ -1240,7 +1236,7 @@ def bandjoin other # @param opts [Hash] Set of options # @option opts [Array] :x x positions of overlay # @option opts [Array] :y y positions of overlay - # @option opts [Vips::Interpretation] :compositing_space Composite images + # @option opts [Vips::Interpretation] :compositing_space Composite images # in this colour space # @option opts [Boolean] :premultiplied Images have premultiplied alpha # @return [Image] blended image @@ -1265,9 +1261,9 @@ def composite overlay, mode, **opts # coordinate of maximum def maxpos v, opts = max x: true, y: true - x = opts['x'] - y = opts['y'] - return v, x, y + x = opts["x"] + y = opts["y"] + [v, x, y] end # Return the coordinates of the image minimum. @@ -1276,9 +1272,9 @@ def maxpos # coordinate of minimum def minpos v, opts = min x: true, y: true - x = opts['x'] - y = opts['y'] - return v, x, y + x = opts["x"] + y = opts["y"] + [v, x, y] end # a median filter @@ -1286,7 +1282,7 @@ def minpos # @param size [Integer] size of filter window # @return [Image] result of median filter def median size = 3 - rank size, size, (size * size) / 2 + rank size, size, size**2 / 2 end # Return the real part of a complex image. @@ -1313,7 +1309,7 @@ def imag # @see xyz # @return [Image] image converted to polar coordinates def polar - Image::run_cmplx(self) { |x| x.complex :polar } + Image.run_cmplx(self) { |x| x.complex :polar } end # Return an image with polar pixels converted to rectangular. @@ -1326,7 +1322,7 @@ def polar # @see xyz # @return [Image] image converted to rectangular coordinates def rect - Image::run_cmplx(self) { |x| x.complex :rect } + Image.run_cmplx(self) { |x| x.complex :rect } end # Return the complex conjugate of an image. @@ -1338,7 +1334,7 @@ def rect # # @return [Image] complex conjugate def conj - Image::run_cmplx(self) { |x| x.complex :conj } + Image.run_cmplx(self) { |x| x.complex :conj } end # Calculate the cross phase of two images. @@ -1541,7 +1537,7 @@ module Yard "VipsArrayDouble" => "Array", "VipsArrayInt" => "Array", "VipsArrayImage" => "Array", - "VipsArrayString" => "Array", + "VipsArrayString" => "Array" } # these have hand-written methods, see above @@ -1552,15 +1548,15 @@ module Yard # turn a gtype into a ruby type name def self.gtype_to_ruby gtype - fundamental = GObject::g_type_fundamental gtype - type_name = GObject::g_type_name gtype + fundamental = GObject.g_type_fundamental gtype + type_name = GObject.g_type_name gtype if MAP_GO_TO_RUBY.include? type_name type_name = MAP_GO_TO_RUBY[type_name] end if fundamental == GObject::GFLAGS_TYPE || - fundamental == GObject::GENUM_TYPE + fundamental == GObject::GENUM_TYPE type_name = "Vips::" + type_name[/Vips(.*)/, 1] end @@ -1579,7 +1575,7 @@ def self.generate_operation introspect print "# @!method " print "self." unless introspect.member_x print "#{introspect.name}(" - print method_args.map{ |x| x[:yard_name] }.join(", ") + print method_args.map { |x| x[:yard_name] }.join(", ") print ", " if method_args.length > 0 puts "**opts)" @@ -1599,8 +1595,7 @@ def self.generate_operation introspect gtype = details[:gtype] blurb = details[:blurb] - puts "# @option opts [#{gtype_to_ruby(gtype)}] :#{yard_name} " + - "#{blurb}" + puts "# @option opts [#{gtype_to_ruby(gtype)}] :#{yard_name} #{blurb}" end optional_output.each do |arg_name, details| yard_name = details[:yard_name] @@ -1618,14 +1613,14 @@ def self.generate_operation introspect print gtype_to_ruby(required_output.first[:gtype]) else print "Array<" - print required_output.map{ |x| gtype_to_ruby(x[:gtype]) }.join(", ") + print required_output.map { |x| gtype_to_ruby(x[:gtype]) }.join(", ") print ">" end if optional_output.length > 0 print ", Hash Object>" end print "] " - print required_output.map{ |x| x[:blurb] }.join(", ") + print required_output.map { |x| x[:blurb] }.join(", ") if optional_output.length > 0 print ", " if required_output.length > 0 print "Hash of optional output items" @@ -1637,16 +1632,16 @@ def self.generate_operation introspect def self.generate alias_gtypes = {} - ALIAS.each do |name| - gtype = Vips::type_find "VipsOperation", name - alias_gtypes[gtype] = name + ALIAS.each do |name| + gtype = Vips.type_find "VipsOperation", name + alias_gtypes[gtype] = name end generate_class = lambda do |gtype, _| - if alias_gtypes.key? gtype - name = alias_gtypes[gtype] + name = if alias_gtypes.key? gtype + alias_gtypes[gtype] else - name = Vips::nickname_find gtype + Vips.nickname_find gtype end if name @@ -1660,14 +1655,14 @@ def self.generate generate_operation(introspect) if introspect end - Vips::vips_type_map gtype, generate_class, nil + Vips.vips_type_map gtype, generate_class, nil end puts "module Vips" puts " class Image" puts "" - generate_class.(GObject::g_type_from_name("VipsOperation"), nil) + generate_class.call(GObject.g_type_from_name("VipsOperation"), nil) puts " end" puts "end" diff --git a/lib/vips/interpolate.rb b/lib/vips/interpolate.rb index eb522cdb..7897a5e9 100644 --- a/lib/vips/interpolate.rb +++ b/lib/vips/interpolate.rb @@ -49,7 +49,7 @@ class ManagedStruct < Vips::Object::ManagedStruct def initialize name name = name.to_s if name.is_a? Symbol - ptr = Vips::vips_interpolate_new name + ptr = Vips.vips_interpolate_new name raise Vips::Error if ptr.nil? super ptr diff --git a/lib/vips/mutableimage.rb b/lib/vips/mutableimage.rb index c23642a6..1f08babe 100644 --- a/lib/vips/mutableimage.rb +++ b/lib/vips/mutableimage.rb @@ -4,8 +4,8 @@ # Author:: John Cupitt (mailto:jcupitt@gmail.com) # License:: MIT -require 'ffi' -require 'forwardable' +require "ffi" +require "forwardable" module Vips # This class represents a libvips image which can be modified. See @@ -13,8 +13,8 @@ module Vips class MutableImage < Vips::Object extend Forwardable alias_method :parent_get_typeof, :get_typeof - def_instance_delegators :@image, :width, :height, :bands, :format, - :interpretation, :filename, :xoffset, :yoffset, :xres, :yres, :size, + def_instance_delegators :@image, :width, :height, :bands, :format, + :interpretation, :filename, :xoffset, :yoffset, :xres, :yres, :size, :get, :get_typeof, :get_fields # layout is exactly as {Image} (since we are also wrapping a VipsImage @@ -41,24 +41,22 @@ class ManagedStruct < Vips::Object::ManagedStruct # # This is for internal use only. See {Vips::Image#mutate} for the # user-facing interface. - def image - @image - end + attr_reader :image - # Make a {MutableImage} from a regular {Image}. + # Make a {MutableImage} from a regular {Image}. # # This is for internal use only. See {Vips::Image#mutate} for the # user-facing interface. def initialize(image) - # We take a copy of the regular Image to ensure we have an unshared - # (unique) object. We forward things like #width and #height to this, and + # We take a copy of the regular Image to ensure we have an unshared + # (unique) object. We forward things like #width and #height to this, and # it's the thing we return at the end of the mutate block. copy_image = image.copy # use ptr since we need the raw unwrapped pointer inside the image ... # and make the ref that gobject will unref when it finishes pointer = copy_image.ptr - ::GObject::g_object_ref pointer + ::GObject.g_object_ref pointer super pointer # and save the copy ready for when we finish mutating @@ -82,7 +80,7 @@ def respond_to? name, include_all = false def respond_to_missing? name, include_all = false # respond to all vips operations by nickname - return true if Vips::type_find("VipsOperation", name.to_s) != 0 + return true if Vips.type_find("VipsOperation", name.to_s) != 0 super end @@ -99,7 +97,7 @@ def method_missing name, *args, **options # Create a metadata item on an image of the specifed type. Ruby types # are automatically transformed into the matching glib type (eg. - # {GObject::GINT_TYPE}), if possible. + # {GObject::GINT_TYPE}), if possible. # # For example, you can use this to set an image's ICC profile: # @@ -117,7 +115,7 @@ def set_type! gtype, name, value gvalue = GObject::GValue.alloc gvalue.init gtype gvalue.set value - Vips::vips_image_set self, name, gvalue + Vips.vips_image_set self, name, gvalue gvalue.unset end @@ -150,8 +148,7 @@ def set! name, value # # @param name [String] Metadata field to remove def remove! name - Vips::vips_image_remove self, name + Vips.vips_image_remove self, name end - end end diff --git a/lib/vips/object.rb b/lib/vips/object.rb index 54b2a95d..c67a7794 100644 --- a/lib/vips/object.rb +++ b/lib/vips/object.rb @@ -4,7 +4,7 @@ # Author:: John Cupitt (mailto:jcupitt@gmail.com) # License:: MIT -require 'ffi' +require "ffi" module Vips private @@ -21,20 +21,20 @@ module Vips public # some handy gtypes - IMAGE_TYPE = GObject::g_type_from_name "VipsImage" - ARRAY_INT_TYPE = GObject::g_type_from_name "VipsArrayInt" - ARRAY_DOUBLE_TYPE = GObject::g_type_from_name "VipsArrayDouble" - ARRAY_IMAGE_TYPE = GObject::g_type_from_name "VipsArrayImage" - REFSTR_TYPE = GObject::g_type_from_name "VipsRefString" - BLOB_TYPE = GObject::g_type_from_name "VipsBlob" - - BAND_FORMAT_TYPE = Vips::vips_band_format_get_type - INTERPRETATION_TYPE = Vips::vips_interpretation_get_type - CODING_TYPE = Vips::vips_coding_get_type - - if Vips::at_least_libvips?(8, 6) + IMAGE_TYPE = GObject.g_type_from_name "VipsImage" + ARRAY_INT_TYPE = GObject.g_type_from_name "VipsArrayInt" + ARRAY_DOUBLE_TYPE = GObject.g_type_from_name "VipsArrayDouble" + ARRAY_IMAGE_TYPE = GObject.g_type_from_name "VipsArrayImage" + REFSTR_TYPE = GObject.g_type_from_name "VipsRefString" + BLOB_TYPE = GObject.g_type_from_name "VipsBlob" + + BAND_FORMAT_TYPE = Vips.vips_band_format_get_type + INTERPRETATION_TYPE = Vips.vips_interpretation_get_type + CODING_TYPE = Vips.vips_coding_get_type + + if Vips.at_least_libvips?(8, 6) attach_function :vips_blend_mode_get_type, [], :GType - BLEND_MODE_TYPE = Vips::vips_blend_mode_get_type + BLEND_MODE_TYPE = Vips.vips_blend_mode_get_type else BLEND_MODE_TYPE = nil end @@ -45,37 +45,37 @@ class Progress < FFI::Struct layout :im, :pointer, :run, :int, :eta, :int, - :tpels, :int64_t, - :npels, :int64_t, - :percent, :int, - :start, :pointer + :tpels, :int64_t, + :npels, :int64_t, + :percent, :int, + :start, :pointer end - # Our signal marshalers. + # Our signal marshalers. # - # These are functions which take the handler as a param and return a + # These are functions which take the handler as a param and return a # closure with the right FFI signature for g_signal_connect for this - # specific signal. + # specific signal. # - # ruby-ffi makes it hard to use the g_signal_connect user data param + # ruby-ffi makes it hard to use the g_signal_connect user data param # to pass the function pointer through, unfortunately. # # We can't throw exceptions across C, so we must catch everything. - MARSHAL_PROGRESS = Proc.new do |handler| + MARSHAL_PROGRESS = proc do |handler| FFI::Function.new(:void, [:pointer, :pointer, :pointer]) do |vi, prog, cb| begin - handler.(Progress.new(prog)) + handler.call(Progress.new(prog)) rescue Exception => e puts "progress: #{e}" end end end - MARSHAL_READ = Proc.new do |handler| + MARSHAL_READ = proc do |handler| FFI::Function.new(:int64_t, [:pointer, :pointer, :int64_t]) do |i, p, len| begin - result = handler.(p, len) + result = handler.call(p, len) rescue Exception => e puts "read: #{e}" result = 0 @@ -85,10 +85,10 @@ class Progress < FFI::Struct end end - MARSHAL_SEEK = Proc.new do |handler| + MARSHAL_SEEK = proc do |handler| FFI::Function.new(:int64_t, [:pointer, :int64_t, :int]) do |i, off, whence| begin - result = handler.(off, whence) + result = handler.call(off, whence) rescue Exception => e puts "seek: #{e}" result = -1 @@ -98,10 +98,10 @@ class Progress < FFI::Struct end end - MARSHAL_WRITE = Proc.new do |handler| + MARSHAL_WRITE = proc do |handler| FFI::Function.new(:int64_t, [:pointer, :pointer, :int64_t]) do |i, p, len| begin - result = handler.(p, len) + result = handler.call(p, len) rescue Exception => e puts "write: #{e}" result = 0 @@ -111,10 +111,10 @@ class Progress < FFI::Struct end end - MARSHAL_FINISH = Proc.new do |handler| + MARSHAL_FINISH = proc do |handler| FFI::Function.new(:void, [:pointer, :pointer]) do |i, cb| begin - handler.() + handler.call rescue Exception => e puts "finish: #{e}" end @@ -123,29 +123,29 @@ class Progress < FFI::Struct # map signal name to marshal proc MARSHAL_ALL = { - :preeval => MARSHAL_PROGRESS, - :eval => MARSHAL_PROGRESS, - :posteval => MARSHAL_PROGRESS, - :read => MARSHAL_READ, - :seek => MARSHAL_SEEK, - :write => MARSHAL_WRITE, - :finish => MARSHAL_FINISH, + preeval: MARSHAL_PROGRESS, + eval: MARSHAL_PROGRESS, + posteval: MARSHAL_PROGRESS, + read: MARSHAL_READ, + seek: MARSHAL_SEEK, + write: MARSHAL_WRITE, + finish: MARSHAL_FINISH } attach_function :vips_enum_from_nick, [:string, :GType, :string], :int attach_function :vips_enum_nick, [:GType, :int], :string attach_function :vips_value_set_ref_string, - [GObject::GValue.ptr, :string], :void + [GObject::GValue.ptr, :string], :void attach_function :vips_value_set_array_double, - [GObject::GValue.ptr, :pointer, :int], :void + [GObject::GValue.ptr, :pointer, :int], :void attach_function :vips_value_set_array_int, - [GObject::GValue.ptr, :pointer, :int], :void + [GObject::GValue.ptr, :pointer, :int], :void attach_function :vips_value_set_array_image, - [GObject::GValue.ptr, :int], :void + [GObject::GValue.ptr, :int], :void callback :free_fn, [:pointer], :void attach_function :vips_value_set_blob, - [GObject::GValue.ptr, :free_fn, :pointer, :size_t], :void + [GObject::GValue.ptr, :free_fn, :pointer, :size_t], :void class SizeStruct < FFI::Struct layout :value, :size_t @@ -156,15 +156,15 @@ class IntStruct < FFI::Struct end attach_function :vips_value_get_ref_string, - [GObject::GValue.ptr, SizeStruct.ptr], :string + [GObject::GValue.ptr, SizeStruct.ptr], :string attach_function :vips_value_get_array_double, - [GObject::GValue.ptr, IntStruct.ptr], :pointer + [GObject::GValue.ptr, IntStruct.ptr], :pointer attach_function :vips_value_get_array_int, - [GObject::GValue.ptr, IntStruct.ptr], :pointer + [GObject::GValue.ptr, IntStruct.ptr], :pointer attach_function :vips_value_get_array_image, - [GObject::GValue.ptr, IntStruct.ptr], :pointer + [GObject::GValue.ptr, IntStruct.ptr], :pointer attach_function :vips_value_get_blob, - [GObject::GValue.ptr, SizeStruct.ptr], :pointer + [GObject::GValue.ptr, SizeStruct.ptr], :pointer attach_function :type_find, :vips_type_find, [:string, :string], :GType @@ -173,7 +173,7 @@ class Object < GObject::GObject # debugging ruby-vips. def self.print_all GC.start - Vips::vips_object_print_all + Vips.vips_object_print_all end # the layout of the VipsObject struct @@ -182,15 +182,15 @@ def self.included base base.class_eval do # don't actually need most of these layout :parent, GObject::GObject::Struct, - :constructed, :int, - :static_object, :int, - :argument_table, :pointer, - :nickname, :string, - :description, :string, - :preclose, :int, - :close, :int, - :postclose, :int, - :local_memory, :size_t + :constructed, :int, + :static_object, :int, + :argument_table, :pointer, + :nickname, :string, + :description, :string, + :preclose, :int, + :close, :int, + :postclose, :int, + :local_memory, :size_t end end end @@ -210,8 +210,8 @@ def get_pspec name argument_class = Vips::ArgumentClassPtr.new argument_instance = Vips::ArgumentInstancePtr.new - result = Vips::vips_object_get_argument self, name, - ppspec, argument_class, argument_instance + result = Vips.vips_object_get_argument self, name, + ppspec, argument_class, argument_instance return nil if result != 0 ppspec[:value] @@ -229,7 +229,7 @@ def get_typeof_error name def get_typeof name pspec = get_pspec name unless pspec - Vips::vips_error_clear + Vips.vips_error_clear return 0 end @@ -240,31 +240,31 @@ def get name gtype = get_typeof_error name gvalue = GObject::GValue.alloc gvalue.init gtype - GObject::g_object_get_property self, name, gvalue + GObject.g_object_get_property self, name, gvalue result = gvalue.get gvalue.unset - GLib::logger.debug("Vips::Object.get") { "#{name} == #{result}" } + GLib.logger.debug("Vips::Object.get") { "#{name} == #{result}" } - return result + result end def set name, value - GLib::logger.debug("Vips::Object.set") { "#{name} = #{value}" } + GLib.logger.debug("Vips::Object.set") { "#{name} = #{value}" } gtype = get_typeof_error name gvalue = GObject::GValue.alloc gvalue.init gtype gvalue.set value - GObject::g_object_set_property self, name, gvalue + GObject.g_object_set_property self, name, gvalue gvalue.unset end - def signal_connect name, handler=nil, &block + def signal_connect name, handler = nil, &block marshal = MARSHAL_ALL[name.to_sym] raise Vips::Error, "unsupported signal #{name}" if marshal.nil? - if block_given? + if block # our block as a Proc prc = block elsif handler @@ -274,16 +274,15 @@ def signal_connect name, handler=nil, &block raise Vips::Error, "must supply either block or handler" end - # The marshal function will make a closure with the right type signature + # The marshal function will make a closure with the right type signature # for the selected signal - callback = marshal.(prc) + callback = marshal.call(prc) # we need to make sure this is not GCd while self is alive @references << callback - GObject::g_signal_connect_data(self, name.to_s, callback, nil, nil, 0) + GObject.g_signal_connect_data(self, name.to_s, callback, nil, nil, 0) end - end class ObjectClass < FFI::Struct @@ -322,10 +321,10 @@ class ArgumentInstance < Argument class ArgumentClass < Argument layout :parent, Argument, - :object_class, ObjectClass.ptr, - :flags, :uint, - :priority, :int, - :offset, :ulong_long + :object_class, ObjectClass.ptr, + :flags, :uint, + :priority, :int, + :offset, :ulong_long end class ArgumentClassPtr < FFI::Struct @@ -339,10 +338,10 @@ class ArgumentInstancePtr < FFI::Struct # just use :pointer, not VipsObject.ptr, to avoid casting gobject # subclasses attach_function :vips_object_get_argument, - [:pointer, :string, - GObject::GParamSpecPtr.ptr, - ArgumentClassPtr.ptr, ArgumentInstancePtr.ptr], - :int + [:pointer, :string, + GObject::GParamSpecPtr.ptr, + ArgumentClassPtr.ptr, ArgumentInstancePtr.ptr], + :int attach_function :vips_object_print_all, [], :void diff --git a/lib/vips/operation.rb b/lib/vips/operation.rb index aeeae197..8fed370c 100644 --- a/lib/vips/operation.rb +++ b/lib/vips/operation.rb @@ -4,8 +4,8 @@ # Author:: John Cupitt (mailto:jcupitt@gmail.com) # License:: MIT -require 'ffi' -require 'set' +require "ffi" +require "set" module Vips private @@ -13,22 +13,22 @@ module Vips attach_function :vips_operation_new, [:string], :pointer # We may well block during this (eg. if it's avg, or perhaps jpegsave), and - # libvips might trigger some signals which ruby has handles for. + # libvips might trigger some signals which ruby has handles for. # - # We need FFI to drop the GIL lock during this call and reacquire it when + # We need FFI to drop the GIL lock during this call and reacquire it when # the call ends, or we'll deadlock. - attach_function :vips_cache_operation_build, [:pointer], :pointer, + attach_function :vips_cache_operation_build, [:pointer], :pointer, blocking: true attach_function :vips_object_unref_outputs, [:pointer], :void callback :argument_map_fn, [:pointer, - GObject::GParamSpec.ptr, - ArgumentClass.ptr, - ArgumentInstance.ptr, - :pointer, :pointer], :pointer + GObject::GParamSpec.ptr, + ArgumentClass.ptr, + ArgumentInstance.ptr, + :pointer, :pointer], :pointer attach_function :vips_argument_map, [:pointer, - :argument_map_fn, - :pointer, :pointer], :pointer + :argument_map_fn, + :pointer, :pointer], :pointer OPERATION_SEQUENTIAL = 1 OPERATION_NOCACHE = 4 @@ -46,8 +46,8 @@ module Vips # everything we know about it. This is used for doc generation as well as # call. class Introspect - attr_reader :name, :description, :flags, :args, :required_input, - :optional_input, :required_output, :optional_output, :member_x, + attr_reader :name, :description, :flags, :args, :required_input, + :optional_input, :required_output, :optional_output, :member_x, :method_args, :vips_name, :destructive @@introspect_cache = {} @@ -58,7 +58,7 @@ def initialize name if name[-1] == "!" @destructive = true # strip the trailing "!" - @vips_name = name[0 ... -1] + @vips_name = name[0...-1] else @destructive = false @vips_name = name @@ -79,9 +79,9 @@ def initialize name # Ruby arg_name = pspec[:name].tr("-", "_") @args << { - :arg_name => arg_name, - :flags => flags, - :gtype => pspec[:value_type] + arg_name: arg_name, + flags: flags, + gtype: pspec[:value_type] } end @@ -93,8 +93,8 @@ def initialize name flags = details[:flags] if (flags & ARGUMENT_INPUT) != 0 - if (flags & ARGUMENT_REQUIRED) != 0 && - (flags & ARGUMENT_DEPRECATED) == 0 + if (flags & ARGUMENT_REQUIRED) != 0 && + (flags & ARGUMENT_DEPRECATED) == 0 @required_input << details else # we allow deprecated optional args @@ -103,17 +103,17 @@ def initialize name # MODIFY INPUT args count as OUTPUT as well in non-destructive mode if (flags & ARGUMENT_MODIFY) != 0 && - !@destructive - if (flags & ARGUMENT_REQUIRED) != 0 && - (flags & ARGUMENT_DEPRECATED) == 0 + !@destructive + if (flags & ARGUMENT_REQUIRED) != 0 && + (flags & ARGUMENT_DEPRECATED) == 0 @required_output << details else @optional_output[arg_name] = details end end elsif (flags & ARGUMENT_OUTPUT) != 0 - if (flags & ARGUMENT_REQUIRED) != 0 && - (flags & ARGUMENT_DEPRECATED) == 0 + if (flags & ARGUMENT_REQUIRED) != 0 && + (flags & ARGUMENT_DEPRECATED) == 0 @required_output << details else # again, allow deprecated optional args @@ -138,8 +138,8 @@ def initialize name # we can. def add_yard_introspection name @name = name - @description = Vips::vips_object_get_description @op - @flags = Vips::vips_operation_get_flags @op + @description = Vips.vips_object_get_description @op + @flags = Vips.vips_operation_get_flags @op @member_x = nil @method_args = [] @@ -150,15 +150,15 @@ def add_yard_introspection name details[:yard_name] = arg_name == "in" ? "im" : arg_name pspec = @op.get_pspec arg_name - details[:blurb] = GObject::g_param_spec_get_blurb pspec + details[:blurb] = GObject.g_param_spec_get_blurb pspec - if (flags & ARGUMENT_INPUT) != 0 && - (flags & ARGUMENT_REQUIRED) != 0 && - (flags & ARGUMENT_DEPRECATED) == 0 - # the first required input image is the thing we will be a method + if (flags & ARGUMENT_INPUT) != 0 && + (flags & ARGUMENT_REQUIRED) != 0 && + (flags & ARGUMENT_DEPRECATED) == 0 + # the first required input image is the thing we will be a method # of if @member_x.nil? && gtype == IMAGE_TYPE - @member_x = details + @member_x = details else @method_args << details end @@ -175,7 +175,6 @@ def self.get_yard name introspect.add_yard_introspection name introspect end - end class Operation < Object @@ -201,7 +200,7 @@ def initialize value # allow init with a pointer so we can wrap the return values from # things like _build if value.is_a? String - value = Vips::vips_operation_new value + value = Vips.vips_operation_new value raise Vips::Error if value.null? end @@ -209,35 +208,35 @@ def initialize value end def build - op = Vips::vips_cache_operation_build self + op = Vips.vips_cache_operation_build self if op.null? - Vips::vips_object_unref_outputs self + Vips.vips_object_unref_outputs self raise Vips::Error end - return Operation.new op + Operation.new op end def argument_map &block - fn = Proc.new do |_op, pspec, argument_class, argument_instance, _a, _b| + fn = proc do |_op, pspec, argument_class, argument_instance, _a, _b| block.call pspec, argument_class, argument_instance end - Vips::vips_argument_map self, fn, nil, nil + Vips.vips_argument_map self, fn, nil, nil end - # Search an object for the first element to match a predicate. Search + # Search an object for the first element to match a predicate. Search # inside subarrays and sub-hashes. Equlvalent to x.flatten.find{}. def self.flat_find object, &block if object.respond_to? :each - object.each do |x| - result = flat_find x, &block - return result if result != nil + object.each do |x| + result = flat_find x, &block + return result unless result.nil? end - else - return object if yield object + elsif yield object + return object end - return nil + nil end # expand a constant into an image @@ -247,11 +246,11 @@ def self.imageize match_image, value # 2D array values become tiny 2D images # if there's nothing to match to, we also make a 2D image if (value.is_a?(Array) && value[0].is_a?(Array)) || match_image.nil? - return Image.new_from_array value + Image.new_from_array value else # we have a 1D array ... use that as a pixel constant and # expand to match match_image - return match_image.new_from_image value + match_image.new_from_image value end end @@ -259,7 +258,7 @@ def self.imageize match_image, value # required def set name, value, match_image, flags, gtype, destructive if gtype == IMAGE_TYPE - value = Operation::imageize match_image, value + value = Operation.imageize match_image, value # in non-destructive mode, make sure we have a unique copy if (flags & ARGUMENT_MODIFY) != 0 && @@ -267,7 +266,7 @@ def set name, value, match_image, flags, gtype, destructive value = value.copy.copy_memory end elsif gtype == ARRAY_IMAGE_TYPE - value = value.map { |x| Operation::imageize match_image, x } + value = value.map { |x| Operation.imageize match_image, x } end super name, value @@ -343,8 +342,8 @@ def set name, value, match_image, flags, gtype, destructive # the constant value 255. def self.call name, supplied, optional = {}, option_string = "" - GLib::logger.debug("Vips::VipsOperation.call") { - "name = #{name}, supplied = #{supplied}, " + + GLib.logger.debug("Vips::VipsOperation.call") { + "name = #{name}, supplied = #{supplied}, " \ "optional = #{optional}, option_string = #{option_string}" } @@ -356,18 +355,18 @@ def self.call name, supplied, optional = {}, option_string = "" destructive = introspect.destructive unless supplied.is_a? Array - raise Vips::Error, "unable to call #{name}: " + - "argument array is not an array" + raise Vips::Error, "unable to call #{name}: " \ + "argument array is not an array" end unless optional.is_a? Hash - raise Vips::Error, "unable to call #{name}: " + - "optional arguments are not a hash" + raise Vips::Error, "unable to call #{name}: " \ + "optional arguments are not a hash" end if supplied.length != required_input.length - raise Vips::Error, "unable to call #{name}: " + - "you supplied #{supplied.length} arguments, " + - "but operation needs " + "#{required_input.length}." + raise Vips::Error, "unable to call #{name}: " \ + "you supplied #{supplied.length} arguments, " \ + "but operation needs #{required_input.length}." end # all supplied_optional keys should be in optional_input or @@ -377,8 +376,8 @@ def self.call name, supplied, optional = {}, option_string = "" unless optional_input.has_key?(arg_name) || optional_output.has_key?(arg_name) - raise Vips::Error, "unable to call #{name}: " + - "unknown option #{arg_name}" + raise Vips::Error, "unable to call #{name}: " \ + "unknown option #{arg_name}" end end @@ -390,32 +389,28 @@ def self.call name, supplied, optional = {}, option_string = "" # # also enforce the rules around mutable and non-mutable images match_image = nil - flat_find(supplied) do |value| - if match_image + flat_find(supplied) do |value| + if match_image # no non-first image arg can ever be mutable if value.is_a?(MutableImage) - raise Vips::Error, "unable to call #{name}: " + - "only the first image argument can be mutable" + raise Vips::Error, "unable to call #{name}: " \ + "only the first image argument can be mutable" end - else - if destructive - if value.is_a?(Image) - raise Vips::Error, "unable to call #{name}: " + - "first image argument to a destructive " + - "operation must be mutable" - elsif value.is_a?(MutableImage) - match_image = value - end - else - # non destructive operation, so no mutable images - if value.is_a?(MutableImage) - raise Vips::Error, "unable to call #{name}: " + - "must not pass mutable images to " + - "non-destructive operations" - elsif value.is_a?(Image) - match_image = value - end + elsif destructive + if value.is_a?(Image) + raise Vips::Error, "unable to call #{name}: " \ + "first image argument to a destructive " \ + "operation must be mutable" + elsif value.is_a?(MutableImage) + match_image = value end + elsif value.is_a?(MutableImage) + # non destructive operation, so no mutable images + raise Vips::Error, "unable to call #{name}: " \ + "must not pass mutable images to " \ + "non-destructive operations" + elsif value.is_a?(Image) + match_image = value end # keep looping @@ -425,8 +420,8 @@ def self.call name, supplied, optional = {}, option_string = "" op = Operation.new introspect.vips_name # set any string args first so they can't be overridden - if option_string != nil - if Vips::vips_object_set_from_string(op, option_string) != 0 + unless option_string.nil? + if Vips.vips_object_set_from_string(op, option_string) != 0 raise Vips::Error end end @@ -509,11 +504,11 @@ def self.call name, supplied, optional = {}, option_string = "" result = nil end - GLib::logger.debug("Vips::Operation.call") { "result = #{result}" } + GLib.logger.debug("Vips::Operation.call") { "result = #{result}" } - Vips::vips_object_unref_outputs op + Vips.vips_object_unref_outputs op - return result + result end end end diff --git a/lib/vips/region.rb b/lib/vips/region.rb index 07829c57..92d08a0d 100644 --- a/lib/vips/region.rb +++ b/lib/vips/region.rb @@ -4,12 +4,12 @@ # Author:: John Cupitt (mailto:jcupitt@gmail.com) # License:: MIT -require 'ffi' +require "ffi" module Vips attach_function :vips_region_new, [:pointer], :pointer - if Vips::at_least_libvips?(8, 8) + if Vips.at_least_libvips?(8, 8) attach_function :vips_region_fetch, [:pointer, :int, :int, :int, :int, SizeStruct.ptr], :pointer attach_function :vips_region_width, [:pointer], :int attach_function :vips_region_height, [:pointer], :int @@ -44,24 +44,24 @@ class ManagedStruct < Vips::Object::ManagedStruct end def initialize(name) - ptr = Vips::vips_region_new name + ptr = Vips.vips_region_new name raise Vips::Error if ptr.null? super ptr end def width - Vips::vips_region_width self + Vips.vips_region_width self end def height - Vips::vips_region_height self + Vips.vips_region_height self end # Fetch a region filled with pixel data. def fetch(left, top, width, height) len = Vips::SizeStruct.new - ptr = Vips::vips_region_fetch self, left, top, width, height, len + ptr = Vips.vips_region_fetch self, left, top, width, height, len raise Vips::Error if ptr.null? # wrap up as an autopointer diff --git a/lib/vips/source.rb b/lib/vips/source.rb index 313ea448..a2526977 100644 --- a/lib/vips/source.rb +++ b/lib/vips/source.rb @@ -4,10 +4,10 @@ # Author:: John Cupitt (mailto:jcupitt@gmail.com) # License:: MIT -require 'ffi' +require "ffi" module Vips - if Vips::at_least_libvips?(8, 9) + if Vips.at_least_libvips?(8, 9) attach_function :vips_source_new_from_descriptor, [:int], :pointer attach_function :vips_source_new_from_file, [:pointer], :pointer attach_function :vips_source_new_from_memory, [:pointer, :size_t], :pointer @@ -42,26 +42,26 @@ class ManagedStruct < Vips::Connection::ManagedStruct # # Pass sources to {Image.new_from_source} to load images from # them. - # + # # @param descriptor [Integer] the file descriptor # @return [Source] the new Vips::Source def self.new_from_descriptor(descriptor) - ptr = Vips::vips_source_new_from_descriptor descriptor + ptr = Vips.vips_source_new_from_descriptor descriptor raise Vips::Error if ptr.null? Vips::Source.new ptr end - # Create a new source from a file name. + # Create a new source from a file name. # # Pass sources to {Image.new_from_source} to load images from # them. - # + # # @param filename [String] the name of the file # @return [Source] the new Vips::Source def self.new_from_file(filename) raise Vips::Error, "filename is nil" if filename.nil? - ptr = Vips::vips_source_new_from_file filename + ptr = Vips.vips_source_new_from_file filename raise Vips::Error if ptr.null? Vips::Source.new ptr @@ -72,18 +72,17 @@ def self.new_from_file(filename) # # Pass sources to {Image.new_from_source} to load images from # them. - # - # @param data [String] memory area + # + # @param data [String] memory area # @return [Source] the new Vips::Source def self.new_from_memory(data) - ptr = Vips::vips_source_new_from_memory data, data.bytesize + ptr = Vips.vips_source_new_from_memory data, data.bytesize raise Vips::Error if ptr.null? - # FIXME do we need to keep a ref to the underlying memory area? what + # FIXME do we need to keep a ref to the underlying memory area? what # about Image.new_from_buffer? Does that need a secret ref too? Vips::Source.new ptr end - end end diff --git a/lib/vips/sourcecustom.rb b/lib/vips/sourcecustom.rb index 39eca3ff..48d5a05c 100644 --- a/lib/vips/sourcecustom.rb +++ b/lib/vips/sourcecustom.rb @@ -4,14 +4,14 @@ # Author:: John Cupitt (mailto:jcupitt@gmail.com) # License:: MIT -require 'ffi' +require "ffi" module Vips - if Vips::at_least_libvips?(8, 9) + if Vips.at_least_libvips?(8, 9) attach_function :vips_source_custom_new, [], :pointer end - # A source you can attach action signal handlers to to implement + # A source you can attach action signal handlers to to implement # custom input types. # # For example: @@ -23,7 +23,7 @@ module Vips # image = Vips::Image.new_from_source source # ``` # - # (just an example -- of course in practice you'd use {Source#new_from_file} + # (just an example -- of course in practice you'd use {Source#new_from_file} # to read from a named file) class SourceCustom < Vips::Source module SourceCustomLayout @@ -44,7 +44,7 @@ class ManagedStruct < Vips::Source::ManagedStruct end def initialize - pointer = Vips::vips_source_custom_new + pointer = Vips.vips_source_custom_new raise Vips::Error if pointer.null? super pointer @@ -70,7 +70,7 @@ def on_read &block end # The block is executed to seek the source. The interface is exactly as - # IO::seek, ie. it should take an offset and whence, and return the + # IO::seek, ie. it should take an offset and whence, and return the # new read position. # # This handler is optional -- if you do not attach a seek handler, @@ -85,6 +85,5 @@ def on_seek &block block.call offset, whence end end - end end diff --git a/lib/vips/target.rb b/lib/vips/target.rb index ea3f1b63..050e2c4a 100644 --- a/lib/vips/target.rb +++ b/lib/vips/target.rb @@ -4,10 +4,10 @@ # Author:: John Cupitt (mailto:jcupitt@gmail.com) # License:: MIT -require 'ffi' +require "ffi" module Vips - if Vips::at_least_libvips?(8, 9) + if Vips.at_least_libvips?(8, 9) attach_function :vips_target_new_to_descriptor, [:int], :pointer attach_function :vips_target_new_to_file, [:string], :pointer attach_function :vips_target_new_to_memory, [], :pointer @@ -43,45 +43,44 @@ class ManagedStruct < Vips::Connection::ManagedStruct # # Pass targets to {Image#write_to_target} to write images to # them. - # + # # @param descriptor [Integer] the file descriptor # @return [Target] the new Vips::Target def self.new_to_descriptor(descriptor) - ptr = Vips::vips_target_new_to_descriptor descriptor + ptr = Vips.vips_target_new_to_descriptor descriptor raise Vips::Error if ptr.null? Vips::Target.new ptr end - # Create a new target to a file name. + # Create a new target to a file name. # # Pass targets to {Image#write_to_target} to write images to # them. - # + # # @param filename [String] the name of the file # @return [Target] the new Vips::Target def self.new_to_file(filename) - raise Vips::Error, 'filename is nil' if filename.nil? - ptr = Vips::vips_target_new_to_file filename + raise Vips::Error, "filename is nil" if filename.nil? + ptr = Vips.vips_target_new_to_file filename raise Vips::Error if ptr.null? Vips::Target.new ptr end - # Create a new target to an area of memory. + # Create a new target to an area of memory. # # Pass targets to {Image#write_to_target} to write images to # them. # - # Once the image has been written, use {Object#get}`("blob")` to read out + # Once the image has been written, use {Object#get}`("blob")` to read out # the data. - # + # # @return [Target] the new Vips::Target def self.new_to_memory - ptr = Vips::vips_target_new_to_memory + ptr = Vips.vips_target_new_to_memory Vips::Target.new ptr end - end end diff --git a/lib/vips/targetcustom.rb b/lib/vips/targetcustom.rb index 3235c4e9..9f07db75 100644 --- a/lib/vips/targetcustom.rb +++ b/lib/vips/targetcustom.rb @@ -4,14 +4,14 @@ # Author:: John Cupitt (mailto:jcupitt@gmail.com) # License:: MIT -require 'ffi' +require "ffi" module Vips - if Vips::at_least_libvips?(8, 9) + if Vips.at_least_libvips?(8, 9) attach_function :vips_target_custom_new, [], :pointer end - # A target you can attach action signal handlers to to implememt + # A target you can attach action signal handlers to to implememt # custom output types. # # For example: @@ -23,7 +23,7 @@ module Vips # image.write_to_target target, ".png" # ``` # - # (just an example -- of course in practice you'd use {Target#new_to_file} + # (just an example -- of course in practice you'd use {Target#new_to_file} # to write to a named file) class TargetCustom < Vips::Target module TargetCustomLayout @@ -44,17 +44,17 @@ class ManagedStruct < Vips::Target::ManagedStruct end def initialize - pointer = Vips::vips_target_custom_new + pointer = Vips.vips_target_custom_new raise Vips::Error if pointer.null? super pointer end # The block is executed to write data to the source. The interface is - # exactly as IO::write, ie. it should write the string and return the + # exactly as IO::write, ie. it should write the string and return the # number of bytes written. # - # @yieldparam bytes [String] Write these bytes to the file + # @yieldparam bytes [String] Write these bytes to the file # @yieldreturn [Integer] The number of bytes written, or -1 on error def on_write &block signal_connect "write" do |p, len| @@ -69,10 +69,9 @@ def on_write &block # The block is executed at the end of write. It should do any necessary # finishing action, such as closing a file. def on_finish &block - signal_connect "finish" do - block.call() + signal_connect "finish" do + block.call end end - end end diff --git a/ruby-vips.gemspec b/ruby-vips.gemspec index 6576a454..acb141e6 100644 --- a/ruby-vips.gemspec +++ b/ruby-vips.gemspec @@ -1,15 +1,14 @@ # frozen_string_literal: true -# coding: utf-8 -require_relative 'lib/vips/version' +require_relative "lib/vips/version" Gem::Specification.new do |spec| spec.name = "ruby-vips" spec.version = Vips::VERSION spec.summary = "A fast image processing library with low memory needs" - spec.description = <<-DESC -ruby-vips is a binding for the libvips image processing library. It is fast -and it can process large images without loading the whole image in memory. + spec.description = <<-DESC.strip + ruby-vips is a binding for the libvips image processing library. It is fast + and it can process large images without loading the whole image in memory. DESC spec.homepage = "http://github.com/libvips/ruby-vips" spec.licenses = ["MIT"] @@ -18,26 +17,24 @@ and it can process large images without loading the whole image in memory. spec.metadata = { "bug_tracker_uri" => "https://github.com/libvips/ruby-vips/issues", - "changelog_uri" => + "changelog_uri" => "https://github.com/libvips/ruby-vips/blob/master/CHANGELOG.md", "documentation_uri" => "https://www.rubydoc.info/gems/ruby-vips", "homepage_uri" => spec.homepage, "source_code_uri" => "https://github.com/libvips/ruby-vips", - "msys2_mingw_dependencies" => "libvips", + "msys2_mingw_dependencies" => "libvips" } spec.require_paths = ["lib"] - spec.extra_rdoc_files = [ - "LICENSE.txt", - "README.md", - "TODO" - ] + spec.extra_rdoc_files = %w[LICENSE.txt README.md TODO] spec.files = `git ls-files -z`.split("\x0").reject do |f| f.match(%r{^(test|spec|features)/}) end + spec.required_ruby_version = ">= 2.0.0" + spec.add_runtime_dependency "ffi", ["~> 1.12"] spec.add_development_dependency "rake", ["~> 12.0"] @@ -49,5 +46,4 @@ and it can process large images without loading the whole image in memory. if Gem.ruby_version >= Gem::Version.new("2.2") spec.add_development_dependency "standard" end - end diff --git a/spec/connection_spec.rb b/spec/connection_spec.rb index c2587dc8..c2649e29 100644 --- a/spec/connection_spec.rb +++ b/spec/connection_spec.rb @@ -1,82 +1,81 @@ -require 'spec_helper.rb' +require "spec_helper" RSpec.describe Vips::Source, version: [8, 9] do - it 'can create a source from a descriptor' do + it "can create a source from a descriptor" do source = Vips::Source.new_from_descriptor(0) expect(source) end - it 'can create a source from a filename' do - source = Vips::Source.new_from_file simg('wagon.jpg') + it "can create a source from a filename" do + source = Vips::Source.new_from_file simg("wagon.jpg") expect(source) end - it 'can\'t create a source from a bad filename' do + it "can't create a source from a bad filename" do expect { - Vips::Source.new_from_file simg('banana.jpg') + Vips::Source.new_from_file simg("banana.jpg") }.to raise_exception(Vips::Error) end - it 'can create a source from an area of memory' do - str = File.open(simg('wagon.jpg'), 'rb').read + it "can create a source from an area of memory" do + str = File.open(simg("wagon.jpg"), "rb").read source = Vips::Source.new_from_memory str expect(source) end - it 'sources have filenames and nicks' do - source = Vips::Source.new_from_file simg('wagon.jpg') + it "sources have filenames and nicks" do + source = Vips::Source.new_from_file simg("wagon.jpg") - expect(source.filename).to eq(simg('wagon.jpg')) + expect(source.filename).to eq(simg("wagon.jpg")) expect(source.nick) end - it 'can load an image from filename source' do - source = Vips::Source.new_from_file simg('wagon.jpg') - image = Vips::Image.new_from_source source, '' + it "can load an image from filename source" do + source = Vips::Source.new_from_file simg("wagon.jpg") + image = Vips::Image.new_from_source source, "" expect(image) expect(image.width).to eq(685) expect(image.height).to eq(478) expect(image.bands).to eq(3) expect(image.avg).to be_within(0.001).of(109.789) - end end RSpec.describe Vips::Target, version: [8, 9] do - it 'can create a target to a filename' do - target = Vips::Target.new_to_file timg('x.jpg') + it "can create a target to a filename" do + target = Vips::Target.new_to_file timg("x.jpg") expect(target) end - it 'can create a target to a descriptor' do + it "can create a target to a descriptor" do target = Vips::Target.new_to_descriptor 1 expect(target) end - it 'can create a target to a memory area' do + it "can create a target to a memory area" do target = Vips::Target.new_to_memory expect(target) end - it 'can\'t create a target to a bad filename' do + it "can't create a target to a bad filename" do expect { - Vips::Target.new_to_file '/banana/monkey' + Vips::Target.new_to_file "/banana/monkey" }.to raise_exception(Vips::Error) end - it 'can save an image to a filename target' do - source = Vips::Source.new_from_file simg('wagon.jpg') - image = Vips::Image.new_from_source source, '' - filename = timg('x4.png') + it "can save an image to a filename target" do + source = Vips::Source.new_from_file simg("wagon.jpg") + image = Vips::Image.new_from_source source, "" + filename = timg("x4.png") target = Vips::Target.new_to_file filename - image.write_to_target target, '.png' + image.write_to_target target, ".png" image = Vips::Image.new_from_file filename expect(image) @@ -86,32 +85,31 @@ expect(image.avg).to be_within(0.001).of(109.789) end - it 'can save an image to a memory target' do - source = Vips::Source.new_from_file simg('wagon.jpg') - image = Vips::Image.new_from_source source, '' + it "can save an image to a memory target" do + source = Vips::Source.new_from_file simg("wagon.jpg") + image = Vips::Image.new_from_source source, "" target = Vips::Target.new_to_memory - image.write_to_target target, '.png' - memory = target.get('blob') + image.write_to_target target, ".png" + memory = target.get("blob") - image = Vips::Image.new_from_buffer memory, '' + image = Vips::Image.new_from_buffer memory, "" expect(image) expect(image.width).to eq(685) expect(image.height).to eq(478) expect(image.bands).to eq(3) expect(image.avg).to be_within(0.001).of(109.789) end - end RSpec.describe Vips::SourceCustom, version: [8, 9] do - it 'can create a custom source' do + it "can create a custom source" do source = Vips::SourceCustom.new expect(source) end - it 'can load a custom source' do - file = File.open simg('wagon.jpg'), "rb" + it "can load a custom source" do + file = File.open simg("wagon.jpg"), "rb" source = Vips::SourceCustom.new source.on_read { |length| file.read length } source.on_seek { |offset, whence| file.seek(offset, whence) } @@ -124,8 +122,8 @@ expect(image.avg).to be_within(0.001).of(109.789) end - it 'on_seek is optional' do - file = File.open simg('wagon.jpg'), "rb" + it "on_seek is optional" do + file = File.open simg("wagon.jpg"), "rb" source = Vips::SourceCustom.new source.on_read { |length| file.read length } image = Vips::Image.new_from_source source, "" @@ -137,19 +135,19 @@ expect(image.avg).to be_within(0.001).of(109.789) end - it 'can create a user output stream' do + it "can create a user output stream" do target = Vips::TargetCustom.new expect(target) end - it 'can write an image to a user output stream' do - filename = timg('x5.png') + it "can write an image to a user output stream" do + filename = timg("x5.png") file = File.open filename, "wb" target = Vips::TargetCustom.new target.on_write { |chunk| file.write(chunk) } target.on_finish { file.close } - image = Vips::Image.new_from_file simg('wagon.jpg') + image = Vips::Image.new_from_file simg("wagon.jpg") image.write_to_target target, ".png" image = Vips::Image.new_from_file filename @@ -159,5 +157,4 @@ expect(image.bands).to eq(3) expect(image.avg).to be_within(0.001).of(109.789) end - end diff --git a/spec/image_spec.rb b/spec/image_spec.rb index aa30c29a..60dec10c 100644 --- a/spec/image_spec.rb +++ b/spec/image_spec.rb @@ -1,12 +1,12 @@ -require 'spec_helper.rb' +require "spec_helper" def has_jpeg? - Vips::type_find('VipsOperation', 'jpegload') != nil + Vips.type_find("VipsOperation", "jpegload") != nil end RSpec.describe Vips::Image do - it 'can save an image to a file' do - filename = timg 'x.v' + it "can save an image to a file" do + filename = timg "x.v" image = Vips::Image.black(16, 16) + 128 image.write_to_file filename @@ -14,8 +14,8 @@ def has_jpeg? expect(File.exist?(filename)).to be true end - it 'can load an image from a file' do - filename = timg 'x.v' + it "can load an image from a file" do + filename = timg "x.v" image = Vips::Image.black(16, 16) + 128 image.write_to_file(filename) @@ -27,16 +27,15 @@ def has_jpeg? expect(x.avg).to eq(128) end - it 'can load an image from memory' do + it "can load an image from memory" do image = Vips::Image.black(16, 16) + 128 data = image.write_to_memory - x = Vips::Image.new_from_memory data, + x = Vips::Image.new_from_memory data, image.width, image.height, image.bands, image.format - # GC to try to trigger a segv if data hasn't been reffed by + # GC to try to trigger a segv if data hasn't been reffed by # new_from_memory - data = nil GC.start expect(x.width).to eq(16) @@ -45,11 +44,11 @@ def has_jpeg? expect(x.avg).to eq(128) end - it 'can load an image from memory and copy' do + it "can load an image from memory and copy" do image = Vips::Image.black(16, 16) + 128 data = image.write_to_memory - x = Vips::Image.new_from_memory_copy data, + x = Vips::Image.new_from_memory_copy data, image.width, image.height, image.bands, image.format expect(x.width).to eq(16) @@ -59,24 +58,24 @@ def has_jpeg? end if has_jpeg? - it 'can save an image to a buffer' do + it "can save an image to a buffer" do image = Vips::Image.black(16, 16) + 128 - buffer = image.write_to_buffer '.jpg' + buffer = image.write_to_buffer ".jpg" expect(buffer.length).to be > 100 end end if has_jpeg? - it 'can load an image from a buffer' do + it "can load an image from a buffer" do image = Vips::Image.black(16, 16) + 128 - buffer = image.write_to_buffer '.jpg' - x = Vips::Image.new_from_buffer buffer, '' + buffer = image.write_to_buffer ".jpg" + x = Vips::Image.new_from_buffer buffer, "" expect(x.width).to eq(16) expect(x.height).to eq(16) end end - it 'can make an image from a 2d array' do + it "can make an image from a 2d array" do image = Vips::Image.new_from_array [[1, 2], [3, 4]] expect(image.width).to eq(2) expect(image.height).to eq(2) @@ -84,7 +83,7 @@ def has_jpeg? expect(image.avg).to eq(2.5) end - it 'can make an image from a 1d array' do + it "can make an image from a 1d array" do image = Vips::Image.new_from_array [1, 2] expect(image.width).to eq(2) expect(image.height).to eq(1) @@ -92,7 +91,7 @@ def has_jpeg? expect(image.avg).to eq(1.5) end - it 'can use array consts for image args' do + it "can use array consts for image args" do r = Vips::Image.black(16, 16) r = r.draw_rect 255, 10, 12, 1, 1 g = Vips::Image.black(16, 16) @@ -109,14 +108,14 @@ def has_jpeg? [0.11, 0.11, 0.11], [0.11, 0.11, 0.11], [0.11, 0.11, 0.11] - ], :precision => :float + ], precision: :float expect(im.width).to eq(16) expect(im.height).to eq(16) expect(im.bands).to eq(3) end - it 'can set scale and offset on a convolution mask', version: [8, 10] do + it "can set scale and offset on a convolution mask", version: [8, 10] do image = Vips::Image.new_from_array [1, 2], 8, 2 expect(image.width).to eq(2) expect(image.height).to eq(1) @@ -126,7 +125,7 @@ def has_jpeg? expect(image.avg).to eq(1.5) end - it 'supports imagescale' do + it "supports imagescale" do image = Vips::Image.new_from_array [1, 2], 8, 2 image = image.scaleimage expect(image.width).to eq(2) @@ -136,8 +135,8 @@ def has_jpeg? end if has_jpeg? - it 'can load a sample jpg image file' do - x = Vips::Image.new_from_file simg('wagon.jpg') + it "can load a sample jpg image file" do + x = Vips::Image.new_from_file simg("wagon.jpg") expect(x.width).to eq(685) expect(x.height).to eq(478) expect(x.bands).to eq(3) @@ -146,9 +145,9 @@ def has_jpeg? end if has_jpeg? - it 'can load a sample jpg image buffer' do - str = File.open(simg('wagon.jpg'), 'rb').read - x = Vips::Image.new_from_buffer str, '' + it "can load a sample jpg image buffer" do + str = File.open(simg("wagon.jpg"), "rb").read + x = Vips::Image.new_from_buffer str, "" expect(x.width).to eq(685) expect(x.height).to eq(478) expect(x.bands).to eq(3) @@ -157,9 +156,9 @@ def has_jpeg? end if has_jpeg? - it 'can load a sample jpg image utf-8 buffer' do - str = File.open(simg('wagon.jpg'), 'r').read - x = Vips::Image.new_from_buffer str, '' + it "can load a sample jpg image utf-8 buffer" do + str = File.open(simg("wagon.jpg"), "r").read + x = Vips::Image.new_from_buffer str, "" expect(x.width).to eq(685) expect(x.height).to eq(478) expect(x.bands).to eq(3) @@ -168,42 +167,42 @@ def has_jpeg? end if has_jpeg? - it 'can extract an ICC profile from a jpg image' do - x = Vips::Image.new_from_file simg('icc.jpg') + it "can extract an ICC profile from a jpg image" do + x = Vips::Image.new_from_file simg("icc.jpg") expect(x.width).to eq(2800) expect(x.height).to eq(2100) expect(x.bands).to eq(3) expect(x.avg).to be_within(0.001).of(109.189) - profile = x.get_value 'icc-profile-data' + profile = x.get_value "icc-profile-data" expect(profile.class).to eq(String) expect(profile.length).to eq(2360) end end if has_jpeg? - it 'can set an ICC profile on a jpg image' do - x = Vips::Image.new_from_file simg('icc.jpg') - profile = File.open(simg('lcd.icc'), 'rb').read + it "can set an ICC profile on a jpg image" do + x = Vips::Image.new_from_file simg("icc.jpg") + profile = File.open(simg("lcd.icc"), "rb").read x = x.copy - x.set_value 'icc-profile-data', profile - x.write_to_file(timg('x.jpg')) + x.set_value "icc-profile-data", profile + x.write_to_file(timg("x.jpg")) - x = Vips::Image.new_from_file timg('x.jpg') + x = Vips::Image.new_from_file timg("x.jpg") expect(x.width).to eq(2800) expect(x.height).to eq(2100) expect(x.bands).to eq(3) expect(x.avg).to be_within(0.1).of(109.189) - profile = x.get_value 'icc-profile-data' + profile = x.get_value "icc-profile-data" expect(profile.class).to eq(String) expect(profile.length).to eq(3048) end end if has_jpeg? - it 'can load a sample jpg image' do - x = Vips::Image.new_from_file simg('wagon.jpg') + it "can load a sample jpg image" do + x = Vips::Image.new_from_file simg("wagon.jpg") expect(x.width).to eq(685) expect(x.height).to eq(478) expect(x.bands).to eq(3) @@ -211,7 +210,7 @@ def has_jpeg? end end - it 'has binary arithmetic operator overloads with constants' do + it "has binary arithmetic operator overloads with constants" do image = Vips::Image.black(16, 16) + 128 image += 128 @@ -231,8 +230,8 @@ def has_jpeg? expect(image.avg).to eq(128) end - it 'has binary arithmetic operator overloads with array constants' do - image = Vips::Image.black(16, 16, :bands => 3) + 128 + it "has binary arithmetic operator overloads with array constants" do + image = Vips::Image.black(16, 16, bands: 3) + 128 image += [128, 0, 0] image -= [128, 0, 0] @@ -251,7 +250,7 @@ def has_jpeg? expect(image.avg).to eq(128) end - it 'has binary arithmetic operator overloads with image args' do + it "has binary arithmetic operator overloads with image args" do image = Vips::Image.black(16, 16) + 128 x = image @@ -268,7 +267,7 @@ def has_jpeg? expect(x.avg).to eq(0) end - it 'has relational operator overloads with constants' do + it "has relational operator overloads with constants" do image = Vips::Image.black(16, 16) + 128 expect((image > 128).avg).to eq(0) @@ -279,8 +278,8 @@ def has_jpeg? expect((image != 128).avg).to eq(0) end - it 'has relational operator overloads with array constants' do - image = Vips::Image.black(16, 16, :bands => 3) + [100, 128, 130] + it "has relational operator overloads with array constants" do + image = Vips::Image.black(16, 16, bands: 3) + [100, 128, 130] expect((image > [100, 128, 130]).avg).to eq(0) expect((image >= [100, 128, 130]).avg).to eq(255) @@ -290,7 +289,7 @@ def has_jpeg? expect((image != [100, 128, 130]).avg).to eq(0) end - it 'has relational operator overloads with image args' do + it "has relational operator overloads with image args" do image = Vips::Image.black(16, 16) + 128 expect((image > image).avg).to eq(0) @@ -301,8 +300,8 @@ def has_jpeg? expect((image != image).avg).to eq(0) end - it 'has band extract with numeric arg' do - image = Vips::Image.black(16, 16, :bands => 3) + [100, 128, 130] + it "has band extract with numeric arg" do + image = Vips::Image.black(16, 16, bands: 3) + [100, 128, 130] x = image[1] expect(x.width).to eq(16) @@ -311,8 +310,8 @@ def has_jpeg? expect(x.avg).to eq(128) end - it 'has band extract with range arg' do - image = Vips::Image.black(16, 16, :bands => 3) + [100, 128, 130] + it "has band extract with range arg" do + image = Vips::Image.black(16, 16, bands: 3) + [100, 128, 130] x = image[1..2] expect(x.width).to eq(16) @@ -321,7 +320,7 @@ def has_jpeg? expect(x.avg).to eq(129) end - it 'has rounding members' do + it "has rounding members" do # need to avoid rounding down to 0.499999 image = Vips::Image.black(16, 16) + 0.500001 @@ -330,8 +329,8 @@ def has_jpeg? expect(image.rint.avg).to eq(1) end - it 'has bandsplit and bandjoin' do - image = Vips::Image.black(16, 16, :bands => 3) + [100, 128, 130] + it "has bandsplit and bandjoin" do + image = Vips::Image.black(16, 16, bands: 3) + [100, 128, 130] split = image.bandsplit x = split[0].bandjoin split[1..2] @@ -341,8 +340,8 @@ def has_jpeg? expect(x[2].avg).to eq(130) end - it 'can bandjoin constants' do - image = Vips::Image.black(16, 16, :bands => 3) + [100, 128, 130] + it "can bandjoin constants" do + image = Vips::Image.black(16, 16, bands: 3) + [100, 128, 130] x = image.bandjoin 255 @@ -362,8 +361,8 @@ def has_jpeg? expect(x.bands).to eq(5) end - it 'can composite', version: [8, 6] do - image = Vips::Image.black(16, 16, :bands => 3) + [100, 128, 130] + it "can composite", version: [8, 6] do + image = Vips::Image.black(16, 16, bands: 3) + [100, 128, 130] image = image.copy interpretation: :srgb base = image + 10 overlay = image.bandjoin 128 @@ -376,7 +375,7 @@ def has_jpeg? expect(pixel[3]).to eq(255) end - it 'has minpos/maxpos' do + it "has minpos/maxpos" do image = Vips::Image.black(16, 16) + 128 image = image.draw_rect 255, 10, 12, 1, 1 v, x, y = image.maxpos @@ -394,7 +393,7 @@ def has_jpeg? expect(y).to eq(12) end - it 'can form complex images' do + it "can form complex images" do r = Vips::Image.black(16, 16) + 128 i = Vips::Image.black(16, 16) + 12 cmplx = r.complexform i @@ -405,7 +404,7 @@ def has_jpeg? expect(im.avg).to eq(12) end - it 'can convert complex polar <-> rectangular' do + it "can convert complex polar <-> rectangular" do r = Vips::Image.black(16, 16) + 128 i = Vips::Image.black(16, 16) + 12 cmplx = r.complexform i @@ -416,7 +415,7 @@ def has_jpeg? expect(cmplx.imag.avg).to be_within(0.001).of(12) end - it 'can take complex conjugate' do + it "can take complex conjugate" do r = Vips::Image.black(16, 16) + 128 i = Vips::Image.black(16, 16) + 12 cmplx = r.complexform i @@ -427,7 +426,7 @@ def has_jpeg? expect(cmplx.imag.avg).to be_within(0.001).of(-12) end - it 'has working trig functions' do + it "has working trig functions" do image = Vips::Image.black(16, 16) + 67 image = image.sin.cos.tan @@ -436,7 +435,7 @@ def has_jpeg? expect(image.avg).to be_within(0.01).of(67) end - it 'has working log functions' do + it "has working log functions" do image = Vips::Image.black(16, 16) + 67 image = image.log.exp.log10.exp10 @@ -444,7 +443,7 @@ def has_jpeg? expect(image.avg).to be_within(0.01).of(67) end - it 'can flip' do + it "can flip" do a = Vips::Image.black(16, 16) a = a.draw_rect 255, 10, 12, 1, 1 b = Vips::Image.black(16, 16) @@ -460,7 +459,7 @@ def has_jpeg? expect((a - b.flipver).abs.max).to eq(0.0) end - it 'can getpoint' do + it "can getpoint" do a = Vips::Image.black(16, 16) a = a.draw_rect 255, 10, 12, 1, 1 b = Vips::Image.black(16, 16) @@ -471,7 +470,7 @@ def has_jpeg? expect(im.getpoint(10, 10)).to eq([0, 255]) end - it 'can median' do + it "can median" do a = Vips::Image.black(16, 16) a = a.draw_rect 255, 10, 12, 1, 1 im = a.median @@ -479,7 +478,7 @@ def has_jpeg? expect(im.max).to eq(0) end - it 'can erode' do + it "can erode" do a = Vips::Image.black(16, 16) a = a.draw_rect 255, 10, 12, 1, 1 mask = Vips::Image.new_from_array [ @@ -492,7 +491,7 @@ def has_jpeg? expect(im.max).to eq(0) end - it 'can dilate' do + it "can dilate" do a = Vips::Image.black(16, 16) a = a.draw_rect 255, 10, 12, 1, 1 mask = Vips::Image.new_from_array [ @@ -507,7 +506,7 @@ def has_jpeg? expect(im.getpoint(12, 12)).to eq([0]) end - it 'can rot' do + it "can rot" do a = Vips::Image.black(16, 16) a = a.draw_rect 255, 10, 12, 1, 1 @@ -521,7 +520,7 @@ def has_jpeg? expect((a - im).abs.max).to eq(0.0) end - it 'can bandbool' do + it "can bandbool" do a = Vips::Image.black(16, 16) a = a.draw_rect 255, 10, 12, 1, 1 b = Vips::Image.black(16, 16) @@ -533,7 +532,7 @@ def has_jpeg? expect(im.bandeor.getpoint(10, 12)).to eq([255]) end - it 'ifthenelse with image arguments' do + it "ifthenelse with image arguments" do image = Vips::Image.black(16, 16) image = image.draw_rect 255, 10, 12, 1, 1 black = Vips::Image.black(16, 16) @@ -548,7 +547,7 @@ def has_jpeg? expect(y).to eq(12) end - it 'ifthenelse with constant arguments' do + it "ifthenelse with constant arguments" do image = Vips::Image.black(16, 16) image = image.draw_rect 255, 10, 12, 1, 1 @@ -561,7 +560,7 @@ def has_jpeg? expect(y).to eq(12) end - it 'ifthenelse with vector arguments' do + it "ifthenelse with vector arguments" do image = Vips::Image.black(16, 16) image = image.draw_rect 255, 10, 12, 1, 1 white = Vips::Image.black(16, 16) + 255 @@ -575,12 +574,12 @@ def has_jpeg? expect(y).to eq(12) end - it 'has a #size method' do + it "has a #size method" do image = Vips::Image.black(200, 100) expect(image.size).to eq([image.width, image.height]) end - it 'has #new_from_image method' do + it "has #new_from_image method" do image = Vips::Image.black(200, 100) image2 = image.new_from_image 12 @@ -592,22 +591,22 @@ def has_jpeg? expect(image2.avg).to eq(2) end - it 'can make interpolate objects' do - inter = Vips::Interpolate.new 'bilinear' + it "can make interpolate objects" do + inter = Vips::Interpolate.new "bilinear" expect(inter).not_to eq(nil) end - it 'can call affine with a non-default interpolator' do + it "can call affine with a non-default interpolator" do image = Vips::Image.black(200, 100) - inter = Vips::Interpolate.new 'bilinear' - result = image.affine [2, 0, 0, 2], :interpolate => inter + inter = Vips::Interpolate.new "bilinear" + result = image.affine [2, 0, 0, 2], interpolate: inter expect(result.width).to eq(400) expect(result.height).to eq(200) end - it 'has a working #to_a' do + it "has a working #to_a" do image = Vips::Image.black(200, 100) array = image.to_a @@ -617,7 +616,7 @@ def has_jpeg? expect(array[0][0][0]).to eq(0) end - it 'supports keyword arguments' do + it "supports keyword arguments" do image = Vips::Image.black 200, 200, bands: 12 expect(image.width).to eq(200) @@ -626,39 +625,39 @@ def has_jpeg? end if has_jpeg? - it 'works with arguments containing -' do + it "works with arguments containing -" do image = Vips::Image.black(16, 16) + 128 - buffer = image.write_to_buffer '.jpg', optimize_coding: true + buffer = image.write_to_buffer ".jpg", optimize_coding: true expect(buffer.length).to be > 100 end end if has_jpeg? - it 'can read exif tags' do - x = Vips::Image.new_from_file simg 'huge.jpg' - orientation = x.get 'exif-ifd0-Orientation' + it "can read exif tags" do + x = Vips::Image.new_from_file simg "huge.jpg" + orientation = x.get "exif-ifd0-Orientation" expect(orientation.length).to be > 20 - expect(orientation.split[0]).to eq('1') + expect(orientation.split[0]).to eq("1") end end # added in 8.5 if Vips.respond_to? :vips_image_get_fields - it 'can read field names' do + it "can read field names" do x = Vips::Image.black 100, 100 y = x.get_fields expect(y.length).to be > 10 - expect(y[0]).to eq('width') + expect(y[0]).to eq("width") end end - it 'can has_alpha?' do - x = Vips::Image.new_from_file './spec/samples/alpha.png' + it "can has_alpha?" do + x = Vips::Image.new_from_file "./spec/samples/alpha.png" expect(x.has_alpha?).to be true end - it 'can add_alpha', version: [8, 6] do - x = Vips::Image.new_from_file './spec/samples/no_alpha.png' + it "can add_alpha", version: [8, 6] do + x = Vips::Image.new_from_file "./spec/samples/no_alpha.png" expect(x.has_alpha?).to be false y = x.add_alpha expect(y.has_alpha?).to be true diff --git a/spec/mutate_spec.rb b/spec/mutate_spec.rb index 9793757d..c0622ded 100644 --- a/spec/mutate_spec.rb +++ b/spec/mutate_spec.rb @@ -1,63 +1,62 @@ -require 'spec_helper.rb' +require "spec_helper" RSpec.describe Vips::MutableImage do - it 'can set! metadata in mutate', version: [8, 10] do + it "can set! metadata in mutate", version: [8, 10] do image = Vips::Image.black(16, 16) - image = image.mutate do |x| + image = image.mutate { |x| x.set_type! GObject::GINT_TYPE, "banana", 12 - end + } - expect(image.get "banana").to eq(12) + expect(image.get("banana")).to eq(12) end - it 'can remove! metadata in mutate' do + it "can remove! metadata in mutate" do image = Vips::Image.black(16, 16) - image = image.mutate do |x| + image = image.mutate { |x| x.set_type! GObject::GINT_TYPE, "banana", 12 - end + } - image = image.mutate do |x| + image = image.mutate { |x| x.remove! "banana" - end + } - expect(image.get_typeof "banana").to eq(0) + expect(image.get_typeof("banana")).to eq(0) end - it 'can call destructive operations in mutate' do + it "can call destructive operations in mutate" do image = Vips::Image.black(16, 16) - image = image.mutate do |x| + image = image.mutate { |x| x.draw_line! 255, 0, 0, x.width, x.height - end + } expect(image.avg).to be > 0 end - it 'cannot call non-destructive operations in mutate' do + it "cannot call non-destructive operations in mutate" do image = Vips::Image.black(16, 16) expect { - image = image.mutate do |x| + image = image.mutate { |x| x.invert - end + } }.to raise_exception(Vips::Error) end - it 'cannot use mutable images as arguments in mutate' do + it "cannot use mutable images as arguments in mutate" do image = Vips::Image.black(16, 16) expect { - image = image.mutate do |x| + image = image.mutate { |x| x.draw_image! x, 10, 10 - end + } }.to raise_exception(Vips::Error) end - it 'cannot call destructive operations outside mutate' do + it "cannot call destructive operations outside mutate" do image = Vips::Image.black(16, 16) expect { image.draw_line! 255, 0, 0, image.width, image.height }.to raise_exception(Vips::Error) end - end diff --git a/spec/region_spec.rb b/spec/region_spec.rb index b8fa85f6..cc14ee9f 100644 --- a/spec/region_spec.rb +++ b/spec/region_spec.rb @@ -1,14 +1,14 @@ -require 'spec_helper.rb' +require "spec_helper" RSpec.describe Vips::Region do - it 'can create a region on an image' do + it "can create a region on an image" do image = Vips::Image.black(100, 100) region = Vips::Region.new image expect(region) end - it 'can fetch pixels from a region', version: [8, 8] do + it "can fetch pixels from a region", version: [8, 8] do image = Vips::Image.black(100, 100) region = Vips::Region.new image pixel_data = region.fetch 10, 20, 30, 40 @@ -17,7 +17,7 @@ expect(pixel_data.length == 30 * 40) end - it 'can make regions with width and height', version: [8, 8] do + it "can make regions with width and height", version: [8, 8] do image = Vips::Image.black(100, 100) region = Vips::Region.new image pixel_data = region.fetch 10, 20, 30, 40 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d4300302..7bcbcb38 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,9 +1,9 @@ -require 'vips' +require "vips" -require 'tempfile' -require 'pathname' +require "tempfile" +require "pathname" -Vips.set_debug ENV['DEBUG'] +Vips.set_debug ENV["DEBUG"] # Vips.leak_set true module Spec @@ -13,11 +13,11 @@ def set_root(path) end def sample(*path) - root.join 'samples', *path + root.join "samples", *path end def tmp(*path) - root.join 'tmp', 'working', *path + root.join "tmp", "working", *path end extend self @@ -25,17 +25,17 @@ def tmp(*path) private def root - @root ||= set_root(File.expand_path('..', __FILE__)) + @root ||= set_root(File.expand_path("..", __FILE__)) end end end def simg(name) - Spec::Path::sample(name).to_s + Spec::Path.sample(name).to_s end def timg(name) - Spec::Path::tmp(name).to_s + Spec::Path.tmp(name).to_s end RSpec.configure do |config| @@ -51,13 +51,13 @@ def timg(name) end config.before(:example, jpeg: true) do - skip 'required jpegload for this spec' unless has_jpeg? + skip "required jpegload for this spec" unless has_jpeg? end - config.before(:example,:version) do |example| + config.before(:example, :version) do |example| required_version = example.metadata[:version] - unless Vips::at_least_libvips?(*required_version) - skip "required at least #{required_version.join('.')} version of the libvips" + unless Vips.at_least_libvips?(*required_version) + skip "required at least #{required_version.join(".")} version of the libvips" end end end diff --git a/spec/vips_spec.rb b/spec/vips_spec.rb index eb633886..6f28cde1 100644 --- a/spec/vips_spec.rb +++ b/spec/vips_spec.rb @@ -1,43 +1,43 @@ -require 'spec_helper.rb' +require "spec_helper" RSpec.describe Vips do - describe 'Vips' do - it 'can set concurrency' do - Vips::concurrency_set 12 + describe "Vips" do + it "can set concurrency" do + Vips.concurrency_set 12 end - it 'can set SIMD' do - Vips::vector_set true + it "can set SIMD" do + Vips.vector_set true end - it 'can enable leak testing' do - Vips::leak_set true - Vips::leak_set false + it "can enable leak testing" do + Vips.leak_set true + Vips.leak_set false end - it 'can set the operation cache size' do - Vips::cache_set_max 0 - Vips::cache_set_max 100 + it "can set the operation cache size" do + Vips.cache_set_max 0 + Vips.cache_set_max 100 end - it 'can set the operation cache memory limit' do - Vips::cache_set_max_mem 0 - Vips::cache_set_max_mem 10000000 + it "can set the operation cache memory limit" do + Vips.cache_set_max_mem 0 + Vips.cache_set_max_mem 10000000 end - it 'can set the operation cache file limit' do - Vips::cache_set_max_files 0 - Vips::cache_set_max_files 100 + it "can set the operation cache file limit" do + Vips.cache_set_max_files 0 + Vips.cache_set_max_files 100 end - it 'can get a set of filename suffixes' do - suffs = Vips::get_suffixes + it "can get a set of filename suffixes" do + suffs = Vips.get_suffixes expect(suffs.length > 10).to be true unless suffs.empty? end end - describe '#call' do - it 'can make a black image' do + describe "#call" do + it "can make a black image" do image = Vips::Operation.call "black", [200, 200] expect(image.width).to eq(200) @@ -45,7 +45,7 @@ expect(image.bands).to eq(1) end - it 'can take an optional argument' do + it "can take an optional argument" do image = Vips::Operation.call "black", [200, 200], bands: 12 expect(image.width).to eq(200) @@ -53,7 +53,7 @@ expect(image.bands).to eq(12) end - it 'ignores optional arguments with nil values' do + it "ignores optional arguments with nil values" do image = Vips::Operation.call "black", [200, 200], bands: nil expect(image.width).to eq(200) @@ -61,7 +61,7 @@ expect(image.bands).to eq(1) end - it 'can handle enum arguments' do + it "can handle enum arguments" do black = Vips::Operation.call "black", [200, 200] embed = Vips::Operation.call "embed", [black, 10, 10, 500, 500], extend: :mirror @@ -71,7 +71,7 @@ expect(embed.bands).to eq(1) end - it 'can handle enum arguments with underscores' do + it "can handle enum arguments with underscores" do black = Vips::Image.black 200, 100, bands: 3 mono = black.colourspace :b_w @@ -80,7 +80,7 @@ expect(mono.bands).to eq(1) end - it 'enum arguments can be strings' do + it "enum arguments can be strings" do black = Vips::Operation.call "black", [200, 200] embed = Vips::Operation.call "embed", [black, 10, 10, 500, 500], extend: "mirror" @@ -90,7 +90,7 @@ expect(embed.bands).to eq(1) end - it 'enum arguments can be ints' do + it "enum arguments can be ints" do black = Vips::Image.black 200, 100 # not angle 0, enum 0 (VIPS_ANGLE_D0) rot = black.rot 0 @@ -100,18 +100,18 @@ expect(rot.bands).to eq(1) end - it 'can return optional output args' do + it "can return optional output args" do point = Vips::Operation.call "black", [1, 1] test = Vips::Operation.call "embed", [point, 20, 10, 100, 100], extend: :white value, opts = Vips::Operation.call "min", [test], x: true, y: true expect(value).to eq(0) - expect(opts['x']).to eq(20) - expect(opts['y']).to eq(10) + expect(opts["x"]).to eq(20) + expect(opts["y"]).to eq(10) end - it 'can call draw operations' do + it "can call draw operations" do black = Vips::Operation.call "black", [100, 100] test = Vips::Operation.call "draw_rect", [black, 255, 10, 10, 1, 1] @@ -122,11 +122,10 @@ expect(max_test).to eq(255) end - it 'can throw errors for failed operations' do + it "can throw errors for failed operations" do black = Vips::Operation.call "black", [100, 1] expect { black.crop(10, 10, 1, 1) }.to raise_exception(Vips::Error) end - end end