Vips.ForeignLoad

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

Subclasses:

None

Methods

Inherited:

Vips.Foreign (11), Vips.Operation (4), Vips.Object (27), GObject.Object (37)

Structs:

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

Virtual Methods

Inherited:

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

do_get_flags ()

do_header ()

do_load ()

Properties

Inherited:

Vips.Object (2)

Name

Type

Flags

Short Description

access

Vips.Access

r/w

Required access pattern for this file

disc

bool

r/w

Open to disc

fail

bool

r/w

Fail on first warning

fail-on

Vips.FailOn

r/w

Error level to fail on

flags

Vips.ForeignFlags

r/w

Flags for this file

memory

bool

r/w

Force open via memory

out

Vips.Image

r/w

Output image

revalidate

bool

r/w

Don’t use a cached result for this operation

sequential

bool

r/w

Sequential read only

Signals

Inherited:

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

Fields

Inherited:

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

Name

Type

Access

Description

access

Vips.Access

r

disc

bool

r

error

bool

r

fail

bool

r

fail_on

Vips.FailOn

r

flags

Vips.ForeignFlags

r

memory

bool

r

nocache

bool

r

out

Vips.Image

r

parent_object

Vips.Foreign

r

real

Vips.Image

r

revalidate

bool

r

sequential

bool

r

Class Details

class Vips.ForeignLoad(**kwargs)
Bases:

Vips.Foreign

Abstract:

Yes

Structure:

Vips.ForeignLoadClass

An abstract base class to load images in a variety of formats.

Writing a new loader

Add a new loader to libvips by subclassing [class`ForeignLoad`]. Subclasses need to implement at least [vfunc`ForeignLoad`.header].

[vfunc`ForeignLoad`.header] must set at least the header fields of out. [vfunc`ForeignLoad`.load], if defined, must load the pixels to real.

The suffix list is used to select a format to save a file in, and to pick a loader if you don’t define [func`Foreign`.is_a].

You should also define [property`Object`:py:data::nickname<Vips.ForeignLoad.props.nickname>] and [property`Object`:py:data::description<Vips.ForeignLoad.props.description>] in [class`Object`].

As a complete example, here’s code for a PNG loader, minus the actual calls to libpng.

```c typedef struct _VipsForeignLoadPng { Vips.ForeignLoad parent_object;

str *filename; } VipsForeignLoadPng;

typedef Vips.ForeignLoadClass VipsForeignLoadPngClass;

G_DEFINE_TYPE(VipsForeignLoadPng, vips_foreign_load_png, VIPS_TYPE_FOREIGN_LOAD);

static Vips.ForeignFlags vips_foreign_load_png_get_flags_filename(const str *filename) { Vips.ForeignFlags flags;

flags = 0; if (vips__png_isinterlaced(filename)) flags = Vips.ForeignFlags.PARTIAL; else flags = Vips.ForeignFlags.SEQUENTIAL;

return flags; }

static Vips.ForeignFlags vips_foreign_load_png_get_flags(Vips.ForeignLoad *load) { VipsForeignLoadPng *png = (VipsForeignLoadPng *) load;

return vips_foreign_load_png_get_flags_filename(png->filename); }

static int vips_foreign_load_png_header(Vips.ForeignLoad *load) { VipsForeignLoadPng *png = (VipsForeignLoadPng *) load;

if (vips__png_header(png->filename, load->out)) return -1;

return 0; }

static int vips_foreign_load_png_load(Vips.ForeignLoad *load) { VipsForeignLoadPng *png = (VipsForeignLoadPng *) load;

if (vips__png_read(png->filename, load->real)) return -1;

return 0; }

static void vips_foreign_load_png_class_init(VipsForeignLoadPngClass *class) { GObject.ObjectClass *gobject_class = G_OBJECT_CLASS(class); Vips.ObjectClass *object_class = (Vips.ObjectClass *) class; Vips.ForeignClass *foreign_class = (Vips.ForeignClass *) class; Vips.ForeignLoadClass *load_class = (Vips.ForeignLoadClass *) class;

gobject_class->set_property = Vips.Object.set_property; gobject_class->get_property = Vips.Object.get_property;

object_class->nickname = “pngload”; object_class->description = _(“load png from file”);

foreign_class->suffs = vips__png_suffs;

load_class->is_a = vips__png_ispng; load_class->get_flags_filename = vips_foreign_load_png_get_flags_filename; load_class->get_flags = vips_foreign_load_png_get_flags; load_class->header = vips_foreign_load_png_header; load_class->load = vips_foreign_load_png_load;

VIPS_ARG_STRING(class, “filename”, 1, _(“Filename”), _(“Filename to load from”), Vips.ARGUMENT_REQUIRED_INPUT, G_STRUCT_OFFSET(VipsForeignLoadPng, filename), None); }

static void vips_foreign_load_png_init(VipsForeignLoadPng *png) { } ```

do_get_flags() virtual
Return type:

Vips.ForeignFlags

do_header() virtual
Return type:

int

do_load() virtual
Return type:

int

Property Details

Vips.ForeignLoad.props.access
Name:

access

Type:

Vips.Access

Default Value:

Vips.Access.RANDOM

Flags:

READABLE, WRITABLE

Required access pattern for this file

Vips.ForeignLoad.props.disc
Name:

disc

Type:

bool

Default Value:

True

Flags:

READABLE, WRITABLE

Open to disc

Vips.ForeignLoad.props.fail
Name:

fail

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE

Fail on first warning

Vips.ForeignLoad.props.fail_on
Name:

fail-on

Type:

Vips.FailOn

Default Value:

Vips.FailOn.NONE

Flags:

READABLE, WRITABLE

Error level to fail on

Vips.ForeignLoad.props.flags
Name:

flags

Type:

Vips.ForeignFlags

Default Value:

Vips.ForeignFlags.NONE

Flags:

READABLE, WRITABLE

Flags for this file

Vips.ForeignLoad.props.memory
Name:

memory

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE

Force open via memory

Vips.ForeignLoad.props.out
Name:

out

Type:

Vips.Image

Default Value:

None

Flags:

READABLE, WRITABLE

Output image

Vips.ForeignLoad.props.revalidate
Name:

revalidate

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE

Don’t use a cached result for this operation

Vips.ForeignLoad.props.sequential
Name:

sequential

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE

Sequential read only