forked from aseprite/aseprite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rgb.h
93 lines (73 loc) · 1.5 KB
/
rgb.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
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
// Aseprite Gfx Library
// Copyright (C) 2001-2013 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifndef GFX_RGB_H_INCLUDED
#define GFX_RGB_H_INCLUDED
#pragma once
#include <cassert>
namespace gfx {
class Hsv;
class Rgb
{
public:
Rgb()
: m_red(0)
, m_green(0)
, m_blue(0)
{ }
Rgb(int red, int green, int blue)
: m_red(red)
, m_green(green)
, m_blue(blue)
{
assert(red >= 0 && red <= 255);
assert(green >= 0 && green <= 255);
assert(blue >= 0 && blue <= 255);
}
Rgb(const Rgb& rgb)
: m_red(rgb.red())
, m_green(rgb.green())
, m_blue(rgb.blue())
{ }
// HSV to RGB conversion
explicit Rgb(const Hsv& hsv);
int red() const {
return m_red;
}
int green() const {
return m_green;
}
int blue() const {
return m_blue;
}
int maxComponent() const;
int minComponent() const;
void red(int red) {
assert(red >= 0 && red <= 255);
m_red = red;
}
void green(int green) {
assert(green >= 0 && green <= 255);
m_green = green;
}
void blue(int blue) {
assert(blue >= 0 && blue <= 255);
m_blue = blue;
}
bool operator==(const Rgb& other) const {
return (m_red == other.m_red &&
m_green == other.m_green &&
m_blue == other.m_blue);
}
bool operator!=(const Rgb& other) const {
return !operator==(other);
}
private:
int m_red;
int m_green;
int m_blue;
};
} // namespace gfx
#endif