im_ri2c() gtkdoc

This commit is contained in:
John Cupitt 2010-02-01 17:25:27 +00:00
parent 66106832a9
commit e79555000b
3 changed files with 82 additions and 90 deletions

View File

@ -32,6 +32,7 @@
- finally removed old flood stuff - finally removed old flood stuff
- im_insert*() bandalike and formatalike - im_insert*() bandalike and formatalike
- im_*join() bandalike and formatalike - im_*join() bandalike and formatalike
- im_ri2c() bandalike
26/11/09 started 7.20.3 26/11/09 started 7.20.3
- updated en_GB.po translation - updated en_GB.po translation

View File

@ -321,8 +321,8 @@ static int bandfmt_add[10] = {
/** /**
* im_add: * im_add:
* @in1: input image 1 * @in1: input image
* @in2: input image 2 * @in2: input image
* @out: output image * @out: output image
* *
* This operation calculates @in1 + @in2 and writes the result to @out. * This operation calculates @in1 + @in2 and writes the result to @out.

View File

@ -1,15 +1,16 @@
/* @(#) Join two images to make a complex. If one of the inputs /* im_ri2c
* @(#) is a double, the output is IM_BANDFMT_DPCOMPLEX, otherwise it is IM_BANDFMT_COMPLEX. *
* @(#)
* @(#) im_ri2c( IMAGE *in1, IMAGE *in2, IMAGE *out )
* @(#)
* @(#) Returns: -1 on error, else 0
* Author: Nicos Dessipris * Author: Nicos Dessipris
* Written on: 12/02/1990 * Written on: 12/02/1990
* Modified on : 10/04/1990 * Modified on : 10/04/1990
* 16/11/94 JC * 16/11/94 JC
* - rewritten with partials * - rewritten with partials
* - more general * - more general
* 1/2/10
* - bandalike
* - better upcasting
* - gtkdoc
* - cleanups
*/ */
/* /*
@ -47,122 +48,112 @@
#include <math.h> #include <math.h>
#include <vips/vips.h> #include <vips/vips.h>
#include <vips/internal.h>
#ifdef WITH_DMALLOC #ifdef WITH_DMALLOC
#include <dmalloc.h> #include <dmalloc.h>
#endif /*WITH_DMALLOC*/ #endif /*WITH_DMALLOC*/
/* Join two float buffers to make a complex. #define JOIN( TYPE ) { \
TYPE *p1 = (TYPE *) p[0]; \
TYPE *p2 = (TYPE *) p[1]; \
TYPE *q0 = (TYPE *) q; \
\
for( x = 0; x < len; x++ ) { \
q0[0] = *p1++; \
q0[1] = *p2++; \
\
q0 += 2; \
} \
}
/* Join two buffers to make a complex.
*/ */
static void static void
join_float( float **p, float *q, int n, IMAGE *im ) join_buffer( PEL **p, PEL *q, int n, IMAGE *im )
{ {
int x; int x;
int len = n * im->Bands; int len = n * im->Bands;
float *p1 = p[0];
float *p2 = p[1];
for( x = 0; x < len; x++ ) { switch( im->BandFmt ) {
q[0] = *p1++; case IM_BANDFMT_FLOAT:
q[1] = *p2++; JOIN( float );
break;
q += 2; case IM_BANDFMT_DOUBLE:
JOIN( double );
break;
default:
g_assert( 0 );
} }
} }
/* Join two double buffers to make a complex. /**
* im_ri2c:
* @in1: input image
* @in2: input image
* @out: output image
*
* Compose two real images to make a complex image. If either @in1 or @in2 are
* %IM_BANDFMT_DOUBLE, @out is %IM_BANDFMT_DPCOMPLEX. Otherwise @out is
* %IM_BANDFMT_COMPLEX.
*
* If the number of bands differs, one of the images
* must have one band. In this case, an n-band image is formed from the
* one-band image by joining n copies of the one-band image together, and then
* the two n-band images are operated upon.
*
* The two input images are cast up to the smallest common type (see table
* Smallest common format in
* <link linkend="VIPS-arithmetic">arithmetic</link>).
*
* See also: im_c2real(), im_c2imag().
*
* Returns: 0 on success, -1 on error
*/ */
static void
join_double( double **p, double *q, int n, IMAGE *im )
{
int x;
int len = n * im->Bands;
double *p1 = p[0];
double *p2 = p[1];
for( x = 0; x < len; x++ ) {
q[0] = *p1++;
q[1] = *p2++;
q += 2;
}
}
/* Type conversion.
*/
static IMAGE *
convert( IMAGE *out, IMAGE *in, int (*cvt_fn)( IMAGE *, IMAGE * ) )
{
IMAGE *t1 = im_open_local( out, "Type conversion", "p" );
if( !t1 )
return( NULL );
if( cvt_fn( in, t1 ) )
return( NULL );
return( t1 );
}
int int
im_ri2c( IMAGE *in1, IMAGE *in2, IMAGE *out ) im_ri2c( IMAGE *in1, IMAGE *in2, IMAGE *out )
{ {
IMAGE *invec[3]; IMAGE *t[5];
extern int im_clip2f( IMAGE *, IMAGE * ); VipsBandFmt fmt;
extern int im_clip2d( IMAGE *, IMAGE * );
/* Check input image. We don't need to check that sizes match -- /* Check input image. We don't need to check that sizes match --
* im_wrapmany does this for us. * im_wrapmany does this for us.
*/ */
if( in1->Coding != IM_CODING_NONE || if( im_check_uncoded( "im_ri2c", in1 ) ||
in2->Coding != IM_CODING_NONE ) { im_check_uncoded( "im_ri2c", in2 ) ||
im_error( "im_ri2c", "%s", _( "inputs should be uncoded" ) ); im_check_noncomplex( "im_ri2c", in1 ) ||
im_check_noncomplex( "im_ri2c", in2 ) ||
im_check_bands_1orn( "im_ri2c", in1, in2 ) )
return( -1 ); return( -1 );
}
if( vips_bandfmt_iscomplex( in1->BandFmt ) ||
vips_bandfmt_iscomplex( in2->BandFmt ) ) {
im_error( "im_ri2c", "%s", _( "inputs already complex" ) );
return( -1 );
}
/* Prepare the output image. If either of the inputs is DOUBLE, we are /* If either of the inputs is DOUBLE, we are
* DPCOMPLEX; otherwise we are COMPLEX. * DPCOMPLEX; otherwise we are COMPLEX.
*/ */
if( im_cp_descv( out, in1, in2, NULL ) )
return( -1 );
if( in1->BandFmt == IM_BANDFMT_DOUBLE || if( in1->BandFmt == IM_BANDFMT_DOUBLE ||
in2->BandFmt == IM_BANDFMT_DOUBLE ) in2->BandFmt == IM_BANDFMT_DOUBLE )
out->BandFmt = IM_BANDFMT_DPCOMPLEX; fmt = IM_BANDFMT_DOUBLE;
else else
out->BandFmt = IM_BANDFMT_COMPLEX; fmt = IM_BANDFMT_FLOAT;
/* Float inputs up to correct type. Note that if they are already the if( im_open_local_array( out, t, 4, "im_ri2c", "p" ) ||
* right type, this operation becomes a NOOP. im_clip2fmt( in1, t[0], fmt ) ||
*/ im_clip2fmt( in2, t[1], fmt ) ||
if( out->BandFmt == IM_BANDFMT_COMPLEX ) { im__bandalike( t[0], t[1], t[2], t[3] ) )
in1 = convert( out, in1, im_clip2f );
in2 = convert( out, in2, im_clip2f );
}
else {
in1 = convert( out, in1, im_clip2d );
in2 = convert( out, in2, im_clip2d );
}
if( !in1 || !in2 )
return( -1 ); return( -1 );
/* Process! /* Remember to NULL-terminate.
*/ */
invec[0] = in1; invec[1] = in2; invec[2] = NULL; t[4] = NULL;
if( out->BandFmt == IM_BANDFMT_COMPLEX ) {
if( im_wrapmany( invec, out, if( im_cp_descv( out, t[2], t[3], NULL ) )
(im_wrapmany_fn) join_float, out, NULL ) ) return( -1 );
return( -1 ); out->BandFmt = fmt == IM_BANDFMT_DOUBLE ?
} IM_BANDFMT_DPCOMPLEX : IM_BANDFMT_COMPLEX;
else {
if( im_wrapmany( invec, out, if( im_wrapmany( t + 2, out, (im_wrapmany_fn) join_buffer, out, NULL ) )
(im_wrapmany_fn) join_double, out, NULL ) ) return( -1 );
return( -1 );
}
return( 0 ); return( 0 );
} }