Comment #2 on issue 551 by j...@
minteronline.com: VP8L specification is incredible wrong
https://bugs.chromium.org/p/webp/issues/detail?id=551#c2re: simple entropy codes, under 5.2.2(i) it has the pseudo code:
[code]
int is_first_8bits = ReadBits(1);
code_lengths[0] = ReadBits(1 + 7 * is_first_8bits);
if (num_code_lengths == 2) {
code_lengths[1] = ReadBits(8);
}
[/code]
while in the libwebp reference decoder inside vp8l_dec.c in the function ReadHuffmanCode:
[code]
code_lengths[symbol] = 1;
// The second code (if present), is always 8 bit long.
if (num_symbols == 2) {
symbol = VP8LReadBits(br, 8);
code_lengths[symbol] = 1;
}
[/code]
This makes more sense since if there are only two values in the huffman table they should both have a length of 1, but is different to the spec
re: normal entropy codes, under 5.2.2(ii) it briefly states how to decode it but is missing a lot of details. These extra details can be found in the later half of ReadHuffmanCode and ReadHuffmanCodeLengths (in vp8l_dec.c). Notably the spec never fully explains how to use the code lengths as described in 5.2.2(ii) to decode the real code lengths, and does not mention reading the max_symbol parameter as shown in the reference decoder:
[code]
if (VP8LReadBits(br, 1)) { // use length
const int length_nbits = 2 + 2 * VP8LReadBits(br, 3);
max_symbol = 2 + VP8LReadBits(br, length_nbits);
if (max_symbol > num_symbols) {
goto End;
}
} else {
max_symbol = num_symbols;
}
[/code]
re: order of huffman code reading, in section 4.1.1 it suggests that the ARGB image data is encoded the exact same way as other image data (except for the extra huffman groups). Also in section 5.2 of the spec the order suggests that the meta huffman codes is before the main entropy-coded image.
Along with this, in section 6, it actually states that:
<image stream> ::= <optional-transform><spatially-coded image>
[...]
<spatially-coded image> ::= <meta huffman><entropy-coded image>
<entropy-coded image> ::= <color cache info><huffman codes><lz77-coded image>
<meta huffman> ::= 1-bit value 0 |
(1-bit value 1; <entropy image>)
Again, showing that the meta huffman is before the rest of the entropy coded image. However in DecodeImage in the reference decoder this seems to be missing, and instead can be found in ReadHuffmanCodes right before reading the huffman groups. Thus the order should be:
<spatially-coded image> ::= <color cache info><meta huffman><huffman codes><lz77-coded image>
<entropy-coded image> ::= <color cache info><huffman codes><lz77-coded image>
And sections 4.1.1 and 5.2 should better explain how the main ARGB image is different to other entropy-coded images in that it embeds the meta huffman in the middle of it, after the color cache.
re: one value huffmans, in the reference decoder in the source file huffman_utils.c in the function BuildHuffmanTable there is this code snippet:
[code]
// Special case code with only one value.
if (offset[MAX_ALLOWED_CODE_LENGTH] == 1) {
if (sorted != NULL) {
HuffmanCode code;
code.bits = 0;
code.value = (uint16_t)sorted[0];
ReplicateValue(table, 1, total_size, code);
}
return total_size;
}
[/code]
Yet again, this is something that logically makes sense, but is completely absent from the specification and would be very helpful to mention somewhere. Perhaps under 5.2.2(i) as a note?