39 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
40 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4,
41 5, 5, 6, 6, 7, 8, 9, 10, 11, 13, 14, 16, 18, 20, 22, 24
45 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 8,
46 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36,
47 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64
52 static const int qp_c[] = {
53 29, 30, 31, 32, 33, 33, 34, 34, 35, 35, 36, 36, 37, 37
55 int qp, qp_i,
offset, idxt;
63 qp_i = av_clip(qp_y + offset, 0, 57);
72 qp = av_clip(qp_i, 0, 51);
85 int xQgBase = xBase - (xBase & MinCuQpDeltaSizeMask);
86 int yQgBase = yBase - (yBase & MinCuQpDeltaSizeMask);
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;
108 qPy_a = s->
qp_y_tab[(x_cb - 1) + y_cb * min_cb_width];
114 qPy_b = s->
qp_y_tab[x_cb + (y_cb - 1) * min_cb_width];
119 return (qPy_a + qPy_b + 1) >> 1;
137 int x = xC >> log2_min_cb_size;
138 int y = yC >> log2_min_cb_size;
143 intptr_t stride_dst, intptr_t stride_src)
147 if (((intptr_t)dst | (intptr_t)src | stride_dst | stride_src) & 15) {
148 for (i = 0; i <
height; i++) {
149 for (j = 0; j <
width; j+=8)
155 for (i = 0; i <
height; i++) {
156 for (j = 0; j <
width; j+=16)
167 *(uint16_t *)dst = *(uint16_t *)
src;
173 int pixel_shift,
int height,
174 int stride_dst,
int stride_src)
177 if (pixel_shift == 0) {
178 for (i = 0; i <
height; i++) {
184 for (i = 0; i <
height; i++) {
185 *(uint16_t *)dst = *(uint16_t *)
src;
194 int c_idx,
int x_ctb,
int y_ctb)
204 src + stride_src * (height - 1), width << sh);
209 copy_vert(s->
sao_pixel_buffer_v[c_idx] + (((2 * x_ctb + 1) * h + y) << sh), src + ((width - 1) << sh), sh, height, 1 << sh, stride_src);
214 ptrdiff_t stride_src, ptrdiff_t stride_dst,
228 for (y = y_min; y < y_max; y++) {
229 for (x = x_min; x < x_max; x++) {
234 for (n = 0; n < (min_pu_size >> vshift); n++) {
235 memcpy(src, dst, len);
245 #define CTB(tab, x, y) ((tab)[(y) * s->sps->ctb_width + (x)])
249 static const uint8_t sao_tab[8] = { 0, 1, 2, 2, 3, 3, 4, 4 };
259 uint8_t vert_edge[] = { 0, 0 };
260 uint8_t horiz_edge[] = { 0, 0 };
261 uint8_t diag_edge[] = { 0, 0, 0, 0 };
265 uint8_t restore = no_tile_filter || !lfase;
271 edges[0] = x_ctb == 0;
272 edges[1] = y_ctb == 0;
293 if (!edges[0] && !edges[1]) {
296 if (!edges[1] && !edges[2]) {
299 if (!edges[2] && !edges[3]) {
302 if (!edges[0] && !edges[3]) {
315 int tab = sao_tab[(
FFALIGN(width, 8) >> 3) - 1];
333 x, y, width, height, c_idx);
345 int left_edge = edges[0];
346 int top_edge = edges[1];
347 int right_edge = edges[2];
348 int bottom_edge = edges[3];
350 int left_pixels, right_pixels;
356 int left = 1 - left_edge;
357 int right = 1 - right_edge;
362 dst1 = dst - stride_dst - (left << sh);
363 src1[0] = src - stride_src - (left << sh);
367 src_idx = (
CTB(s->
sao, x_ctb-1, y_ctb-1).type_idx[c_idx] ==
372 src_idx = (
CTB(s->
sao, x_ctb, y_ctb-1).type_idx[c_idx] ==
374 memcpy(dst1 + pos, src1[src_idx] + pos, width << sh);
377 src_idx = (
CTB(s->
sao, x_ctb+1, y_ctb-1).type_idx[c_idx] ==
379 copy_pixel(dst1 + pos, src1[src_idx] + pos, sh);
383 int left = 1 - left_edge;
384 int right = 1 - right_edge;
389 dst1 = dst + height * stride_dst - (left << sh);
390 src1[0] = src + height * stride_src - (left << sh);
394 src_idx = (
CTB(s->
sao, x_ctb-1, y_ctb+1).type_idx[c_idx] ==
399 src_idx = (
CTB(s->
sao, x_ctb, y_ctb+1).type_idx[c_idx] ==
401 memcpy(dst1 + pos, src1[src_idx] + pos, width << sh);
404 src_idx = (
CTB(s->
sao, x_ctb+1, y_ctb+1).type_idx[c_idx] ==
406 copy_pixel(dst1 + pos, src1[src_idx] + pos, sh);
414 sh, height, stride_dst, 1 << sh);
424 sh, height, stride_dst, 1 << sh);
431 src - (left_pixels << sh),
432 (width + left_pixels + right_pixels) << sh,
433 height, stride_dst, stride_src);
440 stride_src, stride_dst,
448 x, y, width, height, c_idx);
464 x_pu = x >> log2_min_pu_size;
465 y_pu = y >> log2_min_pu_size;
472 #define TC_CALC(qp, bs) \
473 tctable[av_clip((qp) + DEFAULT_INTRA_TC_OFFSET * ((bs) - 1) + \
474 (tc_offset >> 1 << 1), \
475 0, MAX_QP + DEFAULT_INTRA_TC_OFFSET)]
487 int x_end, x_end2, y_end;
488 int ctb_size = 1 << log2_ctb_size;
489 int ctb = (x0 >> log2_ctb_size) +
493 int left_tc_offset, left_beta_offset;
494 int tc_offset, beta_offset;
504 left_beta_offset = 0;
507 x_end = x0 + ctb_size;
510 y_end = y0 + ctb_size;
514 tc_offset = cur_tc_offset;
515 beta_offset = cur_beta_offset;
520 for (y = y0; y < y_end; y += 8) {
522 for (x = x0 ? x0 : 8; x < x_end; x += 8) {
526 const int qp = (
get_qPy(s, x - 1, y) +
get_qPy(s, x, y) + 1) >> 1;
530 tc[0] = bs0 ?
TC_CALC(qp, bs0) : 0;
531 tc[1] = bs1 ?
TC_CALC(qp, bs1) : 0;
534 no_p[0] =
get_pcm(s, x - 1, y);
535 no_p[1] =
get_pcm(s, x - 1, y + 4);
537 no_q[1] =
get_pcm(s, x, y + 4);
540 beta, tc, no_p, no_q);
544 beta, tc, no_p, no_q);
552 for (x = x0 ? x0 - 8 : 0; x < x_end2; x += 8) {
556 const int qp = (
get_qPy(s, x, y - 1) +
get_qPy(s, x, y) + 1) >> 1;
558 tc_offset = x >= x0 ? cur_tc_offset : left_tc_offset;
559 beta_offset = x >= x0 ? cur_beta_offset : left_beta_offset;
562 tc[0] = bs0 ?
TC_CALC(qp, bs0) : 0;
563 tc[1] = bs1 ?
TC_CALC(qp, bs1) : 0;
566 no_p[0] =
get_pcm(s, x, y - 1);
567 no_p[1] =
get_pcm(s, x + 4, y - 1);
569 no_q[1] =
get_pcm(s, x + 4, y);
572 beta, tc, no_p, no_q);
576 beta, tc, no_p, no_q);
582 for (chroma = 1; chroma <= 2; chroma++) {
587 for (y = y0; y < y_end; y += (8 *
v)) {
588 for (x = x0 ? x0 : 8 * h; x < x_end; x += (8 * h)) {
592 if ((bs0 == 2) || (bs1 == 2)) {
593 const int qp0 = (
get_qPy(s, x - 1, y) +
get_qPy(s, x, y) + 1) >> 1;
594 const int qp1 = (
get_qPy(s, x - 1, y + (4 * v)) +
get_qPy(s, x, y + (4 * v)) + 1) >> 1;
596 c_tc[0] = (bs0 == 2) ?
chroma_tc(s, qp0, chroma, tc_offset) : 0;
597 c_tc[1] = (bs1 == 2) ?
chroma_tc(s, qp1, chroma, tc_offset) : 0;
600 no_p[0] =
get_pcm(s, x - 1, y);
601 no_p[1] =
get_pcm(s, x - 1, y + (4 * v));
603 no_q[1] =
get_pcm(s, x, y + (4 * v));
618 tc_offset = x0 ? left_tc_offset : cur_tc_offset;
621 x_end2 = x_end - 8 * h;
622 for (x = x0 ? x0 - 8 * h : 0; x < x_end2; x += (8 * h)) {
625 if ((bs0 == 2) || (bs1 == 2)) {
626 const int qp0 = bs0 == 2 ? (
get_qPy(s, x, y - 1) +
get_qPy(s, x, y) + 1) >> 1 : 0;
627 const int qp1 = bs1 == 2 ? (
get_qPy(s, x + (4 * h), y - 1) +
get_qPy(s, x + (4 * h), y) + 1) >> 1 : 0;
629 c_tc[0] = bs0 == 2 ?
chroma_tc(s, qp0, chroma, tc_offset) : 0;
630 c_tc[1] = bs1 == 2 ?
chroma_tc(s, qp1, chroma, cur_tc_offset) : 0;
633 no_p[0] =
get_pcm(s, x, y - 1);
634 no_p[1] =
get_pcm(s, x + (4 * h), y - 1);
636 no_q[1] =
get_pcm(s, x + (4 * h), y);
697 ref_B = neigh_refPicList[0].
list[neigh->
ref_idx[0]];
700 ref_B = neigh_refPicList[1].
list[neigh->
ref_idx[1]];
703 if (ref_A == ref_B) {
724 int is_intra = tab_mvf[(y0 >> log2_min_pu_size) * min_pu_width +
726 int boundary_upper, boundary_left;
729 boundary_upper = y0 > 0 && !(y0 & 7);
730 if (boundary_upper &&
739 if (boundary_upper) {
743 int yp_pu = (y0 - 1) >> log2_min_pu_size;
744 int yq_pu = y0 >> log2_min_pu_size;
745 int yp_tu = (y0 - 1) >> log2_min_tu_size;
746 int yq_tu = y0 >> log2_min_tu_size;
748 for (i = 0; i < (1 << log2_trafo_size); i += 4) {
749 int x_pu = (x0 + i) >> log2_min_pu_size;
750 int x_tu = (x0 + i) >> log2_min_tu_size;
751 MvField *top = &tab_mvf[yp_pu * min_pu_width + x_pu];
752 MvField *curr = &tab_mvf[yq_pu * min_pu_width + x_pu];
758 else if (curr_cbf_luma || top_cbf_luma)
767 boundary_left = x0 > 0 && !(x0 & 7);
781 int xp_pu = (x0 - 1) >> log2_min_pu_size;
782 int xq_pu = x0 >> log2_min_pu_size;
783 int xp_tu = (x0 - 1) >> log2_min_tu_size;
784 int xq_tu = x0 >> log2_min_tu_size;
786 for (i = 0; i < (1 << log2_trafo_size); i += 4) {
787 int y_pu = (y0 + i) >> log2_min_pu_size;
788 int y_tu = (y0 + i) >> log2_min_tu_size;
789 MvField *left = &tab_mvf[y_pu * min_pu_width + xp_pu];
790 MvField *curr = &tab_mvf[y_pu * min_pu_width + xq_pu];
796 else if (curr_cbf_luma || left_cbf_luma)
804 if (log2_trafo_size > log2_min_pu_size && !is_intra) {
808 for (j = 8; j < (1 << log2_trafo_size); j += 8) {
809 int yp_pu = (y0 + j - 1) >> log2_min_pu_size;
810 int yq_pu = (y0 + j) >> log2_min_pu_size;
812 for (i = 0; i < (1 << log2_trafo_size); i += 4) {
813 int x_pu = (x0 + i) >> log2_min_pu_size;
814 MvField *top = &tab_mvf[yp_pu * min_pu_width + x_pu];
815 MvField *curr = &tab_mvf[yq_pu * min_pu_width + x_pu];
823 for (j = 0; j < (1 << log2_trafo_size); j += 4) {
824 int y_pu = (y0 + j) >> log2_min_pu_size;
826 for (i = 8; i < (1 << log2_trafo_size); i += 8) {
827 int xp_pu = (x0 + i - 1) >> log2_min_pu_size;
828 int xq_pu = (x0 + i) >> log2_min_pu_size;
829 MvField *left = &tab_mvf[y_pu * min_pu_width + xp_pu];
830 MvField *curr = &tab_mvf[y_pu * min_pu_width + xq_pu];
845 int x_end = x >= s->
sps->
width - ctb_size;
848 int y_end = y >= s->
sps->
height - ctb_size;
858 if (x_end && y_end) {
869 int x_end = x_ctb >= s->
sps->
width - ctb_size;
870 int y_end = y_ctb >= s->
sps->
height - ctb_size;