Browse Source

Fixeds docs, fixed API, fixed if check

pull/1673/head
Dmitry Pentin 5 years ago
parent
commit
26a0f0bc6f
  1. 17
      src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanScanEncoder.cs

17
src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanScanEncoder.cs

@ -286,7 +286,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder
} }
} }
if (lastValuableIndex != 63) // if mcu block contains trailing zeros - we must write end of block (EOB) values indicating that current block is over
// this can be done for any number of trailing zeros
if (lastValuableIndex < Block8x8F.Size - 1)
{ {
this.EmitHuff(huffmanTable, 0x00); this.EmitHuff(huffmanTable, 0x00);
} }
@ -461,14 +463,17 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder
/// <summary> /// <summary>
/// Returns index of the last non-zero element in given mcu block, returns -1 if all elements are zero /// Returns index of the last non-zero element in given mcu block, returns -1 if all elements are zero
/// </summary> /// </summary>
/// <param name="block">Input mcu.</param> /// <remarks>Return range is [1..63].</remarks>
/// <param name="mcu">Mcu block.</param>
/// <returns>Index of the last non-zero element.</returns> /// <returns>Index of the last non-zero element.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static int GetLastNonZeroElement(ref Block8x8F block) private static int GetLastNonZeroElement(ref Block8x8F mcu)
{ {
int index = 63; int index = Block8x8F.Size - 1;
ref float elemRef = ref Unsafe.As<Block8x8F, float>(ref block); ref float elemRef = ref Unsafe.As<Block8x8F, float>(ref mcu);
while (index > -1 && (int)Unsafe.Add(ref elemRef, index) == 0)
// Index range is [63..0), first element is a DC value which will be emitted even if entire mcu contains only zeros
while (index > 0 && (int)Unsafe.Add(ref elemRef, index) == 0)
{ {
index--; index--;
} }

Loading…
Cancel
Save