File: color.cpp

package info (click to toggle)
freespace2 24.2.0%2Brepack-1
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 43,716 kB
  • sloc: cpp: 595,001; ansic: 21,741; python: 1,174; sh: 457; makefile: 248; xml: 181
file content (225 lines) | stat: -rw-r--r-- 4,260 bytes parent folder | download | duplicates (2)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#include "graphics/color.h"
#include "graphics/2d.h"
#include "globalincs/pstypes.h"
#include "globalincs/vmallocator.h"
#include "math/floating.h"

void hdr_color::set_vecf(const SCP_vector<float>& input)
{
	size_t l = input.size();
	Assertion(l >= 3, "attempted to set color values invalid component count");
	this->red = input.at(0);
	this->green = input.at(1);
	this->blue = input.at(2);
	if (l > 3)
		this->alpha = input.at(3);
	if (l > 4)
		this->intensity = input.at(4);
}

/*
 * @brief Fills a vector with the raw float color components of the color, in the order red, green, blue, alpha,
 * intensity
 *
 * @param to_fill: The fector that will be filled with the color compoents
 */
void hdr_color::get_v5f(SCP_vector<float>& to_fill) const
{
	to_fill.clear();
	to_fill.push_back(this->red);
	to_fill.push_back(this->green);
	to_fill.push_back(this->blue);
	to_fill.push_back(this->alpha);
	to_fill.push_back(this->intensity);
}

hdr_color::hdr_color()
{
	this->red = 1.0f;
	this->green = 1.0f;
	this->blue = 1.0f;
	this->alpha = 1.0f;
	this->intensity = 1.0f;
}

hdr_color::hdr_color(float new_r, float new_g, float new_b, float new_a, float new_i)
{
	this->red = new_r;
	this->green = new_g;
	this->blue = new_b;
	this->alpha = new_a;
	this->intensity = new_i;
}

hdr_color::hdr_color(const hdr_color* const source_color)
{
	this->red = source_color->red;
	this->green = source_color->green;
	this->blue = source_color->blue;
	this->alpha = source_color->alpha;
	this->intensity = source_color->intensity;
}

/**
 * @brief Sets RGB values from three 0-255 ints
 */
void hdr_color::set_rgb(int new_r, int new_g, int new_b)
{
	this->red = i2fl(new_r) / 255.0f;
	this->green = i2fl(new_g) / 255.0f;
	this->blue = i2fl(new_b) / 255.0f;
}

/**
 * @brief Sets RGBA values from an old style color object
 */
void hdr_color::set_rgb(const color* const new_color)
{
	this->set_rgb(new_color->red, new_color->green, new_color->blue);
	this->alpha = i2fl(new_color->alpha);
}

/**
 * @brief Sets RGB values from an array of three 0-255 ints
 */
void hdr_color::set_rgb(const int* const new_rgb)
{
	this->set_rgb(new_rgb[0], new_rgb[1], new_rgb[2]);
}


/**
 * @brief retreives unmultiplied 0.0f-1.0f color component.
 */
float hdr_color::r() const
{
	return red;
}

/**
 * @brief sets and returns unmultiplied 0.0f-1.0f color component.
 */
float hdr_color::r(float in)
{
	red = in;
	return red;
}

/**
 * @brief sets and returns unmultiplied 0.0f-1.0f color component from 0-255 int.
 */
float hdr_color::r(int in)
{
	red = i2fl(in) / 255.0f;
	return red;
}


/**
 * @brief retreives unmultiplied 0.0f-1.0f color component.
 */
float hdr_color::g() const
{
	return green;
}

/**
 * @brief sets and returns unmultiplied 0.0f-1.0f color component.
 */
float hdr_color::g(float in)
{
	green = in;
	return green;
}

/**
 * @brief sets and returns unmultiplied 0.0f-1.0f color component from 0-255 int.
 */
float hdr_color::g(int in)
{
	green = i2fl(in) / 255.0f;
	return green;
}


/**
 * @brief retreives unmultiplied 0.0f-1.0f color component.
 */
float hdr_color::b() const
{
	return blue;
}

/**
 * @brief sets and returns unmultiplied 0.0f-1.0f color component.
 */
float hdr_color::b(float in)
{
	blue = in;
	return blue;
}

/**
 * @brief sets and returns unmultiplied 0.0f-1.0f color component from 0-255 int.
 */
float hdr_color::b(int in)
{
	blue = i2fl(in) / 255.0f;
	return blue;
}


/**
 * @brief retreives unmultiplied 0.0f-1.0f color component.
 */
float hdr_color::a() const
{
	return alpha;
}

/**
 * @brief sets and returns unmultiplied 0.0f-1.0f color component.
 */
float hdr_color::a(float in)
{
	alpha = in;
	return alpha;
}

/**
 * @brief sets and returns unmultiplied 0.0f-1.0f color component from 0-255 int.
 */
float hdr_color::a(int in)
{
	alpha = i2fl(in) / 255.0f;
	return alpha;
}


/**
 * @brief retreives unmultiplied 0.0f-1.0f color component.
 */
float hdr_color::i() const
{
	return intensity;
}

/**
 * @brief sets and returns unmultiplied 0.0f-1.0f color component.
 */
float hdr_color::i(float in)
{
	intensity = in;
	return intensity;
}
/**
 * @brief Resets to a full alpha, 100% white.
 */
void hdr_color::reset()
{
	this->red = 1.0f;
	this->green = 1.0f;
	this->blue = 1.0f;
	this->alpha = 1.0f;
	this->intensity = 1.0f;
}