Class: Vips::Argument

Inherits:
Object
  • Object
show all
Defined in:
lib/vips/argument.rb

Overview

This class is used internally to convert Ruby values to arguments to libvips operations.

Defined Under Namespace

Classes: ArrayImageConst

Constant Summary collapse

@@map_goi_to_vips =

map gobject-introspection’s ruby class names to ours

{
    "TrueClass" => "Boolean",
    "Vips::ArrayDouble" => "Array<Double>",
    "Vips::ArrayInt" => "Array<Integer>",
    "Vips::ArrayImage" => "Array<Image>",
    "Vips::ArrayString" => "Array<String>",
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(op, name) ⇒ Argument

Returns a new instance of Argument.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/vips/argument.rb', line 20

def initialize(op, name)
    @op = op
    @name = name.tr '-', '_'
    @prop = op.gtype.to_class.property name
    @blurb = @prop.blurb
    @gtype = prop.value_type
    @flags = op.get_argument_flags name
    @priority = op.get_argument_priority @name
    @isset = op.argument_isset @name

    type = GLib::Type[gtype.name].to_class.name
    type = @@map_goi_to_vips[type] if @@map_goi_to_vips.include? type
    @type = type
end

Instance Attribute Details

#blurbObject (readonly)

Returns the value of attribute blurb.



9
10
11
# File 'lib/vips/argument.rb', line 9

def blurb
  @blurb
end

#flagsObject (readonly)

Returns the value of attribute flags.



8
9
10
# File 'lib/vips/argument.rb', line 8

def flags
  @flags
end

#gtypeObject (readonly)

Returns the value of attribute gtype.



9
10
11
# File 'lib/vips/argument.rb', line 9

def gtype
  @gtype
end

#issetObject (readonly)

Returns the value of attribute isset.



8
9
10
# File 'lib/vips/argument.rb', line 8

def isset
  @isset
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/vips/argument.rb', line 8

def name
  @name
end

#opObject (readonly)

Returns the value of attribute op.



8
9
10
# File 'lib/vips/argument.rb', line 8

def op
  @op
end

#priorityObject (readonly)

Returns the value of attribute priority.



8
9
10
# File 'lib/vips/argument.rb', line 8

def priority
  @priority
end

#propObject (readonly)

Returns the value of attribute prop.



8
9
10
# File 'lib/vips/argument.rb', line 8

def prop
  @prop
end

#typeObject (readonly)

Returns the value of attribute type.



9
10
11
# File 'lib/vips/argument.rb', line 9

def type
  @type
end

Instance Method Details

#get_valueObject



157
158
159
# File 'lib/vips/argument.rb', line 157

def get_value
    Argument::unwrap @op.get_property(@name)
end

#set_value(match_image, value) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/vips/argument.rb', line 126

def set_value(match_image, value)
    # array-ize
    value = Argument::arrayize gtype, value

    # blob-ize
    if gtype.type_is_a? GLib::Type["VipsBlob"]
        if not value.is_a? Vips::Blob
            value = Vips::Blob.copy value
        end
    end

    # image-ize
    if gtype.type_is_a? GLib::Type["VipsImage"]
        if not value.is_a? Vips::Image
            value = Argument::imageize match_image, value
        end
    end

    # MODIFY input images need to be copied before assigning them
    if (flags & :modify) != 0
        # don't use .copy(): we want to make a new pipeline with no
        # reference back to the old stuff ... this way we can free the
        # previous image earlier 
        new_image = Vips::Image.memory
        value.write new_image
        value = new_image
    end

    op.set_property @name, value
end