Coverage Report

Created: 2026-09-01 06:17

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libhevc/encoder/ihevce_deblk.c
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2018 The Android Open Source Project
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
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/**
21
*******************************************************************************
22
* @file
23
*  ihevce_deblk.c
24
*
25
* @brief
26
*  Contains definition for the ctb level deblk function
27
*
28
* @author
29
*  ittiam
30
*
31
* @List of Functions:
32
*  ihevce_deblk_populate_qp_map()
33
*  ihevce_deblk_ctb()
34
*  ihevce_hbd_deblk_ctb()
35
*
36
* @remarks
37
*  None
38
*
39
*******************************************************************************
40
*/
41
42
/*****************************************************************************/
43
/* File Includes                                                             */
44
/*****************************************************************************/
45
/* System include files */
46
#include <stdio.h>
47
#include <string.h>
48
#include <stdlib.h>
49
#include <assert.h>
50
#include <stdarg.h>
51
#include <math.h>
52
53
/* User include files */
54
#include "ihevc_typedefs.h"
55
#include "itt_video_api.h"
56
#include "ihevce_api.h"
57
58
#include "rc_cntrl_param.h"
59
#include "rc_frame_info_collector.h"
60
#include "rc_look_ahead_params.h"
61
62
#include "ihevc_defs.h"
63
#include "ihevc_debug.h"
64
#include "ihevc_structs.h"
65
#include "ihevc_platform_macros.h"
66
#include "ihevc_deblk.h"
67
#include "ihevc_deblk_tables.h"
68
#include "ihevc_common_tables.h"
69
#include "ihevc_itrans_recon.h"
70
#include "ihevc_chroma_itrans_recon.h"
71
#include "ihevc_chroma_intra_pred.h"
72
#include "ihevc_intra_pred.h"
73
#include "ihevc_inter_pred.h"
74
#include "ihevc_mem_fns.h"
75
#include "ihevc_padding.h"
76
#include "ihevc_weighted_pred.h"
77
#include "ihevc_sao.h"
78
#include "ihevc_resi_trans.h"
79
#include "ihevc_quant_iquant_ssd.h"
80
#include "ihevc_cabac_tables.h"
81
82
#include "ihevce_defs.h"
83
#include "ihevce_hle_interface.h"
84
#include "ihevce_lap_enc_structs.h"
85
#include "ihevce_multi_thrd_structs.h"
86
#include "ihevce_me_common_defs.h"
87
#include "ihevce_had_satd.h"
88
#include "ihevce_error_codes.h"
89
#include "ihevce_bitstream.h"
90
#include "ihevce_cabac.h"
91
#include "ihevce_rdoq_macros.h"
92
#include "ihevce_function_selector.h"
93
#include "ihevce_enc_structs.h"
94
#include "ihevce_entropy_structs.h"
95
#include "ihevce_cmn_utils_instr_set_router.h"
96
#include "ihevce_enc_loop_structs.h"
97
#include "ihevce_common_utils.h"
98
#include "ihevce_global_tables.h"
99
#include "ihevce_deblk.h"
100
#include "ihevce_tile_interface.h"
101
102
/*****************************************************************************/
103
/* Function Definitions                                                      */
104
/*****************************************************************************/
105
106
/*!
107
******************************************************************************
108
* \if Function name : ihevce_deblk_populate_qp_map \endif
109
*
110
* \brief
111
*
112
*
113
*****************************************************************************
114
*/
115
void ihevce_deblk_populate_qp_map(
116
    ihevce_enc_loop_ctxt_t *ps_ctxt,
117
    deblk_ctbrow_prms_t *ps_deblk_ctb_row_params,
118
    ctb_enc_loop_out_t *ps_ctb_out_dblk,
119
    WORD32 vert_ctr,
120
    frm_ctb_ctxt_t *ps_frm_ctb_prms,
121
    ihevce_tile_params_t *ps_col_tile_params)
122
4.71k
{
123
4.71k
    ctb_enc_loop_out_t *ps_ctb_out;
124
4.71k
    WORD32 ctb_ctr, ctb_start, ctb_end;
125
4.71k
    WORD32 tile_qp_offset, tile_qp_size, i4_offset_for_last_cu_qp;
126
    /* Create the Qp map for the entire current CTB-row for deblocking purpose(only)*/
127
    /* Do this iff cur pic is referred or recon dump is enabled or psnr calc is on*/
128
    /*Qp of the last CU of previous CTB row*/
129
4.71k
    WORD8 i1_last_cu_qp;
130
    /*A pointer pointing to the top 4x4 block's Qp for all CTb rows*/
131
4.71k
    WORD8 *pi1_qp_top_4x4_ctb_row =
132
4.71k
        ps_deblk_ctb_row_params->api1_qp_top_4x4_ctb_row[ps_ctxt->i4_enc_frm_id] +
133
4.71k
        (ps_deblk_ctb_row_params->u4_qp_top_4x4_buf_size * ps_ctxt->i4_bitrate_instance_num);
134
135
4.71k
    UWORD32 u4_qp_top_4x4_buf_strd = ps_deblk_ctb_row_params->u4_qp_top_4x4_buf_strd;
136
137
    /*The Qp map which has to be populated*/
138
4.71k
    UWORD32 u4_qp_buffer_stride = ps_deblk_ctb_row_params->u4_qp_buffer_stride;
139
4.71k
    WORD8 *pi1_ctb_tile_qp = ps_deblk_ctb_row_params->pi1_ctb_row_qp;
140
141
    /*Temporary pointers to Qp map at CTB level*/
142
4.71k
    WORD8 *pi1_ctb_qp_map_tile;
143
144
4.71k
    i4_offset_for_last_cu_qp = ps_ctxt->pi4_offset_for_last_cu_qp[ps_ctxt->i4_tile_col_idx];
145
    /* total QPs to be copied for current row is : */
146
4.71k
    tile_qp_size = i4_offset_for_last_cu_qp + 1;
147
    /*Pointing to the first CTB of current CTB row*/
148
4.71k
    ps_ctb_out = ps_ctb_out_dblk;
149
    /* Offset req. for the row QP to the tile start */
150
4.71k
    tile_qp_offset = ps_col_tile_params->i4_first_ctb_x * (ps_frm_ctb_prms->i4_ctb_size / 4);
151
152
4.71k
    ctb_start = ps_col_tile_params->i4_first_ctb_x;
153
4.71k
    ctb_end =
154
4.71k
        (ps_col_tile_params->i4_first_ctb_x + ps_col_tile_params->i4_curr_tile_wd_in_ctb_unit);
155
156
4.71k
    if(vert_ctr) /*Not first CTB row of frame*/
157
2.32k
    {
158
        /*copy from top4x4_array data stored by upper CTB-row to qp-map*/
159
2.32k
        memcpy(
160
2.32k
            pi1_ctb_tile_qp,
161
2.32k
            (pi1_qp_top_4x4_ctb_row + (vert_ctr - 1) * u4_qp_top_4x4_buf_strd + tile_qp_offset),
162
2.32k
            tile_qp_size);
163
2.32k
    }
164
165
    /*pu1_ctb_row_qp points to top4x4 row in Qp-map.
166
    Now pointing pu1_ctb_qp_map to cur 4x4 row*/
167
4.71k
    pi1_ctb_qp_map_tile = pi1_ctb_tile_qp + u4_qp_buffer_stride;
168
169
    /* This i1_last_cu_qp will be conditionally overwritten later */
170
4.71k
    i1_last_cu_qp = ps_ctxt->i4_frame_qp;
171
172
    /* -- Loop over all the CTBs in a CTB-row for populating the Qp-map ----- */
173
16.1k
    for(ctb_ctr = ctb_start; ctb_ctr < ctb_end; ctb_ctr++)
174
11.4k
    {
175
11.4k
        WORD32 cu_ctr;
176
11.4k
        cu_enc_loop_out_t *ps_curr_cu;
177
178
        /* Update i1_last_cu_qp based on CTB's position in tile */
179
11.4k
        update_last_coded_cu_qp(
180
11.4k
            (ps_deblk_ctb_row_params->pi1_ctb_row_qp + i4_offset_for_last_cu_qp),
181
11.4k
            ps_ctxt->i1_entropy_coding_sync_enabled_flag,
182
11.4k
            ps_frm_ctb_prms,
183
11.4k
            ps_ctxt->i4_frame_qp,
184
11.4k
            vert_ctr,
185
11.4k
            ctb_ctr,
186
11.4k
            &i1_last_cu_qp);
187
188
        /* store the pointer of first cu of current ctb */
189
11.4k
        ps_curr_cu = ps_ctb_out->ps_enc_cu;
190
191
        /* --------- loop over all the CUs in the CTB --------------- */
192
218k
        for(cu_ctr = 0; cu_ctr < ps_ctb_out->u1_num_cus_in_ctb; cu_ctr++)
193
206k
        {
194
206k
            UWORD8 u1_vert_4x4, u1_horz_4x4;  //for_loop counters
195
206k
            WORD8 *pi1_cu_qp_map;
196
197
206k
            WORD8 i1_qp, i1_qp_left, i1_qp_top;
198
199
206k
            pi1_cu_qp_map = pi1_ctb_qp_map_tile +
200
206k
                            (ps_curr_cu->b3_cu_pos_y * 2) * u4_qp_buffer_stride +
201
206k
                            (ps_curr_cu->b3_cu_pos_x * 2);
202
203
            /*If the current CU is coded in skip_mode/zero_CBF then
204
            for deblocking, Qp of the previously coded CU will be used*/
205
206k
            if(ps_curr_cu->b1_skip_flag || ps_curr_cu->b1_no_residual_syntax_flag)
206
53.7k
            {
207
53.7k
                if(0 == ps_curr_cu->b3_cu_pos_x)
208
13.5k
                    i1_qp_left = i1_last_cu_qp;
209
40.1k
                else
210
40.1k
                    i1_qp_left = *(pi1_cu_qp_map - 1);
211
212
53.7k
                if(0 == ps_curr_cu->b3_cu_pos_y)
213
13.1k
                    i1_qp_top = i1_last_cu_qp;
214
40.5k
                else
215
40.5k
                    i1_qp_top = *(pi1_cu_qp_map - u4_qp_buffer_stride);
216
217
53.7k
                i1_qp = (i1_qp_left + i1_qp_top + 1) / 2;
218
219
53.7k
                if(0 == ps_curr_cu->b1_first_cu_in_qg)
220
0
                {
221
0
                    i1_qp = i1_last_cu_qp;
222
0
                }
223
53.7k
            }
224
153k
            else
225
153k
            {
226
153k
                i1_qp = ps_curr_cu->i1_cu_qp;
227
153k
            }
228
229
206k
            i1_last_cu_qp = i1_qp;
230
231
            /*---- Loop for populating Qp map for the current CU -------*/
232
766k
            for(u1_vert_4x4 = 0; u1_vert_4x4 < (ps_curr_cu->b4_cu_size * 2); u1_vert_4x4++)
233
559k
            {
234
2.76M
                for(u1_horz_4x4 = 0; u1_horz_4x4 < (ps_curr_cu->b4_cu_size * 2); u1_horz_4x4++)
235
2.20M
                {
236
2.20M
                    pi1_cu_qp_map[u1_horz_4x4] = i1_qp;
237
2.20M
                }
238
559k
                pi1_cu_qp_map += u4_qp_buffer_stride;
239
559k
            }
240
            /*Update Qp-map ptr. Qp map is at 4x4 level but b4_cu_size is at 8x8 level*/
241
206k
            ps_curr_cu++;
242
206k
        }
243
11.4k
        pi1_ctb_qp_map_tile += (ps_frm_ctb_prms->i4_ctb_size / 4);  //one qp per 4x4 block.
244
11.4k
        ps_ctb_out++;
245
246
11.4k
    }  //for(ctb_ctr = 0; ctb_ctr < num_ctbs_horz; ctb_ctr++)
247
248
    /*fill into the top4x4_array Qp for the lower CTB-row from bottom part of cur CTB row*/
249
4.71k
    memcpy(
250
4.71k
        (pi1_qp_top_4x4_ctb_row + vert_ctr * u4_qp_top_4x4_buf_strd + tile_qp_offset),
251
4.71k
        (pi1_ctb_tile_qp + (ps_frm_ctb_prms->i4_ctb_size / 4) * u4_qp_buffer_stride),
252
4.71k
        tile_qp_size);
253
4.71k
}
254
255
/**
256
*******************************************************************************
257
*
258
* @brief
259
*   Deblock CTB level function.
260
*
261
* @par Description:
262
*   For a given CTB, deblocking on both vertical and
263
*   horizontal edges is done. Both the luma and chroma
264
*   blocks are processed
265
*
266
* @param[in]
267
*   ps_deblk:   Pointer to the deblock context
268
*   last_col:   if the CTB is the last CTB of current CTB-row value is 1 else 0
269
*   ps_deblk_ctb_row_params: deblk ctb row params
270
*
271
* @returns
272
*
273
* @remarks
274
*  None
275
*
276
*******************************************************************************
277
*/
278
void ihevce_deblk_ctb(
279
    deblk_ctb_params_t *ps_deblk, WORD32 last_col, deblk_ctbrow_prms_t *ps_deblk_ctb_row_params)
