gtkdoc stuff

This commit is contained in:
John Cupitt 2009-09-01 15:52:11 +00:00
parent 0534e5563d
commit 6e2679ba5b
8 changed files with 479 additions and 595 deletions

View File

@ -18,6 +18,7 @@
* 30/8/09
* - gtkdoc
* - tiny cleanups
* - make im__math(), share with other math-style functions
*/
/*
@ -54,7 +55,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>
#include <vips/vips.h>
@ -65,7 +65,7 @@
/* Define what we do for each band element type. Non-complex input, any
* output.
*/
#define loop( IN, OUT ) { \
#define COS( IN, OUT ) { \
IN *p = (IN *) in; \
OUT *q = (OUT *) out; \
\
@ -85,20 +85,44 @@ costra_gen( PEL *in, PEL *out, int width, IMAGE *im )
/* Switch for all input types.
*/
switch( im->BandFmt ) {
case IM_BANDFMT_UCHAR: loop( unsigned char, float ); break;
case IM_BANDFMT_CHAR: loop( signed char, float ); break;
case IM_BANDFMT_USHORT: loop( unsigned short, float ); break;
case IM_BANDFMT_SHORT: loop( signed short, float ); break;
case IM_BANDFMT_UINT: loop( unsigned int, float ); break;
case IM_BANDFMT_INT: loop( signed int, float ); break;
case IM_BANDFMT_FLOAT: loop( float, float ); break;
case IM_BANDFMT_DOUBLE: loop( double, double ); break;
case IM_BANDFMT_UCHAR: COS( unsigned char, float ); break;
case IM_BANDFMT_CHAR: COS( signed char, float ); break;
case IM_BANDFMT_USHORT: COS( unsigned short, float ); break;
case IM_BANDFMT_SHORT: COS( signed short, float ); break;
case IM_BANDFMT_UINT: COS( unsigned int, float ); break;
case IM_BANDFMT_INT: COS( signed int, float ); break;
case IM_BANDFMT_FLOAT: COS( float, float ); break;
case IM_BANDFMT_DOUBLE: COS( double, double ); break;
default:
g_assert( 0 );
}
}
/* Do a math (eg. sin(), acos(), log()) type-function. No complex, everything
* goes to float except double.
*/
int
im__math( const char *name, IMAGE *in, IMAGE *out, im_wrapone_fn gen )
{
if( im_piocheck( in, out ) ||
im_check_uncoded( name, in ) ||
im_check_noncomplex( name, in ) )
return( -1 );
if( im_cp_desc( out, in ) )
return( -1 );
if( im_isint( in ) ) {
out->Bbits = IM_BBITS_FLOAT;
out->BandFmt = IM_BANDFMT_FLOAT;
}
if( im_wrapone( in, out, gen, in, NULL ) )
return( -1 );
return( 0 );
}
/**
* im_costra
* @in: input #IMAGE
@ -114,32 +138,13 @@ costra_gen( PEL *in, PEL *out, int width, IMAGE *im )
*/
int
im_costra( IMAGE *in, IMAGE *out )
{
if( im_piocheck( in, out ) ||
im_check_uncoded( "im_costra", in ) ||
im_check_noncomplex( "im_costra", in ) )
return( -1 );
/* Prepare output header.
*/
if( im_cp_desc( out, in ) )
return( -1 );
if( im_isint( in ) ) {
out->Bbits = IM_BBITS_FLOAT;
out->BandFmt = IM_BANDFMT_FLOAT;
}
/* Generate!
*/
if( im_wrapone( in, out, (im_wrapone_fn) costra_gen, in, NULL ) )
return( -1 );
return( 0 );
{
return( im__math( "im_costra", in, out, (im_wrapone_fn) costra_gen ) );
}
/* And acos().
*/
#define aloop( IN, OUT ) { \
#define ACOS( IN, OUT ) { \
IN *p = (IN *) in; \
OUT *q = (OUT *) out; \
\
@ -159,17 +164,17 @@ acostra_gen( PEL *in, PEL *out, int width, IMAGE *im )
/* Switch for all input types.
*/
switch( im->BandFmt ) {
case IM_BANDFMT_UCHAR: aloop( unsigned char, float ); break;
case IM_BANDFMT_CHAR: aloop( signed char, float ); break;
case IM_BANDFMT_USHORT: aloop( unsigned short, float ); break;
case IM_BANDFMT_SHORT: aloop( signed short, float ); break;
case IM_BANDFMT_UINT: aloop( unsigned int, float ); break;
case IM_BANDFMT_INT: aloop( signed int, float ); break;
case IM_BANDFMT_FLOAT: aloop( float, float ); break;
case IM_BANDFMT_DOUBLE: aloop( double, double ); break;
case IM_BANDFMT_UCHAR: ACOS( unsigned char, float ); break;
case IM_BANDFMT_CHAR: ACOS( signed char, float ); break;
case IM_BANDFMT_USHORT: ACOS( unsigned short, float ); break;
case IM_BANDFMT_SHORT: ACOS( signed short, float ); break;
case IM_BANDFMT_UINT: ACOS( unsigned int, float ); break;
case IM_BANDFMT_INT: ACOS( signed int, float ); break;
case IM_BANDFMT_FLOAT: ACOS( float, float ); break;
case IM_BANDFMT_DOUBLE: ACOS( double, double ); break;
default:
assert( 0 );
g_assert( 0 );
}
}
@ -191,24 +196,6 @@ acostra_gen( PEL *in, PEL *out, int width, IMAGE *im )
int
im_acostra( IMAGE *in, IMAGE *out )
{
if( im_piocheck( in, out ) ||
im_check_uncoded( "im_acostra", in ) ||
im_check_noncomplex( "im_acostra", in ) )
return( -1 );
/* Prepare output header.
*/
if( im_cp_desc( out, in ) )
return( -1 );
if( im_isint( in ) ) {
out->Bbits = IM_BBITS_FLOAT;
out->BandFmt = IM_BANDFMT_FLOAT;
}
/* Generate!
*/
if( im_wrapone( in, out, (im_wrapone_fn) acostra_gen, in, NULL ) )
return( -1 );
return( 0 );
return( im__math( "im_acostra", in, out,
(im_wrapone_fn) acostra_gen ) );
}

