Browse Source

Cleanup tests

pull/537/head
Jason Nelson 8 years ago
parent
commit
f3e1e8f42d
  1. 10
      tests/ImageSharp.Tests/Formats/Jpg/AdobeMarkerTests.cs
  2. 18
      tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.CopyToBufferArea.cs
  3. 37
      tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.cs
  4. 23
      tests/ImageSharp.Tests/Formats/Jpg/Block8x8Tests.cs
  5. 28
      tests/ImageSharp.Tests/Formats/Jpg/GenericBlock8x8Tests.cs
  6. 9
      tests/ImageSharp.Tests/Formats/Jpg/JFifMarkerTests.cs
  7. 23
      tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs
  8. 22
      tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs
  9. 23
      tests/ImageSharp.Tests/Formats/Jpg/JpegImagePostProcessorTests.cs
  10. 33
      tests/ImageSharp.Tests/Formats/Jpg/JpegProfilingBenchmarks.cs
  11. 12
      tests/ImageSharp.Tests/Formats/Jpg/LibJpegToolsTests.cs
  12. 21
      tests/ImageSharp.Tests/Formats/Jpg/ParseStreamTests.cs
  13. 10
      tests/ImageSharp.Tests/Formats/Jpg/ProfileResolverTests.cs
  14. 12
      tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.AccurateDCT.cs
  15. 18
      tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.FastFloatingPointDCT.cs
  16. 22
      tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.StandardIntegerDCT.cs
  17. 32
      tests/ImageSharp.Tests/Formats/Jpg/SpectralJpegTests.cs
  18. 36
      tests/ImageSharp.Tests/Formats/Jpg/Utils/JpegFixture.cs
  19. 12
      tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs
  20. 32
      tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.SpectralData.cs
  21. 4
      tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.cs
  22. 12
      tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.AccurateDCT.cs
  23. 4
      tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.GT_FloatingPoint_DCT.cs
  24. 30
      tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.LLM_FloatingPoint_DCT.cs
  25. 8
      tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.StandardIntegerDCT.cs
  26. 11
      tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.cs
  27. 10
      tests/ImageSharp.Tests/Formats/Jpg/Utils/SpanExtensions.cs

10
tests/ImageSharp.Tests/Formats/Jpg/AdobeMarkerTests.cs

@ -1,13 +1,13 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder;
using SixLabors.ImageSharp.Formats.Jpeg.GolangPort;
using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder;
using SixLabors.ImageSharp.Formats.Jpeg.GolangPort;
using Xunit;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
public class AdobeMarkerTests
{
// Taken from actual test image

18
tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.CopyToBufferArea.cs

@ -1,23 +1,19 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
// Uncomment this to turn unit tests into benchmarks:
//#define BENCHMARKING
// ReSharper disable InconsistentNaming
using SixLabors.ImageSharp.Formats.Jpeg.Common;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils;
using SixLabors.Primitives;
using Xunit;
using Xunit.Abstractions;
namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
using SixLabors.ImageSharp.Formats.Jpeg.Common;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils;
using SixLabors.Primitives;
using Xunit;
using Xunit.Abstractions;
public partial class Block8x8FTests : JpegFixture
{
public class CopyToBufferArea : JpegFixture

37
tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.cs

@ -1,24 +1,20 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
// Uncomment this to turn unit tests into benchmarks:
//#define BENCHMARKING
// ReSharper disable InconsistentNaming
using System;
using System.Diagnostics;
namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
using System;
using System.Diagnostics;
using SixLabors.ImageSharp.Formats.Jpeg.Common;
using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils;
using SixLabors.ImageSharp.Formats.Jpeg.Common;
using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils;
using Xunit;
using Xunit.Abstractions;
using Xunit;
using Xunit.Abstractions;
namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
public partial class Block8x8FTests : JpegFixture
{
#if BENCHMARKING
@ -65,7 +61,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
});
Assert.Equal(sum, 64f * 63f * 0.5f);
}
[Fact]
public void Indexer_ReferenceBenchmarkWithArray()
{
@ -207,7 +203,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
sw.Stop();
this.Output.WriteLine($"TranposeInto_PinningImpl_Benchmark finished in {sw.ElapsedMilliseconds} ms");
}
private static float[] Create8x8ColorCropTestData()
{
float[] result = new float[64];
@ -233,7 +229,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
Block8x8F dest = block;
dest.NormalizeColorsInplace();
float[] array = new float[64];
dest.CopyTo(array);
this.Output.WriteLine("Result:");
@ -268,7 +264,6 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
this.CompareBlocks(expected, actual, 0);
}
[Theory]
[InlineData(1)]
[InlineData(2)]
@ -297,7 +292,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
Assert.Equal(expected, actual);
}
}
[Fact]
public void RoundInto()
{
@ -312,7 +307,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
for (int i = 0; i < Block8x8.Size; i++)
{
float expectedFloat = data[i];
short expectedShort = (short) Math.Round(expectedFloat);
short expectedShort = (short)Math.Round(expectedFloat);
short actualShort = dest[i];
Assert.Equal(expectedShort, actualShort);
@ -349,12 +344,12 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
Block8x8F m = CreateRandomFloatBlock(-500, 500, 42);
Block8x8F actual = original;
actual.MultiplyInplace(ref m);
for (int i = 0; i < Block8x8F.Size; i++)
{
Assert.Equal(original[i]*m[i], actual[i]);
Assert.Equal(original[i] * m[i], actual[i]);
}
}
@ -410,7 +405,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
for (int i = 0; i < 64; i++)
{
Assert.Equal(original[i]*42f, actual[i]);
Assert.Equal(original[i] * 42f, actual[i]);
}
}
}

