Top |
Functions
Types and Values
enum | VipsArgumentFlags |
#define | VIPS_ARGUMENT_REQUIRED_INPUT |
#define | VIPS_ARGUMENT_OPTIONAL_INPUT |
#define | VIPS_ARGUMENT_REQUIRED_OUTPUT |
#define | VIPS_ARGUMENT_OPTIONAL_OUTPUT |
VipsArgument | |
VipsArgumentClass | |
VipsArgumentInstance | |
typedef | VipsArgumentTable |
#define | VIPS_ARGUMENT_COLLECT_END |
Object Hierarchy
GObject ╰── VipsObject ├── VipsConnection ├── VipsOperation ├── VipsImage ├── VipsInterpolate ├── VipsRegion ├── VipsSbuf ╰── VipsThreadState
Description
The VipsObject class and associated types and macros.
VipsObject is the base class for all objects in libvips. It has the following major features:
Functional class creation Vips objects have a very regular lifecycle: initialise, build, use, destroy. They behave rather like function calls and are free of side-effects.
Run-time introspection Vips objects can be fully introspected at run-time. There is no need for separate source-code analysis.
Command-line interface Any vips object can be run from
the command-line with the vips
driver program.
The VipsObject lifecycle
VipsObject s have a strictly defined lifecycle, split broadly as construct and then use. In detail, the stages are:
g_object_new(). The VipsObject is created with
g_object_new()
. Objects in this state are blank slates and need to have their various parameters set.g_object_set(). You loop over the VipsArgument that the object has defined with
vips_argument_map()
. Arguments have a set of flags attached to them for required, optional, input, output, type, and so on. You must set all required arguments.vips_object_build(). Call this to construct the object and get it ready for use. Building an object happens in four stages, see below.
g_object_get(). The object has now been built. You can read out any computed values.
g_object_unref(). When you are done with an object, you can unref it. See the section on reference counting for an explanation of the convention that VipsObject uses. When the last ref to an object is released, the object is closed. Objects close in three stages, see below.
The stages inside vips_object_build()
are:
Chain up through the object's
build
class methods. At each stage, each class does any initial setup and checking, then chains up to its superclass.The innermost
build
method inside VipsObject itself checks that all input arguments have been set and then returns.All object
build
methods now finish executing, from innermost to outermost. They know all input arguments have been checked and supplied, so now they set all output arguments.vips_object_build() finishes the process by checking that all output objects have been set, and then triggering the “postbuild” signal. “postbuild” only runs if the object has constructed successfuly.
VipsOperation has a cache of recent operation objects, see that class for
an explanation of vips_cache_operation_build()
.
Finally the stages inside close are:
“preclose”. This is emitted at the start of the VipsObject dispose. The object is still functioning.
“close”. This runs just after all VipsArgument held by the object have been released.
“postclose”. This runs right at the end. The object pointer is still valid, but nothing else is.
VipsArgument
libvips has a simple mechanism for automating at least some aspects of
GObject
properties. You add a set of macros to your _class_init()
which
describe the arguments, and set the get and set functions to the vips ones.
See extending for a complete example.
The VipsObject reference counting convention
VipsObject has a set of conventions to simplify reference counting.
All input
GObject
have a ref added to them, owned by the object. When a VipsObject is unreffed, all of these refs to input objects are automatically dropped.All output
GObject
hold a ref to the object. When aGObject
which is an output of a VipsObject is disposed, it must drop this reference. VipsObject which are outputs of other VipsObject will do this automatically.
See VipsOperation for an example of VipsObject reference counting.
Functions
VIPS_ARG_INTERPOLATE()
#define VIPS_ARG_INTERPOLATE( CLASS, NAME, PRIORITY, LONG, DESC, FLAGS, OFFSET )
VIPS_ARG_DOUBLE()
#define VIPS_ARG_DOUBLE( CLASS, NAME, PRIORITY, LONG, DESC, \ FLAGS, OFFSET, MIN, MAX, VALUE )
VIPS_ARG_INT()
#define VIPS_ARG_INT( CLASS, NAME, PRIORITY, LONG, DESC, \ FLAGS, OFFSET, MIN, MAX, VALUE )
VIPS_ARG_UINT64()
#define VIPS_ARG_UINT64( CLASS, NAME, PRIORITY, LONG, DESC, \ FLAGS, OFFSET, MIN, MAX, VALUE )
VIPS_ARG_ENUM()
#define VIPS_ARG_ENUM( CLASS, NAME, PRIORITY, LONG, DESC, \ FLAGS, OFFSET, TYPE, VALUE )
VIPS_ARG_FLAGS()
#define VIPS_ARG_FLAGS( CLASS, NAME, PRIORITY, LONG, DESC, \ FLAGS, OFFSET, TYPE, VALUE )
VIPS_ARG_STRING()
#define VIPS_ARG_STRING( CLASS, NAME, PRIORITY, LONG, DESC, FLAGS, OFFSET, \ VALUE )
vips_argument_get_id ()
int
vips_argument_get_id (void
);
Allocate a new property id. See g_object_class_install_property()
.
[skip]
vips__object_set_member ()
void vips__object_set_member (VipsObject *object
,GParamSpec *pspec
,GObject **member
,GObject *argument
);
VipsArgumentMapFn ()
void * (*VipsArgumentMapFn) (VipsObject *object
,GParamSpec *pspec
,VipsArgumentClass *argument_class
,VipsArgumentInstance *argument_instance
,void *a
,void *b
);
vips_argument_map ()
void * vips_argument_map (VipsObject *object
,VipsArgumentMapFn fn
,void *a
,void *b
);
Loop over the vips_arguments to an object. Stop when fn
returns non-NULL
and return that value.
[skip]
vips_object_get_args ()
int vips_object_get_args (VipsObject *object
,const char ***names
,int **flags
,int *n_args
);
Get all GParamSpec
names and VipsArgumentFlags for an object.
This is handy for language bindings. From C, it's usually more convenient to
use vips_argument_map()
.
[skip]
Parameters
object |
object whose args should be retrieved |
|
names |
output array of |
[transfer none][array length=n_args][allow-none] |
flags |
output array of VipsArgumentFlags. |
[transfer none][array length=n_args][allow-none] |
n_args |
length of output arrays. |
[allow-none] |
VipsArgumentClassMapFn ()
void * (*VipsArgumentClassMapFn) (VipsObjectClass *object_class
,GParamSpec *pspec
,VipsArgumentClass *argument_class
,void *a
,void *b
);
vips_argument_class_map ()
void * vips_argument_class_map (VipsObjectClass *object_class
,VipsArgumentClassMapFn fn
,void *a
,void *b
);
And loop over a class. Same as ^^, but with no VipsArgumentInstance.
[skip]
vips_argument_class_needsstring ()
gboolean
vips_argument_class_needsstring (VipsArgumentClass *argument_class
);
vips_object_get_argument ()
int vips_object_get_argument (VipsObject *object
,const char *name
,GParamSpec **pspec
,VipsArgumentClass **argument_class
,VipsArgumentInstance **argument_instance
);
Look up the three things you need to work with a vips argument.
[skip]
vips_object_argument_isset ()
gboolean vips_object_argument_isset (VipsObject *object
,const char *name
);
Convenience: has an argument been assigned. Useful for bindings.
vips_object_get_argument_flags ()
VipsArgumentFlags vips_object_get_argument_flags (VipsObject *object
,const char *name
);
Convenience: get the flags for an argument. Useful for bindings.
vips_object_get_argument_priority ()
int vips_object_get_argument_priority (VipsObject *object
,const char *name
);
Convenience: get the priority for an argument. Useful for bindings.
vips_object_set_property ()
void vips_object_set_property (GObject *gobject
,guint property_id
,const GValue *value
,GParamSpec *pspec
);
vips_object_get_property ()
void vips_object_get_property (GObject *gobject
,guint property_id
,GValue *value
,GParamSpec *pspec
);
vips_object_summary_class ()
void vips_object_summary_class (VipsObjectClass *klass
,VipsBuf *buf
);
Generate a human-readable summary for a class.
[skip]
vips_object_summary ()
void vips_object_summary (VipsObject *object
,VipsBuf *buf
);
Generate a human-readable summary for an object.
[skip]
vips_object_dump ()
void vips_object_dump (VipsObject *object
,VipsBuf *buf
);
Dump everything that vips knows about an object to a string.
[skip]
vips_object_class_install_argument ()
void vips_object_class_install_argument (VipsObjectClass *cls
,GParamSpec *pspec
,VipsArgumentFlags flags
,int priority
,guint offset
);
vips_object_set_argument_from_string ()
int vips_object_set_argument_from_string (VipsObject *object
,const char *name
,const char *value
);
vips_object_argument_needsstring ()
gboolean vips_object_argument_needsstring (VipsObject *object
,const char *name
);
vips_object_get_argument_to_string ()
int vips_object_get_argument_to_string (VipsObject *object
,const char *name
,const char *arg
);
vips_object_new ()
VipsObject * vips_object_new (GType type
,VipsObjectSetArguments set
,void *a
,void *b
);
g_object_new() the object, set any arguments with set
, call
vips_object_build()
and return the complete object.
[skip]
vips_object_set_valist ()
int vips_object_set_valist (VipsObject *object
,va_list ap
);
See vips_object_set()
.
vips_object_set ()
int vips_object_set (VipsObject *object
,...
);
Set a list of vips object arguments. For example:
1 2 3 4 |
vips_object_set (operation, "input", in, "output", &out, NULL); |
Input arguments are given in-line, output arguments are given as pointers to where the output value should be written.
See also: vips_object_set_valist()
, vips_object_set_from_string()
.
vips_object_set_from_string ()
int vips_object_set_from_string (VipsObject *object
,const char *string
);
Set object arguments from a string. The string can be something like "a=12", or "a = 12, b = 13", or "fred". The string can optionally be enclosed in brackets.
You'd typically use this between creating the object and building it.
See also: vips_object_set()
, vips_object_build()
,
vips_cache_operation_buildp()
.
vips_object_new_from_string ()
VipsObject * vips_object_new_from_string (VipsObjectClass *object_class
,const char *p
);
vips_object_to_string ()
void vips_object_to_string (VipsObject *object
,VipsBuf *buf
);
The inverse of vips_object_new_from_string()
: turn object
into eg.
"VipsInterpolateSnohalo1(blur=.333333)".
vips_object_map ()
void * vips_object_map (VipsSListMap2Fn fn
,void *a
,void *b
);
Call a function for all alive objects.
Stop when fn
returns non-NULL
and return that value.
[skip]
vips_type_map ()
void * vips_type_map (GType base
,VipsTypeMap2Fn fn
,void *a
,void *b
);
Map over a type's children. Stop when fn
returns non-NULL
and return that value.
[skip]
vips_type_map_all ()
void * vips_type_map_all (GType base
,VipsTypeMapFn fn
,void *a
);
Map over a type's children, direct and indirect. Stop when fn
returns
non-NULL
and return that value.
[skip]
vips_type_find ()
GType vips_type_find (const char *basename
,const char *nickname
);
Search below basename
, return the GType
of the class whose name or
nickname
matches, or 0 for not found.
If basename
is NULL, the whole of VipsObject is searched.
This function uses a cache, so it should be quick.
See also: vips_class_find()
vips_nickname_find ()
const char *
vips_nickname_find (GType type
);
Return the VIPS nickname for a GType
. Handy for language bindings.
vips_class_map_all ()
void * vips_class_map_all (GType type
,VipsClassMapFn fn
,void *a
);
Loop over all the subclasses of type
. Non-abstract classes only.
Stop when fn
returns
non-NULL
and return that value.
[skip]
vips_class_find ()
const VipsObjectClass * vips_class_find (const char *basename
,const char *nickname
);
Search below basename
, return the first class whose name or nickname
matches.
See also: vips_type_find()
vips_object_local_array ()
VipsObject ** vips_object_local_array (VipsObject *parent
,int n
);
Make an array of NULL VipsObject pointers. When parent
closes, every
non-NULL pointer in the array will be unreffed and the array will be
freed. Handy for creating a set of temporary images for a function.
The array is NULL-terminated, ie. contains an extra NULL element at the end.
Example:
1 2 3 4 5 6 7 8 9 |
VipsObject **t; t = vips_object_local_array( parent, 5 ); if( vips_add( a, b, &t[0], NULL ) || vips_invert( t[0], &t[1], NULL ) || vips_add( t[1], t[0], &t[2], NULL ) || vips_costra( t[2], out, NULL ) ) return( -1 ); |
See also: vips_object_local()
.
[skip]
vips_object_unref_outputs ()
void
vips_object_unref_outputs (VipsObject *object
);
Unref all assigned output objects. Useful for language bindings.
After an object is built, all output args are owned by the caller. If something goes wrong before then, we have to unref the outputs that have been made so far. This function can also be useful for callers when they've finished processing outputs themselves.
See also: vips_cache_operation_build()
.
vips_object_get_description ()
const char *
vips_object_get_description (VipsObject *object
);
Fetch the object description. Useful for language bindings.
object.description
is only avaliable after _build()
, which can be too
late. This function fetches from the instance, if possible, but falls back
to the class description if we are too early.
Types and Values
enum VipsArgumentFlags
Flags we associate with each object argument.
Have separate input & output flags. Both set is an error; neither set is OK.
Input gobjects are automatically reffed, output gobjects automatically ref us. We also automatically watch for "destroy" and unlink.
VIPS_ARGUMENT_SET_ALWAYS
is handy for arguments which are set from C. For
example, VipsImage::width is a property that gives access to the Xsize
member of struct _VipsImage. We default its 'assigned' to TRUE
since the field is always set directly by C.
VIPS_ARGUMENT_DEPRECATED
arguments are not shown in help text, are not
looked for if required, are not checked for "have-been-set". You can
deprecate a required argument, but you must obviously add a new required
argument if you do.
Input args with VIPS_ARGUMENT_MODIFY
will be modified by the operation.
This is used for things like the in-place drawing operations.
VipsArgument
typedef struct { GParamSpec *pspec; /* pspec for this argument */ /* More stuff, see below */ } VipsArgument;
VipsArgumentClass
typedef struct { VipsArgument parent; /* The class of the object we are an arg for. */ VipsObjectClass *object_class; VipsArgumentFlags flags; int priority; /* Order args by this */ guint offset; /* G_STRUCT_OFFSET of member in object */ } VipsArgumentClass;
VipsArgumentInstance
typedef struct { VipsArgument parent; /* The class we are part of. */ VipsArgumentClass *argument_class; /* The object we are attached to. */ VipsObject *object; /* Has been set. */ gboolean assigned; /* If this is an output argument, keep the id of our "close" handler * here. */ gulong close_id; /* We need to listen for "invalidate" on input images and send our own * "invalidate" out. If we go, we need to disconnect. */ gulong invalidate_id; } VipsArgumentInstance;
Property Details
The “description”
property
“description” gchar *
Class description.
Owner: VipsObject
Flags: Read / Write
Default value: ""
Signal Details
The “close”
signal
void user_function (VipsObject *object, gpointer user_data)
The ::close signal is emitted once during object close. The object is dying and may not work.
Parameters
object |
the object that is closing |
|
user_data |
user data set when the signal handler was connected. |
Flags: Run Last
The “postbuild”
signal
gint user_function (VipsObject *object, gpointer user_data)
The ::postbuild signal is emitted once just after successful object construction. Return non-zero to cause object construction to fail.
Parameters
object |
the object that has been built |
|
user_data |
user data set when the signal handler was connected. |
Flags: Run Last
The “postclose”
signal
void user_function (VipsObject *object, gpointer user_data)
The ::postclose signal is emitted once after object close. The object pointer is still valid, but nothing else.
Parameters
object |
the object that has closed |
|
user_data |
user data set when the signal handler was connected. |
Flags: Run Last
The “preclose”
signal
void user_function (VipsObject *object, gpointer user_data)
The ::preclose signal is emitted once just before object close starts. The oject is still alive.
Parameters
object |
the object that is to close |
|
user_data |
user data set when the signal handler was connected. |
Flags: Run Last