From ae72b03e9a8bab2ae401626aa581ac4eeb81f945 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Mon, 16 Apr 2018 20:32:25 +1000 Subject: [PATCH] Spectral tests are now 100% accurate. Error is now when collating blocks for color transform. --- .../Jpeg/Common/Decoder/ComponentUtils.cs | 16 ---------------- .../Jpeg/Common/Decoder/IJpegComponent.cs | 8 ++++++++ .../Components/Decoder/OrigComponent.cs | 7 +++++++ .../PdfJsPort/Components/PdfJsFrameComponent.cs | 13 ++++++++++--- .../Jpg/Utils/LibJpegTools.ComponentData.cs | 5 +++++ 5 files changed, 30 insertions(+), 19 deletions(-) delete mode 100644 src/ImageSharp/Formats/Jpeg/Common/Decoder/ComponentUtils.cs diff --git a/src/ImageSharp/Formats/Jpeg/Common/Decoder/ComponentUtils.cs b/src/ImageSharp/Formats/Jpeg/Common/Decoder/ComponentUtils.cs deleted file mode 100644 index da97f9e2a..000000000 --- a/src/ImageSharp/Formats/Jpeg/Common/Decoder/ComponentUtils.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder -{ - /// - /// Various utilities for . - /// - internal static class ComponentUtils - { - /// - /// Gets a reference to the at the given row and column index from - /// - public static ref Block8x8 GetBlockReference(this IJpegComponent component, int bx, int by) - { - return ref component.SpectralBlocks[bx, by]; - } - } -} \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/Common/Decoder/IJpegComponent.cs b/src/ImageSharp/Formats/Jpeg/Common/Decoder/IJpegComponent.cs index 4109fc10e..de9f75dc1 100644 --- a/src/ImageSharp/Formats/Jpeg/Common/Decoder/IJpegComponent.cs +++ b/src/ImageSharp/Formats/Jpeg/Common/Decoder/IJpegComponent.cs @@ -42,5 +42,13 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder /// We need to apply IDCT and dequantiazition to transform them into color-space blocks. /// Buffer2D SpectralBlocks { get; } + + /// + /// Gets a reference to the at the given row and column index from + /// + /// The column + /// The row + /// The + ref Block8x8 GetBlockReference(int column, int row); } } \ No newline at end of file diff --git a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigComponent.cs b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigComponent.cs index e83dd75a5..e2f21bd1c 100644 --- a/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigComponent.cs +++ b/src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigComponent.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; +using System.Runtime.CompilerServices; using SixLabors.ImageSharp.Formats.Jpeg.Common; using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder; using SixLabors.ImageSharp.Memory; @@ -237,6 +238,12 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort.Components.Decoder this.SamplingFactors = new Size(h, v); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ref Block8x8 GetBlockReference(int column, int row) + { + return ref this.SpectralBlocks[column, row]; + } + public void Dispose() { this.SpectralBlocks.Dispose(); diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs index 7d195374a..747e6107e 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs @@ -3,6 +3,7 @@ using System; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using SixLabors.ImageSharp.Formats.Jpeg.Common; using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder; using SixLabors.ImageSharp.Memory; @@ -130,14 +131,20 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components this.SubSamplingDivisors = c0.SamplingFactors.DivideBy(this.SamplingFactors); } - this.SpectralBlocks = this.memoryManager.Allocate2D(this.SizeInBlocks.Width, this.SizeInBlocks.Height, true); + this.SpectralBlocks = this.memoryManager.Allocate2D(this.BlocksPerColumnForMcu, this.BlocksPerLineForMcu + 1, true); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public ref Block8x8 GetBlockReference(int column, int row) + { + int offset = ((this.WidthInBlocks + 1) * row) + column; + return ref Unsafe.Add(ref MemoryMarshal.GetReference(this.SpectralBlocks.Span), offset); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int GetBlockBufferOffset(int row, int col) { - // return 64 * (((this.WidthInBlocks + 1) * row) + col); - return 64 * ((this.WidthInBlocks * row) + col); + return 64 * (((this.WidthInBlocks + 1) * row) + col); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs b/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs index 4cfaa6e61..a003f749e 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs @@ -184,6 +184,11 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils } } + public ref Block8x8 GetBlockReference(int column, int row) + { + throw new NotImplementedException(); + } + public static bool operator ==(ComponentData left, ComponentData right) { return Object.Equals(left, right);