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
|
typedef unsigned long sample;
struct pam
{
sample maxval;
};
typedef sample *tuple;
enum function
{
FN_MULTIPLY, FN_DIVIDE, FN_ADD, FN_SUBTRACT, FN_MIN, FN_MAX, FN_AND, FN_OR,
FN_XOR, FN_NOT, FN_SHIFTLEFT, FN_SHIFTRIGHT
};
struct cmdlineInfo
{
enum function function;
union
{
float divisor;
unsigned int shiftCount;
}
u;
};
applyFunction (struct cmdlineInfo const cmdline, struct pam const inpam,
struct pam const outpam, tuple * const inputRow,
tuple * const outputRow)
{
float const oneOverDivisor = 1 / cmdline.u.divisor;
int col;
{
int plane;
{
sample const inSample = inputRow[col][plane];
sample outSample;
switch (cmdline.function)
{
case FN_DIVIDE:
outSample = ((unsigned int) ((inSample * oneOverDivisor) + 0.5));
break;
case FN_SHIFTLEFT:
outSample = (inSample << cmdline.u.shiftCount) & outpam.maxval;
}
outputRow[col][plane] =
((outpam.maxval) < (outSample) ? (outpam.maxval) : (outSample));
}
}
}
|