From patchwork Fri Nov 20 07:18:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23916 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 87A8A44AD6B for ; Fri, 20 Nov 2020 09:56:04 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 73A3068BEB5; Fri, 20 Nov 2020 09:56:04 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D9DAA68BEB2 for ; Fri, 20 Nov 2020 09:55:57 +0200 (EET) Received: by mail-wr1-f67.google.com with SMTP id b6so9058198wrt.4 for ; Thu, 19 Nov 2020 23:55:57 -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=ejCV1T6PjA2UVOoFv6S/2eW6A4Yp7o+N6BiZB3fRkCs=; b=dNakOhPF9A1DOmUgS0mbnwIV00VwxxPyU1Bf/Wu3lwjPYALlIr1gCf+AwVHaYxfLM8 pPnXbcELLCDnXKEV+NPMuKWXECPqqr0pYUhFKu0Nz+Ml98n/5/lCVK8gXAHkvGatMYM8 SAW5w/L2+R2ph6sCuLc31zyDPafm0kZ5XuNZCTiO9J60o35j/SWPQiB5PQjooQ7LUUZB 10KyHzTM/Mce5ayF7PIUWYCiyVAh+u0ZSwiC7phc11kjfaHrIh/SHsaxZF5pTFJN3tDr 8fXQV3sqhFcRsPyU6JBe1QACg/puBSqT/CFxYG/acZ8Onp3kNUaC2GO1qK7JXu3E/ZNE ZpBA== 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=ejCV1T6PjA2UVOoFv6S/2eW6A4Yp7o+N6BiZB3fRkCs=; b=iPAwGI0qCGNfC9YlzO2myv3RDpkEFwpwkxWRdmkUjg7Daos4EgKMF+1J9tbCWY7X5H VaGokr3AOhsnCswccCXQzzfme1dgs4DjU0VhzQKOb4CuC83cqlmTVn2xMVh2aCDhLaWq 94veEnYFQxQMU+aTWHdNRCLfIB0XOoQaewnk9LCZB/NZrXOHQit1aDayb5XT8CBPLBAT BHJ8AXXG/9p4OdrZ0J020qMlAShm9Zz3SLm+2XofQc3ndnZIUG1jgzg5UtRC2i6KWoUL vV4qct1wZNU+QL9qP8TDMHol+IeTe684cWi03CdYEItjX42sR8EX5+lJBllKH29jSV1a Mq/w== X-Gm-Message-State: AOAM532TVq6bZWD7Mjw3xsvndJ4XTILAxUpQMF6gdCE1yxDqT9QthG0c ZKLv1cKbo7DAG5hMvowztgYgBoqLUfCNnQ== X-Google-Smtp-Source: ABdhPJwPXkVkqXgMZlLuTG1fbOEBpFWbjPv5wOMobTux5moW2hSrrP8lMsz33nh2dlkiZ+XAH0JOiw== X-Received: by 2002:aa7:cdd3:: with SMTP id h19mr34990845edw.330.1605857059540; Thu, 19 Nov 2020 23:24:19 -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.24.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2020 23:24:19 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 20 Nov 2020 08:18:46 +0100 Message-Id: <20201120072116.818090-14-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 013/162] avcodec/imc: Make Huffman tables smaller 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 IMC decoder uses Huffman tables which are created at runtime from length tables of type uint8_t and code tables of type uint16_t together with an implicit symbols table (i.e. symbol[i] == i). This commit changes this: All three tables are subjected to the same permutation to order the codes from left to right in the tree; afterwards the codes can be omitted because they are easily computable at runtime from the lengths, whereas the symbols need to be explicitly coded now. But said symbols fit into an uint8_t, so one saves space. Signed-off-by: Andreas Rheinhardt --- libavcodec/imc.c | 7 +++-- libavcodec/imcdata.h | 66 ++++++++++++++++++++++---------------------- 2 files changed, 37 insertions(+), 36 deletions(-) diff --git a/libavcodec/imc.c b/libavcodec/imc.c index 70ad5b1dbd..5a1649ab62 100644 --- a/libavcodec/imc.c +++ b/libavcodec/imc.c @@ -239,9 +239,10 @@ static av_cold int imc_decode_init(AVCodecContext *avctx) for (j = 0; j < 4; j++) { huffman_vlc[i][j].table = &vlc_tables[vlc_offsets[i * 4 + j]]; huffman_vlc[i][j].table_allocated = vlc_offsets[i * 4 + j + 1] - vlc_offsets[i * 4 + j]; - init_vlc(&huffman_vlc[i][j], IMC_VLC_BITS, imc_huffman_sizes[i], - imc_huffman_lens[i][j], 1, 1, - imc_huffman_bits[i][j], 2, 2, INIT_VLC_USE_NEW_STATIC); + ff_init_vlc_from_lengths(&huffman_vlc[i][j], IMC_VLC_BITS, imc_huffman_sizes[i], + imc_huffman_lens[i][j], 1, + imc_huffman_syms[i][j], 1, 1, + 0, INIT_VLC_USE_NEW_STATIC, NULL); } } diff --git a/libavcodec/imcdata.h b/libavcodec/imcdata.h index 64e7c7185e..46037bd555 100644 --- a/libavcodec/imcdata.h +++ b/libavcodec/imcdata.h @@ -114,55 +114,55 @@ static const uint8_t imc_huffman_sizes[4] = { static const uint8_t imc_huffman_lens[4][4][18] = { { - { 16, 15, 13, 11, 8, 5, 3, 1, 2, 4, 6, 9, 10, 12, 14, 16, 7, 0 }, - { 10, 8, 7, 6, 4, 4, 3, 2, 2, 3, 4, 6, 7, 9, 11, 11, 7, 0 }, - { 15, 15, 14, 11, 8, 6, 4, 2, 1, 4, 5, 7, 9, 10, 12, 13, 4, 0 }, - { 13, 11, 10, 8, 6, 4, 2, 2, 2, 3, 5, 7, 9, 12, 15, 15, 14, 0 }, + { 1, 2, 5, 6, 11, 12, 15, 16, 16, 14, 13, 10, 9, 8, 7, 4, 3 }, + { 2, 3, 3, 4, 4, 4, 6, 6, 7, 7, 7, 8, 9, 10, 11, 11, 2 }, + { 1, 4, 4, 7, 9, 10, 12, 15, 15, 14, 13, 11, 8, 6, 5, 4, 2 }, + { 2, 2, 4, 8, 9, 14, 15, 15, 13, 12, 11, 10, 7, 6, 5, 3, 2 }, }, { - { 14, 12, 10, 8, 7, 4, 2, 2, 2, 3, 5, 7, 9, 11, 13, 14, 7, 0 }, - { 14, 13, 11, 8, 6, 4, 3, 2, 2, 3, 5, 7, 9, 10, 12, 14, 3, 0 }, - { 13, 12, 10, 7, 5, 4, 3, 2, 2, 3, 4, 6, 8, 9, 11, 13, 4, 0 }, - { 13, 12, 10, 7, 5, 4, 3, 2, 2, 3, 4, 6, 8, 9, 11, 13, 4, 0 }, + { 2, 2, 3, 4, 7, 7, 10, 11, 12, 14, 14, 13, 9, 8, 7, 5, 2 }, + { 2, 3, 14, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 3, 2 }, + { 2, 3, 3, 4, 4, 5, 7, 9, 11, 12, 13, 13, 10, 8, 6, 4, 2 }, + { 2, 3, 3, 4, 4, 5, 7, 9, 11, 12, 13, 13, 10, 8, 6, 4, 2 }, }, { - { 16, 14, 12, 10, 8, 5, 3, 1, 2, 4, 7, 9, 11, 13, 15, 17, 6, 17 }, - { 15, 13, 11, 8, 6, 4, 2, 2, 2, 3, 5, 7, 10, 12, 14, 16, 9, 16 }, - { 14, 12, 11, 9, 8, 6, 3, 1, 2, 5, 7, 10, 13, 15, 16, 17, 4, 17 }, - { 16, 14, 12, 9, 7, 5, 2, 2, 2, 3, 4, 6, 8, 11, 13, 15, 10, 16 }, + { 3, 5, 8, 9, 12, 15, 17, 17, 16, 14, 13, 11, 10, 7, 6, 4, 2, 1 }, + { 4, 7, 8, 10, 11, 12, 15, 16, 16, 14, 13, 9, 6, 5, 3, 2, 2, 2 }, + { 4, 5, 6, 7, 12, 13, 17, 17, 16, 15, 14, 11, 10, 9, 8, 3, 2, 1 }, + { 2, 5, 7, 8, 14, 15, 16, 16, 13, 12, 11, 10, 9, 6, 4, 3, 2, 2 }, }, { - { 13, 11, 10, 8, 7, 5, 2, 2, 2, 4, 6, 9, 12, 14, 15, 16, 3, 16 }, - { 11, 11, 10, 9, 8, 7, 5, 4, 3, 3, 3, 3, 3, 3, 4, 5, 6, 5 }, - { 9, 9, 7, 6, 5, 4, 3, 3, 2, 3, 4, 5, 4, 5, 5, 6, 8, 6 }, - { 13, 12, 10, 8, 5, 3, 3, 2, 2, 3, 4, 7, 9, 11, 14, 15, 6, 15 }, + { 2, 4, 7, 9, 10, 12, 13, 15, 16, 16, 14, 11, 8, 6, 5, 3, 2, 2 }, + { 3, 5, 5, 7, 10, 11, 11, 9, 8, 6, 5, 4, 4, 3, 3, 3, 3, 3 }, + { 5, 8, 9, 9, 7, 6, 6, 6, 5, 5, 5, 4, 4, 4, 3, 3, 3, 2 }, + { 2, 3, 5, 7, 8, 11, 12, 13, 15, 15, 14, 10, 9, 6, 4, 3, 3, 2 }, } }; -static const uint16_t imc_huffman_bits[4][4][18] = { +static const uint8_t imc_huffman_syms[4][4][18] = { { - { 0xCC32, 0x6618, 0x1987, 0x0660, 0x00CD, 0x0018, 0x0007, 0x0000, 0x0002, 0x000D, 0x0032, 0x0199, 0x0331, 0x0CC2, 0x330D, 0xCC33, 0x0067, 0x0000 }, - { 0x02FE, 0x00BE, 0x005E, 0x002D, 0x000A, 0x0009, 0x0003, 0x0003, 0x0000, 0x0002, 0x0008, 0x002C, 0x005D, 0x017E, 0x05FE, 0x05FF, 0x005C, 0x0000 }, - { 0x5169, 0x5168, 0x28B5, 0x0517, 0x00A3, 0x0029, 0x0008, 0x0003, 0x0000, 0x0009, 0x0015, 0x0050, 0x0144, 0x028A, 0x0A2C, 0x145B, 0x000B, 0x0000 }, - { 0x1231, 0x048D, 0x0247, 0x0090, 0x0025, 0x0008, 0x0001, 0x0003, 0x0000, 0x0005, 0x0013, 0x0049, 0x0122, 0x0919, 0x48C3, 0x48C2, 0x2460, 0x0000 }, + { 7, 8, 5, 10, 3, 13, 1, 0, 15, 14, 2, 12, 11, 4, 16, 9, 6 }, + { 8, 9, 6, 10, 5, 4, 11, 3, 16, 12, 2, 1, 13, 0, 14, 15, 7 }, + { 8, 6, 9, 11, 12, 13, 14, 1, 0, 2, 15, 3, 4, 5, 10, 16, 7 }, + { 8, 6, 5, 3, 12, 16, 15, 14, 0, 13, 1, 2, 11, 4, 10, 9, 7 }, }, { - { 0x2D1D, 0x0B46, 0x02D0, 0x00B5, 0x0059, 0x000A, 0x0003, 0x0001, 0x0000, 0x0004, 0x0017, 0x005B, 0x0169, 0x05A2, 0x168F, 0x2D1C, 0x0058, 0x0000 }, - { 0x1800, 0x0C01, 0x0301, 0x0061, 0x0019, 0x0007, 0x0004, 0x0003, 0x0000, 0x0005, 0x000D, 0x0031, 0x00C1, 0x0181, 0x0601, 0x1801, 0x0002, 0x0000 }, - { 0x1556, 0x0AAA, 0x02AB, 0x0054, 0x0014, 0x000B, 0x0002, 0x0003, 0x0000, 0x0003, 0x0008, 0x002B, 0x00AB, 0x0154, 0x0554, 0x1557, 0x0009, 0x0000 }, - { 0x1556, 0x0AAA, 0x02AB, 0x0054, 0x0014, 0x000B, 0x0002, 0x0003, 0x0000, 0x0003, 0x0008, 0x002B, 0x00AB, 0x0154, 0x0554, 0x1557, 0x0009, 0x0000 }, + { 8, 7, 9, 5, 16, 4, 2, 13, 1, 15, 0, 14, 12, 3, 11, 10, 6 }, + { 8, 16, 0, 15, 1, 14, 2, 13, 12, 3, 11, 4, 10, 5, 6, 9, 7 }, + { 8, 6, 9, 10, 16, 4, 3, 13, 14, 1, 0, 15, 2, 12, 11, 5, 7 }, + { 8, 6, 9, 10, 16, 4, 3, 13, 14, 1, 0, 15, 2, 12, 11, 5, 7 }, }, { - { 0x2993, 0x0A65, 0x0298, 0x00A7, 0x0028, 0x0004, 0x0000, 0x0001, 0x0001, 0x0003, 0x0015, 0x0052, 0x014D, 0x0533, 0x14C8, 0x5324, 0x000B, 0x5325 }, - { 0x09B8, 0x026F, 0x009A, 0x0012, 0x0005, 0x0000, 0x0001, 0x0002, 0x0003, 0x0001, 0x0003, 0x0008, 0x004C, 0x0136, 0x04DD, 0x1373, 0x0027, 0x1372 }, - { 0x0787, 0x01E0, 0x00F1, 0x003D, 0x001F, 0x0006, 0x0001, 0x0001, 0x0001, 0x0002, 0x000E, 0x0079, 0x03C2, 0x0F0D, 0x1E19, 0x3C30, 0x0000, 0x3C31 }, - { 0x4B06, 0x12C0, 0x04B1, 0x0097, 0x0024, 0x0008, 0x0002, 0x0003, 0x0000, 0x0003, 0x0005, 0x0013, 0x004A, 0x0259, 0x0961, 0x2582, 0x012D, 0x4B07 }, + { 6, 5, 4, 11, 2, 14, 15, 17, 0, 1, 13, 12, 3, 10, 16, 9, 8, 7 }, + { 5, 11, 3, 12, 2, 13, 0, 17, 15, 14, 1, 16, 4, 10, 9, 6, 7, 8 }, + { 16, 9, 5, 10, 1, 12, 15, 17, 14, 13, 0, 2, 11, 3, 4, 6, 8, 7 }, + { 8, 5, 4, 12, 1, 15, 0, 17, 14, 2, 13, 16, 3, 11, 10, 9, 6, 7 }, }, { - { 0x0A5A, 0x0297, 0x014A, 0x0053, 0x0028, 0x000B, 0x0003, 0x0000, 0x0002, 0x0004, 0x0015, 0x00A4, 0x052C, 0x14B7, 0x296C, 0x52DB, 0x0003, 0x52DA }, - { 0x0193, 0x0192, 0x00C8, 0x0065, 0x0033, 0x0018, 0x0007, 0x0004, 0x0000, 0x0004, 0x0005, 0x0007, 0x0006, 0x0003, 0x0005, 0x0005, 0x000D, 0x0004 }, - { 0x0012, 0x0013, 0x0005, 0x0003, 0x0000, 0x0003, 0x0005, 0x0004, 0x0003, 0x0003, 0x0005, 0x0005, 0x0004, 0x0004, 0x0003, 0x0005, 0x0008, 0x0004 }, - { 0x0D66, 0x06B2, 0x01AD, 0x006A, 0x000C, 0x0005, 0x0004, 0x0000, 0x0003, 0x0002, 0x0007, 0x0034, 0x00D7, 0x0358, 0x1ACF, 0x359C, 0x001B, 0x359D }, + { 7, 9, 4, 11, 2, 12, 0, 14, 17, 15, 13, 1, 3, 10, 5, 16, 8, 6 }, + { 8, 17, 15, 5, 2, 1, 0, 3, 4, 16, 6, 7, 14, 13, 9, 10, 12, 11 }, + { 4, 16, 0, 1, 2, 3, 17, 15, 14, 13, 11, 5, 12, 10, 9, 7, 6, 8 }, + { 7, 9, 4, 11, 3, 13, 1, 0, 15, 17, 14, 2, 12, 16, 10, 6, 5, 8 }, } };