github.com/go-oss/image@v0.1.1-0.20230517025328-001b78555e78/jpeg/huffman.go (about) 1 // Copyright 2009 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package jpeg 6 7 // maxCodeLength is the maximum (inclusive) number of bits in a Huffman code. 8 const maxCodeLength = 16 9 10 // maxNCodes is the maximum (inclusive) number of codes in a Huffman tree. 11 const maxNCodes = 256 12 13 // lutSize is the log-2 size of the Huffman decoder's look-up table. 14 const lutSize = 8 15 16 // huffman is a Huffman decoder, specified in section C. 17 type huffman struct { 18 // length is the number of codes in the tree. 19 nCodes int32 20 // lut is the look-up table for the next lutSize bits in the bit-stream. 21 // The high 8 bits of the uint16 are the encoded value. The low 8 bits 22 // are 1 plus the code length, or 0 if the value is too large to fit in 23 // lutSize bits. 24 lut [1 << lutSize]uint16 25 // vals are the decoded values, sorted by their encoding. 26 vals [maxNCodes]uint8 27 // minCodes[i] is the minimum code of length i, or -1 if there are no 28 // codes of that length. 29 minCodes [maxCodeLength]int32 30 // maxCodes[i] is the maximum code of length i, or -1 if there are no 31 // codes of that length. 32 maxCodes [maxCodeLength]int32 33 // valsIndices[i] is the index into vals of minCodes[i]. 34 valsIndices [maxCodeLength]int32 35 }