int im_add_close_callback(
im, fn, a, b )
IMAGE *im;
int (*fn)();
void *a, *b;
int im_add_evalend_callback( im, fn, a, b )
IMAGE *im;
int (*fn)();
void *a, *b;
where
int fn( a, b )
void *a, *b;
char *im_malloc( IMAGE *im, int size );
int im_free( void *s );
#include <vips/vips.h>
#include <vips/time.h>
int im_add_eval_callback( im, fn, a, b )
IMAGE *im;
int (*fn)();
void *a, *b;
where
int fn( a, b )
void *a, *b;
im_add_close_callback(3) adds a callback which will be triggered when the image is closed by im_close(3) . The callback is expected to return 0 for success and non-zero for failure. If the function fails, then the whole im_close(3) fails.
This function is used by VIPS to implement im_malloc(3) . This allocates memory exactly as the standard malloc(3) function, but memory allocated is local to a descriptor. When the descriptor is closed, the memory allocated is automatically freed for you. If you pass NULL for the descriptor, then im_malloc(3) acts as malloc(3) . On error, im_malloc(3) returns NULL, setting an error message. See the man pages for IM_NEW(3) and im_open_local(3) for further examples.
Free memory with im_free(3) .
You may use close callbacks to trigger other im_close(3) operations, and there may even be circularity in your im_close(3) lists.
im_add_evalend_callback(3) adds a callback which will be triggered when VIPS has finished writing to the descriptor. If you want to output some diagnostics from your function (an overflow count, for example), this is the callback to use.
im_add_eval_callback(3) adds a callback which will be triggered repeatedly as the image is written to. This works for both PIO and WIO images, although it is rather more successful with PIO image output.
When the callback is triggered, the time field of the descriptor will point to a time_info structure, as defined in <vips/time.h>
#include
<sys/timeb.h>
struct time_info {
IMAGE *im; /* Image we are part of */
time_t start; /* Start time, in seconds */
int run; /* Time we have been running */
int eta; /* Seconds of computation left */
int ttiles; /* Tiles we expect to calculate */
int ntiles; /* Tiles calculated so far */
int percent; /* Percent complete */
};
These fields are not exact! They should only be used to give approximate feedback to the user. It is possible to have
percent > 100
ntiles > ttiles
eta == 0
so be careful. Again, the eval callback should return 0 for success and non-zero for failure. If the callback fails, evaluation is abandoned. This may be used to provide a ‘cancel’ feature in your user-interface.
int
eval_cb( IMAGE *im )
{
printf( "%d%% complete ...\n", im->time->percent );
return( 0 );
}
if( im_add_eval_callback( out, eval_cb, out, NULL ) )
return( -1 );
... now as we write to out, we will get %complete
... messages on stdout.