File: interpolate.rb

package info (click to toggle)
ruby-vips 2.1.4-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 5,164 kB
  • sloc: ruby: 3,530; makefile: 3
file content (58 lines) | stat: -rw-r--r-- 1,473 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
module Vips
  attach_function :vips_interpolate_new, [:string], :pointer

  # An interpolator. One of these can be given to operations like
  # {Image#affine} or {Image#mapim} to select the type of pixel interpolation
  # to use.
  #
  # To see all interpolators supported by your
  # libvips, try
  #
  # ```
  # $ vips -l interpolate
  # ```
  #
  # But at least these should be available:
  #
  # *   `:nearest` Nearest-neighbour interpolation.
  # *   `:bilinear` Bilinear interpolation.
  # *   `:bicubic` Bicubic interpolation.
  # *   `:lbb` Reduced halo bicubic interpolation.
  # *   `:nohalo` Edge sharpening resampler with halo reduction.
  # *   `:vsqbs` B-Splines with antialiasing smoothing.
  #
  #  For example:
  #
  #  ```ruby
  #  im = im.affine [2, 0, 0, 2],
  #      :interpolate => Vips::Interpolate.new(:bicubic)
  #  ```

  class Interpolate < Vips::Object
    # the layout of the VipsInterpolate struct
    module InterpolateLayout
      def self.included base
        base.class_eval do
          layout :parent, Vips::Object::Struct
          # rest opaque
        end
      end
    end

    class Struct < Vips::Object::Struct
      include InterpolateLayout
    end

    class ManagedStruct < Vips::Object::ManagedStruct
      include InterpolateLayout
    end

    def initialize name
      name = name.to_s if name.is_a? Symbol
      ptr = Vips.vips_interpolate_new name
      raise Vips::Error if ptr.nil?

      super ptr
    end
  end
end