Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libsnes/bsnes/nall/interpolation.hpp
2 views
1
#ifndef NALL_INTERPOLATION_HPP
2
#define NALL_INTERPOLATION_HPP
3
4
namespace nall {
5
6
struct Interpolation {
7
static inline double Nearest(double mu, double a, double b, double c, double d) {
8
return (mu <= 0.5 ? b : c);
9
}
10
11
static inline double Sublinear(double mu, double a, double b, double c, double d) {
12
mu = ((mu - 0.5) * 2.0) + 0.5;
13
if(mu < 0) mu = 0;
14
if(mu > 1) mu = 1;
15
return b * (1.0 - mu) + c * mu;
16
}
17
18
static inline double Linear(double mu, double a, double b, double c, double d) {
19
return b * (1.0 - mu) + c * mu;
20
}
21
22
static inline double Cosine(double mu, double a, double b, double c, double d) {
23
mu = (1.0 - cos(mu * 3.14159265)) / 2.0;
24
return b * (1.0 - mu) + c * mu;
25
}
26
27
static inline double Cubic(double mu, double a, double b, double c, double d) {
28
double A = d - c - a + b;
29
double B = a - b - A;
30
double C = c - a;
31
double D = b;
32
return A * (mu * mu * mu) + B * (mu * mu) + C * mu + D;
33
}
34
35
static inline double Hermite(double mu1, double a, double b, double c, double d) {
36
const double tension = 0.0; //-1 = low, 0 = normal, +1 = high
37
const double bias = 0.0; //-1 = left, 0 = even, +1 = right
38
double mu2, mu3, m0, m1, a0, a1, a2, a3;
39
40
mu2 = mu1 * mu1;
41
mu3 = mu2 * mu1;
42
43
m0 = (b - a) * (1.0 + bias) * (1.0 - tension) / 2.0;
44
m0 += (c - b) * (1.0 - bias) * (1.0 - tension) / 2.0;
45
m1 = (c - b) * (1.0 + bias) * (1.0 - tension) / 2.0;
46
m1 += (d - c) * (1.0 - bias) * (1.0 - tension) / 2.0;
47
48
a0 = +2 * mu3 - 3 * mu2 + 1;
49
a1 = mu3 - 2 * mu2 + mu1;
50
a2 = mu3 - mu2;
51
a3 = -2 * mu3 + 3 * mu2;
52
53
return (a0 * b) + (a1 * m0) + (a2 * m1) + (a3 * c);
54
}
55
};
56
57
}
58
59
#endif
60
61