From patchwork Tue Nov 10 10:47:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23519 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 960DE44A3F2 for ; Tue, 10 Nov 2020 12:59:28 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9981168BEB7; Tue, 10 Nov 2020 12:50:17 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 59EB168BE85 for ; Tue, 10 Nov 2020 12:50:04 +0200 (EET) Received: by mail-wm1-f67.google.com with SMTP id d142so2521283wmd.4 for ; Tue, 10 Nov 2020 02:50:04 -0800 (PST) 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:reply-to :mime-version:content-transfer-encoding; bh=PGyStSwBd4lbKsR92/+CuqSP5Trdw9Rhjj5PJtd61bw=; b=A8LgYXcu/L/SAOrslTlWyUaaTb0e3sSnthw8v8Yi+cAhUsToTcnusALo43HJPDFKtI T6p76k/sttiD72c9Mg8+sfmRQCSP7+UHpbrmDfuXby5RTFEkG179VpTp7GpHyEPXnzbW 06cZqTbmsCwO0Rtb7JYBtJ50wBwvfYKNJU7mhVII1FNKGX5Hk82IXXNO6YB6cDRhsWvF Aj610K9aOGl/nJ165fi6YH154wh67g2UusPeYLeTPUW0dshSUQQXM9LQMwLcSXdDjws2 qPhA0nmKx+frcPggVxOIdwfixmfxOkoZt2MzlJrCYT4i8VACUR49o1I0tJPkcN09Jgg1 bXEg== 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:reply-to:mime-version:content-transfer-encoding; bh=PGyStSwBd4lbKsR92/+CuqSP5Trdw9Rhjj5PJtd61bw=; b=mjlN0A3Ok/BvBw6iHSlRFGmHI/a0yIfnGmH8Wjh5i2pBiH7X97sfaR0G/TSuGzMrE2 AZDIfXmQHO/WjZyaQ1WNsPfixETPBazxO0dGB/MCMRPcMa0XdGGWh0l/LoP9v+EaATvg g5hd5KLRVqiiJ3Eqs3a2KCZWkoxbXGewhGi7FzH8Vx4F3vp4uU41uEwGIUEbJ/sREaeB OzSiTYkuEZSNT7kq7ap/uqq9/IophGDAJvTd9xY3Sajowt0XuNm9EtCGr2Z8vnCuzNne xeKiEkfVTJhYDJMg9J+loeeqaaz8vgBQ5wqQEaVb9yq57E5RlvchEbyPhPMTq2x+O0zi M2XQ== X-Gm-Message-State: AOAM533DnB2coQsjo39HSuiC+DNNG6jfkyEVKShiu32bvQ1GC1fsJ13i UYBhsgWzFHkDd5AQKytA7C8m9W3EuZ4= X-Google-Smtp-Source: ABdhPJymc6Gv++QrVWe1Xnx6VT8HqJhPPjIBkAlCwRAPp2GW0qMckpdhTcrQ6X0ujAM1amVsP0SSnA== X-Received: by 2002:a1c:3142:: with SMTP id x63mr4010918wmx.168.1605005403085; Tue, 10 Nov 2020 02:50:03 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id l24sm2572543wmi.7.2020.11.10.02.50.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 02:50:02 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 10 Nov 2020 11:47:40 +0100 Message-Id: <20201110104851.321029-44-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201110104851.321029-1-andreas.rheinhardt@gmail.com> References: <20201110104851.321029-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 043/114] avcodec/mpc8: Reduce the size of the length tables to initialize VLCs 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" After permuting both length, code as well as symbol tables so that the codes are ordered from left to right in the tree, it became apparent that the length of the codes decreases from left to right. Therefore one can run-length encode the lengths to save space. This commit implements this. Signed-off-by: Andreas Rheinhardt --- libavcodec/mpc8.c | 114 +++++++++++++++-------------- libavcodec/mpc8huff.h | 166 ++++++++++++------------------------------ 2 files changed, 104 insertions(+), 176 deletions(-) diff --git a/libavcodec/mpc8.c b/libavcodec/mpc8.c index 31b7ad14ac..ef0fd6622a 100644 --- a/libavcodec/mpc8.c +++ b/libavcodec/mpc8.c @@ -90,6 +90,21 @@ static const uint16_t vlc_offsets[13] = { 0, 640, 1184, 1748, 2298, 2426, 2554, 3066, 3578, 4106, 4618, 5196, 5708 }; +static av_cold void build_vlc(VLC *vlc, int nb_bits, + const uint8_t codes_counts[16], + const uint8_t syms[], int offset) +{ + uint8_t len[MPC8_MAX_VLC_SIZE]; + unsigned num = 0; + + for (int i = 16; i > 0; i--) + for (unsigned tmp = num + codes_counts[i - 1]; num < tmp; num++) + len[num] = i; + + ff_init_vlc_from_lengths(vlc, nb_bits, num, len, 1, + syms, 1, 1, offset, INIT_VLC_USE_NEW_STATIC); +} + static av_cold int mpc8_decode_init(AVCodecContext * avctx) { int i; @@ -97,7 +112,6 @@ static av_cold int mpc8_decode_init(AVCodecContext * avctx) GetBitContext gb; static int vlc_initialized = 0; int channels; - static VLC_TYPE codes_table[5708][2]; if(avctx->extradata_size < 2){ @@ -133,77 +147,65 @@ static av_cold int mpc8_decode_init(AVCodecContext * avctx) if(vlc_initialized) return 0; av_log(avctx, AV_LOG_DEBUG, "Initing VLC\n"); - INIT_VLC_STATIC_FROM_LENGTHS(&band_vlc, MPC8_BANDS_BITS, MPC8_BANDS_SIZE, - mpc8_bands_bits, 1, - mpc8_bands_syms, 1, 1, 0, 0, 542); - - INIT_VLC_STATIC_FROM_LENGTHS(&q1_vlc, MPC8_Q1_BITS, MPC8_Q1_SIZE, - mpc8_q1_bits, 1, - mpc8_q1_syms, 1, 1, 0, 0, 520); - INIT_VLC_STATIC_FROM_LENGTHS(&q9up_vlc, MPC8_Q9UP_BITS, MPC8_Q9UP_SIZE, - mpc8_q9up_bits, 1, - mpc8_q9up_syms, 1, 1, 0, 0, 524); - - INIT_VLC_STATIC_FROM_LENGTHS(&scfi_vlc[0], MPC8_SCFI0_BITS, MPC8_SCFI0_SIZE, - mpc8_scfi0_bits, 1, - mpc8_scfi0_syms, 1, 1, 0, 0, 1 << MPC8_SCFI0_BITS); - INIT_VLC_STATIC_FROM_LENGTHS(&scfi_vlc[1], MPC8_SCFI1_BITS, MPC8_SCFI1_SIZE, - mpc8_scfi1_bits, 1, - mpc8_scfi1_syms, 1, 1, 0, 0, 1 << MPC8_SCFI1_BITS); - - INIT_VLC_STATIC_FROM_LENGTHS(&dscf_vlc[0], MPC8_DSCF0_BITS, MPC8_DSCF0_SIZE, - mpc8_dscf0_bits, 1, - mpc8_dscf0_syms, 1, 1, 0, 0, 560); - INIT_VLC_STATIC_FROM_LENGTHS(&dscf_vlc[1], MPC8_DSCF1_BITS, MPC8_DSCF1_SIZE, - mpc8_dscf1_bits, 1, - mpc8_dscf1_syms, 1, 1, 0, 0, 598); - - INIT_VLC_STATIC_FROM_LENGTHS(&q3_vlc[0], MPC8_Q3_BITS, MPC8_Q3_SIZE, - mpc8_q3_bits, 1, - mpc8_q3_syms, 1, 1, MPC8_Q3_OFFSET, 0, 512); - INIT_VLC_STATIC_FROM_LENGTHS(&q3_vlc[1], MPC8_Q4_BITS, MPC8_Q4_SIZE, - mpc8_q4_bits, 1, - mpc8_q4_syms, 1, 1, MPC8_Q4_OFFSET, 0, 516); +#define INIT_VLC(vlc, bits, len_counts, symbols, offset, static_size) \ + do { \ + static VLC_TYPE table[static_size][2]; \ + (vlc)->table = table; \ + (vlc)->table_allocated = static_size; \ + build_vlc(vlc, bits, len_counts, symbols, offset); \ + } while (0) + + + INIT_VLC(&band_vlc, MPC8_BANDS_BITS, + mpc8_bands_len_counts, mpc8_bands_syms, 0, 542); + + INIT_VLC(&q1_vlc, MPC8_Q1_BITS, + mpc8_q1_len_counts, mpc8_q1_syms, 0, 520); + INIT_VLC(&q9up_vlc, MPC8_Q9UP_BITS, + mpc8_q9up_len_counts, mpc8_q9up_syms, 0, 524); + + INIT_VLC(&scfi_vlc[0], MPC8_SCFI0_BITS, + mpc8_scfi_len_counts[0], mpc8_scfi0_syms, 0, 1 << MPC8_SCFI0_BITS); + INIT_VLC(&scfi_vlc[1], MPC8_SCFI1_BITS, + mpc8_scfi_len_counts[1], mpc8_scfi1_syms, 0, 1 << MPC8_SCFI1_BITS); + + INIT_VLC(&dscf_vlc[0], MPC8_DSCF0_BITS, + mpc8_dscf_len_counts[0], mpc8_dscf0_syms, 0, 560); + INIT_VLC(&dscf_vlc[1], MPC8_DSCF1_BITS, + mpc8_dscf_len_counts[1], mpc8_dscf1_syms, 0, 598); + + INIT_VLC(&q3_vlc[0], MPC8_Q3_BITS, + mpc8_q3_len_counts, mpc8_q3_syms, MPC8_Q3_OFFSET, 512); + INIT_VLC(&q3_vlc[1], MPC8_Q4_BITS, + mpc8_q4_len_counts, mpc8_q4_syms, MPC8_Q4_OFFSET, 516); for(i = 0; i < 2; i++){ res_vlc[i].table = &codes_table[vlc_offsets[0+i]]; res_vlc[i].table_allocated = vlc_offsets[1+i] - vlc_offsets[0+i]; - ff_init_vlc_from_lengths(&res_vlc[i], MPC8_RES_BITS, MPC8_RES_SIZE, - mpc8_res_bits[i], 1, - mpc8_res_syms[i], 1, 1, - 0, INIT_VLC_USE_NEW_STATIC); + build_vlc(&res_vlc[i], MPC8_RES_BITS, + mpc8_res_len_counts[i], mpc8_res_syms[i], 0); q2_vlc[i].table = &codes_table[vlc_offsets[2+i]]; q2_vlc[i].table_allocated = vlc_offsets[3+i] - vlc_offsets[2+i]; - ff_init_vlc_from_lengths(&q2_vlc[i], MPC8_Q2_BITS, MPC8_Q2_SIZE, - mpc8_q2_bits[i], 1, - mpc8_q2_syms[i], 1, 1, - 0, INIT_VLC_USE_NEW_STATIC); + build_vlc(&q2_vlc[i], MPC8_Q2_BITS, + mpc8_q2_len_counts[i], mpc8_q2_syms[i], 0); quant_vlc[0][i].table = &codes_table[vlc_offsets[4+i]]; quant_vlc[0][i].table_allocated = vlc_offsets[5+i] - vlc_offsets[4+i]; - ff_init_vlc_from_lengths(&quant_vlc[0][i], MPC8_Q5_BITS, MPC8_Q5_SIZE, - mpc8_q5_bits[i], 1, - mpc8_q5_syms[i], 1, 1, - MPC8_Q5_OFFSET, INIT_VLC_USE_NEW_STATIC); + build_vlc(&quant_vlc[0][i], MPC8_Q5_BITS, + mpc8_q5_len_counts[i], mpc8_q5_syms[i], MPC8_Q5_OFFSET); quant_vlc[1][i].table = &codes_table[vlc_offsets[6+i]]; quant_vlc[1][i].table_allocated = vlc_offsets[7+i] - vlc_offsets[6+i]; - ff_init_vlc_from_lengths(&quant_vlc[1][i], MPC8_Q6_BITS, MPC8_Q6_SIZE, - mpc8_q6_bits[i], 1, - mpc8_q6_syms[i], 1, 1, - MPC8_Q6_OFFSET, INIT_VLC_USE_NEW_STATIC); + build_vlc(&quant_vlc[1][i], MPC8_Q6_BITS, + mpc8_q6_len_counts[i], mpc8_q6_syms[i], MPC8_Q6_OFFSET); quant_vlc[2][i].table = &codes_table[vlc_offsets[8+i]]; quant_vlc[2][i].table_allocated = vlc_offsets[9+i] - vlc_offsets[8+i]; - ff_init_vlc_from_lengths(&quant_vlc[2][i], MPC8_Q7_BITS, MPC8_Q7_SIZE, - mpc8_q7_bits[i], 1, - mpc8_q7_syms[i], 1, 1, - MPC8_Q7_OFFSET, INIT_VLC_USE_NEW_STATIC); + build_vlc(&quant_vlc[2][i], MPC8_Q7_BITS, + mpc8_q7_len_counts[i], mpc8_q7_syms[i], MPC8_Q7_OFFSET); quant_vlc[3][i].table = &codes_table[vlc_offsets[10+i]]; quant_vlc[3][i].table_allocated = vlc_offsets[11+i] - vlc_offsets[10+i]; - ff_init_vlc_from_lengths(&quant_vlc[3][i], MPC8_Q8_BITS, MPC8_Q8_SIZE, - mpc8_q8_bits[i], 1, - mpc8_q8_syms[i], 1, 1, - MPC8_Q8_OFFSET, INIT_VLC_USE_NEW_STATIC); + build_vlc(&quant_vlc[3][i], MPC8_Q8_BITS, + mpc8_q8_len_counts[i], mpc8_q8_syms[i], MPC8_Q8_OFFSET); } vlc_initialized = 1; diff --git a/libavcodec/mpc8huff.h b/libavcodec/mpc8huff.h index 687c9f7e98..8838751fd6 100644 --- a/libavcodec/mpc8huff.h +++ b/libavcodec/mpc8huff.h @@ -24,6 +24,8 @@ #include +#define MPC8_MAX_VLC_SIZE 256 + #define MPC8_BANDS_SIZE 33 #define MPC8_BANDS_BITS 9 @@ -31,9 +33,8 @@ static const uint8_t mpc8_bands_syms[MPC8_BANDS_SIZE] = { 13, 19, 10, 11, 12, 14, 15, 16, 17, 18, 20, 21, 22, 9, 23, 24, 25, 8, 26, 27, 7, 28, 5, 6, 29, 4, 3, 30, 2, 31, 1, 32, 0 }; -static const uint8_t mpc8_bands_bits[MPC8_BANDS_SIZE] = { - 13, 13, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 10, 10, - 10, 9, 9, 8, 8, 8, 7, 6, 6, 5, 5, 3, 2, 1 +static const uint8_t mpc8_bands_len_counts[16] = { + 1, 1, 1, 0, 2, 2, 1, 3, 2, 3, 4, 11, 2, 0, 0, 0 }; #define MPC8_SCFI0_SIZE 4 @@ -42,9 +43,6 @@ static const uint8_t mpc8_bands_bits[MPC8_BANDS_SIZE] = { static const uint8_t mpc8_scfi0_syms[MPC8_SCFI0_SIZE] = { 0, 1, 3, 2 }; -static const uint8_t mpc8_scfi0_bits[MPC8_SCFI0_SIZE] = { - 3, 3, 2, 1 -}; #define MPC8_SCFI1_SIZE 16 #define MPC8_SCFI1_BITS 7 @@ -52,8 +50,10 @@ static const uint8_t mpc8_scfi0_bits[MPC8_SCFI0_SIZE] = { static const uint8_t mpc8_scfi1_syms[MPC8_SCFI1_SIZE] = { 1, 4, 0, 2, 3, 8, 12, 5, 6, 7, 9, 13, 11, 14, 10, 15 }; -static const uint8_t mpc8_scfi1_bits[MPC8_SCFI1_SIZE] = { - 7, 7, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 3, 3, 2, 2 + +static const uint8_t mpc8_scfi_len_counts[2][16] = { + { 1, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 2, 2, 0, 5, 5, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, }; #define MPC8_DSCF0_SIZE 64 @@ -65,12 +65,6 @@ static const uint8_t mpc8_dscf0_syms[MPC8_DSCF0_SIZE] = { 17, 18, 41, 42, 43, 19, 20, 21, 22, 40, 23, 24, 38, 39, 25, 28, 37, 26, 27, 29, 30, 32, 36, 33, 34, 35, }; -static const uint8_t mpc8_dscf0_bits[MPC8_DSCF0_SIZE] = { - 14, 14, 14, 14, 14, 14, 13, 13, 13, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, - 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 8, 8, - 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 6, 6, 6, 6, 5, 5, 5, 4, 4, - 4, 4, 4, 4, 3, 3, 3 -}; #define MPC8_DSCF1_SIZE 65 #define MPC8_DSCF1_BITS 9 @@ -81,11 +75,10 @@ static const uint8_t mpc8_dscf1_syms[MPC8_DSCF1_SIZE] = { 44, 45, 18, 19, 20, 41, 42, 21, 22, 39, 40, 23, 24, 38, 25, 37, 26, 35, 36, 27, 28, 34, 29, 30, 31, 32, 33, }; -static const uint8_t mpc8_dscf1_bits[MPC8_DSCF1_SIZE] = { - 15, 15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 12, 12, - 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, - 10, 10, 9, 9, 9, 9, 9, 8, 8, 8, 8, 7, 7, 7, 6, 6, 5, 5, 5, - 4, 4, 4, 3, 3, 3, 3, 3 + +static const uint8_t mpc8_dscf_len_counts[2][16] = { + { 0, 0, 3, 6, 3, 4, 5, 7, 7, 9, 6, 5, 3, 6, 0, 0 }, + { 0, 0, 5, 3, 3, 2, 3, 4, 5, 7, 7, 9, 6, 5, 6, 0 }, }; #define MPC8_RES_SIZE 17 @@ -99,13 +92,10 @@ static const uint8_t mpc8_res_syms[2][MPC8_RES_SIZE] = { 8, 9, 10, 11, 7, 12, 6, 13, 5, 4, 14, 3, 15, 2, 0, 1, 16, } }; -static const uint8_t mpc8_res_bits[2][MPC8_RES_SIZE] = { - { - 16, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 - }, - { - 14, 14, 14, 14, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 2, 2 - } + +static const uint8_t mpc8_res_len_counts[2][16] = { + { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2 }, + { 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 4, 0, 0 }, }; #define MPC8_Q1_SIZE 19 @@ -114,8 +104,9 @@ static const uint8_t mpc8_res_bits[2][MPC8_RES_SIZE] = { static const uint8_t mpc8_q1_syms[MPC8_Q1_SIZE] = { 17, 18, 16, 15, 14, 13, 12, 0, 11, 1, 2, 8, 9, 10, 3, 4, 5, 6, 7, }; -static const uint8_t mpc8_q1_bits[MPC8_Q1_SIZE] = { - 12, 12, 11, 10, 9, 8, 7, 6, 5, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3 + +static const uint8_t mpc8_q1_len_counts[16] = { + 0, 0, 5, 5, 1, 1, 1, 1, 1, 1, 1, 2, 0, 0, 0, 0 }; #define MPC8_Q9UP_SIZE 256 @@ -141,21 +132,9 @@ static const uint8_t mpc8_q9up_syms[MPC8_Q9UP_SIZE] = { 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 148, 127, 128, }; -static const uint8_t mpc8_q9up_bits[MPC8_Q9UP_SIZE] = { - 11, 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 9, - 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, - 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, - 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, - 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 6, 6 + +static const uint8_t mpc8_q9up_len_counts[16] = { + 0, 0, 0, 0, 0, 2, 38, 134, 71, 9, 2, 0, 0, 0, 0, 0 }; #define MPC8_Q2_SIZE 125 @@ -185,35 +164,18 @@ static const uint8_t mpc8_q2_syms[2][MPC8_Q2_SIZE] = { 82, 86, 87, 92, 62, } }; -static const uint8_t mpc8_q2_bits[2][MPC8_Q2_SIZE] = { -{ - 13, 13, 13, 13, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, - 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, - 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, - 6, 6, 6, 6, 4, 4, 4, 4, 4, 4, 3 -}, -{ - 12, 12, 12, 12, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, - 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, - 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4 -} + +static const uint8_t mpc8_q2_len_counts[2][16] = { + { 0, 0, 1, 6, 0, 17, 9, 24, 24, 9, 27, 4, 4, 0, 0, 0 }, + { 0, 0, 0, 1, 16, 10, 6, 48, 9, 27, 4, 4, 0, 0, 0, 0 }, }; #define MPC8_Q3_SIZE 49 #define MPC8_Q3_BITS 9 #define MPC8_Q3_OFFSET -48 -static const uint8_t mpc8_q3_bits[MPC8_Q3_SIZE] = { - 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, - 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 3, +static const uint8_t mpc8_q3_len_counts[16] = { + 0, 0, 1, 6, 6, 11, 13, 8, 4, 0, 0, 0, 0, 0, 0, 0 }; static const uint8_t mpc8_q3_syms[MPC8_Q3_SIZE] = { 13, 3, 109, 99, 14, 2, 29, 19, 93, 83, 110, 98, 15, 0, 1, @@ -226,12 +188,8 @@ static const uint8_t mpc8_q3_syms[MPC8_Q3_SIZE] = { #define MPC8_Q4_BITS 9 #define MPC8_Q4_OFFSET -64 -static const uint8_t mpc8_q4_bits[MPC8_Q4_SIZE] = { - 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, - 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 4, +static const uint8_t mpc8_q4_len_counts[16] = { + 0, 0, 0, 1, 12, 23, 14, 19, 8, 4, 0, 0, 0, 0, 0, 0 }; static const uint8_t mpc8_q4_syms[MPC8_Q4_SIZE] = { 12, 4, 140, 132, 13, 3, 28, 20, 124, 116, 141, 131, 14, 1, 2, @@ -254,13 +212,10 @@ static const uint8_t mpc8_q5_syms[2][MPC8_Q5_SIZE] = { 0, 1, 13, 14, 2, 12, 3, 4, 10, 11, 5, 6, 7, 8, 9, } }; -static const uint8_t mpc8_q5_bits[2][MPC8_Q5_SIZE] = { -{ - 7, 7, 7, 7, 6, 6, 5, 5, 4, 4, 3, 3, 3, 3, 2 -}, -{ - 6, 6, 6, 6, 5, 5, 4, 4, 4, 4, 3, 3, 3, 3, 3 -} + +static const uint8_t mpc8_q5_len_counts[2][16] = { + { 0, 1, 4, 2, 2, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 5, 4, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, }; #define MPC8_Q6_SIZE 31 @@ -277,15 +232,10 @@ static const uint8_t mpc8_q6_syms[2][MPC8_Q6_SIZE] = { 23, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, } }; -static const uint8_t mpc8_q6_bits[2][MPC8_Q6_SIZE] = { -{ - 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 7, 7, 6, 6, 6, 6, 6, - 6, 6, 5, 5, 5, 4, 4, 4, 4, 3, 3, 2 -}, -{ - 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 5, 5, 5, 5, 5, - 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 -} + +static const uint8_t mpc8_q6_len_counts[2][16] = { + { 0, 1, 2, 4, 3, 7, 2, 4, 8, 0, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 11, 6, 4, 6, 4, 0, 0, 0, 0, 0, 0, 0, 0 }, }; #define MPC8_Q7_SIZE 63 @@ -306,19 +256,10 @@ static const uint8_t mpc8_q7_syms[2][MPC8_Q7_SIZE] = { 36, 37, 38, 39, 40, 41, } }; -static const uint8_t mpc8_q7_bits[2][MPC8_Q7_SIZE] = { -{ - 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, - 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 5, 5, 5, - 5, 4, 4, 3, 3, 2 -}, -{ - 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, - 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5 -} + +static const uint8_t mpc8_q7_len_counts[2][MPC8_Q7_SIZE] = { + { 0, 1, 2, 2, 4, 6, 10, 10, 12, 16, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 20, 15, 10, 14, 4, 0, 0, 0, 0, 0, 0, 0 }, }; #define MPC8_Q8_SIZE 127 @@ -349,25 +290,10 @@ static const uint8_t mpc8_q8_syms[2][MPC8_Q8_SIZE] = { 69, 70, 71, 72, 73, 74, 76, } }; -static const uint8_t mpc8_q8_bits[2][MPC8_Q8_SIZE] = { -{ - 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, - 11, 11, 11, 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, - 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, - 6, 6, 6, 6, 6, 6, 5, 5, 5, 4, 3, 3, 2 -}, -{ - 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, - 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6 -} + +static const uint8_t mpc8_q8_len_counts[2][16] = { + { 0, 1, 2, 1, 3, 8, 8, 15, 24, 42, 17, 6, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 26, 55, 38, 8, 0, 0, 0, 0, 0, 0, 0 }, }; #endif /* AVCODEC_MPC8HUFF_H */