Exemple #1
0
int 
im__arith_binary_const( const char *domain,
	IMAGE *in, IMAGE *out, 
	int n, double *c, VipsBandFmt vfmt,
	int format_table[10], 
	im_wrapone_fn fn1, im_wrapone_fn fnn )
{
	PEL *vector;

	if( im_piocheck( in, out ) ||
		im_check_vector( domain, n, in ) ||
		im_check_uncoded( domain, in ) )
		return( -1 );
	if( im_cp_desc( out, in ) )
		return( -1 );
	out->BandFmt = format_table[in->BandFmt];

	/* Some operations need the vector in the input type (eg.
	 * im_equal_vec() where the output type is always uchar and is useless
	 * for comparisons), some need it in the output type (eg.
	 * im_andimage_vec() where we want to get the double to an int so we
	 * can do bitwise-and without having to cast for each pixel), some
	 * need a fixed type (eg. im_powtra_vec(), where we want to keep it as
	 * double).
	 *
	 * Therefore pass in the desired vector type as a param.
	 */
	if( !(vector = make_pixel( out, vfmt, n, c )) )
		return( -1 );

	/* Band-up the input image if we have a >1 vector and
	 * a 1-band image.
	 */
	if( n > 1 && out->Bands == 1 ) {
		IMAGE *t;

		if( !(t = im_open_local( out, domain, "p" )) ||
			im__bandup( domain, in, t, n ) )
			return( -1 );

		in = t;
	}

	if( n == 1 ) {
		if( im_wrapone( in, out, fn1, vector, in ) )
			return( -1 );
	}
	else {
		if( im_wrapone( in, out, fnn, vector, in ) )
			return( -1 );
	}

	return( 0 );
}
Exemple #2
0
/* The common part of most binary inplace operators.
 *
 * Unlike im__formatalike() and friends, we can only change one of the images,
 * since the other is being updated.
 */
VipsImage *
im__inplace_base( const char *domain,
                  VipsImage *main, VipsImage *sub, VipsImage *out )
{
    VipsImage *t[2];

    if( im_rwcheck( main ) ||
            im_pincheck( sub ) ||
            im_check_coding_known( domain, main ) ||
            im_check_coding_same( domain, main, sub ) ||
            im_check_bands_1orn_unary( domain, sub, main->Bands ) )
        return( NULL );

    /* Cast sub to match main in bands and format.
     */
    if( im_open_local_array( out, t, 2, domain, "p" ) ||
            im__bandup( domain, sub, t[0], main->Bands ) ||
            im_clip2fmt( t[0], t[1], main->BandFmt ) )
        return( NULL );

    return( t[1] );
}