Vips.Operation

g GObject.Object GObject.Object Vips.Object Vips.Object GObject.Object->Vips.Object Vips.Operation Vips.Operation Vips.Object->Vips.Operation

Subclasses:

Vips.Foreign

Methods

Inherited:

Vips.Object (27), GObject.Object (37)

Structs:

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

class

block_set (name, state)

class

new (name)

get_flags ()

invalidate ()

Virtual Methods

Inherited:

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

do_get_flags ()

do_invalidate ()

Properties

Inherited:

Vips.Object (2)

Signals

Inherited:

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

Name

Short Description

invalidate

Fields

Inherited:

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

Name

Type

Access

Description

found_hash

bool

r

hash

int

r

parent_instance

Vips.Object

r

pixels

int

r

Class Details

class Vips.Operation(**kwargs)
Bases:

Vips.Object

Abstract:

Yes

Structure:

Vips.OperationClass

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 vips main 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 im and return a new [class`Image`], t1. As the caller of [method`Image`.invert], you are responsible for t1 and must unref it when you no longer need it. If [method`Image`.invert] fails, no t1 is returned and you don’t need to do anything.

If you don’t need to use im for another operation, you can unref im immediately after the call. If im is needed to calculate t1, [method`Image`.invert] will add a ref to im and automatically drop it when t1 is 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 parent is 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 when parent is 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:
  • name (str) – set block state at this point and below

  • state (bool) – the block state to set

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 -l at 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:

Vips.Operation

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:

Vips.OperationFlags

Returns the set of flags for this operation.

invalidate()
do_get_flags() virtual
Returns:

0 on success, or -1 on error.

Return type:

Vips.OperationFlags

Returns the set of flags for this operation.

do_invalidate() virtual

Signal Details

Vips.Operation.signals.invalidate(operation)
Signal Name:

invalidate

Flags:

RUN_LAST

Parameters:

operation (Vips.Operation) – The object which received the signal