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
|
/*
math/color.h
This file is part of the Osirion project and is distributed under
the terms of the GNU General Public License version 2
*/
#ifndef __INCLUDED_MATH_COLOR_H__
#define __INCLUDED_MATH_COLOR_H__
#include <iostream>
namespace math
{
/// a class representing an RGBA color value
class Color
{
public:
/// create the default color, white
Color();
/// create a color from float RGBA value
Color(float red, float green, float blue, float alpha=1.0f);
/// create a greyscale color
Color(const float grey, const float=1.0f);
/// create a copy from an existing color
Color(Color const & other);
/// red channel value
float red() const;
/// green channel value
float green() const;
/// blue channel value
float blue() const;
/// alpha channel value
float alpha() const;
/// assignment
void assign(Color const & other);
/// assignment
void assign(float red, float green, float blue, float alpha=1.0f);
/// assignment
void assign(float grey, float alpha=1.0f);
/// assignment operator
Color const &operator=(Color const & other);
/// multiply rgb values with scalar value.
Color operator*(const float scalar) const;
/// pointer to the internal data
inline float *ptr() const { return (float *) rgba_data; };
/// clamp color values to the 0-1 range
void clamp();
float &r;
float &g;
float &b;
float &a;
private:
float rgba_data[4];
};
/// write color RGB values to stream
std::ostream &operator<<(std::ostream &os, Color const & color);
/// read color RGB values from stream, alpha is set to 1.0
std::istream &operator>>(std::istream & is, Color & color);
/// scalar-with-color multiplication
Color const operator*(float scalar, Color const & color);
} // namespace math
#endif // __INCLUDED_MATH_COLOR_H__
|