-
-
Save NickNaso/c674a93615ae26f45d2b8c656146d106 to your computer and use it in GitHub Desktop.
test libvips load from stream
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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