|
|
|
@ -15,9 +15,6 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg |
|
|
|
{ |
|
|
|
public class RgbToYCbCrConverterTests |
|
|
|
{ |
|
|
|
private const float Epsilon = .5F; |
|
|
|
private static readonly ApproximateColorSpaceComparer Comparer = new ApproximateColorSpaceComparer(Epsilon); |
|
|
|
|
|
|
|
public RgbToYCbCrConverterTests(ITestOutputHelper output) |
|
|
|
{ |
|
|
|
this.Output = output; |
|
|
|
@ -37,7 +34,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg |
|
|
|
|
|
|
|
target.Convert(data.AsSpan(), ref y, ref cb, ref cr); |
|
|
|
|
|
|
|
Verify(data, ref y, ref cb, ref cr); |
|
|
|
Verify(data, ref y, ref cb, ref cr, new ApproximateColorSpaceComparer(1F)); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
@ -61,10 +58,10 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg |
|
|
|
|
|
|
|
RgbToYCbCrConverterVectorized.Convert(data.AsSpan(), ref y, ref cb, ref cr); |
|
|
|
|
|
|
|
Verify(dataCopy, ref y, ref cb, ref cr); |
|
|
|
Verify(dataCopy, ref y, ref cb, ref cr, new ApproximateColorSpaceComparer(0.0001F)); |
|
|
|
} |
|
|
|
|
|
|
|
private static void Verify(ReadOnlySpan<Rgb24> data, ref Block8x8F yResult, ref Block8x8F cbResult, ref Block8x8F crResult) |
|
|
|
private static void Verify(ReadOnlySpan<Rgb24> data, ref Block8x8F yResult, ref Block8x8F cbResult, ref Block8x8F crResult, ApproximateColorSpaceComparer comparer) |
|
|
|
{ |
|
|
|
for (int i = 0; i < data.Length; i++) |
|
|
|
{ |
|
|
|
@ -76,7 +73,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg |
|
|
|
float cb = 128F + ((-0.168736F * r) - (0.331264F * g) + (0.5F * b)); |
|
|
|
float cr = 128F + ((0.5F * r) - (0.418688F * g) - (0.081312F * b)); |
|
|
|
|
|
|
|
Assert.Equal(new YCbCr(y, cb, cr), new YCbCr(yResult[i], cbResult[i], crResult[i]), Comparer); |
|
|
|
Assert.Equal(new YCbCr(y, cb, cr), new YCbCr(yResult[i], cbResult[i], crResult[i]), comparer); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|