Vips.Region¶
- Subclasses:
None
Methods¶
- Inherited:
- Structs:
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
Properties¶
- Inherited:
Signals¶
- Inherited:
Fields¶
- Inherited:
Name |
Type |
Access |
Description |
|---|---|---|---|
bpl |
r |
||
data |
r |
||
im |
r |
||
invalid |
r |
||
parent_object |
r |
||
seq |
r |
||
thread |
r |
||
type |
r |
||
valid |
r |
||
window |
r |
Class Details¶
- class Vips.Region(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
A [class`Region`] represents a small, rectangular part of an image.
You use regions to read pixels out of images without having to have the whole image in memory at once.
A region can be a memory buffer, part of a memory-mapped file, part of some other image, or part of some other region.
Regions must be created, used and freed all within the same thread, since they can reference private per-thread caches. libvips sanity-checks region ownership in various places, so you are likely to see [func`GLib`.assert] errors if you don’t follow this rule.
There is API to transfer ownership of regions between threads, but (hopefully) this is only needed within libvips, so we don’t expose it.
- classmethod new(image)¶
- Parameters:
image (
Vips.Image) – image to create this region on- Return type:
Create a region. [class`Region`] start out empty, you need to call [method`Region`.prepare] to fill them with pixels.
::: seealso [method`Region`.prepare].
- black()¶
Paints 0 into the valid part of self.
::: seealso [method`Region`.paint].
- buffer(r)¶
- Parameters:
r (
Vips.Rect) – [struct`Rect`] of pixels you need to be able to address- Returns:
0 on success, or -1 for error.
- Return type:
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:
dest (
Vips.Region) – destination regionr (
Vips.Rect) – [struct`Rect`] of pixels you need to copyx (
int) – position of r in desty (
int) – position of r in dest
- 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.
::: seealso [method`Region`.paint].
- equalsregion(reg2)¶
- Parameters:
reg2 (
Vips.Region) – region to test- Returns:
non-zero on equality.
- Return type:
Do two regions point to the same piece of image? ie.
``c 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:
- Returns:
A copy of the pixel data.
- Return type:
Generate an area of pixels and return a copy. The result must be freed with [func`GLib`.free]. The requested area must be completely inside the image.
This is equivalent to [method`Region`.prepare], followed by a memcpy. It is convenient for language bindings.
- image(r)¶
- Parameters:
r (
Vips.Rect) – [struct`Rect`] of pixels you need to be able to address- Returns:
0 on success, or -1 for error.
- Return type:
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 [method`Region`.prepare] is called, the region will be recalculated.
This is faster than calling [method`Image`.invalidate_all], but obviously only affects a single region.
::: seealso [method`Image`.invalidate_all], [method`Region`.prepare].
- paint(r, value)¶
-
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.
::: seealso [method`Region`.black].
- paint_pel(r, ink)¶
-
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.
::: seealso [method`Region`.paint].
- position(x, y)¶
- Parameters:
- Returns:
0 on success, or -1 for error.
- Return type:
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) – [struct`Rect`] of pixels you need to be able to address- Returns:
0 on success, or -1 on error.
- Return type:
[method`Region`.prepare] fills self with pixels. After calling, you can address at least the area r with [funcREGION_ADDR] and get valid pixels.
[method`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 [method`Image`.sink_screen] to calculate an area of pixels in the background.
::: seealso [method`Image`.sink_screen], [method`Region`.prepare_to].
- prepare_to(dest, r, x, y)¶
- Parameters:
dest (
Vips.Region) – region to write tor (
Vips.Rect) – [struct`Rect`] of pixels you need to be able to addressx (
int) – position of r in desty (
int) – position of r in dest
- Returns:
0 on success, or -1 on error
- Return type:
Like [method`Region`.prepare]: fill self with the pixels in area r.
Unlike [method`Region`.prepare], rather than writing the result to self, the pixels are written into dest at offset x, y.
Also unlike [method`Region`.prepare], dest is not set up for writing for you with [method`Region`.buffer]. You can point dest at anything, and pixels really will be written there. This makes [method`Region`.prepare_to] useful for making the ends of pipelines.
::: seealso [method`Region`.prepare], [method`Image`.sink_disc].
- region(dest, r, x, y)¶
- Parameters:
dest (
Vips.Region) – region to connect tor (
Vips.Rect) – [struct`Rect`] of pixels you need to be able to addressx (
int) – position of r in desty (
int) – position of r in dest
- Returns:
0 on success, or -1 for error.
- Return type:
Make [funcREGION_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:
to (
Vips.Region) – destination regiontarget (
Vips.Rect) – [struct`Rect`] of pixels you need to copymethod (
Vips.RegionShrink) – method to use when generating target pixels
- 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.
method selects the method used to do the 2x2 shrink.
::: seealso [method`Region`.copy].