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;
/// <summary>
/// Represents a Huffman tree
/// Represents a Huffman tree
/// </summary>
internal struct HuffmanTree : IDisposable
{
/// <summary>
/// The maximum (inclusive) number of codes in a Huffman tree.
/// The maximum (inclusive) number of codes in a Huffman tree.
/// </summary>
public const int MaxNCodes = 256;
/// <summary>
/// The maximum (inclusive) number of bits in a Huffman code.
/// The maximum (inclusive) number of bits in a Huffman code.
/// </summary>
public const int MaxCodeLength = 16;
/// <summary>
/// The maximum number of Huffman table classes
/// The maximum number of Huffman table classes
/// </summary>
public const int MaxTc = 1;
/// <summary>
/// The maximum number of Huffman table identifiers
/// The maximum number of Huffman table identifiers
/// </summary>
public const int MaxTh = 3;
/// <summary>
/// Row size of the Huffman table
/// Row size of the Huffman table
/// </summary>
public const int ThRowSize = MaxTh + 1;
/// <summary>
/// Number of Hufman Trees in the Huffman table
/// Number of Hufman Trees in the Huffman table
/// </summary>
public const int NumberOfTrees = (MaxTc + 1) * (MaxTh + 1);
/// <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>
public const int LutSize = 8;
/// <summary>
/// Gets or sets the number of codes in the tree.
/// Gets or sets the number of codes in the tree.
/// </summary>
public int Length;
/// <summary>
/// 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
/// are 1 plus the code length, or 0 if the value is too large to fit in
/// lutSize bits.
/// 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
/// are 1 plus the code length, or 0 if the value is too large to fit in
/// lutSize bits.
/// </summary>
public ushort[] Lut;
/// <summary>
/// Gets the the decoded values, sorted by their encoding.
/// Gets the the decoded values, sorted by their encoding.
/// </summary>
public byte[] Values;
/// <summary>
/// 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.
/// 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.
/// </summary>
public int[] MinCodes;
/// <summary>
/// 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.
/// 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.
/// </summary>
public int[] MaxCodes;
/// <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>
public int[] Indices;
@ -89,7 +89,7 @@ namespace ImageSharp.Formats.Jpg
private static readonly ArrayPool<int> IntBuffer = ArrayPool<int>.Create(MaxCodeLength, 50);
/// <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>
/// <returns>An array of <see cref="HuffmanTree" /> instances representing the Huffman tables</returns>
public static HuffmanTree[] CreateHuffmanTrees()
@ -107,7 +107,7 @@ namespace ImageSharp.Formats.Jpg
}
/// <summary>
/// Initializes the Huffman tree
/// Initializes the Huffman tree
/// </summary>
private void Init()
{
@ -119,7 +119,7 @@ namespace ImageSharp.Formats.Jpg
}
/// <summary>
/// Disposes the underlying buffers
/// Disposes the underlying buffers
/// </summary>
public void Dispose()
{
@ -131,7 +131,7 @@ namespace ImageSharp.Formats.Jpg
}
/// <summary>
/// Internal part of the DHT processor, whatever does it mean
/// Internal part of the DHT processor, whatever does it mean
/// </summary>
/// <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>

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

@ -12,12 +12,12 @@ namespace ImageSharp.Formats.Jpg
internal unsafe struct JpegScanDecoder
{
/// <summary>
/// The AC table index
/// The AC table index
/// </summary>
internal const int AcTableIndex = 1;
/// <summary>
/// The DC table index
/// The DC table index
/// </summary>
internal const int DcTableIndex = 0;
@ -37,9 +37,9 @@ namespace ImageSharp.Formats.Jpg
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()
{
@ -133,7 +133,7 @@ namespace ImageSharp.Formats.Jpg
private ComponentData Data;
private ComponentPointers Pointers;
public static void Init(JpegScanDecoder* p, JpegDecoderCore decoder, int remaining)
{
p->Data = ComponentData.Create();
@ -387,7 +387,7 @@ namespace ImageSharp.Formats.Jpg
// Reset the DC components, as per section F.2.1.3.1.
this.ResetDc();
// Reset the progressive decoder state, as per section G.1.2.2.
decoder.EobRun = 0;
}
@ -398,7 +398,7 @@ namespace ImageSharp.Formats.Jpg
}
/// <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>
/// <param name="h">The Huffman tree</param>
/// <param name="delta">The low transform offset</param>
@ -473,7 +473,7 @@ namespace ImageSharp.Formats.Jpg
{
break;
}
zig = this.RefineNonZeroes(decoder, zig, val0, delta);
if (zig > this.zigEnd)
{
@ -491,13 +491,13 @@ namespace ImageSharp.Formats.Jpg
if (decoder.EobRun > 0)
{
decoder.EobRun--;
this.RefineNonZeroes(decoder, zig,-1, delta);
this.RefineNonZeroes(decoder, zig, -1, delta);
}
}
/// <summary>
/// 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.
/// 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.
/// </summary>
/// <param name="decoder">The decoder</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);
}
}
}

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

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

Loading…
Cancel
Save