[FFmpeg-devel] [PATCH 1/8] avcodec/magicyuv: Don't invert Huffman table symbols twice

Andreas Rheinhardt andreas.rheinhardt at gmail.com
Tue Sep 1 12:42:13 EEST 2020

Paul B Mahol:
> On 8/31/20, Andreas Rheinhardt <andreas.rheinhardt at gmail.com> wrote:
>> When the MagicYUV decoder builds Huffman tables from an array of code
>> lengths, it proceeds as follows: First it copies the entries of the
>> array of lengths into an array of HuffEntries (a struct which contains
>> a length and a symbol field); it also sets the symbol field in
>> descending order from nb_elem - 1 to 0, where nb_elem is the common number
>> of elements of the length and HuffEntry arrays. Then the HuffEntry array
>> is sorted lexicographically: a > b iff a.len > b.len or a.len == b.len and
>> a.sym > b.sym. Afterwards the symbols of the so sorted array are
>> inverted again (i.e. each symbol sym is replaced by nb_elem - sym).
>> Yet inverting can easily be avoided altogether: Just modify the order so
>> that smaller symbols correspond to bigger HuffEntries. This leads to the
>> same permutation as the current code does and given that the two
>> inversions just cancel each other out, the result is the same.
>> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
>> ---
>>  libavcodec/magicyuv.c | 18 +++++++++---------
>>  1 file changed, 9 insertions(+), 9 deletions(-)
> LGTM whole patch set.
Applied. Thanks for testing and reviewing.

- Andreas

More information about the ffmpeg-devel mailing list