Browse Source

Add simd approach to benchmark

pull/75/head
James Jackson-South 9 years ago
parent
commit
d6a03cb4c8
  1. 25
      tests/ImageSharp.Benchmarks/Color/RgbToYCbCr.cs

25
tests/ImageSharp.Benchmarks/Color/RgbToYCbCr.cs

@ -6,6 +6,10 @@
public class RgbToYCbCr
{
private static readonly Vector3 VectorY = new Vector3(0.299F, 0.587F, 0.114F);
private static readonly Vector3 VectorCb = new Vector3(-0.168736F, 0.331264F, 0.5F);
private static readonly Vector3 VectorCr = new Vector3(0.5F, 0.418688F, 0.081312F);
[Benchmark(Baseline = true, Description = "Floating Point Conversion")]
public Vector3 RgbaToYcbCr()
{
@ -18,6 +22,21 @@
return new Vector3(yy, cb, cr);
}
[Benchmark(Description = "Simd Floating Point Conversion")]
public Vector3 RgbaToYcbCrSimd()
{
Vector3 vectorRgb = new Vector3(255);
Vector3 vectorY = VectorY * vectorRgb;
Vector3 vectorCb = VectorCb * vectorRgb;
Vector3 vectorCr = VectorCr * vectorRgb;
float yy = vectorY.X + vectorY.Y + vectorY.Z;
float cb = 128 + (vectorCb.X - vectorCb.Y + vectorCb.Z);
float cr = 128 + (vectorCr.X - vectorCr.Y - vectorCr.Z);
return new Vector3(yy, cb, cr);
}
[Benchmark(Description = "Scaled Integer Conversion")]
public Vector3 RgbaToYcbCrScaled()
{
@ -38,9 +57,9 @@
int cr1 = 428 * g; // 0.418688F
int cr2 = 83 * b; // 0.081312F
float yy = ((y0) + (y1) + (y2)) >> 10;
float cb = 128 + ((((cb0) - (cb1) + (cb2))) >> 10);
float cr = 128 + ((((cr0) - (cr1) - (cr2))) >> 10);
float yy = (y0 + y1 + y2) >> 10;
float cb = 128 + ((cb0 - cb1 + cb2) >> 10);
float cr = 128 + ((cr0 - cr1 - cr2) >> 10);
return new Vector3(yy, cb, cr);
}

Loading…
Cancel
Save