Exemplo n.º 1
0
        public void Convert_Hsl_To_Rgb(float h, float s, float l, float r, float g, float b)
        {
            // Arrange
            Hsl input = new Hsl(h, s, l);

            // Act
            Rgb output = Converter.ToRgb(input);

            // Assert
            Assert.Equal(Rgb.DefaultWorkingSpace, output.WorkingSpace);
            Assert.Equal(r, output.R, FloatRoundingComparer);
            Assert.Equal(g, output.G, FloatRoundingComparer);
            Assert.Equal(b, output.B, FloatRoundingComparer);
        }
        public void Convert_Cmyk_To_Rgb(float c, float m, float y, float k, float r, float g, float b)
        {
            // Arrange
            Cmyk input = new Cmyk(c, m, y, k);

            // Act
            Rgb output = Converter.ToRgb(input);

            // Assert
            Assert.Equal(Rgb.DefaultWorkingSpace, output.WorkingSpace, ApproximateComparer);
            Assert.Equal(r, output.R, FloatRoundingComparer);
            Assert.Equal(g, output.G, FloatRoundingComparer);
            Assert.Equal(b, output.B, FloatRoundingComparer);
        }
        private static void ValidateYCbCr(JpegColorConverter.ComponentValues values, Vector4[] result, int i)
        {
            float y     = values.Component0[i];
            float cb    = values.Component1[i];
            float cr    = values.Component2[i];
            var   ycbcr = new YCbCr(y, cb, cr);

            Vector4 rgba     = result[i];
            var     actual   = new Rgb(rgba.X, rgba.Y, rgba.Z);
            var     expected = ColorSpaceConverter.ToRgb(ycbcr);

            Assert.True(actual.AlmostEquals(expected, Precision), $"{actual} != {expected}");
            Assert.Equal(1, rgba.W);
        }
Exemplo n.º 4
0
        public void Convert_YCbCr_To_Rgb(float y, float cb, float cr, float r, float g, float b)
        {
            // Arrange
            YCbCr input = new YCbCr(y, cb, cr);

            // Act
            Rgb output = Converter.ToRgb(input);

            // Assert
            Assert.Equal(Rgb.DefaultWorkingSpace, output.WorkingSpace);
            Assert.Equal(r, output.R, FloatRoundingComparer);
            Assert.Equal(g, output.G, FloatRoundingComparer);
            Assert.Equal(b, output.B, FloatRoundingComparer);
        }
Exemplo n.º 5
0
        public static Image <Rgba32> GenerateImage(Hsv[,] contents)
        {
            var converter = new ColorSpaceConverter();
            var image     = new Image <Rgba32>(contents.GetLength(0), contents.GetLength(1));

            for (var i = 0; i < image.Width; ++i)
            {
                for (var j = 0; j < image.Height; ++j)
                {
                    image[i, j] = converter.ToRgb(contents[i, j]);
                }
            }

            return(image);
        }
Exemplo n.º 6
0
        private static async Task SaveGradientAsync(string path, List <CieLch> gradient)
        {
            var       converter = new ColorSpaceConverter();
            var       image     = new Image <Rgba32>(gradient.Count, 50);
            const int height    = 50;

            for (var x = 0; x < gradient.Count; x++)
            {
                for (var y = 0; y < height; y++)
                {
                    image[x, y] = converter.ToRgb(gradient[x]);
                }
            }

            await image.SaveAsync(path);
        }
Exemplo n.º 7
0
        public void Convert_XYZ_D65_to_SRGB(float x, float y, float z, float r, float g, float b)
        {
            // Arrange
            CieXyz input = new CieXyz(x, y, z);
            ColorSpaceConverter converter = new ColorSpaceConverter {
                WhitePoint = Illuminants.D65, TargetRgbWorkingSpace = RgbWorkingSpaces.SRgb
            };

            // Act
            Rgb output = converter.ToRgb(input);

            // Assert
            Assert.Equal(Rgb.DefaultWorkingSpace, output.WorkingSpace);
            Assert.Equal(r, output.R, FloatRoundingComparer);
            Assert.Equal(g, output.G, FloatRoundingComparer);
            Assert.Equal(b, output.B, FloatRoundingComparer);
        }
        public void Convert_XYZ_D50_to_SRGB(float x, float y, float z, float r, float g, float b)
        {
            // Arrange
            CieXyz input = new CieXyz(x, y, z);
            ColorSpaceConverter converter = new ColorSpaceConverter {
                WhitePoint = Illuminants.D50, TargetRgbWorkingSpace = RgbWorkingSpaces.SRgb
            };

            // Act
            Rgb output = converter.ToRgb(input);

            // Assert
            IEqualityComparer <float> comparer = new ApproximateFloatComparer(0.001f);

            Assert.Equal(Rgb.DefaultWorkingSpace, output.WorkingSpace, ApproximateComparer);
            Assert.Equal(r, output.R, comparer);
            Assert.Equal(g, output.G, comparer);
            Assert.Equal(b, output.B, comparer);
        }
Exemplo n.º 9
0
        private Rgba32 GetColour(IReadOnlyList <CieLch> gradient, byte index)
        {
            var overlayOptions = _options.Overlay;
            var maxIntensity   = overlayOptions.MaxIntensity;
            var minIntensity   = overlayOptions.MinIntensity;

            var temperature = GetTemperature(index);
            var range       = maxIntensity - minIntensity;

            if (temperature < minIntensity || temperature > maxIntensity)
            {
                return(Color.Transparent);
            }

            var interpolateAmount = (float)(temperature - minIntensity) / range;
            var cieLch            = gradient[(int)Math.Round(interpolateAmount * (gradient.Count - 1))];

            return(_converter.ToRgb(cieLch));
        }
Exemplo n.º 10
0
 public float ColorSpaceConvert()
 {
     return(ColorSpaceConverter.ToRgb(CieXyz).R);
 }
 /// <summary>
 /// Convert <see cref="Hsv"/> to <see cref="Color"/>.
 /// </summary>
 /// <param name="converter">Converter.</param>
 /// <param name="hsv">Source <see cref="Hsv"/>.</param>
 /// <returns>Converted <see cref="Color"/>.</returns>
 public static Color ToColor(this ColorSpaceConverter converter, Hsv hsv)
 {
     return(ToColor(converter.ToRgb(hsv)));
 }