From patchwork Sat Sep 26 10:27:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22605 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 863B944A10F for ; Sat, 26 Sep 2020 13:30:09 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6C27B68B729; Sat, 26 Sep 2020 13:30:09 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2036068AB33 for ; Sat, 26 Sep 2020 13:30:02 +0300 (EEST) Received: by mail-wr1-f68.google.com with SMTP id z4so6653009wrr.4 for ; Sat, 26 Sep 2020 03:30:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=r0I3+MMfdZvyJvZSbafZYem75Ej9Hix/EOrX3Y2a02g=; b=Qxcbe3kRrr+8tUAWs6YmA2iGRFRxXRQN5gDBMnoT5s0PbzGC4hPmsROpemT+q1DBe9 cSmhlwU0onRwQMeCTtbe125GFj5cjH+iWsj6v7yA6MqJMtpsDtEX59p9MFpLSaTkabZb OTFK0fbcFWsL6kMOJEYqS7aTd/gKBX0zE2pyAQuWz3Audssl4cbQUZOMbKSsOq2tIs+a 7yENdtBucPIlFs7FSOI3pmOa5zJd6ogbcHIjbkoNcDpay6eZjRiwOalmKZ3A1j7gWRR4 ClQa/1aE4cUyDYdFaOdW+xPqfcNELh4gcw1u1KE1SSRF6Rjwu5VG17O7kiSxyDRkpjFq NReA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=r0I3+MMfdZvyJvZSbafZYem75Ej9Hix/EOrX3Y2a02g=; b=rxHwsNy3oiTtcCidh+8wqaJAEMbIFR7dfNLZ1XjHYi41nv81fX+Wn85ohB4Jtbkfft QA4KqXJCbK9GYUucQc8LM1KKLTczCLUPFjU148FMKJXGKJQ5RvT/vwxBPuTW61Ks/jl+ 2QjXMhotqZmDhAVDeU5fltow3zMhKus3pYNKdZQ56McwvdaPVfZRm02k7JMorkdkmz3p saaN9AH3LL3bmIwKagadg7MvlsoM1bMv6Igbhkrt5Cyjn8N9BXX+pr3mtb1qQBvSdU9G qJQIpIcs1+TU8gdoKdti5PIQKbqdufl1We42U2iBZfM8eVCgtN0kGkoMwR3paFhxeKeI gfUw== X-Gm-Message-State: AOAM531uPueuopoLLBjFijkkf/HMNnmqQuJg7NsmxpPGK/6iecDCKwph A9XTUUY7YCkXt93Rd0zQYZ1G61Fq1Us= X-Google-Smtp-Source: ABdhPJxEsEUgOdbLhK3YYnvNeSPntqa77jn4FJUnr9hRE2HApK2A/iDYjpsyzfk9/eZzoUJNTOUscw== X-Received: by 2002:adf:d845:: with SMTP id k5mr8323902wrl.285.1601116201209; Sat, 26 Sep 2020 03:30:01 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id k8sm6064867wrl.42.2020.09.26.03.30.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Sep 2020 03:30:00 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 26 Sep 2020 12:27:48 +0200 Message-Id: <20200926102804.228089-9-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> References: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 09/25] avcodec/magicyuv: Don't invert order unnecessarily X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 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. Signed-off-by: Andreas Rheinhardt --- 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);