Class: Vips::Argument

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

Overview

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

Defined Under Namespace

Classes: ArrayImageConst

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Argument) initialize(op, name)

Returns a new instance of Argument



9
10
11
12
13
14
15
16
# File 'lib/vips8/argument.rb', line 9

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

Instance Attribute Details

- (Object) flags (readonly)

:nodoc:



7
8
9
# File 'lib/vips8/argument.rb', line 7

def flags
  @flags
end

- (Object) isset (readonly)

:nodoc:



7
8
9
# File 'lib/vips8/argument.rb', line 7

def isset
  @isset
end

- (Object) name (readonly)

:nodoc:



7
8
9
# File 'lib/vips8/argument.rb', line 7

def name
  @name
end

- (Object) op (readonly)

:nodoc:



7
8
9
# File 'lib/vips8/argument.rb', line 7

def op
  @op
end

- (Object) priority (readonly)

:nodoc:



7
8
9
# File 'lib/vips8/argument.rb', line 7

def priority
  @priority
end

- (Object) prop (readonly)

:nodoc:



7
8
9
# File 'lib/vips8/argument.rb', line 7

def prop
  @prop
end

Instance Method Details

- (Object) description



143
144
145
146
147
148
149
# File 'lib/vips8/argument.rb', line 143

def description
    blurb = prop.blurb
    direction = (flags & :input) != 0 ?  "input" : "output"
    type = prop.value_type.name

    result = "[#{name}] #{blurb}, #{direction} #{type}"
end

- (Object) get_value



139
140
141
# File 'lib/vips8/argument.rb', line 139

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

- (Object) set_value(match_image, value)



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/vips8/argument.rb', line 108

def set_value(match_image, value)
    # array-ize
    value = Argument::arrayize prop.value_type, value

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

    # image-ize
    if prop.value_type.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