From patchwork Sat Sep 26 10:27:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22620 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 8892D449EC5 for ; Sat, 26 Sep 2020 13:36:01 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6E11468B790; Sat, 26 Sep 2020 13:36:01 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 140A868AE72 for ; Sat, 26 Sep 2020 13:35:55 +0300 (EEST) Received: by mail-wm1-f65.google.com with SMTP id y15so1900130wmi.0 for ; Sat, 26 Sep 2020 03:35:55 -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=OaDUQ0EvQt7SOSF7Cl9gm6A0dFbsfj1x5kZNoIXkJwU=; b=D7nbKZhEWfpjet5MmG7r0EypuO7+yo8kTUfn5huNJapDpSKKY11+pLXXy0g7o1G1uc uBPmY5LwSli6muaw0gaD6Etjq0/yTth9igTdkbiHJoE4dfYmB8Y4fziFsx3wCztw9Fl3 4Ze3KN7EOtC09FmCmhR1/rxeK4jegJ2rq4UCBtMcOTCS6+S++pPUE3yP4SEPXdYH36xu aLBDWLqQruSku9fyHQfaAVWR+xmfICA/F+ZUh2bOe8XGf1L/3Ps1PWSS2WhEwtyCYbb+ wTPxwMoAKLrlHr6AD/ObQ8Ip5imUH9ZYJxN+zZDdv5hfVuBOaBCeW2eaD7c8oJGWJlFt lipw== 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=OaDUQ0EvQt7SOSF7Cl9gm6A0dFbsfj1x5kZNoIXkJwU=; b=ahbTU6P0fvSm5z+Hz1IupVOWgJRO4ubPL8o6hdPT+DV4q6mqkCDkUKG3wpp4YeJ13Q HwgIUorGjutDrq22M7N2prPu5722rydHov15AyW82D7zhAXNJ5fY4sr76lwL5ke3DOmh 7WZHDld1K6d6W9RrKgVfZuMfs+GzgH1pVUwW6sl5/fLuEaYN3wdM8eFc7j1/O3Si1KkD 5uWYyjx2SUZ+aNKXGD4/w/D+PLKC8Hym/htb/bH5LmtITfMyAUg2Yz5fbCkMwG+KBnBb RgvG9BF3e3pVkTzdGA6wjjGLjGyYZ7DJao9g9i88MKOOzD0dKHo70BXSB7FQmXkRSZqK PzMA== X-Gm-Message-State: AOAM53331T9Py5kDlaYtUQHTXH6N1KQl/BHbjO4rRQuTSCt5a8O8wUzY ERadCOkV8J06y6mET7I6v4FWFYW4PuQ= X-Google-Smtp-Source: ABdhPJzN2CqbYp802MgdCH4+/N/J7iYgtVd2GCxcwPjPbZeuATo90E2WTxjFgvnfW+YALb/abiH1tw== X-Received: by 2002:a05:600c:283:: with SMTP id 3mr2095048wmk.110.1601116207187; Sat, 26 Sep 2020 03:30:07 -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.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Sep 2020 03:30:06 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 26 Sep 2020 12:27:53 +0200 Message-Id: <20200926102804.228089-14-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 14/25] avcodec/utvideodec: Remove code duplication when creating Huffman tables 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" Signed-off-by: Andreas Rheinhardt --- libavcodec/utvideodec.c | 55 +++++------------------------------------ 1 file changed, 6 insertions(+), 49 deletions(-) diff --git a/libavcodec/utvideodec.c b/libavcodec/utvideodec.c index b3c4c3519b..f014e90606 100644 --- a/libavcodec/utvideodec.c +++ b/libavcodec/utvideodec.c @@ -40,7 +40,7 @@ #include "thread.h" #include "utvideo.h" -static int build_huff10(const uint8_t *src, VLC *vlc, int *fsym) +static int build_huff(const uint8_t *src, VLC *vlc, int *fsym, unsigned nb_elems) { int i; HuffEntry he[1024]; @@ -51,18 +51,18 @@ static int build_huff10(const uint8_t *src, VLC *vlc, int *fsym) uint32_t code; *fsym = -1; - for (i = 0; i < 1024; i++) { + for (i = 0; i < nb_elems; i++) { he[i].sym = i; he[i].len = *src++; } - qsort(he, 1024, sizeof(*he), ff_ut10_huff_cmp_len); + qsort(he, nb_elems, sizeof(*he), ff_ut10_huff_cmp_len); if (!he[0].len) { *fsym = he[0].sym; return 0; } - last = 1023; + last = nb_elems - 1; while (he[last].len == 255 && last) last--; @@ -84,49 +84,6 @@ static int build_huff10(const uint8_t *src, VLC *vlc, int *fsym) syms, sizeof(*syms), sizeof(*syms), 0); } -static int build_huff(const uint8_t *src, VLC *vlc, int *fsym) -{ - int i; - HuffEntry he[256]; - int last; - uint32_t codes[256]; - uint8_t bits[256]; - uint8_t syms[256]; - uint32_t code; - - *fsym = -1; - for (i = 0; i < 256; i++) { - he[i].sym = i; - he[i].len = *src++; - } - qsort(he, 256, sizeof(*he), ff_ut_huff_cmp_len); - - if (!he[0].len) { - *fsym = he[0].sym; - return 0; - } - - last = 255; - while (he[last].len == 255 && last) - last--; - - if (he[last].len > 32) - return -1; - - code = 0; - for (i = last; i >= 0; i--) { - codes[i] = code >> (32 - he[i].len); - bits[i] = he[i].len; - syms[i] = he[i].sym; - code += 0x80000000u >> (he[i].len - 1); - } - - return ff_init_vlc_sparse(vlc, VLC_BITS, last + 1, - bits, sizeof(*bits), sizeof(*bits), - codes, sizeof(*codes), sizeof(*codes), - syms, sizeof(*syms), sizeof(*syms), 0); -} - static int decode_plane10(UtvideoContext *c, int plane_no, uint16_t *dst, ptrdiff_t stride, int width, int height, @@ -139,7 +96,7 @@ static int decode_plane10(UtvideoContext *c, int plane_no, GetBitContext gb; int prev, fsym; - if ((ret = build_huff10(huff, &vlc, &fsym)) < 0) { + if ((ret = build_huff(huff, &vlc, &fsym, 1024)) < 0) { av_log(c->avctx, AV_LOG_ERROR, "Cannot build Huffman codes\n"); return ret; } @@ -299,7 +256,7 @@ static int decode_plane(UtvideoContext *c, int plane_no, return 0; } - if (build_huff(src, &vlc, &fsym)) { + if (build_huff(src, &vlc, &fsym, 256)) { av_log(c->avctx, AV_LOG_ERROR, "Cannot build Huffman codes\n"); return AVERROR_INVALIDDATA; }