|
| 1 | +/* |
| 2 | + * The MIT License (MIT) |
| 3 | + * Copyright (c) 2014 Andrés Correa Casablanca |
| 4 | + * |
| 5 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | + * of this software and associated documentation files (the "Software"), to deal |
| 7 | + * in the Software without restriction, including without limitation the rights |
| 8 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | + * copies of the Software, and to permit persons to whom the Software is |
| 10 | + * furnished to do so, subject to the following conditions: |
| 11 | + * |
| 12 | + * The above copyright notice and this permission notice shall be included in all |
| 13 | + * copies or substantial portions of the Software. |
| 14 | + * |
| 15 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 | + * SOFTWARE. |
| 22 | + */ |
| 23 | + |
| 24 | +/* |
| 25 | +* Contributors: |
| 26 | +* - Andrés Correa Casablanca <[email protected] , [email protected]> |
| 27 | +*/ |
| 28 | + |
| 29 | + |
| 30 | +using System; |
| 31 | + |
| 32 | + |
| 33 | +namespace Litipk.ColorSharp |
| 34 | +{ |
| 35 | + namespace ColorSpaces |
| 36 | + { |
| 37 | + /** |
| 38 | + * <summary>CIE's 1960 UVW Color Space.</summary> |
| 39 | + */ |
| 40 | + public sealed class CIEUVW : AConvertibleColor |
| 41 | + { |
| 42 | + #region properties |
| 43 | + |
| 44 | + /** |
| 45 | + * <value>U component of the CIE's 1960 UVW color space.</value> |
| 46 | + */ |
| 47 | + public readonly double U; |
| 48 | + |
| 49 | + /** |
| 50 | + * <value>V component of the CIE's 1960 UVW color space.</value> |
| 51 | + */ |
| 52 | + public readonly double V; |
| 53 | + |
| 54 | + /** |
| 55 | + * <value>W component of the CIE's 1960 UVW color space.</value> |
| 56 | + */ |
| 57 | + public readonly double W; |
| 58 | + |
| 59 | + #endregion |
| 60 | + |
| 61 | + |
| 62 | + #region constructors |
| 63 | + |
| 64 | + public CIEUVW (double U, double V, double W, AConvertibleColor dataSource=null) : base(dataSource) |
| 65 | + { |
| 66 | + this.U = U; |
| 67 | + this.V = V; |
| 68 | + this.W = W; |
| 69 | + } |
| 70 | + |
| 71 | + #endregion |
| 72 | + |
| 73 | + |
| 74 | + #region AConvertibleColor methods |
| 75 | + |
| 76 | + /** |
| 77 | + * <inheritdoc /> |
| 78 | + */ |
| 79 | + public override bool IsInsideColorSpace() |
| 80 | + { |
| 81 | + // TODO : Improve ? |
| 82 | + return ToCIExyY ().IsInsideColorSpace (); |
| 83 | + } |
| 84 | + |
| 85 | + /** |
| 86 | + * <inheritdoc /> |
| 87 | + */ |
| 88 | + public override CIEXYZ ToCIEXYZ (ConversionStrategy strategy=ConversionStrategy.Default) |
| 89 | + { |
| 90 | + return (DataSource as CIEXYZ) ?? new CIEXYZ ( |
| 91 | + 1.5 * U, V, 1.5 * U - 3 * V + 2 * W, DataSource ?? this |
| 92 | + ); |
| 93 | + } |
| 94 | + |
| 95 | + /** |
| 96 | + * <inheritdoc /> |
| 97 | + */ |
| 98 | + public override CIEUVW ToCIEUVW (ConversionStrategy strategy = ConversionStrategy.Default) |
| 99 | + { |
| 100 | + return this; |
| 101 | + } |
| 102 | + |
| 103 | + #endregion |
| 104 | + |
| 105 | + |
| 106 | + #region Object methods |
| 107 | + |
| 108 | + /** |
| 109 | + * <inheritdoc /> |
| 110 | + */ |
| 111 | + public override bool Equals(Object obj) |
| 112 | + { |
| 113 | + CIEUVW uvwObj = obj as CIEUVW; |
| 114 | + |
| 115 | + if (uvwObj == this) { |
| 116 | + return true; |
| 117 | + } |
| 118 | + if (uvwObj == null || GetHashCode () != obj.GetHashCode ()) { |
| 119 | + return false; |
| 120 | + } |
| 121 | + |
| 122 | + return (U == uvwObj.U && V == uvwObj.V && W == uvwObj.W); |
| 123 | + } |
| 124 | + |
| 125 | + /** |
| 126 | + * <inheritdoc /> |
| 127 | + */ |
| 128 | + public override int GetHashCode () |
| 129 | + { |
| 130 | + int hash = 77837 + U.GetHashCode (); // 77837 == 277 * 281 |
| 131 | + |
| 132 | + hash = hash * 281 + V.GetHashCode (); |
| 133 | + |
| 134 | + return hash * 281 + W.GetHashCode (); |
| 135 | + } |
| 136 | + |
| 137 | + #endregion |
| 138 | + } |
| 139 | + } |
| 140 | +} |
0 commit comments