Browse Source

Spectral tests are now 100% accurate.

Error is now when collating blocks for color transform.
pull/525/head
James Jackson-South 8 years ago
parent
commit
ae72b03e9a
  1. 16
      src/ImageSharp/Formats/Jpeg/Common/Decoder/ComponentUtils.cs
  2. 8
      src/ImageSharp/Formats/Jpeg/Common/Decoder/IJpegComponent.cs
  3. 7
      src/ImageSharp/Formats/Jpeg/GolangPort/Components/Decoder/OrigComponent.cs
  4. 13
      src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsFrameComponent.cs
  5. 5
      tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs

16
src/ImageSharp/Formats/Jpeg/Common/Decoder/ComponentUtils.cs

@ -1,16 +0,0 @@
namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder
{
/// <summary>
/// Various utilities for <see cref="IJpegComponent"/>.
/// </summary>
internal static class ComponentUtils
{
/// <summary>
/// Gets a reference to the <see cref="Block8x8"/> at the given row and column index from <see cref="IJpegComponent.SpectralBlocks"/>
/// </summary>
public static ref Block8x8 GetBlockReference(this IJpegComponent component, int bx, int by)
{
return ref component.SpectralBlocks[bx, by];
}
}
}

8
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.
/// </summary>
Buffer2D<Block8x8> SpectralBlocks { get; }
/// <summary>
/// Gets a reference to the <see cref="Block8x8"/> at the given row and column index from <see cref="SpectralBlocks"/>
/// </summary>
/// <param name="column">The column</param>
/// <param name="row">The row</param>
/// <returns>The <see cref="Block8x8"/></returns>
ref Block8x8 GetBlockReference(int column, int row);
}
}

7
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();

13
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<Block8x8>(this.SizeInBlocks.Width, this.SizeInBlocks.Height, true);
this.SpectralBlocks = this.memoryManager.Allocate2D<Block8x8>(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);
}
}
}

5
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);

Loading…
Cancel
Save