This repository has been archived by the owner on Sep 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
predict.h
98 lines (85 loc) · 1.72 KB
/
predict.h
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#ifndef IZ_PREDICT_H
#define IZ_PREDICT_H 1
#include "intmacros.h"
namespace IZ {
#define UNUSED(x) { x = x; }
template<typename Sample = unsigned char>
class Predictor3med
{
public:
static int predict(int x, int y, int xy) {
int dx, dy, dxy, s;
dy = x - xy;
dx = xy - y;
dxy = x - y;
s = oppositeSign(dy, dx);
dxy &= oppositeSign(dxy, dy);
return selectVal(s, y + dy, x - dxy);
}
};
template<typename Sample = unsigned char>
class Predictor3alpha
{
public:
static int predict(int x, int y, int xy) {
return clamp0(clampMax(x + y - xy, Sample(~0)));
}
};
template<typename Sample = unsigned char>
class Predictor3plane
{
public:
static int predict(int x, int y, int xy) {
return x + y - xy;
}
};
template<typename Sample = unsigned char>
class Predictor3avgplane
{
public:
static int predict(int x, int y, int xy) {
return (3 * x + 3 * y - 2 * xy + 2) >> 2;
}
};
template<typename Sample = unsigned char>
class Predictor2avg
{
public:
static int predict(int x, int y, int xy) {
UNUSED(xy);
return (x + y + 1) >> 1;
}
};
template<typename Sample = unsigned char>
class Predictor1x
{
public:
static int predict(int x, int y, int xy) {
UNUSED(y);
UNUSED(xy);
return x;
}
};
template<typename Sample = unsigned char>
class Predictor1y
{
public:
static int predict(int x, int y, int xy) {
UNUSED(x);
UNUSED(xy);
return y;
}
};
template<typename Sample = unsigned char>
class Predictor0
{
public:
static int predict(int x, int y, int xy) {
UNUSED(x);
UNUSED(y);
UNUSED(xy);
return 0;
}
};
} // namespace IZ
#endif