From patchwork Fri Nov 20 07:19:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23948 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:c00a:0:0:0:0:0 with SMTP id c10csp953450ybf; Thu, 19 Nov 2020 23:33:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJzkt2j9U+c0iBb6JQzDrfURyyBr6TbtP5sUYV+MRlH6xaewv2CaC4xQxlT9sNX5xuyIrJ1x X-Received: by 2002:a5d:4d86:: with SMTP id b6mr14048537wru.369.1605857620036; Thu, 19 Nov 2020 23:33:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605857620; cv=none; d=google.com; s=arc-20160816; b=FCQSW0+rxJRqEKoxlE6fFAJuNnOevN+g+75ku92j7b5X73ceXdA6AVFmJHCHgUSFaa LktBubi1VblUF9brqGiy1q8WnBEF11yDHPziJt/1m7l7G6gZISim+htimSWdzsEAaz+A q2HAegZXfnEqsbrcspfIPE0isYpT3Cih06etMsaMXxsJybAEzCI2rdVAXMEGLdKMtPoG UVUpi1wWSUZGbcnnXOr0cO6arzljT/QImvYcez8UKtvjcd5tmCU7FTCa5Jwue6UsH7wC tzDRC3JVXVIimgAslxopFptc+bthszqiBv89ovoyMp/fxP54j0dRjdruL3b20nshFWB3 eUvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=JAaE/VEFjC89KdTi4nq5GHExu5RK62L1RmS+dT+2ibI=; b=myL2ubDCx5eEynvt5IIW28sJOdtu8jR5UxGvG3neJddJuJPvb0dsR6FVMjWWrZ9FC/ hV0J3h2gEijOKJOrHMQnAOuz9ojf0M2hIm1GIZ07IQq3cxR0vALWOq34hTd5dsfEs7Ny 9YyiNlgrWtWzTzb9sowIbTqAl7dL0T2iD8IArObQkSYbGaGPEd5UO44hRiWW7AUkRH0h jpPs12kFRNHLCDgbtRm+JqX9qgSbn6Grc6BHlOcNUEvoYAJxK6F//EQXxsf+NEInVd8A m9+FxfldlblBiZn908OlAE51Z8RMDGf9zc6pR1nOj13snOGpdvtMnUfxeY9UL7lbrr5H S7jA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=OaIc9wYF; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 10si2205894wmo.126.2020.11.19.23.33.39; Thu, 19 Nov 2020 23:33:40 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=OaIc9wYF; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A7C5068BB54; Fri, 20 Nov 2020 09:25:15 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f68.google.com (mail-ej1-f68.google.com [209.85.218.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6FBDB68BA26 for ; Fri, 20 Nov 2020 09:25:03 +0200 (EET) Received: by mail-ej1-f68.google.com with SMTP id f23so11521222ejk.2 for ; Thu, 19 Nov 2020 23:25:03 -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=qfbOuO/Vp9fOQYEE+AAXbscEqj7xAnkyo1tPtyDdPqo=; b=OaIc9wYFKPjK3TN/5gf/Xt+SzQIYa8URU/2Bmr+YLukgrvmdyDyUjwfC4CYRfCKXEE 35m5SItFUYa6p3AQC5GpiPnfNJY2i5FGu8esIdRgEads/8SrjeUrcHDNVkSLxl3UavIn 0tnbP5pJqxmb/GPGP13+7OTt5My5DawGPVVn6feVTw3QA9Wdr8lx4AwBIjUos/s1XY1p 8z0XwXJEpJogO+S6HnzSJnC8BA/+d7yk4pA1oW3zUeqhk1vdQCxRarOj10UwQWzKXHtz N/Qy6J28jpSyITIPOzFj8SRfXdA3LM+CYwdnaWk/u7em1ujbvm4n9riELVCTPQ4roHWi 9BLg== 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=qfbOuO/Vp9fOQYEE+AAXbscEqj7xAnkyo1tPtyDdPqo=; b=FxWI4X2dvD4nys7nqliaM63jJiZa568JTmteFUWlvYncSHTW02hRVwwH0f81B/XlgA Y5IqPeClyMoYjzZfrRMiUJqE5uxUw0mgeAzWG8x70Llq8vnQUHi1MQBZ8t97wovM4K4I Pm664BwHCzJk0mM7R18Bv6bgk8dZGx/MW85xisvl2K26Ka7nfKIxJZXoZ4OQS7WcSZVS l1LtOlP83S+c+uTmKn3YVPG+0Ww/mryduV0IlfLtJ0aW0ztHZASXG59H0ygVQTuKEeKV 4WpCFaYhTEAg7Gxs1Wjpu72nnMbACvuyXQzPG3/czvfqXfedrcDl6bKVqNQuA59wdzPI +NVA== X-Gm-Message-State: AOAM532wSJLvNZ2Wy98SkfO1rZbIeUnH0cEXTjMZRHxRtHK4vkh/t39p VAtPa6TRDasb0sAHNHZzBReBcup4zOjUCg== X-Received: by 2002:a17:907:10d9:: with SMTP id rv25mr32402955ejb.437.1605857102243; Thu, 19 Nov 2020 23:25:02 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id lz27sm779419ejb.39.2020.11.19.23.25.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2020 23:25:01 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 20 Nov 2020 08:19:24 +0100 Message-Id: <20201120072116.818090-52-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201120072116.818090-1-andreas.rheinhardt@gmail.com> References: <20201120072116.818090-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 051/162] 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" X-TUID: kS9yda7nrzaT Content-Length: 28353 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 b5f89c845b..64b1967d8d 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, NULL); +} + 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, NULL); + 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, NULL); + 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, NULL); + 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, NULL); + 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, NULL); + 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, NULL); + 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 */