int main( int argc, char **argv ) { GOptionContext *context; GError *error = NULL; IMAGE *im; unsigned char header[IM_SIZEOF_HEADER]; if( im_init_world( argv[0] ) ) error_exit( "%s", _( "unable to start VIPS" ) ); textdomain( GETTEXT_PACKAGE ); setlocale( LC_ALL, "" ); context = g_option_context_new( _( "vipsfile - edit vipsfile header" ) ); g_option_context_add_main_entries( context, entries, GETTEXT_PACKAGE ); g_option_context_add_group( context, im_get_option_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...] vipsfile\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( xsize ) parse_pint( xsize, &im->Xsize ); if( ysize ) parse_pint( ysize, &im->Ysize ); if( bands ) parse_pint( bands, &im->Bands ); if( format ) { if( (im->BandFmt = im_char2BandFmt( format )) < 0 ) error_exit( _( "bad format %s" ), format ); im->Bbits = im_bits_of_fmt( im->BandFmt ); } if( type ) { if( (im->Type = im_char2Type( type )) < 0 ) error_exit( _( "bad type %s" ), type ); } if( coding ) { if( (im->Coding = im_char2Coding( coding )) < 0 ) error_exit( _( "bad coding %s" ), coding ); } 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; unsigned int 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 | edvips --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 ); }
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 ); }