~ubuntu-branches/ubuntu/trusty/python-imaging/trusty

« back to all changes in this revision

Viewing changes to _imagingmath.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2009-11-20 19:22:59 UTC
  • mfrom: (2.1.6 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091120192259-cmnfui5tv2jtq4xu
Tags: 1.1.7-1
New upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * The Python Imaging Library
3
 
 * $Id: _imagingmath.c 2396 2005-05-07 09:17:22Z Fredrik $
4
3
 *
5
4
 * a simple math add-on for the Python Imaging Library
6
5
 *
21
20
#include "math.h"
22
21
#include "float.h"
23
22
 
 
23
#define MAX_INT32 2147483647.0
 
24
#define MIN_INT32 -2147483648.0
 
25
 
 
26
#if defined(_MSC_VER) && _MSC_VER < 1500
 
27
/* python 2.1/2.2/2.3 = VC98 = VER 1200 */
 
28
/* python 2.4/2.5 = VS.NET 2003 = VER 1310 */
 
29
/* python 2.6 = VS 9.0 = VER 1500 */
 
30
#define powf(a, b) ((float) pow((double) (a), (double) (b)))
 
31
#endif
 
32
 
24
33
#define UNOP(name, op, type)\
25
34
void name(Imaging out, Imaging im1)\
26
35
{\
83
92
#define MOD_I(type, v1, v2) ((v2)!=0)?(v1)%(v2):0
84
93
#define MOD_F(type, v1, v2) ((v2)!=0.0F)?fmod((v1),(v2)):0.0F
85
94
 
 
95
static int powi(int x, int y)
 
96
{
 
97
    double v = pow(x, y) + 0.5;
 
98
    if (errno == EDOM)
 
99
        return 0;
 
100
    if (v < MIN_INT32)
 
101
        v = MIN_INT32;
 
102
    else if (v > MAX_INT32)
 
103
        v = MAX_INT32;
 
104
    return (int) v;
 
105
}
 
106
 
 
107
#define POW_I(type, v1, v2) powi(v1, v2)
 
108
#define POW_F(type, v1, v2) powf(v1, v2) /* FIXME: EDOM handling */
 
109
 
86
110
#define DIFF_I(type, v1, v2) abs((v1)-(v2))
87
111
#define DIFF_F(type, v1, v2) fabs((v1)-(v2))
88
112
 
101
125
BINOP(mul_I, MUL, INT32)
102
126
BINOP(div_I, DIV_I, INT32)
103
127
BINOP(mod_I, MOD_I, INT32)
 
128
BINOP(pow_I, POW_I, INT32)
104
129
BINOP(diff_I, DIFF_I, INT32)
105
130
 
106
131
UNOP(invert_I, INVERT, INT32)
128
153
BINOP(mul_F, MUL, FLOAT32)
129
154
BINOP(div_F, DIV_F, FLOAT32)
130
155
BINOP(mod_F, MOD_F, FLOAT32)
 
156
BINOP(pow_F, POW_F, FLOAT32)
131
157
BINOP(diff_F, DIFF_F, FLOAT32)
132
158
 
133
159
BINOP(min_F, MIN, FLOAT32)
220
246
    install(d, "mod_I", mod_I);
221
247
    install(d, "min_I", min_I);
222
248
    install(d, "max_I", max_I);
 
249
    install(d, "pow_I", pow_I);
223
250
 
224
251
    install(d, "invert_I", invert_I);
225
252
    install(d, "and_I", and_I);
245
272
    install(d, "mod_F", mod_F);
246
273
    install(d, "min_F", min_F);
247
274
    install(d, "max_F", max_F);
 
275
    install(d, "pow_F", pow_F);
248
276
 
249
277
    install(d, "eq_F", eq_F);
250
278
    install(d, "ne_F", ne_F);