diff --git a/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanLut.cs b/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanLut.cs
index bc6c8c6cc7..ec77bf87db 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanLut.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanLut.cs
@@ -5,8 +5,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder
{
///
/// A compiled look-up table representation of a huffmanSpec.
- /// Each value maps to a uint32 of which the 8 most significant bits hold the
- /// codeword size in bits and the 24 least significant bits hold the codeword.
+ /// Each value maps to a int32 of which the 24 most significant bits hold the
+ /// codeword in bits and the 8 least significant bits hold the codeword size.
/// The maximum codeword size is 16 bits.
///
internal readonly struct HuffmanLut
@@ -51,10 +51,10 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder
for (int i = 0; i < spec.Count.Length; i++)
{
- int bits = (i + 1) << 24;
+ int len = i + 1;
for (int j = 0; j < spec.Count[i]; j++)
{
- this.Values[spec.Values[k]] = bits | code;
+ this.Values[spec.Values[k]] = len | (code << 8);
code++;
k++;
}
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanScanEncoder.cs b/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanScanEncoder.cs
index 36f97a23df..3f490d2958 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanScanEncoder.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanScanEncoder.cs
@@ -1,6 +1,7 @@
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.
+using System;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
@@ -354,7 +355,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder
private void EmitHuff(int[] table, int value)
{
int x = table[value];
- this.Emit(x & ((1 << 24) - 1), x >> 24);
+ this.Emit(x >> 8, x & 0xff);
}
///
diff --git a/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanSpec.cs b/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanSpec.cs
index 1f9899562b..51364e3c73 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanSpec.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanSpec.cs
@@ -24,9 +24,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder
0, 0, 0
},
new byte[]
- {
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
- }),
+ {
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
+ }),
// Luminance AC.
new HuffmanSpec(