Browse Source

Merge branch 'master' of https://github.com/JimBobSquarePants/ImageSharp into jpeg-optimizations-experimental

Conflicts:
	tests/ImageSharp.Tests/Formats/Jpg/JpegTests.cs
pull/62/head
antonfirsov 10 years ago
parent
commit
ce5882ab25
  1. 46
      src/ImageSharp/Formats/Jpg/Components/Decoder/HuffmanTree.cs
  2. 24
      src/ImageSharp/Formats/Jpg/Components/Decoder/JpegScanDecoder.cs
  3. 8
      src/ImageSharp/Formats/Jpg/Components/Decoder/Scan.cs

46
src/ImageSharp/Formats/Jpg/Components/Decoder/HuffmanTree.cs

@ -8,77 +8,77 @@ namespace ImageSharp.Formats.Jpg
using System.Buffers; using System.Buffers;
/// <summary> /// <summary>
/// Represents a Huffman tree /// Represents a Huffman tree
/// </summary> /// </summary>
internal struct HuffmanTree : IDisposable internal struct HuffmanTree : IDisposable
{ {
/// <summary> /// <summary>
/// The maximum (inclusive) number of codes in a Huffman tree. /// The maximum (inclusive) number of codes in a Huffman tree.
/// </summary> /// </summary>
public const int MaxNCodes = 256; public const int MaxNCodes = 256;
/// <summary> /// <summary>
/// The maximum (inclusive) number of bits in a Huffman code. /// The maximum (inclusive) number of bits in a Huffman code.
/// </summary> /// </summary>
public const int MaxCodeLength = 16; public const int MaxCodeLength = 16;
/// <summary> /// <summary>
/// The maximum number of Huffman table classes /// The maximum number of Huffman table classes
/// </summary> /// </summary>
public const int MaxTc = 1; public const int MaxTc = 1;
/// <summary> /// <summary>
/// The maximum number of Huffman table identifiers /// The maximum number of Huffman table identifiers
/// </summary> /// </summary>
public const int MaxTh = 3; public const int MaxTh = 3;
/// <summary> /// <summary>
/// Row size of the Huffman table /// Row size of the Huffman table
/// </summary> /// </summary>
public const int ThRowSize = MaxTh + 1; public const int ThRowSize = MaxTh + 1;
/// <summary> /// <summary>
/// Number of Hufman Trees in the Huffman table /// Number of Hufman Trees in the Huffman table
/// </summary> /// </summary>
public const int NumberOfTrees = (MaxTc + 1) * (MaxTh + 1); public const int NumberOfTrees = (MaxTc + 1) * (MaxTh + 1);
/// <summary> /// <summary>
/// The log-2 size of the Huffman decoder's look-up table. /// The log-2 size of the Huffman decoder's look-up table.
/// </summary> /// </summary>
public const int LutSize = 8; public const int LutSize = 8;
/// <summary> /// <summary>
/// Gets or sets the number of codes in the tree. /// Gets or sets the number of codes in the tree.
/// </summary> /// </summary>
public int Length; public int Length;
/// <summary> /// <summary>
/// Gets the look-up table for the next LutSize bits in the bit-stream. /// Gets the look-up table for the next LutSize bits in the bit-stream.
/// The high 8 bits of the uint16 are the encoded value. The low 8 bits /// The high 8 bits of the uint16 are the encoded value. The low 8 bits
/// are 1 plus the code length, or 0 if the value is too large to fit in /// are 1 plus the code length, or 0 if the value is too large to fit in
/// lutSize bits. /// lutSize bits.
/// </summary> /// </summary>
public ushort[] Lut; public ushort[] Lut;
/// <summary> /// <summary>
/// Gets the the decoded values, sorted by their encoding. /// Gets the the decoded values, sorted by their encoding.
/// </summary> /// </summary>
public byte[] Values; public byte[] Values;
/// <summary> /// <summary>
/// Gets the array of minimum codes. /// Gets the array of minimum codes.
/// MinCodes[i] is the minimum code of length i, or -1 if there are no codes of that length. /// MinCodes[i] is the minimum code of length i, or -1 if there are no codes of that length.
/// </summary> /// </summary>
public int[] MinCodes; public int[] MinCodes;
/// <summary> /// <summary>
/// Gets the array of maximum codes. /// Gets the array of maximum codes.
/// MaxCodes[i] is the maximum code of length i, or -1 if there are no codes of that length. /// MaxCodes[i] is the maximum code of length i, or -1 if there are no codes of that length.
/// </summary> /// </summary>
public int[] MaxCodes; public int[] MaxCodes;
/// <summary> /// <summary>
/// Gets the array of indices. Indices[i] is the index into Values of MinCodes[i]. /// Gets the array of indices. Indices[i] is the index into Values of MinCodes[i].
/// </summary> /// </summary>
public int[] Indices; public int[] Indices;
@ -89,7 +89,7 @@ namespace ImageSharp.Formats.Jpg
private static readonly ArrayPool<int> IntBuffer = ArrayPool<int>.Create(MaxCodeLength, 50); private static readonly ArrayPool<int> IntBuffer = ArrayPool<int>.Create(MaxCodeLength, 50);
/// <summary> /// <summary>
/// Creates and initializes an array of <see cref="HuffmanTree" /> instances of size <see cref="NumberOfTrees" /> /// Creates and initializes an array of <see cref="HuffmanTree" /> instances of size <see cref="NumberOfTrees" />
/// </summary> /// </summary>
/// <returns>An array of <see cref="HuffmanTree" /> instances representing the Huffman tables</returns> /// <returns>An array of <see cref="HuffmanTree" /> instances representing the Huffman tables</returns>
public static HuffmanTree[] CreateHuffmanTrees() public static HuffmanTree[] CreateHuffmanTrees()
@ -107,7 +107,7 @@ namespace ImageSharp.Formats.Jpg
} }
/// <summary> /// <summary>
/// Initializes the Huffman tree /// Initializes the Huffman tree
/// </summary> /// </summary>
private void Init() private void Init()
{ {
@ -119,7 +119,7 @@ namespace ImageSharp.Formats.Jpg
} }
/// <summary> /// <summary>
/// Disposes the underlying buffers /// Disposes the underlying buffers
/// </summary> /// </summary>
public void Dispose() public void Dispose()
{ {
@ -131,7 +131,7 @@ namespace ImageSharp.Formats.Jpg
} }
/// <summary> /// <summary>
/// Internal part of the DHT processor, whatever does it mean /// Internal part of the DHT processor, whatever does it mean
/// </summary> /// </summary>
/// <param name="decoder">The decoder instance</param> /// <param name="decoder">The decoder instance</param>
/// <param name="defineHuffmanTablesData">The temporal buffer that holds the data that has been read from the Jpeg stream</param> /// <param name="defineHuffmanTablesData">The temporal buffer that holds the data that has been read from the Jpeg stream</param>

