~ubuntu-branches/ubuntu/trusty/vips/trusty-proposed

« back to all changes in this revision

Viewing changes to libvips/arithmetic/divide.c

  • Committer: Package Import Robot
  • Author(s): Jay Berkenbilt
  • Date: 2014-03-29 12:29:29 UTC
  • mfrom: (1.1.21) (30.1.16 sid)
  • Revision ID: package-import@ubuntu.com-20140329122929-fvxnaann32ex0gzk
Tags: 7.38.5-2
Enable dh-autoreconf. (Closes: #742872)

Show diffs side-by-side

added added

removed removed

Lines of Context:
90
90
 
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; \
96
96
        int i; \
97
97
        \
98
98
        for( i = 0; i < sz; i++ ) { \
120
120
#else /* USE_MODARG_DIV */
121
121
 
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; \
126
126
        int i; \
127
127
        \
128
128
        for( i = 0; i < sz; i++ ) { \
157
157
/* Real divide. Cast in to OUT before divide so we work for float output.
158
158
 */
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; \
163
163
        \
164
164
        for( x = 0; x < sz; x++ ) \
165
 
                if( right[x] == 0 ) \
166
 
                        q[x] = 0; \
167
 
                else \
168
 
                        q[x] = (OUT) left[x] / (OUT) right[x]; \
 
165
                q[x] = right[x] == 0 ? 0 : (OUT) left[x] / (OUT) right[x]; \
169
166
}
170
167
 
171
168
static void
177
174
 
178
175
        int x;
179
176
 
180
 
        /* Keep types here in sync with bandfmt_divide[] 
 
177
        /* Keep types here in sync with vips_divide_format_table[] 
181
178
         * below.
182
179
         */
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;
192
 
 
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;
195
191
 
196
192
        default:
197
193
                g_assert( 0 );
214
210
/* Type promotion for division. Sign and value preserving. Make sure 
215
211
 * these match the case statement in divide_buffer() above.
216
212
 */
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
220
216
};
228
224
        object_class->nickname = "divide";
229
225
        object_class->description = _( "divide two images" );
230
226
 
231
 
        vips_arithmetic_set_format_table( aclass, vips_bandfmt_divide );
232
 
 
233
227
        aclass->process_line = vips_divide_buffer;
 
228
 
 
229
        vips_arithmetic_set_format_table( aclass, vips_divide_format_table ); 
234
230
}
235
231
 
236
232
static void
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.
258
254
 *
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: