int main( int argc, char *argv[] ) { GOptionContext *context; GOptionGroup *main_group; GError *error = NULL; if( VIPS_INIT( argv[0] ) ) vips_error_exit( "unable to start VIPS" ); textdomain( GETTEXT_PACKAGE ); setlocale( LC_ALL, "" ); context = g_option_context_new( _( "- introspect" ) ); main_group = g_option_group_new( NULL, NULL, NULL, NULL, NULL ); g_option_group_add_entries( main_group, main_option ); vips_add_option_entries( main_group ); g_option_group_set_translation_domain( main_group, GETTEXT_PACKAGE ); g_option_context_set_main_group( context, main_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( "try \"%s --help\"", g_get_prgname() ); } g_option_context_free( context ); #ifdef DEBUG /* For debugging it's handy to have a copy of the input file. */ if( main_option_introspect_dump ) { char **args; char *cmd; args = g_strsplit( main_option_introspect_dump, ",", 2 ); cmd = g_strdup_printf( "cp %s ~/functions.txt", args[0]); printf( "introspect: running '%s'\n", cmd ); system( cmd ); g_free( cmd ); } #endif /*DEBUG*/ if( main_option_introspect_dump && !g_irepository_dump( main_option_introspect_dump, &error ) ) { if( error ) { fprintf( stderr, "%s\n", error->message ); g_error_free( error ); } vips_error_exit( "unable to dump introspection" ); } vips_shutdown(); return( 0 ); }
int main(int argc, char* argv[]) { if (VIPS_INIT(argv[0])) { vips_error_exit("Unable to start VIPS"); } int ret = 0; // Initialize and open database ret = init_dbfile(argc, argv[1]); if (ret == 0) { print_header(&db_file->header); // Initialize signal handler and kill previous one signal(SIGTERM, signal_handler); signal(SIGINT, signal_handler); struct mg_mgr mgr; struct mg_connection* nc; // Create listening connection mg_mgr_init(&mgr, NULL); nc = mg_bind(&mgr, s_http_port, db_event_handler); if (nc != NULL) { // Set up HTTP server parameters mg_set_protocol_http_websocket(nc); s_http_server_opts.document_root = "."; // Serve current directory s_http_server_opts.enable_directory_listing = "yes"; // Listening loop printf("Starting web server on port %s,\nserving %s\n", s_http_port, s_http_server_opts.document_root); while (!s_sig_received) { mg_mgr_poll(&mgr, 1000); } printf("Exiting on signal %d\n", s_sig_received); } else { fprintf(stderr, "Unable to create web server on port %s\n", s_http_port); } mg_mgr_free(&mgr); } // Close database and free the pointer do_close(db_file); free(db_file); // Print error message if there was an error if (ret) { fprintf(stderr, "ERROR: %s\n", ERROR_MESSAGES[ret]); } vips_shutdown(); return ret; }
int main( int argc, char **argv ) { VipsImage *global; VipsImage **t; if( VIPS_INIT( argv[0] ) ) return( -1 ); global = vips_image_new(); t = (VipsImage **) vips_object_local_array( VIPS_OBJECT( global ), 5 ); VipsInterpolate *interp = vips_interpolate_new( "bilinear" ); if( !(t[0] = vips_image_new_from_file( argv[1], "access", VIPS_ACCESS_SEQUENTIAL, NULL )) ) vips_error_exit( NULL ); t[1] = vips_image_new_matrixv( 3, 3, -1.0, -1.0, -1.0, -1.0, 16.0, -1.0, -1.0, -1.0, -1.0 ); vips_image_set_double( t[1], "scale", 8 ); if( vips_extract_area( t[0], &t[2], 100, 100, t[0]->Xsize - 200, t[0]->Ysize - 200, NULL ) || vips_similarity( t[2], &t[3], "scale", 0.9, "interpolate", interp, NULL ) || vips_conv( t[3], &t[4], t[1], NULL ) || vips_image_write_to_file( t[4], argv[2], NULL ) ) vips_error_exit( NULL ); g_object_unref( global ); g_object_unref( interp ); return( 0 ); }
int main( int argc, char **argv ) { GOptionContext *context; GOptionGroup *main_group; GError *error = NULL; int i; int result; if( VIPS_INIT( argv[0] ) ) vips_error_exit( "unable to start VIPS" ); textdomain( GETTEXT_PACKAGE ); setlocale( LC_ALL, "" ); context = g_option_context_new( _( "- thumbnail generator" ) ); main_group = g_option_group_new( NULL, NULL, NULL, NULL, NULL ); g_option_group_add_entries( main_group, options ); vips_add_option_entries( main_group ); g_option_group_set_translation_domain( main_group, GETTEXT_PACKAGE ); g_option_context_set_main_group( context, main_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( "try \"%s --help\"", g_get_prgname() ); } g_option_context_free( context ); if( sscanf( thumbnail_size, "%d x %d", &thumbnail_width, &thumbnail_height ) != 2 ) { if( sscanf( thumbnail_size, "%d", &thumbnail_width ) != 1 ) vips_error_exit( "unable to parse size \"%s\" -- " "use eg. 128 or 200x300", thumbnail_size ); thumbnail_height = thumbnail_width; } if( rotate_image ) { #ifndef HAVE_EXIF vips_warn( "vipsthumbnail", "%s", _( "auto-rotate disabled: " "libvips built without exif support" ) ); #endif /*!HAVE_EXIF*/ } result = 0; for( i = 1; i < argc; i++ ) { /* Hang resources for processing this thumbnail off @process. */ VipsObject *process = VIPS_OBJECT( vips_image_new() ); if( thumbnail_process( process, argv[i] ) ) { fprintf( stderr, "%s: unable to thumbnail %s\n", argv[0], argv[i] ); fprintf( stderr, "%s", vips_error_buffer() ); vips_error_clear(); /* We had a conversion failure: return an error code * when we finally exit. */ result = -1; } g_object_unref( process ); } vips_shutdown(); return( result ); }
int main( int argc, char **argv ) { GOptionContext *context; GOptionGroup *main_group; GError *error = NULL; IMAGE *im; unsigned char header[IM_SIZEOF_HEADER]; if( VIPS_INIT( argv[0] ) ) vips_error_exit( "%s", _( "unable to start VIPS" ) ); textdomain( GETTEXT_PACKAGE ); setlocale( LC_ALL, "" ); context = g_option_context_new( _( "vipsedit - edit vips file header" ) ); main_group = g_option_group_new( NULL, NULL, NULL, NULL, NULL ); g_option_group_add_entries( main_group, entries ); vips_add_option_entries( main_group ); g_option_group_set_translation_domain( main_group, GETTEXT_PACKAGE ); g_option_context_set_main_group( context, main_group ); if( !g_option_context_parse( context, &argc, &argv, &error ) ) { if( error ) { fprintf( stderr, "%s\n", error->message ); g_error_free( error ); } exit( -1 ); } if( argc != 2 ) { fprintf( stderr, _( "usage: %s [OPTION...] vips-file\n" ), g_get_prgname() ); exit( -1 ); } if( !(im = im_init( argv[1] )) || (im->fd = im__open_image_file( im->filename )) == -1 ) error_exit( _( "could not open image %s" ), argv[1] ); if( read( im->fd, header, IM_SIZEOF_HEADER ) != IM_SIZEOF_HEADER || im__read_header_bytes( im, header ) ) error_exit( _( "could not read VIPS header for %s" ), im->filename ); if( endian ) { if( strcmp( endian, "little" ) == 0 ) im->magic = VIPS_MAGIC_INTEL; else if( strcmp( endian, "big" ) == 0 ) im->magic = VIPS_MAGIC_SPARC; else error_exit( _( "bad endian-ness %s, " "should be 'big' or 'little'" ), endian ); } if( xsize ) parse_pint( xsize, &im->Xsize ); if( ysize ) parse_pint( ysize, &im->Ysize ); if( bands ) parse_pint( bands, &im->Bands ); if( format ) { VipsBandFormat f; if( (f = im_char2BandFmt( format )) < 0 ) error_exit( _( "bad format %s" ), format ); im->BandFmt = f; im->Bbits = im_bits_of_fmt( f ); } if( interpretation ) { VipsInterpretation i; if( (i = im_char2Type( interpretation )) < 0 ) error_exit( _( "bad interpretation %s" ), interpretation ); im->Type = i; } if( coding ) { VipsCoding c; if( (c = im_char2Coding( coding )) < 0 ) error_exit( _( "bad coding %s" ), coding ); im->Coding = c; } if( xres ) im->Xres = atof( xres ); if( yres ) im->Yres = atof( yres ); if( xoffset ) im->Xoffset = atoi( xoffset ); if( yoffset ) im->Yoffset = atoi( yoffset ); if( lseek( im->fd, 0, SEEK_SET ) == (off_t) -1 ) error_exit( _( "could not seek on %s" ), im->filename ); if( im__write_header_bytes( im, header ) || im__write( im->fd, header, IM_SIZEOF_HEADER ) ) error_exit( _( "could not write to %s" ), im->filename ); if( setext ) { char *xml; size_t size; if( !(xml = im__file_read( stdin, "stdin", &size )) ) error_exit( "%s", _( "could not get ext data" ) ); /* Strip trailing whitespace ... we can get stray \n at the * end, eg. "echo | editvips --setext fred.v". */ while( size > 0 && isspace( xml[size - 1] ) ) size -= 1; if( im__write_extension_block( im, xml, size ) ) error_exit( "%s", _( "could not set extension" ) ); im_free( xml ); } im_close( im ); vips_shutdown(); return( 0 ); }