/** * 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 vips__csv_write( VipsImage *in, const char *filename, const char *separator ) { FILE *fp; VipsImage *memory; if( vips_check_mono( "vips2csv", in ) || vips_check_uncoded( "vips2csv", in ) || !(memory = vips_image_copy_memory( in )) ) return( -1 ); if( !(fp = vips__file_open_write( filename, TRUE )) ) { VIPS_UNREF( memory ); return( -1 ); } if( vips2csv( memory, fp, separator ) ) { fclose( fp ); VIPS_UNREF( memory ); return( -1 ); } fclose( fp ); VIPS_UNREF( memory ); return( 0 ); }
int vips__csv_write( VipsImage *in, const char *filename, const char *separator ) { FILE *fp; if( vips_check_mono( "vips2csv", in ) || vips_check_uncoded( "vips2csv", in ) || vips_image_wio_input( in ) ) return( -1 ); if( !(fp = vips__file_open_write( filename, TRUE )) ) return( -1 ); if( vips2csv( in, fp, separator ) ) { fclose( fp ); return( -1 ); } fclose( fp ); return( 0 ); }