Browse Source

Huffman lookup tables are now integers instead of unsigned integers

pull/1632/head
Dmitry Pentin 5 years ago
parent
commit
9c0999e9db
  1. 10
      src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanLut.cs
  2. 2
      src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanScanEncoder.cs

10
src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanLut.cs

@ -1,4 +1,4 @@
// Copyright (c) Six Labors. // Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder
@ -44,7 +44,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder
} }
} }
this.Values = new uint[maxValue + 1]; this.Values = new int[maxValue + 1];
int code = 0; int code = 0;
int k = 0; int k = 0;
@ -54,7 +54,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder
int bits = (i + 1) << 24; int bits = (i + 1) << 24;
for (int j = 0; j < spec.Count[i]; j++) for (int j = 0; j < spec.Count[i]; j++)
{ {
this.Values[spec.Values[k]] = (uint)(bits | code); this.Values[spec.Values[k]] = bits | code;
code++; code++;
k++; k++;
} }
@ -66,6 +66,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder
/// <summary> /// <summary>
/// Gets the collection of huffman values. /// Gets the collection of huffman values.
/// </summary> /// </summary>
public uint[] Values { get; } public int[] Values { get; }
} }
} }

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

@ -344,7 +344,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
private void EmitHuff(int index, int value) private void EmitHuff(int index, int value)
{ {
int x = (int)HuffmanLut.TheHuffmanLut[index].Values[value]; int x = HuffmanLut.TheHuffmanLut[index].Values[value];
this.Emit(x & ((1 << 24) - 1), x >> 24); this.Emit(x & ((1 << 24) - 1), x >> 24);
} }

Loading…
Cancel
Save