Skip to content

Instantly share code, notes, and snippets.

@jcupitt
Last active March 29, 2018 20:22
Show Gist options
  • Save jcupitt/9cd5662838cb749f706c to your computer and use it in GitHub Desktop.
Save jcupitt/9cd5662838cb749f706c to your computer and use it in GitHub Desktop.
test libvips load from stream
/* test load from stream
*
* compile with:
*
* gcc -g -Wall load-from-stream.c `pkg-config vips --cflags --libs`
*
* test with:
*
* cat k2.jpg k4.jpg | ./a.out
*/
#include <vips/vips.h>
int
main( int argc, char **argv )
{
GOptionContext *context;
GOptionGroup *main_group;
GError *error = NULL;
VipsStreamInput *stream;
if( vips_init( argv[0] ) )
vips_error_exit( NULL );
context = g_option_context_new( "load-from-stream - "
"load jpegs from stdin" );
main_group = g_option_group_new( NULL, NULL, NULL, NULL, NULL );
g_option_context_set_main_group( context, main_group );
g_option_context_add_group( context, vips_get_option_group() );
if( !g_option_context_parse( context, &argc, &argv, &error ) ) {
if( error ) {
fprintf( stderr, "%s\n", error->message );
g_error_free( error );
}
vips_error_exit( NULL );
}
stream = vips_stream_input_new_from_descriptor( 0 );
while( !vips_stream_input_eof( stream ) ) {
VipsImage *x;
double avg;
if( vips_jpegload_stream( stream, &x, NULL ) )
vips_error_exit( NULL );
if( vips_avg( x, &avg, NULL ) )
vips_error_exit( NULL );
g_object_unref( x );
printf( "avg = %g\n", avg );
}
g_object_unref( stream );
return( 0 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment