From: toqsxw@gmail.com To: ffmpeg-devel@ffmpeg.org Cc: Wu Jianhua <toqsxw@outlook.com> Subject: [FFmpeg-devel] [PATCH v1 21/23] avcodec/vvc/intra: refact out lmcs_scale_chroma and add_residual Date: Wed, 14 May 2025 21:40:28 +0800 Message-ID: <20250514134031.1584-21-toqsxw@outlook.com> (raw) In-Reply-To: <20250514134031.1584-1-toqsxw@outlook.com> From: Wu Jianhua <toqsxw@outlook.com> prepare for adaptive color transform Signed-off-by: Wu Jianhua <toqsxw@outlook.com> --- 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".
next prev parent reply other threads:[~2025-05-14 13:44 UTC|newest] Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top 2025-05-14 13:40 [FFmpeg-devel] [PATCH v1 01/23] avcodec/vvc/cabac: add 9.3.3.5 k-th order Exp - Golomb binarization process toqsxw 2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 02/23] avcodec/vvc/cabac: add 9.3.3.7 Fixed-length " toqsxw 2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 03/23] avcodec/vvc/cabac: add palette support toqsxw 2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 04/23] avcodec/vvc: add VVC_MAX_NUM_PALETTE_PREDICTOR_SIZE toqsxw 2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 05/23] avcodec/vvc/ctu: refact out ff_vvc_channel_range toqsxw 2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 06/23] avcodec/vvc: refact out ep_init and ep_init_wpp toqsxw 2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 07/23] avcodec/vvc: refact, save pf and ciip_flag in ff_vvc_set_intra_mvf toqsxw 2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 08/23] avcodec/vvc/ctu: refact out intra_data toqsxw 2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 09/23] avcodec/vvc/intra: add ff_vvc_palette_derive_scale toqsxw 2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 10/23] avcodec/vvc/ctu: add palette support toqsxw 2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 11/23] avcodec/vvc/filter: skip deblocking filter for palette toqsxw 2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 12/23] avcodec/vvc/intra: add palette coding decoder toqsxw 2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 13/23] avcodec/vvc/cabac: add ff_vvc_cu_act_enabled_flag toqsxw 2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 14/23] avcodec/vvc/ctu: read act_enabled_flag for adaptive color transform toqsxw 2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 15/23] avcodec/vvc/ctu: fix derive_chroma_intra_pred_mode toqsxw 2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 16/23] avcodec/vvc/dsp: update the interface of pred_residual_joint for joint cbcr residual functionality toqsxw 2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 17/23] avcodec/vvc/dsp: add adaptive_color_transform toqsxw 2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 18/23] avcodec/vvc/intra: fix scaling process for transform coefficients toqsxw 2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 19/23] avcodec/vvc/intra: refact, predict jcbcr to tb->coeffs toqsxw 2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 20/23] avcodec/vvc/intra: make lmcs_scale_chroma inplace toqsxw 2025-05-14 13:40 ` toqsxw [this message] 2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 22/23] avcodec/vvc: add adaptive color transform support toqsxw 2025-05-14 13:40 ` [FFmpeg-devel] [PATCH v1 23/23] Changelog: VVC supports all content of SCC toqsxw 2025-05-14 13:46 ` [FFmpeg-devel] 回复: [PATCH v1 01/23] avcodec/vvc/cabac: add 9.3.3.5 k-th order Exp - Golomb binarization process Wu Jianhua 2025-05-17 5:39 ` [FFmpeg-devel] " Nuo Mi -- strict thread matches above, loose matches on Subject: below -- 2025-05-01 14:42 toqsxw 2025-05-01 14:43 ` [FFmpeg-devel] [PATCH v1 21/23] avcodec/vvc/intra: refact out lmcs_scale_chroma and add_residual toqsxw
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20250514134031.1584-21-toqsxw@outlook.com \ --to=toqsxw@gmail.com \ --cc=ffmpeg-devel@ffmpeg.org \ --cc=toqsxw@outlook.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git