HSL.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System;
  2. namespace LYFZ.OtherExpansion.Imaging
  3. {
  4. public class HSL
  5. {
  6. private int _hue;
  7. private double _saturation;
  8. private double _luminance;
  9. public int Hue
  10. {
  11. get
  12. {
  13. return this._hue;
  14. }
  15. set
  16. {
  17. if (value < 0)
  18. {
  19. this._hue = 0;
  20. return;
  21. }
  22. if (value <= 360)
  23. {
  24. this._hue = value;
  25. return;
  26. }
  27. this._hue = value % 360;
  28. }
  29. }
  30. public double Saturation
  31. {
  32. get
  33. {
  34. return this._saturation;
  35. }
  36. set
  37. {
  38. if (value < 0.0)
  39. {
  40. this._saturation = 0.0;
  41. return;
  42. }
  43. this._saturation = Math.Min(value, 1.0);
  44. }
  45. }
  46. public double Luminance
  47. {
  48. get
  49. {
  50. return this._luminance;
  51. }
  52. set
  53. {
  54. if (value < 0.0)
  55. {
  56. this._luminance = 0.0;
  57. return;
  58. }
  59. this._luminance = Math.Min(value, 1.0);
  60. }
  61. }
  62. public HSL()
  63. {
  64. }
  65. public HSL(int hue, double saturation, double luminance)
  66. {
  67. this.Hue = hue;
  68. this.Saturation = saturation;
  69. this.Luminance = luminance;
  70. }
  71. public override string ToString()
  72. {
  73. return string.Format("HSL [H={0}, S={1}, L={2}]", this._hue, this._saturation, this._luminance);
  74. }
  75. }
  76. }