Class: Vips::Region

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

Overview

A region on an image. Create one, then use fetch to quickly get a region of pixels.

For example:

 region = Vips::Region.new(image)
 pixels = region.fetch(10, 10, 100, 100)

Defined Under Namespace

Modules: RegionLayout Classes: ManagedStruct, Struct

Instance Attribute Summary

Attributes inherited from GObject::GObject

#ptr, #references

Instance Method Summary collapse

Methods inherited from Object

#get, #get_pspec, #get_typeof, #get_typeof_error, print_all, #set, #signal_connect

Methods inherited from GObject::GObject

#ffi_managed_struct, ffi_managed_struct, ffi_struct, #ffi_struct

Constructor Details

#initialize(name) ⇒ Region

Returns a new instance of Region.

Raises:



46
47
48
49
50
51
# File 'lib/vips/region.rb', line 46

def initialize(name)
  pointer = Vips.vips_region_new name
  raise Vips::Error if pointer.null?

  super(pointer)
end

Instance Method Details

#fetch(left, top, width, height) ⇒ Object

Fetch a region filled with pixel data.

Raises:



62
63
64
65
66
67
68
69
70
71
# File 'lib/vips/region.rb', line 62

def fetch(left, top, width, height)
  len = Vips::SizeStruct.new
  ptr = Vips.vips_region_fetch self, left, top, width, height, len
  raise Vips::Error if ptr.null?

  # wrap up as an autopointer
  ptr = FFI::AutoPointer.new(ptr, GLib::G_FREE)

  ptr.get_bytes 0, len[:value]
end

#heightObject



57
58
59
# File 'lib/vips/region.rb', line 57

def height
  Vips.vips_region_height self
end

#widthObject



53
54
55
# File 'lib/vips/region.rb', line 53

def width
  Vips.vips_region_width self
end