View File

@ -28,6 +28,9 @@
* - M_E removed, as not everywhere
* 6/7/98 JC
* - _vec version added
* 30/8/09
* - gtkdoc
* - tiny cleanups
*/
/*
@ -63,9 +66,9 @@
#include <stdio.h>
#include <math.h>
#include <assert.h>
#include <vips/vips.h>
#include <vips/internal.h>
#ifdef WITH_DMALLOC
#include <dmalloc.h>
@ -80,18 +83,17 @@ typedef struct {
/* Define what we do for each band element type. Single constant.
*/
#define loop1(IN, OUT) { \
#define POW1( IN, OUT ) { \
IN *p = (IN *) in; \
OUT *q = (OUT *) out; \
\
for( x = 0; x < sz; x++ ) { \
double f = (double) p[x]; \
\
if( e == 0.0 && f < 0.0 ) { \
if( e == 0.0 && f < 0.0 ) \
/* Division by zero! Difficult to report tho' \
*/ \
q[x] = 0.0; \
} \
else \
q[x] = pow( e, f ); \
} \
@ -102,24 +104,25 @@ typedef struct {
static int
expntra1_gen( PEL *in, PEL *out, int width, IMAGE *im, ExpntraInfo *inf )
{
int sz = width * im->Bands;
double e = inf->e[0];
const int sz = width * im->Bands;
const double e = inf->e[0];
int x;
/* Expntra all non-complex input types.
*/
switch( im->BandFmt ) {
case IM_BANDFMT_UCHAR: loop1(unsigned char, float); break;
case IM_BANDFMT_CHAR: loop1(signed char, float); break;
case IM_BANDFMT_USHORT: loop1(unsigned short, float); break;
case IM_BANDFMT_SHORT: loop1(signed short, float); break;
case IM_BANDFMT_UINT: loop1(unsigned int, float); break;
case IM_BANDFMT_INT: loop1(signed int, float); break;
case IM_BANDFMT_FLOAT: loop1(float, float); break;
case IM_BANDFMT_DOUBLE: loop1(double, double); break;
case IM_BANDFMT_UCHAR: POW1( unsigned char, float ); break;
case IM_BANDFMT_CHAR: POW1( signed char, float ); break;
case IM_BANDFMT_USHORT: POW1( unsigned short, float ); break;
case IM_BANDFMT_SHORT: POW1( signed short, float ); break;
case IM_BANDFMT_UINT: POW1( unsigned int, float ); break;
case IM_BANDFMT_INT: POW1( signed int, float ); break;
case IM_BANDFMT_FLOAT: POW1( float, float ); break;
case IM_BANDFMT_DOUBLE: POW1( double, double ); break;
default:
assert( 0 );
g_assert( 0 );
}
return( 0 );
@ -127,7 +130,7 @@ expntra1_gen( PEL *in, PEL *out, int width, IMAGE *im, ExpntraInfo *inf )
/* Define what we do for each band element type. One constant per band.
*/
#define loopn(IN, OUT) { \
#define POWN( IN, OUT ) { \
IN *p = (IN *) in; \
OUT *q = (OUT *) out; \
\
@ -136,9 +139,8 @@ expntra1_gen( PEL *in, PEL *out, int width, IMAGE *im, ExpntraInfo *inf )
double e = inf->e[k]; \
double f = (double) p[i]; \
\
if( e == 0.0 && f < 0.0 ) { \
if( e == 0.0 && f < 0.0 ) \
q[i] = 0.0; \
} \
else \
q[i] = pow( e, f ); \
} \
@ -154,22 +156,43 @@ expntran_gen( PEL *in, PEL *out, int width, IMAGE *im, ExpntraInfo *inf )
/* Expntra all non-complex input types.
*/
switch( im->BandFmt ) {
case IM_BANDFMT_UCHAR: loopn(unsigned char, float); break;
case IM_BANDFMT_CHAR: loopn(signed char, float); break;
case IM_BANDFMT_USHORT: loopn(unsigned short, float); break;
case IM_BANDFMT_SHORT: loopn(signed short, float); break;
case IM_BANDFMT_UINT: loopn(unsigned int, float); break;
case IM_BANDFMT_INT: loopn(signed int, float); break;
case IM_BANDFMT_FLOAT: loopn(float, float); break;
case IM_BANDFMT_DOUBLE: loopn(double, double); break;
case IM_BANDFMT_UCHAR: POWN( unsigned char, float ); break;
case IM_BANDFMT_CHAR: POWN( signed char, float ); break;
case IM_BANDFMT_USHORT: POWN( unsigned short, float ); break;
case IM_BANDFMT_SHORT: POWN( signed short, float ); break;
case IM_BANDFMT_UINT: POWN( unsigned int, float ); break;
case IM_BANDFMT_INT: POWN( signed int, float ); break;
case IM_BANDFMT_FLOAT: POWN( float, float ); break;
case IM_BANDFMT_DOUBLE: POWN( double, double ); break;
default:
assert( 0 );
g_assert( 0 );
}
return( 0 );
}
/**
* im_expntra_vec:
* @in: input #IMAGE
* @out: output #IMAGE
* @n: number of elements in array
* @b: array of constants
*
* im_expntra_vec() transforms element x of input to
* <function>pow</function>(@b, x) in output.
* It detects division by zero, setting those pixels to zero in the output.
* Beware: it does this silently!
*
* If the array of constants has one element, that constant is used for each
* image band. If the array has more than one element, it must have the same
* number of elements as there are bands in the image, and one array element
* is used for each band.
*
* See also: im_logtra(), im_powtra()
*
* Returns: 0 on success, -1 on error
*/
int
im_expntra_vec( IMAGE *in, IMAGE *out, int n, double *e )
{
@ -177,8 +200,8 @@ im_expntra_vec( IMAGE *in, IMAGE *out, int n, double *e )
int i;
if( im_piocheck( in, out ) ||
im_check_uncoded( "im_expntra", in ) ||
im_check_noncomplex( "im_expntra", in ) ||
im_check_uncoded( "im_expntra_vec", in ) ||
im_check_noncomplex( "im_expntra_vec", in ) ||
im_check_vector( "im_expntra_vec", n, in ) )
return( -1 );
@ -216,13 +239,40 @@ im_expntra_vec( IMAGE *in, IMAGE *out, int n, double *e )
return( 0 );
}
/**
* im_expntra:
* @in: input #IMAGE
* @out: output #IMAGE
* @b: base
*
* im_expntra() transforms element x of input to
* <function>pow</function>(@b, x) in output.
* It detects division by zero, setting those pixels to zero in the output.
* Beware: it does this silently!
*
* See also: im_logtra(), im_powtra()
*
* Returns: 0 on success, -1 on error
*/
int
im_expntra( IMAGE *in, IMAGE *out, double e )
im_expntra( IMAGE *in, IMAGE *out, double b )
{
return( im_expntra_vec( in, out, 1, &e ) );
return( im_expntra_vec( in, out, 1, &b ) );
}
/* Define im_exptra() and im_exp10tra() in terms of im_expntra().
/**
* im_exptra:
* @in: input #IMAGE
* @out: output #IMAGE
*
* im_exptra() transforms element x of input to
* <function>pow</function>(e, x) in output.
* It detects division by zero, setting those pixels to zero in the output.
* Beware: it does this silently!
*
* See also: im_logtra(), im_powtra()
*
* Returns: 0 on success, -1 on error
*/
int
im_exptra( IMAGE *in, IMAGE *out )
@ -230,6 +280,20 @@ im_exptra( IMAGE *in, IMAGE *out )
return( im_expntra( in, out, 2.7182818284590452354 ) );
}
/**
* im_exp10tra:
* @in: input #IMAGE
* @out: output #IMAGE
*
* im_exptra() transforms element x of input to
* <function>pow</function>(10, x) in output.
* It detects division by zero, setting those pixels to zero in the output.
* Beware: it does this silently!
*
* See also: im_logtra(), im_powtra()
*
* Returns: 0 on success, -1 on error
*/
int
im_exp10tra( IMAGE *in, IMAGE *out )
{

View File

@ -18,6 +18,10 @@
* 1/7/93 JC
* - adapted for partial v2
* - ANSIfied
* 30/8/09
* - gtkdoc
* - tiny cleanups
* - use im__math()
*/
/*
@ -54,9 +58,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>
#include <vips/vips.h>
#include <vips/internal.h>
#ifdef WITH_DMALLOC
#include <dmalloc.h>
@ -65,103 +69,56 @@
/* Define what we do for each band element type. Non-complex input, any
* output.
*/
#define loop(IN, OUT)\
for( y = to; y < bo; y++ ) {\
IN *p = (IN *) IM_REGION_ADDR( ir, le, y );\
OUT *q = (OUT *) IM_REGION_ADDR( or, le, y );\
\
for( x = 0; x < sz; x++ )\
*q++ = log10( *p++ );\
}
/* log10tra a small area.
*/
static int
log10tra_gen( REGION *or, void *seq, void *a, void *b )
{
REGION *ir = (REGION *) seq;
Rect *r = &or->valid;
int le = r->left;
int to = r->top;
int bo = IM_RECT_BOTTOM(r);
int sz = IM_REGION_N_ELEMENTS( or );
int x, y;
/* Ask for input we need.
*/
if( im_prepare( ir, r ) )
return( -1 );
/* log10tra all input types.
*/
switch( ir->im->BandFmt ) {
case IM_BANDFMT_UCHAR: loop(unsigned char, float); break;
case IM_BANDFMT_CHAR: loop(signed char, float); break;
case IM_BANDFMT_USHORT: loop(unsigned short, float); break;
case IM_BANDFMT_SHORT: loop(signed short, float); break;
case IM_BANDFMT_UINT: loop(unsigned int, float); break;
case IM_BANDFMT_INT: loop(signed int, float); break;
case IM_BANDFMT_FLOAT: loop(float, float); break;
case IM_BANDFMT_DOUBLE: loop(double, double); break;
default:
assert( 0 );
}
return( 0 );
#define LOG10( IN, OUT ) { \
IN *p = (IN *) in; \
OUT *q = (OUT *) out; \
\
for( x = 0; x < sz; x++ ) \
q[x] = log10( p[x] ); \
}
/* Log 10 transform.
/* log10() a buffer of PELs.
*/
static void
log10tra_gen( PEL *in, PEL *out, int width, IMAGE *im )
{
const int sz = width * im->Bands;
int x;
/* Switch for all input types.
*/
switch( im->BandFmt ) {
case IM_BANDFMT_UCHAR: LOG10( unsigned char, float ); break;
case IM_BANDFMT_CHAR: LOG10( signed char, float ); break;
case IM_BANDFMT_USHORT: LOG10( unsigned short, float ); break;
case IM_BANDFMT_SHORT: LOG10( signed short, float ); break;
case IM_BANDFMT_UINT: LOG10( unsigned int, float ); break;
case IM_BANDFMT_INT: LOG10( signed int, float ); break;
case IM_BANDFMT_FLOAT: LOG10( float, float ); break;
case IM_BANDFMT_DOUBLE: LOG10( double, double ); break;
default:
g_assert( 0 );
}
}
/**
* im_log10tra
* @in: input #IMAGE
* @out: output #IMAGE
*
* For each pixel, call <function>log10(3)</function> (base 10 logarithm).
* The output type is float, unless the input is
* double, in which case the output is double. Non-complex images only.
*
* See also: im_exp10tra(), im_logntra(), im_sintra().
*
* Returns: 0 on success, -1 on error
*/
int
im_log10tra( IMAGE *in, IMAGE *out )
{
/* Check args.
*/
if( im_piocheck( in, out ) )
return( -1 );
if( in->Coding != IM_CODING_NONE ) {
im_error( "im_log10tra", "%s", _( "not uncoded" ) );
return( -1 );
}
if( im_iscomplex( in ) ) {
im_error( "im_log10tra", "%s", _( "not non-complex" ) );
return( -1 );
}
/* Prepare output header.
*/
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 );
}
/* Set demand hints.
*/
if( im_demand_hint( out, IM_THINSTRIP, in, NULL ) )
return( -1 );
/* Generate!
*/
if( im_generate( out,
im_start_one, log10tra_gen, im_stop_one, in, NULL ) )
return( -1 );
return( 0 );
{
return( im__math( "im_log10tra", in, out,
(im_wrapone_fn) log10tra_gen ) );
}

