1 | // LAF Gfx Library |
2 | // Copyright (C) 2001-2017 David Capello |
3 | // |
4 | // This file is released under the terms of the MIT license. |
5 | // Read LICENSE.txt for more information. |
6 | |
7 | #ifndef GFX_RGB_H_INCLUDED |
8 | #define GFX_RGB_H_INCLUDED |
9 | #pragma once |
10 | |
11 | #include "base/debug.h" |
12 | |
13 | namespace gfx { |
14 | |
15 | class Hsv; |
16 | class Hsl; |
17 | |
18 | class Rgb { |
19 | public: |
20 | Rgb() |
21 | : m_red(0) |
22 | , m_green(0) |
23 | , m_blue(0) |
24 | { } |
25 | |
26 | Rgb(int red, int green, int blue) |
27 | : m_red(red) |
28 | , m_green(green) |
29 | , m_blue(blue) |
30 | { |
31 | ASSERT(red >= 0 && red <= 255); |
32 | ASSERT(green >= 0 && green <= 255); |
33 | ASSERT(blue >= 0 && blue <= 255); |
34 | } |
35 | |
36 | Rgb(const Rgb& rgb) |
37 | : m_red(rgb.red()) |
38 | , m_green(rgb.green()) |
39 | , m_blue(rgb.blue()) |
40 | { } |
41 | |
42 | // Conversions |
43 | explicit Rgb(const Hsv& hsv); |
44 | explicit Rgb(const Hsl& hsl); |
45 | |
46 | int red() const { |
47 | return m_red; |
48 | } |
49 | |
50 | int green() const { |
51 | return m_green; |
52 | } |
53 | |
54 | int blue() const { |
55 | return m_blue; |
56 | } |
57 | |
58 | int maxComponent() const; |
59 | int minComponent() const; |
60 | |
61 | void red(int red) { |
62 | ASSERT(red >= 0 && red <= 255); |
63 | m_red = red; |
64 | } |
65 | |
66 | void green(int green) { |
67 | ASSERT(green >= 0 && green <= 255); |
68 | m_green = green; |
69 | } |
70 | |
71 | void blue(int blue) { |
72 | ASSERT(blue >= 0 && blue <= 255); |
73 | m_blue = blue; |
74 | } |
75 | |
76 | bool operator==(const Rgb& other) const { |
77 | return (m_red == other.m_red && |
78 | m_green == other.m_green && |
79 | m_blue == other.m_blue); |
80 | } |
81 | |
82 | bool operator!=(const Rgb& other) const { |
83 | return !operator==(other); |
84 | } |
85 | |
86 | private: |
87 | int m_red; |
88 | int m_green; |
89 | int m_blue; |
90 | }; |
91 | |
92 | } // namespace gfx |
93 | |
94 | #endif |
95 | |