Vips.Region

g GObject.Object GObject.Object Vips.Object Vips.Object GObject.Object->Vips.Object Vips.Region Vips.Region Vips.Object->Vips.Region

Subclasses:None

Methods

Inherited:Vips.Object (26), GObject.Object (37)
Structs:Vips.ObjectClass (1), GObject.ObjectClass (5)
class new (image)
  copy (dest, r, x, y)
  equalsregion (reg2)
  region_black ()
  region_buffer (r)
  region_fetch (left, top, width, height, len)
  region_height ()
  region_image (r)
  region_invalidate ()
  region_paint (r, value)
  region_paint_pel (r, ink)
  region_position (x, y)
  region_prepare (r)
  region_prepare_to (dest, r, x, y)
  region_region (dest, r, x, y)
  region_width ()
  shrink_method (to, target, method)

Virtual Methods

Inherited:Vips.Object (7), GObject.Object (7)

Properties

Inherited:Vips.Object (2)

Fields

Inherited:Vips.Object (4), GObject.Object (1)
Name Type Access Description
bpl int r  
buffer object r  
data int r  
im Vips.Image r the Vips.Image that this region is defined on
invalid bool r  
parent_object Vips.Object r  
seq object r  
thread GLib.Thread r  
type object r  
valid Vips.Rect r the Vips.Rect of pixels that this region represents
window object r  

Class Details

class Vips.Region(**kwargs)
Bases:Vips.Object
Abstract:No
Structure:Vips.RegionClass

A small part of a Vips.Image. valid holds the left/top/width/height of the area of pixels that are available from the region.

See also: VIPS_REGION_ADDR(), Vips.Region.new(), Vips.Region.region_prepare().

classmethod new(image)
Parameters:image (Vips.Image) – image to create this region on
Return type:Vips.Region

Create a region. Vips.Region s start out empty, you need to call Vips.Region.region_prepare() to fill them with pixels.

See also: Vips.Region.region_prepare().

copy(dest, r, x, y)
Parameters:
Returns:

destination region

Return type:

dest: Vips.Region

Copy from one region to another. Copy area r from inside self to dest, positioning the area of pixels at x, y. The two regions must have pixels which are the same size.

See also: Vips.Region.region_paint().

equalsregion(reg2)
Parameters:reg2 (Vips.Region) – region to test
Returns:non-zero on equality.
Return type:int

Do two regions point to the same piece of image? ie.

VIPS_REGION_ADDR( reg1, x, y ) == VIPS_REGION_ADDR( reg2, x, y ) &&
*VIPS_REGION_ADDR( reg1, x, y ) ==
    *VIPS_REGION_ADDR( reg2, x, y ) for all x, y, reg1, reg2.
region_black()

Paints 0 into the valid part of self.

See also: Vips.Region.region_paint().

region_buffer(r)
Parameters:r (Vips.Rect) – Vips.Rect of pixels you need to be able to address
Returns:0 on success, or -1 for error.
Return type:int

The region is transformed so that at least r pixels are available as a memory buffer that can be written to.

region_fetch(left, top, width, height, len)
Parameters:
  • left (int) – area of pixels to fetch
  • top (int) – area of pixels to fetch
  • width (int) – area of pixels to fetch
  • height (int) – area of pixels to fetch
  • len (int) –
Returns:

A copy of the pixel data.

Return type:

int

Generate an area of pixels and return a copy. The result must be freed with GLib.free(). The requested area must be completely inside the image.

This is equivalent to Vips.Region.region_prepare(), followed by a memcpy. It is convenient for language bindings.

region_height()
Returns:Height of the pixels held in region.
Return type:int
region_image(r)
Parameters:r (Vips.Rect) – Vips.Rect of pixels you need to be able to address
Returns:0 on success, or -1 for error.
Return type:int

The region is transformed so that at least r pixels are available to be read from the image. The image needs to be a memory buffer or represent a file on disc that has been mapped or can be mapped.

region_invalidate()

