From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 3A45F4EE9A for ; Wed, 14 May 2025 13:44:49 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E54A468C7A6; Wed, 14 May 2025 16:41:24 +0300 (EEST) Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BE28568C75A for ; Wed, 14 May 2025 16:41:17 +0300 (EEST) Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-739b3fe7ce8so6044136b3a.0 for ; Wed, 14 May 2025 06:41:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1747230076; x=1747834876; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=b8ySlengb0JBWU+YnRgw4CrhfRy6Tpx7jMI+Q5jfIyM=; b=UI0+Le8G9TatXCFHhgWqbx9sIj14id3vBQCkrC/tkeiuiGTWyA/1+67ALY6/TN7nKM JRddaohdcNRpE3ZBQPzDsKIJFkNB7uycDq92PqwDw1nKB45deQY3NR1vZK7PkX3ds6om ARpswsF+/LIYq5BvhbjOd/BBgYEXlM39zRr34zq37bvYXLJvTt2haHmRf5CkALCZloDy gSFtmgciv+R80jq64p+ql5KaqSkbAmzI4bsrHl9n4vVLRTP4kHHS+MDam8pYcPsxKr9P MuTxy+LHrS+PEsOHpe1yxR7VeiO2AsYplzMjGPHZ1T3wMD+Y+ErtJ9qTYdfR9qDboWos 7d1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747230076; x=1747834876; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=b8ySlengb0JBWU+YnRgw4CrhfRy6Tpx7jMI+Q5jfIyM=; b=aPbFN12wNOKnNTZWQ9kYRxMeDC913fRqG4M9HOzHD6jjyImjYK9vUATrHLcxLVR7y/ DI0cLt5pZESzMP6xHEwBveP02eD+f1QB316OBBI9eH9tUVBMfdkFiReLSHabOsiMNqJL Pej9JU821FCd2/oqqByljNHyQgfmh9VolsEgidU5k5Lf7uvlcBcH8rnx+CpR+cRi0iB3 2SQjuKwyLJqa7rtGDBTZFsiIt5nOJfbO8Is+YhHDGY3iGq0eO7dO7ZbQIVg8enOWtemX 4zEcQ8EdZ1+QTEAEjTRffy5o3YtyLqfVZJdFR+0WevGlwfVw8hi5MCjHYCazc7QmK3ZQ /Y+w== X-Gm-Message-State: AOJu0YxmtaMh3MtYDb99vrrQ74nXmRlO4T+Xfq2Lx5pwd/lmIcZsrvje aldxuyhL1ogb9Tb4KCmZ49ce5pyc85ZmtM/AudvNNzruLwbFpRdTTxzVGoI2 X-Gm-Gg: ASbGncuhI1RbSw1X4gAVpwsbXi383NF4QK8oUG5FoQllEWJWlCr0ReHt6HtOo/yw7yN dx96tpT5wJ/DHd/5L83TzdwFcQ/Gw6ggtlGEdxWAB2s8vZOnWRyqhnx1dNcfWw+EKA8sQeDwEpo KiyufoWV7u0dT2Dix0TgwPUfg0Kz6I0xxLWkfJGCnri40t08akgk2KD68i7OX0nEFMmTpzzRfQT YZOlnuk/w8GVxicF7aaV0P0wF/DLkKS05e8jWqOkG2p7bmC0hJ/3NOj4NZIYgHolqUgpgAacCgf 7CB1tIDTZ1rWMTWYwQx5Qd+6VbReAyOPEgAN+YZ1gYaS+Gl5XCqR9aULqIuTCiEvDjx/hEqi X-Google-Smtp-Source: AGHT+IF6IZ6v1WG9gD0I2YHtFx/YO+SaBqXVbpPQLFa3OiOFsg+FKWMU1wXnAcHtWan1h9w2TB2U/w== X-Received: by 2002:a05:6a00:22c9:b0:742:3c10:bcb6 with SMTP id d2e1a72fcca58-742892cf7c8mr4056973b3a.13.1747230075761; Wed, 14 May 2025 06:41:15 -0700 (PDT) Received: from localhost.localdomain ([124.79.129.75]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-74237a8f7edsm9310669b3a.167.2025.05.14.06.41.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 May 2025 06:41:15 -0700 (PDT) From: toqsxw@gmail.com X-Google-Original-From: toqsxw@outlook.com To: ffmpeg-devel@ffmpeg.org Date: Wed, 14 May 2025 21:40:28 +0800 Message-ID: <20250514134031.1584-21-toqsxw@outlook.com> X-Mailer: git-send-email 2.44.0.windows.1 In-Reply-To: <20250514134031.1584-1-toqsxw@outlook.com> References: <20250514134031.1584-1-toqsxw@outlook.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v1 21/23] avcodec/vvc/intra: refact out lmcs_scale_chroma and add_residual 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 Cc: Wu Jianhua Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: From: Wu Jianhua prepare for adaptive color transform Signed-off-by: Wu Jianhua --- libavcodec/vvc/intra.c | 107 ++++++++++++++++++++++++----------------- 1 file changed, 63 insertions(+), 44 deletions(-) diff --git a/libavcodec/vvc/intra.c b/libavcodec/vvc/intra.c index b5842a93d1..0ea33e1e73 100644 --- a/libavcodec/vvc/intra.c +++ b/libavcodec/vvc/intra.c @@ -27,6 +27,10 @@ #include "intra.h" #include "itx_1d.h" +#define POS(c_idx, x, y) \ + &fc->frame->data[c_idx][((y) >> fc->ps.sps->vshift[c_idx]) * fc->frame->linesize[c_idx] + \ + (((x) >> fc->ps.sps->hshift[c_idx]) << fc->ps.sps->pixel_shift)] + static int is_cclm(enum IntraPredMode mode) { return mode == INTRA_LT_CCLM || mode == INTRA_L_CCLM || mode == INTRA_T_CCLM; @@ -488,28 +492,65 @@ static void transform_bdpcm(TransformBlock *tb, const VVCLocalContext *lc, const tb->max_scan_x = tb->tb_width - 1; } -static void itransform(VVCLocalContext *lc, TransformUnit *tu, const int tu_idx, const int target_ch_type) +static void lmcs_scale_chroma(VVCLocalContext *lc, TransformUnit *tu, TransformBlock *tb, const int target_ch_type) { - const VVCFrameContext *fc = lc->fc; - const VVCSPS *sps = fc->ps.sps; - const VVCSH *sh = &lc->sc->sh; - const CodingUnit *cu = lc->cu; - const int ps = fc->ps.sps->pixel_shift; + const VVCFrameContext *fc = lc->fc; + const VVCSH *sh = &lc->sc->sh; + const CodingUnit *cu = lc->cu; + const int c_idx = tb->c_idx; + const int ch_type = c_idx > 0; + const int w = tb->tb_width; + const int h = tb->tb_height; + const int chroma_scale = ch_type && sh->r->sh_lmcs_used_flag && fc->ps.ph.r->ph_chroma_residual_scale_flag && (w * h > 4); + const int has_jcbcr = tu->joint_cbcr_residual_flag && c_idx; + + for (int j = 0; j < 1 + has_jcbcr; j++) { + const bool is_jcbcr = j > 0; + const int jcbcr_idx = CB + tu->coded_flag[CB]; + TransformBlock *jcbcr = &tu->tbs[jcbcr_idx - tu->tbs[0].c_idx]; + int *coeffs = is_jcbcr ? jcbcr->coeffs : tb->coeffs; + + if (!j && has_jcbcr) { + const int c_sign = 1 - 2 * fc->ps.ph.r->ph_joint_cbcr_sign_flag; + const int shift = tu->coded_flag[CB] ^ tu->coded_flag[CR]; + fc->vvcdsp.itx.pred_residual_joint(jcbcr->coeffs, tb->coeffs, w, h, c_sign, shift); + } + if (chroma_scale) + fc->vvcdsp.intra.lmcs_scale_chroma(lc, coeffs, w, h, cu->x0, cu->y0); + } +} + +static void add_residual(const VVCLocalContext *lc, TransformUnit *tu, const int target_ch_type) +{ + const VVCFrameContext *fc = lc->fc; for (int i = 0; i < tu->nb_tbs; i++) { - TransformBlock *tb = &tu->tbs[i]; - const int c_idx = tb->c_idx; - const int ch_type = c_idx > 0; - - if (ch_type == target_ch_type && tb->has_coeffs) { - const int w = tb->tb_width; - const int h = tb->tb_height; - const int chroma_scale = ch_type && sh->r->sh_lmcs_used_flag && fc->ps.ph.r->ph_chroma_residual_scale_flag && (w * h > 4); - const ptrdiff_t stride = fc->frame->linesize[c_idx]; - const int hs = sps->hshift[c_idx]; - const int vs = sps->vshift[c_idx]; - const int has_jcbcr = tu->joint_cbcr_residual_flag && c_idx; + TransformBlock *tb = tu->tbs + i; + const int c_idx = tb->c_idx; + const int ch_type = c_idx > 0; + const ptrdiff_t stride = fc->frame->linesize[c_idx]; + const bool has_residual = tb->has_coeffs || + (c_idx && tu->joint_cbcr_residual_flag); + uint8_t *dst = POS(c_idx, tb->x0, tb->y0); + + if (ch_type == target_ch_type && has_residual) + fc->vvcdsp.itx.add_residual(dst, tb->coeffs, tb->tb_width, tb->tb_height, stride); + } +} + +static void itransform(VVCLocalContext *lc, TransformUnit *tu, const int target_ch_type) +{ + const VVCFrameContext *fc = lc->fc; + const CodingUnit *cu = lc->cu; + TransformBlock *tbs = tu->tbs; + + for (int i = 0; i < tu->nb_tbs; i++) { + TransformBlock *tb = tbs + i; + const int c_idx = tb->c_idx; + const int ch_type = c_idx > 0; + const bool do_itx = ch_type == target_ch_type; + if (tb->has_coeffs && do_itx) { if (cu->bdpcm_flag[tb->c_idx]) transform_bdpcm(tb, lc, cu); dequant(lc, tu, tb); @@ -519,33 +560,15 @@ static void itransform(VVCLocalContext *lc, TransformUnit *tu, const int tu_idx, if (cu->apply_lfnst_flag[c_idx]) ilfnst_transform(lc, tb); derive_transform_type(fc, lc, tb, &trh, &trv); - if (w > 1 && h > 1) + if (tb->tb_width > 1 && tb->tb_height > 1) itx_2d(fc, tb, trh, trv); else itx_1d(fc, tb, trh, trv); } - - for (int j = 0; j < 1 + has_jcbcr; j++) { - const bool is_jcbcr = j > 0; - const int jcbcr_idx = CB + tu->coded_flag[CB]; - TransformBlock *jcbcr = &tu->tbs[jcbcr_idx - tu->tbs[0].c_idx]; - const int c = is_jcbcr ? jcbcr_idx : tb->c_idx; - int *coeffs = is_jcbcr ? jcbcr->coeffs : tb->coeffs; - uint8_t *dst = &fc->frame->data[c][(tb->y0 >> vs) * stride + ((tb->x0 >> hs) << ps)]; - - if (!j && has_jcbcr) { - const int c_sign = 1 - 2 * fc->ps.ph.r->ph_joint_cbcr_sign_flag; - const int shift = tu->coded_flag[CB] ^ tu->coded_flag[CR]; - fc->vvcdsp.itx.pred_residual_joint(jcbcr->coeffs, tb->coeffs, tb->tb_width, tb->tb_height, c_sign, shift); - } - if (chroma_scale) - fc->vvcdsp.intra.lmcs_scale_chroma(lc, coeffs, w, h, cu->x0, cu->y0); - // TODO: Address performance issue here by combining transform, lmcs_scale_chroma, and add_residual into one function. - // Complete this task before implementing ASM code. - fc->vvcdsp.itx.add_residual(dst, coeffs, w, h, stride); - } + lmcs_scale_chroma(lc, tu, tb, target_ch_type); } } + add_residual(lc, tu, target_ch_type); } static int reconstruct(VVCLocalContext *lc) @@ -559,17 +582,13 @@ static int reconstruct(VVCLocalContext *lc) TransformUnit *tu = cu->tus.head; for (int i = 0; tu; i++) { predict_intra(lc, tu, i, ch_type); - itransform(lc, tu, i, ch_type); + itransform(lc, tu, ch_type); tu = tu->next; } } return 0; } -#define POS(c_idx, x, y) \ - &fc->frame->data[c_idx][((y) >> fc->ps.sps->vshift[c_idx]) * fc->frame->linesize[c_idx] + \ - (((x) >> fc->ps.sps->hshift[c_idx]) << fc->ps.sps->pixel_shift)] - #define IBC_POS(c_idx, x, y) \ (fc->tab.ibc_vir_buf[c_idx] + \ (x << ps) + (y + ((cu->y0 & ~(sps->ctb_size_y - 1)) >> vs)) * ibc_stride) -- 2.44.0.windows.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".