static void vips_divide_buffer( VipsArithmetic *arithmetic, VipsPel *out, VipsPel **in, int width ) { VipsImage *im = arithmetic->ready[0]; const int sz = width * vips_image_get_bands( im ); int x; /* Keep types here in sync with bandfmt_divide[] * below. */ switch( vips_image_get_format( im ) ) { case VIPS_FORMAT_CHAR: RLOOP( signed char, float ); break; case VIPS_FORMAT_UCHAR: RLOOP( unsigned char, float ); break; case VIPS_FORMAT_SHORT: RLOOP( signed short, float ); break; case VIPS_FORMAT_USHORT: RLOOP( unsigned short, float ); break; case VIPS_FORMAT_INT: RLOOP( signed int, float ); break; case VIPS_FORMAT_UINT: RLOOP( unsigned int, float ); break; case VIPS_FORMAT_FLOAT: RLOOP( float, float ); break; case VIPS_FORMAT_DOUBLE: RLOOP( double, double ); break; case VIPS_FORMAT_COMPLEX: CLOOP( float ); break; case VIPS_FORMAT_DPCOMPLEX: CLOOP( double ); break; default: g_assert( 0 ); } }
/* Loop over region, accumulating a sum in *tmp. */ static int vips_avg_scan( VipsStatistic *statistic, void *seq, int x, int y, void *in, int n ) { const int sz = n * vips_image_get_bands( statistic->in ); double *sum = (double *) seq; int i; double m; m = *sum; /* Now generate code for all types. */ switch( vips_image_get_format( statistic->in ) ) { case VIPS_FORMAT_UCHAR: LOOP( unsigned char ); break; case VIPS_FORMAT_CHAR: LOOP( signed char ); break; case VIPS_FORMAT_USHORT: LOOP( unsigned short ); break; case VIPS_FORMAT_SHORT: LOOP( signed short ); break; case VIPS_FORMAT_UINT: LOOP( unsigned int ); break; case VIPS_FORMAT_INT: LOOP( signed int ); break; case VIPS_FORMAT_FLOAT: LOOP( float ); break; case VIPS_FORMAT_DOUBLE: LOOP( double ); break; case VIPS_FORMAT_COMPLEX: CLOOP( float ); break; case VIPS_FORMAT_DPCOMPLEX: CLOOP( double ); break; default: g_assert_not_reached(); } *sum = m; return( 0 ); }
static void vips_math2_buffer( VipsArithmetic *arithmetic, PEL *out, PEL **in, int width ) { VipsMath2 *math2 = (VipsMath2 *) arithmetic; VipsImage *im = arithmetic->ready[0]; const int sz = width * vips_image_get_bands( im ); int x; switch( math2->math2 ) { case VIPS_OPERATION_MATH2_POW: SWITCH( LOOP, POW ); break; case VIPS_OPERATION_MATH2_WOP: SWITCH( LOOP, WOP ); break; default: g_assert( 0 ); } }
static void sum_buffer( VipsArithmetic *arithmetic, VipsPel *out, VipsPel **in, int width ) { VipsImage *im = arithmetic->ready[0]; int n = arithmetic->n; /* Complex just doubles the size. */ const int sz = width * vips_image_get_bands( im ) * (vips_band_format_iscomplex( vips_image_get_format( im ) ) ? 2 : 1); int x; int i; /* Sum all input types. Keep types here in sync with * vips_sum_format_table[] below. */ switch( vips_image_get_format( im ) ) { case VIPS_FORMAT_UCHAR: LOOP( unsigned char, unsigned int ); break; case VIPS_FORMAT_CHAR: LOOP( signed char, signed int ); break; case VIPS_FORMAT_USHORT: LOOP( unsigned short, unsigned int ); break; case VIPS_FORMAT_SHORT: LOOP( signed short, signed int ); break; case VIPS_FORMAT_UINT: LOOP( unsigned int, unsigned int ); break; case VIPS_FORMAT_INT: LOOP( signed int, signed int ); break; case VIPS_FORMAT_FLOAT: case VIPS_FORMAT_COMPLEX: LOOP( float, float ); break; case VIPS_FORMAT_DOUBLE: case VIPS_FORMAT_DPCOMPLEX: LOOP( double, double ); break; default: g_assert_not_reached(); } }
static void vips_complex_buffer( VipsArithmetic *arithmetic, VipsPel *out, VipsPel **in, int width ) { VipsComplex *cmplx = (VipsComplex *) arithmetic; VipsImage *im = arithmetic->ready[0]; const int sz = width * vips_image_get_bands( im ); int x; switch( cmplx->cmplx ) { case VIPS_OPERATION_COMPLEX_POLAR: SWITCH( POLAR ); break; case VIPS_OPERATION_COMPLEX_RECT: SWITCH( RECT ); break; case VIPS_OPERATION_COMPLEX_CONJ: SWITCH( CONJ ); break; default: g_assert( 0 ); } }
static int vips_avg_build( VipsObject *object ) { VipsStatistic *statistic = VIPS_STATISTIC( object ); VipsAvg *avg = (VipsAvg *) object; gint64 vals; double average; if( VIPS_OBJECT_CLASS( vips_avg_parent_class )->build( object ) ) return( -1 ); vals = (gint64) vips_image_get_width( statistic->in ) * vips_image_get_height( statistic->in ) * vips_image_get_bands( statistic->in ); average = avg->sum / vals; g_object_set( object, "out", average, NULL ); return( 0 ); }
/* Loop over region, adding to seq. */ static int vips_min_scan( VipsStatistic *statistic, void *seq, int x, int y, void *in, int n ) { VipsMin *min = (VipsMin *) seq; const int bands = vips_image_get_bands( statistic->in ); const int sz = n * bands; int i; switch( vips_image_get_format( statistic->in ) ) { case VIPS_FORMAT_UCHAR: LOOPL( unsigned char, 0 ); break; case VIPS_FORMAT_CHAR: LOOPL( signed char, SCHAR_MIN ); break; case VIPS_FORMAT_USHORT: LOOPL( unsigned short, 0 ); break; case VIPS_FORMAT_SHORT: LOOPL( signed short, SHRT_MIN ); break; case VIPS_FORMAT_UINT: LOOPL( unsigned int, 0 ); break; case VIPS_FORMAT_INT: LOOPL( signed int, INT_MIN ); break; case VIPS_FORMAT_FLOAT: LOOPF( float ); break; case VIPS_FORMAT_DOUBLE: LOOPF( double ); break; case VIPS_FORMAT_COMPLEX: LOOPC( float ); break; case VIPS_FORMAT_DPCOMPLEX: LOOPC( double ); break; default: g_assert( 0 ); } return( 0 ); }
static void vips_invert_buffer( VipsArithmetic *arithmetic, PEL *out, PEL **in, int width ) { VipsImage *im = arithmetic->ready[0]; /* Complex just doubles the size. */ const int sz = width * vips_image_get_bands( im ) * (vips_band_format_iscomplex( vips_image_get_format( im ) ) ? 2 : 1); int x; switch( vips_image_get_format( im ) ) { case VIPS_FORMAT_UCHAR: LOOP( unsigned char, UCHAR_MAX ); break; case VIPS_FORMAT_CHAR: LOOPN( signed char ); break; case VIPS_FORMAT_USHORT: LOOP( unsigned short, USHRT_MAX ); break; case VIPS_FORMAT_SHORT: LOOPN( signed short ); break; case VIPS_FORMAT_UINT: LOOP( unsigned int, UINT_MAX ); break; case VIPS_FORMAT_INT: LOOPN( signed int ); break; case VIPS_FORMAT_FLOAT: case VIPS_FORMAT_COMPLEX: LOOPN( float ); break; case VIPS_FORMAT_DOUBLE: case VIPS_FORMAT_DPCOMPLEX: LOOPN( double ); break; default: g_assert( 0 ); } }
static void vips_remainder_buffer( VipsArithmetic *arithmetic, VipsPel *out, VipsPel **in, int width ) { VipsImage *im = arithmetic->ready[0]; const int sz = width * vips_image_get_bands( im ); int x; switch( vips_image_get_format( im ) ) { case VIPS_FORMAT_CHAR: IREMAINDER( signed char ); break; case VIPS_FORMAT_UCHAR: IREMAINDER( unsigned char ); break; case VIPS_FORMAT_SHORT: IREMAINDER( signed short ); break; case VIPS_FORMAT_USHORT:IREMAINDER( unsigned short ); break; case VIPS_FORMAT_INT: IREMAINDER( signed int ); break; case VIPS_FORMAT_UINT: IREMAINDER( unsigned int ); break; case VIPS_FORMAT_FLOAT: FREMAINDER( float ); break; case VIPS_FORMAT_DOUBLE:FREMAINDER( double ); break; default: g_assert( 0 ); } }
static void vips_invert_buffer( VipsArithmetic *arithmetic, VipsPel *out, VipsPel **in, int width ) { VipsImage *im = arithmetic->ready[0]; const int sz = width * vips_image_get_bands( im ); int x; switch( vips_image_get_format( im ) ) { case VIPS_FORMAT_UCHAR: LOOP( unsigned char, UCHAR_MAX ); break; case VIPS_FORMAT_CHAR: LOOPN( signed char ); break; case VIPS_FORMAT_USHORT: LOOP( unsigned short, USHRT_MAX ); break; case VIPS_FORMAT_SHORT: LOOPN( signed short ); break; case VIPS_FORMAT_UINT: LOOP( unsigned int, UINT_MAX ); break; case VIPS_FORMAT_INT: LOOPN( signed int ); break; case VIPS_FORMAT_FLOAT: LOOPN( float ); break; case VIPS_FORMAT_DOUBLE: LOOPN( double ); break; case VIPS_FORMAT_COMPLEX: LOOPC( float ); break; case VIPS_FORMAT_DPCOMPLEX: LOOPC( double ); break; default: g_assert_not_reached(); } }
static void vips_hist_cum_process( VipsHistogram *histogram, VipsPel *out, VipsPel **in, int width ) { const int bands = vips_image_get_bands( histogram->ready[0] ); const int nb = vips_bandfmt_iscomplex( histogram->ready[0]->BandFmt ) ? bands * 2 : bands; int mx = width * nb; int x, b; switch( vips_image_get_format( histogram->ready[0] ) ) { case VIPS_FORMAT_CHAR: ACCUMULATE( signed char, signed int ); break; case VIPS_FORMAT_UCHAR: ACCUMULATE( unsigned char, unsigned int ); break; case VIPS_FORMAT_SHORT: ACCUMULATE( signed short, signed int ); break; case VIPS_FORMAT_USHORT: ACCUMULATE( unsigned short, unsigned int ); break; case VIPS_FORMAT_INT: ACCUMULATE( signed int, signed int ); break; case VIPS_FORMAT_UINT: ACCUMULATE( unsigned int, unsigned int ); break; case VIPS_FORMAT_FLOAT: case VIPS_FORMAT_COMPLEX: ACCUMULATE( float, float ); break; case VIPS_FORMAT_DOUBLE: case VIPS_FORMAT_DPCOMPLEX: ACCUMULATE( double, double ); break; default: g_assert( 0 ); } }
static void vips_sign_buffer( VipsArithmetic *arithmetic, VipsPel *out, VipsPel **in, int width ) { VipsUnary *unary = VIPS_UNARY( arithmetic ); const int bands = vips_image_get_bands( unary->in ); int sz = width * bands; switch( vips_image_get_format( unary->in ) ) { case VIPS_FORMAT_UCHAR: SIGN( unsigned char ); break; case VIPS_FORMAT_CHAR: SIGN( signed char ); break; case VIPS_FORMAT_USHORT: SIGN( unsigned short ); break; case VIPS_FORMAT_SHORT: SIGN( signed short ); break; case VIPS_FORMAT_UINT: SIGN( unsigned int ); break; case VIPS_FORMAT_INT: SIGN( signed int ); break; case VIPS_FORMAT_FLOAT: SIGN( float ); break; case VIPS_FORMAT_DOUBLE: SIGN( double ); break; case VIPS_FORMAT_COMPLEX: CSIGN( float ); break; case VIPS_FORMAT_DPCOMPLEX: CSIGN( double ); break; default: g_assert_not_reached(); } }
q[x] = abs_ip * sqrt( 1.0 + temp * temp ); \ } \ \ p += 2; \ } \ } #endif /*HAVE_HYPOT*/ static void vips_abs_buffer( VipsArithmetic *arithmetic, VipsPel *out, VipsPel **in, int width ) { VipsArithmeticClass *class = VIPS_ARITHMETIC_GET_CLASS( arithmetic ); VipsImage *im = arithmetic->ready[0]; const int bands = vips_image_get_bands( im ); int sz = width * bands; VipsVector *v; if( (v = vips_arithmetic_get_vector( class, vips_image_get_format( im ) )) ) { VipsExecutor ex; vips_executor_set_program( &ex, v, sz ); vips_executor_set_array( &ex, v->s[0], in[0] ); vips_executor_set_destination( &ex, out ); vips_executor_run( &ex ); } else {