91
91
/* This is going to be much slower */
92
92
#define CLOOP( TYPE ) { \
93
TYPE *left = (TYPE *) in[0]; \
94
TYPE *right = (TYPE *) in[1]; \
95
TYPE *q = (TYPE *) out; \
93
TYPE * restrict left = (TYPE *) in[0]; \
94
TYPE * restrict right = (TYPE *) in[1]; \
95
TYPE * restrict q = (TYPE *) out; \
98
98
for( i = 0; i < sz; i++ ) { \
120
120
#else /* USE_MODARG_DIV */
122
122
#define CLOOP( TYPE ) { \
123
TYPE *left = (TYPE *) in[0]; \
124
TYPE *right = (TYPE *) in[1]; \
125
TYPE *q = (TYPE *) out; \
123
TYPE * restrict left = (TYPE *) in[0]; \
124
TYPE * restrict right = (TYPE *) in[1]; \
125
TYPE * restrict q = (TYPE *) out; \
128
128
for( i = 0; i < sz; i++ ) { \
157
157
/* Real divide. Cast in to OUT before divide so we work for float output.
159
159
#define RLOOP( IN, OUT ) { \
160
IN *left = (IN *) in[0]; \
161
IN *right = (IN *) in[1]; \
162
OUT *q = (OUT *) out; \
160
IN * restrict left = (IN *) in[0]; \
161
IN * restrict right = (IN *) in[1]; \
162
OUT * restrict q = (OUT *) out; \
164
164
for( x = 0; x < sz; x++ ) \
165
if( right[x] == 0 ) \
168
q[x] = (OUT) left[x] / (OUT) right[x]; \
165
q[x] = right[x] == 0 ? 0 : (OUT) left[x] / (OUT) right[x]; \
180
/* Keep types here in sync with bandfmt_divide[]
177
/* Keep types here in sync with vips_divide_format_table[]
183
180
switch( vips_image_get_format( im ) ) {
184
case VIPS_FORMAT_CHAR: RLOOP( signed char, float ); break;
185
case VIPS_FORMAT_UCHAR: RLOOP( unsigned char, float ); break;
186
case VIPS_FORMAT_SHORT: RLOOP( signed short, float ); break;
187
case VIPS_FORMAT_USHORT: RLOOP( unsigned short, float ); break;
188
case VIPS_FORMAT_INT: RLOOP( signed int, float ); break;
189
case VIPS_FORMAT_UINT: RLOOP( unsigned int, float ); break;
190
case VIPS_FORMAT_FLOAT: RLOOP( float, float ); break;
191
case VIPS_FORMAT_DOUBLE: RLOOP( double, double ); break;
193
case VIPS_FORMAT_COMPLEX: CLOOP( float ); break;
194
case VIPS_FORMAT_DPCOMPLEX: CLOOP( double ); break;
181
case VIPS_FORMAT_CHAR: RLOOP( signed char, float ); break;
182
case VIPS_FORMAT_UCHAR: RLOOP( unsigned char, float ); break;
183
case VIPS_FORMAT_SHORT: RLOOP( signed short, float ); break;
184
case VIPS_FORMAT_USHORT: RLOOP( unsigned short, float ); break;
185
case VIPS_FORMAT_INT: RLOOP( signed int, float ); break;
186
case VIPS_FORMAT_UINT: RLOOP( unsigned int, float ); break;
187
case VIPS_FORMAT_FLOAT: RLOOP( float, float ); break;
188
case VIPS_FORMAT_DOUBLE: RLOOP( double, double ); break;
189
case VIPS_FORMAT_COMPLEX: CLOOP( float ); break;
190
case VIPS_FORMAT_DPCOMPLEX: CLOOP( double ); break;
214
210
/* Type promotion for division. Sign and value preserving. Make sure
215
211
* these match the case statement in divide_buffer() above.
217
static int vips_bandfmt_divide[10] = {
213
static int vips_divide_format_table[10] = {
218
214
/* UC C US S UI I F X D DX */
219
215
F, F, F, F, F, F, F, X, D, DX
228
224
object_class->nickname = "divide";
229
225
object_class->description = _( "divide two images" );
231
vips_arithmetic_set_format_table( aclass, vips_bandfmt_divide );
233
227
aclass->process_line = vips_divide_buffer;
229
vips_arithmetic_set_format_table( aclass, vips_divide_format_table );
256
252
* one-band image by joining n copies of the one-band image together, and then
257
253
* the two n-band images are operated upon.
259
* The two input images are cast up to the smallest common type (see table
255
* The two input images are cast up to the smallest common format (see table
260
256
* Smallest common format in
261
257
* <link linkend="VIPS-arithmetic">arithmetic</link>), then the
262
258
* following table is used to determine the output type: