Coverage Report

Created: 2025-11-05 07:08

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
139k
{
101
139k
    WORD32 ctb_size;
102
139k
    WORD32 log2_ctb_size;
103
139k
    UWORD32 u4_bs;
104
139k
    WORD32 bs_tz; /*Leading zeros in boundary strength*/
105
139k
    WORD32 qp_p, qp_q;
106
107
139k
    WORD32 filter_p, filter_q;
108
109
139k
    UWORD8 *pu1_src;
110
139k
    WORD32 qp_strd;
111
139k
    UWORD32 *pu4_vert_bs, *pu4_horz_bs;
112
139k
    UWORD32 *pu4_ctb_vert_bs, *pu4_ctb_horz_bs;
113
139k
    WORD32 bs_strd;
114
139k
    WORD32 src_strd;
115
139k
    UWORD8 *pu1_qp;
116
139k
    UWORD16 *pu2_ctb_no_loop_filter_flag;
117
139k
    UWORD16 au2_ctb_no_loop_filter_flag[9];
118
119
139k
    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
139k
    UWORD32 u4_qp_const_in_ctb[4] = { 0, 0, 0, 0 };
124
139k
    WORD32 ctb_indx;
125
139k
    WORD32  chroma_yuv420sp_vu = ps_deblk->is_chroma_yuv420sp_vu;
126
139k
    sps_t *ps_sps;
127
139k
    pps_t *ps_pps;
128
139k
    codec_t *ps_codec;
129
139k
    slice_header_t *ps_slice_hdr;
130
131
139k
    PROFILE_DISABLE_DEBLK();
132
133
139k
    ps_sps = ps_deblk->ps_sps;
134
139k
    ps_pps = ps_deblk->ps_pps;
135
139k
    ps_codec = ps_deblk->ps_codec;
136
139k
    ps_slice_hdr = ps_deblk->ps_slice_hdr;
137
138
139k
    log2_ctb_size = ps_sps->i1_log2_ctb_size;
139
139k
    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
139k
    bs_strd = (ps_sps->i2_pic_wd_in_ctb + 1) << (2 * log2_ctb_size - 7);
144
145
139k
    pu4_vert_bs = (UWORD32 *)((UWORD8 *)ps_deblk->s_bs_ctxt.pu4_pic_vert_bs +
146
139k
                    (ps_deblk->i4_ctb_x << (2 * log2_ctb_size - 7)) +
147
139k
                    ps_deblk->i4_ctb_y * bs_strd);
148
139k
    pu4_ctb_vert_bs = pu4_vert_bs;
149
150
139k
    pu4_horz_bs = (UWORD32 *)((UWORD8 *)ps_deblk->s_bs_ctxt.pu4_pic_horz_bs +
151
139k
                    (ps_deblk->i4_ctb_x << (2 * log2_ctb_size - 7)) +
152
139k
                    ps_deblk->i4_ctb_y * bs_strd);
153
139k
    pu4_ctb_horz_bs = pu4_horz_bs;
154
155
139k
    qp_strd = ps_sps->i2_pic_wd_in_ctb << (log2_ctb_size - 3);
156
139k
    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
139k
    pu2_ctb_no_loop_filter_flag = ps_deblk->au2_ctb_no_loop_filter_flag;
159
160
139k
    ctb_indx = ps_deblk->i4_ctb_x + ps_sps->i2_pic_wd_in_ctb * ps_deblk->i4_ctb_y;
161
139k
    if(i4_is_last_ctb_y)
162
563
    {
163
563
        pu4_vert_bs = (UWORD32 *)((UWORD8 *)pu4_vert_bs + bs_strd);
164
563
        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
563
        memset(pu4_vert_bs, 0, 1 << (2 * log2_ctb_size - 7));
170
171
563
        pu1_qp += (qp_strd << (log2_ctb_size - 3));
172
563
        pu2_ctb_no_loop_filter_flag += (ctb_size >> 3);
173
563
        ctb_indx += ps_sps->i2_pic_wd_in_ctb;
174
563
    }
175
176
139k
    if(i4_is_last_ctb_x)
177
5.51k
    {
178
5.51k
        pu4_horz_bs = (UWORD32 *)((UWORD8 *)pu4_horz_bs + (1 << (2 * log2_ctb_size - 7)));
179
5.51k
        pu4_ctb_horz_bs = pu4_horz_bs;
180
5.51k
        memset(pu4_horz_bs, 0, 1 << (2 * log2_ctb_size - 7));
181
182
5.51k
        pu1_qp += (ctb_size >> 3);
183
184
55.0k
        for(row = 0; row < (ctb_size >> 3) + 1; row++)
185
49.5k
            au2_ctb_no_loop_filter_flag[row] = ps_deblk->au2_ctb_no_loop_filter_flag[row] >> (ctb_size >> 3);
186
5.51k
        pu2_ctb_no_loop_filter_flag = au2_ctb_no_loop_filter_flag;
187
5.51k
        ctb_indx += 1;
188
5.51k
    }
189
190
139k
    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
139k
    if(ps_deblk->i4_ctb_x || i4_is_last_ctb_x)
193
131k
    {
194
131k
        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
131k
    }
196
197
139k
    if((ps_deblk->i4_ctb_x || i4_is_last_ctb_x) && (ps_deblk->i4_ctb_y || i4_is_last_ctb_y))
198
120k
    {
199
120k
        u4_qp_const_in_ctb[0] =
200
120k
                        ps_deblk->s_bs_ctxt.pu1_pic_qp_const_in_ctb[(ctb_indx - ps_sps->i2_pic_wd_in_ctb - 1) >> 3] &
201
120k
                        (1 << ((ctb_indx - ps_sps->i2_pic_wd_in_ctb - 1) & 7));
202
120k
    }
203
204
205
206
139k
    if(ps_deblk->i4_ctb_y || i4_is_last_ctb_y)
207
127k
    {
208
127k
        u4_qp_const_in_ctb[1] =
209
127k
                        ps_deblk->s_bs_ctxt.pu1_pic_qp_const_in_ctb[(ctb_indx - ps_sps->i2_pic_wd_in_ctb) >> 3] &
210
127k
                        (1 << ((ctb_indx - ps_sps->i2_pic_wd_in_ctb) & 7));
211
127k
    }
212
213
139k
    src_strd = ps_codec->i4_strd;
214
215
    /* Luma Vertical Edge */
216
217
139k
    if(0 == i4_is_last_ctb_x)
218
133k
    {
219
        /* Top CTB's slice header */
220
133k
        slice_header_t *ps_slice_hdr_top;
221
133k
        {
222
133k
            WORD32 cur_ctb_indx = ps_deblk->i4_ctb_x + ps_deblk->i4_ctb_y * ps_sps->i2_pic_wd_in_ctb;
223
133k
            if(i4_is_last_ctb_y)
224
563
                cur_ctb_indx += ps_sps->i2_pic_wd_in_ctb;
225
133k
            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
133k
        }
227
228
133k
        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
133k
        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
133k
        pu1_src -= 4 * src_strd;
234
235
1.17M
        for(col = 0; col < ctb_size / 8; col++)
236
1.04M
        {
237
1.04M
            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
1.04M
            if(6 != log2_ctb_size)
245
23.3k
                shift = (col & 1) << (log2_ctb_size - 1);
246
247
            /* BS for the column - Last row is excluded and the top row is included*/
248
1.04M
            u4_bs = (pu4_vert_bs[0] >> shift) << 2;
249
250
1.04M
            if(ps_deblk->i4_ctb_y || i4_is_last_ctb_y)
251
956k
            {
252
                /* Picking the last BS of the previous CTB corresponding to the same column */
253
956k
                UWORD32 *pu4_vert_bs_top = (UWORD32 *)((UWORD8 *)pu4_vert_bs - bs_strd);
254
956k
                UWORD32 u4_top_bs = (*pu4_vert_bs_top) >> (shift + (1 << (log2_ctb_size - 1)) - 2);
255
956k
                u4_bs |= u4_top_bs & 3;
256
956k
            }
257
258
4.65M
            for(row = 0; row < ctb_size / 4;)
259
3.61M
            {
260
3.61M
                WORD8 i1_beta_offset_div2 = ps_slice_hdr->i1_beta_offset_div2;
261
3.61M
                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
3.61M
                bs_tz = CTZ(u4_bs) >> 1;
265
3.61M
                if(0 != bs_tz)
266
1.92M
                {
267
1.92M
                    u4_bs = u4_bs >> (bs_tz << 1);
268
1.92M
                    if((row + bs_tz) >= (ctb_size / 4))
269
943k
                        pu1_src += 4 * (ctb_size / 4 - row) * src_strd;
270
984k
                    else
271
984k
                        pu1_src += 4 * bs_tz  * src_strd;
272
273
1.92M
                    row += bs_tz;
274
1.92M
                    continue;
275
1.92M
                }
276
277
1.68M
                if(0 == row)
278
100k
                {
279
100k
                    i1_beta_offset_div2 = ps_slice_hdr_top->i1_beta_offset_div2;
280
100k
                    i1_tc_offset_div2 = ps_slice_hdr_top->i1_tc_offset_div2;
281
282
100k
                    if(0 == col)
283
21.5k
                    {
284
21.5k
                        qp_p = u4_qp_const_in_ctb[0] ?
285
21.2k
                                        pu1_qp[-ctb_size / 8 * qp_strd - ctb_size / 8] :
286
21.5k
                                        pu1_qp[-qp_strd - 1];
287
21.5k
                    }
288
78.7k
                    else
289
78.7k
                    {
290
78.7k
                        qp_p = u4_qp_const_in_ctb[1] ?
291
77.1k
                                        pu1_qp[-ctb_size / 8 * qp_strd] :
292
78.7k
                                        pu1_qp[col - 1 - qp_strd];
293
78.7k
                    }
294
295
100k
                    qp_q = u4_qp_const_in_ctb[1] ?
296
98.3k
                                    pu1_qp[-ctb_size / 8 * qp_strd] :
297
100k
                                    pu1_qp[col - qp_strd];
298
100k
                }
299
1.58M
                else
300
1.58M
                {
301
1.58M
                    if(0 == col)
302
343k
                    {
303
343k
                        qp_p = u4_qp_const_in_ctb[2] ?
304
336k
                                        pu1_qp[-ctb_size / 8] :
305
343k
                                        pu1_qp[((row - 1) >> 1) * qp_strd - 1];
306
343k
                    }
307
1.24M
                    else
308
1.24M
                    {
309
1.24M
                        qp_p = u4_qp_const_in_ctb[3] ?
310
1.21M
                                        pu1_qp[0] :
311
1.24M
                                        pu1_qp[((row - 1) >> 1) * qp_strd + col - 1];
312
1.24M
                    }
313
314
1.58M
                    qp_q = u4_qp_const_in_ctb[3] ?
315
1.55M
                                    pu1_qp[0] :
316
1.58M
                                    pu1_qp[((row - 1) >> 1) * qp_strd + col];
317
1.58M
                }
318
319
1.68M
                filter_p = (pu2_ctb_no_loop_filter_flag[(row + 1) >> 1] >> col) & 1;
320
1.68M
                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
1.68M
                filter_p = !filter_p;
323
1.68M
                filter_q = !filter_q;
324
325
1.68M
                if(filter_p || filter_q)
326
1.69M
                {
327
1.69M
                    DUMP_DEBLK_LUMA_VERT(pu1_src, src_strd,
328
1.69M
                                         u4_bs & 3, qp_p, qp_q,
329
1.69M
                                         ps_slice_hdr->i1_beta_offset_div2,
330
1.69M
                                         ps_slice_hdr->i1_tc_offset_div2,
331
1.69M
                                         filter_p, filter_q);
332
1.69M
                    ps_codec->s_func_selector.ihevc_deblk_luma_vert_fptr(pu1_src, src_strd,
333
1.69M
                                                                         u4_bs & 3, qp_p, qp_q,
334
1.69M
                                                                         i1_beta_offset_div2,
335
1.69M
                                                                         i1_tc_offset_div2,
336
1.69M
                                                                         filter_p, filter_q);
337
1.69M
                }
338
339
1.68M
                pu1_src += 4 * src_strd;
340
1.68M
                u4_bs = u4_bs >> 2;
341
1.68M
                row++;
342
1.68M
            }
343
344
1.04M
            if((64 == ctb_size) ||
345
23.3k
                            ((32 == ctb_size) && (col & 1)))
346
1.03M
            {
347
1.03M
                pu4_vert_bs++;
348
1.03M
            }
349
1.04M
            pu1_src -= (src_strd << log2_ctb_size);
350
1.04M
            pu1_src += 8;
351
1.04M
        }
352
133k
        pu4_vert_bs = pu4_ctb_vert_bs;
353
133k
    }
354
355
356
    /* Luma Horizontal Edge */
357
358
139k
    if(0 == i4_is_last_ctb_y)
359
138k
    {
360
361
        /* Left CTB's slice header */
362
138k
        slice_header_t *ps_slice_hdr_left;
363
138k
        {
364
138k
            WORD32 cur_ctb_indx = ps_deblk->i4_ctb_x + ps_deblk->i4_ctb_y * ps_sps->i2_pic_wd_in_ctb;
365
138k
            if(i4_is_last_ctb_x)
366
5.51k
                cur_ctb_indx += 1;
367
138k
            ps_slice_hdr_left = ps_codec->ps_slice_hdr_base + ps_deblk->pu1_slice_idx[cur_ctb_indx - 1];
368
138k
        }
369
138k
        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
138k
        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
138k
        pu1_src -= 4;
375
1.22M
        for(row = 0; row < ctb_size / 8; row++)
376
1.08M
        {
377
1.08M
            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
1.08M
            if(6 != log2_ctb_size)
385
22.0k
                shift = (row & 1) << (log2_ctb_size - 1);
386
387
            /* BS for the row - Last column is excluded and the left column is included*/
388
1.08M
            u4_bs = (pu4_horz_bs[0] >> shift) << 2;
389
390
1.08M
            if(ps_deblk->i4_ctb_x || i4_is_last_ctb_x)
391
1.02M
            {
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
1.02M
                UWORD32 *pu4_horz_bs_left = (UWORD32 *)((UWORD8 *)pu4_horz_bs - (1 << (2 * log2_ctb_size - 7)));
396
1.02M
                UWORD32 u4_left_bs = (*pu4_horz_bs_left) >> (shift + (1 << (log2_ctb_size - 1)) - 2);
397
1.02M
                u4_bs |= u4_left_bs & 3;
398
1.02M
            }
399
400
4.83M
            for(col = 0; col < ctb_size / 4;)
401
3.74M
            {
402
3.74M
                WORD8 i1_beta_offset_div2 = ps_slice_hdr->i1_beta_offset_div2;
403
3.74M
                WORD8 i1_tc_offset_div2 = ps_slice_hdr->i1_tc_offset_div2;
404
405
3.74M
                bs_tz = CTZ(u4_bs) >> 1;
406
3.74M
                if(0 != bs_tz)
407
1.99M
                {
408
1.99M
                    u4_bs = u4_bs >> (bs_tz << 1);
409
410
1.99M
                    if((col + bs_tz) >= (ctb_size / 4))
411
975k
                        pu1_src += 4 * (ctb_size / 4 - col);
412
1.01M
                    else
413
1.01M
                        pu1_src += 4 * bs_tz;
414
415
1.99M
                    col += bs_tz;
416
1.99M
                    continue;
417
1.99M
                }
418
419
1.75M
                if(0 == col)
420
107k
                {
421
107k
                    i1_beta_offset_div2 = ps_slice_hdr_left->i1_beta_offset_div2;
422
107k
                    i1_tc_offset_div2 = ps_slice_hdr_left->i1_tc_offset_div2;
423
424
107k
                    if(0 == row)
425
27.4k
                    {
426
27.4k
                        qp_p = u4_qp_const_in_ctb[0] ?
427
27.0k
                                        pu1_qp[-ctb_size / 8 * qp_strd - ctb_size / 8] :
428
27.4k
                                        pu1_qp[-qp_strd - 1];
429
27.4k
                    }
430
80.4k
                    else
431
80.4k
                    {
432
80.4k
                        qp_p = u4_qp_const_in_ctb[2] ?
433
78.5k
                                        pu1_qp[-ctb_size / 8] :
434
80.4k
                                        pu1_qp[(row - 1) * qp_strd - 1];
435
80.4k
                    }
436
437
107k
                    qp_q = u4_qp_const_in_ctb[2] ?
438
105k
                                    pu1_qp[-ctb_size / 8] :
439
107k
                                    pu1_qp[row * qp_strd - 1];
440
107k
                }
441
1.64M
                else
442
1.64M
                {
443
1.64M
                    if(0 == row)
444
416k
                    {
445
416k
                        qp_p = u4_qp_const_in_ctb[1] ?
446
409k
                                        pu1_qp[-ctb_size / 8 * qp_strd] :
447
416k
                                        pu1_qp[((col - 1) >> 1) - qp_strd];
448
416k
                    }
449
1.22M
                    else
450
1.22M
                    {
451
1.22M
                        qp_p = u4_qp_const_in_ctb[3] ?
452
1.20M
                                        pu1_qp[0] :
453
1.22M
                                        pu1_qp[((col - 1) >> 1) + (row - 1) * qp_strd];
454
1.22M
                    }
455
456
1.64M
                    qp_q = u4_qp_const_in_ctb[3] ?
457
1.61M
                                    pu1_qp[0] :
458
1.64M
                                    pu1_qp[((col - 1) >> 1) + row * qp_strd];
459
1.64M
                }
460
461
1.75M
                filter_p = (pu2_ctb_no_loop_filter_flag[row] >> ((col + 1) >> 1)) & 1;
462
1.75M
                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
1.75M
                filter_p = !filter_p;
465
1.75M
                filter_q = !filter_q;
466
467
1.75M
                if(filter_p || filter_q)
468
1.75M
                {
469
1.75M
                    DUMP_DEBLK_LUMA_HORZ(pu1_src, src_strd,
470
1.75M
                                         u4_bs & 3, qp_p, qp_q,
471
1.75M
                                         ps_slice_hdr->i1_beta_offset_div2,
472
1.75M
                                         ps_slice_hdr->i1_tc_offset_div2,
473
1.75M
                                         filter_p, filter_q);
474
1.75M
                    ps_codec->s_func_selector.ihevc_deblk_luma_horz_fptr(pu1_src, src_strd,
475
1.75M
                                                                         u4_bs & 3, qp_p, qp_q,
476
1.75M
                                                                         i1_beta_offset_div2,
477
1.75M
                                                                         i1_tc_offset_div2, filter_p, filter_q);
478
1.75M
                }
479
480
1.75M
                pu1_src += 4;
481
1.75M
                u4_bs = u4_bs >> 2;
482
1.75M
                col++;
483
1.75M
            }
484
485
1.08M
            if((64 == ctb_size) ||
486
22.0k
                            ((32 == ctb_size) && (row & 1)))
487
1.07M
            {
488
1.07M
                pu4_horz_bs++;
489
1.07M
            }
490
1.08M
            pu1_src -= ctb_size;
491
1.08M
            pu1_src += (src_strd << 3);
492
1.08M
        }
493
138k
        pu4_horz_bs = pu4_ctb_horz_bs;
494
138k
    }
495
496
497
    /* Chroma Veritcal Edge */
498
499
139k
    if(0 == i4_is_last_ctb_x)
500
133k
    {
501
502
        /* Top CTB's slice header */
503
133k
        slice_header_t *ps_slice_hdr_top;
504
133k
        {
505
133k
            WORD32 cur_ctb_indx = ps_deblk->i4_ctb_x + ps_deblk->i4_ctb_y * ps_sps->i2_pic_wd_in_ctb;
506
133k
            if(i4_is_last_ctb_y)
507
563
                cur_ctb_indx += ps_sps->i2_pic_wd_in_ctb;
508
133k
            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
133k
        }
510
511
133k
        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
133k
        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
133k
        pu1_src -= 4 * src_strd;
517
518
655k
        for(col = 0; col < ctb_size / 16; col++)
519
522k
        {
520
521
            /* BS for the column - Last row is excluded and the top row is included*/
522
522k
            u4_bs = pu4_vert_bs[0] << 2;
523
524
522k
            if(ps_deblk->i4_ctb_y || i4_is_last_ctb_y)
525
478k
            {
526
                /* Picking the last BS of the previous CTB corresponding to the same column */
527
478k
                UWORD32 *pu4_vert_bs_top = (UWORD32 *)((UWORD8 *)pu4_vert_bs - bs_strd);
528
478k
                UWORD32 u4_top_bs = (*pu4_vert_bs_top) >> ((1 << (log2_ctb_size - 1)) - 2);
529
478k
                u4_bs |= u4_top_bs & 3;
530
478k
            }
531
532
            /* Every alternate boundary strength value is used for chroma */
533
522k
            u4_bs &= 0x22222222;
534
535
1.69M
            for(row = 0; row < ctb_size / 8;)
536
1.17M
            {
537
1.17M
                WORD8 i1_tc_offset_div2 = ps_slice_hdr->i1_tc_offset_div2;
538
539
1.17M
                bs_tz = CTZ(u4_bs) >> 2;
540
1.17M
                if(0 != bs_tz)
541
995k
                {
542
995k
                    if((row + bs_tz) >= (ctb_size / 8))
543
500k
                        pu1_src += 4 * (ctb_size / 8 - row) * src_strd;
544
495k
                    else
545
495k
                        pu1_src += 4 * bs_tz  * src_strd;
546
995k
                    row += bs_tz;
547
995k
                    u4_bs = u4_bs >> (bs_tz << 2);
548
995k
                    continue;
549
995k
                }
550
551
175k
                if(0 == row)
552
22.3k
                {
553
22.3k
                    i1_tc_offset_div2 = ps_slice_hdr_top->i1_tc_offset_div2;
554
555
22.3k
                    if(0 == col)
556
5.63k
                    {
557
5.63k
                        qp_p = u4_qp_const_in_ctb[0] ?
558
5.48k
                                        pu1_qp[-ctb_size / 8 * qp_strd - ctb_size / 8] :
559
5.63k
                                        pu1_qp[-qp_strd - 1];
560
5.63k
                    }
561
16.7k
                    else
562
16.7k
                    {
563
16.7k
                        qp_p = u4_qp_const_in_ctb[1] ?
564
16.3k
                                        pu1_qp[-ctb_size / 8 * qp_strd] :
565
16.7k
                                        pu1_qp[2 * col - 1 - qp_strd];
566
16.7k
                    }
567
568
22.3k
                    qp_q = u4_qp_const_in_ctb[1] ?
569
21.8k
                                    pu1_qp[-ctb_size / 8 * qp_strd] :
570
22.3k
                                    pu1_qp[2 * col - qp_strd];
571
22.3k
                }
572
152k
                else
573
152k
                {
574
152k
                    if(0 == col)
575
39.0k
                    {
576
39.0k
                        qp_p = u4_qp_const_in_ctb[2] ?
577
37.8k
                                        pu1_qp[-ctb_size / 8] :
578
39.0k
                                        pu1_qp[(row - 1) * qp_strd - 1];
579
39.0k
                    }
580
113k
                    else
581
113k
                    {
582
113k
                        qp_p = u4_qp_const_in_ctb[3] ?
583
111k
                                        pu1_qp[0] :
584
113k
                                        pu1_qp[(row - 1) * qp_strd + 2 * col - 1];
585
113k
                    }
586
587
152k
                    qp_q = u4_qp_const_in_ctb[3] ?
588
148k
                                    pu1_qp[0] :
589
152k
                                    pu1_qp[(row - 1) * qp_strd + 2 * col];
590
152k
                }
591
592
175k
                filter_p = (pu2_ctb_no_loop_filter_flag[row] >> (col << 1)) & 1;
593
175k
                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
175k
                filter_p = !filter_p;
596
175k
                filter_q = !filter_q;
597
598
175k
                if(filter_p || filter_q)
599
175k
                {
600
175k
                    ASSERT(1 == ((u4_bs & 3) >> 1));
601
175k
                    DUMP_DEBLK_CHROMA_VERT(pu1_src, src_strd,
602
175k
                                           u4_bs & 3, qp_p, qp_q,
603
175k
                                           ps_pps->i1_pic_cb_qp_offset,
604
175k
                                           ps_pps->i1_pic_cr_qp_offset,
605
175k
                                           ps_slice_hdr->i1_tc_offset_div2,
606
175k
                                           filter_p, filter_q);
607
175k
                    if(chroma_yuv420sp_vu)
608
4.98k
                    {
609
4.98k
                        ps_codec->s_func_selector.ihevc_deblk_chroma_vert_fptr(pu1_src,
610
4.98k
                                                                               src_strd,
611
4.98k
                                                                               qp_q,
612
4.98k
                                                                               qp_p,
613
4.98k
                                                                               ps_pps->i1_pic_cr_qp_offset,
614
4.98k
                                                                               ps_pps->i1_pic_cb_qp_offset,
615
4.98k
                                                                               i1_tc_offset_div2,
616
4.98k
                                                                               filter_q,
617
4.98k
                                                                               filter_p);
618
4.98k
                    }
619
170k
                    else
620
170k
                    {
621
170k
                        ps_codec->s_func_selector.ihevc_deblk_chroma_vert_fptr(pu1_src,
622
170k
                                                                               src_strd,
623
170k
                                                                               qp_p,
624
170k
                                                                               qp_q,
625
170k
                                                                               ps_pps->i1_pic_cb_qp_offset,
626
170k
                                                                               ps_pps->i1_pic_cr_qp_offset,
627
170k
                                                                               i1_tc_offset_div2,
628
170k
                                                                               filter_p,
629
170k
                                                                               filter_q);
630
170k
                    }
631
175k
                }
632
633
175k
                pu1_src += 4 * src_strd;
634
175k
                u4_bs = u4_bs >> 4;
635
175k
                row++;
636
175k
            }
637
638
522k
            pu4_vert_bs += (64 == ctb_size) ? 2 : 1;
639
522k
            pu1_src -= ((src_strd / 2) << log2_ctb_size);
640
522k
            pu1_src += 16;
641
522k
        }
642
133k
    }
643
644
    /* Chroma Horizontal Edge */
645
646
139k
    if(0 == i4_is_last_ctb_y)
647
138k
    {
648
649
        /* Left CTB's slice header */
650
138k
        slice_header_t *ps_slice_hdr_left;
651
138k
        {
652
138k
            WORD32 cur_ctb_indx = ps_deblk->i4_ctb_x + ps_deblk->i4_ctb_y * ps_sps->i2_pic_wd_in_ctb;
653
138k
            if(i4_is_last_ctb_x)
654
5.51k
                cur_ctb_indx += 1;
655
138k
            ps_slice_hdr_left = ps_codec->ps_slice_hdr_base + ps_deblk->pu1_slice_idx[cur_ctb_indx - 1];
656
138k
        }
657
658
138k
        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
138k
        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
138k
        pu1_src -= 8;
664
681k
        for(row = 0; row < ctb_size / 16; row++)
665
542k
        {
666
            /* BS for the row - Last column is excluded and the left column is included*/
667
542k
            u4_bs = pu4_horz_bs[0] << 2;
668
669
542k
            if(ps_deblk->i4_ctb_x || i4_is_last_ctb_x)
670
513k
            {
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
513k
                UWORD32 *pu4_horz_bs_left = (UWORD32 *)((UWORD8 *)pu4_horz_bs - (1 << (2 * log2_ctb_size - 7)));
675
513k
                UWORD32 u4_left_bs = (*pu4_horz_bs_left) >> ((1 << (log2_ctb_size - 1)) - 2);
676
513k
                u4_bs |= u4_left_bs & 3;
677
513k
            }
678
679
            /* Every alternate boundary strength value is used for chroma */
680
542k
            u4_bs &= 0x22222222;
681
682
1.75M
            for(col = 0; col < ctb_size / 8;)
683
1.21M
            {
684
1.21M
                WORD8 i1_tc_offset_div2 = ps_slice_hdr->i1_tc_offset_div2;
685
686
1.21M
                bs_tz = CTZ(u4_bs) >> 2;
687
1.21M
                if(0 != bs_tz)
688
1.03M
                {
689
1.03M
                    u4_bs = u4_bs >> (bs_tz << 2);
690
691
1.03M
                    if((col + bs_tz) >= (ctb_size / 8))
692
521k
                        pu1_src += 8 * (ctb_size / 8 - col);
693
516k
                    else
694
516k
                        pu1_src += 8 * bs_tz;
695
696
1.03M
                    col += bs_tz;
697
1.03M
                    continue;
698
1.03M
                }
699
700
174k
                if(0 == col)
701
21.0k
                {
702
21.0k
                    i1_tc_offset_div2 = ps_slice_hdr_left->i1_tc_offset_div2;
703
704
21.0k
                    if(0 == row)
705
5.27k
                    {
706
5.27k
                        qp_p = u4_qp_const_in_ctb[0] ?
707
5.13k
                                        pu1_qp[-ctb_size / 8 * qp_strd - ctb_size / 8] :
708
5.27k
                                        pu1_qp[-qp_strd - 1];
709
5.27k
                    }
710
15.8k
                    else
711
15.8k
                    {
712
15.8k
                        qp_p = u4_qp_const_in_ctb[2] ?
713
15.3k
                                        pu1_qp[-ctb_size / 8] :
714
15.8k
                                        pu1_qp[(2 * row - 1) * qp_strd - 1];
715
15.8k
                    }
716
717
21.0k
                    qp_q = u4_qp_const_in_ctb[2] ?
718
20.5k
                                    pu1_qp[-ctb_size / 8] :
719
21.0k
                                    pu1_qp[(2 * row) * qp_strd - 1];
720
21.0k
                }
721
153k
                else
722
153k
                {
723
153k
                    if(0 == row)
724
38.7k
                    {
725
38.7k
                        qp_p = u4_qp_const_in_ctb[1] ?
726
37.7k
                                        pu1_qp[-ctb_size / 8 * qp_strd] :
727
38.7k
                                        pu1_qp[col - 1 - qp_strd];
728
38.7k
                    }
729
114k
                    else
730
114k
                    {
731
114k
                        qp_p = u4_qp_const_in_ctb[3] ?
732
111k
                                        pu1_qp[0] :
733
114k
                                        pu1_qp[(col - 1) +  (2 * row - 1) * qp_strd];
734
114k
                    }
735
736
153k
                    qp_q = u4_qp_const_in_ctb[3] ?
737
149k
                                    pu1_qp[0] :
738
153k
                                    pu1_qp[(col - 1) + 2 * row * qp_strd];
739
153k
                }
740
741
174k
                filter_p = (pu2_ctb_no_loop_filter_flag[row << 1] >> col) & 1;
742
174k
                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
174k
                filter_p = !filter_p;
745
174k
                filter_q = !filter_q;
746
747
174k
                if(filter_p || filter_q)
748
174k
                {
749
174k
                    ASSERT(1 == ((u4_bs & 3) >> 1));
750
174k
                    DUMP_DEBLK_CHROMA_HORZ(pu1_src, src_strd,
751
174k
                                           u4_bs & 3, qp_p, qp_q,
752
174k
                                           ps_pps->i1_pic_cb_qp_offset,
753
174k
                                           ps_pps->i1_pic_cr_qp_offset,
754
174k
                                           ps_slice_hdr->i1_tc_offset_div2,
755
174k
                                           filter_p, filter_q);
756
174k
                    if(chroma_yuv420sp_vu)
757
6.64k
                    {
758
6.64k
                        ps_codec->s_func_selector.ihevc_deblk_chroma_horz_fptr(pu1_src,
759
6.64k
                                                                               src_strd,
760
6.64k
                                                                               qp_q,
761
6.64k
                                                                               qp_p,
762
6.64k
                                                                               ps_pps->i1_pic_cr_qp_offset,
763
6.64k
                                                                               ps_pps->i1_pic_cb_qp_offset,
764
6.64k
                                                                               i1_tc_offset_div2,
765
6.64k
                                                                               filter_q,
766
6.64k
                                                                               filter_p);
767
6.64k
                    }
768
168k
                    else
769
168k
                    {
770
168k
                        ps_codec->s_func_selector.ihevc_deblk_chroma_horz_fptr(pu1_src,
771
168k
                                                                               src_strd,
772
168k
                                                                               qp_p,
773
168k
                                                                               qp_q,
774
168k
                                                                               ps_pps->i1_pic_cb_qp_offset,
775
168k
                                                                               ps_pps->i1_pic_cr_qp_offset,
776
168k
                                                                               i1_tc_offset_div2,
777
168k
                                                                               filter_p,
778
168k
                                                                               filter_q);
779
168k
                    }
780
174k
                }
781
782
174k
                pu1_src += 8;
783
174k
                u4_bs = u4_bs >> 4;
784
174k
                col++;
785
174k
            }
786
787
542k
            pu4_horz_bs += (64 == ctb_size) ? 2 : 1;
788
542k
            pu1_src -= ctb_size;
789
542k
            pu1_src += 8 * src_strd;
790
791
542k
        }
792
138k
    }
793
139k
}