1 /**
2 * Copyright: Mike Wey 2011
3 * License: zlib (See accompanying LICENSE file)
4 * Authors: Mike Wey
5 */6 7 moduledmagick.ColorHSL;
8 9 importdmagick.Color;
10 11 importdmagick.c.gem;
12 importdmagick.c.magickType;
13 importdmagick.c.quantum;
14 15 /**
16 * The HSL color model describes a color by using the three color components
17 * hue (H), saturation (S) and luminance (L). This color format is very
18 * popular for designing and editing (e.g. within graphics design tools)
19 * because it gives the user a good impression about the resulting color
20 * for a certain color value: Hue defines the pure color tone out of the
21 * color spectrum, saturation defines the mixture of the color tone with
22 * gray and finally luminance defines the lightness of the resulting color.
23 */24 classColorHSL : Color25 {
26 /** */27 this()
28 {
29 super();
30 }
31 32 /**
33 * Create a Color from the specified doubles.
34 */35 this(doublehue, doublesaturation, doubleluminance, doubleopacity = 0)
36 {
37 Quantumred, green, blue;
38 39 ConvertHSLToRGB(hue, saturation, luminance, &red, &green, &blue);
40 41 super(red, green, blue, scaleDoubleToQuantum(opacity));
42 }
43 44 /**
45 * Create a Color from a X11 color specification string
46 */47 this(stringcolor)
48 {
49 super(color);
50 }
51 52 /**
53 * The value for hue as a an angle between 0 and 360 degrees.
54 */55 voidhue(doublehue)
56 {
57 doubleoldHue, saturation, luminance;
58 59 ConvertRGBToHSL(packet.red, packet.green, packet.blue, &oldHue, &saturation, &luminance);
60 ConvertHSLToRGB(hue, saturation, luminance, &(packet.red), &(packet.green), &(packet.blue));
61 }
62 ///ditto63 doublehue()
64 {
65 doublehue, saturation, luminance;
66 67 ConvertRGBToHSL(packet.red, packet.green, packet.blue, &hue, &saturation, &luminance);
68 69 returnhue;
70 }
71 72 /**
73 * The value the saturation as a double in the range [0.0 .. 1.0]
74 */75 voidsaturation(doublesaturation)
76 {
77 doublehue, oldSaturation, luminance;
78 79 ConvertRGBToHSL(packet.red, packet.green, packet.blue, &hue, &oldSaturation, &luminance);
80 ConvertHSLToRGB(hue, saturation, luminance, &(packet.red), &(packet.green), &(packet.blue));
81 }
82 ///ditto83 doublesaturation()
84 {
85 doublehue, saturation, luminance;
86 87 ConvertRGBToHSL(packet.red, packet.green, packet.blue, &hue, &saturation, &luminance);
88 89 returnsaturation;
90 }
91 92 /**
93 * The value for the luminance as a double in the range [0.0 .. 1.0]
94 */95 voidluminance(doubleluminance)
96 {
97 doublehue, saturation, oldLuminance;
98 99 ConvertRGBToHSL(packet.red, packet.green, packet.blue, &hue, &saturation, &oldLuminance);
100 ConvertHSLToRGB(hue, saturation, luminance, &(packet.red), &(packet.green), &(packet.blue));
101 }
102 ///ditto103 doubleluminance()
104 {
105 doublehue, saturation, luminance;
106 107 ConvertRGBToHSL(packet.red, packet.green, packet.blue, &hue, &saturation, &luminance);
108 109 returnluminance;
110 }
111 }