copied invert example into examples (#3069)

* simple invert example

* Update meson.build
This commit is contained in:
Kirk Martinez 2022-09-29 11:48:24 +01:00 committed by GitHub
parent 69b139dfff
commit df9f5d38f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 0 deletions

View File

@ -2,6 +2,7 @@ examples = [
'annotate-animated', 'annotate-animated',
'new-from-buffer', 'new-from-buffer',
'progress-cancel', 'progress-cancel',
'use-vips-func',
] ]
foreach example : examples foreach example : examples

43
examples/use-vips-func.c Normal file
View File

@ -0,0 +1,43 @@
/* Example showing how to call a couple of vips functions using an input
* image file and creating an output file
* also gathers some info on the input image
*/
#include <stdio.h>
#include <vips/vips.h>
int
main( int argc, char **argv )
{
VipsImage *in;
double mean;
VipsImage *out;
if( VIPS_INIT( argv[0] ) )
vips_error_exit( NULL );
if( argc != 3 )
vips_error_exit( "usage: %s infile outfile", argv[0] );
if( !(in = vips_image_new_from_file( argv[1], NULL )) )
vips_error_exit( NULL );
printf( "image width = %d\n", vips_image_get_width( in ) );
if( vips_avg( in, &mean, NULL ) )
vips_error_exit( NULL );
printf( "mean pixel value = %g\n", mean );
/* generate photo nexative - replace with other vips_ funcs */
if( vips_invert( in, &out, NULL ) )
vips_error_exit( NULL );
g_object_unref( in );
if( vips_image_write_to_file( out, argv[2], NULL ) )
vips_error_exit( NULL );
g_object_unref( out );
return( 0 );
}