示例#1
0
    public void HowToComputeColorFromCCT()
    {
        double         temperature  = 3000; // in K
        xyChromaticity chromaticity = CCTConverter.GetChromaticityOfCCT(temperature);

        // asserts
        Assert.Equal(0.43657898148148144, chromaticity.x, DoubleComparer);
        Assert.Equal(0.4041745241092054, chromaticity.y, DoubleComparer);

        IColorConverter <xyChromaticity, RGBColor> converter = new ConverterBuilder().Fromxy(Illuminants.D65).ToRGB(RGBWorkingSpaces.sRGB).Build();
        RGBColor color = converter.Convert(chromaticity);

        // asserts
        Assert.Equal(1.282323002024544, color.R, DoubleComparer);
        Assert.Equal(0.92870160729369322, color.G, DoubleComparer);
        Assert.Equal(0.55886769485605214, color.B, DoubleComparer);

        color = color.NormalizeIntensity();

        // asserts
        Assert.Equal(1, color.R, DoubleComparer);
        Assert.Equal(0.72423375844264681, color.G, DoubleComparer);
        Assert.Equal(0.4358244326692311, color.B, DoubleComparer);

        color.ToRGB8Bit(out var r, out var g, out var b);

        // asserts
        Assert.Equal(255, r);
        Assert.Equal(185, g);
        Assert.Equal(111, b);
    }
示例#2
0
    public void RangesOfChannelValuesAndClamping()
    {
        var x1 = (1.25).Clamp(0, 1);
        var x2 = (-0.5).Clamp(0, 1);
        var x3 = (0.75).Clamp(0, 1);

        // asserts
        Assert.Equal(1, x1);
        Assert.Equal(0, x2);
        Assert.Equal(0.75, x3);

        var arr1 = new[] { 1.25, -0.5, 0.75 }.Clamp(0, 1);

        // asserts
        Assert.Equal(new[] { 1, 0, 0.75 }, arr1);

        var arr2 = new[] { -50, 75, 1.25 }.Clamp(new double[] { 0, 0, 0 }, new double[] { 100, 100, 1 }); // { 0, 75, 1 }

        // asserts
        Assert.Equal(new double[] { 0, 75, 1 }, arr2);

        var color1 = new RGBColor(2, -3, 0.5);
        var color2 = color1.Clamp();

        // asserts
        Assert.Equal(new[] { 1, 0, 0.5 }, color2.Vector);

        var color3 = color1.NormalizeIntensity(); // RGB [R=1, G=0, B=0.25]

        // asserts
        Assert.Equal(new[] { 1, 0, 0.25 }, color3.Vector);

        // linear RGB
        var linearColor           = new LinearRGBColor(2, -3, 0.5);
        var normalizedLinearColor = linearColor.NormalizeIntensity(); // LinearRGB [R=1, G=0, B=0.25]

        // asserts
        Assert.Equal(new[] { 1, 0, 0.25 }, normalizedLinearColor.Vector);
    }