public void Convert_CieLab_to_LinearRgb(float l, float a, float b, float r, float g, float b2) { // Arrange var input = new CieLab(l, a, b); var expected = new LinearRgb(r, g, b2); Span <CieLab> inputSpan = new CieLab[5]; inputSpan.Fill(input); Span <LinearRgb> actualSpan = new LinearRgb[5]; // Act var actual = Converter.ToLinearRgb(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); } }
/// <summary> /// Converts a <see cref="LinearRgb"/> into a <see cref="Rgb"/> /// </summary> /// <param name="color">The color to convert.</param> /// <returns>The <see cref="Rgb"/></returns> public Rgb ToRgb(LinearRgb color) { Guard.NotNull(color, nameof(color)); // Conversion return(LinearRgbToRgbConverter.Convert(color)); }
public void Convert_LinearRgb_to_CieXyy(float r, float g, float b, float x, float y, float yl) { // Arrange var input = new LinearRgb(r, g, b); var expected = new CieXyy(x, y, yl); Span <LinearRgb> inputSpan = new LinearRgb[5]; inputSpan.Fill(input); Span <CieXyy> actualSpan = new CieXyy[5]; // Act var actual = Converter.ToCieXyy(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); } }
/// <summary> /// Converts a <see cref="Rgb"/> into a <see cref="CieXyz"/> /// </summary> /// <param name="color">The color to convert.</param> /// <returns>The <see cref="CieXyz"/></returns> public CieXyz ToCieXyz(Rgb color) { // Conversion LinearRgb linear = RgbToLinearRgbConverter.Convert(color); return(this.ToCieXyz(linear)); }
/// <summary> /// Adapts a <see cref="LinearRgb"/> color from the source working space to working space set in <see cref="TargetRgbWorkingSpace"/>. /// </summary> /// <param name="color">The color to adapt</param> /// <returns>The adapted color</returns> public LinearRgb Adapt(LinearRgb color) { Guard.NotNull(color, nameof(color)); if (!this.IsChromaticAdaptationPerformed) { throw new InvalidOperationException("Cannot perform chromatic adaptation, provide a chromatic adaptation method and white point."); } if (color.WorkingSpace.Equals(this.TargetRgbWorkingSpace)) { return(color); } // Conversion to XYZ LinearRgbToCieXyzConverter converterToXYZ = this.GetLinearRgbToCieXyzConverter(color.WorkingSpace); CieXyz unadapted = converterToXYZ.Convert(color); // Adaptation CieXyz adapted = this.ChromaticAdaptation.Transform(unadapted, color.WorkingSpace.WhitePoint, this.TargetRgbWorkingSpace.WhitePoint); // Conversion back to RGB CieXyzToLinearRgbConverter converterToRGB = this.GetCieXyxToLinearRgbConverter(this.TargetRgbWorkingSpace); return(converterToRGB.Convert(adapted)); }
/// <summary> /// Adapts an <see cref="Rgb"/> color from the source working space to working space set in <see cref="TargetRgbWorkingSpace"/>. /// </summary> /// <param name="color">The color to adapt</param> /// <returns>The adapted color</returns> public Rgb Adapt(Rgb color) { LinearRgb linearInput = this.ToLinearRgb(color); LinearRgb linearOutput = this.Adapt(linearInput); return(this.ToRgb(linearOutput)); }
/// <summary> /// Converts a <see cref="LinearRgb"/> into a <see cref="Lms"/> /// </summary> /// <param name="color">The color to convert.</param> /// <returns>The <see cref="Lms"/></returns> public Lms ToLms(LinearRgb color) { Guard.NotNull(color, nameof(color)); var xyzColor = this.ToCieXyz(color); return(this.ToLms(xyzColor)); }
/// <summary> /// Converts a <see cref="LinearRgb"/> into a <see cref="YCbCr"/> /// </summary> /// <param name="color">The color to convert.</param> /// <returns>The <see cref="YCbCr"/></returns> public YCbCr ToYCbCr(LinearRgb color) { Guard.NotNull(color, nameof(color)); var rgb = this.ToRgb(color); return(YCbCrAndRgbConverter.Convert(rgb)); }
/// <summary> /// Converts a <see cref="LinearRgb"/> into a <see cref="HunterLab"/> /// </summary> /// <param name="color">The color to convert.</param> /// <returns>The <see cref="HunterLab"/></returns> public HunterLab ToHunterLab(LinearRgb color) { Guard.NotNull(color, nameof(color)); var xyzColor = this.ToCieXyz(color); return(this.ToHunterLab(xyzColor)); }
/// <summary> /// Converts a <see cref="LinearRgb"/> into a <see cref="CieLchuv"/> /// </summary> /// <param name="color">The color to convert.</param> /// <returns>The <see cref="CieLchuv"/></returns> public CieLchuv ToCieLchuv(LinearRgb color) { Guard.NotNull(color, nameof(color)); CieXyz xyzColor = this.ToCieXyz(color); return(this.ToCieLchuv(xyzColor)); }
/// <summary> /// Converts a <see cref="LinearRgb"/> into a <see cref="Hsl"/> /// </summary> /// <param name="color">The color to convert.</param> /// <returns>The <see cref="Hsl"/></returns> public Hsl ToHsl(LinearRgb color) { Guard.NotNull(color, nameof(color)); var rgb = this.ToRgb(color); return(HslAndRgbConverter.Convert(rgb)); }
/// <summary> /// Converts a <see cref="LinearRgb"/> into a <see cref="Cmyk"/> /// </summary> /// <param name="color">The color to convert.</param> /// <returns>The <see cref="Cmyk"/></returns> public Cmyk ToCmyk(LinearRgb color) { Guard.NotNull(color, nameof(color)); var rgb = this.ToRgb(color); return(CmykAndRgbConverter.Convert(rgb)); }
/// <summary> /// Converts a <see cref="Rgb"/> into a <see cref="CieXyz"/> /// </summary> /// <param name="color">The color to convert.</param> /// <returns>The <see cref="CieXyz"/></returns> public CieXyz ToCieXyz(Rgb color) { Guard.NotNull(color, nameof(color)); // Conversion LinearRgb linear = RgbToLinearRgbConverter.Convert(color); return(this.ToCieXyz(linear)); }
/// <summary> /// Adapts an <see cref="Rgb"/> color from the source working space to working space set in <see cref="TargetRgbWorkingSpace"/>. /// </summary> /// <param name="color">The color to adapt</param> /// <returns>The adapted color</returns> public Rgb Adapt(Rgb color) { Guard.NotNull(color, nameof(color)); LinearRgb linearInput = this.ToLinearRgb(color); LinearRgb linearOutput = this.Adapt(linearInput); return(this.ToRgb(linearOutput)); }
public void LinearRgbConstructorAssignsFields() { const float r = .75F; const float g = .64F; const float b = .87F; var rgb = new LinearRgb(r, g, b); Assert.Equal(r, rgb.R); Assert.Equal(g, rgb.G); Assert.Equal(b, rgb.B); }
/// <summary> /// Converts a <see cref="LinearRgb"/> into a <see cref="CieXyz"/> /// </summary> /// <param name="color">The color to convert.</param> /// <returns>The <see cref="CieXyz"/></returns> public CieXyz ToCieXyz(LinearRgb color) { // Conversion LinearRgbToCieXyzConverter converter = this.GetLinearRgbToCieXyzConverter(color.WorkingSpace); CieXyz unadapted = converter.Convert(color); // Adaptation return(color.WorkingSpace.WhitePoint.Equals(this.WhitePoint) || !this.IsChromaticAdaptationPerformed ? unadapted : this.Adapt(unadapted, color.WorkingSpace.WhitePoint)); }
public void LinearRgbEquality() { var x = default(LinearRgb); var y = new LinearRgb(Vector3.One); Assert.True(default(LinearRgb) == default(LinearRgb)); Assert.False(default(LinearRgb) != default(LinearRgb)); Assert.Equal(default(LinearRgb), default(LinearRgb)); Assert.Equal(new LinearRgb(1, 0, 1), new LinearRgb(1, 0, 1)); Assert.Equal(new LinearRgb(Vector3.One), new LinearRgb(Vector3.One)); Assert.False(x.Equals(y)); Assert.False(x.Equals((object)y)); Assert.False(x.GetHashCode().Equals(y.GetHashCode())); }
/// <summary> /// Converts a <see cref="LinearRgb"/> into a <see cref="CieLch"/> /// </summary> /// <param name="color">The color to convert.</param> /// <returns>The <see cref="CieLch"/></returns> public CieLch ToCieLch(LinearRgb color) { CieXyz xyzColor = this.ToCieXyz(color); return(this.ToCieLch(xyzColor)); }
/// <summary> /// Converts a <see cref="LinearRgb"/> into a <see cref="Cmyk"/> /// </summary> /// <param name="color">The color to convert.</param> /// <returns>The <see cref="Cmyk"/></returns> public Cmyk ToCmyk(LinearRgb color) { var rgb = this.ToRgb(color); return(CmykAndRgbConverter.Convert(rgb)); }
/// <summary> /// Converts a <see cref="LinearRgb"/> into a <see cref="HunterLab"/> /// </summary> /// <param name="color">The color to convert.</param> /// <returns>The <see cref="HunterLab"/></returns> public HunterLab ToHunterLab(LinearRgb color) { var xyzColor = this.ToCieXyz(color); return(this.ToHunterLab(xyzColor)); }
/// <summary> /// Converts a <see cref="LinearRgb"/> into a <see cref="CieXyy"/> /// </summary> /// <param name="color">The color to convert.</param> /// <returns>The <see cref="CieXyy"/></returns> public CieXyy ToCieXyy(LinearRgb color) { var xyzColor = this.ToCieXyz(color); return(this.ToCieXyy(xyzColor)); }
/// <summary> /// Converts a <see cref="LinearRgb"/> into a <see cref="Rgb"/> /// </summary> /// <param name="color">The color to convert.</param> /// <returns>The <see cref="Rgb"/></returns> public Rgb ToRgb(LinearRgb color) { // Conversion return(LinearRgbToRgbConverter.Convert(color)); }
/// <summary> /// Converts a <see cref="LinearRgb"/> into a <see cref="Lms"/> /// </summary> /// <param name="color">The color to convert.</param> /// <returns>The <see cref="Lms"/></returns> public Lms ToLms(LinearRgb color) { var xyzColor = this.ToCieXyz(color); return(this.ToLms(xyzColor)); }
/// <summary> /// Converts a <see cref="LinearRgb"/> into a <see cref="YCbCr"/> /// </summary> /// <param name="color">The color to convert.</param> /// <returns>The <see cref="YCbCr"/></returns> public YCbCr ToYCbCr(LinearRgb color) { var rgb = this.ToRgb(color); return(YCbCrAndRgbConverter.Convert(rgb)); }
/// <summary> /// Converts a <see cref="LinearRgb"/> into a <see cref="Hsl"/> /// </summary> /// <param name="color">The color to convert.</param> /// <returns>The <see cref="Hsl"/></returns> public Hsl ToHsl(LinearRgb color) { var rgb = this.ToRgb(color); return(HslAndRgbConverter.Convert(rgb)); }