예제 #1
0
    public void Equals_Same()
    {
        var first  = new xyYColor(x: .1, y: .205, luminance: .45445);
        var second = new xyYColor(x: .1, y: .205, luminance: .45445);

        CustomAssert.EqualsWithHashCode(first, second);
    }
예제 #2
0
        public void xyYColor()
        {
            var first  = new xyYColor(0, 0.5, 0.445);
            var second = new xyYColor(0, 0.5, 0.445);

            Assert.Equal(first, (object)second);
        }
예제 #3
0
    public void VectorCtor()
    {
        var first  = new xyYColor(x: .2, y: .205, luminance: .45445);
        var vector = new[] { .2, .205, .45445 };
        var second = new xyYColor(vector);

        CustomAssert.EqualsWithHashCode(first, second);
        Assert.Equal(vector, second.Vector);
    }
예제 #4
0
    public void Dctor()
    {
        const double x1         = .1;
        const double y1         = .205;
        const double luminance1 = .45445;

        var(x2, y2, luminance2) = new xyYColor(x1, y1, luminance1);
        Assert.Equal(x1, x2);
        Assert.Equal(y1, y2);
        Assert.Equal(luminance1, luminance2);
    }
        public HunterLabColor ToHunterLab(xyYColor color)
        {
            if (color == null)
            {
                throw new ArgumentNullException("color");
            }

            XYZColor       xyzColor = ToXYZ(color);
            HunterLabColor result   = ToHunterLab(xyzColor);

            return(result);
        }
예제 #6
0
        public xyYColor ToxyY(LChabColor color)
        {
            if (color == null)
            {
                throw new ArgumentNullException("color");
            }

            XYZColor xyzColor = ToXYZ(color);
            xyYColor result   = ToxyY(xyzColor);

            return(result);
        }
예제 #7
0
        public LinearRGBColor ToLinearRGB(xyYColor color)
        {
            if (color == null)
            {
                throw new ArgumentNullException("color");
            }

            XYZColor       xyzColor = ToXYZ(color);
            LinearRGBColor result   = ToLinearRGB(xyzColor);

            return(result);
        }
예제 #8
0
        public XYZColor ToXYZ(xyYColor color)
        {
            if (color == null)
            {
                throw new ArgumentNullException("color");
            }

            // conversion
            var      converter = new xyYAndXYZConverter();
            XYZColor converted = converter.Convert(color);

            return(converted);
        }
예제 #9
0
    public void SamplesXyy()
    {
        // red
        var c1 = new xyYColor(0.5736, 0.3209, 0.21);

        // white (relative to D65 illuminant)
        var c2 = new xyYColor(0.3127, 0.3290, 1);

        // gray (relative to D65 illuminant)
        var c3 = new xyYColor(0.3127, 0.3290, 0.21);

        // black (relative to D65 illuminant), note chromaticity doesn't matter here
        var c4 = new xyYColor(0.3127, 0.3290, 0);
    }
        public void Convert_xyY_to_XYZ(double xyzX, double xyzY, double xyzZ, double x, double y, double Y)
        {
            // arrange
            var input     = new xyYColor(x, y, Y);
            var converter = new ColourfulConverter();

            // act
            var output = converter.ToXYZ(input);

            // assert
            Assert.Equal(output.X, xyzX, DoubleComparer);
            Assert.Equal(output.Y, xyzY, DoubleComparer);
            Assert.Equal(output.Z, xyzZ, DoubleComparer);
        }