View File

@ -18,6 +18,10 @@
* 1/7/93 JC
* - adapted for partial v2
* - ANSIfied
* 30/8/09
* - gtkdoc
* - tiny cleanups
* - use im__math()
*/
/*
@ -54,9 +58,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>
#include <vips/vips.h>
#include <vips/internal.h>
#ifdef WITH_DMALLOC
#include <dmalloc.h>
@ -65,103 +69,56 @@
/* Define what we do for each band element type. Non-complex input, any
* output.
*/
#define loop(IN, OUT)\
for( y = to; y < bo; y++ ) {\
IN *p = (IN *) IM_REGION_ADDR( ir, le, y );\
OUT *q = (OUT *) IM_REGION_ADDR( or, le, y );\
\
for( x = 0; x < sz; x++ )\
*q++ = log( *p++ );\
}
/* logtra a small area.
*/
static int
logtra_gen( REGION *or, void *seq, void *a, void *b )
{
REGION *ir = (REGION *) seq;
Rect *r = &or->valid;
int le = r->left;
int to = r->top;
int bo = IM_RECT_BOTTOM(r);
int sz = IM_REGION_N_ELEMENTS( or );
int x, y;
/* Ask for input we need.
*/
if( im_prepare( ir, r ) )
return( -1 );
/* logtra all input types.
*/
switch( ir->im->BandFmt ) {
case IM_BANDFMT_UCHAR: loop(unsigned char, float); break;
case IM_BANDFMT_CHAR: loop(signed char, float); break;
case IM_BANDFMT_USHORT: loop(unsigned short, float); break;
case IM_BANDFMT_SHORT: loop(signed short, float); break;
case IM_BANDFMT_UINT: loop(unsigned int, float); break;
case IM_BANDFMT_INT: loop(signed int, float); break;
case IM_BANDFMT_FLOAT: loop(float, float); break;
case IM_BANDFMT_DOUBLE: loop(double, double); break;
default:
assert( 0 );
}
return( 0 );
#define LOG( IN, OUT ) { \
IN *p = (IN *) in; \
OUT *q = (OUT *) out; \
\
for( x = 0; x < sz; x++ ) \
q[x] = log( p[x] ); \
}
/* Log transform.
/* log() a buffer of PELs.
*/
static void
logtra_gen( PEL *in, PEL *out, int width, IMAGE *im )
{
const int sz = width * im->Bands;
int x;
/* Switch for all input types.
*/
switch( im->BandFmt ) {
case IM_BANDFMT_UCHAR: LOG( unsigned char, float ); break;
case IM_BANDFMT_CHAR: LOG( signed char, float ); break;
case IM_BANDFMT_USHORT: LOG( unsigned short, float ); break;
case IM_BANDFMT_SHORT: LOG( signed short, float ); break;
case IM_BANDFMT_UINT: LOG( unsigned int, float ); break;
case IM_BANDFMT_INT: LOG( signed int, float ); break;
case IM_BANDFMT_FLOAT: LOG( float, float ); break;
case IM_BANDFMT_DOUBLE: LOG( double, double ); break;
default:
g_assert( 0 );
}
}
/**
* im_logtra
* @in: input #IMAGE
* @out: output #IMAGE
*
* For each pixel, call <function>log(3)</function> (natural logarithm).
* The output type is float, unless the input is
* double, in which case the output is double. Non-complex images only.
*
* See also: im_exp10tra(), im_logntra(), im_sintra().
*
* Returns: 0 on success, -1 on error
*/
int
im_logtra( IMAGE *in, IMAGE *out )
{
/* Check args.
*/
if( im_piocheck( in, out ) )
return( -1 );
if( in->Coding != IM_CODING_NONE ) {
im_error( "im_logtra", "%s", _( "not uncoded" ) );
return( -1 );
}
if( im_iscomplex( in ) ) {
im_error( "im_logtra", "%s", _( "not non-complex" ) );
return( -1 );
}
/* Prepare output header.
*/
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 );
}
/* Set demand hints.
*/
if( im_demand_hint( out, IM_THINSTRIP, in, NULL ) )
return( -1 );
/* Generate!
*/
if( im_generate( out,
im_start_one, logtra_gen, im_stop_one, in, NULL ) )
return( -1 );
return( 0 );
{
return( im__math( "im_logtra", in, out,
(im_wrapone_fn) logtra_gen ) );
}