Mark a region as containing invalid pixels. Calling this function means that the next time Vips.Region.region_prepare() is called, the region will be recalculated.

This is faster than calling Vips.Image.image_invalidate_all(), but obviously only affects a single region.

See also: Vips.Image.image_invalidate_all(), Vips.Region.region_prepare().

region_paint(r, value)
Parameters:
  • r (Vips.Rect) – area to paint
  • value (int) – value to paint

Paints value into self covering rectangle r. r is clipped against self->valid.

For int images, value is passed to memset(), so it usually needs to be 0 or 255. For float images, value is cast to a float and copied in to each band element.

r is clipped against self->valid.

See also: Vips.Region.region_black().

region_paint_pel(r, ink)
Parameters:
  • r (Vips.Rect) – area to paint
  • ink (int) – value to paint

Paints ink into self covering rectangle r. r is clipped against self->valid.

ink should be a byte array of the same size as an image pixel containing the binary value to write into the pixels.

See also: Vips.Region.region_paint().

region_position(x, y)
Parameters:
  • x (int) – position to move to
  • y (int) – position to move to
Returns:

0 on success, or -1 for error.

Return type:

int

Set the position of a region. This only affects reg->valid, ie. the way pixels are addressed, not reg->data, the pixels which are addressed. Clip against the size of the image. Do not allow negative positions, or positions outside the image.

region_prepare(r)
Parameters:r (Vips.Rect) – Vips.Rect of pixels you need to be able to address
Returns:0 on success, or -1 on error.
Return type:int

Vips.Region.region_prepare() fills self with pixels. After calling, you can address at least the area r with VIPS_REGION_ADDR() and get valid pixels.

Vips.Region.region_prepare() runs in-line, that is, computation is done by the calling thread, no new threads are involved, and computation blocks until the pixels are ready.

Use vips_sink_screen() to calculate an area of pixels in the background.

See also: vips_sink_screen(), Vips.Region.region_prepare_to().

region_prepare_to(dest, r, x, y)
Parameters:
  • dest (Vips.Region) – region to write to
  • r (Vips.Rect) – Vips.Rect of pixels you need to be able to address
  • x (int) – postion of r in dest
  • y (int) – postion of r in dest
Returns:

0 on success, or -1 on error

dest:region to write to

Return type:

(int, dest: Vips.Region)

Like Vips.Region.region_prepare(): fill self with the pixels in area r.

Unlike Vips.Region.region_prepare(), rather than writing the result to self, the pixels are written into dest at offset x, y.

Also unlike Vips.Region.region_prepare(), dest is not set up for writing for you with Vips.Region.region_buffer(). You can point dest at anything, and pixels really will be written there. This makes Vips.Region.region_prepare_to() useful for making the ends of pipelines.

See also: Vips.Region.region_prepare(), vips_sink_disc().

region_region(dest, r, x, y)
Parameters:
  • dest (Vips.Region) – region to connect to
  • r (Vips.Rect) – Vips.Rect of pixels you need to be able to address
  • x (int) – postion of r in dest
  • y (int) – postion of r in dest
Returns:

0 on success, or -1 for error.

Return type:

int

Make VIPS_REGION_ADDR() on self go to dest instead.

r is the part of self which you want to be able to address (this effectively becomes the valid field), (x, y) is the top LH corner of the corresponding area in dest.

Performs all clipping necessary to ensure that self->valid is indeed valid.

If the region we attach to is moved or destroyed, we can be left with dangling pointers! If the region we attach to is on another image, the two images must have the same sizeof( pel ).

region_width()
Returns:Width of the pixels held in region.
Return type:int
shrink_method(to, target, method)
Parameters:
Returns:

to:destination region

Return type:

(int, to: Vips.Region)

Write the pixels target in to from the x2 larger area in self. Non-complex uncoded images and LABQ only. Images with alpha (see Vips.Image.image_hasalpha()) shrink with pixels scaled by alpha to avoid fringing.

method selects the method used to do the 2x2 shrink.

See also: Vips.Region.copy().