### Class

# Vips ForeignLoad

#### Description [src]

    abstract class Vips.ForeignLoad : Vips.Foreign
    {
      VipsImage* out,
      VipsImage* real,
      gboolean nocache,
      gboolean disc,
      gboolean error,
      gboolean revalidate
    }

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

## Writing a new loader

Add a new loader to libvips by subclassing `VipsForeignLoad`. Subclasses need to implement at least `Vips.ForeignLoadClass.header`.

`Vips.ForeignLoadClass.header` must set at least the header fields of `out`. `Vips.ForeignLoadClass.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 `vips_foreign_is_a()`.

You should also define `VipsObject:nickname` and `VipsObject:description` in `VipsObject`.

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

    typedef struct _VipsForeignLoadPng {
        VipsForeignLoad parent_object;

        char *filename;
    } VipsForeignLoadPng;

    typedef VipsForeignLoadClass VipsForeignLoadPngClass;

    G_DEFINE_TYPE(VipsForeignLoadPng, vips_foreign_load_png,
        VIPS_TYPE_FOREIGN_LOAD);

    static VipsForeignFlags
    vips_foreign_load_png_get_flags_filename(const char *filename)
    {
        VipsForeignFlags flags;

        flags = 0;
        if (vips__png_isinterlaced(filename))
             flags = VIPS_FOREIGN_PARTIAL;
        else
             flags = VIPS_FOREIGN_SEQUENTIAL;

        return flags;
    }

    static VipsForeignFlags
    vips_foreign_load_png_get_flags(VipsForeignLoad *load)
    {
      VipsForeignLoadPng *png = (VipsForeignLoadPng *) load;

      return vips_foreign_load_png_get_flags_filename(png->filename);
    }

    static int
    vips_foreign_load_png_header(VipsForeignLoad *load)
    {
        VipsForeignLoadPng *png = (VipsForeignLoadPng *) load;

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

        return 0;
    }

    static int
    vips_foreign_load_png_load(VipsForeignLoad *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)
    {
        GObjectClass *gobject_class = G_OBJECT_CLASS(class);
        VipsObjectClass *object_class = (VipsObjectClass *) class;
        VipsForeignClass *foreign_class = (VipsForeignClass *) class;
        VipsForeignLoadClass *load_class = (VipsForeignLoadClass *) 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),
            NULL);
    }

    static void
    vips_foreign_load_png_init(VipsForeignLoadPng *png)
    {
    }

#### Hierarchy

#### Ancestors

- VipsForeign
- VipsOperation
- VipsObject
- GObject

#### Instance methods

##### Methods inherited from VipsOperation (3)

###### vips_operation_call_valist

No description available.

###### vips_operation_get_flags

Returns the set of flags for this operation.

###### vips_operation_invalidate

No description available.

##### Methods inherited from VipsObject (27)

Please see VipsObject for a full list of methods.

##### Methods inherited from GObject (43)

Please see GObject for a full list of methods.

#### Properties

###### Vips.ForeignLoad:access

No description available.

###### Vips.ForeignLoad:disc

No description available.

###### Vips.ForeignLoad:fail

No description available.

###### Vips.ForeignLoad:fail-on

No description available.

###### Vips.ForeignLoad:flags

No description available.

###### Vips.ForeignLoad:memory

No description available.

###### Vips.ForeignLoad:out

No description available.

###### Vips.ForeignLoad:revalidate

No description available.

###### Vips.ForeignLoad:sequential

No description available.

##### Properties inherited from VipsObject (2)

###### Vips.Object:description

No description available.

###### Vips.Object:nickname

No description available.

#### Signals

##### Signals inherited from VipsOperation (1)

###### VipsOperation::invalidate

No description available.

##### Signals inherited from VipsObject (4)

###### VipsObject::close

The ::close signal is emitted once during object close. The object is dying and may not work.

###### VipsObject::postbuild

The ::postbuild signal is emitted once just after successful object construction. Return non-zero to cause object construction to fail.

###### VipsObject::postclose

The ::postclose signal is emitted once after object close. The object pointer is still valid, but nothing else.

###### VipsObject::preclose

The ::preclose signal is emitted once just before object close starts. The object is still alive.

##### Signals inherited from GObject (1)

###### GObject::notify

The notify signal is emitted on an object when one of its properties has its value set through g_object_set_property(), g_object_set(), et al.

#### Class structure

    struct VipsForeignLoadClass {
      VipsForeignClass parent_class;
      gboolean (* is_a) (
        const char* filename
      );
      gboolean (* is_a_buffer) (
        void* data,
        size_t size
      );
      gboolean (* is_a_source) (
        VipsSource* source
      );
      VipsForeignFlags (* get_flags_filename) (
        const char* filename
      );
      VipsForeignFlags (* get_flags) (
        VipsForeignLoad* load
      );
      int (* header) (
        VipsForeignLoad* load
      );
      int (* load) (
        VipsForeignLoad* load
      );

    }

No description available.

###### Class members

`parent_class: VipsForeignClass`

  No description available.

`is_a: gboolean (* is_a) ( const char* filename )`

  No description available.

`is_a_buffer: gboolean (* is_a_buffer) ( void* data, size_t size )`

  No description available.

`is_a_source: gboolean (* is_a_source) ( VipsSource* source )`

  No description available.

`get_flags_filename: VipsForeignFlags (* get_flags_filename) ( const char* filename )`

  No description available.

`get_flags: VipsForeignFlags (* get_flags) ( VipsForeignLoad* load )`

  No description available.

`header: int (* header) ( VipsForeignLoad* load )`

  No description available.

`load: int (* load) ( VipsForeignLoad* load )`

  No description available.

#### Virtual methods

###### Vips.ForeignLoadClass.get_flags

No description available.

###### Vips.ForeignLoadClass.header

No description available.

###### Vips.ForeignLoadClass.load

No description available.