36 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
37 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4,
38 5, 5, 6, 6, 7, 8, 9, 10, 11, 13, 14, 16, 18, 20, 22, 24
42 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 8,
43 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36,
44 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64
48 int qp_y,
int c_idx,
int tc_offset)
50 static const int qp_c[] = {
51 29, 30, 31, 32, 33, 33, 34, 34, 35, 35, 36, 36, 37, 37
53 int qp, qp_i,
offset, idxt;
62 if (
sps->chroma_format_idc == 1) {
80 int xBase,
int yBase,
int log2_cb_size)
82 int ctb_size_mask = (1 <<
sps->log2_ctb_size) - 1;
83 int MinCuQpDeltaSizeMask = (1 << (
sps->log2_ctb_size -
84 pps->diff_cu_qp_delta_depth)) - 1;
85 int xQgBase = xBase - (xBase & MinCuQpDeltaSizeMask);
86 int yQgBase = yBase - (yBase & MinCuQpDeltaSizeMask);
87 int min_cb_width =
sps->min_cb_width;
88 int x_cb = xQgBase >>
sps->log2_min_cb_size;
89 int y_cb = yQgBase >>
sps->log2_min_cb_size;
90 int availableA = (xBase & ctb_size_mask) &&
91 (xQgBase & ctb_size_mask);
92 int availableB = (yBase & ctb_size_mask) &&
93 (yQgBase & ctb_size_mask);
94 int qPy_pred, qPy_a, qPy_b;
99 qPy_pred =
s->sh.slice_qp;
108 qPy_a = l->
qp_y_tab[(x_cb - 1) + y_cb * min_cb_width];
114 qPy_b = l->
qp_y_tab[x_cb + (y_cb - 1) * min_cb_width];
119 return (qPy_a + qPy_b + 1) >> 1;
124 int xBase,
int yBase,
int log2_cb_size)
131 int off =
sps->qp_bd_offset;
140 int log2_min_cb_size =
sps->log2_min_cb_size;
141 int x = xC >> log2_min_cb_size;
142 int y = yC >> log2_min_cb_size;
143 return qp_y_tab[x + y *
sps->min_cb_width];
147 ptrdiff_t stride_dst, ptrdiff_t stride_src)
151 if (((intptr_t)
dst | (intptr_t)
src | stride_dst | stride_src) & 15) {
153 for (j = 0; j <
width - 7; j+=8)
163 for (j = 0; j <
width; j++)
171 for (j = 0; j <
width; j+=16)
182 *(uint16_t *)
dst = *(uint16_t *)
src;
188 int pixel_shift,
int height,
189 ptrdiff_t stride_dst, ptrdiff_t stride_src)
192 if (pixel_shift == 0) {
200 *(uint16_t *)
dst = *(uint16_t *)
src;
209 ptrdiff_t stride_src,
int x,
int y,
int width,
int height,
210 int c_idx,
int x_ctb,
int y_ctb)
212 int sh =
sps->pixel_shift;
213 int w =
sps->width >>
sps->hshift[c_idx];
214 int h =
sps->height >>
sps->vshift[c_idx];
230 uint8_t *
src1,
const uint8_t *dst1,
231 ptrdiff_t stride_src, ptrdiff_t stride_dst,
234 if (
pps->transquant_bypass_enable_flag ||
235 (
sps->pcm_loop_filter_disabled &&
sps->pcm_enabled)) {
237 int min_pu_size = 1 <<
sps->log2_min_pu_size;
238 int hshift =
sps->hshift[c_idx];
239 int vshift =
sps->vshift[c_idx];
240 int x_min = ((x0 ) >>
sps->log2_min_pu_size);
241 int y_min = ((y0 ) >>
sps->log2_min_pu_size);
242 int x_max = ((x0 +
width ) >>
sps->log2_min_pu_size);
243 int y_max = ((y0 +
height) >>
sps->log2_min_pu_size);
244 int len = (min_pu_size >> hshift) <<
sps->pixel_shift;
245 for (y = y_min; y < y_max; y++) {
246 for (x = x_min; x < x_max; x++) {
247 if (l->
is_pcm[y *
sps->min_pu_width + x]) {
250 (((y <<
sps->log2_min_pu_size) - y0) >> vshift) * stride_src +
251 ((((x <<
sps->log2_min_pu_size) - x0) >> hshift) <<
sps->pixel_shift);
252 const uint8_t *
dst = dst1 +
253 (((y <<
sps->log2_min_pu_size) - y0) >> vshift) * stride_dst +
254 ((((x <<
sps->log2_min_pu_size) - x0) >> hshift) <<
sps->pixel_shift);
256 for (n = 0; n < (min_pu_size >> vshift); n++) {
267 #define CTB(tab, x, y) ((tab)[(y) * sps->ctb_width + (x)])
274 static const uint8_t sao_tab[8] = { 0, 1, 2, 2, 3, 3, 4, 4 };
277 int x_ctb = x >>
sps->log2_ctb_size;
278 int y_ctb = y >>
sps->log2_ctb_size;
279 int ctb_addr_rs = y_ctb *
sps->ctb_width + x_ctb;
280 int ctb_addr_ts =
pps->ctb_addr_rs_to_ts[ctb_addr_rs];
283 uint8_t vert_edge[] = { 0, 0 };
284 uint8_t horiz_edge[] = { 0, 0 };
285 uint8_t diag_edge[] = { 0, 0, 0, 0 };
287 uint8_t no_tile_filter =
pps->tiles_enabled_flag &&
288 !
pps->loop_filter_across_tiles_enabled_flag;
289 uint8_t restore = no_tile_filter || !lfase;
290 uint8_t left_tile_edge = 0;
291 uint8_t right_tile_edge = 0;
292 uint8_t up_tile_edge = 0;
293 uint8_t bottom_tile_edge = 0;
295 edges[0] = x_ctb == 0;
296 edges[1] = y_ctb == 0;
297 edges[2] = x_ctb ==
sps->ctb_width - 1;
298 edges[3] = y_ctb ==
sps->ctb_height - 1;
302 left_tile_edge = no_tile_filter &&
pps->tile_id[ctb_addr_ts] !=
pps->tile_id[
pps->ctb_addr_rs_to_ts[ctb_addr_rs-1]];
306 right_tile_edge = no_tile_filter &&
pps->tile_id[ctb_addr_ts] !=
pps->tile_id[
pps->ctb_addr_rs_to_ts[ctb_addr_rs+1]];
310 up_tile_edge = no_tile_filter &&
pps->tile_id[ctb_addr_ts] !=
pps->tile_id[
pps->ctb_addr_rs_to_ts[ctb_addr_rs -
sps->ctb_width]];
314 bottom_tile_edge = no_tile_filter &&
pps->tile_id[ctb_addr_ts] !=
pps->tile_id[
pps->ctb_addr_rs_to_ts[ctb_addr_rs +
sps->ctb_width]];
317 if (!edges[0] && !edges[1]) {
320 if (!edges[1] && !edges[2]) {
323 if (!edges[2] && !edges[3]) {
326 if (!edges[0] && !edges[3]) {
331 for (c_idx = 0; c_idx < (
sps->chroma_format_idc ? 3 : 1); c_idx++) {
332 int x0 = x >>
sps->hshift[c_idx];
333 int y0 = y >>
sps->vshift[c_idx];
334 ptrdiff_t stride_src =
s->cur_frame->f->linesize[c_idx];
335 int ctb_size_h = (1 << (
sps->log2_ctb_size)) >>
sps->hshift[c_idx];
336 int ctb_size_v = (1 << (
sps->log2_ctb_size)) >>
sps->vshift[c_idx];
340 uint8_t *
src = &
s->cur_frame->f->data[c_idx][y0 * stride_src + (x0 <<
sps->pixel_shift)];
341 ptrdiff_t stride_dst;
348 if (
pps->transquant_bypass_enable_flag ||
349 (
sps->pcm_loop_filter_disabled &&
sps->pcm_enabled)) {
353 s->hevcdsp.sao_band_filter[
tab](
src,
dst, stride_src, stride_dst,
359 s->hevcdsp.sao_band_filter[
tab](
src,
src, stride_src, stride_src,
367 int w =
sps->width >>
sps->hshift[c_idx];
368 int h =
sps->height >>
sps->vshift[c_idx];
369 int left_edge = edges[0];
370 int top_edge = edges[1];
371 int right_edge = edges[2];
372 int bottom_edge = edges[3];
373 int sh =
sps->pixel_shift;
374 int left_pixels, right_pixels;
380 int left = 1 - left_edge;
381 int right = 1 - right_edge;
382 const uint8_t *
src1[2];
386 dst1 =
dst - stride_dst - (
left << sh);
391 src_idx = (
CTB(l->
sao, x_ctb-1, y_ctb-1).type_idx[c_idx] ==
396 src_idx = (
CTB(l->
sao, x_ctb, y_ctb-1).type_idx[c_idx] ==
401 src_idx = (
CTB(l->
sao, x_ctb+1, y_ctb-1).type_idx[c_idx] ==
407 int left = 1 - left_edge;
408 int right = 1 - right_edge;
409 const uint8_t *
src1[2];
418 src_idx = (
CTB(l->
sao, x_ctb-1, y_ctb+1).type_idx[c_idx] ==
423 src_idx = (
CTB(l->
sao, x_ctb, y_ctb+1).type_idx[c_idx] ==
428 src_idx = (
CTB(l->
sao, x_ctb+1, y_ctb+1).type_idx[c_idx] ==
438 sh,
height, stride_dst, 1 << sh);
448 sh,
height, stride_dst, 1 << sh);
455 src - (left_pixels << sh),
456 (
width + left_pixels + right_pixels) << sh,
457 height, stride_dst, stride_src);
463 s->hevcdsp.sao_edge_restore[restore](
src,
dst,
464 stride_src, stride_dst,
482 int log2_min_pu_size =
sps->log2_min_pu_size;
488 x_pu = x >> log2_min_pu_size;
489 y_pu = y >> log2_min_pu_size;
491 if (x_pu >=
sps->min_pu_width || y_pu >=
sps->min_pu_height)
493 return is_pcm[y_pu *
sps->min_pu_width + x_pu];
496 #define TC_CALC(qp, bs) \
497 tctable[av_clip((qp) + DEFAULT_INTRA_TC_OFFSET * ((bs) - 1) + \
499 0, MAX_QP + DEFAULT_INTRA_TC_OFFSET)]
505 uint8_t **
data =
s->cur_frame->f->data;
506 int *linesize =
s->cur_frame->f->linesize;
512 uint8_t no_p[2] = { 0 };
513 uint8_t no_q[2] = { 0 };
515 int log2_ctb_size =
sps->log2_ctb_size;
516 int x_end, x_end2, y_end;
517 int ctb_size = 1 << log2_ctb_size;
518 int ctb = (x0 >> log2_ctb_size) +
519 (y0 >> log2_ctb_size) *
sps->ctb_width;
522 int left_tc_offset, left_beta_offset;
523 int tc_offset, beta_offset;
524 int pcmf = (
sps->pcm_enabled &&
525 sps->pcm_loop_filter_disabled) ||
526 pps->transquant_bypass_enable_flag;
533 left_beta_offset = 0;
536 x_end = x0 + ctb_size;
537 if (x_end >
sps->width)
539 y_end = y0 + ctb_size;
540 if (y_end >
sps->height)
543 tc_offset = cur_tc_offset;
544 beta_offset = cur_beta_offset;
547 if (x_end2 !=
sps->width)
549 for (y = y0; y < y_end; y += 8) {
551 for (x = x0 ? x0 : 8; x < x_end; x += 8) {
560 tc[0] = bs0 ?
TC_CALC(qp, bs0) : 0;
561 tc[1] = bs1 ?
TC_CALC(qp, bs1) : 0;
568 s->hevcdsp.hevc_v_loop_filter_luma_c(
src, linesize[
LUMA],
569 beta, tc, no_p, no_q);
571 s->hevcdsp.hevc_v_loop_filter_luma(
src, linesize[
LUMA],
572 beta, tc, no_p, no_q);
580 for (x = x0 ? x0 - 8 : 0; x < x_end2; x += 8) {
587 tc_offset = x >= x0 ? cur_tc_offset : left_tc_offset;
588 beta_offset = x >= x0 ? cur_beta_offset : left_beta_offset;
591 tc[0] = bs0 ?
TC_CALC(qp, bs0) : 0;
592 tc[1] = bs1 ?
TC_CALC(qp, bs1) : 0;
599 s->hevcdsp.hevc_h_loop_filter_luma_c(
src, linesize[
LUMA],
600 beta, tc, no_p, no_q);
602 s->hevcdsp.hevc_h_loop_filter_luma(
src, linesize[
LUMA],
603 beta, tc, no_p, no_q);
608 if (
sps->chroma_format_idc) {
614 for (y = y0; y < y_end; y += (8 * v)) {
615 for (x = x0 ? x0 : 8 *
h; x < x_end; x += (8 *
h)) {
619 if ((bs0 == 2) || (bs1 == 2)) {
633 s->hevcdsp.hevc_v_loop_filter_chroma_c(
src, linesize[
chroma],
636 s->hevcdsp.hevc_v_loop_filter_chroma(
src, linesize[
chroma],
645 tc_offset = x0 ? left_tc_offset : cur_tc_offset;
647 if (x_end !=
sps->width)
648 x_end2 = x_end - 8 *
h;
649 for (x = x0 ? x0 - 8 *
h : 0; x < x_end2; x += (8 *
h)) {
652 if ((bs0 == 2) || (bs1 == 2)) {
666 s->hevcdsp.hevc_h_loop_filter_chroma_c(
src, linesize[
chroma],
669 s->hevcdsp.hevc_h_loop_filter_chroma(
src, linesize[
chroma],
683 if (
s->cur_frame->refPicList[0].list[curr->
ref_idx[0]] == neigh_refPicList[0].
list[neigh->
ref_idx[0]] &&
684 s->cur_frame->refPicList[0].list[curr->
ref_idx[0]] ==
s->cur_frame->refPicList[1].list[curr->
ref_idx[1]] &&
693 }
else if (neigh_refPicList[0].
list[neigh->
ref_idx[0]] ==
s->cur_frame->refPicList[0].list[curr->
ref_idx[0]] &&
694 neigh_refPicList[1].
list[neigh->
ref_idx[1]] ==
s->cur_frame->refPicList[1].list[curr->
ref_idx[1]]) {
700 }
else if (neigh_refPicList[1].
list[neigh->
ref_idx[1]] ==
s->cur_frame->refPicList[0].list[curr->
ref_idx[0]] &&
701 neigh_refPicList[0].
list[neigh->
ref_idx[0]] ==
s->cur_frame->refPicList[1].list[curr->
ref_idx[1]]) {
716 ref_A =
s->cur_frame->refPicList[0].list[curr->
ref_idx[0]];
719 ref_A =
s->cur_frame->refPicList[1].list[curr->
ref_idx[1]];
724 ref_B = neigh_refPicList[0].
list[neigh->
ref_idx[0]];
727 ref_B = neigh_refPicList[1].
list[neigh->
ref_idx[1]];
730 if (ref_A == ref_B) {
744 int x0,
int y0,
int log2_trafo_size)
748 const MvField *tab_mvf =
s->cur_frame->tab_mvf;
749 int log2_min_pu_size =
sps->log2_min_pu_size;
750 int log2_min_tu_size =
sps->log2_min_tb_size;
751 int min_pu_width =
sps->min_pu_width;
752 int min_tu_width =
sps->min_tb_width;
753 int is_intra = tab_mvf[(y0 >> log2_min_pu_size) * min_pu_width +
755 int boundary_upper, boundary_left;
758 boundary_upper = y0 > 0 && !(y0 & 7);
759 if (boundary_upper &&
760 ((!
s->sh.slice_loop_filter_across_slices_enabled_flag &&
762 (y0 % (1 <<
sps->log2_ctb_size)) == 0) ||
763 (!
pps->loop_filter_across_tiles_enabled_flag &&
765 (y0 % (1 <<
sps->log2_ctb_size)) == 0)))
768 if (boundary_upper) {
771 s->cur_frame->refPicList;
772 int yp_pu = (y0 - 1) >> log2_min_pu_size;
773 int yq_pu = y0 >> log2_min_pu_size;
774 int yp_tu = (y0 - 1) >> log2_min_tu_size;
775 int yq_tu = y0 >> log2_min_tu_size;
777 for (
i = 0;
i < (1 << log2_trafo_size);
i += 4) {
778 int x_pu = (x0 +
i) >> log2_min_pu_size;
779 int x_tu = (x0 +
i) >> log2_min_tu_size;
780 const MvField *top = &tab_mvf[yp_pu * min_pu_width + x_pu];
781 const MvField *curr = &tab_mvf[yq_pu * min_pu_width + x_pu];
782 uint8_t top_cbf_luma = l->
cbf_luma[yp_tu * min_tu_width + x_tu];
783 uint8_t curr_cbf_luma = l->
cbf_luma[yq_tu * min_tu_width + x_tu];
787 else if (curr_cbf_luma || top_cbf_luma)
796 boundary_left = x0 > 0 && !(x0 & 7);
798 ((!
s->sh.slice_loop_filter_across_slices_enabled_flag &&
800 (x0 % (1 <<
sps->log2_ctb_size)) == 0) ||
801 (!
pps->loop_filter_across_tiles_enabled_flag &&
803 (x0 % (1 <<
sps->log2_ctb_size)) == 0)))
809 s->cur_frame->refPicList;
810 int xp_pu = (x0 - 1) >> log2_min_pu_size;
811 int xq_pu = x0 >> log2_min_pu_size;
812 int xp_tu = (x0 - 1) >> log2_min_tu_size;
813 int xq_tu = x0 >> log2_min_tu_size;
815 for (
i = 0;
i < (1 << log2_trafo_size);
i += 4) {
816 int y_pu = (y0 +
i) >> log2_min_pu_size;
817 int y_tu = (y0 +
i) >> log2_min_tu_size;
818 const MvField *
left = &tab_mvf[y_pu * min_pu_width + xp_pu];
819 const MvField *curr = &tab_mvf[y_pu * min_pu_width + xq_pu];
820 uint8_t left_cbf_luma = l->
cbf_luma[y_tu * min_tu_width + xp_tu];
821 uint8_t curr_cbf_luma = l->
cbf_luma[y_tu * min_tu_width + xq_tu];
825 else if (curr_cbf_luma || left_cbf_luma)
833 if (log2_trafo_size > log2_min_pu_size && !is_intra) {
837 for (j = 8; j < (1 << log2_trafo_size); j += 8) {
838 int yp_pu = (y0 + j - 1) >> log2_min_pu_size;
839 int yq_pu = (y0 + j) >> log2_min_pu_size;
841 for (
i = 0;
i < (1 << log2_trafo_size);
i += 4) {
842 int x_pu = (x0 +
i) >> log2_min_pu_size;
843 const MvField *top = &tab_mvf[yp_pu * min_pu_width + x_pu];
844 const MvField *curr = &tab_mvf[yq_pu * min_pu_width + x_pu];
852 for (j = 0; j < (1 << log2_trafo_size); j += 4) {
853 int y_pu = (y0 + j) >> log2_min_pu_size;
855 for (
i = 8;
i < (1 << log2_trafo_size);
i += 8) {
856 int xp_pu = (x0 +
i - 1) >> log2_min_pu_size;
857 int xq_pu = (x0 +
i) >> log2_min_pu_size;
858 const MvField *
left = &tab_mvf[y_pu * min_pu_width + xp_pu];
859 const MvField *curr = &tab_mvf[y_pu * min_pu_width + xq_pu];
874 int x,
int y,
int ctb_size)
878 int x_end = x >=
sps->width - ctb_size;
892 if (
sps->sao_enabled && !
skip) {
893 int y_end = y >=
sps->height - ctb_size;
903 if (x_end && y_end) {
914 int x_ctb,
int y_ctb,
int ctb_size)
916 int x_end = x_ctb >=
pps->sps->width - ctb_size;
917 int y_end = y_ctb >=
pps->sps->height - ctb_size;