1/*
2 * Copyright (c) 2020 The Starlight Project
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in all
12 * copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23#pragma once
24
25#include <basis/seadTypes.h>
26
27namespace sead
28{
29class Color4f
30{
31public:
32 Color4f() = default;
33 Color4f(f32 r, f32 g, f32 b, f32 a) : r(r), g(g), b(b), a(a) {}
34
35 static Color4f lerp(const Color4f& color1, const Color4f& color2, f32 t);
36
37 void setLerp(const Color4f& color1, const Color4f& color2, f32 t);
38 // This should actually be called setGammaCorrection...
39 void setGammaCollection(const Color4f& value, f32 gamma);
40 void adjustOverflow();
41
42 Color4f& operator+=(const Color4f& rhs);
43 Color4f& operator-=(const Color4f& rhs);
44 Color4f& operator*=(const Color4f& rhs);
45 Color4f& operator/=(const Color4f& rhs);
46 Color4f& operator+=(f32 x);
47 Color4f& operator-=(f32 x);
48 Color4f& operator*=(f32 x);
49 Color4f& operator/=(f32 x);
50
51 friend Color4f operator+(const Color4f& lhs, const Color4f& rhs);
52 friend Color4f operator-(const Color4f& lhs, const Color4f& rhs);
53 friend Color4f operator*(const Color4f& lhs, const Color4f& rhs);
54 friend Color4f operator/(const Color4f& lhs, const Color4f& rhs);
55 friend Color4f operator+(const Color4f& lhs, f32 x);
56 friend Color4f operator-(const Color4f& lhs, f32 x);
57 friend Color4f operator*(const Color4f& lhs, f32 x);
58 friend Color4f operator/(const Color4f& lhs, f32 x);
59 friend bool operator==(const Color4f& lhs, const Color4f& rhs);
60
61 f32 r = cElementMin;
62 f32 g = cElementMin;
63 f32 b = cElementMin;
64 f32 a = cElementMax;
65
66 static const f32 cElementMax;
67 static const f32 cElementMin;
68
69 static const Color4f cBlack;
70 static const Color4f cGray;
71 static const Color4f cWhite;
72 static const Color4f cRed;
73 static const Color4f cGreen;
74 static const Color4f cBlue;
75 static const Color4f cYellow;
76 static const Color4f cMagenta;
77 static const Color4f cCyan;
78};
79
80class Color4u8
81{
82public:
83 Color4u8() = default;
84 Color4u8(u8 r, u8 g, u8 b, u8 a) : a(a), b(b), g(g), r(r) {}
85
86 static Color4u8 lerp(const Color4u8& color1, const Color4u8& color2, f32 t);
87
88 void setf(f32 r, f32 g, f32 b, f32 a);
89 void setLerp(const Color4u8& color1, const Color4u8& color2, f32 t);
90 // This should actually be called setGammaCorrection...
91 void setGammaCollection(const Color4u8& value, f32 gamma);
92
93 Color4u8& operator+=(const Color4u8& rhs);
94 Color4u8& operator-=(const Color4u8& rhs);
95 Color4u8& operator*=(const Color4u8& rhs);
96 Color4u8& operator/=(const Color4u8& rhs);
97 Color4u8& operator|=(const Color4u8& rhs);
98 Color4u8& operator&=(const Color4u8& rhs);
99 Color4u8& operator+=(u8 x);
100 Color4u8& operator-=(u8 x);
101 Color4u8& operator*=(f32 x);
102 Color4u8& operator/=(f32 x);
103 Color4u8& operator|=(u8 x);
104 Color4u8& operator&=(u8 x);
105
106 friend Color4u8 operator+(const Color4u8& lhs, const Color4u8& rhs);
107 friend Color4u8 operator-(const Color4u8& lhs, const Color4u8& rhs);
108 friend Color4u8 operator*(const Color4u8& lhs, const Color4u8& rhs);
109 friend Color4u8 operator/(const Color4u8& lhs, const Color4u8& rhs);
110 friend Color4u8 operator+(const Color4u8& lhs, u8 x);
111 friend Color4u8 operator-(const Color4u8& lhs, u8 x);
112 friend Color4u8 operator*(const Color4u8& lhs, f32 x);
113 friend Color4u8 operator/(const Color4u8& lhs, f32 x);
114 friend Color4u8 operator&(const Color4u8& lhs, u8 x);
115 friend Color4u8 operator|(const Color4u8& lhs, u8 x);
116 friend bool operator==(const Color4u8& lhs, const Color4u8& rhs);
117
118 u8 a;
119 u8 b;
120 u8 g;
121 u8 r;
122
123 static const u8 cElementMax;
124 static const u8 cElementMin;
125
126 static const Color4u8 cBlack;
127 static const Color4u8 cGray;
128 static const Color4u8 cWhite;
129 static const Color4u8 cRed;
130 static const Color4u8 cGreen;
131 static const Color4u8 cBlue;
132 static const Color4u8 cYellow;
133 static const Color4u8 cMagenta;
134 static const Color4u8 cCyan;
135
136private:
137 template <typename Callable>
138 Color4u8& apply_(Callable fn)
139 {
140 fn(&Color4u8::r);
141 fn(&Color4u8::g);
142 fn(&Color4u8::b);
143 fn(&Color4u8::a);
144 return *this;
145 }
146};
147} // namespace sead
148