]> Cypherpunks repositories - gostls13.git/commitdiff
image/jpeg: add more theHuffmanSpec comments
authorNigel Tao <nigeltao@golang.org>
Sun, 3 Nov 2024 12:09:45 +0000 (23:09 +1100)
committerGopher Robot <gobot@golang.org>
Sun, 3 Nov 2024 17:18:11 +0000 (17:18 +0000)
Change-Id: I2c68dde6e968e0643109161e52a76189e48b4d19
Reviewed-on: https://go-review.googlesource.com/c/go/+/624715
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Nigel Tao <nigeltao@golang.org>
Reviewed-by: Nigel Tao <nigeltao@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
src/image/jpeg/writer.go

index 87c109ab7729782a4182a8f49dba1eb8f83d7217..0bda55c6b66f7676b61723858bf5ee10f2c88c30 100644 (file)
@@ -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.
        {