View File

@ -28,6 +28,9 @@
* - return( 0 ) missing, oops!
* 6/7/98 JC
* - _vec form added
* 30/8/09
* - gtkdoc
* - tiny cleanups
*/
/*
@ -63,7 +66,6 @@
#include <stdio.h>
#include <math.h>
#include <assert.h>
#include <vips/vips.h>
@ -80,22 +82,20 @@ typedef struct {
/* Define what we do for each band element type. Single constant.
*/
#define loop1(IN, OUT)\
{\
IN *p = (IN *) in;\
OUT *q = (OUT *) out;\
#define POW1( IN, OUT ) { \
IN *p = (IN *) in; \
OUT *q = (OUT *) out; \
\
for( x = 0; x < sz; x++ ) {\
double f = (double) p[x];\
for( x = 0; x < sz; x++ ) { \
double f = (double) p[x]; \
\
if( f == 0.0 && e < 0.0 ) {\
/* Division by zero! Difficult to report tho'\
*/\
q[x] = 0.0;\
}\
else\
q[x] = pow( f, e );\
}\
if( f == 0.0 && e < 0.0 ) \
/* Division by zero! Difficult to report tho' \
*/ \
q[x] = 0.0; \
else \
q[x] = pow( f, e ); \
} \
}
/* Powtra a buffer.
@ -103,24 +103,25 @@ typedef struct {
static int
powtra1_gen( PEL *in, PEL *out, int width, IMAGE *im, PowtraInfo *inf )
{
int sz = width * im->Bands;
double e = inf->e[0];
const int sz = width * im->Bands;
const double e = inf->e[0];
int x;
/* Powtra all non-complex input types.
*/
switch( im->BandFmt ) {
case IM_BANDFMT_UCHAR: loop1(unsigned char, float); break;
case IM_BANDFMT_CHAR: loop1(signed char, float); break;
case IM_BANDFMT_USHORT: loop1(unsigned short, float); break;
case IM_BANDFMT_SHORT: loop1(signed short, float); break;
case IM_BANDFMT_UINT: loop1(unsigned int, float); break;
case IM_BANDFMT_INT: loop1(signed int, float); break;
case IM_BANDFMT_FLOAT: loop1(float, float); break;
case IM_BANDFMT_DOUBLE: loop1(double, double); break;
case IM_BANDFMT_UCHAR: POW1( unsigned char, float ); break;
case IM_BANDFMT_CHAR: POW1( signed char, float ); break;
case IM_BANDFMT_USHORT: POW1( unsigned short, float ); break;
case IM_BANDFMT_SHORT: POW1( signed short, float ); break;
case IM_BANDFMT_UINT: POW1( unsigned int, float ); break;
case IM_BANDFMT_INT: POW1( signed int, float ); break;
case IM_BANDFMT_FLOAT: POW1( float, float ); break;
case IM_BANDFMT_DOUBLE: POW1( double, double ); break;
default:
assert( 0 );
g_assert( 0 );
}
return( 0 );
@ -128,21 +129,19 @@ powtra1_gen( PEL *in, PEL *out, int width, IMAGE *im, PowtraInfo *inf )
/* Define what we do for each band element type. One constant per band.
*/
#define loopn(IN, OUT)\
{\
IN *p = (IN *) in;\
OUT *q = (OUT *) out;\
#define POWN( IN, OUT ) { \
IN *p = (IN *) in; \
OUT *q = (OUT *) out; \
\
for( i = 0, x = 0; x < width; x++ )\
for( k = 0; k < im->Bands; k++, i++ ) {\
double e = inf->e[k];\
double f = (double) p[i];\
for( i = 0, x = 0; x < width; x++ ) \
for( k = 0; k < im->Bands; k++, i++ ) { \
double e = inf->e[k]; \
double f = (double) p[i]; \
\
if( f == 0.0 && e < 0.0 ) {\
q[i] = 0.0;\
}\
else\
q[i] = pow( f, e );\
if( f == 0.0 && e < 0.0 ) \
q[i] = 0.0; \
else \
q[i] = pow( f, e ); \
}\
}
@ -156,43 +155,54 @@ powtran_gen( PEL *in, PEL *out, int width, IMAGE *im, PowtraInfo *inf )
/* Powtra all non-complex input types.
*/
switch( im->BandFmt ) {
case IM_BANDFMT_UCHAR: loopn(unsigned char, float); break;
case IM_BANDFMT_CHAR: loopn(signed char, float); break;
case IM_BANDFMT_USHORT: loopn(unsigned short, float); break;
case IM_BANDFMT_SHORT: loopn(signed short, float); break;
case IM_BANDFMT_UINT: loopn(unsigned int, float); break;
case IM_BANDFMT_INT: loopn(signed int, float); break;
case IM_BANDFMT_FLOAT: loopn(float, float); break;
case IM_BANDFMT_DOUBLE: loopn(double, double); break;
case IM_BANDFMT_UCHAR: POWN( unsigned char, float ); break;
case IM_BANDFMT_CHAR: POWN( signed char, float ); break;
case IM_BANDFMT_USHORT: POWN( unsigned short, float ); break;
case IM_BANDFMT_SHORT: POWN( signed short, float ); break;
case IM_BANDFMT_UINT: POWN( unsigned int, float ); break;
case IM_BANDFMT_INT: POWN( signed int, float ); break;
case IM_BANDFMT_FLOAT: POWN( float, float ); break;
case IM_BANDFMT_DOUBLE: POWN( double, double ); break;
default:
assert( 0 );
g_assert( 0 );
}
return( 0 );
}
/**
* im_powtra_vec:
* @in: input #IMAGE
* @out: output #IMAGE
* @n: number of elements in array
* @b: array of constants
*
* im_powtra_vec() transforms element x of input to
* <function>pow</function>(x, @b) in output.
* It detects division by zero, setting those pixels to zero in the output.
* Beware: it does this silently!
*
* If the array of constants has one element, that constant is used for each
* image band. If the array has more than one element, it must have the same
* number of elements as there are bands in the image, and one array element
* is used for each band.
*
* See also: im_logtra(), im_expntra_vec()
*
* Returns: 0 on success, -1 on error
*/
int
im_powtra_vec( IMAGE *in, IMAGE *out, int n, double *e )
{
PowtraInfo *inf;
int i;
/* Check args.
*/
if( in->Coding != IM_CODING_NONE ) {
im_error( "im_powtra_vec", "%s", _( "not uncoded" ) );
if( im_piocheck( in, out ) ||
im_check_uncoded( "im_powtra_vec", in ) ||
im_check_noncomplex( "im_powtra_vec", in ) ||
im_check_vector( "im_powtra_vec", n, in ) )
return( -1 );
}
if( im_iscomplex( in ) ) {
im_error( "im_powtra_vec", "%s", _( "not non-complex" ) );
return( -1 );
}
if( n != 1 && n != in->Bands ) {
im_error( "im_powtra_vec",
_( "not 1 or %d elements in vector" ), in->Bands );
return( -1 );
}
/* Prepare output header.
*/
@ -228,6 +238,21 @@ im_powtra_vec( IMAGE *in, IMAGE *out, int n, double *e )
return( 0 );
}
/**
* im_powntra:
* @in: input #IMAGE
* @out: output #IMAGE
* @e: exponent
*
* im_powtra() transforms element x of input to
* <function>pow</function>(x, @e) in output.
* It detects division by zero, setting those pixels to zero in the output.
* Beware: it does this silently!
*
* See also: im_logtra(), im_powntra_vec()
*
* Returns: 0 on success, -1 on error
*/
int
im_powtra( IMAGE *in, IMAGE *out, double e )
{

View File

@ -23,6 +23,10 @@
* - adapted for im_wrapone()
* 26/1/96 JC
* - im_asintra() added
* 30/8/09
* - gtkdoc
* - tiny cleanups
* - use im__math()
*/
/*
@ -59,9 +63,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>
#include <vips/vips.h>
#include <vips/internal.h>
#ifdef WITH_DMALLOC
#include <dmalloc.h>
@ -70,170 +74,112 @@
/* Define what we do for each band element type. Non-complex input, any
* output.
*/
#define loop( IN, OUT )\
{\
IN *p = (IN *) in;\
OUT *q = (OUT *) out;\
\
for( x = 0; x < sz; x++ )\
q[x] = sin( IM_RAD( (double) p[x] ) );\
}
#define SIN( IN, OUT ) { \
IN *p = (IN *) in; \
OUT *q = (OUT *) out; \
\
for( x = 0; x < sz; x++ ) \
q[x] = sin( IM_RAD( (double) p[x] ) ); \
}
/* sin a buffer of PELs.
/* sin() a buffer of PELs.
*/
static void
sintra_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.
*/
switch( im->BandFmt ) {
case IM_BANDFMT_UCHAR: loop( unsigned char, float ); break;
case IM_BANDFMT_CHAR: loop( signed char, float ); break;
case IM_BANDFMT_USHORT: loop( unsigned short, float ); break;
case IM_BANDFMT_SHORT: loop( signed short, float ); break;
case IM_BANDFMT_UINT: loop( unsigned int, float ); break;
case IM_BANDFMT_INT: loop( signed int, float ); break;
case IM_BANDFMT_FLOAT: loop( float, float ); break;
case IM_BANDFMT_DOUBLE: loop( double, double ); break;
case IM_BANDFMT_UCHAR: SIN( unsigned char, float ); break;
case IM_BANDFMT_CHAR: SIN( signed char, float ); break;
case IM_BANDFMT_USHORT: SIN( unsigned short, float ); break;
case IM_BANDFMT_SHORT: SIN( signed short, float ); break;
case IM_BANDFMT_UINT: SIN( unsigned int, float ); break;
case IM_BANDFMT_INT: SIN( signed int, float ); break;
case IM_BANDFMT_FLOAT: SIN( float, float ); break;
case IM_BANDFMT_DOUBLE: SIN( double, double ); break;
default:
assert( 0 );
g_assert( 0 );
}
}
/* Sin transform.
/**
* im_sintra
* @in: input #IMAGE
* @out: output #IMAGE
*
* For each pixel, call <function>sin(3)</function> (sine). 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_asintra(), im_costra(), im_tantra().
*
* Returns: 0 on success, -1 on error
*/
int
im_sintra( IMAGE *in, IMAGE *out )
{
/* Check args.
*/
if( im_piocheck( in, out ) )
return( -1 );
if( in->Coding != IM_CODING_NONE ) {
im_error( "im_sintra", "%s", _( "not uncoded" ) );
return( -1 );
}
if( im_iscomplex( in ) ) {
im_error( "im_sintra", "%s", _( "not non-complex" ) );
return( -1 );
}
/* Prepare output header.
*/
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 );
}
/* Generate!
*/
if( im_wrapone( in, out, (im_wrapone_fn) sintra_gen, in, NULL ) )
return( -1 );
return( 0 );
{
return( im__math( "im_sintra", in, out, (im_wrapone_fn) sintra_gen ) );
}
/* And asin().
*/
#define aloop( IN, OUT )\
{\
IN *p = (IN *) in;\
OUT *q = (OUT *) out;\
\
for( x = 0; x < sz; x++ )\
q[x] = IM_DEG( asin( (double) p[x] ) );\
}
#define ASIN( IN, OUT ) { \
IN *p = (IN *) in; \
OUT *q = (OUT *) out; \
\
for( x = 0; x < sz; x++ ) \
q[x] = IM_DEG( asin( (double) p[x] ) ); \
}
/* asin a buffer of PELs.
*/
static void
asintra_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.
*/
switch( im->BandFmt ) {
case IM_BANDFMT_UCHAR: aloop( unsigned char, float ); break;
case IM_BANDFMT_CHAR: aloop( signed char, float ); break;
case IM_BANDFMT_USHORT: aloop( unsigned short, float ); break;
case IM_BANDFMT_SHORT: aloop( signed short, float ); break;
case IM_BANDFMT_UINT: aloop( unsigned int, float ); break;
case IM_BANDFMT_INT: aloop( signed int, float ); break;
case IM_BANDFMT_FLOAT: aloop( float, float ); break;
case IM_BANDFMT_DOUBLE: aloop( double, double ); break;
case IM_BANDFMT_UCHAR: ASIN( unsigned char, float ); break;
case IM_BANDFMT_CHAR: ASIN( signed char, float ); break;
case IM_BANDFMT_USHORT: ASIN( unsigned short, float ); break;
case IM_BANDFMT_SHORT: ASIN( signed short, float ); break;
case IM_BANDFMT_UINT: ASIN( unsigned int, float ); break;
case IM_BANDFMT_INT: ASIN( signed int, float ); break;
case IM_BANDFMT_FLOAT: ASIN( float, float ); break;
case IM_BANDFMT_DOUBLE: ASIN( double, double ); break;
default:
assert( 0 );
g_assert( 0 );
}
}
/* Asin transform.
/**
* im_asintra
* @in: input #IMAGE
* @out: output #IMAGE
*
* For each pixel, call <function>asin(3)</function> (arc, or inverse sine).
* 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_asintra(), im_costra(), im_tantra().
*
* Returns: 0 on success, -1 on error
*/
int
im_asintra( IMAGE *in, IMAGE *out )
{
/* Check args.
*/
if( im_piocheck( in, out ) )
return( -1 );
if( in->Coding != IM_CODING_NONE ) {
im_error( "im_asintra", "%s", _( "not uncoded" ) );
return( -1 );
}
if( im_iscomplex( in ) ) {
im_error( "im_asintra", "%s", _( "not non-complex" ) );
return( -1 );
}
/* Prepare output header.
*/
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 );
}
/* Generate!
*/
if( im_wrapone( in, out, (im_wrapone_fn) asintra_gen, in, NULL ) )
return( -1 );
return( 0 );
return( im__math( "im_asintra", in, out,
(im_wrapone_fn) asintra_gen ) );
}

