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 ******************************************************************************
23 * \file ihevce_enc_subpel_gen.c
24 *
25 * \brief
26 * This file contains Padding and Subpel plane generation functions
27 * at CTB level
28 *
29 * \date
30 * 29/12/2012
31 *
32 * \author
33 * Ittiam
34 *
35 *
36 * List of Functions
37 * - ihevce_suppel_padding()
38 * - ihevce_pad_interp_recon_ctb()
39 *
40 *
41 ******************************************************************************
42 */
43
44 /*****************************************************************************/
45 /* File Includes */
46 /*****************************************************************************/
47 /* System include files */
48 #include <stdio.h>
49 #include <string.h>
50 #include <stdlib.h>
51 #include <assert.h>
52 #include <stdarg.h>
53 #include <math.h>
54
55 /* User include files */
56 #include "ihevc_typedefs.h"
57 #include "itt_video_api.h"
58 #include "ihevce_api.h"
59
60 #include "rc_cntrl_param.h"
61 #include "rc_frame_info_collector.h"
62 #include "rc_look_ahead_params.h"
63
64 #include "ihevc_defs.h"
65 #include "ihevc_debug.h"
66 #include "ihevc_macros.h"
67 #include "ihevc_structs.h"
68 #include "ihevc_platform_macros.h"
69 #include "ihevc_deblk.h"
70 #include "ihevc_itrans_recon.h"
71 #include "ihevc_chroma_itrans_recon.h"
72 #include "ihevc_chroma_intra_pred.h"
73 #include "ihevc_intra_pred.h"
74 #include "ihevc_inter_pred.h"
75 #include "ihevc_mem_fns.h"
76 #include "ihevc_padding.h"
77 #include "ihevc_weighted_pred.h"
78 #include "ihevc_sao.h"
79 #include "ihevc_resi_trans.h"
80 #include "ihevc_quant_iquant_ssd.h"
81 #include "ihevc_cabac_tables.h"
82 #include "ihevc_trans_tables.h"
83 #include "ihevc_trans_macros.h"
84
85 #include "ihevce_defs.h"
86 #include "ihevce_lap_enc_structs.h"
87 #include "ihevce_multi_thrd_structs.h"
88 #include "ihevce_multi_thrd_funcs.h"
89 #include "ihevce_me_common_defs.h"
90 #include "ihevce_had_satd.h"
91 #include "ihevce_error_codes.h"
92 #include "ihevce_bitstream.h"
93 #include "ihevce_cabac.h"
94 #include "ihevce_rdoq_macros.h"
95 #include "ihevce_function_selector.h"
96 #include "ihevce_enc_structs.h"
97 #include "ihevce_global_tables.h"
98 #include "ihevce_cmn_utils_instr_set_router.h"
99 #include "ihevce_entropy_structs.h"
100 #include "ihevce_enc_loop_structs.h"
101 #include "ihevce_enc_loop_utils.h"
102 #include "ihevce_inter_pred.h"
103 #include "ihevce_common_utils.h"
104
105 /*!
106 ******************************************************************************
107 * \if Function name : ihevce_suppel_padding \endif
108 *
109 * \brief
110 * Subpel Plane planes Padding Function
111 *
112 * \param[in] pu1_dst : pointer to subpel plane
113 * stride : subpel plane stride same as recon stride
114 * tot_wd : width of the block in subpel plane
115 * tot_ht : hieght of the block in subpel plane
116 * ctb_ctr : ctb horizontal position
117 * vert_ctr : ctb vertical position
118 * ps_frm_ctb_prms : CTB characteristics parameters
119 * \return
120 * None
121 *
122 *
123 * \author
124 * Ittiam
125 *
126 *****************************************************************************
127 */
ihevce_subpel_padding(UWORD8 * pu1_dst,WORD32 stride,WORD32 tot_wd,WORD32 tot_ht,WORD32 pad_subpel_x,WORD32 pad_subpel_y,WORD32 ctb_ctr,WORD32 vert_ctr,WORD32 i4_num_ctbs_horz,WORD32 i4_num_ctbs_vert,func_selector_t * ps_func_selector)128 void ihevce_subpel_padding(
129 UWORD8 *pu1_dst,
130 WORD32 stride,
131 WORD32 tot_wd,
132 WORD32 tot_ht,
133 WORD32 pad_subpel_x,
134 WORD32 pad_subpel_y,
135 WORD32 ctb_ctr,
136 WORD32 vert_ctr,
137 WORD32 i4_num_ctbs_horz,
138 WORD32 i4_num_ctbs_vert,
139 func_selector_t *ps_func_selector)
140 {
141 ihevc_pad_top_ft *pf_pad_top = ps_func_selector->ihevc_pad_top_fptr;
142 ihevc_pad_bottom_ft *pf_pad_bottom = ps_func_selector->ihevc_pad_bottom_fptr;
143 ihevc_pad_left_luma_ft *pf_pad_left_luma = ps_func_selector->ihevc_pad_left_luma_fptr;
144 ihevc_pad_right_luma_ft *pf_pad_right_luma = ps_func_selector->ihevc_pad_right_luma_fptr;
145
146 UWORD8 *pu1_dst_tmp = pu1_dst;
147 WORD32 cpy_ht = tot_ht;
148
149 /* Top padding*/
150 if(vert_ctr == 0)
151 {
152 PAD_BUF_VER(pu1_dst, stride, tot_wd, pad_subpel_x, pad_subpel_y, pf_pad_top);
153 /*if curr ctb is 1st ctb in ctb row, update dst pointer for Left padding*/
154 pu1_dst_tmp = pu1_dst - pad_subpel_y * stride;
155 cpy_ht += pad_subpel_y;
156 }
157 /*bottom padding*/
158 if(vert_ctr == (i4_num_ctbs_vert - 1))
159 {
160 PAD_BUF_VER(
161 (pu1_dst + (tot_ht * stride)),
162 stride,
163 tot_wd,
164 pad_subpel_x,
165 pad_subpel_y,
166 pf_pad_bottom);
167 /*if curr ctb is 1st ctb in ctb row, update dst pointer for right padding*/
168 cpy_ht += pad_subpel_y;
169 }
170
171 /*left padding*/
172 if(ctb_ctr == 0)
173 {
174 PAD_BUF_HOR(pu1_dst_tmp, stride, cpy_ht, pad_subpel_x, pad_subpel_y, pf_pad_left_luma);
175 }
176
177 /*right padding*/
178 if(ctb_ctr == (i4_num_ctbs_horz - 1))
179 {
180 PAD_BUF_HOR(
181 pu1_dst_tmp + tot_wd, stride, cpy_ht, pad_subpel_x, pad_subpel_y, pf_pad_right_luma);
182 }
183 }
184
185 /*!
186 ******************************************************************************
187 * \if Function name : ihevce_pad_interp_recon_ctb \endif
188 *
189 * \brief
190 * Ctb level Subpel Plane generation and padding function
191 *
192 * \param[in]
193 * s_cu_prms : coding unit params structures (recon buffers)
194 * ctb_ctr : ctb horizontal position
195 * vert_ctr : ctb vertical position
196 * ps_frm_ctb_prms : CTB characteristics parameters
197 * i4_dist_nbr_mask : nbr-mask for distributed mode. Should be 0 for standalone
198 * or distributed-single-client mode
199 *
200 * \return
201 * None
202 *
203 * \author
204 * Ittiam
205 *
206 *****************************************************************************
207 */
ihevce_pad_interp_recon_ctb(pad_interp_recon_frm_t * ps_pad_interp_recon,WORD32 ctb_ctr,WORD32 vert_ctr,WORD32 quality_preset,frm_ctb_ctxt_t * ps_frm_ctb_prms,WORD16 * pi2_hxhy_interm,WORD32 i4_bitrate_instance_id,func_selector_t * ps_func_selector)208 void ihevce_pad_interp_recon_ctb(
209 pad_interp_recon_frm_t *ps_pad_interp_recon,
210 WORD32 ctb_ctr,
211 WORD32 vert_ctr,
212 WORD32 quality_preset,
213 frm_ctb_ctxt_t *ps_frm_ctb_prms,
214 WORD16 *pi2_hxhy_interm,
215 WORD32 i4_bitrate_instance_id,
216 func_selector_t *ps_func_selector)
217 {
218 UWORD8 *pu1_src, *pu1_src_uv;
219 WORD32 stride, stride_uv, wd, ht, wd_uv, ht_uv, pad_x, pad_y, pad_subpel_x, pad_subpel_y;
220 WORD32 tot_wd, tot_ht, offset, cpy_ht_y, cpy_ht_uv;
221 WORD32 i4_chroma_vert_pad_default;
222
223 WORD32 ctb_size = ps_frm_ctb_prms->i4_ctb_size;
224 UWORD8 *pu1_dst_hxfy = ps_pad_interp_recon->pu1_sbpel_hxfy +
225 (vert_ctr * ctb_size * ps_pad_interp_recon->i4_luma_recon_stride) +
226 (ctb_ctr * ctb_size);
227 UWORD8 *pu1_dst_fxhy = ps_pad_interp_recon->pu1_sbpel_fxhy +
228 (vert_ctr * ctb_size * ps_pad_interp_recon->i4_luma_recon_stride) +
229 (ctb_ctr * ctb_size);
230 UWORD8 *pu1_dst_hxhy = ps_pad_interp_recon->pu1_sbpel_hxhy +
231 (vert_ctr * ctb_size * ps_pad_interp_recon->i4_luma_recon_stride) +
232 (ctb_ctr * ctb_size);
233 UWORD8 u1_is_422 = (ps_pad_interp_recon->u1_chroma_array_type == 2);
234
235 ihevc_inter_pred_ft *pf_inter_pred_luma_horz =
236 ps_func_selector->ihevc_inter_pred_luma_horz_fptr;
237 ihevc_inter_pred_ft *pf_inter_pred_luma_vert =
238 ps_func_selector->ihevc_inter_pred_luma_vert_fptr;
239 ihevc_inter_pred_w16out_ft *pf_inter_pred_luma_horz_w16out =
240 ps_func_selector->ihevc_inter_pred_luma_horz_w16out_fptr;
241 ihevc_inter_pred_w16inp_ft *pf_inter_pred_luma_vert_w16inp =
242 ps_func_selector->ihevc_inter_pred_luma_vert_w16inp_fptr;
243 stride = ps_pad_interp_recon->i4_luma_recon_stride;
244 wd = ps_pad_interp_recon->i4_ctb_size;
245 ht = ps_pad_interp_recon->i4_ctb_size;
246
247 pu1_src = (UWORD8 *)ps_pad_interp_recon->pu1_luma_recon + (vert_ctr * ctb_size * stride) +
248 (ctb_ctr * ctb_size);
249
250 stride_uv = ps_pad_interp_recon->i4_chrm_recon_stride;
251 wd_uv = ps_pad_interp_recon->i4_ctb_size;
252 ht_uv = ps_pad_interp_recon->i4_ctb_size >> (0 == u1_is_422);
253
254 pu1_src_uv = (UWORD8 *)ps_pad_interp_recon->pu1_chrm_recon +
255 (vert_ctr * (ctb_size >> (0 == u1_is_422)) * stride_uv) + (ctb_ctr * ctb_size);
256
257 pad_x = ALIGN8(NTAPS_LUMA);
258 pad_y = ALIGN8(NTAPS_LUMA);
259 pad_subpel_x = PAD_HORZ - pad_x;
260 pad_subpel_y = PAD_VERT - pad_y;
261
262 offset = pad_x + (pad_y * stride);
263
264 tot_wd = wd + (pad_x << 1);
265 tot_ht = ht + (pad_y << 1);
266
267 i4_chroma_vert_pad_default = PAD_VERT >> (0 == u1_is_422);
268
269 if(ctb_ctr == (ps_frm_ctb_prms->i4_num_ctbs_horz - 1))
270 {
271 WORD32 last_ctb_x =
272 ps_frm_ctb_prms->i4_cu_aligned_pic_wd -
273 ((ps_frm_ctb_prms->i4_num_ctbs_horz - 1) * ps_pad_interp_recon->i4_ctb_size);
274 wd = last_ctb_x;
275 wd_uv = last_ctb_x;
276 }
277 if(vert_ctr == (ps_frm_ctb_prms->i4_num_ctbs_vert - 1))
278 {
279 WORD32 last_ctb_y =
280 ps_frm_ctb_prms->i4_cu_aligned_pic_ht -
281 ((ps_frm_ctb_prms->i4_num_ctbs_vert - 1) * ps_pad_interp_recon->i4_ctb_size);
282 ht = last_ctb_y;
283 ht_uv = last_ctb_y >> (0 == u1_is_422);
284 }
285 tot_ht = ht;
286 tot_wd = wd;
287
288 /*top padding*/
289 if(vert_ctr == 0)
290 {
291 tot_ht = pad_y + ht - 8;
292 }
293 /*bottom padding*/
294 if(vert_ctr == (ps_frm_ctb_prms->i4_num_ctbs_vert - 1))
295 {
296 tot_ht = pad_y + ht + 8;
297 }
298
299 /*Left padding*/
300 if(ctb_ctr == 0)
301 {
302 tot_wd = pad_x + wd - 8;
303 }
304 /*right padding*/
305 if(ctb_ctr == (ps_frm_ctb_prms->i4_num_ctbs_horz - 1))
306 {
307 tot_wd = pad_x + wd + 8;
308 }
309
310 pu1_src -= offset;
311 pu1_dst_hxhy -= offset;
312 pu1_dst_hxfy -= offset;
313 pu1_dst_fxhy -= offset;
314
315 {
316 tot_wd = ALIGN16(tot_wd);
317 if(0 ==
318 i4_bitrate_instance_id) //do the following subpel calculations for reference bit-rate instance only
319 {
320 /* HxFY plane */
321 pf_inter_pred_luma_horz(
322 pu1_src,
323 pu1_dst_hxfy,
324 stride,
325 stride,
326 (WORD8 *)gai1_hevc_luma_filter_taps[2],
327 tot_ht,
328 tot_wd);
329
330 pf_inter_pred_luma_vert(
331 pu1_src,
332 pu1_dst_fxhy,
333 stride,
334 stride,
335 (WORD8 *)gai1_hevc_luma_filter_taps[2],
336 tot_ht,
337 tot_wd);
338
339 pf_inter_pred_luma_horz_w16out(
340 pu1_src - 3 * stride,
341 pi2_hxhy_interm,
342 stride,
343 tot_wd,
344 (WORD8 *)gai1_hevc_luma_filter_taps[2],
345 (tot_ht + 7),
346 tot_wd);
347
348 /* "Stride" of intermediate buffer in pixels,equals tot_wd */
349 pf_inter_pred_luma_vert_w16inp(
350 pi2_hxhy_interm + (3 * tot_wd),
351 pu1_dst_hxhy,
352 tot_wd,
353 stride,
354 (WORD8 *)gai1_hevc_luma_filter_taps[2],
355 tot_ht,
356 tot_wd);
357
358 ihevce_subpel_padding(
359 pu1_dst_fxhy,
360 stride,
361 tot_wd,
362 tot_ht,
363 pad_subpel_x,
364 pad_subpel_y,
365 ctb_ctr,
366 vert_ctr,
367 ps_frm_ctb_prms->i4_num_ctbs_horz,
368 ps_frm_ctb_prms->i4_num_ctbs_vert,
369 ps_func_selector);
370
371 ihevce_subpel_padding(
372 pu1_dst_hxfy,
373 stride,
374 tot_wd,
375 tot_ht,
376 pad_subpel_x,
377 pad_subpel_y,
378 ctb_ctr,
379 vert_ctr,
380 ps_frm_ctb_prms->i4_num_ctbs_horz,
381 ps_frm_ctb_prms->i4_num_ctbs_vert,
382 ps_func_selector);
383
384 ihevce_subpel_padding(
385 pu1_dst_hxhy,
386 stride,
387 tot_wd,
388 tot_ht,
389 pad_subpel_x,
390 pad_subpel_y,
391 ctb_ctr,
392 vert_ctr,
393 ps_frm_ctb_prms->i4_num_ctbs_horz,
394 ps_frm_ctb_prms->i4_num_ctbs_vert,
395 ps_func_selector);
396 }
397 }
398 }
399
ihevce_recon_padding(pad_interp_recon_frm_t * ps_pad_interp_recon,WORD32 ctb_ctr,WORD32 vert_ctr,frm_ctb_ctxt_t * ps_frm_ctb_prms,func_selector_t * ps_func_selector)400 void ihevce_recon_padding(
401 pad_interp_recon_frm_t *ps_pad_interp_recon,
402 WORD32 ctb_ctr,
403 WORD32 vert_ctr,
404 frm_ctb_ctxt_t *ps_frm_ctb_prms,
405 func_selector_t *ps_func_selector)
406 {
407 UWORD8 *pu1_src, *pu1_src_uv, *pu1_buf_y, *pu1_buf_uv;
408 WORD32 stride, stride_uv, wd, ht, wd_uv, ht_uv;
409 WORD32 cpy_ht_y, cpy_ht_uv;
410 WORD32 i4_chroma_vert_pad_default;
411
412 WORD32 top_extra_pix = 0, left_extra_pix = 0;
413 WORD32 ctb_size = ps_frm_ctb_prms->i4_ctb_size;
414 UWORD8 u1_is_422 = (ps_pad_interp_recon->u1_chroma_array_type == 2);
415
416 ihevc_pad_top_ft *pf_pad_top = ps_func_selector->ihevc_pad_top_fptr;
417 ihevc_pad_bottom_ft *pf_pad_bottom = ps_func_selector->ihevc_pad_bottom_fptr;
418 ihevc_pad_left_luma_ft *pf_pad_left_luma = ps_func_selector->ihevc_pad_left_luma_fptr;
419 ihevc_pad_left_chroma_ft *pf_pad_left_chroma = ps_func_selector->ihevc_pad_left_chroma_fptr;
420 ihevc_pad_right_luma_ft *pf_pad_right_luma = ps_func_selector->ihevc_pad_right_luma_fptr;
421 ihevc_pad_right_chroma_ft *pf_pad_right_chroma = ps_func_selector->ihevc_pad_right_chroma_fptr;
422
423 stride = ps_pad_interp_recon->i4_luma_recon_stride;
424 wd = ps_pad_interp_recon->i4_ctb_size;
425 ht = ps_pad_interp_recon->i4_ctb_size;
426
427 pu1_src = (UWORD8 *)ps_pad_interp_recon->pu1_luma_recon + (vert_ctr * ctb_size * stride) +
428 (ctb_ctr * ctb_size);
429
430 stride_uv = ps_pad_interp_recon->i4_chrm_recon_stride;
431 wd_uv = ps_pad_interp_recon->i4_ctb_size;
432 ht_uv = ps_pad_interp_recon->i4_ctb_size >> (0 == u1_is_422);
433
434 pu1_src_uv = (UWORD8 *)ps_pad_interp_recon->pu1_chrm_recon +
435 (vert_ctr * (ctb_size >> (0 == u1_is_422)) * stride_uv) + (ctb_ctr * ctb_size);
436
437 i4_chroma_vert_pad_default = PAD_VERT >> (0 == u1_is_422);
438
439 if(ctb_ctr == (ps_frm_ctb_prms->i4_num_ctbs_horz - 1))
440 {
441 WORD32 last_ctb_x =
442 ps_frm_ctb_prms->i4_cu_aligned_pic_wd -
443 ((ps_frm_ctb_prms->i4_num_ctbs_horz - 1) * ps_pad_interp_recon->i4_ctb_size);
444 wd = last_ctb_x;
445 wd_uv = last_ctb_x;
446 }
447 if(vert_ctr == (ps_frm_ctb_prms->i4_num_ctbs_vert - 1))
448 {
449 WORD32 last_ctb_y =
450 ps_frm_ctb_prms->i4_cu_aligned_pic_ht -
451 ((ps_frm_ctb_prms->i4_num_ctbs_vert - 1) * ps_pad_interp_recon->i4_ctb_size);
452 ht = last_ctb_y;
453 ht_uv = last_ctb_y >> (0 == u1_is_422);
454 }
455
456 pu1_buf_y = pu1_src;
457 pu1_buf_uv = pu1_src_uv;
458 cpy_ht_y = ht;
459 cpy_ht_uv = ht_uv;
460 if(vert_ctr > 0)
461 {
462 top_extra_pix = 8;
463 }
464 if(ctb_ctr > 0)
465 {
466 left_extra_pix = 8;
467 }
468
469 /*top padding*/
470 if(vert_ctr == 0)
471 {
472 PAD_BUF_VER(
473 pu1_src - left_extra_pix, stride, wd + left_extra_pix, PAD_HORZ, PAD_VERT, pf_pad_top);
474 PAD_BUF_VER(
475 pu1_src_uv - left_extra_pix,
476 stride_uv,
477 wd_uv + left_extra_pix,
478 PAD_HORZ,
479 i4_chroma_vert_pad_default,
480 pf_pad_top);
481 /*if curr ctb is 1st ctb in ctb row, update dst pointer for Left padding*/
482 pu1_buf_y = pu1_src - PAD_VERT * stride;
483 pu1_buf_uv = pu1_src_uv - i4_chroma_vert_pad_default * stride_uv;
484 cpy_ht_y += PAD_VERT;
485 cpy_ht_uv += i4_chroma_vert_pad_default;
486 }
487
488 /*bottom padding*/
489 if(vert_ctr == (ps_frm_ctb_prms->i4_num_ctbs_vert - 1))
490 {
491 PAD_BUF_VER(
492 ((pu1_src - left_extra_pix) + (ht * stride)),
493 stride,
494 wd + left_extra_pix,
495 PAD_HORZ,
496 PAD_VERT,
497 pf_pad_bottom);
498 PAD_BUF_VER(
499 ((pu1_src_uv - left_extra_pix) + (ht_uv * stride_uv)),
500 stride_uv,
501 wd_uv + left_extra_pix,
502 PAD_HORZ,
503 i4_chroma_vert_pad_default,
504 pf_pad_bottom);
505 /*if curr ctb is 1st ctb in ctb row, update dst pointer for right padding*/
506 cpy_ht_y += PAD_VERT;
507 cpy_ht_uv += i4_chroma_vert_pad_default;
508 }
509
510 /*Left padding*/
511 if(ctb_ctr == 0)
512 {
513 PAD_BUF_HOR(
514 (pu1_buf_y - top_extra_pix * stride),
515 stride,
516 cpy_ht_y + top_extra_pix,
517 PAD_HORZ,
518 PAD_VERT,
519 pf_pad_left_luma);
520 PAD_BUF_HOR(
521 pu1_buf_uv - (top_extra_pix >> 1) * (u1_is_422 + 1) * stride_uv,
522 stride_uv,
523 cpy_ht_uv + (top_extra_pix >> 1) * (u1_is_422 + 1),
524 PAD_HORZ,
525 i4_chroma_vert_pad_default,
526 pf_pad_left_chroma);
527 }
528
529 /*right padding*/
530 if(ctb_ctr == (ps_frm_ctb_prms->i4_num_ctbs_horz - 1))
531 {
532 PAD_BUF_HOR(
533 ((pu1_buf_y - (top_extra_pix * stride)) + wd),
534 stride,
535 cpy_ht_y + top_extra_pix,
536 PAD_HORZ,
537 PAD_VERT,
538 pf_pad_right_luma);
539 PAD_BUF_HOR(
540 ((pu1_buf_uv - ((top_extra_pix >> 1) * (u1_is_422 + 1) * stride_uv)) + wd_uv),
541 stride_uv,
542 cpy_ht_uv + (top_extra_pix >> 1) * (u1_is_422 + 1),
543 PAD_HORZ,
544 i4_chroma_vert_pad_default,
545 pf_pad_right_chroma);
546 }
547 }
548
ihevce_pad_interp_recon_src_ctb(pad_interp_recon_frm_t * ps_pad_interp_recon,WORD32 ctb_ctr,WORD32 vert_ctr,frm_ctb_ctxt_t * ps_frm_ctb_prms,WORD32 i4_bitrate_instance_id,func_selector_t * ps_func_selector,WORD32 is_chroma_needs_padding)549 void ihevce_pad_interp_recon_src_ctb(
550 pad_interp_recon_frm_t *ps_pad_interp_recon,
551 WORD32 ctb_ctr,
552 WORD32 vert_ctr,
553 frm_ctb_ctxt_t *ps_frm_ctb_prms,
554 WORD32 i4_bitrate_instance_id,
555 func_selector_t *ps_func_selector,
556 WORD32 is_chroma_needs_padding)
557 {
558 UWORD8 *pu1_src, *pu1_src_uv;
559 WORD32 stride, stride_uv, wd, ht, wd_uv, ht_uv, pad_x, pad_y;
560 WORD32 tot_wd, tot_ht;
561 WORD32 i4_chroma_vert_pad_default;
562
563 WORD32 ctb_size = ps_frm_ctb_prms->i4_ctb_size;
564 UWORD8 u1_is_422 = (ps_pad_interp_recon->u1_chroma_array_type == 2);
565
566 ihevc_pad_top_ft *pf_pad_top = ps_func_selector->ihevc_pad_top_fptr;
567 ihevc_pad_bottom_ft *pf_pad_bottom = ps_func_selector->ihevc_pad_bottom_fptr;
568 ihevc_pad_left_luma_ft *pf_pad_left_luma = ps_func_selector->ihevc_pad_left_luma_fptr;
569 ihevc_pad_left_chroma_ft *pf_pad_left_chroma = ps_func_selector->ihevc_pad_left_chroma_fptr;
570 ihevc_pad_right_luma_ft *pf_pad_right_luma = ps_func_selector->ihevc_pad_right_luma_fptr;
571 ihevc_pad_right_chroma_ft *pf_pad_right_chroma = ps_func_selector->ihevc_pad_right_chroma_fptr;
572
573 /* Luma padding */
574 pu1_src = (UWORD8 *)ps_pad_interp_recon->pu1_luma_recon_src +
575 (vert_ctr * ctb_size * ps_pad_interp_recon->i4_luma_recon_stride) +
576 (ctb_ctr * ctb_size);
577
578 stride = ps_pad_interp_recon->i4_luma_recon_stride;
579 wd = ps_pad_interp_recon->i4_ctb_size;
580 ht = ps_pad_interp_recon->i4_ctb_size;
581
582 pu1_src_uv =
583 (UWORD8 *)ps_pad_interp_recon->pu1_chrm_recon_src +
584 (vert_ctr * (ctb_size >> (0 == u1_is_422)) * ps_pad_interp_recon->i4_chrm_recon_stride) +
585 (ctb_ctr * ctb_size);
586
587 stride_uv = ps_pad_interp_recon->i4_chrm_recon_stride;
588 wd_uv = ps_pad_interp_recon->i4_ctb_size;
589 ht_uv = ps_pad_interp_recon->i4_ctb_size >> (0 == u1_is_422);
590
591 pad_x = ALIGN8(NTAPS_LUMA);
592 pad_y = ALIGN8(NTAPS_LUMA);
593
594 tot_wd = wd + (pad_x << 1);
595 tot_ht = ht + (pad_y << 1);
596
597 i4_chroma_vert_pad_default = PAD_VERT >> (0 == u1_is_422);
598
599 if(ctb_ctr == (ps_frm_ctb_prms->i4_num_ctbs_horz - 1))
600 {
601 WORD32 last_ctb_x =
602 ps_frm_ctb_prms->i4_cu_aligned_pic_wd -
603 ((ps_frm_ctb_prms->i4_num_ctbs_horz - 1) * ps_pad_interp_recon->i4_ctb_size);
604 wd = last_ctb_x;
605 wd_uv = last_ctb_x;
606 }
607 if(vert_ctr == (ps_frm_ctb_prms->i4_num_ctbs_vert - 1))
608 {
609 WORD32 last_ctb_y =
610 ps_frm_ctb_prms->i4_cu_aligned_pic_ht -
611 ((ps_frm_ctb_prms->i4_num_ctbs_vert - 1) * ps_pad_interp_recon->i4_ctb_size);
612 ht = last_ctb_y;
613 ht_uv = last_ctb_y >> (0 == u1_is_422);
614 }
615
616 if(ctb_ctr == 0)
617 {
618 if(vert_ctr == 0)
619 {
620 PAD_BUF_HOR(pu1_src, stride, ht, PAD_HORZ, PAD_VERT, pf_pad_left_luma);
621 PAD_BUF_VER(pu1_src - PAD_HORZ, stride, PAD_HORZ + wd, PAD_HORZ, PAD_VERT, pf_pad_top);
622 if(is_chroma_needs_padding)
623 {
624 PAD_BUF_HOR(
625 pu1_src_uv,
626 stride_uv,
627 ht_uv,
628 PAD_HORZ,
629 i4_chroma_vert_pad_default,
630 pf_pad_left_chroma);
631 PAD_BUF_VER(
632 pu1_src_uv - PAD_HORZ,
633 stride_uv,
634 PAD_HORZ + wd_uv,
635 PAD_HORZ,
636 i4_chroma_vert_pad_default,
637 pf_pad_top);
638 }
639 }
640 else if(vert_ctr == (ps_frm_ctb_prms->i4_num_ctbs_vert - 1))
641 {
642 PAD_BUF_HOR(pu1_src - 8 * stride, stride, ht + 8, PAD_HORZ, PAD_VERT, pf_pad_left_luma);
643 PAD_BUF_VER(
644 (pu1_src - PAD_HORZ + (ht * stride)),
645 stride,
646 PAD_HORZ + wd,
647 PAD_HORZ,
648 PAD_VERT,
649 pf_pad_bottom);
650 if(is_chroma_needs_padding)
651 {
652 PAD_BUF_HOR(
653 pu1_src_uv - 4 * (u1_is_422 + 1) * stride_uv,
654 stride_uv,
655 ht_uv + 4 * (u1_is_422 + 1),
656 PAD_HORZ,
657 i4_chroma_vert_pad_default,
658 pf_pad_left_chroma);
659 PAD_BUF_VER(
660 (pu1_src_uv - PAD_HORZ + (ht_uv * stride_uv)),
661 stride_uv,
662 PAD_HORZ + wd_uv,
663 PAD_HORZ,
664 i4_chroma_vert_pad_default,
665 pf_pad_bottom);
666 }
667 }
668 else
669 {
670 PAD_BUF_HOR(pu1_src - 8 * stride, stride, ht + 8, PAD_HORZ, PAD_VERT, pf_pad_left_luma);
671 if(is_chroma_needs_padding)
672 {
673 PAD_BUF_HOR(
674 pu1_src_uv - 4 * (u1_is_422 + 1) * stride_uv,
675 stride_uv,
676 ht_uv + 4 * (u1_is_422 + 1),
677 PAD_HORZ,
678 i4_chroma_vert_pad_default,
679 pf_pad_left_chroma);
680 }
681 }
682 }
683 else if(ctb_ctr == (ps_frm_ctb_prms->i4_num_ctbs_horz - 1))
684 {
685 if(vert_ctr == 0)
686 {
687 PAD_BUF_HOR(pu1_src + wd, stride, ht, PAD_HORZ, PAD_VERT, pf_pad_right_luma);
688 PAD_BUF_VER(pu1_src - 8, stride, PAD_HORZ + (wd + 8), PAD_HORZ, PAD_VERT, pf_pad_top);
689 if(is_chroma_needs_padding)
690 {
691 PAD_BUF_HOR(
692 pu1_src_uv + wd_uv,
693 stride_uv,
694 ht_uv,
695 PAD_HORZ,
696 i4_chroma_vert_pad_default,
697 pf_pad_right_chroma);
698 PAD_BUF_VER(
699 pu1_src_uv - 8,
700 stride_uv,
701 PAD_HORZ + (wd_uv + 8),
702 PAD_HORZ,
703 i4_chroma_vert_pad_default,
704 pf_pad_top);
705 }
706 }
707 else if(vert_ctr == (ps_frm_ctb_prms->i4_num_ctbs_vert - 1))
708 {
709 PAD_BUF_HOR(
710 (pu1_src - (8 * stride) + wd),
711 stride,
712 ht + 8,
713 PAD_HORZ,
714 PAD_VERT,
715 pf_pad_right_luma);
716 PAD_BUF_VER(
717 (pu1_src - 8 + (ht * stride)),
718 stride,
719 PAD_HORZ + (wd + 8),
720 PAD_HORZ,
721 PAD_VERT,
722 pf_pad_bottom);
723 if(is_chroma_needs_padding)
724 {
725 PAD_BUF_HOR(
726 (pu1_src_uv - (4 * (u1_is_422 + 1) * stride_uv) + wd_uv),
727 stride_uv,
728 ht_uv + 4 * (u1_is_422 + 1),
729 PAD_HORZ,
730 i4_chroma_vert_pad_default,
731 pf_pad_right_chroma);
732 PAD_BUF_VER(
733 (pu1_src_uv - 8 + (ht_uv * stride_uv)),
734 stride_uv,
735 PAD_HORZ + (wd_uv + 8),
736 PAD_HORZ,
737 i4_chroma_vert_pad_default,
738 pf_pad_bottom);
739 }
740 }
741 else
742 {
743 PAD_BUF_HOR(
744 (pu1_src - (8 * stride) + wd),
745 stride,
746 ht + 8,
747 PAD_HORZ,
748 PAD_VERT,
749 pf_pad_right_luma);
750 if(is_chroma_needs_padding)
751 {
752 PAD_BUF_HOR(
753 (pu1_src_uv - (4 * (u1_is_422 + 1) * stride_uv) + wd_uv),
754 stride_uv,
755 ht_uv + 4 * (u1_is_422 + 1),
756 PAD_HORZ,
757 i4_chroma_vert_pad_default,
758 pf_pad_right_chroma);
759 }
760 }
761 }
762 else if(vert_ctr == 0)
763 {
764 PAD_BUF_VER(pu1_src - 8, stride, (wd + 8), PAD_HORZ, PAD_VERT, pf_pad_top);
765 if(is_chroma_needs_padding)
766 {
767 PAD_BUF_VER(
768 pu1_src_uv - 8,
769 stride_uv,
770 (wd_uv + 8),
771 PAD_HORZ,
772 i4_chroma_vert_pad_default,
773 pf_pad_top);
774 }
775 }
776 else if(vert_ctr == (ps_frm_ctb_prms->i4_num_ctbs_vert - 1))
777 {
778 PAD_BUF_VER(
779 (pu1_src - 8 + (ht * stride)), stride, (wd + 8), PAD_HORZ, PAD_VERT, pf_pad_bottom);
780 if(is_chroma_needs_padding)
781 {
782 PAD_BUF_VER(
783 (pu1_src_uv - 8 + (ht_uv * stride_uv)),
784 stride_uv,
785 (wd_uv + 8),
786 PAD_HORZ,
787 i4_chroma_vert_pad_default,
788 pf_pad_bottom);
789 }
790 }
791 }
792