diff --git a/ChangeLog b/ChangeLog index 61cd5e8d..f80a36c2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,8 @@ im_tbjoin(), im_extract_area(), im_extract_bands(), im_extract_areabands(), im_replicate(), im_clip2fmt(), im_gbandjoin(), im_bandjoin(), im_invert(), im_lintra(), im_lintra_vec(), im_black(), im_rot90, im_rot180(), im_rot270() + im_sintra(), im_costra(), im_tantra(), im_asintra(), im_acostra(), + im_atantra(), im_exptra(), im_exp10tra(), im_logtra(), im_log10tra(), redone as classes - added argument priorites to help control arg ordering - generate has a 'stop' param to signal successful early termination diff --git a/libvips/arithmetic/Makefile.am b/libvips/arithmetic/Makefile.am index 2286c0b5..0a8778e8 100644 --- a/libvips/arithmetic/Makefile.am +++ b/libvips/arithmetic/Makefile.am @@ -24,7 +24,6 @@ libarithmetic_la_SOURCES = \ min.c \ subtract.c \ math.c \ - v7math.c \ arithmetic.c \ arithmetic.h \ binary.c \ diff --git a/libvips/arithmetic/math.c b/libvips/arithmetic/math.c index 86264f48..d685ed47 100644 --- a/libvips/arithmetic/math.c +++ b/libvips/arithmetic/math.c @@ -150,6 +150,10 @@ vips_math_build( VipsObject *object ) #define ADCOS( X ) (IM_DEG( acos( X ) )) #define ADTAN( X ) (IM_DEG( atan( X ) )) +/* exp10() is a gnu extension, use pow(). + */ +#define EXP10( X ) (pow( 10.0, (X) )) + static void vips_math_buffer( VipsArithmetic *arithmetic, PEL *out, PEL **in, int width ) { @@ -166,8 +170,10 @@ vips_math_buffer( VipsArithmetic *arithmetic, PEL *out, PEL **in, int width ) case VIPS_MATH_OPERATION_ASIN: SWITCH( ADSIN ); break; case VIPS_MATH_OPERATION_ACOS: SWITCH( ADCOS ); break; case VIPS_MATH_OPERATION_ATAN: SWITCH( ADTAN ); break; + case VIPS_MATH_OPERATION_LOG: SWITCH( log ); break; case VIPS_MATH_OPERATION_LOG10: SWITCH( log10 ); break; - case VIPS_MATH_OPERATION_LN: SWITCH( log ); break; + case VIPS_MATH_OPERATION_EXP: SWITCH( exp ); break; + case VIPS_MATH_OPERATION_EXP10: SWITCH( EXP10 ); break; default: g_assert( 0 ); diff --git a/libvips/arithmetic/power.c b/libvips/arithmetic/power.c index 3e86afcb..3ba9a2cd 100644 --- a/libvips/arithmetic/power.c +++ b/libvips/arithmetic/power.c @@ -305,44 +305,3 @@ im_expntra( IMAGE *in, IMAGE *out, double e ) { return( im_expntra_vec( in, out, 1, &e ) ); } - -/** - * im_exptra: - * @in: input #IMAGE - * @out: output #IMAGE - * - * im_exptra() transforms element x of input to - * pow(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 ) -{ - return( im_expntra( in, out, 2.7182818284590452354 ) ); -} - -/** - * im_exp10tra: - * @in: input #IMAGE - * @out: output #IMAGE - * - * im_exptra() transforms element x of input to - * pow(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 ) -{ - return( im_expntra( in, out, 10.0 ) ); -} - diff --git a/libvips/arithmetic/v7math.c b/libvips/arithmetic/v7math.c deleted file mode 100644 index 4b921a05..00000000 --- a/libvips/arithmetic/v7math.c +++ /dev/null @@ -1,322 +0,0 @@ -/* v7math.c --- call various -lm functions (trig, log etc.) on imags - * - * vips7 compat stuff - * - * Copyright: 1990, N. Dessipris, based on im_powtra() - * Author: Nicos Dessipris - * Written on: 02/05/1990 - * Modified on: - * 5/5/93 JC - * - adapted from im_lintra to work with partial images - * - incorrect implementation of complex logs removed - * 1/7/93 JC - * - adapted for partial v2 - * - ANSIfied - * 24/2/95 JC - * - im_logtra() adapted to make im_sintra() - * - adapted for im_wrapone() - * 26/1/96 JC - * - im_asintra() added - * 30/8/09 - * - gtkdoc - * - tiny cleanups - * - use im__math() - * 19/9/09 - * - im_sintra() adapted to make math.c - */ - -/* - - This file is part of VIPS. - - VIPS is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - */ - -/* - - These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk - - */ - -#ifdef HAVE_CONFIG_H -#include -#endif /*HAVE_CONFIG_H*/ -#include - -#include -#include -#include - -#include -#include - -/* What we do for each band element. Non-complex only. - */ -#define FUN_LOOP( IN, OUT, FUN ) { \ - IN *p = (IN *) in; \ - OUT *q = (OUT *) out; \ - \ - for( x = 0; x < ne; x++ ) \ - q[x] = FUN( (double) p[x] ); \ -} - -/* Operate on a buffer of PELs - */ -#define FUN_BUFFER( FUN ) \ -static void \ -FUN ## _buffer( PEL *in, PEL *out, int width, IMAGE *im ) \ -{ \ - const int ne = width * im->Bands; \ - \ - int x; \ - \ - /* Switch for all input types. \ - */ \ - switch( im->BandFmt ) { \ - case IM_BANDFMT_UCHAR: FUN_LOOP( unsigned char, float, FUN ); break; \ - case IM_BANDFMT_CHAR: FUN_LOOP( signed char, float, FUN ); break; \ - case IM_BANDFMT_USHORT: FUN_LOOP( unsigned short, float, FUN ); break; \ - case IM_BANDFMT_SHORT: FUN_LOOP( signed short, float, FUN ); break; \ - case IM_BANDFMT_UINT: FUN_LOOP( unsigned int, float, FUN ); break; \ - case IM_BANDFMT_INT: FUN_LOOP( signed int, float, FUN ); break; \ - case IM_BANDFMT_FLOAT: FUN_LOOP( float, float, FUN ); break; \ - case IM_BANDFMT_DOUBLE: FUN_LOOP( double, double, FUN ); 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( vips_bandfmt_isint( in->BandFmt ) ) - out->BandFmt = IM_BANDFMT_FLOAT; - - if( im_wrapone( in, out, gen, in, NULL ) ) - return( -1 ); - - return( 0 ); -} - -/* Sin in degrees. - */ -#define DSIN( X ) (sin( IM_RAD( X ) )) - -FUN_BUFFER( DSIN ) - -/** - * im_sintra - * @in: input #IMAGE - * @out: output #IMAGE - * - * For each pixel, call sin(3) (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 ) -{ - return( im__math( "im_sintra", in, out, (im_wrapone_fn) DSIN_buffer ) ); -} - -/* Asin in degrees. - */ -#define ADSIN( X ) (IM_DEG( asin( X ) )) - -FUN_BUFFER( ADSIN ) - -/** - * im_asintra - * @in: input #IMAGE - * @out: output #IMAGE - * - * For each pixel, call asin(3) (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 ) -{ - return( im__math( "im_asintra", in, out, - (im_wrapone_fn) ADSIN_buffer ) ); -} - -/* Cos in degrees. - */ -#define DCOS( X ) (cos( IM_RAD( X ) )) - -FUN_BUFFER( DCOS ) - -/** - * im_costra - * @in: input #IMAGE - * @out: output #IMAGE - * - * For each pixel, call cos(3) (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 ) -{ - return( im__math( "im_costra", in, out, (im_wrapone_fn) DCOS_buffer ) ); -} - -/* Acos in degrees. - */ -#define ADCOS( X ) (IM_DEG( acos( X ) )) - -FUN_BUFFER( ADCOS ) - -/** - * im_acostra - * @in: input #IMAGE - * @out: output #IMAGE - * - * For each pixel, call acos(3) (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 ) -{ - return( im__math( "im_acostra", in, out, - (im_wrapone_fn) ADCOS_buffer ) ); -} - -/* Tan in degrees. - */ -#define DTAN( X ) (tan( IM_RAD( X ) )) - -FUN_BUFFER( DTAN ) - -/** - * im_tantra - * @in: input #IMAGE - * @out: output #IMAGE - * - * For each pixel, call tan(3) (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(), im_tantra(). - * - * Returns: 0 on success, -1 on error - */ -int -im_tantra( IMAGE *in, IMAGE *out ) -{ - return( im__math( "im_tantra", in, out, (im_wrapone_fn) DTAN_buffer ) ); -} - -/* Atan in degrees. - */ -#define ADTAN( X ) (IM_DEG( atan( X ) )) - -FUN_BUFFER( ADTAN ) - -/** - * im_atantra - * @in: input #IMAGE - * @out: output #IMAGE - * - * For each pixel, call atan(3) (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_asintra(), im_atantra(). - * - * Returns: 0 on success, -1 on error - */ -int -im_atantra( IMAGE *in, IMAGE *out ) -{ - return( im__math( "im_atantra", in, out, - (im_wrapone_fn) ADTAN_buffer ) ); -} - -FUN_BUFFER( log10 ) - -/** - * im_log10tra - * @in: input #IMAGE - * @out: output #IMAGE - * - * For each pixel, call log10(3) (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 ) -{ - return( im__math( "im_log10tra", in, out, - (im_wrapone_fn) log10_buffer ) ); -} - -FUN_BUFFER( log ) - -/** - * im_logtra - * @in: input #IMAGE - * @out: output #IMAGE - * - * For each pixel, call log(3) (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 ) -{ - return( im__math( "im_logtra", in, out, (im_wrapone_fn) log_buffer ) ); -} diff --git a/libvips/deprecated/vips7compat.c b/libvips/deprecated/vips7compat.c index c9ebfc48..392abebb 100644 --- a/libvips/deprecated/vips7compat.c +++ b/libvips/deprecated/vips7compat.c @@ -1443,3 +1443,80 @@ im_black( IMAGE *out, int x, int y, int bands ) return( 0 ); } + +static int +vips__math( VipsImage *in, VipsImage *out, VipsMathOperation operation ) +{ + VipsImage *t; + + if( vips_math( in, &t, operation, + NULL ) ) + return( -1 ); + if( vips_image_write( t, out ) ) { + g_object_unref( t ); + return( -1 ); + } + g_object_unref( t ); + + return( 0 ); +} + +int +im_sintra( IMAGE *in, IMAGE *out ) +{ + return( vips__math( in, out, VIPS_MATH_OPERATION_SIN ) ); +} + +int +im_costra( IMAGE *in, IMAGE *out ) +{ + return( vips__math( in, out, VIPS_MATH_OPERATION_COS ) ); +} + +int +im_tantra( IMAGE *in, IMAGE *out ) +{ + return( vips__math( in, out, VIPS_MATH_OPERATION_TAN ) ); +} + +int +im_asintra( IMAGE *in, IMAGE *out ) +{ + return( vips__math( in, out, VIPS_MATH_OPERATION_ASIN ) ); +} + +int +im_acostra( IMAGE *in, IMAGE *out ) +{ + return( vips__math( in, out, VIPS_MATH_OPERATION_ACOS ) ); +} + +int +im_atantra( IMAGE *in, IMAGE *out ) +{ + return( vips__math( in, out, VIPS_MATH_OPERATION_ATAN ) ); +} + +int +im_logtra( IMAGE *in, IMAGE *out ) +{ + return( vips__math( in, out, VIPS_MATH_OPERATION_LOG ) ); +} + +int +im_log10tra( IMAGE *in, IMAGE *out ) +{ + return( vips__math( in, out, VIPS_MATH_OPERATION_LOG10 ) ); +} + +int +im_exptra( IMAGE *in, IMAGE *out ) +{ + return( vips__math( in, out, VIPS_MATH_OPERATION_EXP ) ); +} + +int +im_exp10tra( IMAGE *in, IMAGE *out ) +{ + return( vips__math( in, out, VIPS_MATH_OPERATION_EXP10 ) ); +} diff --git a/libvips/include/vips/arithmetic.h b/libvips/include/vips/arithmetic.h index b72bd9a3..595378d1 100644 --- a/libvips/include/vips/arithmetic.h +++ b/libvips/include/vips/arithmetic.h @@ -45,8 +45,10 @@ extern "C" { * @VIPS_MATH_OPERATION_ASIN: asin(), angles in degrees * @VIPS_MATH_OPERATION_ACOS: acos(), angles in degrees * @VIPS_MATH_OPERATION_ATAN: atan(), angles in degrees + * @VIPS_MATH_OPERATION_LOG: log base e * @VIPS_MATH_OPERATION_LOG10: log base 10 - * @VIPS_MATH_OPERATION_LN: log base e + * @VIPS_MATH_OPERATION_EXP: e to the something + * @VIPS_MATH_OPERATION_EXP10: 10 to the something * * See also: vips_math(). */ @@ -57,8 +59,10 @@ typedef enum { VIPS_MATH_OPERATION_ASIN, VIPS_MATH_OPERATION_ACOS, VIPS_MATH_OPERATION_ATAN, + VIPS_MATH_OPERATION_LOG, VIPS_MATH_OPERATION_LOG10, - VIPS_MATH_OPERATION_LN, + VIPS_MATH_OPERATION_EXP, + VIPS_MATH_OPERATION_EXP10, VIPS_MATH_OPERATION_LAST } VipsMathOperation; @@ -118,19 +122,8 @@ int im_point_bilinear( VipsImage *im, int im_powtra( VipsImage *in, VipsImage *out, double e ); int im_powtra_vec( VipsImage *in, VipsImage *out, int n, double *e ); -int im_exptra( VipsImage *in, VipsImage *out ); -int im_exp10tra( VipsImage *in, VipsImage *out ); int im_expntra( VipsImage *in, VipsImage *out, double e ); int im_expntra_vec( VipsImage *in, VipsImage *out, int n, double *e ); -int im_logtra( VipsImage *in, VipsImage *out ); -int im_log10tra( VipsImage *in, VipsImage *out ); - -int im_sintra( VipsImage *in, VipsImage *out ); -int im_costra( VipsImage *in, VipsImage *out ); -int im_tantra( VipsImage *in, VipsImage *out ); -int im_asintra( VipsImage *in, VipsImage *out ); -int im_acostra( VipsImage *in, VipsImage *out ); -int im_atantra( VipsImage *in, VipsImage *out ); int im_cross_phase( VipsImage *a, VipsImage *b, VipsImage *out ); diff --git a/libvips/include/vips/vips7compat.h b/libvips/include/vips/vips7compat.h index 81d0ff06..993dfba2 100644 --- a/libvips/include/vips/vips7compat.h +++ b/libvips/include/vips/vips7compat.h @@ -529,6 +529,17 @@ int im_invert( VipsImage *in, VipsImage *out ); int im_lintra( double a, VipsImage *in, double b, VipsImage *out ); int im_lintra_vec( int n, double *a, VipsImage *in, double *b, VipsImage *out ); +int im_sintra( VipsImage *in, VipsImage *out ); +int im_costra( VipsImage *in, VipsImage *out ); +int im_tantra( VipsImage *in, VipsImage *out ); +int im_asintra( VipsImage *in, VipsImage *out ); +int im_acostra( VipsImage *in, VipsImage *out ); +int im_atantra( VipsImage *in, VipsImage *out ); +int im_logtra( VipsImage *in, VipsImage *out ); +int im_log10tra( VipsImage *in, VipsImage *out ); +int im_exptra( VipsImage *in, VipsImage *out ); +int im_exp10tra( VipsImage *in, VipsImage *out ); + int im_copy( VipsImage *in, VipsImage *out ); int im_copy_set( VipsImage *in, VipsImage *out, VipsInterpretation interpretation, diff --git a/libvips/iofuncs/enumtypes.c b/libvips/iofuncs/enumtypes.c index 38cd15a7..5645fb24 100644 --- a/libvips/iofuncs/enumtypes.c +++ b/libvips/iofuncs/enumtypes.c @@ -97,8 +97,10 @@ vips_math_operation_get_type( void ) {VIPS_MATH_OPERATION_ASIN, "VIPS_MATH_OPERATION_ASIN", "asin"}, {VIPS_MATH_OPERATION_ACOS, "VIPS_MATH_OPERATION_ACOS", "acos"}, {VIPS_MATH_OPERATION_ATAN, "VIPS_MATH_OPERATION_ATAN", "atan"}, + {VIPS_MATH_OPERATION_LOG, "VIPS_MATH_OPERATION_LOG", "log"}, {VIPS_MATH_OPERATION_LOG10, "VIPS_MATH_OPERATION_LOG10", "log10"}, - {VIPS_MATH_OPERATION_LN, "VIPS_MATH_OPERATION_LN", "ln"}, + {VIPS_MATH_OPERATION_EXP, "VIPS_MATH_OPERATION_EXP", "exp"}, + {VIPS_MATH_OPERATION_EXP10, "VIPS_MATH_OPERATION_EXP10", "exp10"}, {VIPS_MATH_OPERATION_LAST, "VIPS_MATH_OPERATION_LAST", "last"}, {0, NULL, NULL} };