23
tests/ImageSharp.Tests/Formats/Jpg/Block8x8Tests.cs

@ -1,12 +1,14 @@
// ReSharper disable InconsistentNaming
namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
using SixLabors.ImageSharp.Formats.Jpeg.Common;
using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils;
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Formats.Jpeg.Common;
using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils;
using Xunit;
using Xunit.Abstractions;
using Xunit;
using Xunit.Abstractions;
namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
public class Block8x8Tests : JpegFixture
{
public Block8x8Tests(ITestOutputHelper output)
@ -26,11 +28,11 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
Assert.Equal(data[i], block[i]);
}
}
[Fact]
public void Indexer_Set()
{
var block = default(Block8x8);
Block8x8 block = default;
block[17] = 17;
block[42] = 42;
@ -40,7 +42,6 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
Assert.Equal(42, block[42]);
}
[Fact]
public unsafe void Indexer_GetScalarAt_SetScalarAt()
{
@ -117,7 +118,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
[Fact]
public void IndexerXY()
{
var block = default(Block8x8);
Block8x8 block = default;
block[8 * 3 + 5] = 42;
short value = block[5, 3];

28
tests/ImageSharp.Tests/Formats/Jpg/GenericBlock8x8Tests.cs

@ -1,13 +1,15 @@
// ReSharper disable InconsistentNaming
namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
using System;
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.Formats.Jpeg.Common;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Formats.Jpeg.Common;
using SixLabors.ImageSharp.PixelFormats;
using Xunit;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
public class GenericBlock8x8Tests
{
public static Image<TPixel> CreateTestImage<TPixel>()
@ -20,7 +22,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
for (int j = 0; j < 10; j++)
{
var rgba = new Rgba32((byte)(i+1), (byte)(j+1), (byte)200, (byte)255);
var rgba = new Rgba32((byte)(i + 1), (byte)(j + 1), (byte)200, (byte)255);
var color = default(TPixel);
color.PackFromRgba32(rgba);
@ -107,11 +109,11 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
span[i] = new Rgb24((byte)i, (byte)(2 * i), (byte)(3 * i));
}
Rgb24 expected00 = new Rgb24(0, 0, 0);
Rgb24 expected07 = new Rgb24(7, 14, 21);
Rgb24 expected11 = new Rgb24(9, 18, 27);
Rgb24 expected77 = new Rgb24(63, 126, 189);
Rgb24 expected67 = new Rgb24(62, 124, 186);
var expected00 = new Rgb24(0, 0, 0);
var expected07 = new Rgb24(7, 14, 21);
var expected11 = new Rgb24(9, 18, 27);
var expected77 = new Rgb24(63, 126, 189);
var expected67 = new Rgb24(62, 124, 186);
Assert.Equal(expected00, block[0, 0]);
Assert.Equal(expected07, block[7, 0]);

9
tests/ImageSharp.Tests/Formats/Jpg/JFifMarkerTests.cs

@ -1,13 +1,12 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder;
using SixLabors.ImageSharp.Formats.Jpeg.GolangPort;
using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder;
using Xunit;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
public class JFifMarkerTests
{
// Taken from actual test image

23
tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs

@ -1,19 +1,20 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Numerics;
using SixLabors.ImageSharp.ColorSpaces;
using SixLabors.ImageSharp.ColorSpaces.Conversion;
using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder;
using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder.ColorConverters;
using SixLabors.ImageSharp.Memory;
using Xunit;
using Xunit.Abstractions;
// ReSharper disable InconsistentNaming
namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder.ColorConverters;
public class JpegColorConverterTests
{
private const float Precision = 0.1f / 255;
@ -69,7 +70,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
public void FromYCbCrSimd_ConvertCore(int size, int seed)
{
JpegColorConverter.ComponentValues values = CreateRandomValues(3, size, seed);
Vector4[] result = new Vector4[size];
var result = new Vector4[size];
JpegColorConverter.FromYCbCrSimd.ConvertCore(values, result);
@ -134,7 +135,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
int times = 50000;
JpegColorConverter.ComponentValues values = CreateRandomValues(3, count, 1);
Vector4[] result = new Vector4[count];
var result = new Vector4[count];
JpegColorConverter converter = simd ? (JpegColorConverter)new JpegColorConverter.FromYCbCrSimd() : new JpegColorConverter.FromYCbCrBasic();
@ -159,7 +160,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
var converter = JpegColorConverter.GetConverter(JpegColorSpace.Cmyk);
JpegColorConverter.ComponentValues values = CreateRandomValues(4, inputBufferLength, seed);
Vector4[] result = new Vector4[resultBufferLength];
var result = new Vector4[resultBufferLength];
converter.ConvertToRGBA(values, result);
@ -192,7 +193,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
var converter = JpegColorConverter.GetConverter(JpegColorSpace.Grayscale);
JpegColorConverter.ComponentValues values = CreateRandomValues(1, inputBufferLength, seed);
Vector4[] result = new Vector4[resultBufferLength];
var result = new Vector4[resultBufferLength];
converter.ConvertToRGBA(values, result);
@ -214,7 +215,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
var converter = JpegColorConverter.GetConverter(JpegColorSpace.RGB);
JpegColorConverter.ComponentValues values = CreateRandomValues(3, inputBufferLength, seed);
Vector4[] result = new Vector4[resultBufferLength];
var result = new Vector4[resultBufferLength];
converter.ConvertToRGBA(values, result);
@ -241,7 +242,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
var converter = JpegColorConverter.GetConverter(JpegColorSpace.Ycck);
JpegColorConverter.ComponentValues values = CreateRandomValues(4, inputBufferLength, seed);
Vector4[] result = new Vector4[resultBufferLength];
var result = new Vector4[resultBufferLength];
converter.ConvertToRGBA(values, result);
@ -278,7 +279,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
float maxVal = 255f)
{
var rnd = new Random(seed);
Buffer2D<float>[] buffers = new Buffer2D<float>[componentCount];
var buffers = new Buffer2D<float>[componentCount];
for (int i = 0; i < componentCount; i++)
{
float[] values = new float[inputBufferLength];
@ -317,7 +318,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
int seed)
{
JpegColorConverter.ComponentValues values = CreateRandomValues(componentCount, inputBufferLength, seed);
Vector4[] result = new Vector4[resultBufferLength];
var result = new Vector4[resultBufferLength];
converter.ConvertToRGBA(values, result);

22
tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs

@ -1,26 +1,16 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.IO;
using SixLabors.ImageSharp.Formats.Jpeg;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
// ReSharper disable InconsistentNaming
using Xunit;
namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
using System.Collections.Generic;
using System.IO;
using SixLabors.ImageSharp.Formats.Bmp;
using SixLabors.ImageSharp.Formats.Jpeg;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
using SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs;
using SixLabors.Primitives;
using Xunit;
using Xunit.Abstractions;
public class JpegEncoderTests
{
public static readonly TheoryData<JpegSubsample, int> BitsPerPixel_Quality =

23
tests/ImageSharp.Tests/Formats/Jpg/JpegImagePostProcessorTests.cs

@ -1,14 +1,17 @@
namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder;
using SixLabors.ImageSharp.Formats.Jpeg.GolangPort;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils;
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using Xunit;
using Xunit.Abstractions;
using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder;
using SixLabors.ImageSharp.Formats.Jpeg.GolangPort;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils;
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
using Xunit;
using Xunit.Abstractions;
namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
public class JpegImagePostProcessorTests
{
public static string[] BaselineTestJpegs =
@ -100,8 +103,6 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
Assert.True(report.TotalNormalizedDifference.Value < 0.005f);
}
}
}
}
}

33
tests/ImageSharp.Tests/Formats/Jpg/JpegProfilingBenchmarks.cs

@ -1,25 +1,22 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
// ReSharper disable InconsistentNaming
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Formats.Jpeg;
using SixLabors.ImageSharp.Formats.Jpeg.GolangPort;
using SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort;
using SixLabors.ImageSharp.PixelFormats;
using Xunit;
using Xunit.Abstractions;
namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Formats.Jpeg;
using SixLabors.ImageSharp.Formats.Jpeg.GolangPort;
using SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort;
using Xunit;
using Xunit.Abstractions;
public class JpegProfilingBenchmarks : MeasureFixture
{
public JpegProfilingBenchmarks(ITestOutputHelper output)
@ -102,14 +99,14 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
tf => TestImageProvider<Rgba32>.File(tf, pixelTypeOverride: PixelTypes.Rgba32).GetImage())
.ToArray();
using (MemoryStream ms = new MemoryStream())
using (var ms = new MemoryStream())
{
this.Measure(executionCount,
() =>
{
foreach (Image<Rgba32> img in testImages)
{
JpegEncoder options = new JpegEncoder { Quality = quality, Subsample = subsample };
var options = new JpegEncoder { Quality = quality, Subsample = subsample };
img.Save(ms, options);
ms.Seek(0, SeekOrigin.Begin);
}
@ -121,4 +118,4 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
}
}
}
}

12
tests/ImageSharp.Tests/Formats/Jpg/LibJpegToolsTests.cs

@ -1,12 +1,12 @@
namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
using System.IO;
using System.IO;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils;
using Xunit;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
public class LibJpegToolsTests
{
[Fact]

21
tests/ImageSharp.Tests/Formats/Jpg/ParseStreamTests.cs

@ -1,4 +1,7 @@
using System;
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Text;
using SixLabors.ImageSharp.Formats.Jpeg.Common;
using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder;
@ -6,14 +9,12 @@ using SixLabors.ImageSharp.Formats.Jpeg.GolangPort;
using SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder;
using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils;
using SixLabors.Primitives;
using Xunit;
using Xunit.Abstractions;
// ReSharper disable InconsistentNaming
namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
using System.Text;
public class ParseStreamTests
{
private ITestOutputHelper Output { get; }
@ -65,19 +66,19 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
[InlineData(TestImages.Jpeg.Baseline.Cmyk)]
public void PrintComponentData(string imageFile)
{
StringBuilder bld = new StringBuilder();
var sb = new StringBuilder();
using (OrigJpegDecoderCore decoder = JpegFixture.ParseStream(imageFile, true))
{
bld.AppendLine(imageFile);
bld.AppendLine($"Size:{decoder.ImageSizeInPixels} MCU:{decoder.ImageSizeInMCU}");
sb.AppendLine(imageFile);
sb.AppendLine($"Size:{decoder.ImageSizeInPixels} MCU:{decoder.ImageSizeInMCU}");
OrigComponent c0 = decoder.Components[0];
OrigComponent c1 = decoder.Components[1];
bld.AppendLine($"Luma: SAMP: {c0.SamplingFactors} BLOCKS: {c0.SizeInBlocks}");
bld.AppendLine($"Chroma: {c1.SamplingFactors} BLOCKS: {c1.SizeInBlocks}");
sb.AppendLine($"Luma: SAMP: {c0.SamplingFactors} BLOCKS: {c0.SizeInBlocks}");
sb.AppendLine($"Chroma: {c1.SamplingFactors} BLOCKS: {c1.SizeInBlocks}");
}
this.Output.WriteLine(bld.ToString());
this.Output.WriteLine(sb.ToString());
}
public static readonly TheoryData<string, int, object, object> ComponentVerificationData = new TheoryData<string, int, object, object>()

10
tests/ImageSharp.Tests/Formats/Jpg/ProfileResolverTests.cs

@ -1,14 +1,14 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
using System.Text;
using System.Text;
using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder;
using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder;
using Xunit;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
public class ProfileResolverTests
{
private static readonly byte[] JFifMarker = Encoding.ASCII.GetBytes("JFIF\0");

12
tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.AccurateDCT.cs

@ -1,11 +1,11 @@
namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
using SixLabors.ImageSharp.Formats.Jpeg.Common;
using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils;
using SixLabors.ImageSharp.Formats.Jpeg.Common;
using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils;
using Xunit;
using Xunit.Abstractions;
using Xunit;
using Xunit.Abstractions;
namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
public partial class ReferenceImplementationsTests
{
public class AccurateDCT : JpegFixture

18
tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.FastFloatingPointDCT.cs

@ -1,14 +1,15 @@
// ReSharper disable InconsistentNaming
namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
using System;
using SixLabors.ImageSharp.Formats.Jpeg.Common;
using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils;
using System;
using SixLabors.ImageSharp.Formats.Jpeg.Common;
using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils;
using Xunit;
using Xunit.Abstractions;
using Xunit;
using Xunit.Abstractions;
namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
public partial class ReferenceImplementationsTests
{
public class FastFloatingPointDCT : JpegFixture
@ -79,7 +80,6 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
this.CompareBlocks(fExpected, fActual, 2);
}
[Theory]
[InlineData(42)]
[InlineData(1)]
@ -88,7 +88,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
float[] floatData = JpegFixture.Create8x8RandomFloatData(-1000, 1000);
Block8x8F source = default(Block8x8F);
Block8x8F source = default;
source.LoadFrom(floatData);
Block8x8F expected = ReferenceImplementations.AccurateDCT.TransformFDCT(ref source);

22
tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.StandardIntegerDCT.cs

@ -1,14 +1,15 @@
// ReSharper disable InconsistentNaming
namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
using System;
using SixLabors.ImageSharp.Formats.Jpeg.Common;
using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils;
using System;
using Xunit;
using Xunit.Abstractions;
using SixLabors.ImageSharp.Formats.Jpeg.Common;
using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils;
using Xunit;
using Xunit.Abstractions;
namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
public partial class ReferenceImplementationsTests
{
public class StandardIntegerDCT : JpegFixture
@ -26,7 +27,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
int[] data = Create8x8RandomIntData(-range, range, seed);
Block8x8 source = default(Block8x8);
Block8x8 source = default;
source.LoadFrom(data);
Block8x8 expected = ReferenceImplementations.AccurateDCT.TransformIDCT(ref source);
@ -43,7 +44,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
int[] data = Create8x8RandomIntData(-1000, 1000, seed);
Block8x8F source = default(Block8x8F);
Block8x8F source = default;
source.LoadFrom(data);
Block8x8F expected = ReferenceImplementations.AccurateDCT.TransformFDCT(ref source);
@ -53,11 +54,10 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
Block8x8 actual8 = ReferenceImplementations.StandardIntegerDCT.Subtract128_TransformFDCT_Upscale8(ref temp);
Block8x8F actual = actual8.AsFloatBlock();
actual /= 8;
this.CompareBlocks(expected, actual, 1f);
}
[Theory]
[InlineData(42, 0)]
[InlineData(1, 0)]

32
tests/ImageSharp.Tests/Formats/Jpg/SpectralJpegTests.cs

@ -1,19 +1,19 @@
// ReSharper disable InconsistentNaming
namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
using System;
using System.IO;
using System.Linq;
using System;
using System.IO;
using System.Linq;
using SixLabors.ImageSharp.Formats.Jpeg;
using SixLabors.ImageSharp.Formats.Jpeg.GolangPort;
using SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils;
using SixLabors.ImageSharp.Formats.Jpeg;
using SixLabors.ImageSharp.Formats.Jpeg.GolangPort;
using SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils;
using Xunit;
using Xunit.Abstractions;
using Xunit;
using Xunit.Abstractions;
namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
public class SpectralJpegTests
{
public SpectralJpegTests(ITestOutputHelper output)
@ -45,7 +45,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
public void PdfJsDecoder_ParseStream_SaveSpectralResult<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
PdfJsJpegDecoderCore decoder = new PdfJsJpegDecoderCore(Configuration.Default, new JpegDecoder());
var decoder = new PdfJsJpegDecoderCore(Configuration.Default, new JpegDecoder());
byte[] sourceBytes = TestFile.Create(provider.SourceFileOrDescription).Bytes;
@ -63,7 +63,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
public void OriginalDecoder_ParseStream_SaveSpectralResult<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
OrigJpegDecoderCore decoder = new OrigJpegDecoderCore(Configuration.Default, new JpegDecoder());
var decoder = new OrigJpegDecoderCore(Configuration.Default, new JpegDecoder());
byte[] sourceBytes = TestFile.Create(provider.SourceFileOrDescription).Bytes;
@ -130,7 +130,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
return;
}
PdfJsJpegDecoderCore decoder = new PdfJsJpegDecoderCore(Configuration.Default, new JpegDecoder());
var decoder = new PdfJsJpegDecoderCore(Configuration.Default, new JpegDecoder());
byte[] sourceBytes = TestFile.Create(provider.SourceFileOrDescription).Bytes;
@ -153,7 +153,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
return;
}
OrigJpegDecoderCore decoder = new OrigJpegDecoderCore(Configuration.Default, new JpegDecoder());
var decoder = new OrigJpegDecoderCore(Configuration.Default, new JpegDecoder());
byte[] sourceBytes = TestFile.Create(provider.SourceFileOrDescription).Bytes;

36
tests/ImageSharp.Tests/Formats/Jpg/Utils/JpegFixture.cs

@ -1,24 +1,22 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
// ReSharper disable InconsistentNaming
namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
{
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using SixLabors.ImageSharp.Formats.Jpeg;
using SixLabors.ImageSharp.Formats.Jpeg.Common;
using SixLabors.ImageSharp.Formats.Jpeg.GolangPort;
using SixLabors.ImageSharp.Formats.Jpeg;
using SixLabors.ImageSharp.Formats.Jpeg.Common;
using SixLabors.ImageSharp.Formats.Jpeg.GolangPort;
using Xunit;
using Xunit.Abstractions;
using Xunit;
using Xunit.Abstractions;
namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
{
public class JpegFixture : MeasureFixture
{
public JpegFixture(ITestOutputHelper output) : base(output)
@ -70,7 +68,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
// ReSharper disable once InconsistentNaming
public static int[] Create8x8RandomIntData(int minValue, int maxValue, int seed = 42)
{
Random rnd = new Random(seed);
var rnd = new Random(seed);
int[] result = new int[64];
for (int i = 0; i < 8; i++)
{
@ -87,7 +85,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
public static float[] Create8x8RandomFloatData(float minValue, float maxValue, int seed = 42)
{
Random rnd = new Random(seed);
var rnd = new Random(seed);
float[] result = new float[64];
for (int i = 0; i < 8; i++)
{
@ -132,12 +130,12 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
{
if (count < 0) count = data.Length;
StringBuilder bld = new StringBuilder();
var sb = new StringBuilder();
for (int i = 0; i < count; i++)
{
bld.Append($"{data[i],3} ");
sb.Append($"{data[i],3} ");
}
this.Output.WriteLine(bld.ToString());
this.Output.WriteLine(sb.ToString());
}
protected void Print(string msg)
@ -154,7 +152,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
internal void CompareBlocks(Span<float> a, Span<float> b, float tolerance)
{
ApproximateFloatComparer comparer = new ApproximateFloatComparer(tolerance);
var comparer = new ApproximateFloatComparer(tolerance);
double totalDifference = 0.0;
bool failed = false;

12
tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs

@ -99,7 +99,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
public Image<Rgba32> CreateGrayScaleImage()
{
Image<Rgba32> result = new Image<Rgba32>(this.WidthInBlocks * 8, this.HeightInBlocks * 8);
var result = new Image<Rgba32>(this.WidthInBlocks * 8, this.HeightInBlocks * 8);
for (int by = 0; by < this.HeightInBlocks; by++)
{
@ -119,10 +119,10 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
{
for (int x = 0; x < 8; x++)
{
var val = this.GetBlockValue(block, x, y);
float val = this.GetBlockValue(block, x, y);
Vector4 v = new Vector4(val, val, val, 1);
Rgba32 color = default(Rgba32);
var v = new Vector4(val, val, val, 1);
Rgba32 color = default;
color.PackFromVector4(v);
int yy = by * 8 + y;
@ -143,8 +143,8 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
public bool Equals(ComponentData other)
{
if (Object.ReferenceEquals(null, other)) return false;
if (Object.ReferenceEquals(this, other)) return true;
if (object.ReferenceEquals(null, other)) return false;
if (object.ReferenceEquals(this, other)) return true;
bool ok = this.Index == other.Index && this.HeightInBlocks == other.HeightInBlocks
&& this.WidthInBlocks == other.WidthInBlocks;
//&& this.MinVal == other.MinVal

32
tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.SpectralData.cs

@ -1,16 +1,16 @@
using System;
using System.Linq;
using System.Numerics;
using SixLabors.ImageSharp.Formats.Jpeg.Common;
using SixLabors.ImageSharp.Formats.Jpeg.GolangPort;
using SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder;
using SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort;
using SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
{
using System;
using System.Linq;
using System.Numerics;
using SixLabors.ImageSharp.Formats.Jpeg.Common;
using SixLabors.ImageSharp.Formats.Jpeg.GolangPort;
using SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder;
using SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort;
using SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components;
internal static partial class LibJpegTools
{
@ -58,7 +58,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
return null;
}
Image<Rgba32> result = new Image<Rgba32>(c0.WidthInBlocks * 8, c0.HeightInBlocks * 8);
var result = new Image<Rgba32>(c0.WidthInBlocks * 8, c0.HeightInBlocks * 8);
for (int by = 0; by < c0.HeightInBlocks; by++)
{
@ -92,8 +92,8 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
float val1 = c0.GetBlockValue(block1, x, y);
float val2 = c0.GetBlockValue(block2, x, y);
Vector4 v = new Vector4(val0, val1, val2, 1);
Rgba32 color = default(Rgba32);
var v = new Vector4(val0, val1, val2, 1);
Rgba32 color = default;
color.PackFromVector4(v);
int yy = by * 8 + y;
@ -105,8 +105,8 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
public bool Equals(SpectralData other)
{
if (Object.ReferenceEquals(null, other)) return false;
if (Object.ReferenceEquals(this, other)) return true;
if (object.ReferenceEquals(null, other)) return false;
if (object.ReferenceEquals(this, other)) return true;
if (this.ComponentCount != other.ComponentCount)
{
return false;
@ -123,8 +123,8 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
public override bool Equals(object obj)
{
if (Object.ReferenceEquals(null, obj)) return false;
if (Object.ReferenceEquals(this, obj)) return true;
if (object.ReferenceEquals(null, obj)) return false;
if (object.ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return this.Equals((SpectralData)obj);
}

4
tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.cs

@ -4,10 +4,10 @@ using System.Diagnostics;
using System.IO;
using System.Numerics;
using SixLabors.ImageSharp.Formats.Jpeg.Common;
namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
{
using SixLabors.ImageSharp.Formats.Jpeg.Common;
/// <summary>
/// Utilities to read raw libjpeg data for reference conversion.
/// </summary>

12
tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.AccurateDCT.cs

@ -1,9 +1,9 @@
namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
{
using System;
using System;
using SixLabors.ImageSharp.Formats.Jpeg.Common;
using SixLabors.ImageSharp.Formats.Jpeg.Common;
namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
{
internal static partial class ReferenceImplementations
{
/// <summary>
@ -54,7 +54,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
{
int x, y, u, v;
double tmp, tmp2;
Block8x8F res = default(Block8x8F);
Block8x8F res = default;
for (y=0; y<8; y++) {
for (x=0; x<8; x++) {
@ -76,7 +76,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
{
int x, y, u, v;
double tmp, tmp2;
Block8x8F res = default(Block8x8F);
Block8x8F res = default;
for (v = 0; v < 8; v++)
{

4
tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.GT_FloatingPoint_DCT.cs

@ -1,9 +1,9 @@
// ReSharper disable InconsistentNaming
using System;
namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
{
using System;
internal static partial class ReferenceImplementations
{
/// <summary>

30
tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.LLM_FloatingPoint_DCT.cs

@ -1,14 +1,14 @@
// ReSharper disable InconsistentNaming
namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
{
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats.Jpeg.Common;
using SixLabors.ImageSharp.Formats.Jpeg.Common;
using Xunit.Abstractions;
using Xunit.Abstractions;
namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
{
internal static partial class ReferenceImplementations
{
/// <summary>
@ -35,7 +35,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
float[] temp = new float[64];
iDCT2D_llm(s, d, temp);
Block8x8F result = default(Block8x8F);
Block8x8F result = default;
result.LoadFrom(d);
return result;
}
@ -48,12 +48,12 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
float[] temp = new float[64];
fDCT2D_llm(s, d, temp);
Block8x8F result = default(Block8x8F);
Block8x8F result = default;
result.LoadFrom(d);
return result;
}
private static double cos(double x) => Math.Cos(x);
private static double Cos(double x) => Math.Cos(x);
private const double M_PI = Math.PI;
@ -64,7 +64,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
float[] r = new float[8];
for (int i = 0; i < 8; i++)
{
r[i] = (float)(cos((double)i / 16.0 * M_PI) * M_SQRT2);
r[i] = (float)(Cos((double)i / 16.0 * M_PI) * M_SQRT2);
output?.WriteLine($"float r{i} = {r[i]:R}f;");
}
return r;
@ -214,8 +214,8 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
/*y[0] = c0 + c1;
y[4] = c0 - c1;*/
Vector4 w0 = new Vector4(0.541196f);
Vector4 w1 = new Vector4(1.306563f);
var w0 = new Vector4(0.541196f);
var w1 = new Vector4(1.306563f);
_mm_store_ps(d, 16, ((w0 * c2) + (w1 * c3)));
@ -248,7 +248,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
_mm_store_ps(d, 40, (c3 - c1));
//y[5] = c3 - c1; y[3] = c0 - c2;
Vector4 invsqrt2 = new Vector4(0.707107f);
var invsqrt2 = new Vector4(0.707107f);
c0 = ((c0 + c2) * invsqrt2);
c3 = ((c3 + c1) * invsqrt2);
//c0 = (c0 + c2) * invsqrt2;
@ -279,7 +279,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
fDCT2D8x4_32f(temp.Slice(4), d.Slice(4));
Vector4 c = new Vector4(0.1250f);
var c = new Vector4(0.1250f);
_mm_store_ps(d, 0, (_mm_load_ps(d, 0) * c)); d = d.Slice(4);//0
_mm_store_ps(d, 0, (_mm_load_ps(d, 0) * c)); d = d.Slice(4);//1

8
tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.StandardIntegerDCT.cs

@ -1,10 +1,10 @@
// ReSharper disable InconsistentNaming
namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
{
using System;
using System;
using SixLabors.ImageSharp.Formats.Jpeg.Common;
using SixLabors.ImageSharp.Formats.Jpeg.Common;
namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
{
internal static partial class ReferenceImplementations
{
/// <summary>

11
tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.cs

@ -1,18 +1,15 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
// ReSharper disable InconsistentNaming
using System;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats.Jpeg.Common;
namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
{
using System;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats.Jpeg.Common;
/// <summary>
/// This class contains simplified (unefficient) reference implementations to produce verification data for unit tests
/// Floating point DCT code Ported from https://github.com/norishigefukushima/dct_simd

10
tests/ImageSharp.Tests/Formats/Jpg/Utils/SpanExtensions.cs

@ -1,12 +1,12 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
{
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
/// <summary>
/// Span Extensions
/// </summary>
@ -118,4 +118,4 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
return result;
}
}
}
}
Loading…
Cancel
Save