View File

@ -23,6 +23,10 @@
* - adapted for im_wrapone()
* 26/1/96 JC
* - atan() added
* 30/8/09
* - gtkdoc
* - tiny cleanups
* - use im__math()
*/
/*
@ -59,9 +63,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>
#include <vips/vips.h>
#include <vips/internal.h>
#ifdef WITH_DMALLOC
#include <dmalloc.h>
@ -70,171 +74,114 @@
/* Define what we do for each band element type. Non-complex input, any
* output.
*/
#define loop( IN, OUT )\
{\
IN *p = (IN *) in;\
OUT *q = (OUT *) out;\
\
for( x = 0; x < sz; x++ )\
q[x] = tan( IM_RAD( (double) p[x] ) );\
}
#define TAN( IN, OUT ) { \
IN *p = (IN *) in; \
OUT *q = (OUT *) out; \
\
for( x = 0; x < sz; x++ ) \
q[x] = tan( IM_RAD( (double) p[x] ) ); \
}
/* tan a buffer of PELs.
*/
static void
tantra_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.
*/
switch( im->BandFmt ) {
case IM_BANDFMT_UCHAR: loop( unsigned char, float ); break;
case IM_BANDFMT_CHAR: loop( signed char, float ); break;
case IM_BANDFMT_USHORT: loop( unsigned short, float ); break;
case IM_BANDFMT_SHORT: loop( signed short, float ); break;
case IM_BANDFMT_UINT: loop( unsigned int, float ); break;
case IM_BANDFMT_INT: loop( signed int, float ); break;
case IM_BANDFMT_FLOAT: loop( float, float ); break;
case IM_BANDFMT_DOUBLE: loop( double, double ); break;
case IM_BANDFMT_UCHAR: TAN( unsigned char, float ); break;
case IM_BANDFMT_CHAR: TAN( signed char, float ); break;
case IM_BANDFMT_USHORT: TAN( unsigned short, float ); break;
case IM_BANDFMT_SHORT: TAN( signed short, float ); break;
case IM_BANDFMT_UINT: TAN( unsigned int, float ); break;
case IM_BANDFMT_INT: TAN( signed int, float ); break;
case IM_BANDFMT_FLOAT: TAN( float, float ); break;
case IM_BANDFMT_DOUBLE: TAN( double, double ); break;
default:
assert( 0 );
g_assert( 0 );
}
}
/* Tan transform.
/**
* im_tantra
* @in: input #IMAGE
* @out: output #IMAGE
*
* For each pixel, call <function>tan(3)</function> (tangent). 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_atantra(), im_sintra().
*
* Returns: 0 on success, -1 on error
*/
int
im_tantra( IMAGE *in, IMAGE *out )
{
/* Check args.
*/
if( im_piocheck( in, out ) )
return( -1 );
if( in->Coding != IM_CODING_NONE ) {
im_error( "im_tantra", "%s", _( "not uncoded" ) );
return( -1 );
}
if( im_iscomplex( in ) ) {
im_error( "im_tantra", "%s", _( "not non-complex" ) );
return( -1 );
}
/* Prepare output header.
*/
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 );
}
/* Generate!
*/
if( im_wrapone( in, out, (im_wrapone_fn) tantra_gen, in, NULL ) )
return( -1 );
return( 0 );
{
return( im__math( "im_tantra", in, out, (im_wrapone_fn) tantra_gen ) );
}
/* Define what we do for each band element type. Non-complex input, any
* output.
*/
#define aloop( IN, OUT )\
{\
IN *p = (IN *) in;\
OUT *q = (OUT *) out;\
\
for( x = 0; x < sz; x++ )\
q[x] = IM_DEG( atan( (double) p[x] ) );\
}
#define ATAN( IN, OUT ) { \
IN *p = (IN *) in; \
OUT *q = (OUT *) out; \
\
for( x = 0; x < sz; x++ ) \
q[x] = IM_DEG( atan( (double) p[x] ) ); \
}
/* atan a buffer of PELs.
*/
static void
atantra_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.
*/
switch( im->BandFmt ) {
case IM_BANDFMT_UCHAR: aloop( unsigned char, float ); break;
case IM_BANDFMT_CHAR: aloop( signed char, float ); break;
case IM_BANDFMT_USHORT: aloop( unsigned short, float ); break;
case IM_BANDFMT_SHORT: aloop( signed short, float ); break;
case IM_BANDFMT_UINT: aloop( unsigned int, float ); break;
case IM_BANDFMT_INT: aloop( signed int, float ); break;
case IM_BANDFMT_FLOAT: aloop( float, float ); break;
case IM_BANDFMT_DOUBLE: aloop( double, double ); break;
case IM_BANDFMT_UCHAR: ATAN( unsigned char, float ); break;
case IM_BANDFMT_CHAR: ATAN( signed char, float ); break;
case IM_BANDFMT_USHORT: ATAN( unsigned short, float ); break;
case IM_BANDFMT_SHORT: ATAN( signed short, float ); break;
case IM_BANDFMT_UINT: ATAN( unsigned int, float ); break;
case IM_BANDFMT_INT: ATAN( signed int, float ); break;
case IM_BANDFMT_FLOAT: ATAN( float, float ); break;
case IM_BANDFMT_DOUBLE: ATAN( double, double ); break;
default:
assert( 0 );
g_assert( 0 );
}
}
/* Atan transform.
/**
* im_atantra
* @in: input #IMAGE
* @out: output #IMAGE
*
* For each pixel, call <function>atan(3)</function> (arc or inverse tangent).
* 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_tantra(), im_sintra().
*
* Returns: 0 on success, -1 on error
*/
int
im_atantra( IMAGE *in, IMAGE *out )
{
/* Check args.
*/
if( im_piocheck( in, out ) )
return( -1 );
if( in->Coding != IM_CODING_NONE ) {
im_error( "im_atantra", "%s", _( "not uncoded" ) );
return( -1 );
}
if( im_iscomplex( in ) ) {
im_error( "im_atantra", "%s", _( "not non-complex" ) );
return( -1 );
}
/* Prepare output header.
*/
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 );
}
/* Generate!
*/
if( im_wrapone( in, out, (im_wrapone_fn) atantra_gen, in, NULL ) )
return( -1 );
return( 0 );
{
return( im__math( "im_atantra", in, out,
(im_wrapone_fn) atantra_gen ) );
}

View File

@ -134,6 +134,7 @@ void im__buffer_init( void );
int im__cast_and_call( IMAGE *in1, IMAGE *in2, IMAGE *out,
im_wrapmany_fn fn, void *a );
VipsBandFmt im__format_common( IMAGE *in1, IMAGE *in2 );
int im__math( const char *name, IMAGE *in, IMAGE *out, im_wrapone_fn gen );
int im__test_kill( IMAGE *im );
void *im__mmap( int fd, int writeable, size_t length, gint64 offset );