forked from aseprite/aseprite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hsv.h
91 lines (71 loc) · 1.78 KB
/
hsv.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
// 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_HSV_H_INCLUDED
#define GFX_HSV_H_INCLUDED
#pragma once
#include <cassert>
namespace gfx {
class Rgb;
class Hsv
{
public:
Hsv()
: m_hue(0.0)
, m_saturation(0.0)
, m_value(0.0)
{ }
Hsv(double hue, double saturation, double value);
Hsv(const Hsv& hsv)
: m_hue(hsv.hue())
, m_saturation(hsv.saturation())
, m_value(hsv.value())
{ }
// RGB to HSV conversion
explicit Hsv(const Rgb& rgb);
// Returns color's hue, a value from 0 to 360
double hue() const {
return m_hue;
}
// Returns color's saturation, a value from 0 to 100
double saturation() const {
return m_saturation;
}
// Returns color's brightness, a value from 0 to 100
double value() const {
return m_value;
}
// Integer getters, hue=[0,360), saturation=[0,100], value=[0,100]
int hueInt() const;
int saturationInt() const;
int valueInt() const;
void hue(double hue) {
assert(hue >= 0.0 && hue <= 360.0);
m_hue = hue;
}
void saturation(double saturation) {
assert(saturation >= 0.0 && saturation <= 1.0);
m_saturation = saturation;
}
void value(double value) {
assert(value >= 0.0 && value <= 1.0);
m_value = value;
}
// The comparison is done through the integer value of each component.
bool operator==(const Hsv& other) const {
return (hueInt() == other.hueInt() &&
saturationInt() == other.saturationInt() &&
valueInt() == other.valueInt());
}
bool operator!=(const Hsv& other) const {
return !operator==(other);
}
private:
double m_hue;
double m_saturation;
double m_value;
};
} // namespace gfx
#endif