![]() |
![]() |
![]() |
VIPS Reference Manual | ![]() |
---|---|---|---|---|
Top | Description | Object Hierarchy | Properties |
#include <vips/vips.h> VipsForeign; VipsForeignClass; enum VipsForeignFlags; VipsForeignLoad; VipsForeignLoadClass; VipsForeignSave; VipsForeignSaveClass; enum VipsForeignTiffCompression; enum VipsForeignTiffPredictor; enum VipsForeignTiffResunit; enum VipsSaveable; int vips_analyzeload (const char *filename
,VipsImage **out
,...
); int vips_csvload (const char *filename
,VipsImage **out
,...
); int vips_csvsave (VipsImage *in
,const char *filename
,...
); int vips_fitsload (const char *filename
,VipsImage **out
,...
); int vips_fitssave (VipsImage *in
,const char *filename
,...
); const char * vips_foreign_find_load (const char *filename
); const char * vips_foreign_find_load_options (const char *filename
); const char * vips_foreign_find_save (const char *filename
); const char * vips_foreign_find_save_options (const char *filename
); VipsForeignFlags vips_foreign_flags (const char *loader
,const char *filename
); gboolean vips_foreign_is_a (const char *loader
,const char *filename
); int vips_foreign_load (const char *filename
,VipsImage **out
,...
); int vips_foreign_load_options (const char *filename
,VipsImage **out
); void * vips_foreign_map (const char *base
,VipsSListMap2Fn fn
,void *a
,void *b
); void vips_foreign_operation_init (void
); int vips_foreign_save (VipsImage *in
,const char *filename
,...
); int vips_foreign_save_options (VipsImage *in
,const char *filename
); int vips_jpegload (const char *filename
,VipsImage **out
,...
); int vips_jpegload_buffer (void *buf
,size_t len
,VipsImage **out
,...
); int vips_jpegsave (VipsImage *in
,const char *filename
,...
); int vips_jpegsave_buffer (VipsImage *in
,void **buf
,size_t *len
,...
); int vips_jpegsave_mime (VipsImage *in
,...
); int vips_magickload (const char *filename
,VipsImage **out
,...
); int vips_matload (const char *filename
,VipsImage **out
,...
); int vips_openexrload (const char *filename
,VipsImage **out
,...
); int vips_openslideload (const char *filename
,VipsImage **out
,...
); int vips_pngload (const char *filename
,VipsImage **out
,...
); int vips_pngsave (VipsImage *in
,const char *filename
,...
); int vips_pngsave_buffer (VipsImage *in
,void **buf
,size_t *len
,...
); int vips_ppmload (const char *filename
,VipsImage **out
,...
); int vips_ppmsave (VipsImage *in
,const char *filename
,...
); int vips_radload (const char *filename
,VipsImage **out
,...
); int vips_radsave (VipsImage *in
,const char *filename
,...
); int vips_rawload (const char *filename
,VipsImage **out
,int width
,int height
,int bands
,...
); int vips_rawsave (VipsImage *in
,const char *filename
,...
); int vips_rawsave_fd (VipsImage *in
,int fd
,...
); int vips_tiffload (const char *filename
,VipsImage **out
,...
); int vips_tiffsave (VipsImage *in
,const char *filename
,...
);
GObject +----VipsObject +----VipsOperation +----VipsForeign +----VipsForeignLoad +----VipsForeignSave
GFlags +----VipsForeignFlags
GObject +----VipsObject +----VipsOperation +----VipsForeign +----VipsForeignLoad
GObject +----VipsObject +----VipsOperation +----VipsForeign +----VipsForeignSave
GEnum +----VipsForeignTiffCompression
GEnum +----VipsForeignTiffPredictor
GEnum +----VipsForeignTiffResunit
GEnum +----VipsSaveable
"disc" gboolean : Read / Write "flags" VipsForeignFlags : Read / Write "out" VipsImage* : Read / Write "sequential" gboolean : Read / Write "in" VipsImage* : Read / Write
This set of operations load and save images in a variety of formats.
The operations share a base class that offers a simple way to search for a
subclass of VipsForeign which can load a certain file (see
vips_foreign_find_load()
) or which could be used to save an image to a
certain file type (see vips_foreign_find_save()
). You can then run these
operations using vips_call()
and friends to perform the load or save.
A pair of convenience
functions, vips_foreign_load()
and vips_foreign_save()
, automate the
process, loading an image from a file or saving an image to a file. These
functions let you give load or save options as name - value pairs in the C
argument list. You can use vips_foreign_load_options()
and
vips_foreign_save_options()
to include options in the file name.
For example:
1 2 3 |
vips_foreign_save (my_image, "frank.tiff", "compression", VIPS_FOREIGN_TIFF_COMPRESSION_JPEG, NULL); |
Will save an image to the file "frank.tiff" in TIFF format (selected by the file name extension) with JPEG compression.
1 |
vips_foreign_save_options (my_image, "frank.tiff[compression=jpeg]"); |
Is the same thing, but with the option in the filename.
You can also invoke the operations directly, for example:
1 2 3 |
vips_tiffsave (my_image, "frank.anything", "compression", VIPS_FOREIGN_TIFF_COMPRESSION_JPEG, NULL); |
To add support for a new file format to vips, simply define a new subclass of VipsForeignLoad or VipsForeignSave.
If you define a new operation which is a subclass of VipsForeign, support
for it automatically appears in all VIPS user-interfaces. It will also be
transparently supported by vips_image_new_from_file()
and friends.
VIPS comes with VipsForeign for TIFF, JPEG, PNG, Analyze, PPM, OpenEXR, CSV, Matlab, Radiance, RAW, FITS and VIPS. It also includes import filters which can load with libMagick and with OpenSlide.
typedef struct { VipsOperationClass parent_class; /* Loop over formats in this order, default 0. We need this because * some formats can be read by several loaders (eg. tiff can be read * by the libMagick loader as well as by the tiff loader), and we want * to make sure the better loader comes first. */ int priority; /* Null-terminated list of recommended suffixes, eg. ".tif", ".tiff". * This can be used by both load and save, so it's in the base class. */ const char **suffs; } VipsForeignClass;
The suffix list is used to select a format to save a file in, and to pick a
loader if you don't define is_a()
.
You should also define nickname
and description
in VipsObject.
typedef enum { VIPS_FOREIGN_NONE = 0, /* No flags set */ VIPS_FOREIGN_PARTIAL = 1, /* Lazy read OK (eg. tiled tiff) */ VIPS_FOREIGN_SEQUENTIAL = 2, /* Top-to-bottom lazy read OK */ VIPS_FOREIGN_BIGENDIAN = 4, /* Most-significant byte first */ VIPS_FOREIGN_ALL = 7 /* All flags set */ } VipsForeignFlags;
Some hints about the image loader.
VIPS_FOREIGN_PARTIAL
means that the image can be read directly from the
file without needing to be unpacked to a temporary image first.
VIPS_FOREIGN_SEQUENTIAL
means that the loader supports lazy reading, but
only top-to-bottom (sequential) access. Formats like PNG can read sets of
scanlines, for example, but only in order.
If neither PARTIAL or SEQUENTIAL is set, the loader only supports whole image read. Setting both PARTIAL and SEQUENTIAL is an error.
VIPS_FOREIGN_BIGENDIAN
means that image pixels are most-significant byte
first. Depending on the native byte order of the host machine, you may
need to swap bytes. See copy_swap()
.
typedef struct { /* The image we generate. This must be set by ->header(). */ VipsImage *out; /* The behind-the-scenes real image we decompress to. This can be a * disc foreign or a memory buffer. This must be set by ->load(). */ VipsImage *real; } VipsForeignLoad;
must set at least the header fields of header()
out
.
, if defined,
must load the pixels to laod()
real
.
typedef struct { VipsForeignClass parent_class; /* Is a file in this format. * * This function should return %TRUE if the file contains an image of * this type. If you don't define this function, #VipsForeignLoad * will use @suffs instead. */ gboolean (*is_a)( const char * ); /* Get the flags from a filename. * * This function should examine the file and return a set * of flags. If you don't define it, vips will default to 0 (no flags * set). * * This operation is necessary for vips7 compatibility. */ VipsForeignFlags (*get_flags_filename)( const char * ); /* Get the flags for this load operation. Images can be loaded from * (for example) memory areas rather than files, so you can't just use * @get_flags_filename(). */ VipsForeignFlags (*get_flags)( VipsForeignLoad * ); /* Do the minimum read we can. * * Set the header fields in @out from @filename. If you can read the * whole image as well with no performance cost (as with vipsload), * or if your loader does not support reading only the header, read * the entire image in this method and leave @load() NULL. * * @header() needs to set the dhint on the image .. otherwise you get * the default SMALLTILE. * * Return 0 for success, -1 for error, setting * vips_error(). */ int (*header)( VipsForeignLoad * ); /* Read the whole image into @real. The pixels will get copied to @out * later. * * You can omit this method if you define a @header() method which * loads the whole file. * * Return 0 for success, -1 for error, setting * vips_error(). */ int (*load)( VipsForeignLoad * ); } VipsForeignLoadClass;
Add a new loader to VIPS by subclassing VipsForeignLoad. Subclasses need to
implement at least
.
header()
As a complete example, here's the code for the PNG loader, minus the actual calls to libpng.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
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 ) { } |
typedef struct { /* The image we are to save, as supplied by our caller. */ VipsImage *in; /* @in converted to a saveable format (eg. 8-bit RGB) according to the * instructions you give in the class fields below. * * This is the image you should actually write to the output. */ VipsImage *ready; } VipsForeignSave;
typedef struct { VipsForeignClass parent_class; /* How this format treats bands. * * @saveable describes the bands that your saver can handle. For * example, PPM images can have 1 or 3 bands (mono or RGB), so it * uses #VIPS_SAVEABLE_RGB. */ VipsSaveable saveable; /* How this format treats band formats. * * @format_table describes the band formats that your saver can * handle. For each of the 10 #VipsBandFormat values, the array * should give the format your saver will accept. */ VipsBandFormat *format_table; /* The set of coding types this format can save. For example, jpeg can * only save NONE, so has NONE TRUE and RAD and LABQ FALSE. * * Default NONE TRUE, RAD and LABQ FALSE. */ gboolean coding[VIPS_CODING_LAST]; } VipsForeignSaveClass;
Call your saver in the class'
method after chaining up. The
prepared image should be ready for you to save in build()
ready
.
As a complete example, here's the code for the CSV saver, minus the calls to the actual save routines.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
typedef struct _VipsForeignSaveCsv { VipsForeignSave parent_object; char *filename; const char *separator; } VipsForeignSaveCsv; typedef VipsForeignSaveClass VipsForeignSaveCsvClass; G_DEFINE_TYPE( VipsForeignSaveCsv, vips_foreign_save_csv, VIPS_TYPE_FOREIGN_SAVE ); static int vips_foreign_save_csv_build( VipsObject *object ) { VipsForeignSave *save = (VipsForeignSave *) object; VipsForeignSaveCsv *csv = (VipsForeignSaveCsv *) object; if( VIPS_OBJECT_CLASS( vips_foreign_save_csv_parent_class )-> build( object ) ) return( -1 ); if( vips__csv_write( save->ready, csv->filename, csv->separator ) ) return( -1 ); return( 0 ); } #define UC VIPS_FORMAT_UCHAR #define C VIPS_FORMAT_CHAR #define US VIPS_FORMAT_USHORT #define S VIPS_FORMAT_SHORT #define UI VIPS_FORMAT_UINT #define I VIPS_FORMAT_INT #define F VIPS_FORMAT_FLOAT #define X VIPS_FORMAT_COMPLEX #define D VIPS_FORMAT_DOUBLE #define DX VIPS_FORMAT_DPCOMPLEX static int bandfmt_csv[10] = { // UC C US S UI I F X D DX UC, C, US, S, UI, I, F, X, D, DX }; static void vips_foreign_save_csv_class_init( VipsForeignSaveCsvClass *class ) { GObjectClass *gobject_class = G_OBJECT_CLASS( class ); VipsObjectClass *object_class = (VipsObjectClass *) class; VipsForeignClass *foreign_class = (VipsForeignClass *) class; VipsForeignSaveClass *save_class = (VipsForeignSaveClass *) class; gobject_class->set_property = vips_object_set_property; gobject_class->get_property = vips_object_get_property; object_class->nickname = "csvsave"; object_class->description = _( "save image to csv file" ); object_class->build = vips_foreign_save_csv_build; foreign_class->suffs = vips__foreign_csv_suffs; save_class->saveable = VIPS_SAVEABLE_MONO; save_class->format_table = bandfmt_csv; VIPS_ARG_STRING( class, "filename", 1, _( "Filename" ), _( "Filename to save to" ), VIPS_ARGUMENT_REQUIRED_INPUT, G_STRUCT_OFFSET( VipsForeignSaveCsv, filename ), NULL ); VIPS_ARG_STRING( class, "separator", 13, _( "Separator" ), _( "Separator characters" ), VIPS_ARGUMENT_OPTIONAL_INPUT, G_STRUCT_OFFSET( VipsForeignSaveCsv, separator ), "\t" ); } static void vips_foreign_save_csv_init( VipsForeignSaveCsv *csv ) { csv->separator = g_strdup( "\t" ); } |
typedef enum { VIPS_FOREIGN_TIFF_COMPRESSION_NONE, VIPS_FOREIGN_TIFF_COMPRESSION_JPEG, VIPS_FOREIGN_TIFF_COMPRESSION_DEFLATE, VIPS_FOREIGN_TIFF_COMPRESSION_PACKBITS, VIPS_FOREIGN_TIFF_COMPRESSION_CCITTFAX4, VIPS_FOREIGN_TIFF_COMPRESSION_LZW, VIPS_FOREIGN_TIFF_COMPRESSION_LAST } VipsForeignTiffCompression;
The compression types supported by the tiff writer.
Use Q
to set the jpeg compression level, default 75.
Use prediction
to set the lzw or deflate prediction, default none.
no compression | |
jpeg compression | |
deflate (zip) compression | |
packbits compression | |
fax4 compression | |
LZW compression | |
typedef enum { VIPS_FOREIGN_TIFF_PREDICTOR_NONE = 1, VIPS_FOREIGN_TIFF_PREDICTOR_HORIZONTAL = 2, VIPS_FOREIGN_TIFF_PREDICTOR_FLOAT = 3, VIPS_FOREIGN_TIFF_PREDICTOR_LAST } VipsForeignTiffPredictor;
The predictor can help deflate and lzw compression. The values are fixed by the tiff library.
typedef enum { VIPS_FOREIGN_TIFF_RESUNIT_CM, VIPS_FOREIGN_TIFF_RESUNIT_INCH, VIPS_FOREIGN_TIFF_RESUNIT_LAST } VipsForeignTiffResunit;
Use inches or centimeters as the resolution unit for a tiff file.
typedef enum { VIPS_SAVEABLE_MONO, VIPS_SAVEABLE_RGB, VIPS_SAVEABLE_RGBA, VIPS_SAVEABLE_RGB_CMYK, VIPS_SAVEABLE_ANY, VIPS_SAVEABLE_LAST } VipsSaveable;
See also: VipsForeignSave.
int vips_analyzeload (const char *filename
,VipsImage **out
,...
);
Load an Analyze 6.0 file. If filename
is "fred.img", this will look for
an image header called "fred.hdr" and pixel data in "fred.img". You can
also load "fred" or "fred.hdr".
Images are loaded lazilly and byte-swapped, if necessary. The Analyze metadata is read and attached.
See also: vips_image_new_from_file()
.
|
file to load |
|
decompressed image |
|
NULL -terminated list of optional named arguments |
Returns : |
0 on success, -1 on error. |
int vips_csvload (const char *filename
,VipsImage **out
,...
);
Optional arguments:
skip
: skip this many lines at start of file
lines
: read this many lines from file
whitespace
: set of whitespace characters
separator
: set of separator characters
Load a CSV (comma-separated values) file. The output image is always 1 band (monochrome), VIPS_FORMAT_DOUBLE.
Items in lines can be either floating point numbers in the C locale, or strings enclosed in double-quotes ("), or empty. You can use a backslash (\) within the quotes to escape special characters, such as quote marks.
The reader is deliberately rather fussy: it will fail if there are any short lines, or if the file is too short. It will ignore lines that are too long.
skip
sets the number of lines to skip at the start of the file.
Default zero.
lines
sets the number of lines to read from the file. Default -1,
meaning read all lines to end of file.
whitespace
sets the skippable whitespace characters.
Default space.
Whitespace characters are always run together.
separator
sets the characters that separate fields.
Default ;,tab. Separators are never run together.
See also: vips_image_new_from_file()
.
|
file to load |
|
output image |
|
NULL -terminated list of optional named arguments |
Returns : |
0 on success, -1 on error. |
int vips_csvsave (VipsImage *in
,const char *filename
,...
);
Optional arguments:
separator
: separator string
Writes the pixels in in
to the filename
as CSV (comma-separated values).
The image is written
one line of text per scanline. Complex numbers are written as
"(real,imaginary)" and will need extra parsing I guess. Only the first band
is written.
separator
gives the string to use to separate numbers in the output.
The default is "\\t" (tab).
See also: vips_image_write_file()
.
|
image to save |
|
file to write to |
|
NULL -terminated list of optional named arguments |
Returns : |
0 on success, -1 on error. |
int vips_fitsload (const char *filename
,VipsImage **out
,...
);
Read a FITS image file into a VIPS image.
See also: vips_image_new_from_file()
.
|
file to load |
|
decompressed image |
|
NULL -terminated list of optional named arguments |
Returns : |
0 on success, -1 on error. |
int vips_fitssave (VipsImage *in
,const char *filename
,...
);
Write a VIPS image to a file as FITS.
See also: vips_image_write_file()
.
|
image to save |
|
file to write to |
|
NULL -terminated list of optional named arguments |
Returns : |
0 on success, -1 on error. |
const char * vips_foreign_find_load (const char *filename
);
Searches for an operation you could use to load filename
.
See also: vips_foreign_read()
.
|
file to find a loader for |
Returns : |
the name of an operation on success, NULL on error |
const char * vips_foreign_find_load_options (const char *filename
);
Searches for an operation you could use to load filename
.
Arguments to the loader may be embedded in the filename using the usual syntax.
See also: vips_foreign_load()
.
|
file to find a loader for |
Returns : |
0 on success, -1 on error |
const char * vips_foreign_find_save (const char *filename
);
Searches for an operation you could use to write to filename
.
filename
may not contain embedded options. See
vips_foreign_find_save_options()
if your filename may have options in.
See also: vips_foreign_write()
.
|
name to find a saver for |
Returns : |
the name of an operation on success, NULL on error |
const char * vips_foreign_find_save_options (const char *filename
);
Searches for an operation you could use to write to filename
.
filename
may contain embedded options. See
vips_foreign_find_save()
if your filename does not options in.
See also: vips_foreign_write()
.
|
name to find a saver for |
Returns : |
0 on success, -1 on error |
VipsForeignFlags vips_foreign_flags (const char *loader
,const char *filename
);
Return the flags for filename
using loader
.
loader
is something like "tiffload" or "VipsForeignLoadTiff".
|
name of loader to use for test |
|
file to test |
Returns : |
the flags for filename . |
gboolean vips_foreign_is_a (const char *loader
,const char *filename
);
Return TRUE
if filename
can be loaded by loader
. loader
is something
like "tiffload" or "VipsForeignLoadTiff".
|
name of loader to use for test |
|
file to test |
Returns : |
TRUE if filename can be loaded by loader . |
int vips_foreign_load (const char *filename
,VipsImage **out
,...
);
Loads filename
into out
using the loader recommended by
vips_foreign_find_load()
.
See also: vips_foreign_save()
, vips_foreign_load_options()
.
|
file to load |
|
output image |
|
NULL -terminated list of optional named arguments |
Returns : |
0 on success, -1 on error |
int vips_foreign_load_options (const char *filename
,VipsImage **out
);
Loads filename
into out
using the loader recommended by
vips_foreign_find_load()
.
Arguments to the loader may be embedded in the filename using the usual syntax.
See also: vips_foreign_load()
.
|
file to load |
|
output image |
Returns : |
0 on success, -1 on error |
void * vips_foreign_map (const char *base
,VipsSListMap2Fn fn
,void *a
,void *b
);
Apply a function to every VipsForeignClass that VIPS knows about. Foreigns are presented to the function in priority order.
Like all VIPS map functions, if fn
returns NULL
, iteration continues. If
it returns non-NULL
, iteration terminates and that value is returned. The
map function returns NULL
if all calls return NULL
.
See also: vips_slist_map()
.
|
base class to search below (eg. "VipsForeignLoad") |
|
function to apply to each VipsForeignClass. [scope call] |
|
user data |
|
user data |
Returns : |
the result of iteration. [transfer none] |
int vips_foreign_save (VipsImage *in
,const char *filename
,...
);
Saves in
to filename
using the saver recommended by
vips_foreign_find_save()
. Options are not in filename
but must be given
as a NULL-terminated list of name-value pairs.
See also: vips_foreign_load()
.
|
image to write |
|
file to write to |
|
NULL -terminated list of optional named arguments |
Returns : |
0 on success, -1 on error |
int vips_foreign_save_options (VipsImage *in
,const char *filename
);
Saves in
to filename
using the saver recommended by
vips_foreign_find_save()
.
Arguments to the saver may be embedded in the filename using the usual syntax.
See also: vips_foreign_save()
.
|
image to write |
|
file to write to |
Returns : |
0 on success, -1 on error |
int vips_jpegload (const char *filename
,VipsImage **out
,...
);
Optional arguments:
shrink
: shrink by this much on load
fail
: fail on warnings
Read a JPEG file into a VIPS image. It can read most 8-bit JPEG images, including CMYK and YCbCr.
shrink
means shrink by this integer factor during load. Possible values
are 1, 2, 4 and 8. Shrinking during read is very much faster than
decompressing the whole image and then shrinking later.
Setting fail
to true makes the JPEG reader fail on any warnings.
This can be useful for detecting truncated files, for example. Normally
reading these produces a warning, but no fatal error.
Example:
1 2 3 4 |
vips_jpegload( "fred.jpg", &out, "shrink", 8, "fail", TRUE, NULL ); |
Any embedded ICC profiles are ignored: you always just get the RGB from
the file. Instead, the embedded profile will be attached to the image as
metadata. You need to use something like im_icc_import()
to get CIE
values from the file. Any EXIF data is also attached as VIPS metadata.
The int metadata item "jpeg-multiscan" is set to the result of
jpeg_has_multiple_scans()
. Interlaced jpeg images need a large amount of
memory to load, so this field gives callers a chance to handle these
images differently.
The EXIF thumbnail, if present, is attached to the image as
"jpeg-thumbnail-data". See vips_image_get_blob()
.
This function only reads the image header and does not decompress any pixel data. Decompression only occurs when pixels are accessed by some other function.
See also: vips_jpegload_buffer()
, vips_image_new_from_file()
.
|
file to load |
|
decompressed image |
|
NULL -terminated list of optional named arguments |
Returns : |
0 on success, -1 on error. |
int vips_jpegload_buffer (void *buf
,size_t len
,VipsImage **out
,...
);
Read a JPEG-formatted memory block into a VIPS image. It can read most 8-bit JPEG images, including CMYK and YCbCr.
This function is handy for processing JPEG image thumbnails.
Caution: on return only the header will have been read, the pixel data is
not decompressed until the first pixel is read. Therefore you must not free
buf
until you have read pixel data from out
.
See also: vips_jpegload()
.
|
memory area to load |
|
size of memory area |
|
image to write |
|
NULL -terminated list of optional named arguments |
Returns : |
0 on success, -1 on error. |
int vips_jpegsave (VipsImage *in
,const char *filename
,...
);
Optional arguments:
Q
: quality factor
profile
: attach this ICC profile
Write a VIPS image to a file as JPEG.
Use Q
to set the JPEG compression factor. Default 75.
Use profile
to give the filename of a profile to be em,bedded in the JPEG.
This does not affect the pixels which are written, just the way
they are tagged. You can use the special string "none" to mean
"don't attach a profile".
If no profile is specified and the VIPS header contains an ICC profile named VIPS_META_ICC_NAME ("icc-profile-data"), the profile from the VIPS header will be attached.
The image is automatically converted to RGB, Monochrome or CMYK before saving. Any metadata attached to the image is saved as EXIF, if possible.
See also: vips_jpegsave_buffer()
, vips_image_write_file()
.
|
image to save |
|
file to write to |
|
NULL -terminated list of optional named arguments |
Returns : |
0 on success, -1 on error. |
int vips_jpegsave_buffer (VipsImage *in
,void **buf
,size_t *len
,...
);
Optional arguments:
Q
: JPEG quality factor
profile
: attach this ICC profile
As vips_jpegsave()
, but save to a memory buffer.
The address of the buffer is returned in obuf
, the length of the buffer in
olen
. You are responsible for freeing the buffer with g_free()
when you
are done with it.
See also: vips_jpegsave()
, vips_image_write_to_file()
.
|
image to save |
|
return output buffer here |
|
return output length here |
|
NULL -terminated list of optional named arguments |
Returns : |
0 on success, -1 on error. |
int vips_jpegsave_mime (VipsImage *in
,...
);
Optional arguments:
Q
: JPEG quality factor
profile
: attach this ICC profile
As vips_jpegsave()
, but save as a mime jpeg on stdout.
See also: vips_jpegsave()
, vips_image_write_to_file()
.
|
image to save |
|
NULL -terminated list of optional named arguments |
Returns : |
0 on success, -1 on error. |
int vips_magickload (const char *filename
,VipsImage **out
,...
);
Read in an image using libMagick, the ImageMagick library. This library can read more than 80 file formats, including SVG, BMP, EPS, DICOM and many others. The reader can handle any ImageMagick image, including the float and double formats. It will work with any quantum size, including HDR. Any metadata attached to the libMagick image is copied on to the VIPS image.
The reader should also work with most versions of GraphicsMagick. See the "--with-magickpackage" configure option.
See also: vips_image_new_from_file()
.
|
file to load |
|
decompressed image |
|
NULL -terminated list of optional named arguments |
Returns : |
0 on success, -1 on error. |
int vips_matload (const char *filename
,VipsImage **out
,...
);
Read a Matlab save file into a VIPS image.
This operation searches the save file for the first array variable with between 1 and 3 dimensions and loads it as an image. It will not handle complex images. It does not handle sparse matrices.
See also: vips_image_new_from_file()
.
|
file to load |
|
output image |
|
NULL -terminated list of optional named arguments |
Returns : |
0 on success, -1 on error. |
int vips_openexrload (const char *filename
,VipsImage **out
,...
);
Read a OpenEXR file into a VIPS image.
The reader can handle scanline and tiled OpenEXR images. It can't handle OpenEXR colour management, image attributes, many pixel formats, anything other than RGBA.
This reader uses the rather limited OpenEXR C API. It should really be redone in C++.
See also: vips_image_new_from_file()
.
|
file to load |
|
decompressed image |
|
NULL -terminated list of optional named arguments |
Returns : |
0 on success, -1 on error. |
int vips_openslideload (const char *filename
,VipsImage **out
,...
);
Optional arguments:
layer
: load this layer
associated
: load this associated image
Read a virtual slide supported by the OpenSlide library into a VIPS image. OpenSlide supports images in Aperio, Hamamatsu VMS, Hamamatsu VMU, MIRAX, and Trestle formats.
To facilitate zooming, virtual slide formats include multiple scaled-down
versions of the high-resolution image. These are typically called
"levels", though OpenSlide and im_openslide2vips()
call them "layers".
By default, vips_openslideload()
reads the highest-resolution layer
(layer 0). Set layer
to the layer number you want.
In addition to the slide image itself, virtual slide formats sometimes
include additional images, such as a scan of the slide's barcode.
OpenSlide calls these "associated images". To read an associated image,
set associated
to the image's name.
A slide's associated images are listed in the
"slide-associated-images" metadata item.
The output of this operator is in pre-multipled ARGB format. Use
im_argb2rgba()
to decode to png-style RGBA.
See also: vips_image_new_from_file()
.
|
file to load |
|
decompressed image |
|
NULL -terminated list of optional named arguments |
Returns : |
0 on success, -1 on error. |
int vips_pngload (const char *filename
,VipsImage **out
,...
);
Optional arguments:
sequential
: sequential read only
Read a PNG file into a VIPS image. It can read all png images, including 8- and 16-bit images, 1 and 3 channel, with and without an alpha channel.
Setting sequential
to TRUE
means you promise to only demand tiles from
this image top-top-bottom, ie. to read sequentially. This means the png
loader can read directly from the image without having to generate a
random-access intermediate. This can save a lot of time and memory for
large images, but limits the sorts of operation you can perform. It's
useful for things like generating thumbnails.
There is no support for embedded ICC profiles.
See also: vips_image_new_from_file()
.
|
file to load |
|
decompressed image |
|
NULL -terminated list of optional named arguments |
Returns : |
0 on success, -1 on error. |
int vips_pngsave (VipsImage *in
,const char *filename
,...
);
Optional arguments:
compression
: compression level
interlace
: interlace image
Write a VIPS image to a file as PNG.
compression
means compress with this much effort (0 - 9). Default 6.
Set interlace
to TRUE
to interlace the image with ADAM7
interlacing. Beware
than an interlaced PNG can be up to 7 times slower to write than a
non-interlaced image.
There is no support for attaching ICC profiles to PNG images.
The image is automatically converted to RGB, RGBA, Monochrome or Mono + alpha before saving. Images with more than one byte per band element are saved as 16-bit PNG, others are saved as 8-bit PNG.
See also: vips_image_new_from_file()
.
|
image to save |
|
file to write to |
|
NULL -terminated list of optional named arguments |
Returns : |
0 on success, -1 on error. |
int vips_pngsave_buffer (VipsImage *in
,void **buf
,size_t *len
,...
);
Optional arguments:
compression
: compression level
interlace
: interlace image
As vips_pngsave()
, but save to a memory buffer.
The address of the buffer is returned in obuf
, the length of the buffer in
olen
. You are responsible for freeing the buffer with g_free()
when you
are done with it.
See also: vips_pngsave()
, vips_image_write_to_file()
.
|
image to save |
|
return output buffer here |
|
return output length here |
|
NULL -terminated list of optional named arguments |
Returns : |
0 on success, -1 on error. |
int vips_ppmload (const char *filename
,VipsImage **out
,...
);
Read a PPM/PBM/PGM/PFM file into a VIPS image.
It can read 1, 8, 16 and 32 bit images, colour or monochrome, stored in binary or in ASCII. One bit images become 8 bit VIPS images, with 0 and 255 for 0 and 1.
See also: vips_image_new_from_file()
.
|
file to load |
|
output image |
|
NULL -terminated list of optional named arguments |
Returns : |
0 on success, -1 on error. |
int vips_ppmsave (VipsImage *in
,const char *filename
,...
);
Optional arguments:
ascii
: save as ASCII rather than binary
Write a VIPS image to a file as PPM. It can write 8, 16 or 32 bit unsigned integer images, float images, colour or monochrome, stored as binary or ASCII. Integer images of more than 8 bits can only be stored in ASCII.
When writing float (PFM) images the scale factor is set from the "pfm-scale" metadata.
Set ascii
to TRUE
to write as human-readable ASCII. Normally data is
written in binary.
The storage format is indicated by a filename extension. Use one of .pbm, .pgm, .ppm, .pfm.
See also: vips_image_write_file()
.
|
image to save |
|
file to write to |
|
NULL -terminated list of optional named arguments |
Returns : |
0 on success, -1 on error. |
int vips_radload (const char *filename
,VipsImage **out
,...
);
Read a Radiance (HDR) file into a VIPS image.
Radiance files are read as VIPS_CODING_RAD. They have one byte for each of
red, green and blue, and one byte of shared exponent. Some operations (like
vips_extract_area()
) can work directly with images in this format, but
mmany (all the arithmetic operations, for example) will not. Unpack
VIPS_CODING_RAD images to 3 band float with im_rad2float()
if you want to do
arithmetic on them.
This operation ignores some header fields, like VIEW and DATE. It will not rotate/flip as the FORMAT string asks.
Sections of this reader from Greg Ward and Radiance with kind permission.
See also: vips_image_new_from_file()
.
|
file to load |
|
output image |
|
NULL -terminated list of optional named arguments |
Returns : |
0 on success, -1 on error. |
int vips_radsave (VipsImage *in
,const char *filename
,...
);
Write a VIPS image in Radiance (HDR) format.
Sections of this reader from Greg Ward and Radiance with kind permission.
See also: vips_image_write_file()
.
|
image to save |
|
file to write to |
|
NULL -terminated list of optional named arguments |
Returns : |
0 on success, -1 on error. |
int vips_rawload (const char *filename
,VipsImage **out
,int width
,int height
,int bands
,...
);
Optional arguments:
width
: width of image in pixels
height
: height of image in pixels
bands
: number of image bands
offset
: offset in bytes from start of file
This operation mmaps the file, setting out
so that access to that
image will read from the file.
Use functions like vips_copy()
to set the pixel type, byte ordering
and so on.
See also: vips_image_new_from_file()
.
|
file to load |
|
output image |
|
NULL -terminated list of optional named arguments |
Returns : |
0 on success, -1 on error. |
int vips_rawsave (VipsImage *in
,const char *filename
,...
);
Writes the pixels in in
to the file filename
with no header or other
metadata.
See also: vips_image_write_file()
.
|
image to save |
|
file to write to |
|
NULL -terminated list of optional named arguments |
Returns : |
0 on success, -1 on error. |
int vips_rawsave_fd (VipsImage *in
,int fd
,...
);
Writes the pixels in in
to the fd
with no header or other
metadata. Handy for implementing other savers.
See also: vips_rawsave()
.
|
image to save |
|
file to write to |
|
NULL -terminated list of optional named arguments |
Returns : |
0 on success, -1 on error. |
int vips_tiffload (const char *filename
,VipsImage **out
,...
);
Optional arguments:
page
: load this page
Read a TIFF file into a VIPS image. It is a full baseline TIFF 6 reader, with extensions for tiled images, multipage images, LAB colour space, pyramidal images and JPEG compression. including CMYK and YCbCr.
page
means load this page from the file. By default the first page (page
0) is read.
Any ICC profile is read and attached to the VIPS image.
See also: vips_image_new_from_file()
.
|
file to load |
|
decompressed image |
|
NULL -terminated list of optional named arguments |
Returns : |
0 on success, -1 on error. |
int vips_tiffsave (VipsImage *in
,const char *filename
,...
);
Optional arguments:
compression
; use this compression scheme
Q
: quality factor
predictor
; compress with this prediction
profile
: attach this ICC profile
tile
; set TRUE
to write a tiled tiff
tile_width
; set tile size
tile_height
; set tile size
pyramid
; set TRUE
to write an image pyramid
squash
; squash 8-bit images down to 1 bit
resunit
; use pixels per inch or cm for the resolution
xres
; horizontal resolution
yres
; vertical resolution
bigtiff
; write a BigTiff file
Write a VIPS image to a file as TIFF.
Use compression
to set the tiff compression. Currently jpeg, packbits,
fax4, lzw, none and deflate are supported. The default is no compression.
JPEG compression is a good lossy compressor for photographs, packbits is
good for 1-bit images, and deflate is the best lossless compression TIFF
can do. LZW has patent problems and is no longer recommended.
Use Q
to set the JPEG compression factor. Default 75.
Use predictor
to set the predictor for lzw and deflate compression.
Predictor is not set by default. There are three predictor values recognised at the moment (2007, July): 1 is no prediction, 2 is a horizontal differencing and 3 is a floating point predictor. Refer to the libtiff specifications for further discussion of various predictors. In short, predictor helps to better compress image, especially in case of digital photos or scanned images and bit depths > 8. Try it to find whether it works for your images.
Use profile
to give the filename of a profile to be embedded in the TIFF.
This does not affect the pixels which are written, just the way
they are tagged. You can use the special string "none" to mean
"don't attach a profile".
If no profile is specified and the VIPS header contains an ICC profile named VIPS_META_ICC_NAME ("icc-profile-data"), the profile from the VIPS header will be attached.
Set tile
to TRUE to write a tiled tiff. By default tiff are written in
strips. Use tile_width
and tile_height
to set the tile size. The defaiult
is 128 by 128.
Set pyramid
to write the image as a set of images, one per page, of
decreasing size.
Set squash
to make 8-bit uchar images write as 1-bit TIFFs with zero
pixels written as 0 and non-zero as 1.
Use resunit
to override the default resolution unit.
The default
resolution unit is taken from the header field "resolution-unit"
(VIPS_META_RESOLUTION_UNIT in C). If this field is not set, then
VIPS defaults to cm.
Use xres
and yres
to override the default horizontal and vertical
resolutions. By default these values are taken from the VIPS image header.
Set bigtiff
to attempt to write a bigtiff.
Bigtiff is a variant of the TIFF
format that allows more than 4GB in a file.
See also: vips_tiffload()
, vips_image_write_file()
.
|
image to save |
|
file to write to |
|
NULL -terminated list of optional named arguments |
Returns : |
0 on success, -1 on error. |
"sequential"
property"sequential" gboolean : Read / Write
Sequential read only.
Default value: FALSE