diff --git a/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanScanEncoder.cs b/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanScanEncoder.cs
index 10fdfeea75..9650a3db46 100644
--- a/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanScanEncoder.cs
+++ b/src/ImageSharp/Formats/Jpeg/Components/Encoder/HuffmanScanEncoder.cs
@@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0.
using System.IO;
+using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading;
using SixLabors.ImageSharp.Memory;
@@ -427,5 +428,53 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder
return Numerics.Log2(value << 1);
#endif
}
+
+ // !!! DO NOT DELETE THIS !!! until custom huffman tables are supported - this is very handy for debugging
+ ///
+ /// Prints given huffman codes to the System.Console for debugging puroses.
+ ///
+ /// Codes array.
+ /// Custom title to print.
+ /// Flag indicating if all codes should be printed.
+ /// Indicates which number base will be used to print codes
+ private static void PrintHuffmanSummary(int[] codes, string title, bool printCode, int codePrintBase = 2)
+ {
+ System.Console.WriteLine(title);
+ System.Console.WriteLine($"Codes count: {codes.Length}");
+
+ // This is possible if custom tree is provided, especially for per-image optimized tree
+ if (codes.Length == 0)
+ {
+ return;
+ }
+
+ // Min
+ int min = codes.Min();
+ int min_len = min >> 24;
+ string min_code = System.Convert.ToString(min & ((1 << 24) - 1), codePrintBase);
+
+ // Max
+ int max = codes.Max();
+ int max_len = max >> 24;
+ string max_code = System.Convert.ToString(max & ((1 << 24) - 1), codePrintBase);
+
+ System.Console.WriteLine($"Min code: {min_code}, len: {min_len} \nMax code: {max_code}, len: {max_len}");
+
+ // Printing codes
+ if (printCode)
+ {
+ PrintHuffmanCodes(codes, codePrintBase);
+ }
+ }
+
+ private static void PrintHuffmanCodes(int[] codes, int codePrintBase)
+ {
+ for (int i = 0; i < codes.Length; i++)
+ {
+ int huffCode = codes[i];
+ string code = System.Convert.ToString(huffCode & ((1 << 24) - 1), codePrintBase);
+ System.Console.WriteLine($"\t{code}");
+ }
+ }
}
}