예제 #11
0
        public void Convert_xyY_to_XYZ(double xyzX, double xyzY, double xyzZ, double x, double y, double Y)
        {
            // arrange
            var input     = new xyYColor(x, y, Y);
            var converter = new ColourfulConverter();

            // act
            XYZColor output = converter.ToXYZ(input);

            // assert
            Assert.That(output.X, Is.EqualTo(xyzX).Using(DoubleComparer));
            Assert.That(output.Y, Is.EqualTo(xyzY).Using(DoubleComparer));
            Assert.That(output.Z, Is.EqualTo(xyzZ).Using(DoubleComparer));
        }
        public void Convert_xyY_to_XYZ(double xyzX, double xyzY, double xyzZ, double x, double y, double Y)
        {
            // arrange
            var input = new xyYColor(x, y, Y);
            var converter = new ColourfulConverter();

            // act
            XYZColor output = converter.ToXYZ(input);

            // assert
            Assert.That(output.X, Is.EqualTo(xyzX).Using(DoubleComparer));
            Assert.That(output.Y, Is.EqualTo(xyzY).Using(DoubleComparer));
            Assert.That(output.Z, Is.EqualTo(xyzZ).Using(DoubleComparer));
        }
예제 #13
0
        public void Convert_XYZ_to_xyY(double xyzX, double xyzY, double xyzZ, double x, double y, double Y)
        {
            // arrange
            var input     = new XYZColor(xyzX, xyzY, xyzZ);
            var converter = new ColourfulConverter();

            // act
            xyYColor output = converter.ToxyY(input);

            // assert
            Assert.That(output.x, Is.EqualTo(x).Using(DoubleComparer));
            Assert.That(output.y, Is.EqualTo(y).Using(DoubleComparer));
            Assert.That(output.Luminance, Is.EqualTo(Y).Using(DoubleComparer));
        }
예제 #14
0
        public xyYColor ToxyY <T>(T color) where T : IColorVector
        {
            if (color == null)
            {
                throw new ArgumentNullException("color");
            }

            xyYColor converted = color as xyYColor;

            if (converted != null)
            {
                return(converted);
            }
            else
            {
                dynamic source = color;

                return(ToxyY(source));
            }
        }
예제 #15
0
    public void ToString_Simple()
    {
        var color = new xyYColor(x: .1, y: .205, luminance: .45445);

        Assert.Equal("xyY [x=0.1, y=0.21, Y=0.45]", color.ToString());
    }
예제 #16
0
        /// <summary>
        /// Convert directly from xyY to RGB
        /// </summary>
        public static float[] xyYtoRGB(xyYColor xyY)
        {
            float Yony = xyY.Y / xyY.y;
            XYZColor XYZ = new XYZColor(xyY.x * Yony, xyY.Y, (1.0f - xyY.x - xyY.y) * Yony);

            float[] XYZf3 = XYZ.AsFloat3;
            float[] ret = new float[3];
            for (int i=0; i<3; i++) {
                ret[i] = 0f;
                for (int j=0; j<3; j++)
                    ret[i] += XYZf3[j] * XYZtoRGBconv[i, j];
            }

            return new float[]{ret[0], ret[1], ret[2], 1.0f};
        }
예제 #17
0
        /// <summary>
        /// Calculates the maximum luminance for the supplied turbidity and sun theta
        /// </summary>
        public static float MaximumLuminance(float turbidity, float sunTheta, xyYColor zenith, xyYCoeffs coeffs)
        {
            float theta = sunTheta;
            if (sunTheta >= HALF_PI)  theta = HALF_PI - 0.01f;

            return Distribution(coeffs.Y, theta, zenith.Y, 0f) * 1.5f;
        }
예제 #18
0
        /// <summary>
        /// Calculates the RGB atmospheric color (fog + lightning use this in sunrise/sunset)
        /// </summary>
        public static float[] AtmosphereColor(float turbidity, float sunTheta, xyYColor zenith, xyYCoeffs coeffs)
        {
            float theta = Math.Min(sunTheta + 0.15f, HALF_PI - 0.01f);
            xyYColor skyColor;

            // Sky color distribution (using the Perez Function)
            skyColor.x = Distribution(coeffs.x, theta, zenith.x, 0.2f);
            skyColor.y = Distribution(coeffs.y, theta, zenith.y, 0.2f);
            skyColor.Y = 0.5f;

            float[] ret = xyYtoRGB(skyColor);
            return ret;
        }