hist hacking

This commit is contained in:
John Cupitt 2010-03-24 10:14:16 +00:00
parent 0954cf9df8
commit 2c2aa11cd9
3 changed files with 39 additions and 12 deletions

View File

@ -61,7 +61,6 @@
#include <vips/intl.h>
#include <stdio.h>
#include <assert.h>
#include <vips/vips.h>
@ -96,15 +95,9 @@ im_histcum( IMAGE *in, IMAGE *out )
PEL *outbuf;
int b, x;
if( in->Coding != IM_CODING_NONE ) {
im_error( "im_histcum", "%s", _( "input coded" ) );
return( -1 );
}
if( px > 65536 ) {
im_error( "im_histcum", "%s", _( "input too large" ) );
return( -1 );
}
if( im_incheck( in ) )
if( im_check_uncoded( "im_histcum", in ) ||
im_check_hist( "im_histcum", in ) ||
im_iocheck( in, out ) )
return( -1 );
if( im_cp_desc( out, in ) )
@ -115,6 +108,8 @@ im_histcum( IMAGE *in, IMAGE *out )
out->BandFmt = IM_BANDFMT_UINT;
else if( vips_bandfmt_isint( in->BandFmt ) )
out->BandFmt = IM_BANDFMT_INT;
if( im_setupout( out ) )
return( -1 );
if( !(outbuf = im_malloc( out, IM_IMAGE_SIZEOF_LINE( out ))) )
return( -1 );
@ -141,10 +136,10 @@ im_histcum( IMAGE *in, IMAGE *out )
ACCUMULATE( double, double ); break;
default:
assert( 0 );
g_assert( 0 );
}
if( im_setupout( out ) || im_writeline( 0, out, outbuf ) )
if( im_writeline( 0, out, outbuf ) )
return( -1 );
return( 0 );

View File

@ -64,6 +64,7 @@ int im_check_8or16( const char *domain, IMAGE *im );
int im_check_format_same( const char *domain, IMAGE *im1, IMAGE *im2 );
int im_check_size_same( const char *domain, IMAGE *im1, IMAGE *im2 );
int im_check_vector( const char *domain, int n, IMAGE *im );
int im_check_hist( const char *domain, IMAGE *im );
int im_check_imask( const char *domain, INTMASK *mask );
int im_check_dmask( const char *domain, DOUBLEMASK *mask );

View File

@ -1048,6 +1048,37 @@ im_check_vector( const char *domain, int n, IMAGE *im )
return( 0 );
}
/**
* im_check_hist:
* @domain: the originating domain for the error message
* @im: image to check
*
* Histogram images must have width or height 1, and must not have more than
* 65536 elements. Return 0 if the image will pass as a histogram, or -1 and
* set an error message otherwise.
*
* See also: im_error().
*
* Returns: 0 if OK, -1 otherwise.
*/
int
im_check_hist( const char *domain, IMAGE *im )
{
if( im->Xsize != 1 && im->Ysize != 1 ) {
im_error( domain, "%s",
_( "histograms must have width or height 1" ) );
return( -1 );
}
if( im->Xsize * im->Ysize > 65536 ) {
im_error( domain, "%s",
_( "histograms must have not have more than "
"65536 elements" ) );
return( -1 );
}
return( 0 );
}
/**
* im_check_imask:
* @domain: the originating domain for the error message