24
src/ImageSharp/Formats/Jpg/Components/Decoder/JpegScanDecoder.cs

@ -12,12 +12,12 @@ namespace ImageSharp.Formats.Jpg
internal unsafe struct JpegScanDecoder internal unsafe struct JpegScanDecoder
{ {
/// <summary> /// <summary>
/// The AC table index /// The AC table index
/// </summary> /// </summary>
internal const int AcTableIndex = 1; internal const int AcTableIndex = 1;
/// <summary> /// <summary>
/// The DC table index /// The DC table index
/// </summary> /// </summary>
internal const int DcTableIndex = 0; internal const int DcTableIndex = 0;
@ -37,9 +37,9 @@ namespace ImageSharp.Formats.Jpg
public UnzigData Unzig; public UnzigData Unzig;
public fixed byte ScanData [3 * JpegDecoderCore.MaxComponents]; public fixed byte ScanData[3 * JpegDecoderCore.MaxComponents];
public fixed int Dc [JpegDecoderCore.MaxComponents]; public fixed int Dc[JpegDecoderCore.MaxComponents];
public static ComponentData Create() public static ComponentData Create()
{ {
@ -133,7 +133,7 @@ namespace ImageSharp.Formats.Jpg
private ComponentData Data; private ComponentData Data;
private ComponentPointers Pointers; private ComponentPointers Pointers;
public static void Init(JpegScanDecoder* p, JpegDecoderCore decoder, int remaining) public static void Init(JpegScanDecoder* p, JpegDecoderCore decoder, int remaining)
{ {
p->Data = ComponentData.Create(); p->Data = ComponentData.Create();
@ -387,7 +387,7 @@ namespace ImageSharp.Formats.Jpg
// Reset the DC components, as per section F.2.1.3.1. // Reset the DC components, as per section F.2.1.3.1.
this.ResetDc(); this.ResetDc();
// Reset the progressive decoder state, as per section G.1.2.2. // Reset the progressive decoder state, as per section G.1.2.2.
decoder.EobRun = 0; decoder.EobRun = 0;
} }
@ -398,7 +398,7 @@ namespace ImageSharp.Formats.Jpg
} }
/// <summary> /// <summary>
/// Decodes a successive approximation refinement block, as specified in section G.1.2. /// Decodes a successive approximation refinement block, as specified in section G.1.2.
/// </summary> /// </summary>
/// <param name="h">The Huffman tree</param> /// <param name="h">The Huffman tree</param>
/// <param name="delta">The low transform offset</param> /// <param name="delta">The low transform offset</param>
@ -473,7 +473,7 @@ namespace ImageSharp.Formats.Jpg
{ {
break; break;
} }
zig = this.RefineNonZeroes(decoder, zig, val0, delta); zig = this.RefineNonZeroes(decoder, zig, val0, delta);
if (zig > this.zigEnd) if (zig > this.zigEnd)
{ {
@ -491,13 +491,13 @@ namespace ImageSharp.Formats.Jpg
if (decoder.EobRun > 0) if (decoder.EobRun > 0)
{ {
decoder.EobRun--; decoder.EobRun--;
this.RefineNonZeroes(decoder, zig,-1, delta); this.RefineNonZeroes(decoder, zig, -1, delta);
} }
} }
/// <summary> /// <summary>
/// Refines non-zero entries of b in zig-zag order. /// Refines non-zero entries of b in zig-zag order.
/// If <paramref name="nz" /> >= 0, the first <paramref name="nz" /> zero entries are skipped over. /// If <paramref name="nz" /> >= 0, the first <paramref name="nz" /> zero entries are skipped over.
/// </summary> /// </summary>
/// <param name="decoder">The decoder</param> /// <param name="decoder">The decoder</param>
/// <param name="zig">The zig-zag start index</param> /// <param name="zig">The zig-zag start index</param>
@ -649,5 +649,5 @@ namespace ImageSharp.Formats.Jpg
destArea.LoadColorsFrom(this.Pointers.Temp1, this.Pointers.Temp2); destArea.LoadColorsFrom(this.Pointers.Temp1, this.Pointers.Temp2);
} }
} }
} }

8
src/ImageSharp/Formats/Jpg/Components/Decoder/Scan.cs

@ -3,23 +3,23 @@
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
/// <summary> /// <summary>
/// Represents a component scan /// Represents a component scan
/// </summary> /// </summary>
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
internal struct Scan internal struct Scan
{ {
/// <summary> /// <summary>
/// Gets or sets the component index. /// Gets or sets the component index.
/// </summary> /// </summary>
public byte Index; public byte Index;
/// <summary> /// <summary>
/// Gets or sets the DC table selector /// Gets or sets the DC table selector
/// </summary> /// </summary>
public byte DcTableSelector; public byte DcTableSelector;
/// <summary> /// <summary>
/// Gets or sets the AC table selector /// Gets or sets the AC table selector
/// </summary> /// </summary>
public byte AcTableSelector; public byte AcTableSelector;
} }

Loading…
Cancel
Save