Vips.Operation¶
- Subclasses:
Methods¶
- Inherited:
- Structs:
class |
|
class |
|
|
|
|
Virtual Methods¶
- Inherited:
|
|
Properties¶
- Inherited:
Signals¶
- Inherited:
Name |
Short Description |
|---|---|
Fields¶
- Inherited:
Name |
Type |
Access |
Description |
|---|---|---|---|
found_hash |
r |
||
hash |
r |
||
parent_instance |
r |
||
pixels |
r |
Class Details¶
- class Vips.Operation(**kwargs)¶
- Bases:
- Abstract:
Yes
- Structure:
An abstract base class for all operations in libvips.
It builds on [class`Object`] to provide the introspection and command-line interface to libvips.
It also maintains a cache of recent operations. See below.
[func`call`], [func`call_split`] and [func`call_split_option_string`] are used by vips to implement the C API. They can execute any [class`Operation`], passing in a set of required and optional arguments. Normally you would not use these functions directly: every operation has a tiny wrapper function which provides type-safety for the required arguments. For example, [method`Image`.embed] is defined as:
```c int vips_embed(
Vips.Image*in,Vips.Image**out, int x, int y, int width, int height, …) { va_list ap; int result;va_start(ap, height); result = vips_call_split(“embed”, ap, in, out, x, y, width, height); va_end(ap);
return result; } ```
Use [func`call_argv`] to run any libvips operation from a command-line style argc/argv array. This is the thing used by the
vipsmain program to implement the command-line interface.- [class`Operation`] and reference counting
After calling a [class`Operation`] you are responsible for unreffing any output objects. For example, consider:
```c
Vips.Image*im = …;Vips.Image*t1;if (vips_invert(im, &t1,
None)) error .. ```This will invert
imand return a new [class`Image`],t1. As the caller of [method`Image`.invert], you are responsible fort1and must unref it when you no longer need it. If [method`Image`.invert] fails, not1is returned and you don’t need to do anything.If you don’t need to use
imfor another operation, you can unrefimimmediately after the call. Ifimis needed to calculatet1, [method`Image`.invert] will add a ref toimand automatically drop it whent1is unreffed.Consider running two operations, one after the other. You could write:
```c
Vips.Image*im = …;Vips.Image*t1, *t2;if (vips_invert(im, &t1,
None)) {GObject.Object.unref(im); return -1; }GObject.Object.unref(im);if (vips_flip(t1, &t2,
Vips.Direction.HORIZONTAL,None)) {GObject.Object.unref(t1); return -1; }GObject.Object.unref(t1); ```This is correct, but rather long-winded. libvips provides a handy thing to make a vector of auto-freeing object references. You can write this as:
```c
Vips.Object*parent = …;Vips.Image*im = …;Vips.Image*t = (Vips.Image**) vips_object_local_array(parent, 2);if (vips_invert(im, &t[0],
None) || vips_flip(t[0], &t[1],Vips.Direction.HORIZONTAL,None)) return -1; ```where
parentis some enclosing object which will be unreffed when this task is complete. [method`Object`.local_array] makes an array of [class`Object`] (or [class`Image`], in this case) where whenparentis freed, all non-NULL[class`Object`] in the array are also unreffed.- The [class`Operation`] cache
Because all [class`Object`] are immutable, they can be cached. The cache is very simple to use: instead of calling [method`Object`.build], call [func`cache_operation_build`]. This function calculates a hash from the operations’ input arguments and looks it up in table of all recent operations. If there’s a hit, the new operation is unreffed, the old operation reffed, and the old operation returned in place of the new one.
The cache size is controlled with [func`cache_set_max`] and friends.
- classmethod block_set(name, state)¶
- Parameters:
Set the block state on all operations in the libvips class hierarchy at name and below.
For example:
``c vips_operation_block_set(“VipsForeignLoad”, TRUE); vips_operation_block_set(“VipsForeignLoadJpeg”, FALSE); ``
Will block all load operations, except JPEG.
Use
vips -lat the command-line to see the class hierarchy.This call does nothing if the named operation is not found.
::: seealso [func`block_untrusted_set`].
- classmethod new(name)¶
- Parameters:
name (
str) – nickname of operation to create- Returns:
the new operation.
- Return type:
Return a new [class`Operation`] with the specified nickname. Useful for language bindings.
You’ll need to set any arguments and build the operation before you can use it. See [func`call`] for a higher-level way to make new operations.
- get_flags()¶
- Returns:
0 on success, or -1 on error.
- Return type:
Returns the set of flags for this operation.
- invalidate()¶
- do_get_flags() virtual¶
- Returns:
0 on success, or -1 on error.
- Return type:
Returns the set of flags for this operation.
- do_invalidate() virtual¶
Signal Details¶
- Vips.Operation.signals.invalidate(operation)¶
- Signal Name:
invalidate- Flags:
- Parameters:
operation (
Vips.Operation) – The object which received the signal