예제 #1
0
static int
vips_freqmult_build( VipsObject *object )
{
	VipsFreqfilt *freqfilt = VIPS_FREQFILT( object );
	VipsFreqmult *freqmult = (VipsFreqmult *) object;
	VipsImage **t = (VipsImage **) vips_object_local_array( object, 5 );

	VipsImage *in;

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

	in = freqfilt->in;

	if( vips_band_format_iscomplex( in->BandFmt ) ) {
		if( vips_multiply( in, freqmult->mask, &t[0], NULL ) ||
			vips_invfft( t[0], &t[1], "real", TRUE, NULL ) ) 
			return( -1 );

		in = t[1];
	}
	else {
		/* Optimisation: output of vips_invfft() is double, we 
		 * will usually cast to char, so rather than keeping a
		 * large double buffer and partial to char from that, 
		 * cast to a memory buffer and copy to out from that.
		 *
		 * FIXME does this actually work now we're a class? test
		 * perhaps we need a temporary object
		 */
		t[4] = vips_image_new_memory();

		if( vips_fwfft( in, &t[0], NULL ) ||
			vips_multiply( t[0], freqmult->mask, &t[1], NULL ) ||
			vips_invfft( t[1], &t[2], "real", TRUE, NULL ) ||
			vips_cast( t[2], &t[3], in->BandFmt, NULL ) ||
			vips_image_write( t[3], t[4] ) )
			return( -1 );

		in = t[4]; 
	}

	if( vips_image_write( in, freqfilt->out ) )
		return( -1 );

	return( 0 );
}
예제 #2
0
파일: smartcrop.c 프로젝트: jcupitt/libvips
/* Calculate sqrt(b1^2 + b2^2 ...)
 */
static int
pythagoras( VipsSmartcrop *smartcrop, VipsImage *in, VipsImage **out )
{
	VipsImage **t = (VipsImage **) 
		vips_object_local_array( VIPS_OBJECT( smartcrop ), 
			2 * in->Bands + 1 );

	int i;

	for( i = 0; i < in->Bands; i++ ) 
		if( vips_extract_band( in, &t[i], i, NULL ) )
			return( -1 );

	for( i = 0; i < in->Bands; i++ ) 
		if( vips_multiply( t[i], t[i], &t[i + in->Bands], NULL ) )
			return( -1 );

	if( vips_sum( &t[in->Bands], &t[2 * in->Bands], in->Bands, NULL ) ||
		vips_pow_const1( t[2 * in->Bands], out, 0.5, NULL ) )
		return( -1 );

	return( 0 );
}