Browse Source

Introduce a few more constants

pull/1038/head
James Jackson-South 7 years ago
parent
commit
5a2c5d27db
  1. 6
      src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanBuffer.cs
  2. 9
      src/ImageSharp/Formats/Jpeg/JpegConstants.cs

6
src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanBuffer.cs

@ -51,7 +51,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
public void CheckBits() public void CheckBits()
{ {
if (this.remainingBits < 16) if (this.remainingBits < JpegConstants.Huffman.MinBits)
{ {
this.FillBuffer(); this.FillBuffer();
} }
@ -85,8 +85,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
{ {
// Attempt to load at least the minimum number of required bits into the buffer. // Attempt to load at least the minimum number of required bits into the buffer.
// We fail to do so only if we hit a marker or reach the end of the input stream. // We fail to do so only if we hit a marker or reach the end of the input stream.
this.remainingBits += JpegConstants.Huffman.MinBits; this.remainingBits += JpegConstants.Huffman.FetchBits;
this.data = (this.data << JpegConstants.Huffman.MinBits) | this.GetBytes(); this.data = (this.data << JpegConstants.Huffman.FetchBits) | this.GetBytes();
} }
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]

9
src/ImageSharp/Formats/Jpeg/JpegConstants.cs

@ -251,9 +251,14 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
public const int RegisterSize = 64; public const int RegisterSize = 64;
/// <summary> /// <summary>
/// The minimum number of bits required by the <see cref="HuffmanScanBuffer"/>. /// The number of bits to fetch when filling the <see cref="HuffmanScanBuffer"/> buffer.
/// </summary> /// </summary>
public const int MinBits = 48; public const int FetchBits = 48;
/// <summary>
/// The minimum number of bits allowed before by the <see cref="HuffmanScanBuffer"/> before fetching.
/// </summary>
public const int MinBits = RegisterSize - FetchBits;
/// <summary> /// <summary>
/// If the next Huffman code is no more than this number of bits, we can obtain its length /// If the next Huffman code is no more than this number of bits, we can obtain its length

Loading…
Cancel
Save