Coverage Report

Created: 2025-11-11 07:01

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libhevc/decoder/ihevcd_deblk.c
Line
Count
Source
1
/******************************************************************************
2
*
3
* Copyright (C) 2012 Ittiam Systems Pvt Ltd, Bangalore
4
*
5
* Licensed under the Apache License, Version 2.0 (the "License");
6
* you may not use this file except in compliance with the License.
7
* You may obtain a copy of the License at:
8
*
9
* http://www.apache.org/licenses/LICENSE-2.0
10
*
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
16
*
17
******************************************************************************/
18
/**
19
*******************************************************************************
20
* @file
21
*  ihevc_deblk.c
22
*
23
* @brief
24
*  Contains definition for the ctb level deblk function
25
*
26
* @author
27
*  Srinivas T
28
*
29
* @par List of Functions:
30
*   - ihevc_deblk()
31
*
32
* @remarks
33
*  None
34
*
35
*******************************************************************************
36
*/
37
38
#include <stdio.h>
39
#include <stddef.h>
40
#include <stdlib.h>
41
#include <string.h>
42
#include <assert.h>
43
44
#include "ihevc_typedefs.h"
45
#include "iv.h"
46
#include "ivd.h"
47
#include "ihevcd_cxa.h"
48
#include "ithread.h"
49
50
#include "ihevc_defs.h"
51
#include "ihevc_debug.h"
52
#include "ihevc_defs.h"
53
#include "ihevc_structs.h"
54
#include "ihevc_macros.h"
55
#include "ihevc_platform_macros.h"
56
#include "ihevc_cabac_tables.h"
57
58
#include "ihevc_error.h"
59
#include "ihevc_common_tables.h"
60
61
#include "ihevcd_trace.h"
62
#include "ihevcd_defs.h"
63
#include "ihevcd_function_selector.h"
64
#include "ihevcd_structs.h"
65
#include "ihevcd_error.h"
66
#include "ihevcd_nal.h"
67
#include "ihevcd_bitstream.h"
68
#include "ihevcd_job_queue.h"
69
#include "ihevcd_utils.h"
70
#include "ihevcd_debug.h"
71
72
#include "ihevc_deblk.h"
73
#include "ihevc_deblk_tables.h"
74
#include "ihevcd_profile.h"
75
/**
76
*******************************************************************************
77
*
78
* @brief
79
*     Deblock CTB level function.
80
*
81
* @par Description:
82
*     For a given CTB, deblocking on both vertical and
83
*     horizontal edges is done. Both the luma and chroma
84
*     blocks are processed
85
*
86
* @param[in] ps_deblk
87
*  Pointer to the deblock context
88
*
89
* @returns
90
*
91
* @remarks
92
*  None
93
*
94
*******************************************************************************
95
*/
96
97
void ihevcd_deblk_ctb(deblk_ctxt_t *ps_deblk,
98
                      WORD32 i4_is_last_ctb_x,
99
                      WORD32 i4_is_last_ctb_y)
