~ppsspp/ppsspp/ffmpeg

« back to all changes in this revision

Viewing changes to libavcodec/hevc_filter.c

  • Committer: Henrik Rydgård
  • Date: 2014-01-03 10:44:32 UTC
  • Revision ID: git-v1:87c6c126784b1718bfa448ecf2e6a9fef781eb4e
Update our ffmpeg snapshot to a clone of the official repository.

This is because Maxim's at3plus support has been officially merged!

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * HEVC video Decoder
 
2
 * HEVC video decoder
3
3
 *
4
4
 * Copyright (C) 2012 - 2013 Guillaume Martres
5
5
 * Copyright (C) 2013 Seppo Tomperi
28
28
#include "cabac_functions.h"
29
29
#include "golomb.h"
30
30
#include "hevc.h"
 
31
 
31
32
#include "bit_depth_template.c"
32
33
 
33
34
#define LUMA 0
35
36
#define CR 2
36
37
 
37
38
static const uint8_t tctable[54] = {
38
 
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, // QP  0...18
39
 
     1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, // QP 19...37
40
 
     5, 5, 6, 6, 7, 8, 9,10,11,13,14,16,18,20,22,24           // QP 38...53
 
39
    0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 0, 0, 1, // QP  0...18
 
40
    1, 1, 1, 1, 1, 1, 1,  1,  2,  2,  2,  2,  3,  3,  3,  3, 4, 4, 4, // QP 19...37
 
41
    5, 5, 6, 6, 7, 8, 9, 10, 11, 13, 14, 16, 18, 20, 22, 24           // QP 38...53
41
42
};
42
43
 
43
44
static const uint8_t betatable[52] = {
44
 
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 8, // QP 0...18
45
 
     9,10,11,12,13,14,15,16,17,18,20,22,24,26,28,30,32,34,36, // QP 19...37
46
 
    38,40,42,44,46,48,50,52,54,56,58,60,62,64                 // QP 38...51
 
45
     0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  6,  7,  8, // QP 0...18
 
46
     9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, // QP 19...37
 
47
    38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64                      // QP 38...51
47
48
};
48
49
 
49
50
static int chroma_tc(HEVCContext *s, int qp_y, int c_idx, int tc_offset)
50
51
{
51
 
    static const int qp_c[] = { 29, 30, 31, 32, 33, 33, 34, 34, 35, 35, 36, 36, 37, 37 };
52
 
    int qp_i, offset;
53
 
    int qp;
54
 
    int idxt;
 
52
    static const int qp_c[] = {
 
53
        29, 30, 31, 32, 33, 33, 34, 34, 35, 35, 36, 36, 37, 37
 
54
    };
 
55
    int qp, qp_i, offset, idxt;
55
56
 
56
57
    // slice qp offset is not used for deblocking
57
58
    if (c_idx == 1)
71
72
    return tctable[idxt];
72
73
}
73
74
 
74
 
static int get_qPy_pred(HEVCContext *s, int xC, int yC, int xBase, int yBase, int log2_cb_size)
 
75
static int get_qPy_pred(HEVCContext *s, int xC, int yC,
 
76
                        int xBase, int yBase, int log2_cb_size)
