History

avcodec/vvc/intra: refact, predict jcbcr to tb->coeffs

prepare for adaptive color transform

Wu Jianhua committed 1 year ago

Commit d2e7ca61 parent 86e96a13 files · +20 −50Browse files

Unified · Split

3 files
  1. libavcodec/vvc/dsp.h +0 −1
  2. libavcodec/vvc/dsp_template.c +0 −18
  3. libavcodec/vvc/intra.c +20 −31
libavcodec/vvc/dsp.h+0−1
@@ -122,7 +122,6 @@ typedef struct VVCIntraDSPContext { · 121 unmodified lines
122 122
123typedef struct VVCItxDSPContext {123typedef struct VVCItxDSPContext {
124 void (*add_residual)(uint8_t *dst, const int *res, int width, int height, ptrdiff_t stride);124 void (*add_residual)(uint8_t *dst, const int *res, int width, int height, ptrdiff_t stride);
125 void (*add_residual_joint)(uint8_t *dst, const int *res, int width, int height, ptrdiff_t stride, int c_sign, int shift);
126 void (*pred_residual_joint)(int *dst, const int *src, int width, int height, int c_sign, int shift);125 void (*pred_residual_joint)(int *dst, const int *src, int width, int height, int c_sign, int shift);
127 126
128 void (*itx[VVC_N_TX_TYPE][VVC_N_TX_SIZE])(int *coeffs, ptrdiff_t step, size_t nz);127 void (*itx[VVC_N_TX_TYPE][VVC_N_TX_SIZE])(int *coeffs, ptrdiff_t step, size_t nz);
libavcodec/vvc/dsp_template.c+0−18
@@ -45,23 +45,6 @@ static void FUNC(add_residual)(uint8_t *_dst, const int *res, · 44 unmodified lines
45 }45 }
46}46}
47 47
48static void FUNC(add_residual_joint)(uint8_t *_dst, const int *res,
49 const int w, const int h, const ptrdiff_t _stride, const int c_sign, const int shift)
50{
51 pixel *dst = (pixel *)_dst;
52
53 const int stride = _stride / sizeof(pixel);
54
55 for (int y = 0; y < h; y++) {
56 for (int x = 0; x < w; x++) {
57 const int r = ((*res) * c_sign) >> shift;
58 dst[x] = av_clip_pixel(dst[x] + r);
59 res++;
60 }
61 dst += stride;
62 }
63}
64
65static void FUNC(pred_residual_joint)(int *dst, const int *src, const int w, const int h,48static void FUNC(pred_residual_joint)(int *dst, const int *src, const int w, const int h,
66 const int c_sign, const int shift)49 const int c_sign, const int shift)
67{50{
@@ -121,7 +104,6 @@ static void FUNC(ff_vvc_itx_dsp_init)(VVCItxDSPContext *const itx) · 53 unmodified lines
121 VVC_ITX(TYPE, type, 32);104 VVC_ITX(TYPE, type, 32);
122 105
123 itx->add_residual = FUNC(add_residual);106 itx->add_residual = FUNC(add_residual);
124 itx->add_residual_joint = FUNC(add_residual_joint);
125 itx->pred_residual_joint = FUNC(pred_residual_joint);107 itx->pred_residual_joint = FUNC(pred_residual_joint);
126 itx->transform_bdpcm = FUNC(transform_bdpcm);108 itx->transform_bdpcm = FUNC(transform_bdpcm);
127 VVC_ITX(DCT2, dct2, 2)109 VVC_ITX(DCT2, dct2, 2)
libavcodec/vvc/intra.c+20−31
@@ -164,28 +164,6 @@ static void derive_transform_type(const VVCFrameContext *fc, const VVCLocalConte · 163 unmodified lines
164 *trv = mts_to_trv[cu->mts_idx];164 *trv = mts_to_trv[cu->mts_idx];
165}165}
166 166
167static void add_residual_for_joint_coding_chroma(VVCLocalContext *lc,
168 const TransformUnit *tu, TransformBlock *tb, const int chroma_scale)
169{
170 const VVCFrameContext *fc = lc->fc;
171 const CodingUnit *cu = lc->cu;
172 const int c_sign = 1 - 2 * fc->ps.ph.r->ph_joint_cbcr_sign_flag;
173 const int shift = tu->coded_flag[1] ^ tu->coded_flag[2];
174 const int c_idx = 1 + tu->coded_flag[1];
175 const ptrdiff_t stride = fc->frame->linesize[c_idx];
176 const int hs = fc->ps.sps->hshift[c_idx];
177 const int vs = fc->ps.sps->vshift[c_idx];
178 uint8_t *dst = &fc->frame->data[c_idx][(tb->y0 >> vs) * stride +
179 ((tb->x0 >> hs) << fc->ps.sps->pixel_shift)];
180 if (chroma_scale) {
181 fc->vvcdsp.itx.pred_residual_joint(tb->coeffs, tb->coeffs, tb->tb_width, tb->tb_height, c_sign, shift);
182 fc->vvcdsp.intra.lmcs_scale_chroma(lc, tb->coeffs, tb->coeffs, tb->tb_width, tb->tb_height, cu->x0, cu->y0);
183 fc->vvcdsp.itx.add_residual(dst, tb->coeffs, tb->tb_width, tb->tb_height, stride);
184 } else {
185 fc->vvcdsp.itx.add_residual_joint(dst, tb->coeffs, tb->tb_width, tb->tb_height, stride, c_sign, shift);
186 }
187}
188
189static int add_reconstructed_area(VVCLocalContext *lc, const int ch_type, const int x0, const int y0, const int w, const int h)167static int add_reconstructed_area(VVCLocalContext *lc, const int ch_type, const int x0, const int y0, const int w, const int h)
190{168{
191 const VVCSPS *sps = lc->fc->ps.sps;169 const VVCSPS *sps = lc->fc->ps.sps;
@@ -531,7 +509,7 @@ static void itransform(VVCLocalContext *lc, TransformUnit *tu, const int tu_idx, · 339 unmodified lines
531 const ptrdiff_t stride = fc->frame->linesize[c_idx];509 const ptrdiff_t stride = fc->frame->linesize[c_idx];
532 const int hs = sps->hshift[c_idx];510 const int hs = sps->hshift[c_idx];
533 const int vs = sps->vshift[c_idx];511 const int vs = sps->vshift[c_idx];
534 uint8_t *dst = &fc->frame->data[c_idx][(tb->y0 >> vs) * stride + ((tb->x0 >> hs) << ps)];512 const int has_jcbcr = tu->joint_cbcr_residual_flag && c_idx;
535 513
536 if (cu->bdpcm_flag[tb->c_idx])514 if (cu->bdpcm_flag[tb->c_idx])
537 transform_bdpcm(tb, lc, cu);515 transform_bdpcm(tb, lc, cu);
@@ -548,14 +526,25 @@ static void itransform(VVCLocalContext *lc, TransformUnit *tu, const int tu_idx, · 10 unmodified lines
548 itx_1d(fc, tb, trh, trv);526 itx_1d(fc, tb, trh, trv);
549 }527 }
550 528
551 if (chroma_scale)529 for (int j = 0; j < 1 + has_jcbcr; j++) {
552 fc->vvcdsp.intra.lmcs_scale_chroma(lc, temp, tb->coeffs, w, h, cu->x0, cu->y0);530 const bool is_jcbcr = j > 0;
553 // TODO: Address performance issue here by combining transform, lmcs_scale_chroma, and add_residual into one function.531 const int jcbcr_idx = CB + tu->coded_flag[CB];
554 // Complete this task before implementing ASM code.532 TransformBlock *jcbcr = &tu->tbs[jcbcr_idx - tu->tbs[0].c_idx];
555 fc->vvcdsp.itx.add_residual(dst, chroma_scale ? temp : tb->coeffs, w, h, stride);533 const int c = is_jcbcr ? jcbcr_idx : tb->c_idx;
556 534 int *coeffs = is_jcbcr ? jcbcr->coeffs : tb->coeffs;
557 if (tu->joint_cbcr_residual_flag && tb->c_idx)535 uint8_t *dst = &fc->frame->data[c][(tb->y0 >> vs) * stride + ((tb->x0 >> hs) << ps)];
558 add_residual_for_joint_coding_chroma(lc, tu, tb, chroma_scale);536
537 if (!j && has_jcbcr) {
538 const int c_sign = 1 - 2 * fc->ps.ph.r->ph_joint_cbcr_sign_flag;
539 const int shift = tu->coded_flag[CB] ^ tu->coded_flag[CR];
540 fc->vvcdsp.itx.pred_residual_joint(jcbcr->coeffs, tb->coeffs, tb->tb_width, tb->tb_height, c_sign, shift);
541 }
542 if (chroma_scale)
543 fc->vvcdsp.intra.lmcs_scale_chroma(lc, temp, coeffs, w, h, cu->x0, cu->y0);
544 // TODO: Address performance issue here by combining transform, lmcs_scale_chroma, and add_residual into one function.
545 // Complete this task before implementing ASM code.
546 fc->vvcdsp.itx.add_residual(dst, chroma_scale ? temp : coeffs, w, h, stride);
547 }
559 }548 }
560 }549 }
561}550}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t