1 /** 2 * Copyright: Mike Wey 2011 3 * License: zlib (See accompanying LICENSE file) 4 * Authors: Mike Wey 5 */ 6 7 module dmagick.ColorHSL; 8 9 import dmagick.Color; 10 11 import dmagick.c.gem; 12 import dmagick.c.magickType; 13 import dmagick.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 class ColorHSL : Color 25 { 26 /** */ 27 this() 28 { 29 super(); 30 } 31 32 /** 33 * Create a Color from the specified doubles. 34 */ 35 this(double hue, double saturation, double luminance, double opacity = 0) 36 { 37 Quantum red, 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(string color) 48 { 49 super(color); 50 } 51 52 /** 53 * The value for hue as a an angle between 0 and 360 degrees. 54 */ 55 void hue(double hue) 56 { 57 double oldHue, 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 ///ditto 63 double hue() 64 { 65 double hue, saturation, luminance; 66 67 ConvertRGBToHSL(packet.red, packet.green, packet.blue, &hue, &saturation, &luminance); 68 69 return hue; 70 } 71 72 /** 73 * The value the saturation as a double in the range [0.0 .. 1.0] 74 */ 75 void saturation(double saturation) 76 { 77 double hue, 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 ///ditto 83 double saturation() 84 { 85 double hue, saturation, luminance; 86 87 ConvertRGBToHSL(packet.red, packet.green, packet.blue, &hue, &saturation, &luminance); 88 89 return saturation; 90 } 91 92 /** 93 * The value for the luminance as a double in the range [0.0 .. 1.0] 94 */ 95 void luminance(double luminance) 96 { 97 double hue, 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 ///ditto 103 double luminance() 104 { 105 double hue, saturation, luminance; 106 107 ConvertRGBToHSL(packet.red, packet.green, packet.blue, &hue, &saturation, &luminance); 108 109 return luminance; 110 } 111 }