From 3a8a2645785909ced0cd0cbe134a468932bebaac Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Wed, 2 Sep 2009 20:37:40 +0000 Subject: [PATCH] more --- libvips/arithmetic/im_max.c | 7 ++--- libvips/arithmetic/im_maxpos_avg.c | 47 +++++++++++++++--------------- libvips/include/vips/proto.h | 1 + libvips/iofuncs/predicate.c | 11 +++++++ 4 files changed, 37 insertions(+), 29 deletions(-) diff --git a/libvips/arithmetic/im_max.c b/libvips/arithmetic/im_max.c index d4c9c705..2713432d 100644 --- a/libvips/arithmetic/im_max.c +++ b/libvips/arithmetic/im_max.c @@ -240,12 +240,9 @@ im_max( IMAGE *in, double *out ) inf.out = out; inf.valid = 0; - if( im_pincheck( in ) ) + if( im_pincheck( in ) || + im_check_uncoded( "im_max", in ) ) return( -1 ); - if( in->Coding != IM_CODING_NONE ) { - im_error( "im_max", "%s", _( "not uncoded" ) ); - return( -1 ); - } if( im_iterate( in, max_start, max_scan, max_stop, &inf, NULL ) ) return( -1 ); diff --git a/libvips/arithmetic/im_maxpos_avg.c b/libvips/arithmetic/im_maxpos_avg.c index 5427aaa1..cdb799fb 100644 --- a/libvips/arithmetic/im_maxpos_avg.c +++ b/libvips/arithmetic/im_maxpos_avg.c @@ -1,14 +1,4 @@ -/* @(#) Function to find the maximum of an image. Returns coords and value at - * @(#) double precision. In the event of a draw, returns average of all - * @(#) drawing coords, and interpolated value at that position. - * @(#) - * @(#) int im_maxpos_avg( - * @(#) IMAGE *im, - * @(#) double *xpos, - * @(#) double *ypos, - * @(#) double *out - * @(#) ); - * @(#) +/* im_maxpos_avg.c * * Copyright: 2006, The Nottingham Trent University * Copyright: 2006, Tom Vajzovic @@ -20,6 +10,8 @@ * - changed spelling of occurrences * - check for !occurrences before using val * - renamed avg as sum, a bit clearer + * 2/9/09 + * - gtkdoc comment */ /* @@ -83,30 +75,37 @@ static int maxpos_avg_stop( void *seq, void *, void * ); /** EXPORTED FUNCTION **/ +/** + * im_maxpos_avg: + * @im: image to scan + * @xpos: returned X position + * @ypos: returned Y position + * @out: returned value + * + * Function to find the maximum of an image. Returns coords and value at + * double precision. In the event of a draw, returns average of all + * drawing coords, and interpolated value at that position. + * + * See also: im_maxpos(), im_min(), im_stats(). + * + * Returns: 0 on success, -1 on error + */ int im_maxpos_avg( IMAGE *im, double *xpos, double *ypos, double *out ){ #define FUNCTION_NAME "im_maxpos_avg" pos_avg_t master= { 0.0, 0.0, 0.0, 0 }; - if( im_pincheck( im ) ) + if( im_pincheck( im ) || + im_check_uncoded( FUNCTION_NAME, im ) || + im_check_noncomplex( FUNCTION_NAME, im ) || + im_check_mono( FUNCTION_NAME, im ) ) return -1; - if( im-> Coding ){ - im_error( FUNCTION_NAME, "%s", _("uncoded images only") ); - return -1; - } - if( !( im_isint( im ) || im_isfloat( im ) ) ){ - im_error( FUNCTION_NAME, "%s", _("scalar images only") ); - return -1; - } - if( 1 != im-> Bands ){ - im_error( FUNCTION_NAME, "%s", _("single band images only") ); - return -1; - } if( ! xpos || ! ypos || ! out ){ im_error( FUNCTION_NAME, "%s", _("invalid argument") ); return -1; } + if( im_iterate( im, maxpos_avg_start, maxpos_avg_scan, maxpos_avg_stop, &master, NULL ) ) return -1; diff --git a/libvips/include/vips/proto.h b/libvips/include/vips/proto.h index 89856014..96447f01 100644 --- a/libvips/include/vips/proto.h +++ b/libvips/include/vips/proto.h @@ -141,6 +141,7 @@ int im_check_bands_1orn( const char *domain, IMAGE *im1, IMAGE *im2 ); int im_check_noncomplex( const char *domain, IMAGE *im ); int im_check_complex( const char *domain, IMAGE *im ); int im_check_uchar( const char *domain, IMAGE *im ); +int im_check_mono( const char *domain, IMAGE *im ); int im_check_int( const char *domain, IMAGE *im ); int im_check_size( const char *domain, IMAGE *im1, IMAGE *im2 ); int im_check_bands( const char *domain, IMAGE *im1, IMAGE *im2 ); diff --git a/libvips/iofuncs/predicate.c b/libvips/iofuncs/predicate.c index d54e8710..313685e3 100644 --- a/libvips/iofuncs/predicate.c +++ b/libvips/iofuncs/predicate.c @@ -417,6 +417,17 @@ im_check_uchar( const char *domain, IMAGE *im ) return( 0 ); } +int +im_check_mono( const char *domain, IMAGE *im ) +{ + if( im->Bands != 1 ) { + im_error( domain, "%s", _( "image must one band" ) ); + return( -1 ); + } + + return( 0 ); +} + int im_check_int( const char *domain, IMAGE *im ) {