Browse Source

Merge branch 'master' into issue-532

af/merge-core
James Jackson-South 8 years ago
committed by GitHub
parent
commit
607119057c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 23
      src/ImageSharp/Formats/Jpeg/Common/Decoder/ProfileResolver.cs
  2. 7
      src/ImageSharp/Formats/Jpeg/IJpegDecoderOptions.cs
  3. 7
      src/ImageSharp/Formats/Jpeg/IJpegEncoderOptions.cs
  4. 2
      src/ImageSharp/Formats/Jpeg/ImageExtensions.cs
  5. 2
      src/ImageSharp/Formats/Jpeg/JpegConfigurationModule.cs
  6. 55
      src/ImageSharp/Formats/Jpeg/JpegImageFormatDetector.cs
  7. 1
      src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs
  8. 22
      src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTable.cs
  9. 5
      src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTables.cs
  10. 18
      src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs
  11. 10
      tests/ImageSharp.Tests/Formats/Jpg/AdobeMarkerTests.cs
  12. 18
      tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.CopyToBufferArea.cs
  13. 37
      tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.cs
  14. 23
      tests/ImageSharp.Tests/Formats/Jpg/Block8x8Tests.cs
  15. 28
      tests/ImageSharp.Tests/Formats/Jpg/GenericBlock8x8Tests.cs
  16. 9
      tests/ImageSharp.Tests/Formats/Jpg/JFifMarkerTests.cs
  17. 23
      tests/ImageSharp.Tests/Formats/Jpg/JpegColorConverterTests.cs
  18. 22
      tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs
  19. 23
      tests/ImageSharp.Tests/Formats/Jpg/JpegImagePostProcessorTests.cs
  20. 33
      tests/ImageSharp.Tests/Formats/Jpg/JpegProfilingBenchmarks.cs
  21. 12
      tests/ImageSharp.Tests/Formats/Jpg/LibJpegToolsTests.cs
  22. 21
      tests/ImageSharp.Tests/Formats/Jpg/ParseStreamTests.cs
  23. 10
      tests/ImageSharp.Tests/Formats/Jpg/ProfileResolverTests.cs
  24. 12
      tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.AccurateDCT.cs
  25. 18
      tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.FastFloatingPointDCT.cs
  26. 22
      tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementationsTests.StandardIntegerDCT.cs
  27. 32
      tests/ImageSharp.Tests/Formats/Jpg/SpectralJpegTests.cs
  28. 36
      tests/ImageSharp.Tests/Formats/Jpg/Utils/JpegFixture.cs
  29. 12
      tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs
  30. 32
      tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.SpectralData.cs
  31. 4
      tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.cs
  32. 12
      tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.AccurateDCT.cs
  33. 4
      tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.GT_FloatingPoint_DCT.cs
  34. 30
      tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.LLM_FloatingPoint_DCT.cs
  35. 8
      tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.StandardIntegerDCT.cs
  36. 11
      tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.cs
  37. 10
      tests/ImageSharp.Tests/Formats/Jpg/Utils/SpanExtensions.cs

23
src/ImageSharp/Formats/Jpeg/Common/Decoder/ProfileResolver.cs

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System; using System;
using System.Text;
namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder
{ {
@ -13,22 +14,22 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder
/// <summary> /// <summary>
/// Describes the EXIF specific markers /// Describes the EXIF specific markers
/// </summary> /// </summary>
public static readonly byte[] JFifMarker = ToAsciiBytes("JFIF\0"); public static readonly byte[] JFifMarker = Encoding.UTF8.GetBytes("JFIF\0");
/// <summary> /// <summary>
/// Describes the EXIF specific markers /// Describes the EXIF specific markers
/// </summary> /// </summary>
public static readonly byte[] IccMarker = ToAsciiBytes("ICC_PROFILE\0"); public static readonly byte[] IccMarker = Encoding.UTF8.GetBytes("ICC_PROFILE\0");
/// <summary> /// <summary>
/// Describes the ICC specific markers /// Describes the ICC specific markers
/// </summary> /// </summary>
public static readonly byte[] ExifMarker = ToAsciiBytes("Exif\0\0"); public static readonly byte[] ExifMarker = Encoding.UTF8.GetBytes("Exif\0\0");
/// <summary> /// <summary>
/// Describes Adobe specific markers <see href="http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/JPEG.html#Adobe"/> /// Describes Adobe specific markers <see href="http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/JPEG.html#Adobe"/>
/// </summary> /// </summary>
public static readonly byte[] AdobeMarker = ToAsciiBytes("Adobe"); public static readonly byte[] AdobeMarker = Encoding.UTF8.GetBytes("Adobe");
/// <summary> /// <summary>
/// Returns a value indicating whether the passed bytes are a match to the profile identifer /// Returns a value indicating whether the passed bytes are a match to the profile identifer
@ -41,19 +42,5 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder
return bytesToCheck.Length >= profileIdentifier.Length return bytesToCheck.Length >= profileIdentifier.Length
&& bytesToCheck.Slice(0, profileIdentifier.Length).SequenceEqual(profileIdentifier); && bytesToCheck.Slice(0, profileIdentifier.Length).SequenceEqual(profileIdentifier);
} }
// No Encoding.ASCII nor Linq.Select on NetStandard 1.1
private static byte[] ToAsciiBytes(string str)
{
int length = str.Length;
byte[] bytes = new byte[length];
char[] chars = str.ToCharArray();
for (int i = 0; i < length; i++)
{
bytes[i] = (byte)chars[i];
}
return bytes;
}
} }
} }

