blob: d53cf494d173367f58e3b4467d7e5ef08592e91a (
plain)
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
|
#include "spectrum.hpp"
static double clamp(double v, double low = 0, double high = 0) {
if (v < low) {
return low;
}
if (v > high) {
return high;
}
return v;
}
Spectrum::Spectrum(double v) {
c[0] = v;
c[1] = v;
c[2] = v;
}
Spectrum Spectrum::FromRGB(double r, double g, double b) {
Spectrum ret;
ret.c[0] = r;
ret.c[1] = g;
ret.c[2] = b;
return ret;
}
Spectrum &Spectrum::operator+=(const Spectrum &o) {
c[0] += o.c[0];
c[1] += o.c[1];
c[2] += o.c[2];
return *this;
}
Spectrum &Spectrum::operator*=(double o) {
c[0] *= o;
c[1] *= o;
c[2] *= o;
return *this;
}
Spectrum Spectrum::operator+(const Spectrum &o) const {
Spectrum ret = *this;
ret.c[0] += o.c[0];
ret.c[1] += o.c[1];
ret.c[2] += o.c[2];
return ret;
}
Spectrum Spectrum::operator-(const Spectrum &o) const {
Spectrum ret = *this;
ret.c[0] -= o.c[0];
ret.c[1] -= o.c[1];
ret.c[2] -= o.c[2];
return ret;
}
Spectrum Spectrum::operator*(const Spectrum &o) const {
Spectrum ret = *this;
ret.c[0] *= o.c[0];
ret.c[1] *= o.c[1];
ret.c[2] *= o.c[2];
return ret;
}
Spectrum Spectrum::operator/(const Spectrum &o) const {
Spectrum ret = *this;
ret.c[0] /= o.c[0];
ret.c[1] /= o.c[1];
ret.c[2] /= o.c[2];
return ret;
}
Spectrum Spectrum::clamp(double low, double high) const {
Spectrum ret;
ret.c[0] = ::clamp(c[0], low, high);
ret.c[1] = ::clamp(c[1], low, high);
ret.c[2] = ::clamp(c[2], low, high);
return ret;
}
|