diff --git a/src/ImageSharp/Formats/Jpg/Components/Block8x8F.cs b/src/ImageSharp/Formats/Jpg/Components/Block8x8F.cs index cd8f17a2c..73d71b282 100644 --- a/src/ImageSharp/Formats/Jpg/Components/Block8x8F.cs +++ b/src/ImageSharp/Formats/Jpg/Components/Block8x8F.cs @@ -133,50 +133,7 @@ namespace ImageSharp.Formats } } - - /// - /// Reference implementation we can benchmark against - /// - internal unsafe void TransposeInto_PinningImpl(ref Block8x8F destination) - { - fixed (Vector4* sPtr = &V0L) - { - float* src = (float*) sPtr; - - fixed (Vector4* dPtr = &destination.V0L) - { - float* dest = (float*) dPtr; - - for (int i = 0; i < 8; i++) - { - int i8 = i*8; - for (int j = 0; j < 8; j++) - { - dest[j*8 + i] = src[i8 + j]; - } - } - } - } - } - - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static unsafe void TransposeInto(Block8x8F* sourcePtr, Block8x8F* destPtr) - { - float* src = (float*) sourcePtr; - float* dest = (float*) destPtr; - - for (int i = 0; i < 8; i++) - { - int i8 = i*8; - for (int j = 0; j < 8; j++) - { - dest[j*8 + i] = src[i8 + j]; - } - } - } - + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void MultiplyAllInplace(Vector4 s) { @@ -449,30 +406,7 @@ namespace ImageSharp.Formats for(i = 0;i < 8;i++){ x[i] *= 0.353554f; } */ } - - internal static void SuchIDCT(ref Block block) - { - Block8x8F source = new Block8x8F(); - source.LoadFrom(block.Data); - - Block8x8F dest = new Block8x8F(); - Block8x8F temp = new Block8x8F(); - - source.IDCTInto(ref dest, ref temp); - dest.CopyTo(block.Data); - } - - internal static void SuchIDCT(ref BlockF block) - { - Block8x8F source = new Block8x8F(); - source.LoadFrom(block.Data); - - Block8x8F dest = new Block8x8F(); - Block8x8F temp = new Block8x8F(); - - source.IDCTInto(ref dest, ref temp); - dest.CopyTo(block.Data); - } + public unsafe float this[int idx] { @@ -525,62 +459,6 @@ namespace ImageSharp.Formats { CopyTo(legacyBlock.Data); } - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static byte ToColorByte(float c) - { - if (c < -128) - { - return 0; - } - else if (c > 127) - { - return 255; - } - else - { - c += 128; - return (byte) c; - } - } - - - - internal unsafe void CopyColorsTo(MutableSpan buffer, int stride) - { - fixed (Block8x8F* p = &this) - { - float* b = (float*) p; - - for (int y = 0; y < 8; y++) - { - int y8 = y*8; - int yStride = y*stride; - - for (int x = 0; x < 8; x++) - { - float c = b[y8 + x]; - - if (c < -128) - { - c = 0; - } - else if (c > 127) - { - c = 255; - } - else - { - c += 128; - } - - buffer[yStride + x] = (byte) c; - } - } - } - - } private static readonly Vector4 CMin4 = new Vector4(-128f); private static readonly Vector4 CMax4 = new Vector4(127f); diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.cs index 07b926f08..25d7af828 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.cs @@ -171,24 +171,7 @@ namespace ImageSharp.Tests.Formats.Jpg Assert.Equal(expected, actual); } - - [Fact] - public void TranposeInto_PinningImpl() - { - float[] expected = Create8x8FloatData(); - ReferenceImplementations.Transpose8x8(expected); - - Block8x8F source = new Block8x8F(); - source.LoadFrom(Create8x8FloatData()); - - Block8x8F dest = new Block8x8F(); - source.TransposeInto_PinningImpl(ref dest); - - float[] actual = new float[64]; - dest.CopyTo(actual); - - Assert.Equal(expected, actual); - } + [Fact] public void TransposeInto() @@ -209,27 +192,6 @@ namespace ImageSharp.Tests.Formats.Jpg } - [Fact] - public unsafe void TransposeInto_WithPointers() - { - float[] expected = Create8x8FloatData(); - ReferenceImplementations.Transpose8x8(expected); - - Block8x8F source = new Block8x8F(); - source.LoadFrom(Create8x8FloatData()); - - Block8x8F dest = new Block8x8F(); - - Block8x8F* sPtr = &source; - Block8x8F* dPtr = &dest; - - Block8x8F.TransposeInto(sPtr, dPtr); - - float[] actual = new float[64]; - dest.CopyTo(actual); - - Assert.Equal(expected, actual); - } private class BufferHolder { @@ -255,53 +217,7 @@ namespace ImageSharp.Tests.Formats.Jpg Output.WriteLine($"TranposeInto_PinningImpl_Benchmark finished in {sw.ElapsedMilliseconds} ms"); } - - [Fact] - public void TranposeInto_PinningImpl_Benchmark() - { - BufferHolder source = new BufferHolder(); - source.Buffer.LoadFrom(Create8x8FloatData()); - BufferHolder dest = new BufferHolder(); - - Output.WriteLine($"TranposeInto_PinningImpl_Benchmark X {Times} ..."); - Stopwatch sw = Stopwatch.StartNew(); - - for (int i = 0; i < Times; i++) - { - source.Buffer.TransposeInto_PinningImpl(ref dest.Buffer); - } - - sw.Stop(); - Output.WriteLine($"TranposeInto_PinningImpl_Benchmark finished in {sw.ElapsedMilliseconds} ms"); - } - - [Fact] - public unsafe void TransposeInto_WithPointers_Benchmark() - { - BufferHolder source = new BufferHolder(); - source.Buffer.LoadFrom(Create8x8FloatData()); - BufferHolder dest = new BufferHolder(); - - fixed (Block8x8F* sPtr = &source.Buffer) - { - fixed (Block8x8F* dPtr = &dest.Buffer) - { - Output.WriteLine($"TransposeInto_WithPointers_Benchmark X {Times} ..."); - Stopwatch sw = Stopwatch.StartNew(); - - for (int i = 0; i < Times; i++) - { - Block8x8F.TransposeInto(sPtr, dPtr); - } - - sw.Stop(); - Output.WriteLine($"TransposeInto_WithPointers_Benchmark finished in {sw.ElapsedMilliseconds} ms"); - } - } - - } - - + [Fact] public void iDCT2D8x4_LeftPart() {