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

« back to all changes in this revision

Viewing changes to libvips/arithmetic/remainder.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:
92
92
/* Integer remainder-after-division.
93
93
 */
94
94
#define IREMAINDER( TYPE ) { \
95
 
        TYPE *p1 = (TYPE *) in[0]; \
96
 
        TYPE *p2 = (TYPE *) in[1]; \
97
 
        TYPE *q = (TYPE *) out; \
 
95
        TYPE * restrict p1 = (TYPE *) in[0]; \
 
96
        TYPE * restrict p2 = (TYPE *) in[1]; \
 
97
        TYPE * restrict q = (TYPE *) out; \
98
98
        \
99
99
        for( x = 0; x < sz; x++ ) \
100
 
                if( p2[x] ) \
101
 
                        q[x] = p1[x] % p2[x]; \
102
 
                else \
103
 
                        q[x] = -1; \
 
100
                q[x] = p2[x] ? p1[x] % p2[x] : -1; \
104
101
}
105
102
 
106
103
/* Float remainder-after-division.
107
104
 */
108
105
#define FREMAINDER( TYPE ) { \
109
 
        TYPE *p1 = (TYPE *) in[0]; \
110
 
        TYPE *p2 = (TYPE *) in[1]; \
111
 
        TYPE *q = (TYPE *) out; \
 
106
        TYPE * restrict p1 = (TYPE *) in[0]; \
 
107
        TYPE * restrict p2 = (TYPE *) in[1]; \
 
108
        TYPE * restrict q = (TYPE *) out; \
112
109
        \
113
110
        for( x = 0; x < sz; x++ ) { \
114
111
                double a = p1[x]; \
115
112
                double b = p2[x]; \
116
113
                \
117
 
                if( b ) \
118
 
                        q[x] = a - b * floor (a / b); \
119
 
                else \
120
 
                        q[x] = -1; \
 
114
                q[x] = b ? a - b * floor (a / b) : -1; \
121
115
        } \
122
116
}
123
117
 
160
154
 
161
155
/* Type promotion for remainder. Keep in sync with remainder_buffer() above.
162
156
 */
163
 
static int vips_bandfmt_remainder[10] = {
 
157
static int vips_remainder_format_table[10] = {
164
158
/* UC  C   US  S   UI  I  F  X  D  DX */
165
159
   UC, C,  US, S,  UI, I, F, X, D, DX
166
160
};
180
174
                _( "remainder after integer division of two images" );
181
175
        object_class->build = vips_remainder_build;
182
176
 
183
 
        vips_arithmetic_set_format_table( aclass, vips_bandfmt_remainder );
184
 
 
185
177
        aclass->process_line = vips_remainder_buffer;
 
178
 
 
179
        vips_arithmetic_set_format_table( aclass, 
 
180
                vips_remainder_format_table ); 
186
181
}
187
182
 
188
183
static void
210
205
 * one-band image by joining n copies of the one-band image together, and then
211
206
 * the two n-band images are operated upon.
212
207
 *
213
 
 * The two input images are cast up to the smallest common type (see table 
 
208
 * The two input images are cast up to the smallest common format (see table 
214
209
 * Smallest common format in 
215
210
 * <link linkend="VIPS-arithmetic">arithmetic</link>), and that format is the
216
211
 * result type.
262
257
/* Integer remainder-after-divide, per-band constant.
263
258
 */
264
259
#define IREMAINDERCONST( TYPE ) { \
265
 
        TYPE *p = (TYPE *) in[0]; \
266
 
        TYPE *q = (TYPE *) out; \
267
 
        TYPE *c = (TYPE *) uconst->c_ready; \
 
260
        TYPE * restrict p = (TYPE *) in[0]; \
 
261
        TYPE * restrict q = (TYPE *) out; \
 
262
        TYPE * restrict c = (TYPE *) uconst->c_ready; \
268
263
        \
269
264
        for( i = 0, x = 0; x < width; x++ ) \
270
265
                for( b = 0; b < bands; b++, i++ ) \
274
269
/* Float remainder-after-divide, per-band constant.
275
270
 */
276
271
#define FREMAINDERCONST( TYPE ) { \
277
 
        TYPE *p = (TYPE *) in[0]; \
278
 
        TYPE *q = (TYPE *) out; \
279
 
        TYPE *c = (TYPE *) uconst->c_ready; \
 
272
        TYPE * restrict p = (TYPE *) in[0]; \
 
273
        TYPE * restrict q = (TYPE *) out; \
 
274
        TYPE * restrict c = (TYPE *) uconst->c_ready; \
280
275
        \
281
276
        for( i = 0, x = 0; x < width; x++ ) \
282
277
                for( b = 0; b < bands; b++, i++ ) { \
283
278
                        double left = p[i]; \
284
279
                        double right = c[b]; \
285
280
                        \
286
 
                        if( right ) \
287
 
                                q[i] = left - right * floor( left / right ); \
288
 
                        else \
289
 
                                q[i] = -1; \
 
281
                        q[i] = right ? \
 
282
                                left - right * floor( left / right ) : \
 
283
                                -1; \
290
284
                } \
291
285
}
292
286
 
331
325
                "and a constant" );
332
326
        object_class->build = vips_remainder_const_build;
333
327
 
334
 
        vips_arithmetic_set_format_table( aclass, vips_bandfmt_remainder );
335
 
 
336
328
        aclass->process_line = vips_remainder_const_buffer;
 
329
 
 
330
        vips_arithmetic_set_format_table( aclass, vips_remainder_format_table );
337
331
}
338
332
 
339
333
static void