class Vips::Argument
This class is used internally to convert Ruby values to arguments to libvips operations. @private
Attributes
blurb[R]
flags[R]
gtype[R]
isset[R]
name[R]
op[R]
priority[R]
prop[R]
type[R]
Public Class Methods
new(op, name)
click to toggle source
# File lib/vips8/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
Private Class Methods
arrayize(gtype, value)
click to toggle source
if this gtype needs an array, try to transform the value into one
# File lib/vips8/argument.rb, line 87 def self.arrayize(gtype, value) arrayize_map = { GLib::Type["VipsArrayDouble"] => Vips::ArrayDouble, GLib::Type["VipsArrayInt"] => Vips::ArrayInt, GLib::Type["VipsArrayImage"] => ArrayImageConst } if arrayize_map.has_key? gtype if not value.is_a? Array value = [value] end value = arrayize_map[gtype].new(value) end value end
imageize(match_image, value)
click to toggle source
# File lib/vips8/argument.rb, line 37 def self.imageize match_image, value return value if match_image == nil return value if value.is_a? Vips::Image # 2D array values become tiny 2D images if value.is_a? Array and value[0].is_a? Array return Vips::Image.new_from_array value end # if there's nothing to match to, we also make a 2D image if match_image == nil return Vips::Image.new_from_array value end # we have a 1D array ... use that as a pixel constant and expand # to match match_image pixel = (Vips::Image.black(1, 1) + value).cast(match_image.format) pixel = pixel.copy :interpretation => match_image.interpretation, :xres => match_image.xres, :yres => match_image.yres pixel.embed(0, 0, match_image.width, match_image.height, :extend => :copy) end
unwrap(value)
click to toggle source
# File lib/vips8/argument.rb, line 105 def self.unwrap value [Vips::Blob, Vips::ArrayDouble, Vips::ArrayImage, Vips::ArrayInt, Vips::RefString].each do |cls| if value.is_a? cls value, length = value.get # blobs come from gobject-introspection as arrays ... # repack as strings for convenience if value and cls == Vips::Blob value = value.pack("C*") end end end value end
Public Instance Methods
get_value()
click to toggle source
# File lib/vips8/argument.rb, line 157 def get_value Argument::unwrap @op.get_property(@name) end
set_value(match_image, value)
click to toggle source
# File lib/vips8/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