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 (27), GObject.Object (37)

Structs:

Vips.ObjectClass (1), GObject.ObjectClass (5)

class

new (image)

black ()

buffer (r)

copy (dest, r, x, y)

equalsregion (reg2)

fetch (left, top, width, height, len)

height ()

image (r)

invalidate ()

paint (r, value)

paint_pel (r, ink)

position (x, y)

prepare (r)

prepare_to (dest, r, x, y)

region (dest, r, x, y)

shrink_method (to, target, method)

width ()

Virtual Methods

Inherited:

Vips.Object (9), GObject.Object (7)

Properties

Inherited:

Vips.Object (2)

Signals

Inherited:

Vips.Object (4), GObject.Object (1)

Fields

Inherited:

Vips.Object (4), GObject.Object (1)

Name

Type

Access

Description

bpl

int

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.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.prepare() to fill them with pixels.

See also: Vips.Region.prepare().

black()

Paints 0 into the valid part of self.

See also: Vips.Region.paint().

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.

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.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.
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.prepare(), followed by a memcpy. It is convenient for language bindings.

height()
Returns:

Height of the pixels held in region.

Return type:

int

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.

invalidate()

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

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

See also: Vips.Image.invalidate_all(), Vips.Region.prepare().

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.black().

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.paint().

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.

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.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.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.prepare_to().

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) – position of r in dest

  • y (int) – position of r in dest

Returns:

0 on success, or -1 on error

Return type:

int

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

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

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

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

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) – position of r in dest

  • y (int) – position 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).

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.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().

width()
Returns:

Width of the pixels held in region.

Return type:

int