This commit is contained in:
John Cupitt 2009-08-31 19:59:11 +00:00
parent f0bbbbaf77
commit b2fc33313e
6 changed files with 111 additions and 91 deletions

2
TODO
View File

@ -1,4 +1,4 @@
- revising im_remainder()
- make im__math and common up code between the trig/log funcs
- 1-bit PNG read is broken?

View File

@ -17,6 +17,9 @@
* - tiny speed up
* 8/12/06
* - add liboil support
* 28/8/09
* - gtkdoc
* - tiny polish
*/
/*

View File

@ -251,9 +251,9 @@ static int bandfmt_add[10] = {
/**
* im_add:
* @in1: input image 1
* @in2: input image 2
* @out: output image
* @in1: input #IMAGE 1
* @in2: input #IMAGE 2
* @out: output #IMAGE
*
* This operation calculates @in1 + @in2 and writes the result to @out.
* The images must be the same size. They may have any format.

View File

@ -1,14 +1,10 @@
/* @(#) ceil() an image ... no promotion, so output type == input type
* @(#)
* @(#) int
* @(#) im_ceil( in, out )
* @(#) IMAGE *in, *out;
* @(#)
* @(#) Returns 0 on success and -1 on error
* @(#)
/* im_ceil.c
*
* 20/6/02 JC
* - adapted from im_abs()
* 29/8/09
* - gtkdoc
* - tiny cleanups
*/
/*
@ -45,7 +41,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>
#include <vips/vips.h>
@ -53,35 +48,54 @@
#include <dmalloc.h>
#endif /*WITH_DMALLOC*/
#define ceil_loop(TYPE)\
{\
TYPE *p = (TYPE *) in;\
TYPE *q = (TYPE *) out;\
\
for( x = 0; x < sz; x++ )\
q[x] = ceil( p[x] );\
}
#define LOOP( TYPE ) { \
TYPE *p = (TYPE *) in; \
TYPE *q = (TYPE *) out; \
\
for( x = 0; x < sz; x++ ) \
q[x] = ceil( p[x] ); \
}
/* Ceil a buffer of PELs.
*/
static void
ceil_gen( PEL *in, PEL *out, int width, IMAGE *im )
{
/* Complex just doubles the size.
*/
const int sz = width * im->Bands * (im_iscomplex( im ) ? 2 : 1);
int x;
int sz = width * im->Bands;
switch( im->BandFmt ) {
case IM_BANDFMT_FLOAT: ceil_loop(float); break;
case IM_BANDFMT_DOUBLE: ceil_loop(double); break;
case IM_BANDFMT_COMPLEX: sz *= 2; ceil_loop(float); break;
case IM_BANDFMT_DPCOMPLEX: sz *= 2; ceil_loop(double); break;
case IM_BANDFMT_COMPLEX:
case IM_BANDFMT_FLOAT:
LOOP( float );
break;
case IM_BANDFMT_DOUBLE:
case IM_BANDFMT_DPCOMPLEX:
LOOP( double );
break;
default:
assert( 0 );
g_assert( 0 );
}
}
/* Ceil of image.
/**
* im_ceil:
* @in: input #IMAGE
* @out: output #IMAGE
*
* For each pixel, find the smallest integral value not less than.
* Copy for integer types, call <function>ceil(3)</function> for float and
* complex types.
* Output type == input type.
*
* See also: im_floor(), im_rint(), im_clip2fmt()
*
* Returns: 0 on success, -1 on error
*/
int
im_ceil( IMAGE *in, IMAGE *out )

View File

