ruby-vips 2.0.13 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE/bug_report.md +42 -0
- data/.github/workflows/test.yml +80 -0
- data/.standard.yml +17 -0
- data/.yardopts +0 -1
- data/CHANGELOG.md +44 -0
- data/Gemfile +3 -1
- data/README.md +45 -47
- data/Rakefile +13 -15
- data/TODO +19 -10
- data/VERSION +1 -1
- data/example/annotate.rb +7 -7
- data/example/connection.rb +26 -0
- data/example/daltonize8.rb +27 -29
- data/example/draw_lines.rb +30 -0
- data/example/example1.rb +5 -6
- data/example/example2.rb +11 -11
- data/example/example3.rb +9 -9
- data/example/example4.rb +8 -8
- data/example/example5.rb +8 -9
- data/example/inheritance_with_refcount.rb +203 -221
- data/example/progress.rb +30 -0
- data/example/thumb.rb +12 -14
- data/example/trim8.rb +7 -7
- data/example/watermark.rb +15 -36
- data/example/wobble.rb +25 -25
- data/lib/ruby-vips.rb +1 -1
- data/lib/vips.rb +473 -338
- data/lib/vips/access.rb +9 -9
- data/lib/vips/align.rb +7 -8
- data/lib/vips/angle.rb +8 -9
- data/lib/vips/angle45.rb +12 -13
- data/lib/vips/bandformat.rb +16 -18
- data/lib/vips/blend_mode.rb +36 -0
- data/lib/vips/coding.rb +11 -12
- data/lib/vips/compass_direction.rb +13 -14
- data/lib/vips/connection.rb +46 -0
- data/lib/vips/direction.rb +7 -8
- data/lib/vips/extend.rb +13 -14
- data/lib/vips/gobject.rb +111 -100
- data/lib/vips/gvalue.rb +243 -237
- data/lib/vips/image.rb +1501 -1338
- data/lib/vips/interesting.rb +10 -11
- data/lib/vips/interpolate.rb +50 -54
- data/lib/vips/interpretation.rb +25 -26
- data/lib/vips/kernel.rb +18 -19
- data/lib/vips/methods.rb +929 -309
- data/lib/vips/mutableimage.rb +154 -0
- data/lib/vips/object.rb +318 -208
- data/lib/vips/operation.rb +467 -320
- data/lib/vips/operationboolean.rb +10 -11
- data/lib/vips/operationcomplex.rb +8 -9
- data/lib/vips/operationcomplex2.rb +6 -7
- data/lib/vips/operationcomplexget.rb +7 -8
- data/lib/vips/operationmath.rb +14 -15
- data/lib/vips/operationmath2.rb +6 -7
- data/lib/vips/operationrelational.rb +11 -12
- data/lib/vips/operationround.rb +7 -8
- data/lib/vips/region.rb +73 -0
- data/lib/vips/size.rb +9 -10
- data/lib/vips/source.rb +88 -0
- data/lib/vips/sourcecustom.rb +89 -0
- data/lib/vips/target.rb +86 -0
- data/lib/vips/targetcustom.rb +77 -0
- data/lib/vips/version.rb +1 -2
- data/ruby-vips.gemspec +29 -20
- metadata +51 -40
- data/.travis.yml +0 -55
- data/install-vips.sh +0 -26
@@ -1,14 +1,13 @@
|
|
1
1
|
module Vips
|
2
|
+
# The type of boolean operation to perform on an image. See
|
3
|
+
# {Image#boolean}.
|
4
|
+
#
|
5
|
+
# * ':and' bitwise and
|
6
|
+
# * ':or' bitwise or
|
7
|
+
# * ':eor' bitwise eor
|
8
|
+
# * ':lshift' shift left n bits
|
9
|
+
# * ':rshift' shift right n bits
|
2
10
|
|
3
|
-
|
4
|
-
|
5
|
-
#
|
6
|
-
# * ':and' bitwise and
|
7
|
-
# * ':or' bitwise or
|
8
|
-
# * ':eor' bitwise eor
|
9
|
-
# * ':lshift' shift left n bits
|
10
|
-
# * ':rshift' shift right n bits
|
11
|
-
|
12
|
-
class OperationBoolean < Symbol
|
13
|
-
end
|
11
|
+
class OperationBoolean < Symbol
|
12
|
+
end
|
14
13
|
end
|
@@ -1,12 +1,11 @@
|
|
1
1
|
module Vips
|
2
|
+
# The type of complex operation to perform on an image. See
|
3
|
+
# {Image#complex}.
|
4
|
+
#
|
5
|
+
# * ':polar' to polar coordinates
|
6
|
+
# * ':rect' to rectangular coordinates
|
7
|
+
# * ':conj' complex conjugate
|
2
8
|
|
3
|
-
|
4
|
-
|
5
|
-
#
|
6
|
-
# * ':polar' to polar coordinates
|
7
|
-
# * ':rect' to rectangular coordinates
|
8
|
-
# * ':conj' complex conjugate
|
9
|
-
|
10
|
-
class OperationComplex < Symbol
|
11
|
-
end
|
9
|
+
class OperationComplex < Symbol
|
10
|
+
end
|
12
11
|
end
|
@@ -1,10 +1,9 @@
|
|
1
1
|
module Vips
|
2
|
+
# The type of binary complex operation to perform on an image. See
|
3
|
+
# {Image#complex2}.
|
4
|
+
#
|
5
|
+
# * ':cross_phase' cross phase
|
2
6
|
|
3
|
-
|
4
|
-
|
5
|
-
#
|
6
|
-
# * ':cross_phase' cross phase
|
7
|
-
|
8
|
-
class OperationComplex2 < Symbol
|
9
|
-
end
|
7
|
+
class OperationComplex2 < Symbol
|
8
|
+
end
|
10
9
|
end
|
@@ -1,11 +1,10 @@
|
|
1
1
|
module Vips
|
2
|
+
# The type of complex projection operation to perform on an image. See
|
3
|
+
# {Image#complexget}.
|
4
|
+
#
|
5
|
+
# * ':real' get real part
|
6
|
+
# * ':imag' get imaginary part
|
2
7
|
|
3
|
-
|
4
|
-
|
5
|
-
#
|
6
|
-
# * ':real' get real part
|
7
|
-
# * ':imag' get imaginary part
|
8
|
-
|
9
|
-
class OperationComplexget < Symbol
|
10
|
-
end
|
8
|
+
class OperationComplexget < Symbol
|
9
|
+
end
|
11
10
|
end
|
data/lib/vips/operationmath.rb
CHANGED
@@ -1,18 +1,17 @@
|
|
1
1
|
module Vips
|
2
|
+
# The math operation to perform on an image. See {Image#math}.
|
3
|
+
#
|
4
|
+
# * ':sin' sin(), angles in degrees
|
5
|
+
# * ':cos' cos(), angles in degrees
|
6
|
+
# * ':tan' tan(), angles in degrees
|
7
|
+
# * ':asin' asin(), angles in degrees
|
8
|
+
# * ':acos' acos(), angles in degrees
|
9
|
+
# * ':atan' atan(), angles in degrees
|
10
|
+
# * ':log' log base e
|
11
|
+
# * ':log10' log base 10
|
12
|
+
# * ':exp' e to the something
|
13
|
+
# * ':exp10' 10 to the something
|
2
14
|
|
3
|
-
|
4
|
-
|
5
|
-
# * ':sin' sin(), angles in degrees
|
6
|
-
# * ':cos' cos(), angles in degrees
|
7
|
-
# * ':tan' tan(), angles in degrees
|
8
|
-
# * ':asin' asin(), angles in degrees
|
9
|
-
# * ':acos' acos(), angles in degrees
|
10
|
-
# * ':atan' atan(), angles in degrees
|
11
|
-
# * ':log' log base e
|
12
|
-
# * ':log10' log base 10
|
13
|
-
# * ':exp' e to the something
|
14
|
-
# * ':exp10' 10 to the something
|
15
|
-
|
16
|
-
class OperationMath < Symbol
|
17
|
-
end
|
15
|
+
class OperationMath < Symbol
|
16
|
+
end
|
18
17
|
end
|
data/lib/vips/operationmath2.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
module Vips
|
2
|
+
# The binary math operation to perform on an image. See {Image#math2}.
|
3
|
+
#
|
4
|
+
# * ':pow' pow()
|
5
|
+
# * ':wop' pow(), but with the arguments reversed
|
2
6
|
|
3
|
-
|
4
|
-
|
5
|
-
# * ':pow' pow()
|
6
|
-
# * ':wop' pow(), but with the arguments reversed
|
7
|
-
|
8
|
-
class OperationMath2 < Symbol
|
9
|
-
end
|
7
|
+
class OperationMath2 < Symbol
|
8
|
+
end
|
10
9
|
end
|
@@ -1,15 +1,14 @@
|
|
1
1
|
module Vips
|
2
|
+
# The type of relational operation to perform on an image. See
|
3
|
+
# {Image#relational}.
|
4
|
+
#
|
5
|
+
# * ':more' more than
|
6
|
+
# * ':less' less than
|
7
|
+
# * ':moreeq' more than or equal to
|
8
|
+
# * ':lesseq' less than or equal to
|
9
|
+
# * ':equal' equal to
|
10
|
+
# * ':noteq' not equal to
|
2
11
|
|
3
|
-
|
4
|
-
|
5
|
-
#
|
6
|
-
# * ':more' more than
|
7
|
-
# * ':less' less than
|
8
|
-
# * ':moreeq' more than or equal to
|
9
|
-
# * ':lesseq' less than or equal to
|
10
|
-
# * ':equal' equal to
|
11
|
-
# * ':noteq' not equal to
|
12
|
-
|
13
|
-
class OperationRelational < Symbol
|
14
|
-
end
|
12
|
+
class OperationRelational < Symbol
|
13
|
+
end
|
15
14
|
end
|
data/lib/vips/operationround.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
module Vips
|
2
|
+
# The type of rounding to perform on an image. See {Image#round}.
|
3
|
+
#
|
4
|
+
# * ':ceil' round up
|
5
|
+
# * ':floor' round down
|
6
|
+
# * ':rint' round to nearest integer
|
2
7
|
|
3
|
-
|
4
|
-
|
5
|
-
# * ':ceil' round up
|
6
|
-
# * ':floor' round down
|
7
|
-
# * ':rint' round to nearest integer
|
8
|
-
|
9
|
-
class OperationRound < Symbol
|
10
|
-
end
|
8
|
+
class OperationRound < Symbol
|
9
|
+
end
|
11
10
|
end
|
data/lib/vips/region.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# This module provides an interface to the top level bits of libvips
|
2
|
+
# via ruby-ffi.
|
3
|
+
#
|
4
|
+
# Author:: John Cupitt (mailto:jcupitt@gmail.com)
|
5
|
+
# License:: MIT
|
6
|
+
|
7
|
+
require "ffi"
|
8
|
+
|
9
|
+
module Vips
|
10
|
+
attach_function :vips_region_new, [:pointer], :pointer
|
11
|
+
|
12
|
+
if Vips.at_least_libvips?(8, 8)
|
13
|
+
attach_function :vips_region_fetch, [:pointer, :int, :int, :int, :int, SizeStruct.ptr], :pointer
|
14
|
+
attach_function :vips_region_width, [:pointer], :int
|
15
|
+
attach_function :vips_region_height, [:pointer], :int
|
16
|
+
end
|
17
|
+
|
18
|
+
# A region on an image. Create one, then use `fetch` to quickly get a region
|
19
|
+
# of pixels.
|
20
|
+
#
|
21
|
+
# For example:
|
22
|
+
#
|
23
|
+
# ```ruby
|
24
|
+
# region = Vips::Region.new(image)
|
25
|
+
# pixels = region.fetch(10, 10, 100, 100)
|
26
|
+
# ```
|
27
|
+
class Region < Vips::Object
|
28
|
+
# The layout of the VipsRegion struct.
|
29
|
+
module RegionLayout
|
30
|
+
def self.included(base)
|
31
|
+
base.class_eval do
|
32
|
+
layout :parent, Vips::Object::Struct
|
33
|
+
# rest opaque
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class Struct < Vips::Object::Struct
|
39
|
+
include RegionLayout
|
40
|
+
end
|
41
|
+
|
42
|
+
class ManagedStruct < Vips::Object::ManagedStruct
|
43
|
+
include RegionLayout
|
44
|
+
end
|
45
|
+
|
46
|
+
def initialize(name)
|
47
|
+
ptr = Vips.vips_region_new name
|
48
|
+
raise Vips::Error if ptr.null?
|
49
|
+
|
50
|
+
super ptr
|
51
|
+
end
|
52
|
+
|
53
|
+
def width
|
54
|
+
Vips.vips_region_width self
|
55
|
+
end
|
56
|
+
|
57
|
+
def height
|
58
|
+
Vips.vips_region_height self
|
59
|
+
end
|
60
|
+
|
61
|
+
# Fetch a region filled with pixel data.
|
62
|
+
def fetch(left, top, width, height)
|
63
|
+
len = Vips::SizeStruct.new
|
64
|
+
ptr = Vips.vips_region_fetch self, left, top, width, height, len
|
65
|
+
raise Vips::Error if ptr.null?
|
66
|
+
|
67
|
+
# wrap up as an autopointer
|
68
|
+
ptr = FFI::AutoPointer.new(ptr, GLib::G_FREE)
|
69
|
+
|
70
|
+
ptr.get_bytes 0, len[:value]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/lib/vips/size.rb
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
module Vips
|
2
|
+
# Controls whether an operation should upsize, downsize, or both up and
|
3
|
+
# downsize.
|
4
|
+
#
|
5
|
+
# * `:both` size both up and down
|
6
|
+
# * `:up` only upsize
|
7
|
+
# * `:down` only downsize
|
8
|
+
# * `:force` change aspect ratio
|
2
9
|
|
3
|
-
|
4
|
-
|
5
|
-
#
|
6
|
-
# * `:both` size both up and down
|
7
|
-
# * `:up` only upsize
|
8
|
-
# * `:down` only downsize
|
9
|
-
# * `:force` change aspect ratio
|
10
|
-
|
11
|
-
class Size < Symbol
|
12
|
-
end
|
10
|
+
class Size < Symbol
|
11
|
+
end
|
13
12
|
end
|
data/lib/vips/source.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
# This module provides an interface to the top level bits of libvips
|
2
|
+
# via ruby-ffi.
|
3
|
+
#
|
4
|
+
# Author:: John Cupitt (mailto:jcupitt@gmail.com)
|
5
|
+
# License:: MIT
|
6
|
+
|
7
|
+
require "ffi"
|
8
|
+
|
9
|
+
module Vips
|
10
|
+
if Vips.at_least_libvips?(8, 9)
|
11
|
+
attach_function :vips_source_new_from_descriptor, [:int], :pointer
|
12
|
+
attach_function :vips_source_new_from_file, [:pointer], :pointer
|
13
|
+
attach_function :vips_source_new_from_memory, [:pointer, :size_t], :pointer
|
14
|
+
end
|
15
|
+
|
16
|
+
# A source. For example:
|
17
|
+
#
|
18
|
+
# ```ruby
|
19
|
+
# source = Vips::Source.new_from_file("k2.jpg")
|
20
|
+
# image = Vips::Image.new_from_source(source)
|
21
|
+
# ```
|
22
|
+
class Source < Vips::Connection
|
23
|
+
module SourceLayout
|
24
|
+
def self.included(base)
|
25
|
+
base.class_eval do
|
26
|
+
layout :parent, Vips::Connection::Struct
|
27
|
+
# rest opaque
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class Struct < Vips::Connection::Struct
|
33
|
+
include SourceLayout
|
34
|
+
end
|
35
|
+
|
36
|
+
class ManagedStruct < Vips::Connection::ManagedStruct
|
37
|
+
include SourceLayout
|
38
|
+
end
|
39
|
+
|
40
|
+
# Create a new source from a file descriptor. File descriptors are
|
41
|
+
# small integers, for example 0 is stdin.
|
42
|
+
#
|
43
|
+
# Pass sources to {Image.new_from_source} to load images from
|
44
|
+
# them.
|
45
|
+
#
|
46
|
+
# @param descriptor [Integer] the file descriptor
|
47
|
+
# @return [Source] the new Vips::Source
|
48
|
+
def self.new_from_descriptor(descriptor)
|
49
|
+
ptr = Vips.vips_source_new_from_descriptor descriptor
|
50
|
+
raise Vips::Error if ptr.null?
|
51
|
+
|
52
|
+
Vips::Source.new ptr
|
53
|
+
end
|
54
|
+
|
55
|
+
# Create a new source from a file name.
|
56
|
+
#
|
57
|
+
# Pass sources to {Image.new_from_source} to load images from
|
58
|
+
# them.
|
59
|
+
#
|
60
|
+
# @param filename [String] the name of the file
|
61
|
+
# @return [Source] the new Vips::Source
|
62
|
+
def self.new_from_file(filename)
|
63
|
+
raise Vips::Error, "filename is nil" if filename.nil?
|
64
|
+
ptr = Vips.vips_source_new_from_file filename
|
65
|
+
raise Vips::Error if ptr.null?
|
66
|
+
|
67
|
+
Vips::Source.new ptr
|
68
|
+
end
|
69
|
+
|
70
|
+
# Create a new source from an area of memory. Memory areas can be
|
71
|
+
# strings, arrays and so forth -- anything that supports bytesize.
|
72
|
+
#
|
73
|
+
# Pass sources to {Image.new_from_source} to load images from
|
74
|
+
# them.
|
75
|
+
#
|
76
|
+
# @param data [String] memory area
|
77
|
+
# @return [Source] the new Vips::Source
|
78
|
+
def self.new_from_memory(data)
|
79
|
+
ptr = Vips.vips_source_new_from_memory data, data.bytesize
|
80
|
+
raise Vips::Error if ptr.null?
|
81
|
+
|
82
|
+
# FIXME do we need to keep a ref to the underlying memory area? what
|
83
|
+
# about Image.new_from_buffer? Does that need a secret ref too?
|
84
|
+
|
85
|
+
Vips::Source.new ptr
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# This module provides an interface to the top level bits of libvips
|
2
|
+
# via ruby-ffi.
|
3
|
+
#
|
4
|
+
# Author:: John Cupitt (mailto:jcupitt@gmail.com)
|
5
|
+
# License:: MIT
|
6
|
+
|
7
|
+
require "ffi"
|
8
|
+
|
9
|
+
module Vips
|
10
|
+
if Vips.at_least_libvips?(8, 9)
|
11
|
+
attach_function :vips_source_custom_new, [], :pointer
|
12
|
+
end
|
13
|
+
|
14
|
+
# A source you can attach action signal handlers to to implement
|
15
|
+
# custom input types.
|
16
|
+
#
|
17
|
+
# For example:
|
18
|
+
#
|
19
|
+
# ```ruby
|
20
|
+
# file = File.open "some/file/name", "rb"
|
21
|
+
# source = Vips::SourceCustom.new
|
22
|
+
# source.on_read { |length| file.read length }
|
23
|
+
# image = Vips::Image.new_from_source source
|
24
|
+
# ```
|
25
|
+
#
|
26
|
+
# (just an example -- of course in practice you'd use {Source#new_from_file}
|
27
|
+
# to read from a named file)
|
28
|
+
class SourceCustom < Vips::Source
|
29
|
+
module SourceCustomLayout
|
30
|
+
def self.included(base)
|
31
|
+
base.class_eval do
|
32
|
+
layout :parent, Vips::Source::Struct
|
33
|
+
# rest opaque
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class Struct < Vips::Source::Struct
|
39
|
+
include SourceCustomLayout
|
40
|
+
end
|
41
|
+
|
42
|
+
class ManagedStruct < Vips::Source::ManagedStruct
|
43
|
+
include SourceCustomLayout
|
44
|
+
end
|
45
|
+
|
46
|
+
def initialize
|
47
|
+
pointer = Vips.vips_source_custom_new
|
48
|
+
raise Vips::Error if pointer.null?
|
49
|
+
|
50
|
+
super pointer
|
51
|
+
end
|
52
|
+
|
53
|
+
# The block is executed to read data from the source. The interface is
|
54
|
+
# exactly as IO::read, ie. it takes a maximum number of bytes to read and
|
55
|
+
# returns a string of bytes from the source, or nil if the source is already
|
56
|
+
# at end of file.
|
57
|
+
#
|
58
|
+
# @yieldparam length [Integer] Read and return up to this many bytes
|
59
|
+
# @yieldreturn [String] Up to length bytes of data, or nil for EOF
|
60
|
+
def on_read &block
|
61
|
+
signal_connect "read" do |buf, len|
|
62
|
+
chunk = block.call len
|
63
|
+
return 0 if chunk.nil?
|
64
|
+
bytes_read = chunk.bytesize
|
65
|
+
buf.put_bytes(0, chunk, 0, bytes_read)
|
66
|
+
chunk.clear
|
67
|
+
|
68
|
+
bytes_read
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# The block is executed to seek the source. The interface is exactly as
|
73
|
+
# IO::seek, ie. it should take an offset and whence, and return the
|
74
|
+
# new read position.
|
75
|
+
#
|
76
|
+
# This handler is optional -- if you do not attach a seek handler,
|
77
|
+
# {Source} will treat your source like an unseekable pipe object and
|
78
|
+
# do extra caching.
|
79
|
+
#
|
80
|
+
# @yieldparam offset [Integer] Seek offset
|
81
|
+
# @yieldparam whence [Integer] Seek whence
|
82
|
+
# @yieldreturn [Integer] the new read position, or -1 on error
|
83
|
+
def on_seek &block
|
84
|
+
signal_connect "seek" do |offset, whence|
|
85
|
+
block.call offset, whence
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|