/** * im_vips2csv: * @in: image to save * @filename: file to write to * * Save a CSV (comma-separated values) file. The image is written * one line of text per scanline. Complex numbers are written as * "(real,imaginary)" and will need extra parsing I guess. The image must * have a single band. * * Write options can be embedded in the filename. The options can be given * in any order and are: * * <itemizedlist> * <listitem> * <para> * <emphasis>sep:separator-string</emphasis> * The string to use to separate numbers in the output. * The default is "\\t" (tab). * </para> * </listitem> * </itemizedlist> * * For example: * * |[ * im_csv2vips( in, "fred.csv:sep:\t" ); * ]| * * Will write to fred.csv, separating numbers with tab characters. * * See also: #VipsFormat, im_csv2vips(), im_write_dmask(), im_vips2ppm(). * * Returns: 0 on success, -1 on error. */ int im_vips2csv( IMAGE *in, const char *filename ) { char *separator = "\t"; char name[FILENAME_MAX]; char mode[FILENAME_MAX]; FILE *fp; char *p, *q, *r; /* Parse mode string. */ im_filename_split( filename, name, mode ); p = &mode[0]; while( (q = im_getnextoption( &p )) ) { if( im_isprefix( "sep", q ) && (r = im_getsuboption( q )) ) separator = r; } if( im_incheck( in ) || im_check_mono( "im_vips2csv", in ) || im_check_uncoded( "im_vips2csv", in ) ) return( -1 ); if( !(fp = im__file_open_write( name, TRUE )) ) return( -1 ); if( vips2csv( in, fp, separator ) ) { fclose( fp ); return( -1 ); } fclose( fp ); return( 0 ); }
int im_vips2tiff( IMAGE *in, const char *filename ) { char *p, *q, *r; char name[FILENAME_MAX]; char mode[FILENAME_MAX]; char buf[FILENAME_MAX]; VipsForeignTiffCompression compression = VIPS_FOREIGN_TIFF_COMPRESSION_NONE; int Q = 75; VipsForeignTiffPredictor predictor = VIPS_FOREIGN_TIFF_PREDICTOR_NONE; char *profile = NULL; gboolean tile = FALSE; int tile_width = 128; int tile_height = 128; gboolean pyramid = FALSE; gboolean squash = FALSE; VipsForeignTiffResunit resunit = VIPS_FOREIGN_TIFF_RESUNIT_CM; double xres = in->Xres * 10.0; double yres = in->Yres * 10.0; gboolean bigtiff = FALSE; im_filename_split( filename, name, mode ); strcpy( buf, mode ); p = &buf[0]; if( (q = im_getnextoption( &p )) ) { if( im_isprefix( "none", q ) ) compression = VIPS_FOREIGN_TIFF_COMPRESSION_NONE; else if( im_isprefix( "packbits", q ) ) compression = VIPS_FOREIGN_TIFF_COMPRESSION_PACKBITS; else if( im_isprefix( "ccittfax4", q ) ) compression = VIPS_FOREIGN_TIFF_COMPRESSION_CCITTFAX4; else if( im_isprefix( "lzw", q ) ) { compression = VIPS_FOREIGN_TIFF_COMPRESSION_LZW; if( (r = im_getsuboption( q )) ) { int i; if( sscanf( r, "%d", &i ) != 1 ) { im_error( "im_vips2tiff", "%s", _( "bad predictor " "parameter" ) ); return( -1 ); } predictor = i; } } else if( im_isprefix( "deflate", q ) ) { compression = VIPS_FOREIGN_TIFF_COMPRESSION_DEFLATE; if( (r = im_getsuboption( q )) ) { int i; if( sscanf( r, "%d", &i ) != 1 ) { im_error( "im_vips2tiff", "%s", _( "bad predictor " "parameter" ) ); return( -1 ); } predictor = i; } } else if( im_isprefix( "jpeg", q ) ) { compression = VIPS_FOREIGN_TIFF_COMPRESSION_JPEG; if( (r = im_getsuboption( q )) ) if( sscanf( r, "%d", &Q ) != 1 ) { im_error( "im_vips2tiff", "%s", _( "bad JPEG quality " "parameter" ) ); return( -1 ); } } else { im_error( "im_vips2tiff", _( "unknown compression mode " "\"%s\"\nshould be one of \"none\", " "\"packbits\", \"ccittfax4\", \"lzw\", " "\"deflate\" or \"jpeg\"" ), q ); return( -1 ); } } if( (q = im_getnextoption( &p )) ) { if( im_isprefix( "tile", q ) ) { tile = TRUE; if( (r = im_getsuboption( q )) ) { if( sscanf( r, "%dx%d", &tile_width, &tile_height ) != 2 ) { im_error( "im_vips2tiff", "%s", _( "bad tile sizes" ) ); return( -1 ); } } } else if( im_isprefix( "strip", q ) ) tile = FALSE; else { im_error( "im_vips2tiff", _( "unknown layout mode " "\"%s\"\nshould be one of \"tile\" or " "\"strip\"" ), q ); return( -1 ); } } if( (q = im_getnextoption( &p )) ) { if( im_isprefix( "pyramid", q ) ) pyramid = TRUE; else if( im_isprefix( "flat", q ) ) pyramid = FALSE; else { im_error( "im_vips2tiff", _( "unknown multi-res mode " "\"%s\"\nshould be one of \"flat\" or " "\"pyramid\"" ), q ); return( -1 ); } } if( (q = im_getnextoption( &p )) ) { if( im_isprefix( "onebit", q ) ) squash = TRUE; else if( im_isprefix( "manybit", q ) ) squash = FALSE; else { im_error( "im_vips2tiff", _( "unknown format " "\"%s\"\nshould be one of \"onebit\" or " "\"manybit\"" ), q ); return( -1 ); } } if( (q = im_getnextoption( &p )) ) { if( im_isprefix( "res_cm", q ) ) resunit = VIPS_FOREIGN_TIFF_RESUNIT_CM; else if( im_isprefix( "res_inch", q ) ) resunit = VIPS_FOREIGN_TIFF_RESUNIT_INCH; else { im_error( "im_vips2tiff", _( "unknown resolution unit " "\"%s\"\nshould be one of \"res_cm\" or " "\"res_inch\"" ), q ); return( -1 ); } if( (r = im_getsuboption( q )) ) { if( sscanf( r, "%lfx%lf", &xres, &yres ) != 2 ) { if( sscanf( r, "%lf", &xres ) != 1 ) { im_error( "im_vips2tiff", "%s", _( "bad resolution values" ) ); return( -1 ); } yres = xres; } /* vips resolutions are always in pixels/mm. If the * user specifies ",res_inch:72x72" then they are * using pixels/inch instead and we must convert. */ if( resunit == VIPS_FOREIGN_TIFF_RESUNIT_INCH ) { xres /= 2.54; yres /= 2.54; } } } if( (q = im_getnextoption( &p )) && strcmp( q, "" ) != 0 ) profile = im_strdup( NULL, q ); if( (q = im_getnextoption( &p )) && strcmp( q, "8" ) == 0 ) bigtiff = TRUE; if( (q = im_getnextoption( &p )) ) { im_error( "im_vips2tiff", _( "unknown extra options \"%s\"" ), q ); return( -1 ); } if( vips_tiffsave( in, name, "compression", compression, "Q", Q, "predictor", predictor, "profile", profile, "tile", tile, "tile_width", tile_width, "tile_height", tile_height, "pyramid", pyramid, "squash", squash, "resunit", resunit, "xres", xres, "yres", yres, "bigtiff", bigtiff, NULL ) ) return( -1 ); return( 0 ); }