From patchwork Wed Sep 28 10:07:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Tomas_H=C3=A4rdin?= X-Patchwork-Id: 38425 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp99351pzh; Wed, 28 Sep 2022 03:07:48 -0700 (PDT) X-Google-Smtp-Source: AMsMyM54AsE4buQdeAiM5Rx66LknfOZqhKk1nLY9g0dZHCEuWUZtKx6vdrvIs7fquGx/B0eGmc6c X-Received: by 2002:a05:6402:944:b0:457:6680:a5c0 with SMTP id h4-20020a056402094400b004576680a5c0mr12036989edz.428.1664359668332; Wed, 28 Sep 2022 03:07:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664359668; cv=none; d=google.com; s=arc-20160816; b=cEJ8kmRYAfFLmPn1U5ozJSyHxoJjZpKudGGJw9ZirzR30XYYHmgUmh6sfM8O22edsT tfpwZ1W8d/Tcv4q7PBGfnR2RqEE7jv186dmyel3aylbArjLHgsWd2And9yIUrgDTRo6o OlKrpHFGGwk7wIFNP1w0Yxer4ep2xnya+3UN4+ybJv93P3GoyN4ZH4x9h3NWrRhwGPg2 JaM0/ZsDmHmp8upS6uO1H7bqLm65nOdGImS1NU1YLN3B9Zo2d7Zh6Tw57TJ5ehj9+/o/ lvcGFXC2/3IPtpffXR/I6Ir1IwsBw0eXVuIG18wFTHMmB+u9CioFgMaii9K9XuKw7VeH zQTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:user-agent:references:in-reply-to:date:to:from :message-id:delivered-to; bh=NY4D24b70xj9qtiN3KmcDFaV3dxhuqq5U16mOKsBcC8=; b=HtyZ3b6ryIzCa/RKWarS4fhG5RP1HrhUDXFI29FleQFt9/+rhqHWREi1W5jTvGt7pJ 2/vIwkCe+ySzUXS7d6Ovt2hiz/C9SpOj6/W8RFn804iwui7ctJSeKGOEaHf0uU963qOl akmk16raqMpRJ+az4RhQLyo4o6el2uGTUQMcR2uhHNIUrfozzXeuTJGSxqxS4I206Ze+ i1n+XXu1asbTpCCfnClSJBOeTpxyPhPOGTnbbiqo+nofg/gL4E/36zYenQr2y5lgkf5k FUzjGgyVYQ23cY5lFuoIl82e3bChafJVWryI6O8oHGDHvdl3choSLeKtBaK8v6iSfaWF Ng1w== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id ho33-20020a1709070ea100b0077c5ec87ec2si4779227ejc.297.2022.09.28.03.07.47; Wed, 28 Sep 2022 03:07:48 -0700 (PDT) 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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 336A468BC3D; Wed, 28 Sep 2022 13:07:46 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.frobbit.se (mail.frobbit.se [85.30.129.176]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5AC1568BBBD for ; Wed, 28 Sep 2022 13:07:39 +0300 (EEST) Received: from debian.lan (unknown [IPv6:2a00:66c0:a::72c]) by mail.frobbit.se (Postfix) with ESMTPSA id D5D31213E0 for ; Wed, 28 Sep 2022 12:07:38 +0200 (CEST) Message-ID: <09bb5c361832325cabe36845a51ebe060a2fc4c8.camel@haerdin.se> From: Tomas =?iso-8859-1?q?H=E4rdin?= To: FFmpeg development discussions and patches Date: Wed, 28 Sep 2022 12:07:38 +0200 In-Reply-To: <65e79fe701374868bb2f4b70ce8fd220938e2e86.camel@haerdin.se> References: <65e79fe701374868bb2f4b70ce8fd220938e2e86.camel@haerdin.se> User-Agent: Evolution 3.38.3-1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 07/11] lavc/jpeg2000: Speed up ff_jpeg2000_tag_tree_init() using stereotypes for sizes <= 4x4 X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: W1F9Z9yODgMu From a31a6d82b257f51618389a67af18d49cc78ac240 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= Date: Wed, 8 Jun 2022 10:08:15 +0200 Subject: [PATCH 07/11] lavc/jpeg2000: Speed up ff_jpeg2000_tag_tree_init() using stereotypes for sizes <= 4x4 --- libavcodec/jpeg2000.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/libavcodec/jpeg2000.c b/libavcodec/jpeg2000.c index 4ddb45bf33..203782502c 100644 --- a/libavcodec/jpeg2000.c +++ b/libavcodec/jpeg2000.c @@ -51,6 +51,31 @@ static int32_t tag_tree_size(int w, int h) return (int32_t)(res + 1); } +#define T(x) (x*sizeof(Jpeg2000TgtNode)) + +static const size_t tt_sizes[16] = { + T(1),T(3),T(6),T(7),T(3),T(5),T(9),T(11),T(6),T(9),T(14),T(17),T(7),T(11),T(17),T(21), +}; + +static const Jpeg2000TgtNode tt_stereotypes[16][21] = { + {{-1},}, + {{2},{2},{-1},}, + {{3},{3},{4},{5},{5},{-1},}, + {{4},{4},{5},{5},{6},{6},{-1},}, + {{2},{2},{-1},}, + {{4},{4},{4},{4},{-1},}, + {{6},{6},{7},{6},{6},{7},{8},{8},{-1},}, + {{8},{8},{9},{9},{8},{8},{9},{9},{10},{10},{-1},}, + {{3},{3},{4},{5},{5},{-1},}, + {{6},{6},{6},{6},{7},{7},{8},{8},{-1},}, + {{9},{9},{10},{9},{9},{10},{11},{11},{12},{13},{13},{13},{13},{-1},}, + {{12},{12},{13},{13},{12},{12},{13},{13},{14},{14},{15},{15},{16},{16},{16},{16},{-1},}, + {{4},{4},{5},{5},{6},{6},{-1},}, + {{8},{8},{8},{8},{9},{9},{9},{9},{10},{10},{-1},}, + {{12},{12},{13},{12},{12},{13},{14},{14},{15},{14},{14},{15},{16},{16},{16},{16},{-1},}, + {{16},{16},{17},{17},{16},{16},{17},{17},{18},{18},{19},{19},{18},{18},{19},{19},{20},{20},{20},{20},{-1},}, +}; + /* allocate the memory for tag tree */ static int ff_jpeg2000_tag_tree_init(Jpeg2000TgtNode **old, unsigned int *size, int w, int h) { @@ -59,6 +84,16 @@ static int ff_jpeg2000_tag_tree_init(Jpeg2000TgtNode **old, unsigned int *size, int32_t tt_size, ofs = 0; size_t prod; + if (w <= 4 && h <= 4) { + int idx = w-1 + (h-1)*4; + size_t sz = tt_sizes[idx]; + av_fast_malloc(old, size, sz); + if (*old) { + memcpy(*old, tt_stereotypes[idx], sz); + return 0; + } else + return AVERROR(ENOMEM); + } else { tt_size = tag_tree_size(w, h); if (av_size_mult(tt_size, sizeof(*t), &prod)) @@ -87,6 +122,7 @@ static int ff_jpeg2000_tag_tree_init(Jpeg2000TgtNode **old, unsigned int *size, } t[0].parent = -1; return 0; + } } void ff_tag_tree_zero(Jpeg2000TgtNode *t, int w, int h, int val) -- 2.30.2