static int vips_bandary_build( VipsObject *object ) { VipsObjectClass *object_class = VIPS_OBJECT_GET_CLASS( object ); VipsBandaryClass *class = VIPS_BANDARY_GET_CLASS( object ); VipsConversion *conversion = VIPS_CONVERSION( object ); VipsBandary *bandary = VIPS_BANDARY( object ); int i; VipsImage **decode; VipsImage **format; VipsImage **size; if( VIPS_OBJECT_CLASS( vips_bandary_parent_class )->build( object ) ) return( -1 ); if( bandary->n <= 0 ) { vips_error( object_class->nickname, "%s", _( "no input images" ) ); return( -1 ); } if( bandary->n > MAX_INPUT_IMAGES ) { vips_error( object_class->nickname, "%s", _( "too many input images" ) ); return( -1 ); } decode = (VipsImage **) vips_object_local_array( object, bandary->n ); format = (VipsImage **) vips_object_local_array( object, bandary->n ); size = (VipsImage **) vips_object_local_array( object, bandary->n ); for( i = 0; i < bandary->n; i++ ) if( vips_image_decode( bandary->in[i], &decode[i] ) ) return( -1 ); if( vips__formatalike_vec( decode, format, bandary->n ) || vips__sizealike_vec( format, size, bandary->n ) ) return( -1 ); bandary->ready = size; if( vips_image_pipeline_array( conversion->out, VIPS_DEMAND_STYLE_THINSTRIP, bandary->ready ) ) return( -1 ); conversion->out->Bands = bandary->out_bands; if( class->format_table ) conversion->out->BandFmt = class->format_table[bandary->ready[0]->BandFmt]; if( vips_image_generate( conversion->out, vips_start_many, vips_bandary_gen, vips_stop_many, bandary->ready, bandary ) ) return( -1 ); return( 0 ); }
static int vips_histogram_build( VipsObject *object ) { VipsHistogram *histogram = VIPS_HISTOGRAM( object ); VipsObjectClass *class = VIPS_OBJECT_GET_CLASS( object ); VipsHistogramClass *hclass = VIPS_HISTOGRAM_GET_CLASS( histogram ); VipsImage **decode; VipsImage **format; VipsImage **band; VipsImage **size; VipsImage **memory; VipsPel *outbuf; VipsPel **inbuf; int i; #ifdef DEBUG printf( "vips_histogram_build: " ); vips_object_print_name( object ); printf( "\n" ); #endif /*DEBUG*/ if( VIPS_OBJECT_CLASS( vips_histogram_parent_class )->build( object ) ) return( -1 ); g_assert( histogram->n > 0 ); /* Must be NULL-terminated. */ g_assert( !histogram->in[histogram->n] ); decode = (VipsImage **) vips_object_local_array( object, histogram->n ); format = (VipsImage **) vips_object_local_array( object, histogram->n ); band = (VipsImage **) vips_object_local_array( object, histogram->n ); size = (VipsImage **) vips_object_local_array( object, histogram->n ); memory = (VipsImage **) vips_object_local_array( object, histogram->n ); g_object_set( histogram, "out", vips_image_new(), NULL ); for( i = 0; i < histogram->n; i++ ) if( vips_image_decode( histogram->in[i], &decode[i] ) || vips_check_hist( class->nickname, decode[i] ) ) return( -1 ); /* Cast our input images up to a common format, bands and size. If * input_format is set, cast to a fixed input type. */ if( hclass->input_format != VIPS_FORMAT_NOTSET ) { for( i = 0; i < histogram->n; i++ ) if( vips_cast( decode[i], &format[i], hclass->input_format, NULL ) ) return( -1 ); } else { if( vips__formatalike_vec( decode, format, histogram->n ) ) return( -1 ); } if( vips__bandalike_vec( class->nickname, format, band, histogram->n, 1 ) || vips__hist_sizealike_vec( band, size, histogram->n ) ) return( -1 ); if( vips_image_pipeline_array( histogram->out, VIPS_DEMAND_STYLE_THINSTRIP, size ) ) return( -1 ); /* Need a copy of the inputs in memory. */ if( !(inbuf = VIPS_ARRAY( object, histogram->n + 1, VipsPel * )) ) return( -1 ); for( i = 0; i < histogram->n; i++ ) { if( !(memory[i] = vips_image_copy_memory( size[i] )) ) return( -1 ); inbuf[i] = VIPS_IMAGE_ADDR( memory[i], 0, 0 ); } inbuf[i] = NULL; /* Keep a copy of the memory images here for subclasses. */ histogram->ready = memory; histogram->out->Xsize = VIPS_IMAGE_N_PELS( histogram->ready[0] ); histogram->out->Ysize = 1; if( hclass->format_table ) histogram->out->BandFmt = hclass->format_table[histogram->ready[0]->BandFmt]; histogram->out->Type = VIPS_INTERPRETATION_HISTOGRAM; if( !(outbuf = vips_malloc( object, VIPS_IMAGE_SIZEOF_LINE( histogram->out ))) ) return( -1 ); hclass->process( histogram, outbuf, inbuf, histogram->ready[0]->Xsize ); if( vips_image_write_line( histogram->out, 0, outbuf ) ) return( -1 ); return( 0 ); }