[FFmpeg-devel] [PATCH 09/25] avcodec/magicyuv: Don't invert order unnecessarily
Paul B Mahol
onemda at gmail.com
Sat Sep 26 14:03:01 EEST 2020
On Sat, Sep 26, 2020 at 12:27:48PM +0200, Andreas Rheinhardt wrote:
> The MagicYUV decoder currently sets both the length and the symbol field
> of an array of HuffEntries; hereby the symbol of the ith entry (0-based)
> is just i. Then said array gets sorted so that entries with greater
> length are at the end and entries with the same length are ordered so
> that those with smaller symbols are at the end. Afterwards the newly
> sorted array is traversed in reverse order. This commit instead inverts
> the ordering and traverses the array in its ordinary order in order to
> simplify understanding.
apply as you wish.
>
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
> ---
> This commit actually only exists to simplify understanding of the next
> two commits; apart from that, it is unnecessary.
>
> libavcodec/magicyuv.c | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/libavcodec/magicyuv.c b/libavcodec/magicyuv.c
> index 93ee739093..1b3f4cfc6b 100644
> --- a/libavcodec/magicyuv.c
> +++ b/libavcodec/magicyuv.c
> @@ -77,24 +77,23 @@ typedef struct MagicYUVContext {
> static int huff_cmp_len(const void *a, const void *b)
> {
> const HuffEntry *aa = a, *bb = b;
> - return (aa->len - bb->len) * 4096 + bb->sym - aa->sym;
> + return (bb->len - aa->len) * 4096 + aa->sym - bb->sym;
> }
>
> static int huff_build(HuffEntry he[], VLC *vlc, int nb_elems)
> {
> uint32_t code;
> - int i;
>
> AV_QSORT(he, nb_elems, HuffEntry, huff_cmp_len);
>
> code = 1;
> - for (i = nb_elems - 1; i >= 0; i--) {
> + for (unsigned i = 0; i < nb_elems; i++) {
> he[i].code = code >> (32 - he[i].len);
> code += 0x80000000u >> (he[i].len - 1);
> }
>
> ff_free_vlc(vlc);
> - return ff_init_vlc_sparse(vlc, FFMIN(he[nb_elems - 1].len, 12), nb_elems,
> + return ff_init_vlc_sparse(vlc, FFMIN(he[0].len, 12), nb_elems,
> &he[0].len, sizeof(he[0]), sizeof(he[0].len),
> &he[0].code, sizeof(he[0]), sizeof(he[0].code),
> &he[0].sym, sizeof(he[0]), sizeof(he[0].sym), 0);
> --
> 2.25.1
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".
More information about the ffmpeg-devel
mailing list