예제 #1
0
static int
vips_ifthenelse_build( VipsObject *object )
{
	VipsConversion *conversion = VIPS_CONVERSION( object );
	VipsIfthenelse *ifthenelse = (VipsIfthenelse *) object;

	VipsImage *all[3];
	VipsImage **band = (VipsImage **) vips_object_local_array( object, 3 );
	VipsImage **size = (VipsImage **) vips_object_local_array( object, 3 );
	VipsImage **format = 
		(VipsImage **) vips_object_local_array( object, 3 );

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

	/* We have to have the condition image last since we want the output
	 * image to inherit its properties from the then/else parts.
	 */
	all[0] = ifthenelse->in1;
	all[1] = ifthenelse->in2;
	all[2] = ifthenelse->cond;

	/* No need to check input images, sizealike and friends will do this
	 * for us.
	 */

	/* Cast our input images up to a common bands and size.
	 */
	if( vips__bandalike_vec( "VipsIfthenelse", all, band, 3, 0 ) ||
		vips__sizealike_vec( band, size, 3 ) )
		return( -1 );

	/* Condition is cast to uchar, then/else to a common type.
	 */
	if( vips_cast( size[2], &format[2], VIPS_FORMAT_UCHAR, NULL ) )
		return( -1 );
	if( vips__formatalike_vec( size, format, 2 ) ) 
		return( -1 ); 

	if( vips_image_copy_fields_array( conversion->out, format ) )
		return( -1 );
        vips_demand_hint_array( conversion->out, 
		VIPS_DEMAND_STYLE_SMALLTILE, format );

	if( vips_image_generate( conversion->out,
		vips_start_many, vips_ifthenelse_gen, vips_stop_many, 
		format, ifthenelse ) )
		return( -1 );

	return( 0 );
}
예제 #2
0
파일: arithmetic.c 프로젝트: imclab/libvips
int
vips__bandalike( const char *domain,
                 VipsImage *in1, VipsImage *in2, VipsImage **out1, VipsImage **out2 )
{
    VipsImage *in[2];
    VipsImage *out[2];

    in[0] = in1;
    in[1] = in2;

    if( vips__bandalike_vec( domain, in, out, 2, 1 ) )
        return( -1 );

    *out1 = out[0];
    *out2 = out[1];

    return( 0 );
}