Exemplo n.º 1
0
static int
vips_statistic_build( VipsObject *object )
{
	VipsStatistic *statistic = VIPS_STATISTIC( object );
	VipsObjectClass *class = VIPS_OBJECT_GET_CLASS( object );
	const char *domain = class->nickname;

#ifdef DEBUG
	printf( "vips_statistic_build: " );
	vips_object_print_name( object );
	printf( "\n" );
#endif /*DEBUG*/

	if( VIPS_OBJECT_CLASS( vips_statistic_parent_class )->build( object ) )
		return( -1 );

	if( vips_image_pio_input( statistic->in ) || 
		vips_check_uncoded( domain, statistic->in ) )
		return( -1 );

	if( vips_sink( statistic->in, 
		vips_statistic_scan_start, 
		vips_statistic_scan, 
		vips_statistic_scan_stop, 
		statistic, NULL ) )
		return( -1 );

	return( 0 );
}
Exemplo n.º 2
0
int
vips__ppm_save( VipsImage *in, const char *filename, gboolean ascii )
{
	Write *write;

	if( vips_check_uintorf( "vips2ppm", in ) || 
		vips_check_bands_1or3( "vips2ppm", in ) || 
		vips_check_uncoded( "vips2ppm", in ) || 
		vips_image_pio_input( in ) )
		return( -1 );

	/* We can only write >8 bit binary images in float.
	 */
	if( vips_format_sizeof( in->BandFmt ) > 1 && 
		!ascii && 
		in->BandFmt != VIPS_FORMAT_FLOAT ) {
		vips_error( "vips2ppm", 
			"%s", _( "binary >8 bit images must be float" ) );
		return( -1 );
	}

	if( !(write = write_new( in, filename )) )
		return( -1 );

	if( write_ppm( write, ascii ) ) {
		write_destroy( write );
		return( -1 );
	}
	write_destroy( write );

	return( 0 );
}
Exemplo n.º 3
0
Arquivo: csv.c Projeto: songfj/libvips
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 );
}
Exemplo n.º 4
0
static int
vips_recomb_build( VipsObject *object )
{
	VipsConversion *conversion = (VipsConversion *) object;
	VipsRecomb *recomb = (VipsRecomb *) object;
	VipsImage **t = (VipsImage **) vips_object_local_array( object, 2 );

	if( VIPS_OBJECT_CLASS( vips_recomb_parent_class )->build( object ) )
		return( -1 );

	if( vips_image_pio_input( recomb->in ) || 
		vips_check_uncoded( "VipsRecomb", recomb->in ) ||
		vips_check_noncomplex( "VipsRecomb", recomb->in ) )
		return( -1 );
	if( vips_image_pio_input( recomb->m ) || 
		vips_check_uncoded( "VipsRecomb", recomb->m ) ||
		vips_check_noncomplex( "VipsRecomb", recomb->m ) ||
		vips_check_mono( "VipsRecomb", recomb->m ) )
		return( -1 );
	if( recomb->in->Bands != recomb->m->Xsize ) {
		vips_error( "VipsRecomb", 
			"%s", _( "bands in must equal matrix width" ) );
		return( -1 );
	}

	if( vips_cast( recomb->m, &t[0], VIPS_FORMAT_DOUBLE, NULL ) ||
		vips_image_wio_input( t[0] ) )
		return( -1 );
	recomb->coeff = (double *) VIPS_IMAGE_ADDR( t[0], 0, 0 );

	if( vips_image_copy_fields( conversion->out, recomb->in ) )
		return( -1 );
        vips_demand_hint( conversion->out, 
		VIPS_DEMAND_STYLE_THINSTRIP, recomb->in, NULL );

	conversion->out->Bands = recomb->m->Ysize;
	if( vips_bandfmt_isint( recomb->in->BandFmt ) ) 
		conversion->out->BandFmt = VIPS_FORMAT_FLOAT;

	if( vips_image_generate( conversion->out,
		vips_start_one, vips_recomb_gen, vips_stop_one, 
		recomb->in, recomb ) )
		return( -1 );

	return( 0 );
}
Exemplo n.º 5
0
static int
vips_bandary_build( VipsObject *object )
{
	VipsConversion *conversion = VIPS_CONVERSION( object );
	VipsBandary *bandary = (VipsBandary *) object;

	int i;
	VipsImage **format;
	VipsImage **size;

	if( VIPS_OBJECT_CLASS( vips_bandary_parent_class )->build( object ) )
		return( -1 );

	if( bandary->n <= 0 ) {
		vips_error( "VipsBandary", "%s", _( "no input images" ) );
		return( -1 );
	}
	if( bandary->n > MAX_INPUT_IMAGES ) {
		vips_error( "VipsBandary", "%s", _( "too many input images" ) );
		return( -1 );
	}
	if( vips_image_pio_output( conversion->out ) )
		return( -1 );
	for( i = 0; i < bandary->n; i++ )
		if( vips_image_pio_input( bandary->in[i] ) || 
			vips_check_uncoded( "VipsBandary", bandary->in[i] ) )
			return( -1 );

	format = (VipsImage **) vips_object_local_array( object, bandary->n );
	size = (VipsImage **) vips_object_local_array( object, bandary->n );
	if( vips__formatalike_vec( bandary->in, format, bandary->n ) ||
		vips__sizealike_vec( format, size, bandary->n ) )
		return( -1 );
	bandary->ready = size;

	if( vips_image_copy_fields_array( conversion->out, bandary->ready ) )
		return( -1 );
        vips_demand_hint_array( conversion->out, 
		VIPS_DEMAND_STYLE_THINSTRIP, bandary->ready );

	conversion->out->Bands = bandary->out_bands;

	if( vips_image_generate( conversion->out,
		vips_start_many, vips_bandary_gen, vips_stop_many, 
		bandary->ready, bandary ) )
		return( -1 );

	return( 0 );
}
Exemplo n.º 6
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 );
}