280
11.4k
{
281
11.4k
    WORD32 ctb_size;
282
11.4k
    UWORD32 u4_bs;
283
11.4k
    WORD32 bs_lz; /*Leading zeros in boundary strength*/
284
11.4k
    WORD32 qp_p, qp_q;
285
11.4k
    UWORD8 *pu1_src;
286
11.4k
    UWORD8 *pu1_src_uv;
287
11.4k
    UWORD8 *pu1_curr_src;
288
11.4k
    WORD32 col_size;
289
11.4k
    WORD32 col, row, i4_edge_count;
290
11.4k
    WORD32 num_columns_for_vert_filt;
291
11.4k
    WORD32 num_blks_for_vert_filt;
292
11.4k
    WORD32 num_rows_for_horz_filt;
293
294
11.4k
    ihevc_deblk_chroma_horz_ft *pf_deblk_chroma_horz;
295
11.4k
    ihevc_deblk_chroma_horz_ft *pf_deblk_chroma_vert;
296
297
    /* Filter flags are packed along with the qp info.
298
    6 out of the 8 bits correspond to qp and 1 to filter flag. */
299
    /* filter_p and filter_q are initialized to 1.
300
    They are to be extracted along with the qp info. */
301
11.4k
    WORD32 filter_p, filter_q;
302
11.4k
    WORD8 *pi1_ctb_row_qp_p, *pi1_ctb_row_qp_temp;
303
11.4k
    WORD8 *pi1_ctb_row_qp_q;
304
305
11.4k
    func_selector_t *ps_func_slector = ps_deblk->ps_func_selector;
306
307
11.4k
    WORD32 left_luma_edge_filter_flag = ps_deblk->i4_deblock_left_ctb_edge;
308
11.4k
    WORD32 top_luma_edge_filter_flag = ps_deblk->i4_deblock_top_ctb_edge;
309
11.4k
    WORD32 left_chroma_edge_filter_flag = ps_deblk->i4_deblock_left_ctb_edge;
310
11.4k
    WORD32 top_chroma_edge_filter_flag = ps_deblk->i4_deblock_top_ctb_edge;
311
11.4k
    UWORD32 *bs_vert = ps_deblk_ctb_row_params->pu4_ctb_row_bs_vert;
312
11.4k
    UWORD32 *bs_horz = ps_deblk_ctb_row_params->pu4_ctb_row_bs_horz;
313
11.4k
    UWORD32 *bs_vert_uv = bs_vert;
314
11.4k
    UWORD32 *bs_horz_uv = bs_horz;
315
11.4k
    UWORD32 u4_qp_buffer_stride = ps_deblk_ctb_row_params->u4_qp_buffer_stride;
316
11.4k
    UWORD8 u1_is_422 = (ps_deblk->u1_chroma_array_type == 2);
317
318
11.4k
    if(u1_is_422)
319
0
    {
320
0
        pf_deblk_chroma_horz = ps_func_slector->ihevc_deblk_422chroma_horz_fptr;
321
0
        pf_deblk_chroma_vert = ps_func_slector->ihevc_deblk_422chroma_vert_fptr;
322
0
    }
323
11.4k
    else
324
11.4k
    {
325
11.4k
        pf_deblk_chroma_horz = ps_func_slector->ihevc_deblk_chroma_horz_fptr;
326
11.4k
        pf_deblk_chroma_vert = ps_func_slector->ihevc_deblk_chroma_vert_fptr;
327
11.4k
    }
328
329
11.4k
    ctb_size = ps_deblk->i4_ctb_size;
330
331
    /* The PCM filter flag and bypass trans flag are always set to 1 in encoder profile */
332
    /* Can be removed during optimization */
333
11.4k
    filter_q = 1;
334
11.4k
    filter_p = 1;
335
336
    //////////////////////////////////////////////////////////////////////////////
337
    /* Luma Veritcal Edge */
338
11.4k
    pu1_src = ps_deblk->pu1_ctb_y;
339
11.4k
    pi1_ctb_row_qp_temp = ps_deblk_ctb_row_params->pi1_ctb_row_qp + u4_qp_buffer_stride;
340
11.4k
    num_columns_for_vert_filt = ctb_size / 8;
341
11.4k
    num_blks_for_vert_filt = ctb_size / 4;
342
343
102k
    for(i4_edge_count = 0; i4_edge_count < num_columns_for_vert_filt; i4_edge_count++)
344
91.2k
    {
345
91.2k
        u4_bs = *bs_vert;
346
        /* get the current 4x4 vertical pointer */
347
91.2k
        pu1_curr_src = pu1_src;
348
91.2k
        pi1_ctb_row_qp_q = pi1_ctb_row_qp_temp + (i4_edge_count << 1);
349
350
        /* If the current edge is not the 1st edge of frame or slice */
351
91.2k
        if(1 == left_luma_edge_filter_flag)
352
86.4k
        {
353
668k
            for(row = 0; row < num_blks_for_vert_filt;)
354
581k
            {
355
581k
                bs_lz = CLZ(u4_bs) >> 1;
356
                /* If BS = 0, skip the egde filtering */
357
581k
                if(0 != bs_lz)
358
113k
                {
359
113k
                    u4_bs = u4_bs << (bs_lz << 1);
360
113k
                    pu1_curr_src += ((bs_lz << 2) * ps_deblk->i4_luma_pic_stride);
361
113k
                    pi1_ctb_row_qp_q += (bs_lz * u4_qp_buffer_stride);
362
113k
                    row += bs_lz;
363
113k
                    continue;
364
113k
                }
365
468k
                qp_p = *(pi1_ctb_row_qp_q - 1);
366
468k
                qp_q = *pi1_ctb_row_qp_q;
367
368
468k
                ps_func_slector->ihevc_deblk_luma_vert_fptr(
369
468k
                    pu1_curr_src,
370
468k
                    ps_deblk->i4_luma_pic_stride,
371
468k
                    (u4_bs >> 30), /* bits 31 and 30 are extracted */
372
468k
                    qp_p,
373
468k
                    qp_q,
374
468k
                    ps_deblk->i4_beta_offset_div2,
375
468k
                    ps_deblk->i4_tc_offset_div2,
376
468k
                    filter_p,
377
468k
                    filter_q);
378
379
468k
                u4_bs = u4_bs << 2;
380
468k
                pu1_curr_src += (ps_deblk->i4_luma_pic_stride << 2);
381
468k
                pi1_ctb_row_qp_q += u4_qp_buffer_stride;
382
468k
                row++;
383
468k
            }
384
86.4k
        }
385
386
        /* Increment the boundary strength and src pointer for the next column */
387
91.2k
        bs_vert += 1;
388
91.2k
        pu1_src += 8;
389
390
        /* Enable for the next edges of ctb*/
391
91.2k
        left_luma_edge_filter_flag = 1;
392
91.2k
    }
393
394
    //////////////////////////////////////////////////////////////////////////////
395
    /* Chroma Veritcal Edge */
396
11.4k
    pu1_src_uv = ps_deblk->pu1_ctb_uv;
397
11.4k
    pi1_ctb_row_qp_temp = ps_deblk_ctb_row_params->pi1_ctb_row_qp + u4_qp_buffer_stride;
398
399
    /* Column spacing is 4 for each chroma component */
400
    /* and hence 8 when they are interleaved. */
401
    /* But, only those columns with a x co-ordinate */
402
    /* that is divisiblee by 8 are filtered */
403
    /* Hence, denominator is 16 */
404
11.4k
    num_columns_for_vert_filt = ctb_size / 16;
405
    /* blk_size is 4 and chroma_ctb_height is ctb_size/2 */
406
11.4k
    num_blks_for_vert_filt = (0 == u1_is_422) ? (ctb_size / 2) / 4 : (ctb_size) / 4;
407
408
57.0k
    for(i4_edge_count = 0; i4_edge_count < num_columns_for_vert_filt; i4_edge_count++)
409
45.6k
    {
410
        /* Every alternate boundary strength value is used for 420 chroma */
411
45.6k
        u4_bs = *(bs_vert_uv) & ((0 == u1_is_422) ? 0x88888888 : 0xaaaaaaaa);
412
45.6k
        pu1_curr_src = pu1_src_uv;
413
45.6k
        pi1_ctb_row_qp_q = pi1_ctb_row_qp_temp + (i4_edge_count << 2);
414
415
        /* If the current edge is not the 1st edge of frame or slice */
416
45.6k
        if(1 == left_chroma_edge_filter_flag)
417
40.8k
        {
418
            /* Each 'bs' is 2 bits long */
419
            /* The divby4 in 420 is */
420
            /* necessitated by the fact that */
421
            /* chroma ctb_ht is half that of luma */
422
40.8k
            WORD32 i4_log2_num_bits_per_bs = ((0 == u1_is_422) + 1);
423
            /* i4_sub_heightC = 2 for 420 */
424
            /* i4_sub_heightC = 1 for 422 */
425
40.8k
            WORD32 i4_sub_heightC = i4_log2_num_bits_per_bs;
426
427
222k
            for(row = 0; row < num_blks_for_vert_filt;)
428
181k
            {
429
181k
                bs_lz = CLZ(u4_bs) >> i4_log2_num_bits_per_bs;
430
431
                /* If BS = 0, skip the egde filtering */
432
181k
                if(0 != bs_lz)
433
47.2k
                {
434
47.2k
                    row += bs_lz;
435
47.2k
                    u4_bs = u4_bs << (bs_lz << i4_log2_num_bits_per_bs);
436
                    /* '<<2' because of blk_size being 4x4 */
437
47.2k
                    pu1_curr_src += ((bs_lz << 2) * ps_deblk->i4_chroma_pic_stride);
438
439
                    /* In 420, every alternate QP row is skipped, because chroma height */
440
                    /* In 422, no row is skipped */
441
47.2k
                    pi1_ctb_row_qp_q += ((u4_qp_buffer_stride << (i4_sub_heightC - 1)) * bs_lz);
442
443
47.2k
                    continue;
444
47.2k
                }
445
446
134k
                qp_p = *(pi1_ctb_row_qp_q - i4_sub_heightC);
447
134k
                qp_q = *pi1_ctb_row_qp_q;
448
449
134k
                pf_deblk_chroma_vert(
450
134k
                    pu1_curr_src,
451
134k
                    ps_deblk->i4_chroma_pic_stride,
452
134k
                    qp_p,
453
134k
                    qp_q,
454
134k
                    ps_deblk->i4_cb_qp_indx_offset,
455
134k
                    ps_deblk->i4_cr_qp_indx_offset,
456
134k
                    ps_deblk->i4_tc_offset_div2,
457
134k
                    filter_p,
458
134k
                    filter_q,
459
134k
                    ps_deblk->u1_chroma_array_type);
460
461
134k
                u4_bs = u4_bs << (1 << i4_log2_num_bits_per_bs);
462
134k
                pu1_curr_src += (ps_deblk->i4_chroma_pic_stride << 2);
463
134k
                pi1_ctb_row_qp_q += (u4_qp_buffer_stride << (i4_sub_heightC - 1));
464
134k
                row++;
465
134k
            }
466
40.8k
        }
467
        /* Increment the boundary strength by 2 and src pointer for the next column */
468
        /* As the edge filtering happens for alternate column */
469
45.6k
        bs_vert_uv += 2;
470
45.6k
        pu1_src_uv += 16;
471
45.6k
        left_chroma_edge_filter_flag = 1;
472
45.6k
    }
473
474
    //////////////////////////////////////////////////////////////////////////////
475
476
    /* Luma Horizontal Edge */
477
11.4k
    pu1_src = ps_deblk->pu1_ctb_y;
478
11.4k
    col_size = ctb_size / 4;
479
480
    /* If the ctb is the 1st ctb of row,                     */
481
    /* Decrement the loop count to exclude filtering of last 4 pixels */
482
    /* else shift the src pointer by 4 pixels to do filtering for shifted ctb */
483
11.4k
    if(ps_deblk->i4_deblock_left_ctb_edge == 1)
484
6.68k
    {
485
6.68k
        pu1_src -= 4;
486
        /*If the ctb is at the horizonatl end of PIC*/
487
        /* Increase the column size to filter last 4 pixels */
488
6.68k
        col_size += last_col;
489
6.68k
    }
490
4.71k
    else if(!last_col)
491
2.41k
    {
492
2.41k
        col_size -= 1;
493
2.41k
    }
494
11.4k
    {
495
11.4k
        UWORD8 *pu1_src_temp = pu1_src;
496
        //pu1_ctb_row_qp_p and pu1_ctb_row_qp_q point to alternate rows
497
11.4k
        pi1_ctb_row_qp_p = ps_deblk_ctb_row_params->pi1_ctb_row_qp;
498
499
11.4k
        num_rows_for_horz_filt = ctb_size / 8;
500
501
102k
        for(i4_edge_count = 0; i4_edge_count < num_rows_for_horz_filt; i4_edge_count++)
502
91.2k
        {
503
91.2k
            WORD32 col_size_temp = col_size;
504
91.2k
            pi1_ctb_row_qp_q = pi1_ctb_row_qp_p + u4_qp_buffer_stride;
505
91.2k
            pu1_src = pu1_src_temp + (i4_edge_count * 8 * ps_deblk->i4_luma_pic_stride);
506
507
91.2k
            if(1 == top_luma_edge_filter_flag)
508
86.1k
            {
509
                //Deblock the last vertical_4x4_column of previous CTB
510
86.1k
                if(ps_deblk->i4_deblock_left_ctb_edge == 1)
511
50.8k
                {
512
50.8k
                    u4_bs = ps_deblk->au1_prev_bs[i4_edge_count] & 0x3;
513
50.8k
                    if(u4_bs != 0)
514
22.8k
                    {
515
22.8k
                        qp_p = *(pi1_ctb_row_qp_p - 1);
516
22.8k
                        qp_q = *(pi1_ctb_row_qp_q - 1);
517
518
22.8k
                        ps_func_slector->ihevc_deblk_luma_horz_fptr(
519
22.8k
                            pu1_src,
520
22.8k
                            ps_deblk->i4_luma_pic_stride,
521
22.8k
                            u4_bs,
522
22.8k
                            qp_p,
523
22.8k
                            qp_q,
524
22.8k
                            ps_deblk->i4_beta_offset_div2,
525
22.8k
                            ps_deblk->i4_tc_offset_div2,
526
22.8k
                            1,
527
22.8k
                            1);
528
22.8k
                    }
529
530
50.8k
                    pu1_src += 4;
531
50.8k
                    col_size_temp--;
532
50.8k
                }
533
                //Start deblocking current CTB
534
86.1k
                u4_bs = *(bs_horz);
535
536
636k
                for(col = 0; col < col_size_temp;)
537
549k
                {
538
549k
                    bs_lz = CLZ(u4_bs) >> 1;
539
549k
                    if(0 != bs_lz)
540
82.8k
                    {
541
82.8k
                        u4_bs = u4_bs << (bs_lz << 1);
542
82.8k
                        pu1_src += 4 * bs_lz;
543
82.8k
                        col += bs_lz;
544
82.8k
                        continue;
545
82.8k
                    }
546
467k
                    qp_p = *(pi1_ctb_row_qp_p + col);
547
467k
                    qp_q = *(pi1_ctb_row_qp_q + col);
548
549
467k
                    ps_func_slector->ihevc_deblk_luma_horz_fptr(
550
467k
                        pu1_src,
551
467k
                        ps_deblk->i4_luma_pic_stride,
552
467k
                        u4_bs >> (sizeof(u4_bs) * 8 - 2),
553
467k
                        qp_p,
554
467k
                        qp_q,
555
467k
                        ps_deblk->i4_beta_offset_div2,
556
467k
                        ps_deblk->i4_tc_offset_div2,
557
467k
                        filter_p,
558
467k
                        filter_q);
559
560
467k
                    pu1_src += 4;
561
467k
                    u4_bs = u4_bs << 2;
562
467k
                    col++;
563
467k
                }
564
                //Store the last vertical_4x4 column of CTB's info for next CTB deblocking
565
86.1k
                u4_bs = *bs_horz;
566
86.1k
                ps_deblk->au1_prev_bs[i4_edge_count] =
567
86.1k
                    (UWORD8)(((u4_bs << ((ctb_size >> 1) - 2))) >> 30);
568
86.1k
            }
569
91.2k
            bs_horz += 1;
570
91.2k
            pi1_ctb_row_qp_p += (u4_qp_buffer_stride << 1);
571
91.2k
            top_luma_edge_filter_flag = 1;
572
91.2k
        }
573
11.4k
    }
574
575
    //////////////////////////////////////////////////////////////////////////////
576
    /* Chroma Horizontal Edge */
577
11.4k
    pu1_src_uv = ps_deblk->pu1_ctb_uv;
578
11.4k
    col_size = ctb_size / 8;
579
580
    /* If the ctb is the 1st ctb of row,                     */
581
    /* Decrement the loop count to exclude filtering of last 4 pixels */
582
    /* else shift the src pointer by 8 (uv) pixels to do filtering for shifted ctb */
583
11.4k
    if(ps_deblk->i4_deblock_left_ctb_edge == 1)
584
6.68k
    {
585
6.68k
        pu1_src_uv -= 8;
586
587
        /*If the ctb is at the horizonatl end of PIC*/
588
        /* Increase the column size to filter last 8 (uv) pixels */
589
6.68k
        col_size += last_col;
590
6.68k
    }
591
4.71k
    else if(!last_col)
592
2.41k
    {
593
2.41k
        col_size--;
594
2.41k
    }
595
596
11.4k
    {
597
11.4k
        UWORD8 *pu1_src_temp = pu1_src_uv;
598
599
        //pu1_ctb_row_qp_p and pu1_ctb_row_qp_q point to alternate rows
600
11.4k
        pi1_ctb_row_qp_p = ps_deblk_ctb_row_params->pi1_ctb_row_qp;
601
11.4k
        num_rows_for_horz_filt = ctb_size / ((0 == u1_is_422) ? 16 : 8);
602
603
57.0k
        for(i4_edge_count = 0; i4_edge_count < num_rows_for_horz_filt; i4_edge_count++)
604
45.6k
        {
605
45.6k
            WORD32 col_size_temp = col_size;
606
607
45.6k
            pi1_ctb_row_qp_q = pi1_ctb_row_qp_p + u4_qp_buffer_stride;
608
45.6k
            pu1_src_uv = pu1_src_temp + (i4_edge_count * 8 * ps_deblk->i4_chroma_pic_stride);
609
610
45.6k
            if(1 == top_chroma_edge_filter_flag)
611
40.5k
            {
612
                //Deblock the last vertical _4x4_column of previous CTB
613
40.5k
                if(ps_deblk->i4_deblock_left_ctb_edge == 1)
614
24.1k
                {
615
24.1k
                    u4_bs = ps_deblk->au1_prev_bs_uv[i4_edge_count] & 0x2;
616
617
24.1k
                    if(u4_bs == 2)
618
13.1k
                    {
619
13.1k
                        qp_p = *(pi1_ctb_row_qp_p - 1);
620
13.1k
                        qp_q = *(pi1_ctb_row_qp_q - 1);
621
622
13.1k
                        pf_deblk_chroma_horz(
623
13.1k
                            pu1_src_uv,
624
13.1k
                            ps_deblk->i4_chroma_pic_stride,
625
13.1k
                            qp_p,
626
13.1k
                            qp_q,
627
13.1k
                            ps_deblk->i4_cb_qp_indx_offset,
628
13.1k
                            ps_deblk->i4_cr_qp_indx_offset,
629
13.1k
                            ps_deblk->i4_tc_offset_div2,
630
13.1k
                            1,
631
13.1k
                            1,
632
13.1k
                            ps_deblk->u1_chroma_array_type);
633
13.1k
                    }
634
635
24.1k
                    pu1_src_uv += 8;
636
24.1k
                    col_size_temp--;
637
24.1k
                }
638
639
                //Start deblocking current CTB
640
40.5k
                u4_bs = *(bs_horz_uv)&0x88888888;
641
642
200k
                for(col = 0; col < col_size_temp;)
643
159k
                {
644
159k
                    bs_lz = CLZ(u4_bs) >> 2;
645
646
159k
                    if(0 != bs_lz)
647
35.4k
                    {
648
35.4k
                        u4_bs = u4_bs << (bs_lz << 2);
649
35.4k
                        pu1_src_uv += (8 * bs_lz);
650
651
35.4k
                        col += bs_lz;
652
35.4k
                        continue;
653
35.4k
                    }
654
655
124k
                    qp_p = *(pi1_ctb_row_qp_p + (col << 1));
656
124k
                    qp_q = *(pi1_ctb_row_qp_q + (col << 1));
657
658
124k
                    pf_deblk_chroma_horz(
659
124k
                        pu1_src_uv,
660
124k
                        ps_deblk->i4_chroma_pic_stride,
661
124k
                        qp_p,
662
124k
                        qp_q,
663
124k
                        ps_deblk->i4_cb_qp_indx_offset,
664
124k
                        ps_deblk->i4_cr_qp_indx_offset,
665
124k
                        ps_deblk->i4_tc_offset_div2,
666
124k
                        filter_p,
667
124k
                        filter_q,
668
124k
                        ps_deblk->u1_chroma_array_type);
669
670
124k
                    pu1_src_uv += 8;
671
124k
                    u4_bs = u4_bs << 4;
672
124k
                    col++;
673
124k
                }
674
675
                //Store the last vertical_4x4 column of CTB's info for next CTB deblocking
676
40.5k
                u4_bs = *bs_horz_uv;
677
40.5k
                ps_deblk->au1_prev_bs_uv[i4_edge_count] =
678
40.5k
                    (UWORD8)(((u4_bs << ((ctb_size >> 1) - 4))) >> 30);
679
40.5k
            }
680
681
45.6k
            bs_horz_uv += ((0 == u1_is_422) + 1);
682
45.6k
            pi1_ctb_row_qp_p += (u4_qp_buffer_stride << ((0 == u1_is_422) + 1));
683
45.6k
            top_chroma_edge_filter_flag = 1;
684
45.6k
        }
685
11.4k
    }
686
687
11.4k
    return;
688
11.4k
}