add some more examples
This commit is contained in:
parent
ce31c04cd2
commit
d836166087
@ -1,5 +1,7 @@
|
||||
examples = [
|
||||
'annotate-animated',
|
||||
'new-from-buffer',
|
||||
'progress-cancel',
|
||||
]
|
||||
|
||||
foreach example : examples
|
||||
|
54
examples/new-from-buffer.c
Normal file
54
examples/new-from-buffer.c
Normal file
@ -0,0 +1,54 @@
|
||||
/* Read and write formatted images to memory.
|
||||
*
|
||||
* Compile with:
|
||||
*
|
||||
* gcc -g -Wall new-from-buffer.c `pkg-config vips --cflags --libs`
|
||||
*
|
||||
*/
|
||||
|
||||
#include <vips/vips.h>
|
||||
|
||||
int
|
||||
main( int argc, char **argv )
|
||||
{
|
||||
gchar *buf;
|
||||
gsize len;
|
||||
int i;
|
||||
|
||||
if( VIPS_INIT( argv[0] ) )
|
||||
vips_error_exit( NULL );
|
||||
|
||||
if( argc != 2 )
|
||||
vips_error_exit( "usage: %s FILENAME", argv[0] );
|
||||
|
||||
if( !g_file_get_contents( argv[1], &buf, &len, NULL ) )
|
||||
vips_error_exit( NULL );
|
||||
|
||||
for( i = 0; i < 10; i++ ) {
|
||||
VipsImage *image;
|
||||
void *new_buf;
|
||||
size_t new_len;
|
||||
|
||||
printf( "loop %d ...\n", i );
|
||||
|
||||
if( !(image = vips_image_new_from_buffer( buf, len, "",
|
||||
"access", VIPS_ACCESS_SEQUENTIAL,
|
||||
NULL )) )
|
||||
vips_error_exit( NULL );
|
||||
|
||||
if( vips_image_write_to_buffer( image,
|
||||
".jpg", &new_buf, &new_len,
|
||||
"Q", 95,
|
||||
NULL ) )
|
||||
vips_error_exit( NULL );
|
||||
|
||||
g_object_unref( image );
|
||||
g_free( new_buf );
|
||||
}
|
||||
|
||||
g_free( buf );
|
||||
|
||||
vips_shutdown();
|
||||
|
||||
return( 0 );
|
||||
}
|
78
examples/progress-cancel.c
Normal file
78
examples/progress-cancel.c
Normal file
@ -0,0 +1,78 @@
|
||||
/* Show progress feedback and computation cancel.
|
||||
*
|
||||
* compile with
|
||||
*
|
||||
* gcc -g -Wall progress-cancel.c `pkg-config vips --cflags --libs`
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <vips/vips.h>
|
||||
#include <errno.h>
|
||||
|
||||
void
|
||||
preeval_callback( VipsImage *image, VipsProgress *progress, void* pdata )
|
||||
{
|
||||
printf( "preeval_callback:\n" );
|
||||
}
|
||||
|
||||
void
|
||||
eval_callback( VipsImage *image, VipsProgress *progress, void* pdata )
|
||||
{
|
||||
printf( "eval_callback: percent = %d\n", progress->percent );
|
||||
|
||||
if( progress->percent >= 25 ) {
|
||||
printf( "calling vips_image_set_kill() ...\n" );
|
||||
vips_image_set_kill( image, TRUE );
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
posteval_callback( VipsImage *image, VipsProgress *progress, void* pdata )
|
||||
{
|
||||
printf( "posteval_callback: finished in %.3gs\n",
|
||||
g_timer_elapsed( progress->start, NULL ) );
|
||||
}
|
||||
|
||||
int
|
||||
main( int argc, char **argv )
|
||||
{
|
||||
VipsImage *image;
|
||||
VipsImage *out;
|
||||
void *output;
|
||||
size_t output_length;
|
||||
|
||||
if( VIPS_INIT( argv[0] ) )
|
||||
vips_error_exit( NULL );
|
||||
|
||||
if( argc != 3 )
|
||||
vips_error_exit( "usage: %s INPUT-FILE OUTPUT-FILE", argv[0] );
|
||||
|
||||
if( !(image = vips_image_new_from_file( argv[1],
|
||||
"access", VIPS_ACCESS_SEQUENTIAL,
|
||||
NULL )) )
|
||||
vips_error_exit( NULL );
|
||||
|
||||
if( vips_resize( image, &out, 0.5, NULL ) )
|
||||
vips_error_exit( NULL );
|
||||
|
||||
vips_image_set_progress( out, TRUE );
|
||||
g_signal_connect( out, "preeval",
|
||||
G_CALLBACK( preeval_callback ), NULL );
|
||||
g_signal_connect( out, "eval",
|
||||
G_CALLBACK( eval_callback ), NULL );
|
||||
g_signal_connect( out, "posteval",
|
||||
G_CALLBACK( posteval_callback ), NULL );
|
||||
|
||||
output = NULL;
|
||||
if( vips_image_write_to_buffer( out, argv[2], &output, &output_length,
|
||||
NULL ) )
|
||||
printf( "error return from vips_image_write_to_buffer()\n" );
|
||||
|
||||
g_object_unref( out );
|
||||
g_object_unref( image );
|
||||
if( output )
|
||||
g_free( output );
|
||||
vips_shutdown();
|
||||
|
||||
return 0;
|
||||
}
|
@ -633,6 +633,7 @@ build_summary = {
|
||||
'enable gtk-doc': [get_option('gtk_doc')],
|
||||
'enable doxygen': [get_option('doxygen')],
|
||||
'enable introspection': [get_option('introspection')],
|
||||
'enable examples': [get_option('examples')],
|
||||
'enable RAD load/save': [get_option('radiance')],
|
||||
'enable Analyze7 load/save': [get_option('analyze')],
|
||||
'enable PPM load/save': [get_option('ppm')],
|
||||
@ -686,6 +687,8 @@ subdir('cplusplus')
|
||||
subdir('man')
|
||||
subdir('po')
|
||||
subdir('tools')
|
||||
if get_option('examples')
|
||||
subdir('examples')
|
||||
endif
|
||||
subdir('test')
|
||||
subdir('fuzz')
|
||||
|
@ -5,6 +5,11 @@ option('deprecated',
|
||||
value: true,
|
||||
description: 'Build deprecated components')
|
||||
|
||||
option('examples',
|
||||
type: 'boolean',
|
||||
value: true,
|
||||
description: 'Build example programs')
|
||||
|
||||
option('doxygen',
|
||||
type: 'boolean',
|
||||
value: false,
|
||||
|
Loading…
Reference in New Issue
Block a user