summaryrefslogtreecommitdiff
path: root/libavcodec/utvideodec.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2020-09-24 16:19:03 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2020-09-26 21:10:29 +0200
commit099feb941147fbf10d1ae941b96bf94c4b4dbd1c (patch)
tree7720657dba541836e5d33262263b488578ab11e5 /libavcodec/utvideodec.c
parent116b235a0b86276aea2fc9021c056744977a1527 (diff)
downloadffmpeg-099feb941147fbf10d1ae941b96bf94c4b4dbd1c.tar.gz
avcodec/utvideodec/enc: Fix edge case of creating Huffman table
The Ut Video format stores Huffman tables in its bitstream by coding the length of a given symbol; it does not code the actual code directly, instead this is to be inferred by the rule that a symbol is to the left of every shorter symbol in the Huffman tree and that for symbols of the same length the symbol is descending from left to right. With one exception, this is also what our de- and encoder did. The exception only matters when there are codes of length 32, because in this case the first symbol of this length did not get the code 0, but 1; this is tantamount to pretending that there is a (nonexistent) leaf of length 32. This is simply false. The reference software agrees with this [1]. [1]: https://github.com/umezawatakeshi/utvideo/blob/2700a471a78402e5c340150b38e8a793ef3676f1/utv_core/HuffmanCode.cpp#L280 Reviewed-by: Paul B Mahol <onemda@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Diffstat (limited to 'libavcodec/utvideodec.c')
-rw-r--r--libavcodec/utvideodec.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/libavcodec/utvideodec.c b/libavcodec/utvideodec.c
index c07636d435..b3c4c3519b 100644
--- a/libavcodec/utvideodec.c
+++ b/libavcodec/utvideodec.c
@@ -70,7 +70,7 @@ static int build_huff10(const uint8_t *src, VLC *vlc, int *fsym)
return -1;
}
- code = 1;
+ code = 0;
for (i = last; i >= 0; i--) {
codes[i] = code >> (32 - he[i].len);
bits[i] = he[i].len;
@@ -113,7 +113,7 @@ static int build_huff(const uint8_t *src, VLC *vlc, int *fsym)
if (he[last].len > 32)
return -1;
- code = 1;
+ code = 0;
for (i = last; i >= 0; i--) {
codes[i] = code >> (32 - he[i].len);
bits[i] = he[i].len;