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
109
110
111
|
/**
* Copyright: Mike Wey 2011
* License: zlib (See accompanying LICENSE file)
* Authors: Mike Wey
*/
module dmagick.ColorHSL;
import dmagick.Color;
import dmagick.c.gem;
import dmagick.c.magickType;
import dmagick.c.quantum;
/**
* The HSL color model describes a color by using the three color components
* hue (H), saturation (S) and luminance (L). This color format is very
* popular for designing and editing (e.g. within graphics design tools)
* because it gives the user a good impression about the resulting color
* for a certain color value: Hue defines the pure color tone out of the
* color spectrum, saturation defines the mixture of the color tone with
* gray and finally luminance defines the lightness of the resulting color.
*/
class ColorHSL : Color
{
/** */
this()
{
super();
}
/**
* Create a Color from the specified doubles.
*/
this(double hue, double saturation, double luminance, double opacity = 0)
{
Quantum red, green, blue;
ConvertHSLToRGB(hue, saturation, luminance, &red, &green, &blue);
super(red, green, blue, scaleDoubleToQuantum(opacity));
}
/**
* Create a Color from a X11 color specification string
*/
this(string color)
{
super(color);
}
/**
* The value for hue as a an angle between 0 and 360 degrees.
*/
void hue(double hue)
{
double oldHue, saturation, luminance;
ConvertRGBToHSL(packet.red, packet.green, packet.blue, &oldHue, &saturation, &luminance);
ConvertHSLToRGB(hue, saturation, luminance, &(packet.red), &(packet.green), &(packet.blue));
}
///ditto
double hue()
{
double hue, saturation, luminance;
ConvertRGBToHSL(packet.red, packet.green, packet.blue, &hue, &saturation, &luminance);
return hue;
}
/**
* The value the saturation as a double in the range [0.0 .. 1.0]
*/
void saturation(double saturation)
{
double hue, oldSaturation, luminance;
ConvertRGBToHSL(packet.red, packet.green, packet.blue, &hue, &oldSaturation, &luminance);
ConvertHSLToRGB(hue, saturation, luminance, &(packet.red), &(packet.green), &(packet.blue));
}
///ditto
double saturation()
{
double hue, saturation, luminance;
ConvertRGBToHSL(packet.red, packet.green, packet.blue, &hue, &saturation, &luminance);
return saturation;
}
/**
* The value for the luminance as a double in the range [0.0 .. 1.0]
*/
void luminance(double luminance)
{
double hue, saturation, oldLuminance;
ConvertRGBToHSL(packet.red, packet.green, packet.blue, &hue, &saturation, &oldLuminance);
ConvertHSLToRGB(hue, saturation, luminance, &(packet.red), &(packet.green), &(packet.blue));
}
///ditto
double luminance()
{
double hue, saturation, luminance;
ConvertRGBToHSL(packet.red, packet.green, packet.blue, &hue, &saturation, &luminance);
return luminance;
}
}
|