patch im_check_ back
This commit is contained in:
parent
ec73347f59
commit
97f1c38bef
@ -221,12 +221,8 @@ abs_gen( PEL *in, PEL *out, int width, IMAGE *im )
|
||||
int
|
||||
im_abs( IMAGE *in, IMAGE *out )
|
||||
{
|
||||
/* Check args.
|
||||
*/
|
||||
if( in->Coding != IM_CODING_NONE ) {
|
||||
im_error( "im_abs", "%s", _( "not uncoded" ) );
|
||||
if( im_check_uncoded( "im_abs", in ) )
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
/* Is this one of the unsigned types? Degenerate to im_copy() if it
|
||||
* is.
|
||||
|
@ -344,19 +344,13 @@ static int bandfmt_add[10] = {
|
||||
int
|
||||
im_add( IMAGE *in1, IMAGE *in2, IMAGE *out )
|
||||
{
|
||||
/* Basic checks.
|
||||
*/
|
||||
if( im_piocheck( in1, out ) || im_pincheck( in2 ) )
|
||||
if( im_piocheck( in1, out ) ||
|
||||
im_pincheck( in2 ) ||
|
||||
im_check_bands_1orn( "im_add", in1, in2 ) ||
|
||||
im_check_uncoded( "im_add", in1 ) ||
|
||||
im_check_uncoded( "im_add", in2 ) )
|
||||
return( -1 );
|
||||
if( in1->Bands != in2->Bands &&
|
||||
(in1->Bands != 1 && in2->Bands != 1) ) {
|
||||
im_error( "im_add", "%s", _( "not same number of bands" ) );
|
||||
return( -1 );
|
||||
}
|
||||
if( in1->Coding != IM_CODING_NONE || in2->Coding != IM_CODING_NONE ) {
|
||||
im_error( "im_add", "%s", _( "not uncoded" ) );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
if( im_cp_descv( out, in1, in2, NULL ) )
|
||||
return( -1 );
|
||||
|
||||
|
@ -181,16 +181,10 @@ im_avg( IMAGE *in, double *out )
|
||||
|
||||
/* Check our args.
|
||||
*/
|
||||
if( im_pincheck( in ) )
|
||||
if( im_pincheck( in ) ||
|
||||
im_check_noncomplex( "im_avg", in ) ||
|
||||
im_check_uncoded( "im_avg", in ) )
|
||||
return( -1 );
|
||||
if( im_iscomplex( in ) ) {
|
||||
im_error( "im_avg", "%s", _( "bad input type" ) );
|
||||
return( -1 );
|
||||
}
|
||||
if( in->Coding != IM_CODING_NONE ) {
|
||||
im_error( "im_avg", "%s", _( "not uncoded" ) );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
/* Loop over input, summing pixels.
|
||||
*/
|
||||
|
@ -138,10 +138,8 @@ im_bandmean( IMAGE *in, IMAGE *out )
|
||||
*/
|
||||
if( in->Bands == 1 )
|
||||
return( im_copy( in, out ) );
|
||||
if( in->Coding != IM_CODING_NONE ) {
|
||||
im_error( "im_bandmean", "%s", _( "uncoded multiband only" ) );
|
||||
if( im_check_uncoded( "im_bandmean", in ) )
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
/* Prepare output image.
|
||||
*/
|
||||
|
@ -86,12 +86,8 @@ ceil_gen( PEL *in, PEL *out, int width, IMAGE *im )
|
||||
int
|
||||
im_ceil( IMAGE *in, IMAGE *out )
|
||||
{
|
||||
/* Check args.
|
||||
*/
|
||||
if( in->Coding != IM_CODING_NONE ) {
|
||||
im_error( "im_ceil", "%s", _( "not uncoded" ) );
|
||||
if( im_check_uncoded( "im_ceil", in ) )
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
/* Is this one of the int types? Degenerate to im_copy() if it
|
||||
* is.
|
||||
|
@ -70,14 +70,13 @@
|
||||
/* 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] = cos( IM_RAD( (double) p[x] ) );\
|
||||
}
|
||||
#define loop( IN, OUT ) { \
|
||||
IN *p = (IN *) in; \
|
||||
OUT *q = (OUT *) out; \
|
||||
\
|
||||
for( x = 0; x < sz; x++ ) \
|
||||
q[x] = cos( IM_RAD( (double) p[x] ) ); \
|
||||
}
|
||||
|
||||
/* cos a buffer of PELs.
|
||||
*/
|
||||
@ -109,18 +108,10 @@ costra_gen( PEL *in, PEL *out, int width, IMAGE *im )
|
||||
int
|
||||
im_costra( IMAGE *in, IMAGE *out )
|
||||
{
|
||||
/* Check args.
|
||||
*/
|
||||
if( im_piocheck( in, out ) )
|
||||
if( im_piocheck( in, out ) ||
|
||||
im_check_uncoded( "im_costra", in ) ||
|
||||
im_check_noncomplex( "im_costra", in ) )
|
||||
return( -1 );
|
||||
if( in->Coding != IM_CODING_NONE ) {
|
||||
im_error( "im_costra", "%s", _( "not uncoded" ) );
|
||||
return( -1 );
|
||||
}
|
||||
if( im_iscomplex( in ) ) {
|
||||
im_error( "im_costra", "%s", _( "bad input type" ) );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
/* Prepare output header.
|
||||
*/
|
||||
@ -155,14 +146,13 @@ im_costra( IMAGE *in, IMAGE *out )
|
||||
|
||||
/* And acos().
|
||||
*/
|
||||
#define aloop( IN, OUT )\
|
||||
{\
|
||||
IN *p = (IN *) in;\
|
||||
OUT *q = (OUT *) out;\
|
||||
\
|
||||
for( x = 0; x < sz; x++ )\
|
||||
q[x] = IM_DEG( acos( (double) p[x] ) );\
|
||||
}
|
||||
#define aloop( IN, OUT ) { \
|
||||
IN *p = (IN *) in; \
|
||||
OUT *q = (OUT *) out; \
|
||||
\
|
||||
for( x = 0; x < sz; x++ ) \
|
||||
q[x] = IM_DEG( acos( (double) p[x] ) ); \
|
||||
}
|
||||
|
||||
/* acos a buffer of PELs.
|
||||
*/
|
||||
@ -193,19 +183,11 @@ acostra_gen( PEL *in, PEL *out, int width, IMAGE *im )
|
||||
*/
|
||||
int
|
||||
im_acostra( IMAGE *in, IMAGE *out )
|
||||
{
|
||||
/* Check args.
|
||||
*/
|
||||
if( im_piocheck( in, out ) )
|
||||
{
|
||||
if( im_piocheck( in, out ) ||
|
||||
im_check_uncoded( "im_acostra", in ) ||
|
||||
im_check_noncomplex( "im_acostra", in ) )
|
||||
return( -1 );
|
||||
if( in->Coding != IM_CODING_NONE ) {
|
||||
im_error( "im_acostra", "%s", _( "not uncoded" ) );
|
||||
return( -1 );
|
||||
}
|
||||
if( im_iscomplex( in ) ) {
|
||||
im_error( "im_acostra", "%s", _( "bad input type" ) );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
/* Prepare output header.
|
||||
*/
|
||||
|
@ -133,26 +133,15 @@ int im_cross_phase( IMAGE *a, IMAGE *b, IMAGE *out ){
|
||||
if( im_pincheck( a ) || im_pincheck( b ) || im_poutcheck( out ))
|
||||
return -1;
|
||||
|
||||
if( a-> Xsize != b-> Xsize || a-> Ysize != b-> Ysize ){
|
||||
im_error( FUNCTION_NAME, "not same size" );
|
||||
if( im_check_size( FUNCTION_NAME, a, b ) ||
|
||||
im_check_bands( FUNCTION_NAME, a, b ) ||
|
||||
im_check_uncoded( FUNCTION_NAME, a ) ||
|
||||
im_check_uncoded( FUNCTION_NAME, b ) ||
|
||||
im_check_format( FUNCTION_NAME, a, b ) ||
|
||||
im_check_complex( FUNCTION_NAME, a ) ||
|
||||
im_check_complex( FUNCTION_NAME, b ) )
|
||||
return -1;
|
||||
}
|
||||
if( a-> Bands != b-> Bands ){
|
||||
im_error( FUNCTION_NAME, "numbers of bands differ" );
|
||||
return -1;
|
||||
}
|
||||
if( a-> Coding || b-> Coding ){
|
||||
im_error( FUNCTION_NAME, "not uncoded" );
|
||||
return -1;
|
||||
}
|
||||
if( a-> BandFmt != b-> BandFmt ){
|
||||
im_error( FUNCTION_NAME, "formats differ" );
|
||||
return -1;
|
||||
}
|
||||
if( IM_BANDFMT_COMPLEX != a-> BandFmt && IM_BANDFMT_DPCOMPLEX != a-> BandFmt ){
|
||||
im_error( FUNCTION_NAME, "not complex format" );
|
||||
return -1;
|
||||
}
|
||||
|
||||
return im_cp_descv( out, a, b, NULL ) || im_wraptwo( a, b, out,
|
||||
IM_BANDFMT_COMPLEX == a-> BandFmt ? complex_phase_float : complex_phase_double, a, NULL );
|
||||
}
|
||||
|
@ -193,16 +193,10 @@ im_deviate( IMAGE *in, double *out )
|
||||
|
||||
/* Check our args.
|
||||
*/
|
||||
if( im_pincheck( in ) )
|
||||
if( im_pincheck( in ) ||
|
||||
im_check_uncoded( "im_deviate", in ) ||
|
||||
im_check_noncomplex( "im_deviate", in ) )
|
||||
return( -1 );
|
||||
if( in->Coding != IM_CODING_NONE ) {
|
||||
im_error( "im_deviate", "%s", _( "not uncoded" ) );
|
||||
return( -1 );
|
||||
}
|
||||
if( im_iscomplex( in ) ) {
|
||||
im_error( "im_deviate", "%s", _( "bad input type" ) );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
/* Loop over input, summing pixels.
|
||||
*/
|
||||
@ -211,7 +205,7 @@ im_deviate( IMAGE *in, double *out )
|
||||
|
||||
/*
|
||||
|
||||
NOTE: NR suggests a two-pass algorithm to minimise roundoff.
|
||||
NOTE: NR suggests a two-pass algorithm to minimise roundoff.
|
||||
But that's too expensive for us :-( so do it the old one-pass
|
||||
way.
|
||||
|
||||
|
@ -172,20 +172,14 @@ divide_buffer( PEL **in, PEL *out, int width, IMAGE *im )
|
||||
|
||||
int
|
||||
im_divide( IMAGE *in1, IMAGE *in2, IMAGE *out )
|
||||
{
|
||||
/* Basic checks.
|
||||
*/
|
||||
if( im_piocheck( in1, out ) || im_pincheck( in2 ) )
|
||||
{
|
||||
if( im_piocheck( in1, out ) ||
|
||||
im_pincheck( in2 ) ||
|
||||
im_check_bands_1orn( "im_divide", in1, in2 ) ||
|
||||
im_check_uncoded( "im_divide", in1 ) ||
|
||||
im_check_uncoded( "im_divide", in2 ) )
|
||||
return( -1 );
|
||||
if( in1->Bands != in2->Bands &&
|
||||
(in1->Bands != 1 && in2->Bands != 1) ) {
|
||||
im_error( "im_divide", "%s", _( "not same number of bands" ) );
|
||||
return( -1 );
|
||||
}
|
||||
if( in1->Coding != IM_CODING_NONE || in2->Coding != IM_CODING_NONE ) {
|
||||
im_error( "im_divide", "%s", _( "not uncoded" ) );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
if( im_cp_descv( out, in1, in2, NULL ) )
|
||||
return( -1 );
|
||||
|
||||
|
@ -80,22 +80,21 @@ 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 loop1(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( e == 0.0 && f < 0.0 ) {\
|
||||
/* Division by zero! Difficult to report tho'\
|
||||
*/\
|
||||
q[x] = 0.0;\
|
||||
}\
|
||||
else\
|
||||
q[x] = pow( e, f );\
|
||||
}\
|
||||
if( e == 0.0 && f < 0.0 ) { \
|
||||
/* Division by zero! Difficult to report tho' \
|
||||
*/ \
|
||||
q[x] = 0.0; \
|
||||
} \
|
||||
else \
|
||||
q[x] = pow( e, f ); \
|
||||
} \
|
||||
}
|
||||
|
||||
/* Expntra a buffer.
|
||||
@ -128,22 +127,21 @@ 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)\
|
||||
{\
|
||||
IN *p = (IN *) in;\
|
||||
OUT *q = (OUT *) out;\
|
||||
#define loopn(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( e == 0.0 && f < 0.0 ) {\
|
||||
q[i] = 0.0;\
|
||||
}\
|
||||
else\
|
||||
q[i] = pow( e, f );\
|
||||
}\
|
||||
if( e == 0.0 && f < 0.0 ) { \
|
||||
q[i] = 0.0; \
|
||||
} \
|
||||
else \
|
||||
q[i] = pow( e, f ); \
|
||||
} \
|
||||
}
|
||||
|
||||
/* Expntra a buffer.
|
||||
@ -178,21 +176,11 @@ im_expntra_vec( IMAGE *in, IMAGE *out, int n, double *e )
|
||||
ExpntraInfo *inf;
|
||||
int i;
|
||||
|
||||
/* Check args.
|
||||
*/
|
||||
if( in->Coding != IM_CODING_NONE ) {
|
||||
im_error( "im_expntra_vec", "%s", _( "not uncoded" ) );
|
||||
if( im_piocheck( in, out ) ||
|
||||
im_check_uncoded( "im_expntra", in ) ||
|
||||
im_check_noncomplex( "im_expntra", in ) ||
|
||||
im_check_vector( "im_expntra_vec", n, in ) )
|
||||
return( -1 );
|
||||
}
|
||||
if( im_iscomplex( in ) ) {
|
||||
im_error( "im_expntra_vec", "%s", _( "not non-complex" ) );
|
||||
return( -1 );
|
||||
}
|
||||
if( n != 1 && n != in->Bands ) {
|
||||
im_error( "im_expntra_vec",
|
||||
_( "not 1 or %d elements in vector" ), in->Bands );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
/* Prepare output header.
|
||||
*/
|
||||
|
@ -136,6 +136,15 @@ int im_ispartial( IMAGE * );
|
||||
int im_isMSBfirst( IMAGE * );
|
||||
int im_amiMSBfirst( void );
|
||||
|
||||
int im_check_uncoded( const char *domain, IMAGE *im );
|
||||
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_size( const char *domain, IMAGE *im1, IMAGE *im2 );
|
||||
int im_check_bands( const char *domain, IMAGE *im1, IMAGE *im2 );
|
||||
int im_check_format( const char *domain, IMAGE *im1, IMAGE *im2 );
|
||||
int im_check_vector( const char *domain, int n, IMAGE *im );
|
||||
|
||||
int im_ispoweroftwo( int );
|
||||
|
||||
int im_existsf( const char *name, ... )
|
||||
|
@ -26,6 +26,8 @@
|
||||
* - cleanups
|
||||
* 22/5/08
|
||||
* - image format stuff broken out
|
||||
* 29/7/09
|
||||
* - check funcs added
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -356,3 +358,97 @@ im_isvips( const char *filename )
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
int
|
||||
im_check_uncoded( const char *domain, IMAGE *im )
|
||||
{
|
||||
if( im->Coding != IM_CODING_NONE ) {
|
||||
im_error( domain, "%s", _( "image must be uncoded" ) );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
int
|
||||
im_check_bands_1orn( const char *domain, IMAGE *im1, IMAGE *im2 )
|
||||
{
|
||||
if( im1->Bands != im2->Bands &&
|
||||
(im1->Bands != 1 && im2->Bands != 1) ) {
|
||||
im_error( domain, "%s",
|
||||
_( "images must have the same number of bands, "
|
||||
"or one muct be single-band" ) );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
int
|
||||
im_check_noncomplex( const char *domain, IMAGE *im )
|
||||
{
|
||||
if( im_iscomplex( im ) ) {
|
||||
im_error( domain, "%s", _( "image must be non-complex" ) );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
int
|
||||
im_check_complex( const char *domain, IMAGE *im )
|
||||
{
|
||||
if( !im_iscomplex( im ) ) {
|
||||
im_error( domain, "%s", _( "image must be complex" ) );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
int
|
||||
im_check_size( const char *domain, IMAGE *im1, IMAGE *im2 )
|
||||
{
|
||||
if( im1->Xsize != im2->Xsize || im1->Ysize != im2->Ysize ) {
|
||||
im_error( domain, "%s", _( "images must match in size" ) );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
int
|
||||
im_check_bands( const char *domain, IMAGE *im1, IMAGE *im2 )
|
||||
{
|
||||
if( im1->Bands != im2->Bands ) {
|
||||
im_error( domain, "%s",
|
||||
_( "images must have the same number of bands" ) );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
int
|
||||
im_check_format( const char *domain, IMAGE *im1, IMAGE *im2 )
|
||||
{
|
||||
if( im1->BandFmt != im2->BandFmt ) {
|
||||
im_error( domain, "%s",
|
||||
_( "images must have the same band format" ) );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
int
|
||||
im_check_vector( const char *domain, int n, IMAGE *im )
|
||||
{
|
||||
if( n != 1 && n != im->Bands ) {
|
||||
im_error( domain,
|
||||
_( "vector must have 1 or %d elements" ), im->Bands );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user