From 9c93d99c616b8708bed55781915f7256051ab91e Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Sun, 3 Nov 2024 23:09:45 +1100 Subject: [PATCH] image/jpeg: add more theHuffmanSpec comments Change-Id: I2c68dde6e968e0643109161e52a76189e48b4d19 Reviewed-on: https://go-review.googlesource.com/c/go/+/624715 Reviewed-by: Dmitri Shuralyov Auto-Submit: Nigel Tao Reviewed-by: Nigel Tao LUCI-TryBot-Result: Go LUCI Reviewed-by: Dmitri Shuralyov --- src/image/jpeg/writer.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/image/jpeg/writer.go b/src/image/jpeg/writer.go index 87c109ab77..0bda55c6b6 100644 --- a/src/image/jpeg/writer.go +++ b/src/image/jpeg/writer.go @@ -50,8 +50,8 @@ const ( // unscaledQuant are the unscaled quantization tables in zig-zag order. Each // encoder copies and scales the tables according to its quality parameter. -// The values are derived from section K.1 after converting from natural to -// zig-zag order. +// The values are derived from section K.1 of the spec, after converting from +// natural to zig-zag order. var unscaledQuant = [nQuantIndex][blockSize]byte{ // Luminance. { @@ -89,14 +89,22 @@ const ( // huffmanSpec specifies a Huffman encoding. type huffmanSpec struct { - // count[i] is the number of codes of length i bits. + // count[i] is the number of codes of length i+1 bits. count [16]byte // value[i] is the decoded value of the i'th codeword. value []byte } // theHuffmanSpec is the Huffman encoding specifications. -// This encoder uses the same Huffman encoding for all images. +// +// This encoder uses the same Huffman encoding for all images. It is also the +// same Huffman encoding used by section K.3 of the spec. +// +// The DC tables have 12 decoded values, called categories. +// +// The AC tables have 162 decoded values: bytes that pack a 4-bit Run and a +// 4-bit Size. There are 16 valid Runs and 10 valid Sizes, plus two special R|S +// cases: 0|0 (meaning EOB) and F|0 (meaning ZRL). var theHuffmanSpec = [nHuffIndex]huffmanSpec{ // Luminance DC. { -- 2.50.0