@ -1,16 +1,4 @@
/* @(#) Multiplies two complex images. complex output is normalised to 1
* @(#) Inputs can be complex double or complex float
* @(#) Result (double complex or float complex) depends on inputs
* @(#) Function im_cmulnorm() assumes that the both input files
* @(#) are either memory mapped or in a buffer.
* @(#) Images must have the same no of bands and must be complex
* @(#) No check for overflow is carried out.
* @(#)
* @(#) int im_cmulnorm(in1, in2, out)
* @(#) IMAGE *in1, *in2, *out;
* @(#)
* @(#) Returns 0 on success and -1 on error
* @(#)
/* im_cmulnorm.c
*
* Copyright: 1990, N. Dessipris.
*
@ -21,6 +9,9 @@
* - thrown away and redone in terms of im_multiply()
* 9/7/02 JC
* - im_sign() broken out, done in terms of that
* 28/8/09
* - gtkdoc
* - tiny polish
*/
/*
@ -63,12 +54,31 @@
#include <dmalloc.h>
#endif /*WITH_DMALLOC*/
/**
* im_cmulnorm
* @in1: input #IMAGE 1
* @in2: input #IMAGE 2
* @out: output #IMAGE
*
* im_cmulnorm() multiplies two complex images. The complex output is
* normalised to 1 by dividing both the real and the imaginary part of each
* pel with the norm. This is useful for phase correlation.
*
* This operation used to be important, but now simply calls im_multiply()
* then im_sign().
*
* See also: im_multiply(), im_sign().
*
* Returns: 0 on success, -1 on error
*/
int
im_cmulnorm( IMAGE *in1, IMAGE *in2, IMAGE *out )
{
IMAGE *t1 = im_open_local( out, "im_cmulnorm:1", "p" );
IMAGE *t1;
if( !t1 || im_multiply( in1, in2, t1 ) || im_sign( t1, out ) )
if( !(t1 = im_open_local( out, "im_cmulnorm:1", "p" )) ||
im_multiply( in1, in2, t1 ) ||
im_sign( t1, out ) )
return( -1 );
return( 0 );

View File

@ -1,12 +1,4 @@
/* @(#) Find cos of any non-complex image. Output is always float for integer
* @(#) input and double for double input. All angles in degrees.
* @(#)
* @(#) int
* @(#) im_costra( in, out )
* @(#) IMAGE *in, *out;
* @(#)
* @(#) Returns 0 on success and -1 on error
* @(#)
/* im_costra
*
* Copyright: 1990, N. Dessipris, based on im_powtra()
* Author: Nicos Dessipris
@ -23,6 +15,9 @@
* - adapted for im_wrapone()
* 26/1/96 JC
* - im_acostra() added
* 30/8/09
* - gtkdoc
* - tiny cleanups
*/
/*
@ -83,8 +78,9 @@
static void
costra_gen( PEL *in, PEL *out, int width, IMAGE *im )
{
const int sz = width * im->Bands;
int x;
int sz = width * im->Bands;
/* Switch for all input types.
*/
@ -99,11 +95,22 @@ costra_gen( PEL *in, PEL *out, int width, IMAGE *im )
case IM_BANDFMT_DOUBLE: loop( double, double ); break;
default:
assert( 0 );
g_assert( 0 );
}
}
/* Cos transform.
/**
* im_costra
* @in: input #IMAGE
* @out: output #IMAGE
*
* For each pixel, call <function>cos(3)</function> (cosine). Angles are
* expressed in degrees. The output type is float, unless the input is
* double, in which case the output is double. Non-complex images only.
*
* See also: im_acostra(), im_sintra(), im_tantra().
*
* Returns: 0 on success, -1 on error
*/
int
im_costra( IMAGE *in, IMAGE *out )
@ -117,23 +124,9 @@ im_costra( IMAGE *in, IMAGE *out )
*/
if( im_cp_desc( out, in ) )
return( -1 );
switch( in->BandFmt ) {
case IM_BANDFMT_UCHAR:
case IM_BANDFMT_CHAR:
case IM_BANDFMT_USHORT:
case IM_BANDFMT_SHORT:
case IM_BANDFMT_UINT:
case IM_BANDFMT_INT:
out->Bbits = IM_BBITS_FLOAT;
out->BandFmt = IM_BANDFMT_FLOAT;
break;
case IM_BANDFMT_FLOAT:
case IM_BANDFMT_DOUBLE:
break;
default:
assert( 0 );
if( im_isint( in ) ) {
out->Bbits = IM_BBITS_FLOAT;
out->BandFmt = IM_BANDFMT_FLOAT;
}
/* Generate!
@ -159,8 +152,9 @@ im_costra( IMAGE *in, IMAGE *out )
static void
acostra_gen( PEL *in, PEL *out, int width, IMAGE *im )
{
const int sz = width * im->Bands;
int x;
int sz = width * im->Bands;
/* Switch for all input types.
*/
@ -179,7 +173,20 @@ acostra_gen( PEL *in, PEL *out, int width, IMAGE *im )
}
}
/* Acos transform.
/**
* im_acostra
* @in: input #IMAGE
* @out: output #IMAGE
*
* For each pixel, call <function>acos(3)</function> (arc or inverse cosine).
* Angles are expressed in
* degrees. The output type is float, unless the input is double, in which
* case the output is double. Non-complex images only.
*
* See also: im_costra(), im_asintra(), im_atantra().
*
* Returns: 0 on success, -1 on error
*/
int
im_acostra( IMAGE *in, IMAGE *out )
@ -193,23 +200,9 @@ im_acostra( IMAGE *in, IMAGE *out )
*/
if( im_cp_desc( out, in ) )
return( -1 );
switch( in->BandFmt ) {
case IM_BANDFMT_UCHAR:
case IM_BANDFMT_CHAR:
case IM_BANDFMT_USHORT:
case IM_BANDFMT_SHORT:
case IM_BANDFMT_UINT:
case IM_BANDFMT_INT:
out->Bbits = IM_BBITS_FLOAT;
out->BandFmt = IM_BANDFMT_FLOAT;
break;
case IM_BANDFMT_FLOAT:
case IM_BANDFMT_DOUBLE:
break;
default:
assert( 0 );
if( im_isint( in ) ) {
out->Bbits = IM_BBITS_FLOAT;
out->BandFmt = IM_BANDFMT_FLOAT;
}
/* Generate!