-
Notifications
You must be signed in to change notification settings - Fork 0
/
ColorData.h
52 lines (41 loc) · 1.36 KB
/
ColorData.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
//
// ColorData.h
// Originally created by the CSci-3081W TAs.
//
#ifndef COLORDATA_H
#define COLORDATA_H
/** This color data class stores color in floating point format.
The Red, Green, Blue, and Alpha channels range from 0.0 to 1.0. */
class ColorData
{
public:
ColorData();
ColorData(float r, float g, float b );
ColorData(float r, float g, float b, float a);
void setRed(float r);
void setBlue(float b);
void setGreen(float g);
void setAlpha(float a);
float getRed() const;
float getBlue() const;
float getGreen() const;
float getAlpha() const;
// Returns the "brightness" of the color according to a perceptual metric that
// weights the red, green, and blue components of the color non-uniformly.
float getLuminance() const;
// Return a clamped version of this ColorData
ColorData clampedColor() const;
// Arithmatic operators (friends so that non-member functions can access private variables)
friend ColorData operator* (const ColorData& a, float f);
friend ColorData operator+ (const ColorData& a, const ColorData& b);
friend ColorData operator- (const ColorData& a, const ColorData& b);
private:
// General helper function for clamping values between 0 and 1
static inline float clampValue(float input, float a, float b)
{return input < a ? a : (input > b ? b : input);}
float m_red;
float m_green;
float m_blue;
float m_alpha;
};
#endif