100
7.32M
{
101
7.32M
    WORD32 ctb_size;
102
7.32M
    WORD32 log2_ctb_size;
103
7.32M
    UWORD32 u4_bs;
104
7.32M
    WORD32 bs_tz; /*Leading zeros in boundary strength*/
105
7.32M
    WORD32 qp_p, qp_q;
106
107
7.32M
    WORD32 filter_p, filter_q;
108
109
7.32M
    UWORD8 *pu1_src;
110
7.32M
    WORD32 qp_strd;
111
7.32M
    UWORD32 *pu4_vert_bs, *pu4_horz_bs;
112
7.32M
    UWORD32 *pu4_ctb_vert_bs, *pu4_ctb_horz_bs;
113
7.32M
    WORD32 bs_strd;
114
7.32M
    WORD32 src_strd;
115
7.32M
    UWORD8 *pu1_qp;
116
7.32M
    UWORD16 *pu2_ctb_no_loop_filter_flag;
117
7.32M
    UWORD16 au2_ctb_no_loop_filter_flag[9];
118
119
7.32M
    WORD32 col, row;
120
121
    /* Flag to indicate if QP is constant in CTB
122
     * 0 - top_left, 1 - top, 2 - left, 3 - current */
123
7.32M
    UWORD32 u4_qp_const_in_ctb[4] = { 0, 0, 0, 0 };
124
7.32M
    WORD32 ctb_indx;
125
7.32M
    WORD32  chroma_yuv420sp_vu = ps_deblk->is_chroma_yuv420sp_vu;
126
7.32M
    sps_t *ps_sps;
127
7.32M
    pps_t *ps_pps;
128
7.32M
    codec_t *ps_codec;
129
7.32M
    slice_header_t *ps_slice_hdr;
130
131
7.32M
    PROFILE_DISABLE_DEBLK();
132
133
7.32M
    ps_sps = ps_deblk->ps_sps;
134
7.32M
    ps_pps = ps_deblk->ps_pps;
135
7.32M
    ps_codec = ps_deblk->ps_codec;
136
7.32M
    ps_slice_hdr = ps_deblk->ps_slice_hdr;
137
138
7.32M
    log2_ctb_size = ps_sps->i1_log2_ctb_size;
139
7.32M
    ctb_size = (1 << ps_sps->i1_log2_ctb_size);
140
141
    /* strides are in units of number of bytes */
142
    /* ctb_size * ctb_size / 8 / 16 is the number of bytes needed per CTB */
143
7.32M
    bs_strd = (ps_sps->i2_pic_wd_in_ctb + 1) << (2 * log2_ctb_size - 7);
144
145
7.32M
    pu4_vert_bs = (UWORD32 *)((UWORD8 *)ps_deblk->s_bs_ctxt.pu4_pic_vert_bs +
146
7.32M
                    (ps_deblk->i4_ctb_x << (2 * log2_ctb_size - 7)) +
147
7.32M
                    ps_deblk->i4_ctb_y * bs_strd);
148
7.32M
    pu4_ctb_vert_bs = pu4_vert_bs;
149
150
7.32M
    pu4_horz_bs = (UWORD32 *)((UWORD8 *)ps_deblk->s_bs_ctxt.pu4_pic_horz_bs +
151
7.32M
                    (ps_deblk->i4_ctb_x << (2 * log2_ctb_size - 7)) +
152
7.32M
                    ps_deblk->i4_ctb_y * bs_strd);
153
7.32M
    pu4_ctb_horz_bs = pu4_horz_bs;
154
155
7.32M
    qp_strd = ps_sps->i2_pic_wd_in_ctb << (log2_ctb_size - 3);
156
7.32M
    pu1_qp = ps_deblk->s_bs_ctxt.pu1_pic_qp + ((ps_deblk->i4_ctb_x + ps_deblk->i4_ctb_y * qp_strd) << (log2_ctb_size - 3));
157
158
7.32M
    pu2_ctb_no_loop_filter_flag = ps_deblk->au2_ctb_no_loop_filter_flag;
159
160
7.32M
    ctb_indx = ps_deblk->i4_ctb_x + ps_sps->i2_pic_wd_in_ctb * ps_deblk->i4_ctb_y;
161
7.32M
    if(i4_is_last_ctb_y)
162
8.83k
    {
163
8.83k
        pu4_vert_bs = (UWORD32 *)((UWORD8 *)pu4_vert_bs + bs_strd);
164
8.83k
        pu4_ctb_vert_bs = pu4_vert_bs;
165
        /* ctb_size/8 is the number of edges per CTB
166
         * ctb_size/4 is the number of BS values needed per edge
167
         * divided by 8 for the number of bytes
168
         * 2 is the number of bits needed for each BS value */
169
8.83k
        memset(pu4_vert_bs, 0, 1 << (2 * log2_ctb_size - 7));
170
171
8.83k
        pu1_qp += (qp_strd << (log2_ctb_size - 3));
172
8.83k
        pu2_ctb_no_loop_filter_flag += (ctb_size >> 3);
173
8.83k
        ctb_indx += ps_sps->i2_pic_wd_in_ctb;
174
8.83k
    }
175
176
7.32M
    if(i4_is_last_ctb_x)
177
31.5k
    {
178
31.5k
        pu4_horz_bs = (UWORD32 *)((UWORD8 *)pu4_horz_bs + (1 << (2 * log2_ctb_size - 7)));
179
31.5k
        pu4_ctb_horz_bs = pu4_horz_bs;
180
31.5k
        memset(pu4_horz_bs, 0, 1 << (2 * log2_ctb_size - 7));
181
182
31.5k
        pu1_qp += (ctb_size >> 3);
183
184
250k
        for(row = 0; row < (ctb_size >> 3) + 1; row++)
185
219k
            au2_ctb_no_loop_filter_flag[row] = ps_deblk->au2_ctb_no_loop_filter_flag[row] >> (ctb_size >> 3);
186
31.5k
        pu2_ctb_no_loop_filter_flag = au2_ctb_no_loop_filter_flag;
187
31.5k
        ctb_indx += 1;
188
31.5k
    }
189
190
7.32M
    u4_qp_const_in_ctb[3] = ps_deblk->s_bs_ctxt.pu1_pic_qp_const_in_ctb[(ctb_indx) >> 3] & (1 << (ctb_indx & 7));
191
192
7.32M
    if(ps_deblk->i4_ctb_x || i4_is_last_ctb_x)
193
7.15M
    {
194
7.15M
        u4_qp_const_in_ctb[2] = ps_deblk->s_bs_ctxt.pu1_pic_qp_const_in_ctb[(ctb_indx - 1) >> 3] & (1 << ((ctb_indx - 1) & 7));
195
7.15M
    }
196
197
7.32M
    if((ps_deblk->i4_ctb_x || i4_is_last_ctb_x) && (ps_deblk->i4_ctb_y || i4_is_last_ctb_y))
198
6.60M
    {
199
6.60M
        u4_qp_const_in_ctb[0] =
200
6.60M
                        ps_deblk->s_bs_ctxt.pu1_pic_qp_const_in_ctb[(ctb_indx - ps_sps->i2_pic_wd_in_ctb - 1) >> 3] &
201
6.60M
                        (1 << ((ctb_indx - ps_sps->i2_pic_wd_in_ctb - 1) & 7));
202
6.60M
    }
203
204
205
206
7.32M
    if(ps_deblk->i4_ctb_y || i4_is_last_ctb_y)
207
6.76M
    {
208
6.76M
        u4_qp_const_in_ctb[1] =
209
6.76M
                        ps_deblk->s_bs_ctxt.pu1_pic_qp_const_in_ctb[(ctb_indx - ps_sps->i2_pic_wd_in_ctb) >> 3] &
210
6.76M
                        (1 << ((ctb_indx - ps_sps->i2_pic_wd_in_ctb) & 7));
211
6.76M
    }
212
213
7.32M
    src_strd = ps_codec->i4_strd;
214
215
    /* Luma Vertical Edge */
216
217
7.32M
    if(0 == i4_is_last_ctb_x)
218
7.29M
    {
219
        /* Top CTB's slice header */
220
7.29M
        slice_header_t *ps_slice_hdr_top;
221
7.29M
        {
222
7.29M
            WORD32 cur_ctb_indx = ps_deblk->i4_ctb_x + ps_deblk->i4_ctb_y * ps_sps->i2_pic_wd_in_ctb;
223
7.29M
            if(i4_is_last_ctb_y)
224
8.83k
                cur_ctb_indx += ps_sps->i2_pic_wd_in_ctb;
225
7.29M
            ps_slice_hdr_top = ps_codec->ps_slice_hdr_base + ps_deblk->pu1_slice_idx[cur_ctb_indx - ps_sps->i2_pic_wd_in_ctb];
226
7.29M
        }
227
228
7.29M
        pu1_src = ps_deblk->pu1_cur_pic_luma + ((ps_deblk->i4_ctb_x + ps_deblk->i4_ctb_y * ps_deblk->ps_codec->i4_strd) << (log2_ctb_size));
229
7.29M
        pu1_src += i4_is_last_ctb_y ? ps_deblk->ps_codec->i4_strd << log2_ctb_size : 0;
230
231
        /** Deblocking is done on a shifted CTB -
232
         *  Vertical edge processing is done by shifting the CTB up by four pixels */
233
7.29M
        pu1_src -= 4 * src_strd;
234
235
50.9M
        for(col = 0; col < ctb_size / 8; col++)
236
43.6M
        {
237
43.6M
            WORD32 shift = 0;
238
239
            /*  downshift vert_bs by ctb_size/2 for each column
240
             *  shift = (col & ((MAX_CTB_SIZE >> log2_ctb_size) - 1)) << (log2_ctb_size - 1);
241
             *  which will reduce to the following assuming ctb size is one of 16, 32 and 64
242
             *  and deblocking is done on 8x8 grid
243
             */
244
43.6M
            if(6 != log2_ctb_size)
245
6.73M
                shift = (col & 1) << (log2_ctb_size - 1);
246
247
            /* BS for the column - Last row is excluded and the top row is included*/
248
43.6M
            u4_bs = (pu4_vert_bs[0] >> shift) << 2;
249
250
43.6M
            if(ps_deblk->i4_ctb_y || i4_is_last_ctb_y)
251
39.3M
            {
252
                /* Picking the last BS of the previous CTB corresponding to the same column */
253
39.3M
                UWORD32 *pu4_vert_bs_top = (UWORD32 *)((UWORD8 *)pu4_vert_bs - bs_strd);
254
39.3M
                UWORD32 u4_top_bs = (*pu4_vert_bs_top) >> (shift + (1 << (log2_ctb_size - 1)) - 2);
255
39.3M
                u4_bs |= u4_top_bs & 3;
256
39.3M
            }
257
258
334M
            for(row = 0; row < ctb_size / 4;)
259
291M
            {
260
291M
                WORD8 i1_beta_offset_div2 = ps_slice_hdr->i1_beta_offset_div2;
261
291M
                WORD8 i1_tc_offset_div2 = ps_slice_hdr->i1_tc_offset_div2;
262
263
                /* Trailing zeros are computed and the corresponding rows are not processed */
264
291M
                bs_tz = CTZ(u4_bs) >> 1;
265
291M
                if(0 != bs_tz)
266
51.9M
                {
267
51.9M
                    u4_bs = u4_bs >> (bs_tz << 1);
268
51.9M
                    if((row + bs_tz) >= (ctb_size / 4))
269
29.1M
                        pu1_src += 4 * (ctb_size / 4 - row) * src_strd;
270
22.7M
                    else
271
22.7M
                        pu1_src += 4 * bs_tz  * src_strd;
272
273
51.9M
                    row += bs_tz;
274
51.9M
                    continue;
275
51.9M
                }
276
277
239M
                if(0 == row)
278
14.4M
                {
279
14.4M
                    i1_beta_offset_div2 = ps_slice_hdr_top->i1_beta_offset_div2;
280
14.4M
                    i1_tc_offset_div2 = ps_slice_hdr_top->i1_tc_offset_div2;
281
282
14.4M
                    if(0 == col)
283
2.54M
                    {
284
2.54M
                        qp_p = u4_qp_const_in_ctb[0] ?
285
2.53M
                                        pu1_qp[-ctb_size / 8 * qp_strd - ctb_size / 8] :
286
2.54M
                                        pu1_qp[-qp_strd - 1];
287
2.54M
                    }
288
11.9M
                    else
289
11.9M
                    {
290
11.9M
                        qp_p = u4_qp_const_in_ctb[1] ?
291
11.9M
                                        pu1_qp[-ctb_size / 8 * qp_strd] :
292
11.9M
                                        pu1_qp[col - 1 - qp_strd];
293
11.9M
                    }
294
295
14.4M
                    qp_q = u4_qp_const_in_ctb[1] ?
296
14.4M
                                    pu1_qp[-ctb_size / 8 * qp_strd] :
297
14.4M
                                    pu1_qp[col - qp_strd];
298
14.4M
                }
299
224M
                else
300
224M
                {
301
224M
                    if(0 == col)
302
39.7M
                    {
303
39.7M
                        qp_p = u4_qp_const_in_ctb[2] ?
304
39.5M
                                        pu1_qp[-ctb_size / 8] :
305
39.7M
                                        pu1_qp[((row - 1) >> 1) * qp_strd - 1];
306
39.7M
                    }
307
184M
                    else
308
184M
                    {
309
184M
                        qp_p = u4_qp_const_in_ctb[3] ?
310
186M
                                        pu1_qp[0] :
311
18.4E
                                        pu1_qp[((row - 1) >> 1) * qp_strd + col - 1];
312
184M
                    }
313
314
224M
                    qp_q = u4_qp_const_in_ctb[3] ?
315
224M
                                    pu1_qp[0] :
316
224M
                                    pu1_qp[((row - 1) >> 1) * qp_strd + col];
317
224M
                }
318
319
239M
                filter_p = (pu2_ctb_no_loop_filter_flag[(row + 1) >> 1] >> col) & 1;
320
239M
                filter_q = (pu2_ctb_no_loop_filter_flag[(row + 1) >> 1] >> col) & 2;
321
                /* filter_p and filter_q are inverted as they are calculated using no_loop_filter_flags */
322
239M
                filter_p = !filter_p;
323
239M
                filter_q = !filter_q;
324
325
239M
                if(filter_p || filter_q)
326
238M
                {
327
238M
                    DUMP_DEBLK_LUMA_VERT(pu1_src, src_strd,
328
238M
                                         u4_bs & 3, qp_p, qp_q,
329
238M
                                         ps_slice_hdr->i1_beta_offset_div2,
330
238M
                                         ps_slice_hdr->i1_tc_offset_div2,
331
238M
                                         filter_p, filter_q);
332
238M
                    ps_codec->s_func_selector.ihevc_deblk_luma_vert_fptr(pu1_src, src_strd,
333
238M
                                                                         u4_bs & 3, qp_p, qp_q,
334
238M
                                                                         i1_beta_offset_div2,
335
238M
                                                                         i1_tc_offset_div2,
336
238M
                                                                         filter_p, filter_q);
337
238M
                }
338
339
239M
                pu1_src += 4 * src_strd;
340
239M
                u4_bs = u4_bs >> 2;
341
239M
                row++;
342
239M
            }
343
344
43.6M
            if((64 == ctb_size) ||
345
6.73M
                            ((32 == ctb_size) && (col & 1)))
346
38.2M
            {
347
38.2M
                pu4_vert_bs++;
348
38.2M
            }
349
43.6M
            pu1_src -= (src_strd << log2_ctb_size);
350
43.6M
            pu1_src += 8;
351
43.6M
        }
352
7.29M
        pu4_vert_bs = pu4_ctb_vert_bs;
353
7.29M
    }
354
355
356
    /* Luma Horizontal Edge */
357
358
7.32M
    if(0 == i4_is_last_ctb_y)
359
7.32M
    {
360
361
        /* Left CTB's slice header */
362
7.32M
        slice_header_t *ps_slice_hdr_left;
363
7.32M
        {
364
7.32M
            WORD32 cur_ctb_indx = ps_deblk->i4_ctb_x + ps_deblk->i4_ctb_y * ps_sps->i2_pic_wd_in_ctb;
365
7.32M
            if(i4_is_last_ctb_x)
366
31.5k
                cur_ctb_indx += 1;
367
7.32M
            ps_slice_hdr_left = ps_codec->ps_slice_hdr_base + ps_deblk->pu1_slice_idx[cur_ctb_indx - 1];
368
7.32M
        }
369
7.32M
        pu1_src = ps_deblk->pu1_cur_pic_luma + ((ps_deblk->i4_ctb_x + ps_deblk->i4_ctb_y * ps_deblk->ps_codec->i4_strd) << log2_ctb_size);
370
7.32M
        pu1_src += i4_is_last_ctb_x ? ctb_size : 0;
371
372
        /** Deblocking is done on a shifted CTB -
373
         *  Horizontal edge processing is done by shifting the CTB left by four pixels */
374
7.32M
        pu1_src -= 4;
375
51.1M
        for(row = 0; row < ctb_size / 8; row++)
376
43.7M
        {
377
43.7M
            WORD32 shift = 0;
378
379
            /* downshift vert_bs by ctb_size/2 for each column
380
             *  shift = (row & (MAX_CTB_SIZE / ctb_size - 1)) * ctb_size / 2;
381
             *  which will reduce to the following assuming ctb size is one of 16, 32 and 64
382
             *  and deblocking is done on 8x8 grid
383
             */
384
43.7M
            if(6 != log2_ctb_size)
385
6.77M
                shift = (row & 1) << (log2_ctb_size - 1);
386
387
            /* BS for the row - Last column is excluded and the left column is included*/
388
43.7M
            u4_bs = (pu4_horz_bs[0] >> shift) << 2;
389
390
43.7M
            if(ps_deblk->i4_ctb_x || i4_is_last_ctb_x)
391
42.6M
            {
392
                /** Picking the last BS of the previous CTB corresponding to the same row
393
                * UWORD32 *pu4_horz_bs_left = (UWORD32 *)((UWORD8 *)pu4_horz_bs - (ctb_size / 8) * (ctb_size / 4) / 8 * 2);
394
                */
395
42.6M
                UWORD32 *pu4_horz_bs_left = (UWORD32 *)((UWORD8 *)pu4_horz_bs - (1 << (2 * log2_ctb_size - 7)));
396
42.6M
                UWORD32 u4_left_bs = (*pu4_horz_bs_left) >> (shift + (1 << (log2_ctb_size - 1)) - 2);
397
42.6M
                u4_bs |= u4_left_bs & 3;
398
42.6M
            }
399
400
333M
            for(col = 0; col < ctb_size / 4;)
401
289M
            {
402
289M
                WORD8 i1_beta_offset_div2 = ps_slice_hdr->i1_beta_offset_div2;
403
289M
                WORD8 i1_tc_offset_div2 = ps_slice_hdr->i1_tc_offset_div2;
404
405
289M
                bs_tz = CTZ(u4_bs) >> 1;
406
289M
                if(0 != bs_tz)
407
50.8M
                {
408
50.8M
                    u4_bs = u4_bs >> (bs_tz << 1);
409
410
50.8M
                    if((col + bs_tz) >= (ctb_size / 4))
411
28.6M
                        pu1_src += 4 * (ctb_size / 4 - col);
412
22.2M
                    else
413
22.2M
                        pu1_src += 4 * bs_tz;
414
415
50.8M
                    col += bs_tz;
416
50.8M
                    continue;
417
50.8M
                }
418
419
238M
                if(0 == col)
420
15.1M
                {
421
15.1M
                    i1_beta_offset_div2 = ps_slice_hdr_left->i1_beta_offset_div2;
422
15.1M
                    i1_tc_offset_div2 = ps_slice_hdr_left->i1_tc_offset_div2;
423
424
15.1M
                    if(0 == row)
425
2.51M
                    {
426
2.51M
                        qp_p = u4_qp_const_in_ctb[0] ?
427
2.50M
                                        pu1_qp[-ctb_size / 8 * qp_strd - ctb_size / 8] :
428
2.51M
                                        pu1_qp[-qp_strd - 1];
429
2.51M
                    }
430
12.6M
                    else
431
12.6M
                    {
432
12.6M
                        qp_p = u4_qp_const_in_ctb[2] ?
433
12.5M
                                        pu1_qp[-ctb_size / 8] :
434
12.6M
                                        pu1_qp[(row - 1) * qp_strd - 1];
435
12.6M
                    }
436
437
15.1M
                    qp_q = u4_qp_const_in_ctb[2] ?
438
15.0M
                                    pu1_qp[-ctb_size / 8] :
439
15.1M
                                    pu1_qp[row * qp_strd - 1];
440
15.1M
                }
441
223M
                else
442
223M
                {
443
223M
                    if(0 == row)
444
37.5M
                    {
445
37.5M
                        qp_p = u4_qp_const_in_ctb[1] ?
446
37.3M
                                        pu1_qp[-ctb_size / 8 * qp_strd] :
447
37.5M
                                        pu1_qp[((col - 1) >> 1) - qp_strd];
448
37.5M
                    }
449
185M
                    else
450
185M
                    {
451
185M
                        qp_p = u4_qp_const_in_ctb[3] ?
452
186M
                                        pu1_qp[0] :
453
18.4E
                                        pu1_qp[((col - 1) >> 1) + (row - 1) * qp_strd];
454
185M
                    }
455
456
223M
                    qp_q = u4_qp_const_in_ctb[3] ?
457
222M
                                    pu1_qp[0] :
458
223M
                                    pu1_qp[((col - 1) >> 1) + row * qp_strd];
459
223M
                }
460
461
238M
                filter_p = (pu2_ctb_no_loop_filter_flag[row] >> ((col + 1) >> 1)) & 1;
462
238M
                filter_q = (pu2_ctb_no_loop_filter_flag[row + 1] >> ((col + 1) >> 1)) & 1;
463
                /* filter_p and filter_q are inverted as they are calculated using no_loop_filter_flags */
464
238M
                filter_p = !filter_p;
465
238M
                filter_q = !filter_q;
466
467
238M
                if(filter_p || filter_q)
468
237M
                {
469
237M
                    DUMP_DEBLK_LUMA_HORZ(pu1_src, src_strd,
470
237M
                                         u4_bs & 3, qp_p, qp_q,
471
237M
                                         ps_slice_hdr->i1_beta_offset_div2,
472
237M
                                         ps_slice_hdr->i1_tc_offset_div2,
473
237M
                                         filter_p, filter_q);
474
237M
                    ps_codec->s_func_selector.ihevc_deblk_luma_horz_fptr(pu1_src, src_strd,
475
237M
                                                                         u4_bs & 3, qp_p, qp_q,
476
237M
                                                                         i1_beta_offset_div2,
477
237M
                                                                         i1_tc_offset_div2, filter_p, filter_q);
478
237M
                }
479
480
238M
                pu1_src += 4;
481
238M
                u4_bs = u4_bs >> 2;
482
238M
                col++;
483
238M
            }
484
485
43.7M
            if((64 == ctb_size) ||
486
6.77M
                            ((32 == ctb_size) && (row & 1)))
487
38.4M
            {
488
38.4M
                pu4_horz_bs++;
489
38.4M
            }
490
43.7M
            pu1_src -= ctb_size;
491
43.7M
            pu1_src += (src_strd << 3);
492
43.7M
        }
493
7.32M
        pu4_horz_bs = pu4_ctb_horz_bs;
494
7.32M
    }
495
496
497
    /* Chroma Veritcal Edge */
498
499
7.32M
    if(0 == i4_is_last_ctb_x)
500
7.30M
    {
501
502
        /* Top CTB's slice header */
503
7.30M
        slice_header_t *ps_slice_hdr_top;
504
7.30M
        {
505
7.30M
            WORD32 cur_ctb_indx = ps_deblk->i4_ctb_x + ps_deblk->i4_ctb_y * ps_sps->i2_pic_wd_in_ctb;
506
7.30M
            if(i4_is_last_ctb_y)
507
8.83k
                cur_ctb_indx += ps_sps->i2_pic_wd_in_ctb;
508
7.30M
            ps_slice_hdr_top = ps_codec->ps_slice_hdr_base + ps_deblk->pu1_slice_idx[cur_ctb_indx - ps_sps->i2_pic_wd_in_ctb];
509
7.30M
        }
510
511
7.30M
        pu1_src = ps_deblk->pu1_cur_pic_chroma + ((ps_deblk->i4_ctb_x + ps_deblk->i4_ctb_y * ps_deblk->ps_codec->i4_strd / 2) << log2_ctb_size);
512
7.30M
        pu1_src += i4_is_last_ctb_y ? (ps_deblk->ps_codec->i4_strd / 2) << log2_ctb_size : 0;
513
514
        /** Deblocking is done on a shifted CTB -
515
         *  Vertical edge processing is done by shifting the CTB up by four pixels */
516
7.30M
        pu1_src -= 4 * src_strd;
517
518
29.1M
        for(col = 0; col < ctb_size / 16; col++)
519
21.8M
        {
520
521
            /* BS for the column - Last row is excluded and the top row is included*/
522
21.8M
            u4_bs = pu4_vert_bs[0] << 2;
523
524
21.8M
            if(ps_deblk->i4_ctb_y || i4_is_last_ctb_y)
525
19.7M
            {
526
                /* Picking the last BS of the previous CTB corresponding to the same column */
527
19.7M
                UWORD32 *pu4_vert_bs_top = (UWORD32 *)((UWORD8 *)pu4_vert_bs - bs_strd);
528
19.7M
                UWORD32 u4_top_bs = (*pu4_vert_bs_top) >> ((1 << (log2_ctb_size - 1)) - 2);
529
19.7M
                u4_bs |= u4_top_bs & 3;
530
19.7M
            }
531
532
            /* Every alternate boundary strength value is used for chroma */
533
21.8M
            u4_bs &= 0x22222222;
534
535
114M
            for(row = 0; row < ctb_size / 8;)
536
93.0M
            {
537
93.0M
                WORD8 i1_tc_offset_div2 = ps_slice_hdr->i1_tc_offset_div2;
538
539
93.0M
                bs_tz = CTZ(u4_bs) >> 2;
540
93.0M
                if(0 != bs_tz)
541
23.7M
                {
542
23.7M
                    if((row + bs_tz) >= (ctb_size / 8))
543
13.5M
                        pu1_src += 4 * (ctb_size / 8 - row) * src_strd;
544
10.2M
                    else
545
10.2M
                        pu1_src += 4 * bs_tz  * src_strd;
546
23.7M
                    row += bs_tz;
547
23.7M
                    u4_bs = u4_bs >> (bs_tz << 2);
548
23.7M
                    continue;
549
23.7M
                }
550
551
69.3M
                if(0 == row)
552
8.30M
                {
553
8.30M
                    i1_tc_offset_div2 = ps_slice_hdr_top->i1_tc_offset_div2;
554
555
8.30M
                    if(0 == col)
556
2.48M
                    {
557
2.48M
                        qp_p = u4_qp_const_in_ctb[0] ?
558
2.47M
                                        pu1_qp[-ctb_size / 8 * qp_strd - ctb_size / 8] :
559
2.48M
                                        pu1_qp[-qp_strd - 1];
560
2.48M
                    }
561
5.82M
                    else
562
5.82M
                    {
563
5.82M
                        qp_p = u4_qp_const_in_ctb[1] ?
564
5.80M
                                        pu1_qp[-ctb_size / 8 * qp_strd] :
565
5.82M
                                        pu1_qp[2 * col - 1 - qp_strd];
566
5.82M
                    }
567
568
8.30M
                    qp_q = u4_qp_const_in_ctb[1] ?
569
8.27M
                                    pu1_qp[-ctb_size / 8 * qp_strd] :
570
8.30M
                                    pu1_qp[2 * col - qp_strd];
571
8.30M
                }
572
60.9M
                else
573
60.9M
                {
574
60.9M
                    if(0 == col)
575
18.2M
                    {
576
18.2M
                        qp_p = u4_qp_const_in_ctb[2] ?
577
18.2M
                                        pu1_qp[-ctb_size / 8] :
578
18.2M
                                        pu1_qp[(row - 1) * qp_strd - 1];
579
18.2M
                    }
580
42.7M
                    else
581
42.7M
                    {
582
42.7M
                        qp_p = u4_qp_const_in_ctb[3] ?
583
42.9M
                                        pu1_qp[0] :
584
18.4E
                                        pu1_qp[(row - 1) * qp_strd + 2 * col - 1];
585
42.7M
                    }
586
587
60.9M
                    qp_q = u4_qp_const_in_ctb[3] ?
588
61.0M
                                    pu1_qp[0] :
589
18.4E
                                    pu1_qp[(row - 1) * qp_strd + 2 * col];
590
60.9M
                }
591
592
69.3M
                filter_p = (pu2_ctb_no_loop_filter_flag[row] >> (col << 1)) & 1;
593
69.3M
                filter_q = (pu2_ctb_no_loop_filter_flag[row] >> (col << 1)) & 2;
594
                /* filter_p and filter_q are inverted as they are calculated using no_loop_filter_flags */
595
69.3M
                filter_p = !filter_p;
596
69.3M
                filter_q = !filter_q;
597
598
69.3M
                if(filter_p || filter_q)
599
69.3M
                {
600
69.3M
                    ASSERT(1 == ((u4_bs & 3) >> 1));
601
69.3M
                    DUMP_DEBLK_CHROMA_VERT(pu1_src, src_strd,
602
69.3M
                                           u4_bs & 3, qp_p, qp_q,
603
69.3M
                                           ps_pps->i1_pic_cb_qp_offset,
604
69.3M
                                           ps_pps->i1_pic_cr_qp_offset,
605
69.3M
                                           ps_slice_hdr->i1_tc_offset_div2,
606
69.3M
                                           filter_p, filter_q);
607
69.3M
                    if(chroma_yuv420sp_vu)
608
33.2M
                    {
609
33.2M
                        ps_codec->s_func_selector.ihevc_deblk_chroma_vert_fptr(pu1_src,
610
33.2M
                                                                               src_strd,
611
33.2M
                                                                               qp_q,
612
33.2M
                                                                               qp_p,
613
33.2M
                                                                               ps_pps->i1_pic_cr_qp_offset,
614
33.2M
                                                                               ps_pps->i1_pic_cb_qp_offset,
615
33.2M
                                                                               i1_tc_offset_div2,
616
33.2M
                                                                               filter_q,
617
33.2M
                                                                               filter_p);
618
33.2M
                    }
619
36.0M
                    else
620
36.0M
                    {
621
36.0M
                        ps_codec->s_func_selector.ihevc_deblk_chroma_vert_fptr(pu1_src,
622
36.0M
                                                                               src_strd,
623
36.0M
                                                                               qp_p,
624
36.0M
                                                                               qp_q,
625
36.0M
                                                                               ps_pps->i1_pic_cb_qp_offset,
626
36.0M
                                                                               ps_pps->i1_pic_cr_qp_offset,
627
36.0M
                                                                               i1_tc_offset_div2,
628
36.0M
                                                                               filter_p,
629
36.0M
                                                                               filter_q);
630
36.0M
                    }
631
69.3M
                }
632
633
69.3M
                pu1_src += 4 * src_strd;
634
69.2M
                u4_bs = u4_bs >> 4;
635
69.2M
                row++;
636
69.2M
            }
637
638
21.8M
            pu4_vert_bs += (64 == ctb_size) ? 2 : 1;
639
21.8M
            pu1_src -= ((src_strd / 2) << log2_ctb_size);
640
21.8M
            pu1_src += 16;
641
21.8M
        }
642
7.30M
    }
643
644
    /* Chroma Horizontal Edge */
645
646
7.29M
    if(0 == i4_is_last_ctb_y)
647
7.32M
    {
648
649
        /* Left CTB's slice header */
650
7.32M
        slice_header_t *ps_slice_hdr_left;
651
7.32M
        {
652
7.32M
            WORD32 cur_ctb_indx = ps_deblk->i4_ctb_x + ps_deblk->i4_ctb_y * ps_sps->i2_pic_wd_in_ctb;
653
7.32M
            if(i4_is_last_ctb_x)
654
31.5k
                cur_ctb_indx += 1;
655
7.32M
            ps_slice_hdr_left = ps_codec->ps_slice_hdr_base + ps_deblk->pu1_slice_idx[cur_ctb_indx - 1];
656
7.32M
        }
657
658
7.32M
        pu1_src = ps_deblk->pu1_cur_pic_chroma + ((ps_deblk->i4_ctb_x + ps_deblk->i4_ctb_y * ps_deblk->ps_codec->i4_strd / 2) << log2_ctb_size);
659
7.32M
        pu1_src += i4_is_last_ctb_x ? ctb_size : 0;
660
661
        /** Deblocking is done on a shifted CTB -
662
         * Vertical edge processing is done by shifting the CTB up by four pixels (8 here beacuse UV are interleaved) */
663
7.32M
        pu1_src -= 8;
664
29.2M
        for(row = 0; row < ctb_size / 16; row++)
665
21.9M
        {
666
            /* BS for the row - Last column is excluded and the left column is included*/
667
21.9M
            u4_bs = pu4_horz_bs[0] << 2;
668
669
21.9M
            if(ps_deblk->i4_ctb_x || i4_is_last_ctb_x)
670
21.3M
            {
671
                /** Picking the last BS of the previous CTB corresponding to the same row
672
                * UWORD32 *pu4_horz_bs_left = (UWORD32 *)((UWORD8 *)pu4_horz_bs - (ctb_size / 8) * (ctb_size / 4) / 8 * 2);
673
                */
674
21.3M
                UWORD32 *pu4_horz_bs_left = (UWORD32 *)((UWORD8 *)pu4_horz_bs - (1 << (2 * log2_ctb_size - 7)));
675
21.3M
                UWORD32 u4_left_bs = (*pu4_horz_bs_left) >> ((1 << (log2_ctb_size - 1)) - 2);
676
21.3M
                u4_bs |= u4_left_bs & 3;
677
21.3M
            }
678
679
            /* Every alternate boundary strength value is used for chroma */
680
21.9M
            u4_bs &= 0x22222222;
681
682
113M
            for(col = 0; col < ctb_size / 8;)
683
91.1M
            {
684
91.1M
                WORD8 i1_tc_offset_div2 = ps_slice_hdr->i1_tc_offset_div2;
685
686
91.1M
                bs_tz = CTZ(u4_bs) >> 2;
687
91.1M
                if(0 != bs_tz)
688
23.6M
                {
689
23.6M
                    u4_bs = u4_bs >> (bs_tz << 2);
690
691
23.6M
                    if((col + bs_tz) >= (ctb_size / 8))
692
13.4M
                        pu1_src += 8 * (ctb_size / 8 - col);
693
10.1M
                    else
694
10.1M
                        pu1_src += 8 * bs_tz;
695
696
23.6M
                    col += bs_tz;
697
23.6M
                    continue;
698
23.6M
                }
699
700
67.5M
                if(0 == col)
701
8.45M
                {
702
8.45M
                    i1_tc_offset_div2 = ps_slice_hdr_left->i1_tc_offset_div2;
703
704
8.45M
                    if(0 == row)
705
2.41M
                    {
706
2.41M
                        qp_p = u4_qp_const_in_ctb[0] ?
707
2.40M
                                        pu1_qp[-ctb_size / 8 * qp_strd - ctb_size / 8] :
708
2.41M
                                        pu1_qp[-qp_strd - 1];
709
2.41M
                    }
710
6.03M
                    else
711
6.03M
                    {
712
6.03M
                        qp_p = u4_qp_const_in_ctb[2] ?
713
6.01M
                                        pu1_qp[-ctb_size / 8] :
714
6.03M
                                        pu1_qp[(2 * row - 1) * qp_strd - 1];
715
6.03M
                    }
716
717
8.45M
                    qp_q = u4_qp_const_in_ctb[2] ?
718
8.42M
                                    pu1_qp[-ctb_size / 8] :
719
8.45M
                                    pu1_qp[(2 * row) * qp_strd - 1];
720
8.45M
                }
721
59.0M
                else
722
59.0M
                {
723
59.0M
                    if(0 == row)
724
16.9M
                    {
725
16.9M
                        qp_p = u4_qp_const_in_ctb[1] ?
726
16.8M
                                        pu1_qp[-ctb_size / 8 * qp_strd] :
727
16.9M
                                        pu1_qp[col - 1 - qp_strd];
728
16.9M
                    }
729
42.1M
                    else
730
42.1M
                    {
731
42.1M
                        qp_p = u4_qp_const_in_ctb[3] ?
732
42.1M
                                        pu1_qp[0] :
733
18.4E
                                        pu1_qp[(col - 1) +  (2 * row - 1) * qp_strd];
734
42.1M
                    }
735
736
59.0M
                    qp_q = u4_qp_const_in_ctb[3] ?
737
59.0M
                                    pu1_qp[0] :
738
59.0M
                                    pu1_qp[(col - 1) + 2 * row * qp_strd];
739
59.0M
                }
740
741
67.5M
                filter_p = (pu2_ctb_no_loop_filter_flag[row << 1] >> col) & 1;
742
67.5M
                filter_q = (pu2_ctb_no_loop_filter_flag[(row << 1) + 1] >> col) & 1;
743
                /* filter_p and filter_q are inverted as they are calculated using no_loop_filter_flags */
744
67.5M
                filter_p = !filter_p;
745
67.5M
                filter_q = !filter_q;
746
747
67.5M
                if(filter_p || filter_q)
748
67.5M
                {
749
67.5M
                    ASSERT(1 == ((u4_bs & 3) >> 1));
750
67.5M
                    DUMP_DEBLK_CHROMA_HORZ(pu1_src, src_strd,
751
67.5M
                                           u4_bs & 3, qp_p, qp_q,
752
67.5M
                                           ps_pps->i1_pic_cb_qp_offset,
753
67.5M
                                           ps_pps->i1_pic_cr_qp_offset,
754
67.5M
                                           ps_slice_hdr->i1_tc_offset_div2,
755
67.5M
                                           filter_p, filter_q);
756
67.5M
                    if(chroma_yuv420sp_vu)
757
32.2M
                    {
758
32.2M
                        ps_codec->s_func_selector.ihevc_deblk_chroma_horz_fptr(pu1_src,
759
32.2M
                                                                               src_strd,
760
32.2M
                                                                               qp_q,
761
32.2M
                                                                               qp_p,
762
32.2M
                                                                               ps_pps->i1_pic_cr_qp_offset,
763
32.2M
                                                                               ps_pps->i1_pic_cb_qp_offset,
764
32.2M
                                                                               i1_tc_offset_div2,
765
32.2M
                                                                               filter_q,
766
32.2M
                                                                               filter_p);
767
32.2M
                    }
768
35.3M
                    else
769
35.3M
                    {
770
35.3M
                        ps_codec->s_func_selector.ihevc_deblk_chroma_horz_fptr(pu1_src,
771
35.3M
                                                                               src_strd,
772
35.3M
                                                                               qp_p,
773
35.3M
                                                                               qp_q,
774
35.3M
                                                                               ps_pps->i1_pic_cb_qp_offset,
775
35.3M
                                                                               ps_pps->i1_pic_cr_qp_offset,
776
35.3M
                                                                               i1_tc_offset_div2,
777
35.3M
                                                                               filter_p,
778
35.3M
                                                                               filter_q);
779
35.3M
                    }
780
67.5M
                }
781
782
67.5M
                pu1_src += 8;
783
67.4M
                u4_bs = u4_bs >> 4;
784
67.4M
                col++;
785
67.4M
            }
786
787
21.9M
            pu4_horz_bs += (64 == ctb_size) ? 2 : 1;
788
21.9M
            pu1_src -= ctb_size;
789
21.9M
            pu1_src += 8 * src_strd;
790
791
21.9M
        }
792
7.32M
    }
793
7.29M
}