-
Notifications
You must be signed in to change notification settings - Fork 2
/
amaze-port.c
63 lines (50 loc) · 1.33 KB
/
amaze-port.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "sleefsseavx.c"
#define initialGain 1.0 /* IDK */
/* assume RGGB */
/* see RT rawimage.h */
static inline int FC(int row, int col)
{
if ((row%2) == 0 && (col%2) == 0)
return 0; /* red */
else if ((row%2) == 1 && (col%2) == 1)
return 2; /* blue */
else
return 1; /* green */
}
#define COERCE(x,lo,hi) MAX(MIN((x),(hi)),(lo))
#define MIN(a,b) \
({ typeof ((a)+(b)) _a = (a); \
typeof ((a)+(b)) _b = (b); \
_a < _b ? _a : _b; })
#define MAX(a,b) \
({ typeof ((a)+(b)) _a = (a); \
typeof ((a)+(b)) _b = (b); \
_a > _b ? _a : _b; })
#define SQR(a) \
({ typeof (a) _a = (a); \
_a * _a; })
#define min MIN
/* from RT sleef.c */
__inline float xmul2f(float d) {
if (*(int*)&d & 0x7FFFFFFF) { // if f==0 do nothing
*(int*)&d += 1 << 23; // add 1 to the exponent
}
return d;
}
__inline float xdiv2f(float d) {
if (*(int*)&d & 0x7FFFFFFF) { // if f==0 do nothing
*(int*)&d -= 1 << 23; // sub 1 from the exponent
}
return d;
}
__inline float xdivf( float d, int n){
if (*(int*)&d & 0x7FFFFFFF) { // if f==0 do nothing
*(int*)&d -= n << 23; // add n to the exponent
}
return d;
}
/* adapted from rt_math.h */
#define LIM COERCE
#define ULIM(a, b, c) (((b) < (c)) ? LIM(a,b,c) : LIM(a,c,b))
#define bool int
#pragma GCC diagnostic ignored "-Wunused-variable"