public void Convert_CieLchuv_to_CieLch(float l, float c, float h, float l2, float c2, float h2)
        {
            // Arrange
            var input    = new CieLchuv(l, c, h);
            var expected = new CieLch(l2, c2, h2);

            Span <CieLchuv> inputSpan = new CieLchuv[5];

            inputSpan.Fill(input);

            Span <CieLch> actualSpan = new CieLch[5];

            // Act
            var actual = Converter.ToCieLch(input);

            Converter.Convert(inputSpan, actualSpan);

            // Assert
            Assert.Equal(expected, actual, ColorSpaceComparer);

            for (int i = 0; i < actualSpan.Length; i++)
            {
                Assert.Equal(expected, actualSpan[i], ColorSpaceComparer);
            }
        }
        public void Convert_YCbCr_to_CieLch(float y, float cb, float cr, float l, float c, float h)
        {
            // Arrange
            var input    = new YCbCr(y, cb, cr);
            var expected = new CieLch(l, c, h);

            Span <YCbCr> inputSpan = new YCbCr[5];

            inputSpan.Fill(input);

            Span <CieLch> actualSpan = new CieLch[5];

            // Act
            var actual = Converter.ToCieLch(input);

            Converter.Convert(inputSpan, actualSpan);

            // Assert
            Assert.Equal(expected, actual, ColorSpaceComparer);

            for (int i = 0; i < actualSpan.Length; i++)
            {
                Assert.Equal(expected, actualSpan[i], ColorSpaceComparer);
            }
        }
Example #3
0
        public void Convert_HunterLab_to_CieLch(float l2, float a, float b, float l, float c, float h)
        {
            // Arrange
            var input    = new HunterLab(l2, a, b);
            var expected = new CieLch(l, c, h);

            Span <HunterLab> inputSpan = new HunterLab[5];

            inputSpan.Fill(input);

            Span <CieLch> actualSpan = new CieLch[5];

            // Act
            var actual = Converter.ToCieLch(input);

            Converter.Convert(inputSpan, actualSpan);

            // Assert
            Assert.Equal(expected, actual, ColorSpaceComparer);

            for (int i = 0; i < actualSpan.Length; i++)
            {
                Assert.Equal(expected, actualSpan[i], ColorSpaceComparer);
            }
        }
Example #4
0
        public async Task InitialiseAsync()
        {
            var json = await File.ReadAllTextAsync(_options.Overlay.GradientPath);

            var gradient = JsonConvert.DeserializeObject <List <RgbColourStop> >(json)
                           .Select(c =>
            {
                if (c.Colour == null)
                {
                    throw new ValidationException("Colour must be specified");
                }
                var colour = c.Colour.FromHexString();

                if (colour == null)
                {
                    throw new ValidationException($"Unable to parse {c.Colour} as a hex triplet");
                }
                if (c.Position == null)
                {
                    throw new ValidationException("Position must be specified for all colour stops");
                }
                if (c.Position < 0 || c.Position > 1)
                {
                    throw new ValidationException($"{c.Position} is an invalid position; valid values are from 0.0 to 1.0");
                }

                var rgb = colour.Value.ToPixel <Rgba32>();
                return(new ColourStop(_colourSpaceConverter.ToCieLch(rgb), c.Position.Value));
            })
                           .OrderBy(c => c.Position)
                           .ToImmutableList();

            _interpolatedGradient = InterpolateGradient(gradient);
            _initialised          = true;
        }
Example #5
0
        public void Convert_LinearRgb_to_CieLch(float r, float g, float b, float l, float c, float h)
        {
            // Arrange
            var input    = new LinearRgb(r, g, b);
            var expected = new CieLch(l, c, h);

            Span <LinearRgb> inputSpan = new LinearRgb[5];

            inputSpan.Fill(input);

            Span <CieLch> actualSpan = new CieLch[5];

            // Act
            var actual = Converter.ToCieLch(input);

            Converter.Convert(inputSpan, actualSpan, actualSpan.Length);

            // Assert
            Assert.Equal(expected, actual, ColorSpaceComparer);

            for (int i = 0; i < actualSpan.Length; i++)
            {
                Assert.Equal(expected, actualSpan[i], ColorSpaceComparer);
            }
        }
Example #6
0
        public void Convert_Cmyk_to_CieLch(float c, float m, float y, float k, float l, float c2, float h)
        {
            // Arrange
            var input    = new Cmyk(c, m, y, k);
            var expected = new CieLch(l, c2, h);

            Span <Cmyk> inputSpan = new Cmyk[5];

            inputSpan.Fill(input);

            Span <CieLch> actualSpan = new CieLch[5];

            // Act
            var actual = Converter.ToCieLch(input);

            Converter.Convert(inputSpan, actualSpan, actualSpan.Length);

            // Assert
            Assert.Equal(expected, actual, ColorSpaceComparer);

            for (int i = 0; i < actualSpan.Length; i++)
            {
                Assert.Equal(expected, actualSpan[i], ColorSpaceComparer);
            }
        }
        public void Convert_Lab_to_LCHab(float l, float a, float b, float l2, float c, float h)
        {
            // Arrange
            CieLab input = new CieLab(l, a, b);

            // Act
            CieLch output = Converter.ToCieLch(input);

            // Assert
            Assert.Equal(l2, output.L, FloatRoundingComparer);
            Assert.Equal(c, output.C, FloatRoundingComparer);
            Assert.Equal(h, output.H, FloatRoundingComparer);
        }