/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 | 23.2M | { |
101 | 23.2M | WORD32 ctb_size; |
102 | 23.2M | WORD32 log2_ctb_size; |
103 | 23.2M | UWORD32 u4_bs; |
104 | 23.2M | WORD32 bs_tz; /*Leading zeros in boundary strength*/ |
105 | 23.2M | WORD32 qp_p, qp_q; |
106 | | |
107 | 23.2M | WORD32 filter_p, filter_q; |
108 | | |
109 | 23.2M | UWORD8 *pu1_src; |
110 | 23.2M | WORD32 qp_strd; |
111 | 23.2M | UWORD32 *pu4_vert_bs, *pu4_horz_bs; |
112 | 23.2M | UWORD32 *pu4_ctb_vert_bs, *pu4_ctb_horz_bs; |
113 | 23.2M | WORD32 bs_strd; |
114 | 23.2M | WORD32 src_strd, chroma_strd; |
115 | 23.2M | WORD8 *pi1_qp; |
116 | 23.2M | UWORD16 *pu2_ctb_no_loop_filter_flag; |
117 | 23.2M | UWORD16 au2_ctb_no_loop_filter_flag[9]; |
118 | 23.2M | WORD32 pixel_size_y, pixel_size_uv; |
119 | 23.2M | UWORD8 u1_bit_depth_luma, u1_bit_depth_chroma; |
120 | | |
121 | 23.2M | WORD32 col, row; |
122 | | |
123 | | /* Flag to indicate if QP is constant in CTB |
124 | | * 0 - top_left, 1 - top, 2 - left, 3 - current */ |
125 | 23.2M | UWORD32 u4_qp_const_in_ctb[4] = { 0, 0, 0, 0 }; |
126 | 23.2M | WORD32 ctb_indx; |
127 | 23.2M | WORD32 chroma_yuv420sp_vu = ps_deblk->is_chroma_yuv420sp_vu; |
128 | 23.2M | sps_t *ps_sps; |
129 | 23.2M | pps_t *ps_pps; |
130 | 23.2M | codec_t *ps_codec; |
131 | 23.2M | slice_header_t *ps_slice_hdr; |
132 | | |
133 | 23.2M | ihevc_deblk_chroma_horz_ft *pf_deblk_chroma_horz; |
134 | 23.2M | ihevc_deblk_chroma_vert_ft *pf_deblk_chroma_vert; |
135 | 23.2M | ihevc_hbd_deblk_chroma_horz_ft *pf_hbd_deblk_chroma_horz; |
136 | 23.2M | ihevc_hbd_deblk_chroma_vert_ft *pf_hbd_deblk_chroma_vert; |
137 | | |
138 | 23.2M | PROFILE_DISABLE_DEBLK(); |
139 | | |
140 | 23.2M | ps_sps = ps_deblk->ps_sps; |
141 | 23.2M | ps_pps = ps_deblk->ps_pps; |
142 | 23.2M | ps_codec = ps_deblk->ps_codec; |
143 | 23.2M | ps_slice_hdr = ps_deblk->ps_slice_hdr; |
144 | | |
145 | 23.2M | WORD32 is_yuv422 = ps_sps->i1_chroma_format_idc == CHROMA_FMT_IDC_YUV422 ? 1 : 0; |
146 | 23.2M | WORD32 is_yuv444 = ps_sps->i1_chroma_format_idc == CHROMA_FMT_IDC_YUV444 ? 1 : 0; |
147 | 23.2M | WORD32 h_samp_factor = (CHROMA_FMT_IDC_YUV444 == ps_sps->i1_chroma_format_idc) ? 1 : 2; |
148 | 23.2M | WORD32 v_samp_factor = (CHROMA_FMT_IDC_YUV420 == ps_sps->i1_chroma_format_idc) ? 2 : 1; |
149 | 23.2M | WORD32 chroma_pixel_strd = 2; |
150 | | |
151 | 23.2M | log2_ctb_size = ps_sps->i1_log2_ctb_size; |
152 | 23.2M | ctb_size = (1 << ps_sps->i1_log2_ctb_size); |
153 | 23.2M | pixel_size_y = ps_codec->i4_pixel_size_y; |
154 | 23.2M | pixel_size_uv = ps_codec->i4_pixel_size_uv; |
155 | 23.2M | u1_bit_depth_luma = (UWORD8)ps_codec->i4_bit_depth_luma; |
156 | 23.2M | u1_bit_depth_chroma = (UWORD8)ps_codec->i4_bit_depth_chroma; |
157 | | |
158 | | |
159 | 23.2M | if(is_yuv422) |
160 | 1.52M | { |
161 | 1.52M | pf_deblk_chroma_horz = ps_codec->s_func_selector.ihevc_deblk_422chroma_horz_fptr; |
162 | 1.52M | pf_deblk_chroma_vert = ps_codec->s_func_selector.ihevc_deblk_422chroma_vert_fptr; |
163 | 1.52M | } |
164 | 21.7M | else |
165 | 21.7M | { |
166 | 21.7M | pf_deblk_chroma_horz = ps_codec->s_func_selector.ihevc_deblk_chroma_horz_fptr; |
167 | 21.7M | pf_deblk_chroma_vert = ps_codec->s_func_selector.ihevc_deblk_chroma_vert_fptr; |
168 | 21.7M | } |
169 | | |
170 | 23.2M | pf_hbd_deblk_chroma_horz = ps_codec->s_func_selector.ihevc_hbd_deblk_chroma_horz_fptr; |
171 | 23.2M | pf_hbd_deblk_chroma_vert = ps_codec->s_func_selector.ihevc_hbd_deblk_chroma_vert_fptr; |
172 | | |
173 | | /* strides are in units of number of bytes */ |
174 | | /* ctb_size * ctb_size / 8 / 16 is the number of bytes needed per CTB */ |
175 | 23.2M | bs_strd = (ps_sps->i2_pic_wd_in_ctb + 1) << (2 * log2_ctb_size - 7); |
176 | | |
177 | 23.2M | pu4_vert_bs = (UWORD32 *)((UWORD8 *)ps_deblk->s_bs_ctxt.pu4_pic_vert_bs + |
178 | 23.2M | (ps_deblk->i4_ctb_x << (2 * log2_ctb_size - 7)) + |
179 | 23.2M | ps_deblk->i4_ctb_y * bs_strd); |
180 | 23.2M | pu4_ctb_vert_bs = pu4_vert_bs; |
181 | | |
182 | 23.2M | pu4_horz_bs = (UWORD32 *)((UWORD8 *)ps_deblk->s_bs_ctxt.pu4_pic_horz_bs + |
183 | 23.2M | (ps_deblk->i4_ctb_x << (2 * log2_ctb_size - 7)) + |
184 | 23.2M | ps_deblk->i4_ctb_y * bs_strd); |
185 | 23.2M | pu4_ctb_horz_bs = pu4_horz_bs; |
186 | | |
187 | 23.2M | qp_strd = ps_sps->i2_pic_wd_in_ctb << (log2_ctb_size - 3); |
188 | 23.2M | pi1_qp = ps_deblk->s_bs_ctxt.pi1_pic_qp + ((ps_deblk->i4_ctb_x + ps_deblk->i4_ctb_y * qp_strd) << (log2_ctb_size - 3)); |
189 | | |
190 | 23.2M | pu2_ctb_no_loop_filter_flag = ps_deblk->au2_ctb_no_loop_filter_flag; |
191 | | |
192 | 23.2M | ctb_indx = ps_deblk->i4_ctb_x + ps_sps->i2_pic_wd_in_ctb * ps_deblk->i4_ctb_y; |
193 | 23.2M | if(i4_is_last_ctb_y) |
194 | 101k | { |
195 | 101k | pu4_vert_bs = (UWORD32 *)((UWORD8 *)pu4_vert_bs + bs_strd); |
196 | 101k | pu4_ctb_vert_bs = pu4_vert_bs; |
197 | | /* ctb_size/8 is the number of edges per CTB |
198 | | * ctb_size/4 is the number of BS values needed per edge |
199 | | * divided by 8 for the number of bytes |
200 | | * 2 is the number of bits needed for each BS value */ |
201 | 101k | memset(pu4_vert_bs, 0, 1 << (2 * log2_ctb_size - 7)); |
202 | | |
203 | 101k | pi1_qp += (qp_strd << (log2_ctb_size - 3)); |
204 | 101k | pu2_ctb_no_loop_filter_flag += (ctb_size >> 3); |
205 | 101k | ctb_indx += ps_sps->i2_pic_wd_in_ctb; |
206 | 101k | } |
207 | | |
208 | 23.2M | if(i4_is_last_ctb_x) |
209 | 297k | { |
210 | 297k | pu4_horz_bs = (UWORD32 *)((UWORD8 *)pu4_horz_bs + (1 << (2 * log2_ctb_size - 7))); |
211 | 297k | pu4_ctb_horz_bs = pu4_horz_bs; |
212 | 297k | memset(pu4_horz_bs, 0, 1 << (2 * log2_ctb_size - 7)); |
213 | | |
214 | 297k | pi1_qp += (ctb_size >> 3); |
215 | | |
216 | 2.45M | for(row = 0; row < (ctb_size >> 3) + 1; row++) |
217 | 2.15M | au2_ctb_no_loop_filter_flag[row] = ps_deblk->au2_ctb_no_loop_filter_flag[row] >> (ctb_size >> 3); |
218 | 297k | pu2_ctb_no_loop_filter_flag = au2_ctb_no_loop_filter_flag; |
219 | 297k | ctb_indx += 1; |
220 | 297k | } |
221 | | |
222 | 23.2M | u4_qp_const_in_ctb[3] = ps_deblk->s_bs_ctxt.pu1_pic_qp_const_in_ctb[(ctb_indx) >> 3] & (1 << (ctb_indx & 7)); |
223 | | |
224 | 23.2M | if(ps_deblk->i4_ctb_x || i4_is_last_ctb_x) |
225 | 22.2M | { |
226 | 22.2M | 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)); |
227 | 22.2M | } |
228 | | |
229 | 23.2M | if((ps_deblk->i4_ctb_x || i4_is_last_ctb_x) && (ps_deblk->i4_ctb_y || i4_is_last_ctb_y)) |
230 | 21.1M | { |
231 | 21.1M | u4_qp_const_in_ctb[0] = |
232 | 21.1M | ps_deblk->s_bs_ctxt.pu1_pic_qp_const_in_ctb[(ctb_indx - ps_sps->i2_pic_wd_in_ctb - 1) >> 3] & |
233 | 21.1M | (1 << ((ctb_indx - ps_sps->i2_pic_wd_in_ctb - 1) & 7)); |
234 | 21.1M | } |
235 | | |
236 | | |
237 | | |
238 | 23.2M | if(ps_deblk->i4_ctb_y || i4_is_last_ctb_y) |
239 | 22.0M | { |
240 | 22.0M | u4_qp_const_in_ctb[1] = |
241 | 22.0M | ps_deblk->s_bs_ctxt.pu1_pic_qp_const_in_ctb[(ctb_indx - ps_sps->i2_pic_wd_in_ctb) >> 3] & |
242 | 22.0M | (1 << ((ctb_indx - ps_sps->i2_pic_wd_in_ctb) & 7)); |
243 | 22.0M | } |
244 | | |
245 | 23.2M | src_strd = ps_codec->i4_strd; |
246 | 23.2M | chroma_strd = src_strd * chroma_pixel_strd / h_samp_factor; |
247 | | |
248 | | /* Luma Vertical Edge */ |
249 | | |
250 | 23.2M | if(0 == i4_is_last_ctb_x) |
251 | 22.8M | { |
252 | | /* Top CTB's slice header */ |
253 | 22.8M | slice_header_t *ps_slice_hdr_top; |
254 | 22.8M | { |
255 | 22.8M | WORD32 cur_ctb_indx = ps_deblk->i4_ctb_x + ps_deblk->i4_ctb_y * ps_sps->i2_pic_wd_in_ctb; |
256 | 22.8M | if(i4_is_last_ctb_y) |
257 | 101k | cur_ctb_indx += ps_sps->i2_pic_wd_in_ctb; |
258 | 22.8M | 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]; |
259 | 22.8M | } |
260 | | |
261 | 22.8M | pu1_src = ps_deblk->pu1_cur_pic_luma + |
262 | 22.8M | ((ps_deblk->i4_ctb_x + ps_deblk->i4_ctb_y * ps_codec->i4_strd) << (log2_ctb_size)) * pixel_size_y; |
263 | 22.8M | pu1_src += i4_is_last_ctb_y ? ((ps_codec->i4_strd << log2_ctb_size) * pixel_size_y) : 0; |
264 | | |
265 | | /** Deblocking is done on a shifted CTB - |
266 | | * Vertical edge processing is done by shifting the CTB up by four pixels */ |
267 | 22.8M | pu1_src -= 4 * src_strd * pixel_size_y; |
268 | | |
269 | 112M | for(col = 0; col < ctb_size / 8; col++) |
270 | 89.5M | { |
271 | 89.5M | WORD32 shift = 0; |
272 | | |
273 | | /* downshift vert_bs by ctb_size/2 for each column |
274 | | * shift = (col & ((MAX_CTB_SIZE >> log2_ctb_size) - 1)) << (log2_ctb_size - 1); |
275 | | * which will reduce to the following assuming ctb size is one of 16, 32 and 64 |
276 | | * and deblocking is done on 8x8 grid |
277 | | */ |
278 | 89.5M | if(6 != log2_ctb_size) |
279 | 48.6M | shift = (col & 1) << (log2_ctb_size - 1); |
280 | | |
281 | | /* BS for the column - Last row is excluded and the top row is included*/ |
282 | 89.5M | u4_bs = (pu4_vert_bs[0] >> shift) << 2; |
283 | | |
284 | 89.5M | if(ps_deblk->i4_ctb_y || i4_is_last_ctb_y) |
285 | 82.8M | { |
286 | | /* Picking the last BS of the previous CTB corresponding to the same column */ |
287 | 82.8M | UWORD32 *pu4_vert_bs_top = (UWORD32 *)((UWORD8 *)pu4_vert_bs - bs_strd); |
288 | 82.8M | UWORD32 u4_top_bs = (*pu4_vert_bs_top) >> (shift + (1 << (log2_ctb_size - 1)) - 2); |
289 | 82.8M | u4_bs |= u4_top_bs & 3; |
290 | 82.8M | } |
291 | | |
292 | 358M | for(row = 0; row < ctb_size / 4;) |
293 | 268M | { |
294 | 268M | WORD8 i1_beta_offset_div2 = ps_slice_hdr->i1_beta_offset_div2; |
295 | 268M | WORD8 i1_tc_offset_div2 = ps_slice_hdr->i1_tc_offset_div2; |
296 | | |
297 | | /* Trailing zeros are computed and the corresponding rows are not processed */ |
298 | 268M | bs_tz = CTZ(u4_bs) >> 1; |
299 | 268M | if(0 != bs_tz) |
300 | 104M | { |
301 | 104M | u4_bs = u4_bs >> (bs_tz << 1); |
302 | 104M | if((row + bs_tz) >= (ctb_size / 4)) |
303 | 73.5M | pu1_src += 4 * (ctb_size / 4 - row) * src_strd * pixel_size_y; |
304 | 31.3M | else |
305 | 31.3M | pu1_src += 4 * bs_tz * src_strd * pixel_size_y; |
306 | | |
307 | 104M | row += bs_tz; |
308 | 104M | continue; |
309 | 104M | } |
310 | | |
311 | 163M | if(0 == row) |
312 | 16.1M | { |
313 | 16.1M | i1_beta_offset_div2 = ps_slice_hdr_top->i1_beta_offset_div2; |
314 | 16.1M | i1_tc_offset_div2 = ps_slice_hdr_top->i1_tc_offset_div2; |
315 | | |
316 | 16.1M | if(0 == col) |
317 | 4.37M | { |
318 | 4.37M | qp_p = u4_qp_const_in_ctb[0] ? |
319 | 4.25M | pi1_qp[-ctb_size / 8 * qp_strd - ctb_size / 8] : |
320 | 4.37M | pi1_qp[-qp_strd - 1]; |
321 | 4.37M | } |
322 | 11.7M | else |
323 | 11.7M | { |
324 | 11.7M | qp_p = u4_qp_const_in_ctb[1] ? |
325 | 11.5M | pi1_qp[-ctb_size / 8 * qp_strd] : |
326 | 11.7M | pi1_qp[col - 1 - qp_strd]; |
327 | 11.7M | } |
328 | | |
329 | 16.1M | qp_q = u4_qp_const_in_ctb[1] ? |
330 | 15.6M | pi1_qp[-ctb_size / 8 * qp_strd] : |
331 | 16.1M | pi1_qp[col - qp_strd]; |
332 | 16.1M | } |
333 | 147M | else |
334 | 147M | { |
335 | 147M | if(0 == col) |
336 | 36.5M | { |
337 | 36.5M | qp_p = u4_qp_const_in_ctb[2] ? |
338 | 34.9M | pi1_qp[-ctb_size / 8] : |
339 | 36.5M | pi1_qp[((row - 1) >> 1) * qp_strd - 1]; |
340 | 36.5M | } |
341 | 110M | else |
342 | 110M | { |
343 | 110M | qp_p = u4_qp_const_in_ctb[3] ? |
344 | 121M | pi1_qp[0] : |
345 | 18.4E | pi1_qp[((row - 1) >> 1) * qp_strd + col - 1]; |
346 | 110M | } |
347 | | |
348 | 147M | qp_q = u4_qp_const_in_ctb[3] ? |
349 | 149M | pi1_qp[0] : |
350 | 18.4E | pi1_qp[((row - 1) >> 1) * qp_strd + col]; |
351 | 147M | } |
352 | | |
353 | 163M | filter_p = (pu2_ctb_no_loop_filter_flag[(row + 1) >> 1] >> col) & 1; |
354 | 163M | filter_q = (pu2_ctb_no_loop_filter_flag[(row + 1) >> 1] >> col) & 2; |
355 | | /* filter_p and filter_q are inverted as they are calculated using no_loop_filter_flags */ |
356 | 163M | filter_p = !filter_p; |
357 | 163M | filter_q = !filter_q; |
358 | | |
359 | 163M | if(filter_p || filter_q) |
360 | 165M | { |
361 | 165M | DUMP_DEBLK_LUMA_VERT(pu1_src, src_strd, |
362 | 165M | u4_bs & 3, qp_p, qp_q, |
363 | 165M | ps_slice_hdr->i1_beta_offset_div2, |
364 | 165M | ps_slice_hdr->i1_tc_offset_div2, |
365 | 165M | filter_p, filter_q); |
366 | 165M | if(PIXEL_SIZE_1BYTE == ps_codec->i4_pixel_size_y) |
367 | 81.7M | { |
368 | 81.7M | ps_codec->s_func_selector.ihevc_deblk_luma_vert_fptr(pu1_src, src_strd, |
369 | 81.7M | u4_bs & 3, qp_p, qp_q, |
370 | 81.7M | i1_beta_offset_div2, |
371 | 81.7M | i1_tc_offset_div2, |
372 | 81.7M | filter_p, filter_q); |
373 | 81.7M | } |
374 | 83.3M | else |
375 | 83.3M | { |
376 | 83.3M | ps_codec->s_func_selector.ihevc_hbd_deblk_luma_vert_fptr((UWORD16 *)pu1_src, |
377 | 83.3M | src_strd, |
378 | 83.3M | u4_bs & 3, qp_p, qp_q, |
379 | 83.3M | i1_beta_offset_div2, |
380 | 83.3M | i1_tc_offset_div2, |
381 | 83.3M | filter_p, filter_q, |
382 | 83.3M | u1_bit_depth_luma); |
383 | 83.3M | } |
384 | 165M | } |
385 | | |
386 | 163M | pu1_src += 4 * src_strd * pixel_size_y; |
387 | 163M | u4_bs = u4_bs >> 2; |
388 | 163M | row++; |
389 | 163M | } |
390 | | |
391 | 89.5M | if((64 == ctb_size) || |
392 | 48.2M | ((32 == ctb_size) && (col & 1))) |
393 | 54.8M | { |
394 | 54.8M | pu4_vert_bs++; |
395 | 54.8M | } |
396 | 89.5M | pu1_src -= ((src_strd << log2_ctb_size) * pixel_size_y); |
397 | 89.5M | pu1_src += 8 * pixel_size_y; |
398 | 89.5M | } |
399 | 22.8M | pu4_vert_bs = pu4_ctb_vert_bs; |
400 | 22.8M | } |
401 | | |
402 | | |
403 | | /* Luma Horizontal Edge */ |
404 | | |
405 | 23.2M | if(0 == i4_is_last_ctb_y) |
406 | 22.6M | { |
407 | | |
408 | | /* Left CTB's slice header */ |
409 | 22.6M | slice_header_t *ps_slice_hdr_left; |
410 | 22.6M | { |
411 | 22.6M | WORD32 cur_ctb_indx = ps_deblk->i4_ctb_x + ps_deblk->i4_ctb_y * ps_sps->i2_pic_wd_in_ctb; |
412 | 22.6M | if(i4_is_last_ctb_x) |
413 | 297k | cur_ctb_indx += 1; |
414 | 22.6M | ps_slice_hdr_left = ps_codec->ps_slice_hdr_base + ps_deblk->pu1_slice_idx[cur_ctb_indx - 1]; |
415 | 22.6M | } |
416 | 22.6M | pu1_src = ps_deblk->pu1_cur_pic_luma + |
417 | 22.6M | ((ps_deblk->i4_ctb_x + ps_deblk->i4_ctb_y * ps_codec->i4_strd) << log2_ctb_size) * pixel_size_y; |
418 | 22.6M | pu1_src += i4_is_last_ctb_x ? (ctb_size * pixel_size_y) : 0; |
419 | | |
420 | | /** Deblocking is done on a shifted CTB - |
421 | | * Horizontal edge processing is done by shifting the CTB left by four pixels */ |
422 | 22.6M | pu1_src -= 4 * pixel_size_y; |
423 | 113M | for(row = 0; row < ctb_size / 8; row++) |
424 | 91.3M | { |
425 | 91.3M | WORD32 shift = 0; |
426 | | |
427 | | /* downshift vert_bs by ctb_size/2 for each column |
428 | | * shift = (row & (MAX_CTB_SIZE / ctb_size - 1)) * ctb_size / 2; |
429 | | * which will reduce to the following assuming ctb size is one of 16, 32 and 64 |
430 | | * and deblocking is done on 8x8 grid |
431 | | */ |
432 | 91.3M | if(6 != log2_ctb_size) |
433 | 48.9M | shift = (row & 1) << (log2_ctb_size - 1); |
434 | | |
435 | | /* BS for the row - Last column is excluded and the left column is included*/ |
436 | 91.3M | u4_bs = (pu4_horz_bs[0] >> shift) << 2; |
437 | | |
438 | 91.3M | if(ps_deblk->i4_ctb_x || i4_is_last_ctb_x) |
439 | 86.6M | { |
440 | | /** Picking the last BS of the previous CTB corresponding to the same row |
441 | | * UWORD32 *pu4_horz_bs_left = (UWORD32 *)((UWORD8 *)pu4_horz_bs - (ctb_size / 8) * (ctb_size / 4) / 8 * 2); |
442 | | */ |
443 | 86.6M | UWORD32 *pu4_horz_bs_left = (UWORD32 *)((UWORD8 *)pu4_horz_bs - (1 << (2 * log2_ctb_size - 7))); |
444 | 86.6M | UWORD32 u4_left_bs = (*pu4_horz_bs_left) >> (shift + (1 << (log2_ctb_size - 1)) - 2); |
445 | 86.6M | u4_bs |= u4_left_bs & 3; |
446 | 86.6M | } |
447 | | |
448 | 368M | for(col = 0; col < ctb_size / 4;) |
449 | 276M | { |
450 | 276M | WORD8 i1_beta_offset_div2 = ps_slice_hdr->i1_beta_offset_div2; |
451 | 276M | WORD8 i1_tc_offset_div2 = ps_slice_hdr->i1_tc_offset_div2; |
452 | | |
453 | 276M | bs_tz = CTZ(u4_bs) >> 1; |
454 | 276M | if(0 != bs_tz) |
455 | 106M | { |
456 | 106M | u4_bs = u4_bs >> (bs_tz << 1); |
457 | | |
458 | 106M | if((col + bs_tz) >= (ctb_size / 4)) |
459 | 73.9M | pu1_src += 4 * (ctb_size / 4 - col) * pixel_size_y; |
460 | 32.0M | else |
461 | 32.0M | pu1_src += 4 * bs_tz * pixel_size_y; |
462 | | |
463 | 106M | col += bs_tz; |
464 | 106M | continue; |
465 | 106M | } |
466 | | |
467 | 170M | if(0 == col) |
468 | 17.4M | { |
469 | 17.4M | i1_beta_offset_div2 = ps_slice_hdr_left->i1_beta_offset_div2; |
470 | 17.4M | i1_tc_offset_div2 = ps_slice_hdr_left->i1_tc_offset_div2; |
471 | | |
472 | 17.4M | if(0 == row) |
473 | 4.44M | { |
474 | 4.44M | qp_p = u4_qp_const_in_ctb[0] ? |
475 | 4.32M | pi1_qp[-ctb_size / 8 * qp_strd - ctb_size / 8] : |
476 | 4.44M | pi1_qp[-qp_strd - 1]; |
477 | 4.44M | } |
478 | 12.9M | else |
479 | 12.9M | { |
480 | 12.9M | qp_p = u4_qp_const_in_ctb[2] ? |
481 | 12.7M | pi1_qp[-ctb_size / 8] : |
482 | 12.9M | pi1_qp[(row - 1) * qp_strd - 1]; |
483 | 12.9M | } |
484 | | |
485 | 17.4M | qp_q = u4_qp_const_in_ctb[2] ? |
486 | 16.9M | pi1_qp[-ctb_size / 8] : |
487 | 17.4M | pi1_qp[row * qp_strd - 1]; |
488 | 17.4M | } |
489 | 153M | else |
490 | 153M | { |
491 | 153M | if(0 == row) |
492 | 37.9M | { |
493 | 37.9M | qp_p = u4_qp_const_in_ctb[1] ? |
494 | 36.3M | pi1_qp[-ctb_size / 8 * qp_strd] : |
495 | 37.9M | pi1_qp[((col - 1) >> 1) - qp_strd]; |
496 | 37.9M | } |
497 | 115M | else |
498 | 115M | { |
499 | 115M | qp_p = u4_qp_const_in_ctb[3] ? |
500 | 125M | pi1_qp[0] : |
501 | 18.4E | pi1_qp[((col - 1) >> 1) + (row - 1) * qp_strd]; |
502 | 115M | } |
503 | | |
504 | 153M | qp_q = u4_qp_const_in_ctb[3] ? |
505 | 154M | pi1_qp[0] : |
506 | 18.4E | pi1_qp[((col - 1) >> 1) + row * qp_strd]; |
507 | 153M | } |
508 | | |
509 | 170M | filter_p = (pu2_ctb_no_loop_filter_flag[row] >> ((col + 1) >> 1)) & 1; |
510 | 170M | filter_q = (pu2_ctb_no_loop_filter_flag[row + 1] >> ((col + 1) >> 1)) & 1; |
511 | | /* filter_p and filter_q are inverted as they are calculated using no_loop_filter_flags */ |
512 | 170M | filter_p = !filter_p; |
513 | 170M | filter_q = !filter_q; |
514 | | |
515 | 170M | if(filter_p || filter_q) |
516 | 170M | { |
517 | 170M | DUMP_DEBLK_LUMA_HORZ(pu1_src, src_strd, |
518 | 170M | u4_bs & 3, qp_p, qp_q, |
519 | 170M | ps_slice_hdr->i1_beta_offset_div2, |
520 | 170M | ps_slice_hdr->i1_tc_offset_div2, |
521 | 170M | filter_p, filter_q); |
522 | 170M | if(PIXEL_SIZE_1BYTE == ps_codec->i4_pixel_size_y) |
523 | 86.7M | { |
524 | 86.7M | ps_codec->s_func_selector.ihevc_deblk_luma_horz_fptr(pu1_src, src_strd, |
525 | 86.7M | u4_bs & 3, qp_p, qp_q, |
526 | 86.7M | i1_beta_offset_div2, |
527 | 86.7M | i1_tc_offset_div2, filter_p, filter_q); |
528 | 86.7M | } |
529 | 84.1M | else |
530 | 84.1M | { |
531 | 84.1M | ps_codec->s_func_selector.ihevc_hbd_deblk_luma_horz_fptr((UWORD16 *)pu1_src, |
532 | 84.1M | src_strd, |
533 | 84.1M | u4_bs & 3, qp_p, qp_q, |
534 | 84.1M | i1_beta_offset_div2, |
535 | 84.1M | i1_tc_offset_div2, |
536 | 84.1M | filter_p, filter_q, |
537 | 84.1M | u1_bit_depth_luma); |
538 | 84.1M | } |
539 | 170M | } |
540 | | |
541 | 170M | pu1_src += 4 * pixel_size_y; |
542 | 170M | u4_bs = u4_bs >> 2; |
543 | 170M | col++; |
544 | 170M | } |
545 | | |
546 | 91.3M | if((64 == ctb_size) || |
547 | 49.1M | ((32 == ctb_size) && (row & 1))) |
548 | 56.7M | { |
549 | 56.7M | pu4_horz_bs++; |
550 | 56.7M | } |
551 | 91.3M | pu1_src -= ctb_size * pixel_size_y; |
552 | 91.3M | pu1_src += ((src_strd << 3) * pixel_size_y); |
553 | 91.3M | } |
554 | 22.6M | pu4_horz_bs = pu4_ctb_horz_bs; |
555 | 22.6M | } |
556 | | |
557 | | |
558 | | /* Chroma Veritcal Edge */ |
559 | | |
560 | 23.2M | if(CHROMA_FMT_IDC_MONOCHROME != ps_sps->i1_chroma_format_idc && 0 == i4_is_last_ctb_x) |
561 | 22.6M | { |
562 | | |
563 | | /* Top CTB's slice header */ |
564 | 22.6M | slice_header_t *ps_slice_hdr_top; |
565 | 22.6M | { |
566 | 22.6M | WORD32 cur_ctb_indx = ps_deblk->i4_ctb_x + ps_deblk->i4_ctb_y * ps_sps->i2_pic_wd_in_ctb; |
567 | 22.6M | if(i4_is_last_ctb_y) |
568 | 99.4k | cur_ctb_indx += ps_sps->i2_pic_wd_in_ctb; |
569 | 22.6M | 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]; |
570 | 22.6M | } |
571 | | |
572 | 22.6M | pu1_src = ps_deblk->pu1_cur_pic_chroma + |
573 | 22.6M | ((((ps_deblk->i4_ctb_x * chroma_pixel_strd / h_samp_factor) + |
574 | 22.6M | ps_deblk->i4_ctb_y * ps_deblk->ps_codec->i4_strd * chroma_pixel_strd / (h_samp_factor * v_samp_factor)) << log2_ctb_size) * pixel_size_uv); |
575 | 22.6M | pu1_src += i4_is_last_ctb_y ? |
576 | 22.5M | ((((ps_codec->i4_strd * chroma_pixel_strd) / (h_samp_factor * v_samp_factor)) << log2_ctb_size) * pixel_size_uv) : 0; |
577 | | |
578 | | /** Deblocking is done on a shifted CTB - |
579 | | * Vertical edge processing is done by shifting the CTB up by four pixels */ |
580 | 22.6M | pu1_src -= 4 * chroma_strd * pixel_size_uv; |
581 | | |
582 | 68.9M | for(col = 0; col < ctb_size / (8 * h_samp_factor); col++) |
583 | 46.2M | { |
584 | 46.2M | WORD32 shift = 0; |
585 | | |
586 | 46.2M | if(is_yuv444 && 6 != log2_ctb_size) |
587 | 172k | shift = (col & 1) << (log2_ctb_size - 1); |
588 | | |
589 | | /* BS for the column - Last row is excluded and the top row is included*/ |
590 | 46.2M | u4_bs = (pu4_vert_bs[0] >> shift) << 2; |
591 | | |
592 | 46.2M | if(ps_deblk->i4_ctb_y || i4_is_last_ctb_y) |
593 | 42.5M | { |
594 | | /* Picking the last BS of the previous CTB corresponding to the same column */ |
595 | 42.5M | UWORD32 *pu4_vert_bs_top = (UWORD32 *)((UWORD8 *)pu4_vert_bs - bs_strd); |
596 | 42.5M | UWORD32 u4_top_bs = (*pu4_vert_bs_top) >> (shift + (1 << (log2_ctb_size - 1)) - 2); |
597 | 42.5M | u4_bs |= u4_top_bs & 3; |
598 | 42.5M | } |
599 | | |
600 | 46.2M | if(ps_sps->i1_chroma_format_idc == CHROMA_FMT_IDC_YUV420) { |
601 | | /* Every alternate boundary strength value is used for chroma */ |
602 | 38.8M | u4_bs &= 0x22222222; |
603 | 38.8M | } else if(ps_sps->i1_chroma_format_idc == CHROMA_FMT_IDC_YUV444 || ps_sps->i1_chroma_format_idc == CHROMA_FMT_IDC_YUV422) { |
604 | | /* Every boundary strength value is used for chroma */ |
605 | 7.46M | u4_bs &= 0xAAAAAAAA; |
606 | 7.46M | } |
607 | | |
608 | 180M | for(row = 0; row < ctb_size / (4 * v_samp_factor);) |
609 | 134M | { |
610 | 134M | WORD8 i1_tc_offset_div2 = ps_slice_hdr->i1_tc_offset_div2; |
611 | | |
612 | 134M | bs_tz = CTZ(u4_bs) >> v_samp_factor; |
613 | 134M | if(0 != bs_tz) |
614 | 51.9M | { |
615 | 51.9M | if((row + bs_tz) >= (ctb_size / (4 * v_samp_factor))) |
616 | 36.5M | pu1_src += 4 * (ctb_size / (4 * v_samp_factor) - row) * chroma_strd * pixel_size_uv; |
617 | 15.3M | else |
618 | 15.3M | pu1_src += 4 * bs_tz * chroma_strd * pixel_size_uv; |
619 | 51.9M | row += bs_tz; |
620 | 51.9M | u4_bs = u4_bs >> (bs_tz << v_samp_factor); |
621 | 51.9M | continue; |
622 | 51.9M | } |
623 | | |
624 | 82.5M | if(0 == row) |
625 | 9.69M | { |
626 | 9.69M | i1_tc_offset_div2 = ps_slice_hdr_top->i1_tc_offset_div2; |
627 | | |
628 | 9.69M | if(0 == col) |
629 | 4.39M | { |
630 | 4.39M | qp_p = u4_qp_const_in_ctb[0] ? |
631 | 4.27M | pi1_qp[-ctb_size / 8 * qp_strd - ctb_size / 8] : |
632 | 4.39M | pi1_qp[-qp_strd - 1]; |
633 | 4.39M | } |
634 | 5.30M | else |
635 | 5.30M | { |
636 | 5.30M | qp_p = u4_qp_const_in_ctb[1] ? |
637 | 5.12M | pi1_qp[-ctb_size / 8 * qp_strd] : |
638 | 5.30M | pi1_qp[h_samp_factor * col - 1 - qp_strd]; |
639 | 5.30M | } |
640 | | |
641 | 9.69M | qp_q = u4_qp_const_in_ctb[1] ? |
642 | 9.31M | pi1_qp[-ctb_size / 8 * qp_strd] : |
643 | 9.69M | pi1_qp[h_samp_factor * col - qp_strd]; |
644 | 9.69M | } |
645 | 72.8M | else |
646 | 72.8M | { |
647 | 72.8M | if(0 == col) |
648 | 24.1M | { |
649 | 24.1M | qp_p = u4_qp_const_in_ctb[2] ? |
650 | 23.3M | pi1_qp[-ctb_size / 8] : |
651 | 24.1M | pi1_qp[((row - 1) >> (2 - v_samp_factor)) * qp_strd - 1]; |
652 | 24.1M | } |
653 | 48.7M | else |
654 | 48.7M | { |
655 | 48.7M | qp_p = u4_qp_const_in_ctb[3] ? |
656 | 49.8M | pi1_qp[0] : |
657 | 18.4E | pi1_qp[((row - 1) >> (2 - v_samp_factor)) * qp_strd + h_samp_factor * col - 1]; |
658 | 48.7M | } |
659 | | |
660 | 72.8M | qp_q = u4_qp_const_in_ctb[3] ? |
661 | 71.2M | pi1_qp[0] : |
662 | 72.8M | pi1_qp[((row - 1) >> (2 - v_samp_factor)) * qp_strd + h_samp_factor * col]; |
663 | 72.8M | } |
664 | | |
665 | 82.5M | filter_p = (pu2_ctb_no_loop_filter_flag[(row + (2 - v_samp_factor)) >> (2 - v_samp_factor)] >> (col << (h_samp_factor - 1))) & 1; |
666 | 82.5M | filter_q = (pu2_ctb_no_loop_filter_flag[(row + (2 - v_samp_factor)) >> (2 - v_samp_factor)] >> (col << (h_samp_factor - 1))) & 2; |
667 | | /* filter_p and filter_q are inverted as they are calculated using no_loop_filter_flags */ |
668 | 82.5M | filter_p = !filter_p; |
669 | 82.5M | filter_q = !filter_q; |
670 | | |
671 | 82.5M | if(filter_p || filter_q) |
672 | 81.4M | { |
673 | 81.4M | if(ps_sps->i1_chroma_format_idc == CHROMA_FMT_IDC_YUV420) { |
674 | 39.2M | ASSERT(1 == ((u4_bs & 3) >> 1)); |
675 | 39.2M | } |
676 | 81.4M | DUMP_DEBLK_CHROMA_VERT(pu1_src, chroma_strd, |
677 | 81.4M | u4_bs & 3, qp_p, qp_q, |
678 | 81.4M | ps_pps->i1_pic_cb_qp_offset, |
679 | 81.4M | ps_pps->i1_pic_cr_qp_offset, |
680 | 81.4M | ps_slice_hdr->i1_tc_offset_div2, |
681 | 81.4M | filter_p, filter_q); |
682 | 81.4M | if(chroma_yuv420sp_vu) |
683 | 3.75M | { |
684 | 3.75M | if(PIXEL_SIZE_1BYTE == ps_codec->i4_pixel_size_uv) |
685 | 2.91M | { |
686 | 2.91M | pf_deblk_chroma_vert(pu1_src, |
687 | 2.91M | chroma_strd, |
688 | 2.91M | qp_q, |
689 | 2.91M | qp_p, |
690 | 2.91M | ps_pps->i1_pic_cr_qp_offset, |
691 | 2.91M | ps_pps->i1_pic_cb_qp_offset, |
692 | 2.91M | i1_tc_offset_div2, |
693 | 2.91M | filter_q, |
694 | 2.91M | filter_p, |
695 | 2.91M | ps_sps->i1_chroma_format_idc); |
696 | 2.91M | } |
697 | 840k | else |
698 | 840k | { |
699 | 840k | pf_hbd_deblk_chroma_vert((UWORD16 *)pu1_src, |
700 | 840k | chroma_strd, |
701 | 840k | qp_q, |
702 | 840k | qp_p, |
703 | 840k | ps_pps->i1_pic_cr_qp_offset, |
704 | 840k | ps_pps->i1_pic_cb_qp_offset, |
705 | 840k | i1_tc_offset_div2, |
706 | 840k | filter_q, |
707 | 840k | filter_p, |
708 | 840k | u1_bit_depth_chroma, |
709 | 840k | ps_sps->i1_chroma_format_idc); |
710 | 840k | } |
711 | 3.75M | } |
712 | 77.6M | else |
713 | 77.6M | { |
714 | 77.6M | if(PIXEL_SIZE_1BYTE == ps_codec->i4_pixel_size_uv) |
715 | 29.1M | { |
716 | 29.1M | pf_deblk_chroma_vert(pu1_src, |
717 | 29.1M | chroma_strd, |
718 | 29.1M | qp_p, |
719 | 29.1M | qp_q, |
720 | 29.1M | ps_pps->i1_pic_cb_qp_offset, |
721 | 29.1M | ps_pps->i1_pic_cr_qp_offset, |
722 | 29.1M | i1_tc_offset_div2, |
723 | 29.1M | filter_p, |
724 | 29.1M | filter_q, |
725 | 29.1M | ps_sps->i1_chroma_format_idc); |
726 | 29.1M | } |
727 | 48.5M | else |
728 | 48.5M | { |
729 | 48.5M | pf_hbd_deblk_chroma_vert((UWORD16 *)pu1_src, |
730 | 48.5M | chroma_strd, |
731 | 48.5M | qp_p, |
732 | 48.5M | qp_q, |
733 | 48.5M | ps_pps->i1_pic_cb_qp_offset, |
734 | 48.5M | ps_pps->i1_pic_cr_qp_offset, |
735 | 48.5M | i1_tc_offset_div2, |
736 | 48.5M | filter_p, |
737 | 48.5M | filter_q, |
738 | 48.5M | u1_bit_depth_chroma, |
739 | 48.5M | ps_sps->i1_chroma_format_idc); |
740 | 48.5M | } |
741 | 77.6M | } |
742 | 81.4M | } |
743 | | |
744 | 82.5M | pu1_src += 4 * chroma_strd * pixel_size_uv; |
745 | 82.5M | u4_bs = u4_bs >> (2 * v_samp_factor); |
746 | 82.5M | row++; |
747 | 82.5M | } |
748 | | |
749 | 46.2M | pu1_src -= ((((src_strd * chroma_pixel_strd) / (h_samp_factor * v_samp_factor)) << log2_ctb_size) * pixel_size_uv); |
750 | 46.2M | if(is_yuv444) |
751 | 2.30M | { |
752 | 2.30M | if((64 ==ctb_size) || ((32 == ctb_size) && (col & 1))) pu4_vert_bs++; |
753 | 2.30M | } |
754 | 43.9M | else |
755 | 43.9M | { |
756 | 43.9M | pu4_vert_bs += (64 == ctb_size) ? 2 : 1; |
757 | 43.9M | } |
758 | 46.2M | pu1_src += 16 * pixel_size_uv; |
759 | 46.2M | } |
760 | 22.6M | } |
761 | | |
762 | | /* Chroma Horizontal Edge */ |
763 | | |
764 | 23.2M | if(CHROMA_FMT_IDC_MONOCHROME != ps_sps->i1_chroma_format_idc && 0 == i4_is_last_ctb_y) |
765 | 22.6M | { |
766 | | |
767 | | /* Left CTB's slice header */ |
768 | 22.6M | slice_header_t *ps_slice_hdr_left; |
769 | 22.6M | { |
770 | 22.6M | WORD32 cur_ctb_indx = ps_deblk->i4_ctb_x + ps_deblk->i4_ctb_y * ps_sps->i2_pic_wd_in_ctb; |
771 | 22.6M | if(i4_is_last_ctb_x) |
772 | 293k | cur_ctb_indx += 1; |
773 | 22.6M | ps_slice_hdr_left = ps_codec->ps_slice_hdr_base + ps_deblk->pu1_slice_idx[cur_ctb_indx - 1]; |
774 | 22.6M | } |
775 | | |
776 | 22.6M | pu1_src = ps_deblk->pu1_cur_pic_chroma + |
777 | 22.6M | ((((ps_deblk->i4_ctb_x * chroma_pixel_strd / h_samp_factor) + |
778 | 22.6M | ps_deblk->i4_ctb_y * ps_deblk->ps_codec->i4_strd * chroma_pixel_strd / (v_samp_factor * h_samp_factor)) << log2_ctb_size) * pixel_size_uv); |
779 | 22.6M | pu1_src += i4_is_last_ctb_x ? (ctb_size * chroma_pixel_strd / h_samp_factor * pixel_size_uv) : 0; |
780 | | |
781 | | /** Deblocking is done on a shifted CTB - |
782 | | * Vertical edge processing is done by shifting the CTB up by four pixels (8 here beacuse UV are interleaved) */ |
783 | 22.6M | pu1_src -= 8 * pixel_size_uv; |
784 | 74.7M | for(row = 0; row < ctb_size / (8 * v_samp_factor); row++) |
785 | 52.0M | { |
786 | 52.0M | WORD32 shift = 0; |
787 | | |
788 | 52.0M | if((is_yuv444 || is_yuv422) && 6 != log2_ctb_size) |
789 | 712k | shift = (row & 1) << (log2_ctb_size - 1); |
790 | | |
791 | | /* BS for the row - Last column is excluded and the left column is included*/ |
792 | 52.0M | u4_bs = (pu4_horz_bs[0] >> shift) << 2; |
793 | | |
794 | 52.0M | if(ps_deblk->i4_ctb_x || i4_is_last_ctb_x) |
795 | 49.1M | { |
796 | | /** Picking the last BS of the previous CTB corresponding to the same row |
797 | | * UWORD32 *pu4_horz_bs_left = (UWORD32 *)((UWORD8 *)pu4_horz_bs - (ctb_size / 8) * (ctb_size / 4) / 8 * 2); |
798 | | */ |
799 | 49.1M | UWORD32 *pu4_horz_bs_left = (UWORD32 *)((UWORD8 *)pu4_horz_bs - (1 << (2 * log2_ctb_size - 7))); |
800 | 49.1M | UWORD32 u4_left_bs = (*pu4_horz_bs_left) >> (shift + (1 << (log2_ctb_size - 1)) - 2); |
801 | 49.1M | u4_bs |= u4_left_bs & 3; |
802 | 49.1M | } |
803 | | |
804 | 52.0M | if(ps_sps->i1_chroma_format_idc == CHROMA_FMT_IDC_YUV420 || ps_sps->i1_chroma_format_idc == CHROMA_FMT_IDC_YUV422) { |
805 | | /* Every alternate boundary strength value is used for chroma */ |
806 | 49.3M | u4_bs &= 0x22222222; |
807 | 49.3M | } else if(ps_sps->i1_chroma_format_idc == CHROMA_FMT_IDC_YUV444) { |
808 | | /* Every boundary strength value is used for chroma */ |
809 | 2.67M | u4_bs &= 0xAAAAAAAA; |
810 | 2.67M | } |
811 | | |
812 | 186M | for(col = 0; col < ctb_size / (4 * h_samp_factor);) |
813 | 134M | { |
814 | 134M | WORD8 i1_tc_offset_div2 = ps_slice_hdr->i1_tc_offset_div2; |
815 | | |
816 | 134M | bs_tz = CTZ(u4_bs) >> h_samp_factor; |
817 | 134M | if(0 != bs_tz) |
818 | 59.4M | { |
819 | 59.4M | u4_bs = u4_bs >> (bs_tz << h_samp_factor); |
820 | | |
821 | 59.4M | if((col + bs_tz) >= (ctb_size / (4 * h_samp_factor))) |
822 | 40.3M | pu1_src += 8 * (ctb_size / (4 * h_samp_factor) - col) * pixel_size_uv; |
823 | 19.0M | else |
824 | 19.0M | pu1_src += 8 * bs_tz * pixel_size_uv; |
825 | | |
826 | 59.4M | col += bs_tz; |
827 | 59.4M | continue; |
828 | 59.4M | } |
829 | | |
830 | 74.7M | if(0 == col) |
831 | 11.7M | { |
832 | 11.7M | i1_tc_offset_div2 = ps_slice_hdr_left->i1_tc_offset_div2; |
833 | | |
834 | 11.7M | if(0 == row) |
835 | 4.39M | { |
836 | 4.39M | qp_p = u4_qp_const_in_ctb[0] ? |
837 | 4.28M | pi1_qp[-ctb_size / 8 * qp_strd - ctb_size / 8] : |
838 | 4.39M | pi1_qp[-qp_strd - 1]; |
839 | 4.39M | } |
840 | 7.33M | else |
841 | 7.33M | { |
842 | 7.33M | qp_p = u4_qp_const_in_ctb[2] ? |
843 | 7.15M | pi1_qp[-ctb_size / 8] : |
844 | 7.33M | pi1_qp[(v_samp_factor * row - 1) * qp_strd - 1]; |
845 | 7.33M | } |
846 | | |
847 | 11.7M | qp_q = u4_qp_const_in_ctb[2] ? |
848 | 11.3M | pi1_qp[-ctb_size / 8] : |
849 | 11.7M | pi1_qp[(v_samp_factor * row) * qp_strd - 1]; |
850 | 11.7M | } |
851 | 63.0M | else |
852 | 63.0M | { |
853 | 63.0M | if(0 == row) |
854 | 17.4M | { |
855 | 17.4M | qp_p = u4_qp_const_in_ctb[1] ? |
856 | 16.7M | pi1_qp[-ctb_size / 8 * qp_strd] : |
857 | 17.4M | pi1_qp[((col - 1) >> (2 - h_samp_factor)) - qp_strd]; |
858 | 17.4M | } |
859 | 45.5M | else |
860 | 45.5M | { |
861 | 45.5M | qp_p = u4_qp_const_in_ctb[3] ? |
862 | 46.6M | pi1_qp[0] : |
863 | 18.4E | pi1_qp[((col - 1) >> (2 - h_samp_factor)) + (v_samp_factor * row - 1) * qp_strd]; |
864 | 45.5M | } |
865 | | |
866 | 63.0M | qp_q = u4_qp_const_in_ctb[3] ? |
867 | 62.1M | pi1_qp[0] : |
868 | 63.0M | pi1_qp[((col - 1) >> (2 - h_samp_factor)) + v_samp_factor * row * qp_strd]; |
869 | 63.0M | } |
870 | 74.7M | filter_p = (pu2_ctb_no_loop_filter_flag[row * v_samp_factor] >> ((col + 2 - h_samp_factor) >> (2 - h_samp_factor))) & 1; |
871 | 74.7M | filter_q = (pu2_ctb_no_loop_filter_flag[(row * v_samp_factor) + 1] >> ((col + 2 - h_samp_factor) >> (2 - h_samp_factor))) & 1; |
872 | | /* filter_p and filter_q are inverted as they are calculated using no_loop_filter_flags */ |
873 | 74.7M | filter_p = !filter_p; |
874 | 74.7M | filter_q = !filter_q; |
875 | | |
876 | 74.7M | if(filter_p || filter_q) |
877 | 74.3M | { |
878 | 74.3M | if(ps_sps->i1_chroma_format_idc == CHROMA_FMT_IDC_YUV420) { |
879 | 38.8M | ASSERT(1 == ((u4_bs & 3) >> 1)); |
880 | 38.8M | } |
881 | 74.3M | DUMP_DEBLK_CHROMA_HORZ(pu1_src, chroma_strd, |
882 | 74.3M | u4_bs & 3, qp_p, qp_q, |
883 | 74.3M | ps_pps->i1_pic_cb_qp_offset, |
884 | 74.3M | ps_pps->i1_pic_cr_qp_offset, |
885 | 74.3M | ps_slice_hdr->i1_tc_offset_div2, |
886 | 74.3M | filter_p, filter_q); |
887 | 74.3M | if(chroma_yuv420sp_vu) |
888 | 3.77M | { |
889 | 3.77M | if(PIXEL_SIZE_1BYTE == ps_codec->i4_pixel_size_uv) |
890 | 2.88M | { |
891 | 2.88M | pf_deblk_chroma_horz(pu1_src, |
892 | 2.88M | chroma_strd, |
893 | 2.88M | qp_q, |
894 | 2.88M | qp_p, |
895 | 2.88M | ps_pps->i1_pic_cr_qp_offset, |
896 | 2.88M | ps_pps->i1_pic_cb_qp_offset, |
897 | 2.88M | i1_tc_offset_div2, |
898 | 2.88M | filter_q, |
899 | 2.88M | filter_p, |
900 | 2.88M | ps_sps->i1_chroma_format_idc); |
901 | 2.88M | } |
902 | 883k | else |
903 | 883k | { |
904 | 883k | pf_hbd_deblk_chroma_horz((UWORD16 *)pu1_src, |
905 | 883k | chroma_strd, |
906 | 883k | qp_q, |
907 | 883k | qp_p, |
908 | 883k | ps_pps->i1_pic_cr_qp_offset, |
909 | 883k | ps_pps->i1_pic_cb_qp_offset, |
910 | 883k | i1_tc_offset_div2, |
911 | 883k | filter_q, |
912 | 883k | filter_p, |
913 | 883k | u1_bit_depth_chroma, |
914 | 883k | ps_sps->i1_chroma_format_idc); |
915 | 883k | } |
916 | 3.77M | } |
917 | 70.6M | else |
918 | 70.6M | { |
919 | 70.6M | if(PIXEL_SIZE_1BYTE == ps_codec->i4_pixel_size_uv) |
920 | 28.4M | { |
921 | 28.4M | pf_deblk_chroma_horz(pu1_src, |
922 | 28.4M | chroma_strd, |
923 | 28.4M | qp_p, |
924 | 28.4M | qp_q, |
925 | 28.4M | ps_pps->i1_pic_cb_qp_offset, |
926 | 28.4M | ps_pps->i1_pic_cr_qp_offset, |
927 | 28.4M | i1_tc_offset_div2, |
928 | 28.4M | filter_p, |
929 | 28.4M | filter_q, |
930 | 28.4M | ps_sps->i1_chroma_format_idc); |
931 | 28.4M | } |
932 | 42.1M | else |
933 | 42.1M | { |
934 | 42.1M | pf_hbd_deblk_chroma_horz((UWORD16 *)pu1_src, |
935 | 42.1M | chroma_strd, |
936 | 42.1M | qp_p, |
937 | 42.1M | qp_q, |
938 | 42.1M | ps_pps->i1_pic_cb_qp_offset, |
939 | 42.1M | ps_pps->i1_pic_cr_qp_offset, |
940 | 42.1M | i1_tc_offset_div2, |
941 | 42.1M | filter_p, |
942 | 42.1M | filter_q, |
943 | 42.1M | u1_bit_depth_chroma, |
944 | 42.1M | ps_sps->i1_chroma_format_idc); |
945 | 42.1M | } |
946 | 70.6M | } |
947 | 74.3M | } |
948 | | |
949 | 74.7M | pu1_src += 8 * pixel_size_uv; |
950 | 74.7M | u4_bs = u4_bs >> (2 * h_samp_factor); |
951 | 74.7M | col++; |
952 | 74.7M | } |
953 | 52.0M | if(is_yuv444 || is_yuv422) |
954 | 12.8M | { |
955 | 12.8M | if((64 == ctb_size) || ((32 == ctb_size) && (row & 1))) pu4_horz_bs++; |
956 | 12.8M | } |
957 | 39.1M | else |
958 | 39.1M | { |
959 | 39.1M | pu4_horz_bs += (64 == ctb_size) ? 2 : 1; |
960 | 39.1M | } |
961 | 52.0M | pu1_src -= ctb_size * (chroma_pixel_strd / h_samp_factor) * pixel_size_uv; |
962 | 52.0M | pu1_src += 8 * chroma_strd * pixel_size_uv; |
963 | | |
964 | 52.0M | } |
965 | 22.6M | } |
966 | 23.2M | } |