aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/SideChains/Colourful/Implementation/RGB/RGBWorkingSpace.cs
blob: 98ee3f66dd1f3412a3ff02c7020a092f424c6e26 (plain)
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
namespace Colourful.Implementation.RGB
{
    /// <summary>
    /// Trivial implementation of <see cref="IRGBWorkingSpace" />
    /// </summary>
    public sealed class RGBWorkingSpace : IRGBWorkingSpace
    {
        /// <summary>
        /// Constructs RGB working space using a reference white, companding, and chromacity coordinates.
        /// </summary>
        public RGBWorkingSpace(XYZColor referenceWhite, ICompanding companding, RGBPrimariesChromaticityCoordinates chromaticityCoordinates)
        {
            WhitePoint = referenceWhite;
            Companding = companding;
            ChromaticityCoordinates = chromaticityCoordinates;
        }

        /// <summary>
        /// Reference white point
        /// </summary>
        public XYZColor WhitePoint { get; }

        /// <summary>
        /// Chromacity coordinates
        /// </summary>
        public RGBPrimariesChromaticityCoordinates ChromaticityCoordinates { get; }

        /// <summary>
        /// Companding
        /// </summary>
        public ICompanding Companding { get; }

        #region Overrides

        /// <inheritdoc cref="object" />
        public bool Equals(IRGBWorkingSpace other)
        {
            if (other == null)
                return false;

            if (ReferenceEquals(this, other))
                return true;

            return Equals(WhitePoint, other.WhitePoint)
                   && ChromaticityCoordinates.Equals(other.ChromaticityCoordinates)
                   && Companding.Equals(other.Companding);
        }

        /// <inheritdoc cref="object" />
        public override bool Equals(object obj) => obj is IRGBWorkingSpace other && Equals(other);

        /// <inheritdoc cref="object" />
        public override int GetHashCode()
        {
            unchecked
            {
                var hashCode = WhitePoint.GetHashCode();
                hashCode = (hashCode * 397) ^ ChromaticityCoordinates.GetHashCode();
                hashCode = (hashCode * 397) ^ (Companding != null ? Companding.GetHashCode() : 0);
                return hashCode;
            }
        }

        /// <inheritdoc cref="object" />
        public static bool operator ==(RGBWorkingSpace left, RGBWorkingSpace right) => Equals(left, right);

        /// <inheritdoc cref="object" />
        public static bool operator !=(RGBWorkingSpace left, RGBWorkingSpace right) => !Equals(left, right);

        #endregion
    }
}