75
77
{
76
 
    HEVCLocalContext *lc     = &s->HEVClc;
 
78
    HEVCLocalContext *lc     = s->HEVClc;
77
79
    int ctb_size_mask        = (1 << s->sps->log2_ctb_size) - 1;
78
 
    int MinCuQpDeltaSizeMask = (1 << (s->sps->log2_ctb_size - s->pps->diff_cu_qp_delta_depth)) - 1;
79
 
    int xQgBase              = xBase - ( xBase & MinCuQpDeltaSizeMask );
80
 
    int yQgBase              = yBase - ( yBase & MinCuQpDeltaSizeMask );
81
 
    int pic_width            = s->sps->width  >> s->sps->log2_min_coding_block_size;
82
 
    int pic_height           = s->sps->height >> s->sps->log2_min_coding_block_size;
83
 
    int x_cb                 = xQgBase >> s->sps->log2_min_coding_block_size;
84
 
    int y_cb                 = yQgBase >> s->sps->log2_min_coding_block_size;
85
 
    int availableA           = (xBase & ctb_size_mask) && (xQgBase & ctb_size_mask);
86
 
    int availableB           = (yBase & ctb_size_mask) && (yQgBase & ctb_size_mask);
87
 
    int qPy_pred;
88
 
    int qPy_a;
89
 
    int qPy_b;
 
80
    int MinCuQpDeltaSizeMask = (1 << (s->sps->log2_ctb_size -
 
81
                                      s->pps->diff_cu_qp_delta_depth)) - 1;
 
82
    int xQgBase              = xBase - (xBase & MinCuQpDeltaSizeMask);
 
83
    int yQgBase              = yBase - (yBase & MinCuQpDeltaSizeMask);
 
84
    int min_cb_width         = s->sps->min_cb_width;
 
85
    int min_cb_height        = s->sps->min_cb_height;
 
86
    int x_cb                 = xQgBase >> s->sps->log2_min_cb_size;
 
87
    int y_cb                 = yQgBase >> s->sps->log2_min_cb_size;
 
88
    int availableA           = (xBase   & ctb_size_mask) &&
 
89
                               (xQgBase & ctb_size_mask);
 
90
    int availableB           = (yBase   & ctb_size_mask) &&
 
91
                               (yQgBase & ctb_size_mask);
 
92
    int qPy_pred, qPy_a, qPy_b;
90
93
 
91
94
    // qPy_pred
92
95
    if (lc->first_qp_group) {
94
97
        qPy_pred = s->sh.slice_qp;
95
98
    } else {
96
99
        qPy_pred = lc->qp_y;
97
 
        if (log2_cb_size < s->sps->log2_ctb_size - s->pps->diff_cu_qp_delta_depth) {
 
100
        if (log2_cb_size < s->sps->log2_ctb_size -
 
101
                           s->pps->diff_cu_qp_delta_depth) {
98
102
            static const int offsetX[8][8] = {
99
 
                    {-1, 1, 3, 1, 7, 1, 3, 1},
100
 
                    { 0, 0, 0, 0, 0, 0, 0, 0},
101
 
                    { 1, 3, 1, 3, 1, 3, 1, 3},
102
 
                    { 2, 2, 2, 2, 2, 2, 2, 2},
103
 
                    { 3, 5, 7, 5, 3, 5, 7, 5},
104
 
                    { 4, 4, 4, 4, 4, 4, 4, 4},
105
 
                    { 5, 7, 5, 7, 5, 7, 5, 7},
106
 
                    { 6, 6, 6, 6, 6, 6, 6, 6}
 
103
                { -1, 1, 3, 1, 7, 1, 3, 1 },
 
104
                {  0, 0, 0, 0, 0, 0, 0, 0 },
 
105
                {  1, 3, 1, 3, 1, 3, 1, 3 },
 
106
                {  2, 2, 2, 2, 2, 2, 2, 2 },
 
107
                {  3, 5, 7, 5, 3, 5, 7, 5 },
 
108
                {  4, 4, 4, 4, 4, 4, 4, 4 },
 
109
                {  5, 7, 5, 7, 5, 7, 5, 7 },
 
110
                {  6, 6, 6, 6, 6, 6, 6, 6 }
107
111
            };
108
112
            static const int offsetY[8][8] = {
109
 
                    { 7, 0, 1, 2, 3, 4, 5, 6},
110
 
                    { 0, 1, 2, 3, 4, 5, 6, 7},
111
 
                    { 1, 0, 3, 2, 5, 4, 7, 6},
112
 
                    { 0, 1, 2, 3, 4, 5, 6, 7},
113
 
                    { 3, 0, 1, 2, 7, 4, 5, 6},
114
 
                    { 0, 1, 2, 3, 4, 5, 6, 7},
115
 
                    { 1, 0, 3, 2, 5, 4, 7, 6},
116
 
                    { 0, 1, 2, 3, 4, 5, 6, 7}
 
113
                { 7, 0, 1, 2, 3, 4, 5, 6 },
 
114
                { 0, 1, 2, 3, 4, 5, 6, 7 },
 
115
                { 1, 0, 3, 2, 5, 4, 7, 6 },
 
116
                { 0, 1, 2, 3, 4, 5, 6, 7 },
 
117
                { 3, 0, 1, 2, 7, 4, 5, 6 },
 
118
                { 0, 1, 2, 3, 4, 5, 6, 7 },
 
119
                { 1, 0, 3, 2, 5, 4, 7, 6 },
 
120
                { 0, 1, 2, 3, 4, 5, 6, 7 }
117
121
            };
118
 
            int xC0b = (xC - (xC & ctb_size_mask)) >> s->sps->log2_min_coding_block_size;
119
 
            int yC0b = (yC - (yC & ctb_size_mask)) >> s->sps->log2_min_coding_block_size;
120
 
            int idxX = (xQgBase & ctb_size_mask)   >> s->sps->log2_min_coding_block_size;
121
 
            int idxY = (yQgBase & ctb_size_mask)   >> s->sps->log2_min_coding_block_size;
122
 
            int idx_mask = ctb_size_mask >> s->sps->log2_min_coding_block_size;
 
122
            int xC0b = (xC - (xC & ctb_size_mask)) >> s->sps->log2_min_cb_size;
 
123
            int yC0b = (yC - (yC & ctb_size_mask)) >> s->sps->log2_min_cb_size;
 
124
            int idxX = (xQgBase  & ctb_size_mask)  >> s->sps->log2_min_cb_size;
 
125
            int idxY = (yQgBase  & ctb_size_mask)  >> s->sps->log2_min_cb_size;
 
126
            int idx_mask = ctb_size_mask >> s->sps->log2_min_cb_size;
123
127
            int x, y;
124
128
 
125
 
            x = FFMIN(xC0b + offsetX[idxX][idxY],              pic_width  - 1);
126
 
            y = FFMIN(yC0b + (offsetY[idxX][idxY] & idx_mask), pic_height - 1);
 
129
            x = FFMIN(xC0b +  offsetX[idxX][idxY],             min_cb_width  - 1);
 
130
            y = FFMIN(yC0b + (offsetY[idxX][idxY] & idx_mask), min_cb_height - 1);
127
131
 
128
 
            if (xC0b == (lc->start_of_tiles_x >> s->sps->log2_min_coding_block_size) &&
 
132
            if (xC0b == (lc->start_of_tiles_x >> s->sps->log2_min_cb_size) &&
129
133
                offsetX[idxX][idxY] == -1) {
130
 
                x = (lc->end_of_tiles_x >> s->sps->log2_min_coding_block_size) - 1;
 
134
                x = (lc->end_of_tiles_x >> s->sps->log2_min_cb_size) - 1;
131
135
                y = yC0b - 1;
132
136
            }
133
 
            qPy_pred = s->qp_y_tab[y * pic_width + x];
 
137
            qPy_pred = s->qp_y_tab[y * min_cb_width + x];
134
138
        }
135
139
    }
136
140
 
138
142
    if (availableA == 0)
139
143
        qPy_a = qPy_pred;
140
144
    else
141
 
        qPy_a = s->qp_y_tab[(x_cb - 1) + y_cb * pic_width];
 
145
        qPy_a = s->qp_y_tab[(x_cb - 1) + y_cb * min_cb_width];
142
146
 
143
147
    // qPy_b
144
148
    if (availableB == 0)
145
149
        qPy_b = qPy_pred;
146
150
    else
147
 
        qPy_b = s->qp_y_tab[x_cb + (y_cb - 1) * pic_width];
 
151
        qPy_b = s->qp_y_tab[x_cb + (y_cb - 1) * min_cb_width];
148
152
 
149
153
    return (qPy_a + qPy_b + 1) >> 1;
150
154
}
151
155
 
152
 
void ff_hevc_set_qPy(HEVCContext *s, int xC, int yC, int xBase, int yBase, int log2_cb_size)
 
156
void ff_hevc_set_qPy(HEVCContext *s, int xC, int yC,
 
157
                     int xBase, int yBase, int log2_cb_size)
153
158
{
154
159
    int qp_y = get_qPy_pred(s, xC, yC, xBase, yBase, log2_cb_size);
155
160
 
156
 
    if (s->HEVClc.tu.cu_qp_delta != 0) {
 
161
    if (s->HEVClc->tu.cu_qp_delta != 0) {
157
162
        int off = s->sps->qp_bd_offset;
158
 
        s->HEVClc.qp_y = ((qp_y + s->HEVClc.tu.cu_qp_delta + 52 + 2 * off) % (52 + off)) - off;
 
163
        s->HEVClc->qp_y = ((qp_y + s->HEVClc->tu.cu_qp_delta + 52 + 2 * off) %
 
164
                          (52 + off)) - off;
159
165
    } else
160
 
        s->HEVClc.qp_y = qp_y;
 
166
        s->HEVClc->qp_y = qp_y;
161
167
}
162
168
 
163
169
static int get_qPy(HEVCContext *s, int xC, int yC)
164
170
{
165
 
    int log2_min_cb_size  = s->sps->log2_min_coding_block_size;
166
 
    int pic_width         = s->sps->width>>log2_min_cb_size;
 
171
    int log2_min_cb_size  = s->sps->log2_min_cb_size;
167
172
    int x                 = xC >> log2_min_cb_size;
168
173
    int y                 = yC >> log2_min_cb_size;
169
 
    return s->qp_y_tab[x + y * pic_width];
 
174
    return s->qp_y_tab[x + y * s->sps->min_cb_width];
170
175
}
171
176
 
172
 
static void copy_CTB(uint8_t *dst, uint8_t *src, int width, int height, int stride)
 
177
static void copy_CTB(uint8_t *dst, uint8_t *src,
 
178
                     int width, int height, int stride)
173
179
{
174
180
    int i;
175
181
 
176
 
    for(i=0; i< height; i++){
 
182
    for (i = 0; i < height; i++) {
177
183
        memcpy(dst, src, width);
178
184
        dst += stride;
179
185
        src += stride;
182
188
 
183
189
#define CTB(tab, x, y) ((tab)[(y) * s->sps->ctb_width + (x)])
184
190
 
185
 
static void sao_filter_CTB(HEVCContext *s, int x, int y, int c_idx_min, int c_idx_max)
 
191
static void sao_filter_CTB(HEVCContext *s, int x, int y)
186
192
{
187
193
    //  TODO: This should be easily parallelizable
188
194
    //  TODO: skip CBs when (cu_transquant_bypass_flag || (pcm_loop_filter_disable_flag && pcm_flag))
189
195
    int c_idx = 0;
190
196
    int class = 1, class_index;
191
 
    int  edges[4]; // 0 left 1 top 2 right 3 bottom
 
197
    int edges[4];  // 0 left 1 top 2 right 3 bottom
192
198
    SAOParams *sao[4];
193
199
    int classes[4];
194
200
    int x_shift = 0, y_shift = 0;
195
 
    int x_ctb = x>>s->sps->log2_ctb_size;
196
 
    int y_ctb = y>>s->sps->log2_ctb_size;
 
201
    int x_ctb = x >> s->sps->log2_ctb_size;
 
202
    int y_ctb = y >> s->sps->log2_ctb_size;
197
203
    int ctb_addr_rs = y_ctb * s->sps->ctb_width + x_ctb;
198
204
    int ctb_addr_ts = s->pps->ctb_addr_rs_to_ts[ctb_addr_rs];
199
205
 
200
206
    // flags indicating unfilterable edges
201
 
    uint8_t vert_edge[] = {0,0,0,0};
202
 
    uint8_t horiz_edge[] = {0,0,0,0};
203
 
    uint8_t diag_edge[] = {0,0,0,0};
 
207
    uint8_t vert_edge[]  = { 0, 0, 0, 0 };
 
208
    uint8_t horiz_edge[] = { 0, 0, 0, 0 };
 
209
    uint8_t diag_edge[]  = { 0, 0, 0, 0 };
204
210
    uint8_t lfase[3]; // current, above, left
205
 
    uint8_t no_tile_filter = s->pps->tiles_enabled_flag && !s->pps->loop_filter_across_tiles_enabled_flag;
 
211
    uint8_t no_tile_filter = s->pps->tiles_enabled_flag &&
 
212
                             !s->pps->loop_filter_across_tiles_enabled_flag;
206
213
    uint8_t left_tile_edge = 0;
207
214
    uint8_t up_tile_edge = 0;
208
215
 
209
216
    sao[0]     = &CTB(s->sao, x_ctb, y_ctb);
210
217
    edges[0]   = x_ctb == 0;
211
218
    edges[1]   = y_ctb == 0;
212
 
    edges[2]   = x_ctb == (s->sps->ctb_width - 1);
213
 
    edges[3]   = y_ctb == (s->sps->ctb_height - 1);
 
219
    edges[2]   = x_ctb == s->sps->ctb_width  - 1;
 
220
    edges[3]   = y_ctb == s->sps->ctb_height - 1;
214
221
    lfase[0]   = CTB(s->filter_slice_edges, x_ctb, y_ctb);
215
222
    classes[0] = 0;
216
223
 
250
257
            diag_edge[3] = diag_edge[0];
251
258
 
252
259
            // Does left CTB comes after above CTB?
253
 
            if(CTB(s->tab_slice_address, x_ctb - 1, y_ctb) > CTB(s->tab_slice_address, x_ctb, y_ctb - 1)) {
 
260
            if (CTB(s->tab_slice_address, x_ctb - 1, y_ctb) >
 
261
                CTB(s->tab_slice_address, x_ctb, y_ctb - 1)) {
254
262
                diag_edge[2] = !lfase[2] || left_tile_edge || up_tile_edge;
255
263
                diag_edge[1] = diag_edge[2];
256
 
            } else if(CTB(s->tab_slice_address, x_ctb - 1, y_ctb) < CTB(s->tab_slice_address, x_ctb, y_ctb - 1)) {
 
264
            } else if (CTB(s->tab_slice_address, x_ctb - 1, y_ctb) <
 
265
                       CTB(s->tab_slice_address, x_ctb, y_ctb - 1)) {
257
266
                diag_edge[1] = !lfase[1] || left_tile_edge || up_tile_edge;
258
267
                diag_edge[2] = diag_edge[1];
259
268
            } else {
283
292
                 (edges[2] ? width  + (x_shift >> chroma) : width)  << s->sps->pixel_shift,
284
293
                 (edges[3] ? height + (y_shift >> chroma) : height), stride);
285
294
 
286
 
        for (class_index = 0; class_index < class && c_idx >= c_idx_min &&
287
 
                              c_idx < c_idx_max; class_index++) {
 
295
        for (class_index = 0; class_index < class; class_index++) {
 
296
 
288
297
            switch (sao[class_index]->type_idx[c_idx]) {
289
298
            case SAO_BAND:
290
 
                s->hevcdsp.sao_band_filter[classes[class_index]](dst, src, stride, sao[class_index], edges, width, height, c_idx);
291
 
                    break;
 
299
                s->hevcdsp.sao_band_filter[classes[class_index]](dst, src,
 
300
                                                                 stride,
 
301
                                                                 sao[class_index],
 
302
                                                                 edges, width,
 
303
                                                                 height, c_idx);
 
304
                break;
292
305
            case SAO_EDGE:
293
 
                s->hevcdsp.sao_edge_filter[classes[class_index]](dst, src, stride, sao[class_index],  edges, width, height, c_idx, vert_edge[classes[class_index]], horiz_edge[classes[class_index]], diag_edge[classes[class_index]]);
 
306
                s->hevcdsp.sao_edge_filter[classes[class_index]](dst, src,
 
307
                                                                 stride,
 
308
                                                                 sao[class_index],
 
309
                                                                 edges, width,
 
310
                                                                 height, c_idx,
 
311
                                                                 vert_edge[classes[class_index]],
 
312
                                                                 horiz_edge[classes[class_index]],
 
313
                                                                 diag_edge[classes[class_index]]);
294
314
                break;
295
315
            }
296
316
        }
299
319
 
300
320
static int get_pcm(HEVCContext *s, int x, int y)
301
321
{
302
 
    int log2_min_pu_size     = s->sps->log2_min_pu_size;
303
 
    int pic_width_in_min_pu  = s->sps->width  >> s->sps->log2_min_pu_size;
304
 
    int pic_height_in_min_pu = s->sps->height >> s->sps->log2_min_pu_size;
305
 
    int x_pu = x >> log2_min_pu_size;
306
 
    int y_pu = y >> log2_min_pu_size;
 
322
    int log2_min_pu_size = s->sps->log2_min_pu_size;
 
323
    int x_pu             = x >> log2_min_pu_size;
 
324
    int y_pu             = y >> log2_min_pu_size;
307
325
 
308
 
    if (x < 0 || x_pu >= pic_width_in_min_pu || y < 0 || y_pu >= pic_height_in_min_pu)
 
326
    if (x < 0 || x_pu >= s->sps->min_pu_width ||
 
327
        y < 0 || y_pu >= s->sps->min_pu_height)
309
328
        return 2;
310
 
    return s->is_pcm[y_pu * pic_width_in_min_pu + x_pu];
 
329
    return s->is_pcm[y_pu * s->sps->min_pu_width + x_pu];
311
330
}
312
331
 
313
 
#define TC_CALC(qp, bs) tctable[av_clip((qp) + DEFAULT_INTRA_TC_OFFSET * ((bs) - 1) + ((tc_offset >> 1) << 1), 0, MAX_QP + DEFAULT_INTRA_TC_OFFSET)]
 
332
#define TC_CALC(qp, bs)                                                 \
 
333
    tctable[av_clip((qp) + DEFAULT_INTRA_TC_OFFSET * ((bs) - 1) +       \
 
334
                    (tc_offset >> 1 << 1),                              \
 
335
                    0, MAX_QP + DEFAULT_INTRA_TC_OFFSET)]
314
336
 
315
337
static void deblocking_filter_CTB(HEVCContext *s, int x0, int y0)
316
338
{
317
339
    uint8_t *src;
318
340
    int x, y;
319
341
    int chroma;
320
 
    int c_tc[2];
321
 
    int beta[2];
322
 
    int tc[2];
323
 
    uint8_t no_p[2] = {0};
324
 
    uint8_t no_q[2] = {0};
 
342
    int c_tc[2], beta[2], tc[2];
 
343
    uint8_t no_p[2] = { 0 };
 
344
    uint8_t no_q[2] = { 0 };
325
345
 
326
 
    int log2_ctb_size =  s->sps->log2_ctb_size;
 
346
    int log2_ctb_size = s->sps->log2_ctb_size;
327
347
    int x_end, y_end;
328
 
    int ctb_size    = 1<<log2_ctb_size;
329
 
    int ctb         = (x0 >> log2_ctb_size) + (y0 >> log2_ctb_size) * s->sps->ctb_width;
 
348
    int ctb_size        = 1 << log2_ctb_size;
 
349
    int ctb             = (x0 >> log2_ctb_size) +
 
350
                          (y0 >> log2_ctb_size) * s->sps->ctb_width;
330
351
    int cur_tc_offset   = s->deblock[ctb].tc_offset;
331
352
    int cur_beta_offset = s->deblock[ctb].beta_offset;
332
353
    int left_tc_offset, left_beta_offset;
333
354
    int tc_offset, beta_offset;
334
 
    int pcmf        = (s->sps->pcm_enabled_flag && s->sps->pcm.loop_filter_disable_flag) ||
335
 
                      s->pps->transquant_bypass_enable_flag;
336
 
 
337
 
    if (s->deblock[ctb].disable)
338
 
        return;
 
355
    int pcmf = (s->sps->pcm_enabled_flag &&
 
356
                s->sps->pcm.loop_filter_disable_flag) ||
 
357
               s->pps->transquant_bypass_enable_flag;
339
358
 
340
359
    if (x0) {
341
 
        left_tc_offset   = s->deblock[ctb-1].tc_offset;
342
 
        left_beta_offset = s->deblock[ctb-1].beta_offset;
 
360
        left_tc_offset   = s->deblock[ctb - 1].tc_offset;
 
361
        left_beta_offset = s->deblock[ctb - 1].beta_offset;
343
362
    }
344
363
 
345
 
    x_end = x0+ctb_size;
 
364
    x_end = x0 + ctb_size;
346
365
    if (x_end > s->sps->width)
347
366
        x_end = s->sps->width;
348
 
    y_end = y0+ctb_size;
 
367
    y_end = y0 + ctb_size;
349
368
    if (y_end > s->sps->height)
350
369
        y_end = s->sps->height;
351
370
 
352
 
    tc_offset = cur_tc_offset;
 
371
    tc_offset   = cur_tc_offset;
353
372
    beta_offset = cur_beta_offset;
354
373
 
355
374
    // vertical filtering luma
358
377
            const int bs0 = s->vertical_bs[(x >> 3) + (y       >> 2) * s->bs_width];
359
378
            const int bs1 = s->vertical_bs[(x >> 3) + ((y + 4) >> 2) * s->bs_width];
360
379
            if (bs0 || bs1) {
361
 
                const int qp0 = (get_qPy(s, x - 1, y) + get_qPy(s, x, y) + 1) >> 1;
 
380
                const int qp0 = (get_qPy(s, x - 1, y)     + get_qPy(s, x, y)     + 1) >> 1;
362
381
                const int qp1 = (get_qPy(s, x - 1, y + 4) + get_qPy(s, x, y + 4) + 1) >> 1;
363
382
 
364
 
                beta[0] = betatable[av_clip(qp0 + ((beta_offset >> 1) << 1), 0, MAX_QP)];
365
 
                beta[1] = betatable[av_clip(qp1 + ((beta_offset >> 1) << 1), 0, MAX_QP)];
366
 
                tc[0] = bs0 ? TC_CALC(qp0, bs0) : 0;
367
 
                tc[1] = bs1 ? TC_CALC(qp1, bs1) : 0;
368
 
                src = &s->frame->data[LUMA][y * s->frame->linesize[LUMA] + (x << s->sps->pixel_shift)];
 
383
                beta[0] = betatable[av_clip(qp0 + (beta_offset >> 1 << 1), 0, MAX_QP)];
 
384
                beta[1] = betatable[av_clip(qp1 + (beta_offset >> 1 << 1), 0, MAX_QP)];
 
385
                tc[0]   = bs0 ? TC_CALC(qp0, bs0) : 0;
 
386
                tc[1]   = bs1 ? TC_CALC(qp1, bs1) : 0;
 
387
                src     = &s->frame->data[LUMA][y * s->frame->linesize[LUMA] + (x << s->sps->pixel_shift)];
369
388
                if (pcmf) {
370
389
                    no_p[0] = get_pcm(s, x - 1, y);
371
390
                    no_p[1] = get_pcm(s, x - 1, y + 4);
372
391
                    no_q[0] = get_pcm(s, x, y);
373
392
                    no_q[1] = get_pcm(s, x, y + 4);
374
 
                    s->hevcdsp.hevc_v_loop_filter_luma_c(src, s->frame->linesize[LUMA], beta, tc, no_p, no_q);
 
393
                    s->hevcdsp.hevc_v_loop_filter_luma_c(src,
 
394
                                                         s->frame->linesize[LUMA],
 
395
                                                         beta, tc, no_p, no_q);
375
396
                } else
376
 
                    s->hevcdsp.hevc_v_loop_filter_luma(src, s->frame->linesize[LUMA], beta, tc, no_p, no_q);
 
397
                    s->hevcdsp.hevc_v_loop_filter_luma(src,
 
398
                                                       s->frame->linesize[LUMA],
 
399
                                                       beta, tc, no_p, no_q);
377
400
            }
378
401
        }
379
402
    }
381
404
    // vertical filtering chroma
382
405
    for (chroma = 1; chroma <= 2; chroma++) {
383
406
        for (y = y0; y < y_end; y += 16) {
384
 
            for (x = x0 ? x0:16; x < x_end; x += 16) {
385
 
                const int bs0 = s->vertical_bs[(x >> 3) + (y >> 2) * s->bs_width];
 
407
            for (x = x0 ? x0 : 16; x < x_end; x += 16) {
 
408
                const int bs0 = s->vertical_bs[(x >> 3) + (y       >> 2) * s->bs_width];
386
409
                const int bs1 = s->vertical_bs[(x >> 3) + ((y + 8) >> 2) * s->bs_width];
387
410
                if ((bs0 == 2) || (bs1 == 2)) {
388
 
                    const int qp0 = (get_qPy(s, x - 1, y) + get_qPy(s, x, y) + 1) >> 1;
 
411
                    const int qp0 = (get_qPy(s, x - 1, y)     + get_qPy(s, x, y)     + 1) >> 1;
389
412
                    const int qp1 = (get_qPy(s, x - 1, y + 8) + get_qPy(s, x, y + 8) + 1) >> 1;
390
413
 
391
414
                    c_tc[0] = (bs0 == 2) ? chroma_tc(s, qp0, chroma, tc_offset) : 0;
392
415
                    c_tc[1] = (bs1 == 2) ? chroma_tc(s, qp1, chroma, tc_offset) : 0;
393
 
                    src = &s->frame->data[chroma][(y / 2) * s->frame->linesize[chroma] + ((x / 2) << s->sps->pixel_shift)];
 
416
                    src     = &s->frame->data[chroma][y / 2 * s->frame->linesize[chroma] + ((x / 2) << s->sps->pixel_shift)];
394
417
                    if (pcmf) {
395
418
                        no_p[0] = get_pcm(s, x - 1, y);
396
419
                        no_p[1] = get_pcm(s, x - 1, y + 8);
397
420
                        no_q[0] = get_pcm(s, x, y);
398
421
                        no_q[1] = get_pcm(s, x, y + 8);
399
 
                        s->hevcdsp.hevc_v_loop_filter_chroma_c(src, s->frame->linesize[chroma], c_tc, no_p, no_q);
 
422
                        s->hevcdsp.hevc_v_loop_filter_chroma_c(src,
 
423
                                                               s->frame->linesize[chroma],
 
424
                                                               c_tc, no_p, no_q);
400
425
                    } else
401
 
                        s->hevcdsp.hevc_v_loop_filter_chroma(src, s->frame->linesize[chroma], c_tc, no_p, no_q);
 
426
                        s->hevcdsp.hevc_v_loop_filter_chroma(src,
 
427
                                                             s->frame->linesize[chroma],
 
428
                                                             c_tc, no_p, no_q);
402
429
                }
403
430
            }
404
431
        }
415
442
                const int qp0 = (get_qPy(s, x, y - 1)     + get_qPy(s, x, y)     + 1) >> 1;
416
443
                const int qp1 = (get_qPy(s, x + 4, y - 1) + get_qPy(s, x + 4, y) + 1) >> 1;
417
444
 
418
 
                tc_offset = x >= x0 ? cur_tc_offset : left_tc_offset;
 
445
                tc_offset   = x >= x0 ? cur_tc_offset : left_tc_offset;
419
446
                beta_offset = x >= x0 ? cur_beta_offset : left_beta_offset;
420
447
 
421
 
                beta[0]  = betatable[av_clip(qp0 + ((beta_offset >> 1) << 1), 0, MAX_QP)];
422
 
                beta[1]  = betatable[av_clip(qp1 + ((beta_offset >> 1) << 1), 0, MAX_QP)];
423
 
                tc[0] = bs0 ? TC_CALC(qp0, bs0) : 0;
424
 
                tc[1] = bs1 ? TC_CALC(qp1, bs1) : 0;
425
 
                src = &s->frame->data[LUMA][y * s->frame->linesize[LUMA] + (x << s->sps->pixel_shift)];
 
448
                beta[0] = betatable[av_clip(qp0 + (beta_offset >> 1 << 1), 0, MAX_QP)];
 
449
                beta[1] = betatable[av_clip(qp1 + (beta_offset >> 1 << 1), 0, MAX_QP)];
 
450
                tc[0]   = bs0 ? TC_CALC(qp0, bs0) : 0;
 
451
                tc[1]   = bs1 ? TC_CALC(qp1, bs1) : 0;
 
452
                src     = &s->frame->data[LUMA][y * s->frame->linesize[LUMA] + (x << s->sps->pixel_shift)];
426
453
                if (pcmf) {
427
454
                    no_p[0] = get_pcm(s, x, y - 1);
428
455
                    no_p[1] = get_pcm(s, x + 4, y - 1);
429
456
                    no_q[0] = get_pcm(s, x, y);
430
457
                    no_q[1] = get_pcm(s, x + 4, y);
431
 
                    s->hevcdsp.hevc_h_loop_filter_luma_c(src, s->frame->linesize[LUMA], beta, tc, no_p, no_q);
 
458
                    s->hevcdsp.hevc_h_loop_filter_luma_c(src,
 
459
                                                         s->frame->linesize[LUMA],
 
460
                                                         beta, tc, no_p, no_q);
432
461
                } else
433
 
                    s->hevcdsp.hevc_h_loop_filter_luma(src, s->frame->linesize[LUMA], beta, tc, no_p, no_q);
 
462
                    s->hevcdsp.hevc_h_loop_filter_luma(src,
 
463
                                                       s->frame->linesize[LUMA],
 
464
                                                       beta, tc, no_p, no_q);
434
465
            }
435
466
        }
436
467
    }
446
477
                    bs0 = 0;
447
478
                    bs1 = s->horizontal_bs[(x + 8 + y * s->bs_width) >> 2];
448
479
                } else if (x >= x_end - 8) {
449
 
                    bs0 = s->horizontal_bs[(x + y * s->bs_width) >> 2];
 
480
                    bs0 = s->horizontal_bs[(x +     y * s->bs_width) >> 2];
450
481
                    bs1 = 0;
451
482
                } else {
452
 
                    bs0 = s->horizontal_bs[(x + y * s->bs_width) >> 2];
 
483
                    bs0 = s->horizontal_bs[(x + y     * s->bs_width) >> 2];
453
484
                    bs1 = s->horizontal_bs[(x + 8 + y * s->bs_width) >> 2];
454
485
                }
455
486
 
456
487
                if ((bs0 == 2) || (bs1 == 2)) {
457
 
                    const int qp0 = (bs0 == 2) ? ((get_qPy(s, x, y - 1)     + get_qPy(s, x, y)     + 1) >> 1) : 0;
458
 
                    const int qp1 = (bs1 == 2) ? ((get_qPy(s, x + 8, y - 1) + get_qPy(s, x + 8, y) + 1) >> 1) : 0;
 
488
                    const int qp0 = bs0 == 2 ? (get_qPy(s, x,     y - 1) + get_qPy(s, x,     y) + 1) >> 1 : 0;
 
489
                    const int qp1 = bs1 == 2 ? (get_qPy(s, x + 8, y - 1) + get_qPy(s, x + 8, y) + 1) >> 1 : 0;
459
490
 
460
491
                    tc_offset = x >= x0 ? cur_tc_offset : left_tc_offset;
461
 
                    c_tc[0] = (bs0 == 2) ? chroma_tc(s, qp0, chroma, tc_offset) : 0;
462
 
                    c_tc[1] = (bs1 == 2) ? chroma_tc(s, qp1, chroma, cur_tc_offset) : 0;
463
 
                    src = &s->frame->data[chroma][(y / 2) * s->frame->linesize[chroma] + ((x / 2) << s->sps->pixel_shift)];
 
492
                    c_tc[0]   = bs0 == 2 ? chroma_tc(s, qp0, chroma, tc_offset)     : 0;
 
493
                    c_tc[1]   = bs1 == 2 ? chroma_tc(s, qp1, chroma, cur_tc_offset) : 0;
 
494
                    src       = &s->frame->data[chroma][y / 2 * s->frame->linesize[chroma] + ((x / 2) << s->sps->pixel_shift)];
464
495
                    if (pcmf) {
465
496
                        no_p[0] = get_pcm(s, x, y - 1);
466
497
                        no_p[1] = get_pcm(s, x + 8, y - 1);
467
498
                        no_q[0] = get_pcm(s, x, y);
468
499
                        no_q[1] = get_pcm(s, x + 8, y);
469
 
                        s->hevcdsp.hevc_h_loop_filter_chroma_c(src, s->frame->linesize[chroma], c_tc, no_p, no_q);
 
500
                        s->hevcdsp.hevc_h_loop_filter_chroma_c(src,
 
501
                                                               s->frame->linesize[chroma],
 
502
                                                               c_tc, no_p, no_q);
470
503
                    } else
471
 
                        s->hevcdsp.hevc_h_loop_filter_chroma(src, s->frame->linesize[chroma], c_tc, no_p, no_q);
 
504
                        s->hevcdsp.hevc_h_loop_filter_chroma(src,
 
505
                                                             s->frame->linesize[chroma],
 
506
                                                             c_tc, no_p, no_q);
472
507
                }
473
508
            }
474
509
        }
477
512
 
478
513
static int boundary_strength(HEVCContext *s, MvField *curr,
479
514
                             uint8_t curr_cbf_luma, MvField *neigh,
480
 
                             uint8_t neigh_cbf_luma, RefPicList *neigh_refPicList,
 
515
                             uint8_t neigh_cbf_luma,
 
516
                             RefPicList *neigh_refPicList,
481
517
                             int tu_border)
482
518
{
483
519
    int mvs = curr->pred_flag[0] + curr->pred_flag[1];
492
528
    if (mvs == neigh->pred_flag[0] + neigh->pred_flag[1]) {
493
529
        if (mvs == 2) {
494
530
            // same L0 and L1
495
 
            if (s->ref->refPicList[0].list[curr->ref_idx[0]] == neigh_refPicList[0].list[neigh->ref_idx[0]]   &&
 
531
            if (s->ref->refPicList[0].list[curr->ref_idx[0]] == neigh_refPicList[0].list[neigh->ref_idx[0]]  &&
496
532
                s->ref->refPicList[0].list[curr->ref_idx[0]] == s->ref->refPicList[1].list[curr->ref_idx[1]] &&
497
533
                neigh_refPicList[0].list[neigh->ref_idx[0]] == neigh_refPicList[1].list[neigh->ref_idx[1]]) {
498
534
                if ((abs(neigh->mv[0].x - curr->mv[0].x) >= 4 || abs(neigh->mv[0].y - curr->mv[0].y) >= 4 ||
521
557
            }
522
558
        } else { // 1 MV
523
559
            Mv A, B;
524
 
            int ref_A;
525
 
            int ref_B;
 
560
            int ref_A, ref_B;
526
561
 
527
562
            if (curr->pred_flag[0]) {
528
 
                A = curr->mv[0];
 
563
                A     = curr->mv[0];
529
564
                ref_A = s->ref->refPicList[0].list[curr->ref_idx[0]];
530
565
            } else {
531
 
                A = curr->mv[1];
 
566
                A     = curr->mv[1];
532
567
                ref_A = s->ref->refPicList[1].list[curr->ref_idx[1]];
533
568
            }
534
569
 
535
570
            if (neigh->pred_flag[0]) {
536
 
                B = neigh->mv[0];
 
571
                B     = neigh->mv[0];
537
572
                ref_B = neigh_refPicList[0].list[neigh->ref_idx[0]];
538
573
            } else {
539
 
                B = neigh->mv[1];
 
574
                B     = neigh->mv[1];
540
575
                ref_B = neigh_refPicList[1].list[neigh->ref_idx[1]];
541
576
            }
542
577
 
553
588
    return 1;
554
589
}
555
590
 
556
 
void ff_hevc_deblocking_boundary_strengths(HEVCContext *s, int x0, int y0, int log2_trafo_size,
557
 
                                           int slice_or_tiles_up_boundary, int slice_or_tiles_left_boundary)
 
591
void ff_hevc_deblocking_boundary_strengths(HEVCContext *s, int x0, int y0,
 
592
                                           int log2_trafo_size,
 
593
                                           int slice_or_tiles_up_boundary,
 
594
                                           int slice_or_tiles_left_boundary)
558
595
{
559
 
    MvField *tab_mvf      = s->ref->tab_mvf;
560
 
    int log2_min_pu_size  = s->sps->log2_min_pu_size;
561
 
    int log2_min_tu_size  = s->sps->log2_min_transform_block_size;
562
 
    int pic_width_in_min_pu = s->sps->width >> log2_min_pu_size;
563
 
    int pic_width_in_min_tu = s->sps->width >> log2_min_tu_size;
564
 
    int is_intra = tab_mvf[(y0 >> log2_min_pu_size) * pic_width_in_min_pu + (x0 >> log2_min_pu_size)].is_intra;
565
 
 
566
 
    int i, j;
567
 
    int bs;
 
596
    MvField *tab_mvf     = s->ref->tab_mvf;
 
597
    int log2_min_pu_size = s->sps->log2_min_pu_size;
 
598
    int log2_min_tu_size = s->sps->log2_min_tb_size;
 
599
    int min_pu_width     = s->sps->min_pu_width;
 
600
    int min_tu_width     = s->sps->min_tb_width;
 
601
    int is_intra = tab_mvf[(y0 >> log2_min_pu_size) * min_pu_width +
 
602
                           (x0 >> log2_min_pu_size)].is_intra;
 
603
    int i, j, bs;
568
604
 
569
605
    if (y0 > 0 && (y0 & 7) == 0) {
570
606
        int yp_pu = (y0 - 1) >> log2_min_pu_size;
571
 
        int yq_pu = y0 >> log2_min_pu_size;
 
607
        int yq_pu =  y0      >> log2_min_pu_size;
572
608
        int yp_tu = (y0 - 1) >> log2_min_tu_size;
573
 
        int yq_tu = y0 >> log2_min_tu_size;
 
609
        int yq_tu =  y0      >> log2_min_tu_size;
574
610
 
575
611
        for (i = 0; i < (1 << log2_trafo_size); i += 4) {
576
612
            int x_pu = (x0 + i) >> log2_min_pu_size;
577
613
            int x_tu = (x0 + i) >> log2_min_tu_size;
578
 
            MvField *top  = &tab_mvf[yp_pu * pic_width_in_min_pu + x_pu];
579
 
            MvField *curr = &tab_mvf[yq_pu * pic_width_in_min_pu + x_pu];
580
 
            uint8_t top_cbf_luma  = s->cbf_luma[yp_tu * pic_width_in_min_tu + x_tu];
581
 
            uint8_t curr_cbf_luma = s->cbf_luma[yq_tu * pic_width_in_min_tu + x_tu];
582
 
            RefPicList* top_refPicList = ff_hevc_get_ref_list(s, s->ref, x0 + i, y0 - 1);
 
614
            MvField *top  = &tab_mvf[yp_pu * min_pu_width + x_pu];
 
615
            MvField *curr = &tab_mvf[yq_pu * min_pu_width + x_pu];
 
616
            uint8_t top_cbf_luma  = s->cbf_luma[yp_tu * min_tu_width + x_tu];
 
617
            uint8_t curr_cbf_luma = s->cbf_luma[yq_tu * min_tu_width + x_tu];
 
618
            RefPicList *top_refPicList = ff_hevc_get_ref_list(s, s->ref,
 
619
                                                              x0 + i, y0 - 1);
583
620
 
584
 
            bs = boundary_strength(s, curr, curr_cbf_luma, top, top_cbf_luma, top_refPicList, 1);
585
 
            if (!s->sh.slice_loop_filter_across_slices_enabled_flag && (slice_or_tiles_up_boundary & 1) && (y0 % (1 << s->sps->log2_ctb_size)) == 0)
 
621
            bs = boundary_strength(s, curr, curr_cbf_luma,
 
622
                                   top, top_cbf_luma, top_refPicList, 1);
 
623
            if (!s->sh.slice_loop_filter_across_slices_enabled_flag &&
 
624
                (slice_or_tiles_up_boundary & 1) &&
 
625
                (y0 % (1 << s->sps->log2_ctb_size)) == 0)
586
626
                bs = 0;
587
 
            else if (!s->pps->loop_filter_across_tiles_enabled_flag && (slice_or_tiles_up_boundary & 2)  && (y0 % (1 << s->sps->log2_ctb_size)) == 0)
 
627
            else if (!s->pps->loop_filter_across_tiles_enabled_flag &&
 
628
                     (slice_or_tiles_up_boundary & 2) &&
 
629
                     (y0 % (1 << s->sps->log2_ctb_size)) == 0)
588
630
                bs = 0;
589
631
            if (y0 == 0 || s->sh.disable_deblocking_filter_flag == 1)
590
632
                bs = 0;
601
643
            int yp_tu = (y0 + j - 1) >> log2_min_tu_size;
602
644
            int yq_tu = (y0 + j)     >> log2_min_tu_size;
603
645
 
604
 
 
605
 
            for (i = 0; i < (1<<log2_trafo_size); i += 4) {
 
646
            for (i = 0; i < (1 << log2_trafo_size); i += 4) {
606
647
                int x_pu = (x0 + i) >> log2_min_pu_size;
607
648
                int x_tu = (x0 + i) >> log2_min_tu_size;
608
 
                MvField *top  = &tab_mvf[yp_pu * pic_width_in_min_pu + x_pu];
609
 
                MvField *curr = &tab_mvf[yq_pu * pic_width_in_min_pu + x_pu];
610
 
                uint8_t top_cbf_luma  = s->cbf_luma[yp_tu * pic_width_in_min_tu + x_tu];
611
 
                uint8_t curr_cbf_luma = s->cbf_luma[yq_tu * pic_width_in_min_tu + x_tu];
612
 
                RefPicList* top_refPicList = ff_hevc_get_ref_list(s, s->ref, x0 + i, y0 + j - 1);
 
649
                MvField *top  = &tab_mvf[yp_pu * min_pu_width + x_pu];
 
650
                MvField *curr = &tab_mvf[yq_pu * min_pu_width + x_pu];
 
651
                uint8_t top_cbf_luma  = s->cbf_luma[yp_tu * min_tu_width + x_tu];
 
652
                uint8_t curr_cbf_luma = s->cbf_luma[yq_tu * min_tu_width + x_tu];
 
653
                RefPicList *top_refPicList = ff_hevc_get_ref_list(s, s->ref,
 
654
                                                                  x0 + i,
 
655
                                                                  y0 + j - 1);
613
656
 
614
 
                bs = boundary_strength(s, curr, curr_cbf_luma, top, top_cbf_luma, top_refPicList, 0);
 
657
                bs = boundary_strength(s, curr, curr_cbf_luma,
 
658
                                       top, top_cbf_luma, top_refPicList, 0);
615
659
                if (s->sh.disable_deblocking_filter_flag == 1)
616
660
                    bs = 0;
617
661
                if (bs)
627
671
        int xq_tu =  x0      >> log2_min_tu_size;
628
672
 
629
673
        for (i = 0; i < (1 << log2_trafo_size); i += 4) {
630
 
            int y_pu = (y0 + i) >> log2_min_pu_size;
631
 
            int y_tu = (y0 + i) >> log2_min_tu_size;
632
 
            MvField *left = &tab_mvf[y_pu * pic_width_in_min_pu + xp_pu];
633
 
            MvField *curr = &tab_mvf[y_pu * pic_width_in_min_pu + xq_pu];
634
 
 
635
 
            uint8_t left_cbf_luma = s->cbf_luma[y_tu * pic_width_in_min_tu + xp_tu];
636
 
            uint8_t curr_cbf_luma = s->cbf_luma[y_tu * pic_width_in_min_tu + xq_tu];
637
 
            RefPicList* left_refPicList = ff_hevc_get_ref_list(s, s->ref, x0 - 1, y0 + i);
638
 
 
639
 
            bs = boundary_strength(s, curr, curr_cbf_luma, left, left_cbf_luma, left_refPicList, 1);
640
 
            if (!s->sh.slice_loop_filter_across_slices_enabled_flag && (slice_or_tiles_left_boundary & 1) && (x0 % (1 << s->sps->log2_ctb_size)) == 0)
 
674
            int y_pu      = (y0 + i) >> log2_min_pu_size;
 
675
            int y_tu      = (y0 + i) >> log2_min_tu_size;
 
676
            MvField *left = &tab_mvf[y_pu * min_pu_width + xp_pu];
 
677
            MvField *curr = &tab_mvf[y_pu * min_pu_width + xq_pu];
 
678
 
 
679
            uint8_t left_cbf_luma = s->cbf_luma[y_tu * min_tu_width + xp_tu];
 
680
            uint8_t curr_cbf_luma = s->cbf_luma[y_tu * min_tu_width + xq_tu];
 
681
            RefPicList *left_refPicList = ff_hevc_get_ref_list(s, s->ref,
 
682
                                                               x0 - 1, y0 + i);
 
683
 
 
684
            bs = boundary_strength(s, curr, curr_cbf_luma,
 
685
                                   left, left_cbf_luma, left_refPicList, 1);
 
686
            if (!s->sh.slice_loop_filter_across_slices_enabled_flag &&
 
687
                (slice_or_tiles_left_boundary & 1) &&
 
688
                (x0 % (1 << s->sps->log2_ctb_size)) == 0)
641
689
                bs = 0;
642
 
            else if (!s->pps->loop_filter_across_tiles_enabled_flag && (slice_or_tiles_left_boundary & 2) && (x0 % (1 << s->sps->log2_ctb_size)) == 0)
 
690
            else if (!s->pps->loop_filter_across_tiles_enabled_flag &&
 
691
                     (slice_or_tiles_left_boundary & 2) &&
 
692
                     (x0 % (1 << s->sps->log2_ctb_size)) == 0)
643
693
                bs = 0;
644
694
            if (x0 == 0 || s->sh.disable_deblocking_filter_flag == 1)
645
695
                bs = 0;
649
699
    }
650
700
 
651
701
    // bs for TU internal vertical PU boundaries
652
 
    if (log2_trafo_size > s->sps->log2_min_pu_size && !is_intra)
 
702
    if (log2_trafo_size > log2_min_pu_size && !is_intra)
653
703
        for (j = 0; j < (1 << log2_trafo_size); j += 4) {
654
704
            int y_pu = (y0 + j) >> log2_min_pu_size;
655
705
            int y_tu = (y0 + j) >> log2_min_tu_size;
656
706
 
657
707
            for (i = 8; i < (1 << log2_trafo_size); i += 8) {
658
708
                int xp_pu = (x0 + i - 1) >> log2_min_pu_size;
659
 
                int xq_pu = (x0 + i) >> log2_min_pu_size;
 
709
                int xq_pu = (x0 + i)     >> log2_min_pu_size;
660
710
                int xp_tu = (x0 + i - 1) >> log2_min_tu_size;
661
 
                int xq_tu = (x0 + i) >> log2_min_tu_size;
662
 
                MvField *left = &tab_mvf[y_pu * pic_width_in_min_pu + xp_pu];
663
 
                MvField *curr = &tab_mvf[y_pu * pic_width_in_min_pu + xq_pu];
664
 
                uint8_t left_cbf_luma = s->cbf_luma[y_tu * pic_width_in_min_tu + xp_tu];
665
 
                uint8_t curr_cbf_luma = s->cbf_luma[y_tu * pic_width_in_min_tu + xq_tu];
666
 
                RefPicList* left_refPicList = ff_hevc_get_ref_list(s, s->ref, x0 + i - 1, y0 + j);
667
 
 
668
 
 
669
 
                bs = boundary_strength(s, curr, curr_cbf_luma, left, left_cbf_luma, left_refPicList, 0);
 
711
                int xq_tu = (x0 + i)     >> log2_min_tu_size;
 
712
                MvField *left = &tab_mvf[y_pu * min_pu_width + xp_pu];
 
713
                MvField *curr = &tab_mvf[y_pu * min_pu_width + xq_pu];
 
714
                uint8_t left_cbf_luma = s->cbf_luma[y_tu * min_tu_width + xp_tu];
 
715
                uint8_t curr_cbf_luma = s->cbf_luma[y_tu * min_tu_width + xq_tu];
 
716
                RefPicList *left_refPicList = ff_hevc_get_ref_list(s, s->ref,
 
717
                                                                   x0 + i - 1,
 
718
                                                                   y0 + j);
 
719
 
 
720
                bs = boundary_strength(s, curr, curr_cbf_luma,
 
721
                                       left, left_cbf_luma, left_refPicList, 0);
670
722
                if (s->sh.disable_deblocking_filter_flag == 1)
671
723
                    bs = 0;
672
724
                if (bs)
674
726
            }
675
727
        }
676
728
}
 
729
 
677
730
#undef LUMA
678
731
#undef CB
679
732
#undef CR
680
733
 
681
734
void ff_hevc_hls_filter(HEVCContext *s, int x, int y)
682
735
{
683
 
    int c_idx_min = s->sh.slice_sample_adaptive_offset_flag[0] != 0 ? 0 : 1;
684
 
    int c_idx_max = s->sh.slice_sample_adaptive_offset_flag[1] != 0 ? 3 : 1;
685
736
    deblocking_filter_CTB(s, x, y);
686
737
    if (s->sps->sao_enabled)
687
 
        sao_filter_CTB(s, x, y, c_idx_min, c_idx_max);
 
738
        sao_filter_CTB(s, x, y);
688
739
}
689
740
 
690
741
void ff_hevc_hls_filters(HEVCContext *s, int x_ctb, int y_ctb, int ctb_size)
691
742
{
692
743
    if (y_ctb && x_ctb)
693
744
        ff_hevc_hls_filter(s, x_ctb - ctb_size, y_ctb - ctb_size);
694
 
    if (y_ctb && x_ctb >= s->sps->width - ctb_size)
 
745
    if (y_ctb && x_ctb >= s->sps->width - ctb_size) {
695
746
        ff_hevc_hls_filter(s, x_ctb, y_ctb - ctb_size);
 
747
        if (s->threads_type == FF_THREAD_FRAME )
 
748
            ff_thread_report_progress(&s->ref->tf, y_ctb - ctb_size, 0);
 
749
    }
696
750
    if (x_ctb && y_ctb >= s->sps->height - ctb_size)
697
751
        ff_hevc_hls_filter(s, x_ctb - ctb_size, y_ctb);
698
752
}