Top |
#define | VIPS_META_EXIF_NAME |
#define | VIPS_META_XMP_NAME |
#define | VIPS_META_IPCT_NAME |
#define | VIPS_META_ICC_NAME |
#define | VIPS_META_XML |
#define | VIPS_META_RESOLUTION_UNIT |
#define | VIPS_META_LOADER |
These functions let you get at image header data (including metadata) in a uniform way.
Use vips_image_get_typeof()
to test for the
existance and GType
of a header field.
You can attach arbitrary metadata to images. Metadata is copied as images are processed, so all images which used this image as input, directly or indirectly, will have this same bit of metadata attached to them. Copying is implemented with reference-counted pointers, so it is efficient, even for large items of data. This does however mean that metadata items need to be immutable. Metadata is handy for things like ICC profiles or EXIF data.
Various convenience functions (eg. vips_image_set_int()
) let you easily
attach
simple types like
numbers, strings and memory blocks to images. Use vips_image_map()
to loop
over an image's fields, including all metadata.
Items of metadata are identified by strings. Some strings are reserved, for example the ICC profile for an image is known by convention as "icc-profile-data".
If you save an image in VIPS format, all metadata (with a restriction, see
below) is automatically saved for you in a block of XML at the end of the
file. When you load a VIPS image, the metadata is restored. You can use the
vipsedit
command-line tool to extract or replace this block of XML.
VIPS metadata is based on GValue
. See the docs for that system if you want
to do fancy stuff such as defining a new metadata type.
VIPS defines a new GValue
called vips_save_string
, a variety of string,
see vips_value_set_save_string()
.
If your GValue
can be transformed to vips_save_string
, it will be
saved and loaded to and from VIPS files for you.
VIPS provides a couple of base classes which implement reference-counted areas of memory. If you base your metadata on one of these types, it can be copied between images efficiently.
VipsInterpretation
vips_image_get_interpretation (const VipsImage *image
);
Return the VipsInterpretation set in the image header.
Use vips_image_guess_interpretation()
if you want a sanity-checked value.
VipsInterpretation
vips_image_guess_interpretation (const VipsImage *image
);
Return the VipsInterpretation for an image, guessing a sane value if the set value looks crazy.
const char *
vips_image_get_mode (const VipsImage *image
);
Image modes are things like "t"
, meaning a memory buffer, and "p"
meaning a delayed computation.
double
vips_image_get_scale (const VipsImage *image
);
Matrix images can have an optional scale
field for use by integer
convolution.
double
vips_image_get_offset (const VipsImage *image
);
Matrix images can have an optional offset
field for use by integer
convolution.
const void *
vips_image_get_data (VipsImage *image
);
Return a pointer to the image's pixel data, if possible. This can involve allocating large amounts of memory and performing a long computation. Image pixels are laid out in band-packed rows.
See also: vips_image_wio_input()
.
void vips_image_init_fields (VipsImage *image
,int xsize
,int ysize
,int bands
,VipsBandFormat format
,VipsCoding coding
,VipsInterpretation interpretation
,double xres
,double yres
);
A convenience function to set the header fields after creating an image.
Normally you copy the fields from your input images with
vips_image_pipelinev()
and then make
any adjustments you need, but if you are creating an image from scratch,
for example vips_black()
or vips_jpegload()
, you do need to set all the
fields yourself.
See also: vips_image_pipelinev()
.
void vips_image_set (VipsImage *image
,const char *field
,GValue *value
);
Set a piece of metadata on image
. Any old metadata with that name is
destroyed. The GValue
is copied into the image, so you need to unset the
value when you're done with it.
For example, to set an integer on an image (though you would use the
convenience function vips_image_set_int()
in practice), you would do:
GValue value = { 0 }; g_value_init (&value, G_TYPE_INT); g_value_set_int (&value, 42); vips_image_set (image, field, &value); g_value_unset (&value);
See also: vips_image_get()
.
int vips_image_get (const VipsImage *image
,const char *field
,GValue *value_copy
);
Fill value_copy
with a copy of the header field. value_copy
must be zeroed
but uninitialised.
This will return -1 and add a message to the error buffer if the field
does not exist. Use vips_image_get_typeof()
to test for the
existence of a field first if you are not certain it will be there.
For example, to read a double from an image (though of course you would use
vips_image_get_double()
in practice):
GValue value = { 0 }; double d; if (vips_image_get (image, field, &value)) return -1; if (G_VALUE_TYPE (&value) != G_TYPE_DOUBLE) { vips_error( "mydomain", _("field \"%s\" is of type %s, not double"), field, g_type_name (G_VALUE_TYPE (&value))); g_value_unset (&value); return -1; } d = g_value_get_double (&value); g_value_unset (&value);
See also: vips_image_get_typeof()
, vips_image_get_double()
.
int vips_image_get_as_string (const VipsImage *image
,const char *field
,char **out
);
Gets out
from im
under the name field
.
This function will read any field, returning it as a printable string.
You need to free the string with g_free()
when you are done with it.
See also: vips_image_get()
, vips_image_get_typeof()
.
GType vips_image_get_typeof (const VipsImage *image
,const char *field
);
Read the GType
for a header field. Returns zero if there is no
field of that name.
See also: vips_image_get()
.
gboolean vips_image_remove (VipsImage *image
,const char *field
);
Find and remove an item of metadata. Return FALSE
if no metadata of that
name was found.
See also: vips_image_set()
, vips_image_get_typeof()
.
void * (*VipsImageMapFn) (VipsImage *image
,const char *field
,GValue *value
,void *a
);
void * vips_image_map (VipsImage *image
,VipsImageMapFn fn
,void *a
);
This function calls fn
for every header field, including every item of
metadata.
Like all _map functions, the user function should return NULL
to continue
iteration, or a non-NULL
pointer to indicate early termination.
See also: vips_image_get_typeof()
, vips_image_get()
.
void vips_image_set_area (VipsImage *image
,const char *field
,VipsCallbackFn free_fn
,void *data
);
Attaches data
as a metadata item on image
under the name field
. When
VIPS no longer needs the metadata, it will be freed with free_fn
.
See also: vips_image_get_double()
, vips_image_set()
int vips_image_get_area (const VipsImage *image
,const char *field
,void **data
);
Gets data
from image
under the name field
. A convenience
function over vips_image_get()
. Use vips_image_get_typeof()
to test for
the existance of a piece of metadata.
See also: vips_image_set_area()
, vips_image_get()
,
vips_image_get_typeof()
void vips_image_set_blob (VipsImage *image
,const char *field
,VipsCallbackFn free_fn
,void *data
,size_t length
);
Attaches blob
as a metadata item on image
under the name field
. A
convenience
function over vips_image_set()
using an vips_blob.
See also: vips_image_get_blob()
, vips_image_set()
.
int vips_image_get_blob (const VipsImage *image
,const char *field
,void **data
,size_t *length
);
Gets blob
from image
under the name field
, optionally return its length in
length
. A convenience
function over vips_image_get()
. Use vips_image_get_typeof()
to test for the
existance
of a piece of metadata.
See also: vips_image_get()
, vips_image_get_typeof()
, vips_blob_get()
,
int vips_image_get_int (const VipsImage *image
,const char *field
,int *out
);
Gets out
from im
under the name field
. This function searches for
int-valued fields.
See also: vips_image_get()
, vips_image_get_typeof()
void vips_image_set_int (VipsImage *image
,const char *field
,int i
);
Attaches i
as a metadata item on image
under the name field
. A
convenience
function over vips_image_set()
.
See also: vips_image_get_int()
, vips_image_set()
int vips_image_get_double (const VipsImage *image
,const char *field
,double *out
);
Gets out
from im
under the name field
.
This function searches for
double-valued fields.
See also: vips_image_get()
, vips_image_get_typeof()
void vips_image_set_double (VipsImage *image
,const char *field
,double d
);
Attaches d
as a metadata item on image
under the name field
. A
convenience
function over vips_image_set()
.
See also: vips_image_get_double()
, vips_image_set()
int vips_image_get_string (const VipsImage *image
,const char *field
,const char **out
);
Gets out
from im
under the name field
.
This function searches for string-valued fields.
Do not free out
.
See also: vips_image_get()
, vips_image_get_typeof()
void vips_image_set_string (VipsImage *image
,const char *field
,const char *str
);
Attaches str
as a metadata item on image
under the name field
.
A convenience
function over vips_image_set()
using an vips_ref_string.
See also: vips_image_get_double()
, vips_image_set()
, vips_ref_string
int vips_image_history_printf (VipsImage *image
,const char *format
,...
);
Add a line to the image history. The format
and arguments are expanded, the
date and time is appended prefixed with a hash character, and the whole
string is appended to the image history and terminated with a newline.
For example:
vips_image_history_printf (image, "vips invert %s %s", in->filename, out->filename);
Might add the string
"vips invert /home/john/fred.v /home/john/jim.v # Fri Apr 3 23:30:35 2009\n"
VIPS operations don't add history lines for you because a single action at the application level might involve many VIPS operations. History must be recorded by the application.
int vips_image_history_args (VipsImage *image
,const char *name
,int argc
,char *argv[]
);
Formats the name/argv as a single string and calls
vips_image_history_printf()
. A
convenience function for command-line prorams.
See also: vips_image_get_history()
.
const char *
vips_image_get_history (VipsImage *image
);
This function reads the image history as a C string. The string is owned by VIPS and must not be freed.
VIPS tracks the history of each image, that is, the sequence of operations
that generated that image. Applications built on VIPS need to call
vips_image_history_printf()
for each action they perform, setting the
command-line equivalent for the action.
See also: vips_image_history_printf()
.
#define VIPS_META_EXIF_NAME "exif-data"
The name that JPEG read and write operations use for the image's EXIF data.
#define VIPS_META_XMP_NAME "xmp-data"
The name that JPEG read and write operations use for the image's XMP data.
#define VIPS_META_IPCT_NAME "ipct-data"
The name that JPEG read and write operations use for the image's IPCT data.
#define VIPS_META_ICC_NAME "icc-profile-data"
The name we use to attach an ICC profile. The file read and write
operations for TIFF, JPEG, PNG and others use this item of metadata to
attach and save ICC profiles. The profile is updated by the
vips_icc_transform()
operations.
#define VIPS_META_XML "xml-header"
The original XML that was used to code the metadata after reading a VIPS format file.
#define VIPS_META_RESOLUTION_UNIT "resolution-unit"
The JPEG and TIFF read and write operations use this to record the file's preferred unit for resolution.