-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathHSB.cs
More file actions
108 lines (92 loc) · 3.05 KB
/
Copy pathHSB.cs
File metadata and controls
108 lines (92 loc) · 3.05 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#region License and copyright notice
// Original code by Guillaume Leparmentier, licensed under The Code Project Open License (CPOL)
#endregion
#pragma warning disable 1591
namespace Kaliko.ImageLibrary.ColorSpace {
using System;
/// <summary>
/// Structure to define HSB.
/// </summary>
public struct HSB {
/// <summary>
/// Gets an empty HSB structure;
/// </summary>
public static readonly HSB Empty = new HSB();
#region Fields
private double hue;
private double saturation;
private double brightness;
#endregion
#region Operators
public static bool operator ==(HSB item1, HSB item2) {
return (
item1.Hue == item2.Hue
&& item1.Saturation == item2.Saturation
&& item1.Brightness == item2.Brightness
);
}
public static bool operator !=(HSB item1, HSB item2) {
return (
item1.Hue != item2.Hue
|| item1.Saturation != item2.Saturation
|| item1.Brightness != item2.Brightness
);
}
#endregion
#region Accessors
/// <summary>
/// Gets or sets the hue component.
/// </summary>
public double Hue {
get {
return hue;
}
set {
hue = (value > 360) ? 360 : ((value < 0) ? 0 : value);
}
}
/// <summary>
/// Gets or sets saturation component.
/// </summary>
public double Saturation {
get {
return saturation;
}
set {
saturation = (value > 1) ? 1 : ((value < 0) ? 0 : value);
}
}
/// <summary>
/// Gets or sets the brightness component.
/// </summary>
public double Brightness {
get {
return brightness;
}
set {
brightness = (value > 1) ? 1 : ((value < 0) ? 0 : value);
}
}
#endregion
/// <summary>
/// Creates an instance of a HSB structure.
/// </summary>
/// <param name="h">Hue value.</param>
/// <param name="s">Saturation value.</param>
/// <param name="b">Brightness value.</param>
public HSB(double h, double s, double b) {
hue = (h > 360) ? 360 : ((h < 0) ? 0 : h);
saturation = (s > 1) ? 1 : ((s < 0) ? 0 : s);
brightness = (b > 1) ? 1 : ((b < 0) ? 0 : b);
}
#region Methods
public override bool Equals(Object obj) {
if (obj == null || GetType() != obj.GetType()) return false;
return (this == (HSB)obj);
}
public override int GetHashCode() {
return Hue.GetHashCode() ^ Saturation.GetHashCode() ^ Brightness.GetHashCode();
}
#endregion
}
}