Example #1
0
 /// <inheritdoc/>
 public bool Equals(IRgbWorkingSpace other)
 {
     // TODO: Object.Equals for ICompanding will be slow.
     return(this.WhitePoint.Equals(other.WhitePoint) &&
            this.ChromaticityCoordinates.Equals(other.ChromaticityCoordinates) &&
            Equals(this.Companding, other.Companding));
 }
Example #2
0
 public Rgb(Vector3 vector, IRgbWorkingSpace workingSpace)
     : this()
 {
     // Clamp to 0-1 range.
     this.backingVector = Vector3.Clamp(vector, Vector3.Zero, Vector3.One);
     this.WorkingSpace  = workingSpace;
 }
Example #3
0
        /// <summary>
        /// Gets the correct converter for the given rgb working space.
        /// </summary>
        /// <param name="workingSpace">The target working space</param>
        /// <returns>The <see cref="CieXyzToLinearRgbConverter"/></returns>
        private CieXyzToLinearRgbConverter GetCieXyxToLinearRgbConverter(IRgbWorkingSpace workingSpace)
        {
            if (this.cieXyzToLinearRgbConverter != null && this.cieXyzToLinearRgbConverter.TargetWorkingSpace.Equals(workingSpace))
            {
                return(this.cieXyzToLinearRgbConverter);
            }

            return(this.cieXyzToLinearRgbConverter = new CieXyzToLinearRgbConverter(workingSpace));
        }
Example #4
0
        /// <summary>
        /// Gets the correct converter for the given rgb working space.
        /// </summary>
        /// <param name="workingSpace">The source working space</param>
        /// <returns>The <see cref="LinearRgbToCieXyzConverter"/></returns>
        private LinearRgbToCieXyzConverter GetLinearRgbToCieXyzConverter(IRgbWorkingSpace workingSpace)
        {
            if (this.linearRgbToCieXyzConverter != null && this.linearRgbToCieXyzConverter.SourceWorkingSpace.Equals(workingSpace))
            {
                return(this.linearRgbToCieXyzConverter);
            }

            return(this.linearRgbToCieXyzConverter = new LinearRgbToCieXyzConverter(workingSpace));
        }
Example #5
0
        public bool Equals(IRgbWorkingSpace x, IRgbWorkingSpace y)
        {
            if (x is IRgbWorkingSpace g1 && y is IRgbWorkingSpace g2)
            {
                return(this.Equals(g1.WhitePoint, g2.WhitePoint) &&
                       this.Equals(g1.ChromaticityCoordinates, g2.ChromaticityCoordinates));
            }

            return(this.Equals(x.WhitePoint, y.WhitePoint) &&
                   this.Equals(x.ChromaticityCoordinates, y.ChromaticityCoordinates));
        }
        /// <summary>
        /// Geturns the correct matrix to convert between the Rgb and CieXyz color space.
        /// </summary>
        /// <param name="workingSpace">The Rgb working space.</param>
        /// <returns>The <see cref="Matrix4x4"/> based on the chromaticity and working space.</returns>
        public static Matrix4x4 GetRgbToCieXyzMatrix(IRgbWorkingSpace workingSpace)
        {
            DebugGuard.NotNull(workingSpace, nameof(workingSpace));

            RgbPrimariesChromaticityCoordinates chromaticity = workingSpace.ChromaticityCoordinates;

            float xr = chromaticity.R.X;
            float xg = chromaticity.G.X;
            float xb = chromaticity.B.X;
            float yr = chromaticity.R.Y;
            float yg = chromaticity.G.Y;
            float yb = chromaticity.B.Y;

            float       mXr = xr / yr;
            const float Yr  = 1;
            float       mZr = (1 - xr - yr) / yr;

            float       mXg = xg / yg;
            const float Yg  = 1;
            float       mZg = (1 - xg - yg) / yg;

            float       mXb = xb / yb;
            const float Yb  = 1;
            float       mZb = (1 - xb - yb) / yb;

            Matrix4x4 xyzMatrix = new Matrix4x4
            {
                M11 = mXr, M21 = mXg, M31 = mXb,
                M12 = Yr, M22 = Yg, M32 = Yb,
                M13 = mZr, M23 = mZg, M33 = mZb,
                M44 = 1F
            };

            Matrix4x4 inverseXyzMatrix;

            Matrix4x4.Invert(xyzMatrix, out inverseXyzMatrix);

            Vector3 vector = Vector3.Transform(workingSpace.WhitePoint.Vector, inverseXyzMatrix);

            // Use transposed Rows/Coloumns
            // TODO: Is there a built in method for this multiplication?
            return(new Matrix4x4
            {
                M11 = vector.X * mXr, M21 = vector.Y * mXg, M31 = vector.Z * mXb,
                M12 = vector.X * Yr, M22 = vector.Y * Yg, M32 = vector.Z * Yb,
                M13 = vector.X * mZr, M23 = vector.Y * mZg, M33 = vector.Z * mZb,
                M44 = 1F
            });
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="LinearRgbToCieXyzConverter"/> class.
 /// </summary>
 /// <param name="workingSpace">The target working space.</param>
 public LinearRgbToCieXyzConverter(IRgbWorkingSpace workingSpace)
 {
     this.SourceWorkingSpace = workingSpace;
     this.conversionMatrix   = GetRgbToCieXyzMatrix(workingSpace);
 }
Example #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CieXyzToLinearRgbConverter"/> class.
 /// </summary>
 /// <param name="workingSpace">The target working space.</param>
 public CieXyzToLinearRgbConverter(IRgbWorkingSpace workingSpace)
 {
     this.TargetWorkingSpace = workingSpace;
     this.conversionMatrix   = GetRgbToCieXyzMatrix(workingSpace);
 }
Example #9
0
 public Rgb(float r, float g, float b, IRgbWorkingSpace workingSpace)
     : this(new Vector3(r, g, b), workingSpace)
 {
 }
Example #10
0
 public int GetHashCode(IRgbWorkingSpace obj)
 {
     throw new NotImplementedException();
 }