7
src/ImageSharp/Formats/Jpeg/IJpegDecoderOptions.cs

@ -1,11 +1,6 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System;
using System.Collections.Generic;
using System.IO;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Formats.Jpeg namespace SixLabors.ImageSharp.Formats.Jpeg
{ {
/// <summary> /// <summary>
@ -18,4 +13,4 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
/// </summary> /// </summary>
bool IgnoreMetadata { get; } bool IgnoreMetadata { get; }
} }
} }

7
src/ImageSharp/Formats/Jpeg/IJpegEncoderOptions.cs

@ -1,11 +1,6 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System;
using System.Collections.Generic;
using System.IO;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Formats.Jpeg namespace SixLabors.ImageSharp.Formats.Jpeg
{ {
/// <summary> /// <summary>
@ -31,4 +26,4 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
/// <value>The subsample ratio of the jpg image.</value> /// <value>The subsample ratio of the jpg image.</value>
JpegSubsample? Subsample { get; } JpegSubsample? Subsample { get; }
} }
} }

2
src/ImageSharp/Formats/Jpeg/ImageExtensions.cs

@ -1,10 +1,8 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System;
using System.IO; using System.IO;
using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Formats.Jpeg; using SixLabors.ImageSharp.Formats.Jpeg;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;

2
src/ImageSharp/Formats/Jpeg/JpegConfigurationModule.cs

@ -17,4 +17,4 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
config.ImageFormatsManager.AddImageFormatDetector(new JpegImageFormatDetector()); config.ImageFormatsManager.AddImageFormatDetector(new JpegImageFormatDetector());
} }
} }
} }

55
src/ImageSharp/Formats/Jpeg/JpegImageFormatDetector.cs

@ -16,12 +16,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
/// <inheritdoc/> /// <inheritdoc/>
public IImageFormat DetectFormat(ReadOnlySpan<byte> header) public IImageFormat DetectFormat(ReadOnlySpan<byte> header)
{ {
if (this.IsSupportedFileFormat(header)) return this.IsSupportedFileFormat(header) ? ImageFormats.Jpeg : null;
{
return ImageFormats.Jpeg;
}
return null;
} }
private bool IsSupportedFileFormat(ReadOnlySpan<byte> header) private bool IsSupportedFileFormat(ReadOnlySpan<byte> header)
@ -35,36 +30,24 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
/// </summary> /// </summary>
/// <param name="header">The bytes representing the file header.</param> /// <param name="header">The bytes representing the file header.</param>
/// <returns>The <see cref="bool"/></returns> /// <returns>The <see cref="bool"/></returns>
private bool IsJfif(ReadOnlySpan<byte> header) private bool IsJfif(ReadOnlySpan<byte> header) =>
{ header[6] == 0x4A && // J
// TODO: This should be in constants header[7] == 0x46 && // F
bool isJfif = header[8] == 0x49 && // I
header[6] == 0x4A && // J header[9] == 0x46 && // F
header[7] == 0x46 && // F header[10] == 0x00;
header[8] == 0x49 && // I
header[9] == 0x46 && // F
header[10] == 0x00;
return isJfif;
}
/// <summary> /// <summary>
/// Returns a value indicating whether the given bytes identify EXIF data. /// Returns a value indicating whether the given bytes identify EXIF data.
/// </summary> /// </summary>
/// <param name="header">The bytes representing the file header.</param> /// <param name="header">The bytes representing the file header.</param>
/// <returns>The <see cref="bool"/></returns> /// <returns>The <see cref="bool"/></returns>
private bool IsExif(ReadOnlySpan<byte> header) private bool IsExif(ReadOnlySpan<byte> header) =>
{ header[6] == 0x45 && // E
// TODO: This should be in constants header[7] == 0x78 && // X
bool isExif = header[8] == 0x69 && // I
header[6] == 0x45 && // E header[9] == 0x66 && // F
header[7] == 0x78 && // X header[10] == 0x00;
header[8] == 0x69 && // I
header[9] == 0x66 && // F
header[10] == 0x00;
return isExif;
}
/// <summary> /// <summary>
/// Returns a value indicating whether the given bytes identify Jpeg data. /// Returns a value indicating whether the given bytes identify Jpeg data.
@ -72,14 +55,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
/// </summary> /// </summary>
/// <param name="header">The bytes representing the file header.</param> /// <param name="header">The bytes representing the file header.</param>
/// <returns>The <see cref="bool"/></returns> /// <returns>The <see cref="bool"/></returns>
private bool IsJpeg(ReadOnlySpan<byte> header) private bool IsJpeg(ReadOnlySpan<byte> header) =>
{ header[0] == 0xFF && // 255
// TODO: This should be in constants header[1] == 0xD8; // 216
bool isJpg =
header[0] == 0xFF && // 255
header[1] == 0xD8; // 216
return isJpg;
}
} }
} }

