## VipsInterpolate

VipsInterpolate — various interpolators: nearest, bilinear, and some non-linear

## Stability Level

Stable, unless otherwise indicated

## Synopsis

    #include <vips/vips.h>

                        VipsInterpolate;
    void                (*VipsInterpolateMethod)            (VipsInterpolate *interpolate,
                                                             void *out,
                                                             VipsRegion *in,
                                                             double x,
                                                             double y);
                        VipsInterpolateClass;
    void                vips_interpolate                    (VipsInterpolate *interpolate,
                                                             void *out,
                                                             VipsRegion *in,
                                                             double x,
                                                             double y);
    VipsInterpolateMethod vips_interpolate_get_method       (VipsInterpolate *interpolate);
    int                 vips_interpolate_get_window_size    (VipsInterpolate *interpolate);
    int                 vips_interpolate_get_window_offset  (VipsInterpolate *interpolate);
    #define             VIPS_TRANSFORM_SHIFT
    #define             VIPS_TRANSFORM_SCALE
    #define             VIPS_INTERPOLATE_SHIFT
    #define             VIPS_INTERPOLATE_SCALE
    VipsInterpolate *   vips_interpolate_nearest_static     (void);
    VipsInterpolate *   vips_interpolate_bilinear_static    (void);
    VipsInterpolate *   vips_interpolate_new                (const char *nickname);

## Object Hierarchy

      GObject
       +----VipsObject
             +----VipsInterpolate

## Description

A number of image interpolators.

## Details

### VipsInterpolate

    typedef struct _VipsInterpolate VipsInterpolate;

### VipsInterpolateMethod ()

    void                (*VipsInterpolateMethod)            (VipsInterpolate *interpolate,
                                                             void *out,
                                                             VipsRegion *in,
                                                             double x,
                                                             double y);

An interpolation function. It should read source pixels from `in` with `VIPS_REGION_ADDR()`, it can look left and up from (x, y) by `window_offset` pixels and it can access pixels in a window of size `window_size`.

The interpolated value should be written to the pixel pointed to by `out`.

See also: VipsInterpolateClass.

`interpolate` : | the interpolator
`out` : | write the interpolated pixel here
`in` : | read source pixels from here
`x` : | interpolate value at this position
`y` : | interpolate value at this position

### VipsInterpolateClass

    typedef struct {
    	VipsObjectClass parent_class;

    	/* Write to pixel out(x,y), interpolating from in(x,y). The caller has
    	 * to set the regions up.
    	 */
    	VipsInterpolateMethod interpolate;

    	/* This interpolator needs a window this many pixels across and down.
    	 */
    	int (*get_window_size)( VipsInterpolate * );

    	/* Or just set this if you want a constant.
    	 */
    	int window_size;

    	/* Stencils are offset by this much. Default to window_size / 2 - 1
    	 * (centering) if get_window_offset is NULL and window_offset is -1.
    	 */
    	int (*get_window_offset)( VipsInterpolate * );
    	int window_offset;
    } VipsInterpolateClass;

The abstract base class for the various VIPS interpolation functions. Use "vips --list classes" to see all the interpolators available.

An interpolator consists of a function to perform the interpolation, plus some extra data fields which tell vips how to call the function and what data it needs.

`window_size` is the size of the window that the interpolator needs. For example, a bicubic interpolator needs to see a window of 4x4 pixels to be able to interpolate a value.

You can either have a function in `get_window_size` which returns the window that a specific interpolator needs, or you can leave `get_window_size` `NULL` and set a constant value in `window_size`.

`window_offset` is how much to offset the window up and left of (x, y). For example, a bicubic interpolator will want a `window_offset` of 1.

You can either have a function in `get_window_offset` which returns the offset that a specific interpolator needs, or you can leave `get_window_offset` `NULL` and set a constant value in `window_offset`.

You also need to set `nickname` and `description` in VipsObject.

See also: VipsInterpolateMethod, VipsObject, `vips_interpolate_bilinear_static()`.

VipsObjectClass `parent_class`; |
VipsInterpolateMethod `interpolate`; | the interpolation method
`get_window_size` () | return the size of the window needed by this method
int `window_size`; | or just set this for a constant window size
`get_window_offset` () | return the window offset for this method
int `window_offset`; | or just set this for a constant window offset

### vips_interpolate ()

    void                vips_interpolate                    (VipsInterpolate *interpolate,
                                                             void *out,
                                                             VipsRegion *in,
                                                             double x,
                                                             double y);

Look up the `interpolate` method in the class and call it. Use `vips_interpolate_get_method()` to get a direct pointer to the function and avoid the lookup overhead.

You need to set `in` and `out` up correctly.

`interpolate` : | interpolator to use
`out` : | write result here
`in` : | read source data from here
`x` : | interpolate value at this position
`y` : | interpolate value at this position

### vips_interpolate_get_method ()

    VipsInterpolateMethod vips_interpolate_get_method       (VipsInterpolate *interpolate);

Look up the `interpolate` method in the class and return it. Use this instead of `vips_interpolate()` to cache method dispatch.

`interpolate` : | interpolator to use
Returns : | a pointer to the interpolation function

### vips_interpolate_get_window_size ()

    int                 vips_interpolate_get_window_size    (VipsInterpolate *interpolate);

Look up an interpolators desired window size.

`interpolate` : | interpolator to use
Returns : | the interpolators required window size

### vips_interpolate_get_window_offset ()

    int                 vips_interpolate_get_window_offset  (VipsInterpolate *interpolate);

Look up an interpolators desired window offset.

`interpolate` : | interpolator to use
Returns : | the interpolators required window offset

### VIPS_TRANSFORM_SHIFT

    #define VIPS_TRANSFORM_SHIFT (6)

Many of the vips interpolators use fixed-point arithmetic for coordinate calculation. This is how many bits of precision they use.

### VIPS_TRANSFORM_SCALE

    #define VIPS_TRANSFORM_SCALE (1 << VIPS_TRANSFORM_SHIFT)

VIPS_TRANSFORM_SHIFT as a multiplicative constant.

### VIPS_INTERPOLATE_SHIFT

    #define VIPS_INTERPOLATE_SHIFT (12)

Many of the vips interpolators use fixed-point arithmetic for value calcualtion. This is how many bits of precision they use.

### VIPS_INTERPOLATE_SCALE

    #define VIPS_INTERPOLATE_SCALE (1 << VIPS_INTERPOLATE_SHIFT)

VIPS_INTERPOLATE_SHIFT as a multiplicative constant.

### vips_interpolate_nearest_static ()

    VipsInterpolate *   vips_interpolate_nearest_static     (void);

A convenience function that returns a nearest-neighbour interpolator you don't need to free.

Returns : | a nearest-neighbour interpolator. [transfer none]

### vips_interpolate_bilinear_static ()

    VipsInterpolate *   vips_interpolate_bilinear_static    (void);

A convenience function that returns a bilinear interpolator you don't need to free.

Returns : | a bilinear interpolator. [transfer none]

### vips_interpolate_new ()

    VipsInterpolate *   vips_interpolate_new                (const char *nickname);

Look up an interpolator from a nickname and make one. You need to free the result with `g_object_unref()` when you're done with it.

See also: `vips_type_find()`.

`nickname` : | nickname for interpolator
Returns : | an interpolator, or `NULL` on error.