From 8fe50220d57f9e44b54e20c3a04a7c63c965d52c Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Thu, 10 Nov 2011 13:53:58 +0000 Subject: [PATCH] move mask/ to deprecated, add VipsRound --- ChangeLog | 4 +- TODO | 8 - configure.in | 1 - libvips/Makefile.am | 2 - libvips/arithmetic/arithmetic.c | 2 + libvips/arithmetic/math.c | 40 +-- libvips/arithmetic/round.c | 269 ++++++++++-------- libvips/conversion/Makefile.am | 2 - libvips/conversion/conver_dispatch.c | 61 ---- libvips/deprecated/Makefile.am | 14 +- libvips/deprecated/deprecated_dispatch.c | 61 ++++ libvips/{mask => deprecated}/im_gaussmasks.c | 0 libvips/{mask => deprecated}/im_logmasks.c | 0 .../{conversion => deprecated}/im_mask2vips.c | 0 libvips/{mask => deprecated}/im_matcat.c | 0 libvips/{mask => deprecated}/im_matinv.c | 0 libvips/{mask => deprecated}/im_matmul.c | 0 libvips/{mask => deprecated}/im_mattrn.c | 0 .../{conversion => deprecated}/im_vips2mask.c | 0 libvips/{mask => deprecated}/mask_dispatch.c | 0 libvips/{mask => deprecated}/matalloc.c | 0 libvips/{mask => deprecated}/rotmask.c | 0 libvips/{mask => deprecated}/rw_mask.c | 0 libvips/deprecated/vips7compat.c | 59 +++- libvips/include/vips/arithmetic.h | 68 +++-- libvips/include/vips/conversion.h | 5 - libvips/include/vips/enumtypes.h | 6 +- libvips/include/vips/vips7compat.h | 7 + libvips/iofuncs/enumtypes.c | 45 ++- libvips/mask/Makefile.am | 15 - 30 files changed, 383 insertions(+), 286 deletions(-) rename libvips/{mask => deprecated}/im_gaussmasks.c (100%) rename libvips/{mask => deprecated}/im_logmasks.c (100%) rename libvips/{conversion => deprecated}/im_mask2vips.c (100%) rename libvips/{mask => deprecated}/im_matcat.c (100%) rename libvips/{mask => deprecated}/im_matinv.c (100%) rename libvips/{mask => deprecated}/im_matmul.c (100%) rename libvips/{mask => deprecated}/im_mattrn.c (100%) rename libvips/{conversion => deprecated}/im_vips2mask.c (100%) rename libvips/{mask => deprecated}/mask_dispatch.c (100%) rename libvips/{mask => deprecated}/matalloc.c (100%) rename libvips/{mask => deprecated}/rotmask.c (100%) rename libvips/{mask => deprecated}/rw_mask.c (100%) delete mode 100644 libvips/mask/Makefile.am diff --git a/ChangeLog b/ChangeLog index 9e767e39..5ebe61af 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,7 +8,8 @@ im_sintra(), im_costra(), im_tantra(), im_asintra(), im_acostra(), im_atantra(), im_exptra(), im_exp10tra(), im_logtra(), im_log10tra(), im_abs(), im_sign(), im_max(), im_maxpos(), im_deviate(), im_divide(), - im_multiply(), im_stats(), im_measure(), im_recomb() + im_multiply(), im_stats(), im_measure(), im_recomb(), im_floor(), im_ceil(), + im_rint() redone as classes - added argument priorites to help control arg ordering - generate has a 'stop' param to signal successful early termination @@ -40,6 +41,7 @@ - oop mode "rd" was not always being used for images - added ARRAY interpretation for images - VipsStats tracks minpos/maxpos as well +- moved mask/ to deprecated 12/10/11 started 7.26.6 - NOCACHE was not being set correctly on OS X causing performance diff --git a/TODO b/TODO index cf71c93b..108ddc7c 100644 --- a/TODO +++ b/TODO @@ -3,14 +3,6 @@ -- can move the whole of mask, plus headers, plus conversion/im_vips2mask and - mask2vips to deprecated - - make a new thing to load a mask file from csv2vips? - - - - - im_open_local() is broken? try Adam's prog under 7.27 ... it's the operation cache, we just need to call vips_shutdown() diff --git a/configure.in b/configure.in index 927b23ea..0db26c9d 100644 --- a/configure.in +++ b/configure.in @@ -640,7 +640,6 @@ AC_OUTPUT([ libvips/histograms_lut/Makefile libvips/inplace/Makefile libvips/iofuncs/Makefile - libvips/mask/Makefile libvips/morphology/Makefile libvips/mosaicing/Makefile libvips/other/Makefile diff --git a/libvips/Makefile.am b/libvips/Makefile.am index 2f89f768..315b6bb5 100644 --- a/libvips/Makefile.am +++ b/libvips/Makefile.am @@ -24,7 +24,6 @@ SUBDIRS = \ histograms_lut \ inplace \ iofuncs \ - mask \ morphology \ mosaicing \ other \ @@ -60,7 +59,6 @@ libvips_la_LIBADD = \ histograms_lut/libhistograms_lut.la \ inplace/libinplace.la \ iofuncs/libiofuncs.la \ - mask/libmask.la \ morphology/libmorphology.la \ mosaicing/libmosaicing.la \ other/libother.la \ diff --git a/libvips/arithmetic/arithmetic.c b/libvips/arithmetic/arithmetic.c index cabbc29a..8969ab41 100644 --- a/libvips/arithmetic/arithmetic.c +++ b/libvips/arithmetic/arithmetic.c @@ -517,6 +517,7 @@ vips_arithmetic_operation_init( void ) extern GType vips_stats_get_type( void ); extern GType vips_measure_get_type( void ); extern GType vips_recomb_get_type( void ); + extern GType vips_round_get_type( void ); vips_add_get_type(); vips_subtract_get_type(); @@ -534,4 +535,5 @@ vips_arithmetic_operation_init( void ) vips_stats_get_type(); vips_measure_get_type(); vips_recomb_get_type(); + vips_round_get_type(); } diff --git a/libvips/arithmetic/math.c b/libvips/arithmetic/math.c index d685ed47..38aa9d14 100644 --- a/libvips/arithmetic/math.c +++ b/libvips/arithmetic/math.c @@ -73,7 +73,7 @@ * VipsMath: * @in: input #VipsImage * @out: output #VipsImage - * @operation: operation to perform + * @math: math operation to perform * * Perform various functions in -lm, the maths library, on images. * @@ -87,7 +87,7 @@ typedef struct _VipsMath { VipsUnary parent_instance; - VipsMathOperation operation; + VipsOperationMath math; } VipsMath; @@ -163,17 +163,17 @@ vips_math_buffer( VipsArithmetic *arithmetic, PEL *out, PEL **in, int width ) int x; - switch( math->operation ) { - case VIPS_MATH_OPERATION_SIN: SWITCH( DSIN ); break; - case VIPS_MATH_OPERATION_COS: SWITCH( DCOS ); break; - case VIPS_MATH_OPERATION_TAN: SWITCH( DTAN ); break; - 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_EXP: SWITCH( exp ); break; - case VIPS_MATH_OPERATION_EXP10: SWITCH( EXP10 ); break; + switch( math->math ) { + case VIPS_OPERATION_MATH_SIN: SWITCH( DSIN ); break; + case VIPS_OPERATION_MATH_COS: SWITCH( DCOS ); break; + case VIPS_OPERATION_MATH_TAN: SWITCH( DTAN ); break; + case VIPS_OPERATION_MATH_ASIN: SWITCH( ADSIN ); break; + case VIPS_OPERATION_MATH_ACOS: SWITCH( ADCOS ); break; + case VIPS_OPERATION_MATH_ATAN: SWITCH( ADTAN ); break; + case VIPS_OPERATION_MATH_LOG: SWITCH( log ); break; + case VIPS_OPERATION_MATH_LOG10: SWITCH( log10 ); break; + case VIPS_OPERATION_MATH_EXP: SWITCH( exp ); break; + case VIPS_OPERATION_MATH_EXP10: SWITCH( EXP10 ); break; default: g_assert( 0 ); @@ -216,12 +216,12 @@ vips_math_class_init( VipsMathClass *class ) aclass->process_line = vips_math_buffer; - VIPS_ARG_ENUM( class, "operation", 200, + VIPS_ARG_ENUM( class, "math", 200, _( "Operation" ), - _( "operation to perform" ), + _( "math to perform" ), VIPS_ARGUMENT_REQUIRED_INPUT, - G_STRUCT_OFFSET( VipsMath, operation ), - VIPS_TYPE_MATH_OPERATION, VIPS_MATH_OPERATION_SIN ); + G_STRUCT_OFFSET( VipsMath, math ), + VIPS_TYPE_OPERATION_MATH, VIPS_OPERATION_MATH_SIN ); } static void @@ -230,13 +230,13 @@ vips_math_init( VipsMath *math ) } int -vips_math( VipsImage *in, VipsImage **out, VipsMathOperation operation, ... ) +vips_math( VipsImage *in, VipsImage **out, VipsOperationMath math, ... ) { va_list ap; int result; - va_start( ap, operation ); - result = vips_call_split( "math", ap, in, out, operation ); + va_start( ap, math ); + result = vips_call_split( "math", ap, in, out, math ); va_end( ap ); return( result ); diff --git a/libvips/arithmetic/round.c b/libvips/arithmetic/round.c index d59546b2..750ace33 100644 --- a/libvips/arithmetic/round.c +++ b/libvips/arithmetic/round.c @@ -7,23 +7,25 @@ * - tiny cleanups * 19/9/09 * - im_ceil.c adapted to make round.c + * 10/11/11 + * - redone as a class */ /* - 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 + Copyright (C) 1991-2005 The National Gallery + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU 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. + GNU General Public License for more details. - You should have received a copy of the GNU Lesser General Public License + You should have received a copy of the GNU 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 @@ -35,6 +37,10 @@ */ +/* +#define DEBUG + */ + #ifdef HAVE_CONFIG_H #include #endif /*HAVE_CONFIG_H*/ @@ -46,132 +52,163 @@ #include -#define ROUND_LOOP( TYPE, FUN ) { \ - TYPE *p = (TYPE *) in; \ - TYPE *q = (TYPE *) out; \ - \ - for( x = 0; x < ne; x++ ) \ - q[x] = FUN( p[x] ); \ -} +#include "arithmetic.h" +#include "unary.h" -#define ROUND_BUFFER( FUN ) \ -static void \ -FUN ## _buffer( PEL *in, PEL *out, int width, IMAGE *im ) \ -{ \ - /* Complex just doubles the size. \ - */ \ - const int ne = width * im->Bands * \ - (vips_bandfmt_iscomplex( im->BandFmt ) ? 2 : 1); \ - \ - int x; \ - \ - switch( im->BandFmt ) { \ - case IM_BANDFMT_COMPLEX: \ - case IM_BANDFMT_FLOAT: \ - ROUND_LOOP( float, FUN ); \ - break; \ - \ - case IM_BANDFMT_DOUBLE: \ - case IM_BANDFMT_DPCOMPLEX: \ - ROUND_LOOP( double, FUN ); \ - break; \ - \ - default: \ - g_assert( 0 ); \ - } \ -} +/** + * VipsRound: + * @in: input #VipsImage + * @out: output #VipsImage + * @round: #VipsOperationRound rounding operation to perform + * + * Round to an integral value. + * + * Copy for integer types, round float and + * complex types. Output type == input type. + * + * See also: #VipsCast. + */ -static int -im__round( const char *name, IMAGE *in, IMAGE *out, im_wrapone_fn gen ) -{ - if( im_piocheck( in, out ) || - im_check_uncoded( name, in ) ) - return( -1 ); +typedef struct _VipsRound { + VipsUnary parent_instance; + + VipsOperationRound round; + +} VipsRound; + +typedef VipsUnaryClass VipsRoundClass; + +G_DEFINE_TYPE( VipsRound, vips_round, VIPS_TYPE_UNARY ); + +static int +vips_round_build( VipsObject *object ) +{ + VipsArithmetic *arithmetic = VIPS_ARITHMETIC( object ); + VipsUnary *unary = (VipsUnary *) object; /* Is this one of the int types? Degenerate to im_copy() if it * is. */ - if( vips_bandfmt_isint( in->BandFmt ) ) - return( im_copy( in, out ) ); + if( unary->in && + vips_bandfmt_isint( unary->in->BandFmt ) ) { + /* This isn't set by arith until build(), so we have to set + * again here. + * + * Should arith set out in _init()? + */ + g_object_set( arithmetic, "out", vips_image_new(), NULL ); - /* Output type == input type. - */ - if( im_cp_desc( out, in ) ) - return( -1 ); + return( vips_image_write( unary->in, arithmetic->out ) ); + } - /* Generate! - */ - if( im_wrapone( in, out, (im_wrapone_fn) gen, in, NULL ) ) + if( VIPS_OBJECT_CLASS( vips_round_parent_class )->build( object ) ) return( -1 ); return( 0 ); } -ROUND_BUFFER( ceil ) - -/** - * im_ceil: - * @in: input #IMAGE - * @out: output #IMAGE - * - * For each pixel, find the smallest integral value not less than. - * Copy for integer types, call ceil(3) 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 ) -{ - return( im__round( "im_ceil", in, out, (im_wrapone_fn) ceil_buffer ) ); +#define LOOP( TYPE, OP ) { \ + TYPE *p = (TYPE *) in[0]; \ + TYPE *q = (TYPE *) out; \ + \ + for( x = 0; x < sz; x++ ) \ + q[x] = OP( p[x] ); \ } -ROUND_BUFFER( floor ) - -/** - * im_floor: - * @in: input #IMAGE - * @out: output #IMAGE - * - * For each pixel, find the largest integral value not less than. - * Copy for integer types, call floor() for float and - * complex types. - * Output type == input type. - * - * See also: im_ceil(), im_rint(), im_clip2fmt() - * - * Returns: 0 on success, -1 on error - */ -int -im_floor( IMAGE *in, IMAGE *out ) -{ - return( im__round( "im_floor", in, out, - (im_wrapone_fn) floor_buffer ) ); +#define SWITCH( OP ) { \ + switch( vips_image_get_format( im ) ) { \ + case VIPS_FORMAT_COMPLEX: \ + case VIPS_FORMAT_FLOAT: LOOP( float, OP ); break; \ + \ + case VIPS_FORMAT_DPCOMPLEX: \ + case VIPS_FORMAT_DOUBLE:LOOP( double, OP ); break;\ + \ + default: \ + g_assert( 0 ); \ + } \ } -ROUND_BUFFER( IM_RINT ) +static void +vips_round_buffer( VipsArithmetic *arithmetic, PEL *out, PEL **in, int width ) +{ + VipsRound *round = (VipsRound *) arithmetic; + VipsImage *im = arithmetic->ready[0]; -/** - * im_rint: - * @in: input #IMAGE - * @out: output #IMAGE - * - * Finds the nearest integral value. Copy for integer types, - * call IM_RINT() for float and complex types. Output type == input type. - * - * IM_RINT() is a pseudo-round-to-nearest. It is much faster than - * rint(3), but does not give the same result for - * negative integral values. - * - * See also: im_ceil(), im_floor(), im_clip2fmt() - * - * Returns: 0 on success, -1 on error - */ -int -im_rint( IMAGE *in, IMAGE *out ) -{ - return( im__round( "im_rint", in, out, (im_wrapone_fn) IM_RINT_buffer ) ); + /* Complex just doubles the size. + */ + const int sz = width * im->Bands * + (vips_bandfmt_iscomplex( im->BandFmt ) ? 2 : 1); + + int x; + + switch( round->round ) { + case VIPS_OPERATION_ROUND_NEAREST: SWITCH( VIPS_RINT ); break; + case VIPS_OPERATION_ROUND_CEIL: SWITCH( ceil ); break; + case VIPS_OPERATION_ROUND_FLOOR: SWITCH( floor ); break; + + default: + g_assert( 0 ); + } +} + +/* Save a bit of typing. + */ +#define UC VIPS_FORMAT_UCHAR +#define C VIPS_FORMAT_CHAR +#define US VIPS_FORMAT_USHORT +#define S VIPS_FORMAT_SHORT +#define UI VIPS_FORMAT_UINT +#define I VIPS_FORMAT_INT +#define F VIPS_FORMAT_FLOAT +#define X VIPS_FORMAT_COMPLEX +#define D VIPS_FORMAT_DOUBLE +#define DX VIPS_FORMAT_DPCOMPLEX + +static const VipsBandFormat vips_bandfmt_round[10] = { +/* UC C US S UI I F X D DX */ + UC, C, US, S, UI, I, F, X, D, DX +}; + +static void +vips_round_class_init( VipsRoundClass *class ) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS( class ); + VipsObjectClass *object_class = (VipsObjectClass *) class; + VipsArithmeticClass *aclass = VIPS_ARITHMETIC_CLASS( class ); + + gobject_class->set_property = vips_object_set_property; + gobject_class->get_property = vips_object_get_property; + + object_class->nickname = "round"; + object_class->description = _( "perform a round function on an image" ); + object_class->build = vips_round_build; + + vips_arithmetic_set_format_table( aclass, vips_bandfmt_round ); + + aclass->process_line = vips_round_buffer; + + VIPS_ARG_ENUM( class, "round", 200, + _( "Round operation" ), + _( "rounding operation to perform" ), + VIPS_ARGUMENT_REQUIRED_INPUT, + G_STRUCT_OFFSET( VipsRound, round ), + VIPS_TYPE_OPERATION_ROUND, VIPS_OPERATION_ROUND_NEAREST ); +} + +static void +vips_round_init( VipsRound *round ) +{ +} + +int +vips_round( VipsImage *in, VipsImage **out, VipsOperationRound round, ... ) +{ + va_list ap; + int result; + + va_start( ap, round ); + result = vips_call_split( "round", ap, in, out, round ); + va_end( ap ); + + return( result ); } diff --git a/libvips/conversion/Makefile.am b/libvips/conversion/Makefile.am index 38a3e5b7..7f9775ad 100644 --- a/libvips/conversion/Makefile.am +++ b/libvips/conversion/Makefile.am @@ -21,7 +21,6 @@ libconversion_la_SOURCES = \ im_c2real.c \ im_copy_file.c \ im_falsecolour.c \ - im_mask2vips.c \ im_msb.c \ im_grid.c \ im_ri2c.c \ @@ -32,7 +31,6 @@ libconversion_la_SOURCES = \ im_system_image.c \ im_text.c \ im_gaussnoise.c \ - im_vips2mask.c \ im_wrap.c \ im_zoom.c diff --git a/libvips/conversion/conver_dispatch.c b/libvips/conversion/conver_dispatch.c index 9ae9bd71..c43d8cc8 100644 --- a/libvips/conversion/conver_dispatch.c +++ b/libvips/conversion/conver_dispatch.c @@ -1053,65 +1053,6 @@ static im_function tbjoin_desc = { two_in_one_out /* Arg list */ }; -/* Args to im_mask2vips. - */ -static im_arg_desc mask2vips_args[] = { - IM_INPUT_DMASK( "input" ), - IM_OUTPUT_IMAGE( "output" ), -}; - -/* Call im_mask2vips via arg vector. - */ -static int -mask2vips_vec( im_object *argv ) -{ - im_mask_object *mo = argv[0]; - - return( im_mask2vips( mo->mask, argv[1] ) ); -} - -/* Description of im_mask2vips. - */ -static im_function mask2vips_desc = { - "im_mask2vips", /* Name */ - "convert DOUBLEMASK to VIPS image", - 0, /* Flags */ - mask2vips_vec, /* Dispatch function */ - IM_NUMBER( mask2vips_args ), /* Size of arg list */ - mask2vips_args /* Arg list */ -}; - -/* Args to im_vips2mask. - */ -static im_arg_desc vips2mask_args[] = { - IM_INPUT_IMAGE( "input" ), - IM_OUTPUT_DMASK( "output" ), -}; - -/* Call im_vips2mask via arg vector. - */ -static int -vips2mask_vec( im_object *argv ) -{ - im_mask_object *mo = argv[1]; - - if( !(mo->mask = im_vips2mask( argv[0], mo->name )) ) - return( -1 ); - - return( 0 ); -} - -/* Description of im_vips2mask. - */ -static im_function vips2mask_desc = { - "im_vips2mask", /* Name */ - "convert VIPS image to DOUBLEMASK", - 0, /* Flags */ - vips2mask_vec, /* Dispatch function */ - IM_NUMBER( vips2mask_args ), /* Size of arg list */ - vips2mask_args /* Arg list */ -}; - /* Call im_scale via arg vector. */ static int @@ -1392,7 +1333,6 @@ static im_function *conv_list[] = { &insert_noexpand_desc, &embed_desc, &lrjoin_desc, - &mask2vips_desc, &msb_desc, &msb_band_desc, &replicate_desc, @@ -1407,7 +1347,6 @@ static im_function *conv_list[] = { &system_image_desc, &tbjoin_desc, &text_desc, - &vips2mask_desc, &wrap_desc, &zoom_desc }; diff --git a/libvips/deprecated/Makefile.am b/libvips/deprecated/Makefile.am index 57fd5482..b9f91318 100644 --- a/libvips/deprecated/Makefile.am +++ b/libvips/deprecated/Makefile.am @@ -30,6 +30,18 @@ libdeprecated_la_SOURCES = \ im_thresh.c \ im_slice.c \ im_print.c \ - im_litecor.c + im_litecor.c \ + im_mask2vips.c \ + im_vips2mask.c \ + rotmask.c \ + im_gaussmasks.c \ + im_logmasks.c \ + rw_mask.c \ + im_matcat.c \ + im_matinv.c \ + im_matmul.c \ + im_mattrn.c \ + matalloc.c \ + mask_dispatch.c INCLUDES = -I${top_srcdir}/libvips/include @VIPS_CFLAGS@ @VIPS_INCLUDES@ diff --git a/libvips/deprecated/deprecated_dispatch.c b/libvips/deprecated/deprecated_dispatch.c index a73f8ec4..ca59f9dd 100644 --- a/libvips/deprecated/deprecated_dispatch.c +++ b/libvips/deprecated/deprecated_dispatch.c @@ -1425,6 +1425,65 @@ static im_function remainderconst_vec_desc = { remainderconst_vec_args /* Arg list */ }; +/* Args to im_mask2vips. + */ +static im_arg_desc mask2vips_args[] = { + IM_INPUT_DMASK( "input" ), + IM_OUTPUT_IMAGE( "output" ), +}; + +/* Call im_mask2vips via arg vector. + */ +static int +mask2vips_vec( im_object *argv ) +{ + im_mask_object *mo = argv[0]; + + return( im_mask2vips( mo->mask, argv[1] ) ); +} + +/* Description of im_mask2vips. + */ +static im_function mask2vips_desc = { + "im_mask2vips", /* Name */ + "convert DOUBLEMASK to VIPS image", + 0, /* Flags */ + mask2vips_vec, /* Dispatch function */ + IM_NUMBER( mask2vips_args ), /* Size of arg list */ + mask2vips_args /* Arg list */ +}; + +/* Args to im_vips2mask. + */ +static im_arg_desc vips2mask_args[] = { + IM_INPUT_IMAGE( "input" ), + IM_OUTPUT_DMASK( "output" ), +}; + +/* Call im_vips2mask via arg vector. + */ +static int +vips2mask_vec( im_object *argv ) +{ + im_mask_object *mo = argv[1]; + + if( !(mo->mask = im_vips2mask( argv[0], mo->name )) ) + return( -1 ); + + return( 0 ); +} + +/* Description of im_vips2mask. + */ +static im_function vips2mask_desc = { + "im_vips2mask", /* Name */ + "convert VIPS image to DOUBLEMASK", + 0, /* Flags */ + vips2mask_vec, /* Dispatch function */ + IM_NUMBER( vips2mask_args ), /* Size of arg list */ + vips2mask_args /* Arg list */ +}; + /* Package up all these functions. */ static im_function *deprecated_list[] = { @@ -1475,6 +1534,8 @@ static im_function *deprecated_list[] = { &similarity_area_desc, &similarity_desc, &remainderconst_vec_desc, + &mask2vips_desc, + &vips2mask_desc, &insertplace_desc, &circle_desc }; diff --git a/libvips/mask/im_gaussmasks.c b/libvips/deprecated/im_gaussmasks.c similarity index 100% rename from libvips/mask/im_gaussmasks.c rename to libvips/deprecated/im_gaussmasks.c diff --git a/libvips/mask/im_logmasks.c b/libvips/deprecated/im_logmasks.c similarity index 100% rename from libvips/mask/im_logmasks.c rename to libvips/deprecated/im_logmasks.c diff --git a/libvips/conversion/im_mask2vips.c b/libvips/deprecated/im_mask2vips.c similarity index 100% rename from libvips/conversion/im_mask2vips.c rename to libvips/deprecated/im_mask2vips.c diff --git a/libvips/mask/im_matcat.c b/libvips/deprecated/im_matcat.c similarity index 100% rename from libvips/mask/im_matcat.c rename to libvips/deprecated/im_matcat.c diff --git a/libvips/mask/im_matinv.c b/libvips/deprecated/im_matinv.c similarity index 100% rename from libvips/mask/im_matinv.c rename to libvips/deprecated/im_matinv.c diff --git a/libvips/mask/im_matmul.c b/libvips/deprecated/im_matmul.c similarity index 100% rename from libvips/mask/im_matmul.c rename to libvips/deprecated/im_matmul.c diff --git a/libvips/mask/im_mattrn.c b/libvips/deprecated/im_mattrn.c similarity index 100% rename from libvips/mask/im_mattrn.c rename to libvips/deprecated/im_mattrn.c diff --git a/libvips/conversion/im_vips2mask.c b/libvips/deprecated/im_vips2mask.c similarity index 100% rename from libvips/conversion/im_vips2mask.c rename to libvips/deprecated/im_vips2mask.c diff --git a/libvips/mask/mask_dispatch.c b/libvips/deprecated/mask_dispatch.c similarity index 100% rename from libvips/mask/mask_dispatch.c rename to libvips/deprecated/mask_dispatch.c diff --git a/libvips/mask/matalloc.c b/libvips/deprecated/matalloc.c similarity index 100% rename from libvips/mask/matalloc.c rename to libvips/deprecated/matalloc.c diff --git a/libvips/mask/rotmask.c b/libvips/deprecated/rotmask.c similarity index 100% rename from libvips/mask/rotmask.c rename to libvips/deprecated/rotmask.c diff --git a/libvips/mask/rw_mask.c b/libvips/deprecated/rw_mask.c similarity index 100% rename from libvips/mask/rw_mask.c rename to libvips/deprecated/rw_mask.c diff --git a/libvips/deprecated/vips7compat.c b/libvips/deprecated/vips7compat.c index 81f41160..d95a29d7 100644 --- a/libvips/deprecated/vips7compat.c +++ b/libvips/deprecated/vips7compat.c @@ -1529,11 +1529,11 @@ im_black( IMAGE *out, int x, int y, int bands ) } static int -vips__math( VipsImage *in, VipsImage *out, VipsMathOperation operation ) +vips__math( VipsImage *in, VipsImage *out, VipsOperationMath math ) { VipsImage *t; - if( vips_math( in, &t, operation, + if( vips_math( in, &t, math, NULL ) ) return( -1 ); if( vips_image_write( t, out ) ) { @@ -1548,61 +1548,61 @@ vips__math( VipsImage *in, VipsImage *out, VipsMathOperation operation ) int im_sintra( IMAGE *in, IMAGE *out ) { - return( vips__math( in, out, VIPS_MATH_OPERATION_SIN ) ); + return( vips__math( in, out, VIPS_OPERATION_MATH_SIN ) ); } int im_costra( IMAGE *in, IMAGE *out ) { - return( vips__math( in, out, VIPS_MATH_OPERATION_COS ) ); + return( vips__math( in, out, VIPS_OPERATION_MATH_COS ) ); } int im_tantra( IMAGE *in, IMAGE *out ) { - return( vips__math( in, out, VIPS_MATH_OPERATION_TAN ) ); + return( vips__math( in, out, VIPS_OPERATION_MATH_TAN ) ); } int im_asintra( IMAGE *in, IMAGE *out ) { - return( vips__math( in, out, VIPS_MATH_OPERATION_ASIN ) ); + return( vips__math( in, out, VIPS_OPERATION_MATH_ASIN ) ); } int im_acostra( IMAGE *in, IMAGE *out ) { - return( vips__math( in, out, VIPS_MATH_OPERATION_ACOS ) ); + return( vips__math( in, out, VIPS_OPERATION_MATH_ACOS ) ); } int im_atantra( IMAGE *in, IMAGE *out ) { - return( vips__math( in, out, VIPS_MATH_OPERATION_ATAN ) ); + return( vips__math( in, out, VIPS_OPERATION_MATH_ATAN ) ); } int im_logtra( IMAGE *in, IMAGE *out ) { - return( vips__math( in, out, VIPS_MATH_OPERATION_LOG ) ); + return( vips__math( in, out, VIPS_OPERATION_MATH_LOG ) ); } int im_log10tra( IMAGE *in, IMAGE *out ) { - return( vips__math( in, out, VIPS_MATH_OPERATION_LOG10 ) ); + return( vips__math( in, out, VIPS_OPERATION_MATH_LOG10 ) ); } int im_exptra( IMAGE *in, IMAGE *out ) { - return( vips__math( in, out, VIPS_MATH_OPERATION_EXP ) ); + return( vips__math( in, out, VIPS_OPERATION_MATH_EXP ) ); } int im_exp10tra( IMAGE *in, IMAGE *out ) { - return( vips__math( in, out, VIPS_MATH_OPERATION_EXP10 ) ); + return( vips__math( in, out, VIPS_OPERATION_MATH_EXP10 ) ); } DOUBLEMASK * @@ -1645,3 +1645,38 @@ im_recomb( IMAGE *in, IMAGE *out, DOUBLEMASK *recomb ) return( 0 ); } + +static int +vips__round( VipsImage *in, VipsImage *out, VipsOperationRound round ) +{ + VipsImage *t; + + if( vips_round( in, &t, round, + NULL ) ) + return( -1 ); + if( vips_image_write( t, out ) ) { + g_object_unref( t ); + return( -1 ); + } + g_object_unref( t ); + + return( 0 ); +} + +int +im_rint( IMAGE *in, IMAGE *out ) +{ + return( vips__round( in, out, VIPS_OPERATION_ROUND_NEAREST ) ); +} + +int +im_floor( IMAGE *in, IMAGE *out ) +{ + return( vips__round( in, out, VIPS_OPERATION_ROUND_FLOOR ) ); +} + +int +im_ceil( IMAGE *in, IMAGE *out ) +{ + return( vips__round( in, out, VIPS_OPERATION_ROUND_CEIL ) ); +} diff --git a/libvips/include/vips/arithmetic.h b/libvips/include/vips/arithmetic.h index ed5f6705..ed67f3b7 100644 --- a/libvips/include/vips/arithmetic.h +++ b/libvips/include/vips/arithmetic.h @@ -38,33 +38,48 @@ extern "C" { #endif /*__cplusplus*/ /** - * VipsMathOperation: - * @VIPS_MATH_OPERATION_SIN: sin(), angles in degrees - * @VIPS_MATH_OPERATION_COS: cos(), angles in degrees - * @VIPS_MATH_OPERATION_TAN: tan(), angles in degrees - * @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_EXP: e to the something - * @VIPS_MATH_OPERATION_EXP10: 10 to the something + * VipsOperationMath: + * @VIPS_OPERATION_MATH_SIN: sin(), angles in degrees + * @VIPS_OPERATION_MATH_COS: cos(), angles in degrees + * @VIPS_OPERATION_MATH_TAN: tan(), angles in degrees + * @VIPS_OPERATION_MATH_ASIN: asin(), angles in degrees + * @VIPS_OPERATION_MATH_ACOS: acos(), angles in degrees + * @VIPS_OPERATION_MATH_ATAN: atan(), angles in degrees + * @VIPS_OPERATION_MATH_LOG: log base e + * @VIPS_OPERATION_MATH_LOG10: log base 10 + * @VIPS_OPERATION_MATH_EXP: e to the something + * @VIPS_OPERATION_MATH_EXP10: 10 to the something * * See also: vips_math(). */ typedef enum { - VIPS_MATH_OPERATION_SIN, - VIPS_MATH_OPERATION_COS, - VIPS_MATH_OPERATION_TAN, - VIPS_MATH_OPERATION_ASIN, - VIPS_MATH_OPERATION_ACOS, - VIPS_MATH_OPERATION_ATAN, - VIPS_MATH_OPERATION_LOG, - VIPS_MATH_OPERATION_LOG10, - VIPS_MATH_OPERATION_EXP, - VIPS_MATH_OPERATION_EXP10, - VIPS_MATH_OPERATION_LAST -} VipsMathOperation; + VIPS_OPERATION_MATH_SIN, + VIPS_OPERATION_MATH_COS, + VIPS_OPERATION_MATH_TAN, + VIPS_OPERATION_MATH_ASIN, + VIPS_OPERATION_MATH_ACOS, + VIPS_OPERATION_MATH_ATAN, + VIPS_OPERATION_MATH_LOG, + VIPS_OPERATION_MATH_LOG10, + VIPS_OPERATION_MATH_EXP, + VIPS_OPERATION_MATH_EXP10, + VIPS_OPERATION_MATH_LAST +} VipsOperationMath; + +/** + * VipsOperationRound: + * @VIPS_OPERATION_ROUND_NEAREST: round to nearest + * @VIPS_OPERATION_ROUND_FLOOR: largest integral value not greater than + * @VIPS_OPERATION_ROUND_CEIL: the smallest integral value not less than + * + * See also: vips_round(). + */ +typedef enum { + VIPS_OPERATION_ROUND_NEAREST, + VIPS_OPERATION_ROUND_CEIL, + VIPS_OPERATION_ROUND_FLOOR, + VIPS_OPERATION_ROUND_LAST +} VipsOperationRound; int vips_add( VipsImage *left, VipsImage *right, VipsImage **out, ... ) __attribute__((sentinel)); @@ -90,7 +105,7 @@ int vips_linear( VipsImage *in, VipsImage **out, int vips_linear1( VipsImage *in, VipsImage **out, double a, double b, ... ) __attribute__((sentinel)); int vips_math( VipsImage *in, VipsImage **out, - VipsMathOperation operation, ... ) + VipsOperationMath math, ... ) __attribute__((sentinel)); int vips_abs( VipsImage *in, VipsImage **out, ... ) __attribute__((sentinel)); @@ -102,6 +117,8 @@ int vips_measure( VipsImage *in, VipsImage **out, int h, int v, ... ) __attribute__((sentinel)); int vips_recomb( VipsImage *in, VipsImage **out, VipsImage *m, ... ) __attribute__((sentinel)); +int vips_round( VipsImage *in, VipsImage **out, VipsOperationRound round, ... ) + __attribute__((sentinel)); @@ -115,9 +132,6 @@ int im_remainder( VipsImage *in1, VipsImage *in2, VipsImage *out ); int im_remainder_vec( VipsImage *in, VipsImage *out, int n, double *c ); int im_remainderconst( VipsImage *in, VipsImage *out, double c ); -int im_floor( VipsImage *in, VipsImage *out ); -int im_rint( VipsImage *in, VipsImage *out ); -int im_ceil( VipsImage *in, VipsImage *out ); int im_linreg( VipsImage **ins, VipsImage *out, double *xs ); int im_point( VipsImage *im, VipsInterpolate *interpolate, diff --git a/libvips/include/vips/conversion.h b/libvips/include/vips/conversion.h index d76778b1..482010bd 100644 --- a/libvips/include/vips/conversion.h +++ b/libvips/include/vips/conversion.h @@ -167,11 +167,6 @@ int vips_rot( VipsImage *in, VipsImage **out, VipsAngle angle, ... ) __attribute__((sentinel)); - - -DOUBLEMASK *im_vips2mask( VipsImage *in, const char *filename ); -int im_mask2vips( DOUBLEMASK *in, VipsImage *out ); - int im_copy_file( VipsImage *in, VipsImage *out ); int im_scale( VipsImage *in, VipsImage *out ); diff --git a/libvips/include/vips/enumtypes.h b/libvips/include/vips/enumtypes.h index 6b6d8d85..545d9f60 100644 --- a/libvips/include/vips/enumtypes.h +++ b/libvips/include/vips/enumtypes.h @@ -7,8 +7,10 @@ G_BEGIN_DECLS /* enumerations from "../../../libvips/include/vips/arithmetic.h" */ -GType vips_math_operation_get_type (void) G_GNUC_CONST; -#define VIPS_TYPE_MATH_OPERATION (vips_math_operation_get_type()) +GType vips_operation_math_get_type (void) G_GNUC_CONST; +#define VIPS_TYPE_OPERATION_MATH (vips_operation_math_get_type()) +GType vips_operation_round_get_type (void) G_GNUC_CONST; +#define VIPS_TYPE_OPERATION_ROUND (vips_operation_round_get_type()) /* enumerations from "../../../libvips/include/vips/conversion.h" */ GType vips_extend_get_type (void) G_GNUC_CONST; #define VIPS_TYPE_EXTEND (vips_extend_get_type()) diff --git a/libvips/include/vips/vips7compat.h b/libvips/include/vips/vips7compat.h index 50aa9597..bd87dd1f 100644 --- a/libvips/include/vips/vips7compat.h +++ b/libvips/include/vips/vips7compat.h @@ -553,6 +553,10 @@ int im_log10tra( VipsImage *in, VipsImage *out ); int im_exptra( VipsImage *in, VipsImage *out ); int im_exp10tra( VipsImage *in, VipsImage *out ); +int im_floor( VipsImage *in, VipsImage *out ); +int im_rint( VipsImage *in, VipsImage *out ); +int im_ceil( VipsImage *in, VipsImage *out ); + int im_copy( VipsImage *in, VipsImage *out ); int im_copy_set( VipsImage *in, VipsImage *out, VipsInterpretation interpretation, @@ -587,6 +591,9 @@ int im_rot90( VipsImage *in, VipsImage *out ); int im_rot180( VipsImage *in, VipsImage *out ); int im_rot270( VipsImage *in, VipsImage *out ); +DOUBLEMASK *im_vips2mask( VipsImage *in, const char *filename ); +int im_mask2vips( DOUBLEMASK *in, VipsImage *out ); + /* ruby-vips uses this diff --git a/libvips/iofuncs/enumtypes.c b/libvips/iofuncs/enumtypes.c index ead250d8..45220476 100644 --- a/libvips/iofuncs/enumtypes.c +++ b/libvips/iofuncs/enumtypes.c @@ -85,27 +85,46 @@ vips_angle_get_type( void ) } /* enumerations from "../../libvips/include/vips/arithmetic.h" */ GType -vips_math_operation_get_type( void ) +vips_operation_math_get_type( void ) { static GType etype = 0; if( etype == 0 ) { static const GEnumValue values[] = { - {VIPS_MATH_OPERATION_SIN, "VIPS_MATH_OPERATION_SIN", "sin"}, - {VIPS_MATH_OPERATION_COS, "VIPS_MATH_OPERATION_COS", "cos"}, - {VIPS_MATH_OPERATION_TAN, "VIPS_MATH_OPERATION_TAN", "tan"}, - {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_EXP, "VIPS_MATH_OPERATION_EXP", "exp"}, - {VIPS_MATH_OPERATION_EXP10, "VIPS_MATH_OPERATION_EXP10", "exp10"}, - {VIPS_MATH_OPERATION_LAST, "VIPS_MATH_OPERATION_LAST", "last"}, + {VIPS_OPERATION_MATH_SIN, "VIPS_OPERATION_MATH_SIN", "sin"}, + {VIPS_OPERATION_MATH_COS, "VIPS_OPERATION_MATH_COS", "cos"}, + {VIPS_OPERATION_MATH_TAN, "VIPS_OPERATION_MATH_TAN", "tan"}, + {VIPS_OPERATION_MATH_ASIN, "VIPS_OPERATION_MATH_ASIN", "asin"}, + {VIPS_OPERATION_MATH_ACOS, "VIPS_OPERATION_MATH_ACOS", "acos"}, + {VIPS_OPERATION_MATH_ATAN, "VIPS_OPERATION_MATH_ATAN", "atan"}, + {VIPS_OPERATION_MATH_LOG, "VIPS_OPERATION_MATH_LOG", "log"}, + {VIPS_OPERATION_MATH_LOG10, "VIPS_OPERATION_MATH_LOG10", "log10"}, + {VIPS_OPERATION_MATH_EXP, "VIPS_OPERATION_MATH_EXP", "exp"}, + {VIPS_OPERATION_MATH_EXP10, "VIPS_OPERATION_MATH_EXP10", "exp10"}, + {VIPS_OPERATION_MATH_LAST, "VIPS_OPERATION_MATH_LAST", "last"}, {0, NULL, NULL} }; - etype = g_enum_register_static( "VipsMathOperation", values ); + etype = g_enum_register_static( "VipsOperationMath", values ); + } + + return( etype ); +} +GType +vips_operation_round_get_type( void ) +{ + static GType etype = 0; + + if( etype == 0 ) { + static const GEnumValue values[] = { + {VIPS_OPERATION_ROUND_NEAREST, "VIPS_OPERATION_ROUND_NEAREST", "nearest"}, + {VIPS_OPERATION_ROUND_CEIL, "VIPS_OPERATION_ROUND_CEIL", "ceil"}, + {VIPS_OPERATION_ROUND_FLOOR, "VIPS_OPERATION_ROUND_FLOOR", "floor"}, + {VIPS_OPERATION_ROUND_LAST, "VIPS_OPERATION_ROUND_LAST", "last"}, + {0, NULL, NULL} + }; + + etype = g_enum_register_static( "VipsOperationRound", values ); } return( etype ); diff --git a/libvips/mask/Makefile.am b/libvips/mask/Makefile.am deleted file mode 100644 index d38e4dfa..00000000 --- a/libvips/mask/Makefile.am +++ /dev/null @@ -1,15 +0,0 @@ -noinst_LTLIBRARIES = libmask.la - -libmask_la_SOURCES = \ - rotmask.c \ - im_gaussmasks.c \ - im_logmasks.c \ - rw_mask.c \ - im_matcat.c \ - im_matinv.c \ - im_matmul.c \ - im_mattrn.c \ - matalloc.c \ - mask_dispatch.c - -INCLUDES = -I${top_srcdir}/libvips/include @VIPS_CFLAGS@ @VIPS_INCLUDES@