1
src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs

@ -17,7 +17,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
internal class PdfJsFrameComponent : IDisposable, IJpegComponent internal class PdfJsFrameComponent : IDisposable, IJpegComponent
{ {
private readonly MemoryManager memoryManager; private readonly MemoryManager memoryManager;
#pragma warning disable SA1401 // Fields should be private
public PdfJsFrameComponent(MemoryManager memoryManager, PdfJsFrame frame, byte id, int horizontalFactor, int verticalFactor, byte quantizationTableIndex, int index) public PdfJsFrameComponent(MemoryManager memoryManager, PdfJsFrame frame, byte id, int horizontalFactor, int verticalFactor, byte quantizationTableIndex, int index)
{ {

22
src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTable.cs

@ -40,7 +40,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
/// <param name="memoryManager">The <see cref="MemoryManager"/> to use for buffer allocations.</param> /// <param name="memoryManager">The <see cref="MemoryManager"/> to use for buffer allocations.</param>
/// <param name="lengths">The code lengths</param> /// <param name="lengths">The code lengths</param>
/// <param name="values">The huffman values</param> /// <param name="values">The huffman values</param>
public PdfJsHuffmanTable(MemoryManager memoryManager, byte[] lengths, byte[] values) public PdfJsHuffmanTable(MemoryManager memoryManager, ReadOnlySpan<byte> lengths, ReadOnlySpan<byte> values)
{ {
const int length = 257; const int length = 257;
using (IBuffer<short> huffsize = memoryManager.Allocate<short>(length)) using (IBuffer<short> huffsize = memoryManager.Allocate<short>(length))
@ -57,10 +57,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
fixed (byte* huffValRef = this.HuffVal.Data) fixed (byte* huffValRef = this.HuffVal.Data)
{ {
for (int i = 0; i < values.Length; i++) var huffValSpan = new Span<byte>(huffValRef, 256);
{
huffValRef[i] = values[i]; values.CopyTo(huffValSpan);
}
} }
} }
@ -69,7 +68,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
/// </summary> /// </summary>
/// <param name="lengths">The code lengths</param> /// <param name="lengths">The code lengths</param>
/// <param name="huffsizeRef">The huffman size span ref</param> /// <param name="huffsizeRef">The huffman size span ref</param>
private static void GenerateSizeTable(byte[] lengths, ref short huffsizeRef) private static void GenerateSizeTable(ReadOnlySpan<byte> lengths, ref short huffsizeRef)
{ {
short index = 0; short index = 0;
for (short l = 1; l <= 16; l++) for (short l = 1; l <= 16; l++)
@ -115,7 +114,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
/// </summary> /// </summary>
/// <param name="lengths">The code lengths</param> /// <param name="lengths">The code lengths</param>
/// <param name="huffcodeRef">The huffman code span ref</param> /// <param name="huffcodeRef">The huffman code span ref</param>
private void GenerateDecoderTables(byte[] lengths, ref short huffcodeRef) private void GenerateDecoderTables(ReadOnlySpan<byte> lengths, ref short huffcodeRef)
{ {
fixed (short* valOffsetRef = this.ValOffset.Data) fixed (short* valOffsetRef = this.ValOffset.Data)
fixed (long* maxcodeRef = this.MaxCode.Data) fixed (long* maxcodeRef = this.MaxCode.Data)
@ -147,7 +146,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
/// <param name="lengths">The code lengths</param> /// <param name="lengths">The code lengths</param>
/// <param name="huffval">The huffman value array</param> /// <param name="huffval">The huffman value array</param>
/// <param name="huffcodeRef">The huffman code span ref</param> /// <param name="huffcodeRef">The huffman code span ref</param>
private void GenerateLookaheadTables(byte[] lengths, byte[] huffval, ref short huffcodeRef) private void GenerateLookaheadTables(ReadOnlySpan<byte> lengths, ReadOnlySpan<byte> huffval, ref short huffcodeRef)
{ {
// TODO: This generation code matches the libJpeg code but the lookahead table is not actually used yet. // TODO: This generation code matches the libJpeg code but the lookahead table is not actually used yet.
// To use it we need to implement fast lookup path in PdfJsScanDecoder.DecodeHuffman // To use it we need to implement fast lookup path in PdfJsScanDecoder.DecodeHuffman
@ -155,10 +154,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
// will be 8 or fewer bits long and can be handled without looping. // will be 8 or fewer bits long and can be handled without looping.
fixed (short* lookaheadRef = this.Lookahead.Data) fixed (short* lookaheadRef = this.Lookahead.Data)
{ {
for (int i = 0; i < 256; i++) var lookaheadSpan = new Span<short>(lookaheadRef, 256);
{
lookaheadRef[i] = 2034; // 9 << 8; lookaheadSpan.Fill(2034); // 9 << 8;
}
int p = 0; int p = 0;
for (int l = 1; l <= 8; l++) for (int l = 1; l <= 8; l++)

5
src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTables.cs

@ -21,10 +21,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
public ref PdfJsHuffmanTable this[int index] public ref PdfJsHuffmanTable this[int index]
{ {
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
get get => ref this.tables[index];
{
return ref this.tables[index];
}
} }
} }
} }

18
src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs

@ -7,7 +7,6 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Formats.Jpeg.Common; using SixLabors.ImageSharp.Formats.Jpeg.Common;
using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder; using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder;
using SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components; using SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components;
@ -367,14 +366,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort
if (this.ComponentCount == 4) if (this.ComponentCount == 4)
{ {
if (this.adobe.ColorTransform == PdfJsJpegConstants.Markers.Adobe.ColorTransformYcck) return this.adobe.ColorTransform == PdfJsJpegConstants.Markers.Adobe.ColorTransformYcck
{ ? JpegColorSpace.Ycck
return JpegColorSpace.Ycck; : JpegColorSpace.Cmyk;
}
else
{
return JpegColorSpace.Cmyk;
}
} }
throw new ImageFormatException($"Unsupported color mode. Max components 4; found {this.ComponentCount}"); throw new ImageFormatException($"Unsupported color mode. Max components 4; found {this.ComponentCount}");
@ -700,8 +694,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort
this.BuildHuffmanTable( this.BuildHuffmanTable(
huffmanTableSpec >> 4 == 0 ? this.dcHuffmanTables : this.acHuffmanTables, huffmanTableSpec >> 4 == 0 ? this.dcHuffmanTables : this.acHuffmanTables,
huffmanTableSpec & 15, huffmanTableSpec & 15,
codeLengths.Array, codeLengths.Span,
huffmanValues.Array); huffmanValues.Span);
} }
} }
} }
@ -785,7 +779,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort
/// <param name="codeLengths">The codelengths</param> /// <param name="codeLengths">The codelengths</param>
/// <param name="values">The values</param> /// <param name="values">The values</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
private void BuildHuffmanTable(PdfJsHuffmanTables tables, int index, byte[] codeLengths, byte[] values) private void BuildHuffmanTable(PdfJsHuffmanTables tables, int index, ReadOnlySpan<byte> codeLengths, ReadOnlySpan<byte> values)
{ {
tables[index] = new PdfJsHuffmanTable(this.configuration.MemoryManager, codeLengths, values); tables[index] = new PdfJsHuffmanTable(this.configuration.MemoryManager, codeLengths, values);
} }

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

@ -1,13 +1,13 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // 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 public class AdobeMarkerTests
{ {
// Taken from actual test image // Taken from actual test image

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

@ -1,23 +1,19 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// Uncomment this to turn unit tests into benchmarks: // Uncomment this to turn unit tests into benchmarks:
//#define BENCHMARKING //#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 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 partial class Block8x8FTests : JpegFixture
{ {
public class CopyToBufferArea : JpegFixture public class CopyToBufferArea : JpegFixture

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

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

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

@ -1,13 +1,15 @@
// ReSharper disable InconsistentNaming // Copyright (c) Six Labors and contributors.
namespace SixLabors.ImageSharp.Tests.Formats.Jpg // Licensed under the Apache License, Version 2.0.
{
using System; using System;
using SixLabors.ImageSharp.Formats.Jpeg.Common; using SixLabors.ImageSharp.Formats.Jpeg.Common;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using Xunit; using Xunit;
namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
public class GenericBlock8x8Tests public class GenericBlock8x8Tests
{ {
public static Image<TPixel> CreateTestImage<TPixel>() public static Image<TPixel> CreateTestImage<TPixel>()
@ -20,7 +22,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{ {
for (int j = 0; j < 10; j++) 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); var color = default(TPixel);
color.PackFromRgba32(rgba); 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)); span[i] = new Rgb24((byte)i, (byte)(2 * i), (byte)(3 * i));
} }
Rgb24 expected00 = new Rgb24(0, 0, 0); var expected00 = new Rgb24(0, 0, 0);
Rgb24 expected07 = new Rgb24(7, 14, 21); var expected07 = new Rgb24(7, 14, 21);
Rgb24 expected11 = new Rgb24(9, 18, 27); var expected11 = new Rgb24(9, 18, 27);
Rgb24 expected77 = new Rgb24(63, 126, 189); var expected77 = new Rgb24(63, 126, 189);
Rgb24 expected67 = new Rgb24(62, 124, 186); var expected67 = new Rgb24(62, 124, 186);
Assert.Equal(expected00, block[0, 0]); Assert.Equal(expected00, block[0, 0]);
Assert.Equal(expected07, block[7, 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. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // 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.Common.Decoder;
using SixLabors.ImageSharp.Formats.Jpeg.GolangPort;
using Xunit; using Xunit;
namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
public class JFifMarkerTests public class JFifMarkerTests
{ {
// Taken from actual test image // 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;
using System.Numerics; using System.Numerics;
using SixLabors.ImageSharp.ColorSpaces; using SixLabors.ImageSharp.ColorSpaces;
using SixLabors.ImageSharp.ColorSpaces.Conversion; using SixLabors.ImageSharp.ColorSpaces.Conversion;
using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder; using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder;
using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder.ColorConverters;
using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Memory;
using Xunit; using Xunit;
using Xunit.Abstractions; using Xunit.Abstractions;
// ReSharper disable InconsistentNaming
namespace SixLabors.ImageSharp.Tests.Formats.Jpg namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{ {
using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder.ColorConverters;
public class JpegColorConverterTests public class JpegColorConverterTests
{ {
private const float Precision = 0.1f / 255; 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) public void FromYCbCrSimd_ConvertCore(int size, int seed)
{ {
JpegColorConverter.ComponentValues values = CreateRandomValues(3, size, seed); JpegColorConverter.ComponentValues values = CreateRandomValues(3, size, seed);
Vector4[] result = new Vector4[size]; var result = new Vector4[size];
JpegColorConverter.FromYCbCrSimd.ConvertCore(values, result); JpegColorConverter.FromYCbCrSimd.ConvertCore(values, result);
@ -134,7 +135,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
int times = 50000; int times = 50000;
JpegColorConverter.ComponentValues values = CreateRandomValues(3, count, 1); 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(); 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); var converter = JpegColorConverter.GetConverter(JpegColorSpace.Cmyk);
JpegColorConverter.ComponentValues values = CreateRandomValues(4, inputBufferLength, seed); JpegColorConverter.ComponentValues values = CreateRandomValues(4, inputBufferLength, seed);
Vector4[] result = new Vector4[resultBufferLength]; var result = new Vector4[resultBufferLength];
converter.ConvertToRGBA(values, result); converter.ConvertToRGBA(values, result);
@ -192,7 +193,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{ {
var converter = JpegColorConverter.GetConverter(JpegColorSpace.Grayscale); var converter = JpegColorConverter.GetConverter(JpegColorSpace.Grayscale);
JpegColorConverter.ComponentValues values = CreateRandomValues(1, inputBufferLength, seed); JpegColorConverter.ComponentValues values = CreateRandomValues(1, inputBufferLength, seed);
Vector4[] result = new Vector4[resultBufferLength]; var result = new Vector4[resultBufferLength];
converter.ConvertToRGBA(values, result); converter.ConvertToRGBA(values, result);
@ -214,7 +215,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{ {
var converter = JpegColorConverter.GetConverter(JpegColorSpace.RGB); var converter = JpegColorConverter.GetConverter(JpegColorSpace.RGB);
JpegColorConverter.ComponentValues values = CreateRandomValues(3, inputBufferLength, seed); JpegColorConverter.ComponentValues values = CreateRandomValues(3, inputBufferLength, seed);
Vector4[] result = new Vector4[resultBufferLength]; var result = new Vector4[resultBufferLength];
converter.ConvertToRGBA(values, result); converter.ConvertToRGBA(values, result);
@ -241,7 +242,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
var converter = JpegColorConverter.GetConverter(JpegColorSpace.Ycck); var converter = JpegColorConverter.GetConverter(JpegColorSpace.Ycck);
JpegColorConverter.ComponentValues values = CreateRandomValues(4, inputBufferLength, seed); JpegColorConverter.ComponentValues values = CreateRandomValues(4, inputBufferLength, seed);
Vector4[] result = new Vector4[resultBufferLength]; var result = new Vector4[resultBufferLength];
converter.ConvertToRGBA(values, result); converter.ConvertToRGBA(values, result);
@ -278,7 +279,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
float maxVal = 255f) float maxVal = 255f)
{ {
var rnd = new Random(seed); 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++) for (int i = 0; i < componentCount; i++)
{ {
float[] values = new float[inputBufferLength]; float[] values = new float[inputBufferLength];
@ -317,7 +318,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
int seed) int seed)
{ {
JpegColorConverter.ComponentValues values = CreateRandomValues(componentCount, inputBufferLength, seed); JpegColorConverter.ComponentValues values = CreateRandomValues(componentCount, inputBufferLength, seed);
Vector4[] result = new Vector4[resultBufferLength]; var result = new Vector4[resultBufferLength];
converter.ConvertToRGBA(values, result); converter.ConvertToRGBA(values, result);

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

@ -1,26 +1,16 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // 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;
using Xunit;
// ReSharper disable InconsistentNaming
namespace SixLabors.ImageSharp.Tests.Formats.Jpg 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 class JpegEncoderTests
{ {
public static readonly TheoryData<JpegSubsample, int> BitsPerPixel_Quality = 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 // Copyright (c) Six Labors and contributors.
{ // Licensed under the Apache License, Version 2.0.
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 SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder;
using Xunit.Abstractions; 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 class JpegImagePostProcessorTests
{ {
public static string[] BaselineTestJpegs = public static string[] BaselineTestJpegs =
@ -100,8 +103,6 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
Assert.True(report.TotalNormalizedDifference.Value < 0.005f); 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. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // 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 SixLabors.ImageSharp.PixelFormats;
using Xunit;
using Xunit.Abstractions;
namespace SixLabors.ImageSharp.Tests.Formats.Jpg 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 class JpegProfilingBenchmarks : MeasureFixture
{ {
public JpegProfilingBenchmarks(ITestOutputHelper output) public JpegProfilingBenchmarks(ITestOutputHelper output)
@ -102,14 +99,14 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
tf => TestImageProvider<Rgba32>.File(tf, pixelTypeOverride: PixelTypes.Rgba32).GetImage()) tf => TestImageProvider<Rgba32>.File(tf, pixelTypeOverride: PixelTypes.Rgba32).GetImage())
.ToArray(); .ToArray();
using (MemoryStream ms = new MemoryStream()) using (var ms = new MemoryStream())
{ {
this.Measure(executionCount, this.Measure(executionCount,
() => () =>
{ {
foreach (Image<Rgba32> img in testImages) 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); img.Save(ms, options);
ms.Seek(0, SeekOrigin.Begin); 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.PixelFormats;
using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils; using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils;
using Xunit; using Xunit;
namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
public class LibJpegToolsTests public class LibJpegToolsTests
{ {
[Fact] [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;
using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder; 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.Formats.Jpeg.GolangPort.Components.Decoder;
using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils; using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils;
using SixLabors.Primitives; using SixLabors.Primitives;
using Xunit; using Xunit;
using Xunit.Abstractions; using Xunit.Abstractions;
// ReSharper disable InconsistentNaming
namespace SixLabors.ImageSharp.Tests.Formats.Jpg namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{ {
using System.Text;
public class ParseStreamTests public class ParseStreamTests
{ {
private ITestOutputHelper Output { get; } private ITestOutputHelper Output { get; }
@ -65,19 +66,19 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
[InlineData(TestImages.Jpeg.Baseline.Cmyk)] [InlineData(TestImages.Jpeg.Baseline.Cmyk)]
public void PrintComponentData(string imageFile) public void PrintComponentData(string imageFile)
{ {
StringBuilder bld = new StringBuilder(); var sb = new StringBuilder();
using (OrigJpegDecoderCore decoder = JpegFixture.ParseStream(imageFile, true)) using (OrigJpegDecoderCore decoder = JpegFixture.ParseStream(imageFile, true))
{ {
bld.AppendLine(imageFile); sb.AppendLine(imageFile);
bld.AppendLine($"Size:{decoder.ImageSizeInPixels} MCU:{decoder.ImageSizeInMCU}"); sb.AppendLine($"Size:{decoder.ImageSizeInPixels} MCU:{decoder.ImageSizeInMCU}");
OrigComponent c0 = decoder.Components[0]; OrigComponent c0 = decoder.Components[0];
OrigComponent c1 = decoder.Components[1]; OrigComponent c1 = decoder.Components[1];
bld.AppendLine($"Luma: SAMP: {c0.SamplingFactors} BLOCKS: {c0.SizeInBlocks}"); sb.AppendLine($"Luma: SAMP: {c0.SamplingFactors} BLOCKS: {c0.SizeInBlocks}");
bld.AppendLine($"Chroma: {c1.SamplingFactors} BLOCKS: {c1.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>() 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. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // 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 public class ProfileResolverTests
{ {
private static readonly byte[] JFifMarker = Encoding.ASCII.GetBytes("JFIF\0"); 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;
using Xunit.Abstractions; using Xunit.Abstractions;
namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
public partial class ReferenceImplementationsTests public partial class ReferenceImplementationsTests
{ {
public class AccurateDCT : JpegFixture public class AccurateDCT : JpegFixture

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

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

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

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

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

@ -1,19 +1,19 @@
// ReSharper disable InconsistentNaming // ReSharper disable InconsistentNaming
namespace SixLabors.ImageSharp.Tests.Formats.Jpg using System;
{ using System.IO;
using System; using System.Linq;
using System.IO;
using System.Linq;
using SixLabors.ImageSharp.Formats.Jpeg; using SixLabors.ImageSharp.Formats.Jpeg;
using SixLabors.ImageSharp.Formats.Jpeg.GolangPort; using SixLabors.ImageSharp.Formats.Jpeg.GolangPort;
using SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort; using SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils; using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils;
using Xunit; using Xunit;
using Xunit.Abstractions; using Xunit.Abstractions;
namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
public class SpectralJpegTests public class SpectralJpegTests
{ {
public SpectralJpegTests(ITestOutputHelper output) public SpectralJpegTests(ITestOutputHelper output)
@ -45,7 +45,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
public void PdfJsDecoder_ParseStream_SaveSpectralResult<TPixel>(TestImageProvider<TPixel> provider) public void PdfJsDecoder_ParseStream_SaveSpectralResult<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel> 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; 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) public void OriginalDecoder_ParseStream_SaveSpectralResult<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel> 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; byte[] sourceBytes = TestFile.Create(provider.SourceFileOrDescription).Bytes;
@ -130,7 +130,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
return; return;
} }
PdfJsJpegDecoderCore decoder = new PdfJsJpegDecoderCore(Configuration.Default, new JpegDecoder()); var decoder = new PdfJsJpegDecoderCore(Configuration.Default, new JpegDecoder());
byte[] sourceBytes = TestFile.Create(provider.SourceFileOrDescription).Bytes; byte[] sourceBytes = TestFile.Create(provider.SourceFileOrDescription).Bytes;
@ -153,7 +153,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
return; return;
} }
OrigJpegDecoderCore decoder = new OrigJpegDecoderCore(Configuration.Default, new JpegDecoder()); var decoder = new OrigJpegDecoderCore(Configuration.Default, new JpegDecoder());
byte[] sourceBytes = TestFile.Create(provider.SourceFileOrDescription).Bytes; 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. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// ReSharper disable InconsistentNaming // ReSharper disable InconsistentNaming
namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils using System;
{ using System.Diagnostics;
using System; using System.IO;
using System.Diagnostics; using System.Text;
using System.IO;
using System.Text;
using SixLabors.ImageSharp.Formats.Jpeg; using SixLabors.ImageSharp.Formats.Jpeg;
using SixLabors.ImageSharp.Formats.Jpeg.Common; using SixLabors.ImageSharp.Formats.Jpeg.Common;
using SixLabors.ImageSharp.Formats.Jpeg.GolangPort; using SixLabors.ImageSharp.Formats.Jpeg.GolangPort;
using Xunit; using Xunit;
using Xunit.Abstractions; using Xunit.Abstractions;
namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
{
public class JpegFixture : MeasureFixture public class JpegFixture : MeasureFixture
{ {
public JpegFixture(ITestOutputHelper output) : base(output) public JpegFixture(ITestOutputHelper output) : base(output)
@ -70,7 +68,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
// ReSharper disable once InconsistentNaming // ReSharper disable once InconsistentNaming
public static int[] Create8x8RandomIntData(int minValue, int maxValue, int seed = 42) 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]; int[] result = new int[64];
for (int i = 0; i < 8; i++) 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) 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]; float[] result = new float[64];
for (int i = 0; i < 8; i++) for (int i = 0; i < 8; i++)
{ {
@ -132,12 +130,12 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
{ {
if (count < 0) count = data.Length; if (count < 0) count = data.Length;
StringBuilder bld = new StringBuilder(); var sb = new StringBuilder();
for (int i = 0; i < count; i++) 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) 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) 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; double totalDifference = 0.0;
bool failed = false; 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() 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++) 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++) 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); var v = new Vector4(val, val, val, 1);
Rgba32 color = default(Rgba32); Rgba32 color = default;
color.PackFromVector4(v); color.PackFromVector4(v);
int yy = by * 8 + y; int yy = by * 8 + y;
@ -143,8 +143,8 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
public bool Equals(ComponentData other) public bool Equals(ComponentData other)
{ {
if (Object.ReferenceEquals(null, other)) return false; if (object.ReferenceEquals(null, other)) return false;
if (Object.ReferenceEquals(this, other)) return true; if (object.ReferenceEquals(this, other)) return true;
bool ok = this.Index == other.Index && this.HeightInBlocks == other.HeightInBlocks bool ok = this.Index == other.Index && this.HeightInBlocks == other.HeightInBlocks
&& this.WidthInBlocks == other.WidthInBlocks; && this.WidthInBlocks == other.WidthInBlocks;
//&& this.MinVal == other.MinVal //&& 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; using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils 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 internal static partial class LibJpegTools
{ {
@ -58,7 +58,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
return null; 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++) 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 val1 = c0.GetBlockValue(block1, x, y);
float val2 = c0.GetBlockValue(block2, x, y); float val2 = c0.GetBlockValue(block2, x, y);
Vector4 v = new Vector4(val0, val1, val2, 1); var v = new Vector4(val0, val1, val2, 1);
Rgba32 color = default(Rgba32); Rgba32 color = default;
color.PackFromVector4(v); color.PackFromVector4(v);
int yy = by * 8 + y; int yy = by * 8 + y;
@ -105,8 +105,8 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
public bool Equals(SpectralData other) public bool Equals(SpectralData other)
{ {
if (Object.ReferenceEquals(null, other)) return false; if (object.ReferenceEquals(null, other)) return false;
if (Object.ReferenceEquals(this, other)) return true; if (object.ReferenceEquals(this, other)) return true;
if (this.ComponentCount != other.ComponentCount) if (this.ComponentCount != other.ComponentCount)
{ {
return false; return false;
@ -123,8 +123,8 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (Object.ReferenceEquals(null, obj)) return false; if (object.ReferenceEquals(null, obj)) return false;
if (Object.ReferenceEquals(this, obj)) return true; if (object.ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false; if (obj.GetType() != this.GetType()) return false;
return this.Equals((SpectralData)obj); 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.IO;
using System.Numerics; using System.Numerics;
using SixLabors.ImageSharp.Formats.Jpeg.Common;
namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
{ {
using SixLabors.ImageSharp.Formats.Jpeg.Common;
/// <summary> /// <summary>
/// Utilities to read raw libjpeg data for reference conversion. /// Utilities to read raw libjpeg data for reference conversion.
/// </summary> /// </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 internal static partial class ReferenceImplementations
{ {
/// <summary> /// <summary>
@ -54,7 +54,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
{ {
int x, y, u, v; int x, y, u, v;
double tmp, tmp2; double tmp, tmp2;
Block8x8F res = default(Block8x8F); Block8x8F res = default;
for (y=0; y<8; y++) { for (y=0; y<8; y++) {
for (x=0; x<8; x++) { for (x=0; x<8; x++) {
@ -76,7 +76,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
{ {
int x, y, u, v; int x, y, u, v;
double tmp, tmp2; double tmp, tmp2;
Block8x8F res = default(Block8x8F); Block8x8F res = default;
for (v = 0; v < 8; v++) 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 // ReSharper disable InconsistentNaming
using System;
namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
{ {
using System;
internal static partial class ReferenceImplementations internal static partial class ReferenceImplementations
{ {
/// <summary> /// <summary>

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

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

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

@ -1,18 +1,15 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// ReSharper disable InconsistentNaming // ReSharper disable InconsistentNaming
using System;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats.Jpeg.Common;
namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
{ {
using System;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Formats.Jpeg.Common;
/// <summary> /// <summary>
/// This class contains simplified (unefficient) reference implementations to produce verification data for unit tests /// 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 /// 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. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
{ {
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
/// <summary> /// <summary>
/// Span Extensions /// Span Extensions
/// </summary> /// </summary>
@ -118,4 +118,4 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
return result; return result;
} }
} }
} }
Loading…
Cancel
Save