1 /******************************************************************************
2 *
3 * Copyright (C) 2022 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 * isvcd_resamp_svc.c
24 *
25 * @brief
26 * Contains routines that resample for SVC resampling
27 *
28 * @author
29 * Kishore
30 *
31 * @remarks
32 * None
33 *
34 *******************************************************************************
35 */
36
37 #include <assert.h>
38 #include <string.h>
39
40 #include "ih264_typedefs.h"
41 #include "ih264_macros.h"
42 #include "ih264_platform_macros.h"
43 #include "ih264d_bitstrm.h"
44 #include "ih264d_defs.h"
45 #include "ih264d_debug.h"
46 #include "ih264d_structs.h"
47 #include "ih264d_defs.h"
48 #include "ih264d_parse_cavlc.h"
49 #include "ih264d_mb_utils.h"
50 #include "ih264d_deblocking.h"
51 #include "ih264d_dpb_manager.h"
52 #include "ih264d_mvpred.h"
53 #include "ih264d_inter_pred.h"
54 #include "ih264d_process_pslice.h"
55 #include "ih264d_error_handler.h"
56 #include "ih264d_cabac.h"
57 #include "ih264d_debug.h"
58 #include "ih264d_tables.h"
59 #include "ih264d_parse_slice.h"
60 #include "ih264d_utils.h"
61 #include "ih264d_parse_islice.h"
62 #include "ih264d_process_bslice.h"
63 #include "ih264d_process_intra_mb.h"
64 #include "isvcd_resamp_svc.h"
65 #include "ih264_debug.h"
66
67 /*****************************************************************************/
68 /* */
69 /* Function Name : svcd_get_ceil_log2 */
70 /* */
71 /* Description : this function returns the CeilLog2 of the given number */
72 /* */
73 /* */
74 /* Inputs : i4_input : input number */
75 /* Globals : none */
76 /* Processing : it calculate the bits and returns it */
77 /* */
78 /* Outputs : none */
79 /* Returns : ceil of log to base 2 */
80 /* */
81 /* Issues : none */
82 /* */
83 /* Revision History: */
84 /* */
85 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
86 /* 05 04 2009 vijayakumar creation */
87 /* */
88 /*****************************************************************************/
svcd_get_ceil_log2(WORD32 i4_input)89 WORD32 svcd_get_ceil_log2(WORD32 i4_input)
90 {
91 WORD32 i4_bits = 0;
92
93 /* check for negative number */
94 ASSERT(i4_input >= 0);
95
96 i4_input--;
97 while(i4_input > 0)
98 {
99 i4_bits++;
100 i4_input >>= 1;
101 } /* endof while input > 0 loop */
102 return (i4_bits);
103 }
104
105 /*****************************************************************************/
106 /* */
107 /* Function Name : svcd_2d_memset */
108 /* */
109 /* Description : Function performs 2D memset operation */
110 /* */
111 /* */
112 /* Inputs : 1. Buffer pointer */
113 /* 2. width */
114 /* 3. Height */
115 /* 4. Stride */
116 /* 5. value */
117 /* Globals : None */
118 /* Processing : calls memset fucntion */
119 /* */
120 /* Outputs : Updates the buffer */
121 /* Returns : status */
122 /* */
123 /* Issues : None */
124 /* */
125 /* Revision History: */
126 /* */
127 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
128 /* 24 06 2009 Kishore Draft */
129 /* */
130 /*****************************************************************************/
svcd_2d_memset(void * pv_buf,WORD32 i4_width,WORD32 i4_ht,WORD32 i4_stride,WORD32 i4_val)131 void svcd_2d_memset(void *pv_buf, WORD32 i4_width, WORD32 i4_ht, WORD32 i4_stride, WORD32 i4_val)
132 {
133 WORD32 i4_y;
134 UWORD8 *pu1_buf;
135
136 pu1_buf = (UWORD8 *) pv_buf;
137
138 for(i4_y = 0; i4_y < i4_ht; i4_y++)
139 {
140 memset(pu1_buf, i4_val, i4_width);
141
142 /* Increment the pointer */
143 pu1_buf += i4_stride;
144 }
145 }
146
147 /*****************************************************************************/
148 /* */
149 /* Function Name : svcd_copy_data */
150 /* */
151 /* Description : this module copies the data from source to destination */
152 /* the amount of data to be copied is passed as input */
153 /* */
154 /* Inputs : pu1_src : pointer to the source buffer */
155 /* u2_src_stride : source buffer stride */
156 /* pu1_dst : pointer to the destination buffer */
157 /* u2_dst_stride : destination buffer stride */
158 /* u4_num_bytes : number of bytes to be copied */
159 /* u4_num_lines : number of lines to be copied */
160 /* Globals : none */
161 /* Processing : it does a memcpy from source to destination */
162 /* */
163 /* Outputs : none */
164 /* Returns : none */
165 /* Issues : both buffers are assumed to be 2-D buffers */
166 /* */
167 /* Revision History: */
168 /* */
169 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
170 /* 29 04 2009 vijayakumar creation */
171 /* */
172 /*****************************************************************************/
svcd_copy_data(UWORD8 * pu1_src,WORD32 i4_src_stride,UWORD8 * pu1_dst,WORD32 i4_dst_stride,WORD32 i4_num_bytes,WORD32 i4_num_lines)173 void svcd_copy_data(UWORD8 *pu1_src, WORD32 i4_src_stride, UWORD8 *pu1_dst, WORD32 i4_dst_stride,
174 WORD32 i4_num_bytes, WORD32 i4_num_lines)
175 {
176 WORD32 i4_vert_lines;
177
178 ASSERT(NULL != pu1_src);
179 ASSERT(NULL != pu1_dst);
180
181 /* loop for copy all the lines requried */
182 for(i4_vert_lines = 0; i4_vert_lines < i4_num_lines; i4_vert_lines++)
183 {
184 memcpy(pu1_dst, pu1_src, i4_num_bytes);
185 pu1_src += i4_src_stride;
186 pu1_dst += i4_dst_stride;
187 }
188 return;
189 }
190 /*****************************************************************************/
191 /* */
192 /* Function Name : svcd_copy_data_semiplanr */
193 /* */
194 /* Description : this module copies the data from source to destination */
195 /* the amount of data to be copied is passed as input */
196 /* */
197 /* Inputs : pu1_src : pointer to the source buffer */
198 /* i4_src_stride : source buffer stride */
199 /* pu1_dst1 : pointer to the destination buffer 1 */
200 /* pu1_dst2 : pointer to the destination buffer 2 */
201 /* i4_dst_stride : destination buffer stride */
202 /* i4_num_bytes : number of bytes to be copied */
203 /* i4_num_lines : number of lines to be copied */
204 /* Globals : none */
205 /* Processing : it does a memcpy from source to destination */
206 /* */
207 /* Outputs : none */
208 /* Returns : none */
209 /* Issues : both buffers are assumed to be 2-D buffers */
210 /* */
211 /* Revision History: */
212 /* */
213 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
214 /* 29 04 2009 vijayakumar creation */
215 /* */
216 /*****************************************************************************/
svcd_copy_data_semiplanr(UWORD8 * pu1_src,WORD32 i4_src_stride,UWORD8 * pu1_dst1,UWORD8 * pu1_dst2,WORD32 i4_dst_stride,WORD32 i4_num_bytes,WORD32 i4_num_lines)217 void svcd_copy_data_semiplanr(UWORD8 *pu1_src, WORD32 i4_src_stride, UWORD8 *pu1_dst1,
218 UWORD8 *pu1_dst2, WORD32 i4_dst_stride, WORD32 i4_num_bytes,
219 WORD32 i4_num_lines)
220 {
221 WORD32 i4_vert_lines, u4_i;
222
223 if(NULL == pu1_src) ||(NULL == pu1_dst1) ||(NULL == pu1_dst2)){return;}
224
225 /* loop for copy all the lines requried */
226 for(i4_vert_lines = 0; i4_vert_lines < i4_num_lines; i4_vert_lines++)
227 {
228 for(u4_i = 0; u4_i < i4_num_bytes; u4_i++)
229 {
230 *(pu1_dst1 + u4_i) = *(pu1_src + (2 * u4_i));
231 *(pu1_dst2 + u4_i) = *(pu1_src + (2 * u4_i) + 1);
232 }
233
234 pu1_src += i4_src_stride;
235 pu1_dst1 += i4_dst_stride;
236 pu1_dst2 += i4_dst_stride;
237 }
238 return;
239 }
240
241 /*****************************************************************************/
242 /* */
243 /* Function Name : svcd_get_ref_layer_avlblty_dyadic */
244 /* */
245 /* Description : This function is used to find the mb type of the */
246 /* corresponding MB in the reference layer for dyadic cases */
247 /* */
248 /* Inputs : pv_intra_samp_ctxt : intra samp context */
249 /* pi1_ref_mb_modes : ref mb modes buffer pointer */
250 /* i4_ref_mode_stride : mb mode buffer stride */
251 /* i4_ref_mb_x : reference MB location X */
252 /* i4_ref_mb_y : reference MB location Y */
253 /* pi4_mb_type : pointer to store the mb type */
254 /* i1_curr_slice_id : slice id of current MB */
255 /* i1_cons_intr_samp_flag :constrained intra resampling flag*/
256 /* Globals : none */
257 /* Processing : it derives the bit corresponding to reference MB and */
258 /* stores the mbtype as INTRA if the bit is set */
259 /* Outputs : none */
260 /* Returns : none */
261 /* */
262 /* Issues : none */
263 /* */
264 /* Revision History: */
265 /* */
266 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
267 /* 26 06 2009 vijayakumar creation */
268 /* */
269 /*****************************************************************************/
svcd_get_ref_layer_avlblty_dyadic(WORD8 * pi1_ref_mb_modes,WORD32 i4_ref_mode_stride,WORD32 i4_element_size,WORD32 i4_ref_mb_x,WORD32 i4_ref_mb_y,WORD32 * pi4_avlblty,WORD8 i1_curr_slice_id,WORD8 i1_cons_intr_samp_flag)270 void svcd_get_ref_layer_avlblty_dyadic(WORD8 *pi1_ref_mb_modes, WORD32 i4_ref_mode_stride,
271 WORD32 i4_element_size, WORD32 i4_ref_mb_x,
272 WORD32 i4_ref_mb_y, WORD32 *pi4_avlblty,
273 WORD8 i1_curr_slice_id, WORD8 i1_cons_intr_samp_flag)
274 {
275 inter_lyr_mb_prms_t *ps_inter_lyr_mb_prms;
276 WORD8 i1_mb_mode;
277
278 /* get the location of the byte which has the current mb mode */
279 pi1_ref_mb_modes += (i4_ref_mb_y * i4_ref_mode_stride * i4_element_size);
280 pi1_ref_mb_modes += (i4_ref_mb_x * i4_element_size);
281 ps_inter_lyr_mb_prms = (inter_lyr_mb_prms_t *) pi1_ref_mb_modes;
282 i1_mb_mode = ps_inter_lyr_mb_prms->i1_mb_mode;
283
284 if(0 > i1_mb_mode)
285 {
286 /* INTER */
287 *pi4_avlblty = 0;
288 }
289 else
290 {
291 /* INTRA */
292 *pi4_avlblty = 1;
293 }
294
295 /* if constrained intra flag is 1 then check for same slice id */
296 if(1 == i1_cons_intr_samp_flag)
297 {
298 if(1 == *pi4_avlblty)
299 {
300 /* check for different slice idc */
301 if(i1_mb_mode != i1_curr_slice_id)
302 {
303 /* store the mode as not available for upsampling */
304 *pi4_avlblty = 0;
305 }
306 }
307 }
308 }
309 /*****************************************************************************/
310 /* */
311 /* Function Name : svcd_diagonal_construct_dyadic */
312 /* */
313 /* Description : This function fills the unavaible pixels in the reference*/
314 /* array with diagonally constructed samples */
315 /* Inputs : i4_x :current position in reference array X to be filled */
316 /* i4_y :current position in reference array Y to be filled */
317 /* i4_xd_index : diagonal index in horizontal direction */
318 /* i4_yd_index : diagonal index in vertical direction */
319 /* pu1_refarray : popinter to reference array */
320 /* i4_refarray_wd: width of the reference array */
321 /* Globals : none */
322 /* Processing : Fills the sample which is unavailable with filtered */
323 /* diagonal samples */
324 /* Outputs : pixel filled */
325 /* Returns : constructed pixel */
326 /* */
327 /* Issues : none */
328 /* */
329 /* Revision History: */
330 /* */
331 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
332 /* 03 12 2010 Nithya creation */
333 /* */
334 /*****************************************************************************/
svcd_diagonal_construct_dyadic(WORD32 i4_x,WORD32 i4_y,WORD32 i4_xd_index,WORD32 i4_yd_index,UWORD8 * pu1_refarray,WORD32 i4_refarray_wd)335 UWORD8 svcd_diagonal_construct_dyadic(WORD32 i4_x, WORD32 i4_y, WORD32 i4_xd_index,
336 WORD32 i4_yd_index, UWORD8 *pu1_refarray,
337 WORD32 i4_refarray_wd)
338 {
339 WORD32 i4_diff_hor_ver, i4_sgn_xy;
340 WORD32 i4_xc, i4_yc;
341 WORD32 i4_samp1, i4_samp2, i4_samp3;
342 WORD32 i4_result;
343 UWORD8 *pu1_tmp;
344
345 i4_diff_hor_ver = ABS(i4_xd_index) - ABS(i4_yd_index);
346 i4_sgn_xy = SIGN(i4_xd_index * i4_yd_index);
347
348 if(i4_diff_hor_ver > 0)
349 {
350 i4_xc = i4_x - (i4_sgn_xy * i4_yd_index);
351 i4_yc = i4_y - i4_yd_index;
352
353 pu1_tmp = pu1_refarray + (i4_yc * i4_refarray_wd);
354
355 i4_samp1 = pu1_tmp[i4_xc - 1];
356 i4_samp2 = pu1_tmp[i4_xc];
357 i4_samp3 = pu1_tmp[i4_xc + 1];
358 }
359 else if(i4_diff_hor_ver < 0)
360 {
361 i4_xc = i4_x - i4_xd_index;
362 i4_yc = i4_y - (i4_sgn_xy * i4_xd_index);
363
364 pu1_tmp = pu1_refarray + ((i4_yc - 1) * i4_refarray_wd);
365
366 i4_samp1 = pu1_tmp[i4_xc];
367 pu1_tmp += i4_refarray_wd;
368 i4_samp2 = pu1_tmp[i4_xc];
369 pu1_tmp += i4_refarray_wd;
370 i4_samp3 = pu1_tmp[i4_xc];
371 }
372 else
373 {
374 WORD32 i4_ref_xd, i4_ref_yd;
375
376 i4_ref_xd = i4_x - i4_xd_index;
377 i4_ref_yd = i4_y - i4_yd_index;
378
379 i4_xc = i4_ref_xd + SIGN(i4_xd_index);
380 i4_yc = i4_ref_yd + SIGN(i4_yd_index);
381
382 pu1_tmp = pu1_refarray + (i4_ref_yd * i4_refarray_wd);
383
384 i4_samp1 = pu1_tmp[i4_xc];
385 i4_samp2 = pu1_tmp[i4_ref_xd];
386 pu1_tmp = pu1_refarray + (i4_yc * i4_refarray_wd);
387 i4_samp3 = pu1_tmp[i4_ref_xd];
388 }
389
390 i4_result = (i4_samp1 + (i4_samp2 << 1) + i4_samp3 + 2) >> 2;
391
392 pu1_tmp = pu1_refarray + (i4_y * i4_refarray_wd);
393 /* Store the filled sample */
394 pu1_tmp[i4_x] = i4_result;
395
396 return (i4_result);
397 }
398
399 /*****************************************************************************/
400 /* */
401 /* Function Name : svcd_corner_samp_dyadic */
402 /* */
403 /* Description : This function fills the corner sample in the reference */
404 /* array with diagonally constructed samples */
405 /* Inputs : i4_x :current position in reference array X to be filled */
406 /* i4_y :current position in reference array Y to be filled */
407 /* i4_xd_index : diagonal index in horizontal direction */
408 /* i4_yd_index : diagonal index in vertical direction */
409 /* pu1_refarray_y : pointer to luma reference array */
410 /* pu1_refarray_cb : pointer to Cb reference array */
411 /* pu1_refarray_cr : pointer to Cr reference array */
412 /* Globals : none */
413 /* Processing : Fills the sample which is unavailable with filtered */
414 /* diagonal samples */
415 /* Outputs : pixel filled */
416 /* Returns : none */
417 /* */
418 /* Issues : none */
419 /* */
420 /* Revision History: */
421 /* */
422 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
423 /* 03 12 2010 Nithya creation */
424 /* */
425 /*****************************************************************************/
svcd_corner_samp_dyadic(WORD32 i4_x,WORD32 i4_y,WORD32 i4_xD,WORD32 i4_yD,UWORD8 * pu1_refarray_y,UWORD8 * pu1_refarray_cb,UWORD8 * pu1_refarray_cr)426 void svcd_corner_samp_dyadic(WORD32 i4_x, WORD32 i4_y, WORD32 i4_xD, WORD32 i4_yD,
427 UWORD8 *pu1_refarray_y, UWORD8 *pu1_refarray_cb,
428 UWORD8 *pu1_refarray_cr)
429 {
430 WORD32 i4_ref_xD, i4_ref_yD;
431 WORD32 i4_c_ref_xD, i4_c_ref_yD;
432 WORD32 i4_xc, i4_yc;
433 WORD32 i4_c_xc, i4_c_yc;
434 WORD32 i4_samp1, i4_samp2;
435 UWORD8 *pu1_tmp_src, *pu1_tmp_dst;
436
437 i4_ref_xD = i4_x - i4_xD;
438 i4_ref_yD = i4_y - i4_yD;
439 i4_xc = i4_ref_xD + SIGN(i4_xD);
440 i4_yc = i4_ref_yD + SIGN(i4_yD);
441
442 /* Luma */
443 pu1_tmp_src = pu1_refarray_y + (i4_yc * DYADIC_REF_W_Y);
444 i4_samp1 = pu1_tmp_src[i4_ref_xD];
445 pu1_tmp_src = pu1_refarray_y + (i4_ref_yD * DYADIC_REF_W_Y);
446 i4_samp2 = pu1_tmp_src[i4_xc];
447 pu1_tmp_dst = pu1_tmp_src;
448
449 pu1_tmp_dst[i4_ref_xD] = (i4_samp1 + i4_samp2 + 1) >> 1;
450
451 /* Chroma */
452 i4_c_ref_xD = i4_ref_xD >> 1;
453 i4_c_ref_yD = i4_ref_yD >> 1;
454 i4_c_xc = i4_c_ref_xD + SIGN(i4_xD);
455 i4_c_yc = i4_c_ref_yD + SIGN(i4_yD);
456
457 /* Cb */
458 pu1_tmp_src = pu1_refarray_cb + (i4_c_yc * DYADIC_REF_W_C);
459 i4_samp1 = pu1_tmp_src[i4_c_ref_xD];
460 pu1_tmp_src = pu1_refarray_cb + (i4_c_ref_yD * DYADIC_REF_W_C);
461 i4_samp2 = pu1_tmp_src[i4_c_xc];
462 pu1_tmp_dst = pu1_tmp_src;
463
464 pu1_tmp_dst[i4_c_ref_xD] = (i4_samp1 + i4_samp2 + 1) >> 1;
465
466 /* Cr */
467 pu1_tmp_src = pu1_refarray_cr + (i4_c_yc * DYADIC_REF_W_C);
468 i4_samp1 = pu1_tmp_src[i4_c_ref_xD];
469 pu1_tmp_src = pu1_refarray_cr + (i4_c_ref_yD * DYADIC_REF_W_C);
470 i4_samp2 = pu1_tmp_src[i4_c_xc];
471 pu1_tmp_dst = pu1_tmp_src;
472 pu1_tmp_dst[i4_c_ref_xD] = (i4_samp1 + i4_samp2 + 1) >> 1;
473 }
474
475 /*****************************************************************************/
476 /* */
477 /* Function Name : svcd_reflayer_construction_dyadic */
478 /* */
479 /* Description : This function constructs the reference array buffer */
480 /* for dyadic cases used for intra resampling of a */
481 /* component in an MB */
482 /* */
483 /* Inputs : pv_intra_samp_ctxt : intra sampling context */
484 /* ps_ref_mb_mode_map : ref layer mb mode buffer desc */
485 /* pu1_inp_luma : luma input (reference layer data) */
486 /* pu1_inp_chroma : chroma input (reference layer data) */
487 /* i4_inp_luma_stride : luma input buffer stride */
488 /* i4_inp_chroma_stride : chroma input buffer stride */
489 /* i4_top : indicates whether the core 8x8 reference block */
490 /* is one of 0 and 1 or one of 2 and 3 */
491 /* i4_left : indicates whether the core 8x8 reference block */
492 /* is one of 0 and 2 or one of 1 and 3 */
493 /* ps_ref_mb_coord : coordinates of the reference MB */
494 /* Globals : none */
495 /* Processing : it fills the reference layer data if they are falling in */
496 /* INTRA MB region. If all the pixels are not filled it */
497 /* calls the border extension algorithm to fill them */
498 /* Outputs : none */
499 /* Returns : none */
500 /* */
501 /* Issues : none */
502 /* */
503 /* Revision History: */
504 /* */
505 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
506 /* 02 12 2010 Nithya creation */
507 /* */
508 /*****************************************************************************/
svcd_reflayer_construction_dyadic(void * pv_intra_samp_ctxt,mem_element_t * ps_ref_mb_mode_map,UWORD8 * pu1_inp_luma,UWORD8 * pu1_inp_chroma,WORD32 i4_inp_luma_stride,WORD32 i4_inp_chroma_stride,WORD32 i4_top,WORD32 i4_left,UWORD16 u2_mb_x,UWORD16 u2_mb_y)509 void svcd_reflayer_construction_dyadic(void *pv_intra_samp_ctxt, mem_element_t *ps_ref_mb_mode_map,
510 UWORD8 *pu1_inp_luma, UWORD8 *pu1_inp_chroma,
511 WORD32 i4_inp_luma_stride, WORD32 i4_inp_chroma_stride,
512 WORD32 i4_top, WORD32 i4_left, UWORD16 u2_mb_x,
513 UWORD16 u2_mb_y)
514 {
515 /* Index variables */
516 WORD32 i4_x, i4_y;
517 WORD32 i4_x0, i4_y0;
518 WORD32 i4_xc0, i4_yc0;
519 WORD32 i4_ref_xD, i4_ref_yD;
520 WORD32 i4_c_ref_xD, i4_c_ref_yD;
521
522 /* --------------------------------------------------------------------- */
523 /* Context and reference layer related variables */
524 /* --------------------------------------------------------------------- */
525 intra_sampling_ctxt_t *ps_ctxt;
526 intra_samp_lyr_ctxt *ps_lyr_ctxt;
527 WORD8 *pi1_ref_mb_modes;
528 WORD32 i4_ref_mode_stride;
529 WORD32 i4_element_size;
530 WORD32 i4_mbaddr_y;
531 WORD32 i4_mbaddr_x;
532
533 /* --------------------------------------------------------------------- */
534 /* Temp Variables for Mapping context */
535 /* --------------------------------------------------------------------- */
536 WORD32 i4_ref_wd_in_mbs;
537 WORD32 i4_ref_ht_in_mbs;
538 WORD32 i4_refarray_wd_luma, i4_refarray_wd_chroma;
539 WORD32 i4_refarray_ht_luma, i4_refarray_ht_chroma;
540 WORD32 i4_avlblty;
541 WORD8 i1_cons_intr_samp_flag;
542 WORD8 i1_slice_id;
543 WORD8 i1_corner_samp_avlbl_flag;
544 UWORD8 u1_ny_avlblty;
545
546 /* --------------------------------------------------------------------- */
547 /* Local Pointer Declaration for arrays in Mapping context */
548 /* --------------------------------------------------------------------- */
549 UWORD8 *pu1_refarray_luma;
550 UWORD8 *pu1_refarray_cb, *pu1_refarray_cr;
551
552 /* --------------------------------------------------------------------- */
553 /* Derivation of local variables */
554 /* --------------------------------------------------------------------- */
555 ps_ctxt = (intra_sampling_ctxt_t *) pv_intra_samp_ctxt;
556 ps_lyr_ctxt = &ps_ctxt->as_res_lyrs[ps_ctxt->i4_res_lyr_id];
557 pi1_ref_mb_modes = (WORD8 *) ps_ref_mb_mode_map->pv_buffer;
558 i4_ref_mode_stride = ps_ref_mb_mode_map->i4_num_element_stride;
559 i4_element_size = ps_ref_mb_mode_map->i4_element_size;
560
561 /* --------------------------------------------------------------------- */
562 /* get the constrained intra resampling flag */
563 /* --------------------------------------------------------------------- */
564 i1_cons_intr_samp_flag = ps_lyr_ctxt->i1_constrained_intra_rsmpl_flag;
565
566 ASSERT(NULL != pi1_ref_mb_modes);
567
568 i4_ref_wd_in_mbs = ps_lyr_ctxt->i4_ref_width >> 4;
569 i4_ref_ht_in_mbs = ps_lyr_ctxt->i4_ref_height >> 4;
570 pu1_refarray_luma = ps_ctxt->pu1_refarray_buffer;
571 pu1_refarray_cb = ps_ctxt->pu1_refarray_cb;
572 pu1_refarray_cr = ps_ctxt->pu1_refarray_cr;
573
574 /* --------------------------------------------------------------------- */
575 /* Get the coordinates of the reference layer MB */
576 /* --------------------------------------------------------------------- */
577 i4_mbaddr_x = u2_mb_x;
578 i4_mbaddr_y = u2_mb_y;
579
580 /* --------------------------------------------------------------------- */
581 /* Getting the size of the valid area of ref array to be brought in */
582 /* --------------------------------------------------------------------- */
583 i4_refarray_wd_luma = 20;
584 i4_refarray_ht_luma = 20;
585 i4_refarray_wd_chroma = i4_refarray_wd_luma >> 1;
586 i4_refarray_ht_chroma = i4_refarray_ht_luma >> 1;
587
588 /* --------------------------------------------------------------------- */
589 /* Derivation of ref slice MB idc */
590 /* --------------------------------------------------------------------- */
591 if(1 == i1_cons_intr_samp_flag)
592 {
593 inter_lyr_mb_prms_t *ps_inter_lyr_mb_prms;
594 WORD8 *pi1_ref_mb_mode_tmp;
595 WORD8 i1_mb_mode;
596
597 /* get the location of the byte which has the current mb mode */
598 pi1_ref_mb_mode_tmp = pi1_ref_mb_modes;
599 pi1_ref_mb_mode_tmp += (i4_mbaddr_y * i4_ref_mode_stride * i4_element_size);
600 pi1_ref_mb_mode_tmp += (i4_mbaddr_x * i4_element_size);
601 ps_inter_lyr_mb_prms = (inter_lyr_mb_prms_t *) pi1_ref_mb_mode_tmp;
602 i1_mb_mode = ps_inter_lyr_mb_prms->i1_mb_mode;
603
604 /* The reference layer MB should be intra */
605 ASSERT(i1_mb_mode >= 0);
606 i1_slice_id = i1_mb_mode;
607 }
608 else
609 {
610 /* set to non valid value */
611 i1_slice_id = -1;
612 }
613
614 /* --------------------------------------------------------------------- */
615 /* Bring in the reference array */
616 /* --------------------------------------------------------------------- */
617 {
618 UWORD8 *pu1_src, *pu1_dst;
619 WORD32 i4_src_stride, i4_dst_stride;
620
621 /* Copy luma */
622 i4_src_stride = i4_inp_luma_stride;
623 i4_dst_stride = DYADIC_REF_W_Y;
624 pu1_src = pu1_inp_luma;
625 pu1_dst = pu1_refarray_luma;
626 svcd_copy_data(pu1_src, i4_src_stride, pu1_dst, i4_dst_stride, i4_refarray_wd_luma,
627 i4_refarray_ht_luma);
628 // Semi planar
629 i4_src_stride = i4_inp_chroma_stride;
630 i4_dst_stride = DYADIC_REF_W_C;
631 pu1_src = pu1_inp_chroma;
632 svcd_copy_data_semiplanr(pu1_src, i4_src_stride, pu1_refarray_cb, pu1_refarray_cr,
633 i4_dst_stride, i4_refarray_wd_chroma, i4_refarray_ht_chroma);
634 }
635
636 /* --------------------------------------------------------------------- */
637 /* Get the availability of 5 neighboring MBs */
638 /* --------------------------------------------------------------------- */
639 {
640 /* mb_x + left, mb_y + top */
641 svcd_get_ref_layer_avlblty_dyadic(pi1_ref_mb_modes, i4_ref_mode_stride, i4_element_size,
642 i4_mbaddr_x + i4_left, i4_mbaddr_y + i4_top, &i4_avlblty,
643 i1_slice_id, i1_cons_intr_samp_flag);
644 u1_ny_avlblty = i4_avlblty;
645
646 /* mb_x + left, mb_y */
647 svcd_get_ref_layer_avlblty_dyadic(pi1_ref_mb_modes, i4_ref_mode_stride, i4_element_size,
648 i4_mbaddr_x + i4_left, i4_mbaddr_y, &i4_avlblty,
649 i1_slice_id, i1_cons_intr_samp_flag);
650 u1_ny_avlblty += (i4_avlblty << 1);
651
652 /* mb_x, mb_y + top */
653 svcd_get_ref_layer_avlblty_dyadic(pi1_ref_mb_modes, i4_ref_mode_stride, i4_element_size,
654 i4_mbaddr_x, i4_mbaddr_y + i4_top, &i4_avlblty,
655 i1_slice_id, i1_cons_intr_samp_flag);
656 u1_ny_avlblty += (i4_avlblty << 2);
657
658 /* mb_x - left, mb_y + top */
659 svcd_get_ref_layer_avlblty_dyadic(pi1_ref_mb_modes, i4_ref_mode_stride, i4_element_size,
660 i4_mbaddr_x - i4_left, i4_mbaddr_y + i4_top, &i4_avlblty,
661 i1_slice_id, i1_cons_intr_samp_flag);
662 u1_ny_avlblty += (i4_avlblty << 3);
663
664 /* mb_x + left, mb_y - top */
665 svcd_get_ref_layer_avlblty_dyadic(pi1_ref_mb_modes, i4_ref_mode_stride, i4_element_size,
666 i4_mbaddr_x + i4_left, i4_mbaddr_y - i4_top, &i4_avlblty,
667 i1_slice_id, i1_cons_intr_samp_flag);
668 u1_ny_avlblty += (i4_avlblty << 4);
669 }
670
671 /* --------------------------------------------------------------------- */
672 /* Filling the unavailable samples, if any */
673 /* --------------------------------------------------------------------- */
674 if(0x7 == u1_ny_avlblty)
675 {
676 /* All are available, exit */
677 return;
678 }
679
680 if(!(u1_ny_avlblty & 0x7))
681 {
682 UWORD8 *pu1_tmp_src, *pu1_tmp_dst1, *pu1_tmp_dst2;
683 UWORD8 *pu1_tmp_src1, *pu1_tmp_src2;
684
685 /* Set the 4 corner samples to (x-xD,y-yD) */
686 i4_x0 = 9 + (i4_left << 3) + i4_left;
687 i4_y0 = 9 + (i4_top << 3) + i4_top;
688
689 i4_ref_xD = i4_x0 - i4_left - (i4_left >> 1);
690 i4_ref_yD = i4_y0 - i4_top - (i4_top >> 1);
691
692 pu1_tmp_src = pu1_refarray_luma + (i4_ref_yD * DYADIC_REF_W_Y);
693 pu1_tmp_dst1 = pu1_refarray_luma + (i4_y0 * DYADIC_REF_W_Y);
694 pu1_tmp_dst2 = pu1_tmp_dst1 + DYADIC_REF_W_Y;
695
696 pu1_tmp_dst1[i4_x0] = pu1_tmp_src[i4_ref_xD];
697 pu1_tmp_dst1[i4_x0 + 1] = pu1_tmp_src[i4_ref_xD];
698 pu1_tmp_dst2[i4_x0] = pu1_tmp_src[i4_ref_xD];
699 pu1_tmp_dst2[i4_x0 + 1] = pu1_tmp_src[i4_ref_xD];
700
701 /* Set the corner sample of Cb and Cr to (x-xD,y-yD) */
702 i4_xc0 = i4_x0 >> 1;
703 i4_yc0 = i4_y0 >> 1;
704
705 i4_c_ref_yD = i4_ref_yD >> 1;
706 i4_c_ref_xD = i4_ref_xD >> 1;
707
708 pu1_tmp_src1 = pu1_refarray_cb + (i4_c_ref_yD * DYADIC_REF_W_C);
709 pu1_tmp_dst1 = pu1_refarray_cb + (i4_yc0 * DYADIC_REF_W_C);
710 pu1_tmp_dst1[i4_xc0] = pu1_tmp_src1[i4_c_ref_xD];
711 pu1_tmp_src2 = pu1_refarray_cr + (i4_c_ref_yD * DYADIC_REF_W_C);
712 pu1_tmp_dst2 = pu1_refarray_cr + (i4_yc0 * DYADIC_REF_W_C);
713 pu1_tmp_dst2[i4_xc0] = pu1_tmp_src2[i4_c_ref_xD];
714 }
715
716 if(!(u1_ny_avlblty & 0x5))
717 {
718 UWORD8 *pu1_tmp_src, *pu1_tmp_dst1, *pu1_tmp_dst2;
719 UWORD8 *pu1_tmp_src1, *pu1_tmp_src2;
720
721 /* Copy (x0,ref_yD), (x0+1,ref_yD), ..., (x0+7,ref_yD) to */
722 /* (x0,y0), (x0+1,y0), ..., (x0+7,y0) and */
723 /* (x0,y0+1), (x0+1,y0+1), ..., (x0+7,y0+1) */
724 i4_x0 = 2;
725 i4_y0 = 9 + (i4_top << 3) + i4_top;
726 if(i4_left > 0)
727 {
728 i4_x0 += 8;
729 }
730 i4_ref_yD = i4_y0 - i4_top - (i4_top >> 1);
731
732 pu1_tmp_src = pu1_refarray_luma + (i4_ref_yD * DYADIC_REF_W_Y);
733 pu1_tmp_dst1 = pu1_refarray_luma + (i4_y0 * DYADIC_REF_W_Y);
734 pu1_tmp_dst2 = pu1_tmp_dst1 + DYADIC_REF_W_Y;
735
736 for(i4_x = i4_x0; i4_x < i4_x0 + 8; i4_x++)
737 {
738 pu1_tmp_dst1[i4_x] = pu1_tmp_src[i4_x];
739 pu1_tmp_dst2[i4_x] = pu1_tmp_src[i4_x];
740 }
741
742 /* Cb and Cr copy */
743 i4_xc0 = i4_x0 >> 1;
744 i4_yc0 = i4_y0 >> 1;
745 i4_c_ref_yD = i4_ref_yD >> 1;
746
747 pu1_tmp_src1 = pu1_refarray_cb + (i4_c_ref_yD * DYADIC_REF_W_C);
748 pu1_tmp_dst1 = pu1_refarray_cb + (i4_yc0 * DYADIC_REF_W_C);
749 pu1_tmp_src2 = pu1_refarray_cr + (i4_c_ref_yD * DYADIC_REF_W_C);
750 pu1_tmp_dst2 = pu1_refarray_cr + (i4_yc0 * DYADIC_REF_W_C);
751
752 for(i4_x = i4_xc0; i4_x < i4_xc0 + 4; i4_x++)
753 {
754 pu1_tmp_dst1[i4_x] = pu1_tmp_src1[i4_x];
755 pu1_tmp_dst2[i4_x] = pu1_tmp_src2[i4_x];
756 }
757 }
758
759 if(!(u1_ny_avlblty & 0x3))
760 {
761 UWORD8 *pu1_tmp_src, *pu1_tmp_dst1, *pu1_tmp_dst2;
762 UWORD8 *pu1_tmp_src1, *pu1_tmp_src2;
763
764 /* Copy (ref_xD,y0) to (x0,y0) and (x0+1,y0); */
765 /* copy (ref_xD,y0+1) to (x0,y0+1) and (x0+1,y0+1); ... ;*/
766 /* copy (ref_xD,y0+7) to (x0,y0+7) and (x0+1,y0+7) */
767 i4_x0 = 9 + (i4_left << 3) + i4_left;
768 i4_y0 = 2;
769 if(i4_top > 0)
770 {
771 i4_y0 += 8;
772 }
773 i4_ref_xD = i4_x0 - i4_left - (i4_left >> 1);
774
775 pu1_tmp_src = pu1_refarray_luma + (i4_y0 * DYADIC_REF_W_Y);
776 pu1_tmp_dst1 = pu1_tmp_src;
777
778 for(i4_y = i4_y0; i4_y < i4_y0 + 8; i4_y++)
779 {
780 pu1_tmp_dst1[i4_x0] = pu1_tmp_src[i4_ref_xD];
781 pu1_tmp_dst1[i4_x0 + 1] = pu1_tmp_src[i4_ref_xD];
782 pu1_tmp_src += DYADIC_REF_W_Y;
783 pu1_tmp_dst1 += DYADIC_REF_W_Y;
784 }
785
786 /* Cb and Cr copy */
787 i4_xc0 = i4_x0 >> 1;
788 i4_yc0 = i4_y0 >> 1;
789 i4_c_ref_xD = i4_ref_xD >> 1;
790
791 pu1_tmp_src1 = pu1_refarray_cb + (i4_yc0 * DYADIC_REF_W_C);
792 pu1_tmp_dst1 = pu1_tmp_src1;
793 pu1_tmp_src2 = pu1_refarray_cr + (i4_yc0 * DYADIC_REF_W_C);
794 pu1_tmp_dst2 = pu1_tmp_src2;
795
796 for(i4_y = i4_yc0; i4_y < i4_yc0 + 4; i4_y++)
797 {
798 pu1_tmp_dst1[i4_xc0] = pu1_tmp_src1[i4_c_ref_xD];
799 pu1_tmp_dst2[i4_xc0] = pu1_tmp_src2[i4_c_ref_xD];
800 pu1_tmp_src1 += DYADIC_REF_W_C;
801 pu1_tmp_src2 += DYADIC_REF_W_C;
802 pu1_tmp_dst1 += DYADIC_REF_W_C;
803 pu1_tmp_dst2 += DYADIC_REF_W_C;
804 }
805 }
806
807 if(!(u1_ny_avlblty & 0x4))
808 {
809 if(!(u1_ny_avlblty & 0x8))
810 {
811 /* (mb_x-left,mb_y+top) not available */
812 UWORD8 *pu1_tmp_src, *pu1_tmp_dst;
813
814 i4_x0 = 9 - i4_left;
815 i4_y0 = 9 + (i4_top << 3) + i4_top;
816
817 i4_ref_yD = i4_y0 - i4_top - (i4_top >> 1);
818
819 /* Copy (x0,ref_yD) and (x0+1,ref_yD) to (x0,y0) and (x0+1,y0), and */
820 /* to (x0,y0+1) and (x0+1,y0+1) */
821 pu1_tmp_src = pu1_refarray_luma + (i4_ref_yD * DYADIC_REF_W_Y);
822 pu1_tmp_dst = pu1_refarray_luma + (i4_y0 * DYADIC_REF_W_Y);
823
824 pu1_tmp_dst[i4_x0] = pu1_tmp_src[i4_x0];
825 pu1_tmp_dst[i4_x0 + 1] = pu1_tmp_src[i4_x0 + 1];
826
827 pu1_tmp_dst += DYADIC_REF_W_Y;
828
829 pu1_tmp_dst[i4_x0] = pu1_tmp_src[i4_x0];
830 pu1_tmp_dst[i4_x0 + 1] = pu1_tmp_src[i4_x0 + 1];
831
832 /* Cb copy */
833 i4_xc0 = i4_x0 >> 1;
834 i4_yc0 = i4_y0 >> 1;
835 i4_c_ref_yD = i4_ref_yD >> 1;
836
837 pu1_tmp_src = pu1_refarray_cb + (i4_c_ref_yD * DYADIC_REF_W_C);
838 pu1_tmp_dst = pu1_refarray_cb + (i4_yc0 * DYADIC_REF_W_C);
839
840 pu1_tmp_dst[i4_xc0] = pu1_tmp_src[i4_xc0];
841
842 /* Cr copy */
843 pu1_tmp_src = pu1_refarray_cr + (i4_c_ref_yD * DYADIC_REF_W_C);
844 pu1_tmp_dst = pu1_refarray_cr + (i4_yc0 * DYADIC_REF_W_C);
845
846 pu1_tmp_dst[i4_xc0] = pu1_tmp_src[i4_xc0];
847
848 } /* if (mb_x-left,mb_y+top) not available */
849 else
850 {
851 WORD32 i4_xD, i4_yD;
852 WORD32 i4_c_xD, i4_c_yD;
853 UWORD8 u1_filled_samp;
854
855 svcd_get_ref_layer_avlblty_dyadic(pi1_ref_mb_modes, i4_ref_mode_stride, i4_element_size,
856 i4_mbaddr_x - i4_left, i4_mbaddr_y, &i4_avlblty,
857 i1_slice_id, i1_cons_intr_samp_flag);
858 i1_corner_samp_avlbl_flag = i4_avlblty;
859
860 i4_x0 = 9 - i4_left;
861 i4_y0 = 9 + (i4_top << 3) + i4_top;
862
863 i4_xc0 = i4_x0 >> 1;
864 i4_yc0 = i4_y0 >> 1;
865
866 i4_ref_yD = i4_y0 - i4_top - (i4_top >> 1);
867 i4_ref_xD = i4_x0 - (i4_left * 7) - (i4_left >> 1);
868
869 i4_c_ref_xD = i4_ref_xD >> 1;
870 i4_c_ref_yD = i4_ref_yD >> 1;
871
872 i4_xD = i4_x0 - i4_ref_xD;
873 i4_yD = i4_y0 - i4_ref_yD;
874
875 i4_c_xD = i4_xc0 - i4_c_ref_xD;
876 i4_c_yD = i4_yc0 - i4_c_ref_yD;
877
878 /* Fill corner sample if not available */
879 if(!i1_corner_samp_avlbl_flag)
880 {
881 svcd_corner_samp_dyadic(i4_x0, i4_y0, i4_xD, i4_yD, pu1_refarray_luma,
882 pu1_refarray_cb, pu1_refarray_cr);
883 }
884
885 /* Call diagonal construction for luma */
886 for(i4_y = i4_y0; i4_y < i4_y0 + 2; i4_y++)
887 {
888 for(i4_x = i4_x0; i4_x < i4_x0 + 2; i4_x++)
889 {
890 u1_filled_samp = svcd_diagonal_construct_dyadic(
891 i4_x, i4_y, i4_xD, i4_yD, pu1_refarray_luma, DYADIC_REF_W_Y);
892 i4_xD++;
893 }
894 i4_yD++;
895 i4_xD -= 2;
896 }
897
898 /* Call diagonal construction for chroma */
899 u1_filled_samp = svcd_diagonal_construct_dyadic(i4_xc0, i4_yc0, i4_c_xD, i4_c_yD,
900 pu1_refarray_cb, DYADIC_REF_W_C);
901
902 u1_filled_samp = svcd_diagonal_construct_dyadic(i4_xc0, i4_yc0, i4_c_xD, i4_c_yD,
903 pu1_refarray_cr, DYADIC_REF_W_C);
904 }
905 }
906
907 if(!(u1_ny_avlblty & 0x2))
908 {
909 if(!(u1_ny_avlblty & 0x10))
910 {
911 UWORD8 *pu1_tmp_src, *pu1_tmp_dst;
912
913 i4_x0 = 9 + (i4_left << 3) + i4_left;
914 i4_y0 = 9 - i4_top;
915 i4_ref_xD = i4_x0 - i4_left - (i4_left >> 1);
916
917 /* Copy (ref_xD,y0) to (x0,y0), (x0+1,y0), and */
918 /* copy (ref_xD,y0+1) to (x0,y0+1), (x0+1,y0+1) */
919 pu1_tmp_src = pu1_refarray_luma + (i4_y0 * DYADIC_REF_W_Y);
920 pu1_tmp_dst = pu1_tmp_src;
921
922 pu1_tmp_dst[i4_x0] = pu1_tmp_src[i4_ref_xD];
923 pu1_tmp_dst[i4_x0 + 1] = pu1_tmp_src[i4_ref_xD];
924
925 pu1_tmp_src += DYADIC_REF_W_Y;
926 pu1_tmp_dst += DYADIC_REF_W_Y;
927
928 pu1_tmp_dst[i4_x0] = pu1_tmp_src[i4_ref_xD];
929 pu1_tmp_dst[i4_x0 + 1] = pu1_tmp_src[i4_ref_xD];
930
931 /* Cb copy */
932 i4_xc0 = i4_x0 >> 1;
933 i4_yc0 = i4_y0 >> 1;
934 i4_c_ref_xD = i4_ref_xD >> 1;
935
936 pu1_tmp_src = pu1_refarray_cb + (i4_yc0 * DYADIC_REF_W_C);
937 pu1_tmp_dst = pu1_tmp_src;
938
939 pu1_tmp_dst[i4_xc0] = pu1_tmp_src[i4_c_ref_xD];
940
941 /* Cr copy */
942 pu1_tmp_src = pu1_refarray_cr + (i4_yc0 * DYADIC_REF_W_C);
943 pu1_tmp_dst = pu1_tmp_src;
944
945 pu1_tmp_dst[i4_xc0] = pu1_tmp_src[i4_c_ref_xD];
946
947 } /* if (mb_x+left,mb_y-top) not available */
948 else
949 {
950 WORD32 i4_xD, i4_yD;
951 WORD32 i4_c_xD, i4_c_yD;
952 UWORD8 u1_filled_samp;
953
954 svcd_get_ref_layer_avlblty_dyadic(pi1_ref_mb_modes, i4_ref_mode_stride, i4_element_size,
955 i4_mbaddr_x, i4_mbaddr_y - i4_top, &i4_avlblty,
956 i1_slice_id, i1_cons_intr_samp_flag);
957 i1_corner_samp_avlbl_flag = i4_avlblty;
958
959 i4_x0 = 9 + (i4_left << 3) + i4_left;
960 i4_y0 = 9 - i4_top;
961
962 i4_xc0 = i4_x0 >> 1;
963 i4_yc0 = i4_y0 >> 1;
964
965 i4_ref_xD = i4_x0 - i4_left - (i4_left >> 1);
966 i4_ref_yD = i4_y0 - (i4_top * 7) - (i4_top >> 1);
967
968 i4_c_ref_xD = i4_ref_xD >> 1;
969 i4_c_ref_yD = i4_ref_yD >> 1;
970
971 i4_xD = i4_x0 - i4_ref_xD;
972 i4_yD = i4_y0 - i4_ref_yD;
973
974 i4_c_xD = i4_xc0 - i4_c_ref_xD;
975 i4_c_yD = i4_yc0 - i4_c_ref_yD;
976
977 if(!i1_corner_samp_avlbl_flag)
978 {
979 svcd_corner_samp_dyadic(i4_x0, i4_y0, i4_xD, i4_yD, pu1_refarray_luma,
980 pu1_refarray_cb, pu1_refarray_cr);
981 }
982
983 /* Call diagonal consrtuction for luma */
984 for(i4_y = i4_y0; i4_y < i4_y0 + 2; i4_y++)
985 {
986 for(i4_x = i4_x0; i4_x < i4_x0 + 2; i4_x++)
987 {
988 u1_filled_samp = svcd_diagonal_construct_dyadic(
989 i4_x, i4_y, i4_xD, i4_yD, pu1_refarray_luma, DYADIC_REF_W_Y);
990 i4_xD++;
991 }
992 i4_yD++;
993 i4_xD -= 2;
994 }
995
996 /* Call diagonal construction for chroma */
997 u1_filled_samp = svcd_diagonal_construct_dyadic(i4_xc0, i4_yc0, i4_c_xD, i4_c_yD,
998 pu1_refarray_cb, DYADIC_REF_W_C);
999
1000 u1_filled_samp = svcd_diagonal_construct_dyadic(i4_xc0, i4_yc0, i4_c_xD, i4_c_yD,
1001 pu1_refarray_cr, DYADIC_REF_W_C);
1002 }
1003 }
1004
1005 if(u1_ny_avlblty & 1)
1006 {
1007 if(!(u1_ny_avlblty & 2))
1008 {
1009 /* (mb_x+left,mb_y) is unavailable */
1010 WORD32 i4_xD, i4_yD;
1011 WORD32 i4_c_xD, i4_c_yD;
1012 UWORD8 *pu1_tmp_dst;
1013 UWORD8 u1_filled_samp;
1014
1015 i1_corner_samp_avlbl_flag = (u1_ny_avlblty & 4) >> 2;
1016
1017 i4_x0 = 9 + (i4_left << 3) + i4_left;
1018 i4_y0 = 2;
1019 i4_ref_yD = 1;
1020 if(i4_top > 0)
1021 {
1022 i4_y0 += 8;
1023 i4_ref_yD = 18;
1024 }
1025
1026 i4_ref_xD = i4_x0 - (i4_left) - (i4_left >> 1);
1027
1028 i4_xD = i4_x0 - i4_ref_xD;
1029 i4_yD = i4_y0 - i4_ref_yD;
1030
1031 i4_xc0 = i4_x0 >> 1;
1032 i4_yc0 = i4_y0 >> 1;
1033
1034 i4_c_ref_xD = i4_ref_xD >> 1;
1035 i4_c_ref_yD = i4_ref_yD >> 1;
1036
1037 i4_c_xD = i4_xc0 - i4_c_ref_xD;
1038 i4_c_yD = i4_yc0 - i4_c_ref_yD;
1039
1040 /* Fill corner sample if unavailable */
1041 if(!i1_corner_samp_avlbl_flag)
1042 {
1043 svcd_corner_samp_dyadic(i4_x0, i4_y0, i4_xD, i4_yD, pu1_refarray_luma,
1044 pu1_refarray_cb, pu1_refarray_cr);
1045 }
1046
1047 /* Call the diagonal construction for the 8 rows */
1048 if(i4_top == i4_left)
1049 {
1050 /* if top * left = 1 */
1051 /* (x0,y0) */
1052 u1_filled_samp = svcd_diagonal_construct_dyadic(i4_x0, i4_y0, i4_xD, i4_yD,
1053 pu1_refarray_luma, DYADIC_REF_W_Y);
1054
1055 pu1_tmp_dst = pu1_refarray_luma + (i4_y0 * DYADIC_REF_W_Y);
1056
1057 /* (x0,y0+1), ..., (x0,y0+7) and */
1058 /* (x0+1,y0), ..., (x0+1,y0+6) */
1059 for(i4_y = i4_y0 + 1; i4_y < i4_y0 + 8; i4_y++)
1060 {
1061 i4_yD++;
1062 u1_filled_samp = svcd_diagonal_construct_dyadic(
1063 i4_x0, i4_y, i4_xD, i4_yD, pu1_refarray_luma, DYADIC_REF_W_Y);
1064 pu1_tmp_dst[i4_x0 + 1] = u1_filled_samp;
1065 pu1_tmp_dst += DYADIC_REF_W_Y;
1066 }
1067
1068 /* (x0+1,y0+7) */
1069 u1_filled_samp = svcd_diagonal_construct_dyadic(
1070 i4_x0 + 1, i4_y0 + 7, i4_xD + 1, i4_yD, pu1_refarray_luma, DYADIC_REF_W_Y);
1071 }
1072 else
1073 {
1074 /* top * left = -1 */
1075 /* (x0+1,y0) */
1076 u1_filled_samp = svcd_diagonal_construct_dyadic(i4_x0 + 1, i4_y0, i4_xD + 1, i4_yD,
1077 pu1_refarray_luma, DYADIC_REF_W_Y);
1078
1079 pu1_tmp_dst = pu1_refarray_luma + (i4_y0 * DYADIC_REF_W_Y);
1080
1081 /* (x0,y0), ..., (x0,y0+6) and */
1082 /* (x0+1,y0+1), ..., (x0+1,y0+7) */
1083 for(i4_y = i4_y0; i4_y < i4_y0 + 7; i4_y++)
1084 {
1085 u1_filled_samp = svcd_diagonal_construct_dyadic(
1086 i4_x0, i4_y, i4_xD, i4_yD, pu1_refarray_luma, DYADIC_REF_W_Y);
1087
1088 pu1_tmp_dst += DYADIC_REF_W_Y;
1089 pu1_tmp_dst[i4_x0 + 1] = u1_filled_samp;
1090 i4_yD++;
1091 }
1092 /* (x0,y0+7) */
1093 u1_filled_samp = svcd_diagonal_construct_dyadic(i4_x0, i4_y0 + 7, i4_xD, i4_yD,
1094 pu1_refarray_luma, DYADIC_REF_W_Y);
1095 }
1096
1097 /* For Cb and Cr */
1098 for(i4_y = i4_yc0; i4_y < i4_yc0 + 4; i4_y++)
1099 {
1100 u1_filled_samp = svcd_diagonal_construct_dyadic(i4_xc0, i4_y, i4_c_xD, i4_c_yD,
1101 pu1_refarray_cb, DYADIC_REF_W_C);
1102 u1_filled_samp = svcd_diagonal_construct_dyadic(i4_xc0, i4_y, i4_c_xD, i4_c_yD,
1103 pu1_refarray_cr, DYADIC_REF_W_C);
1104 i4_c_yD++;
1105 }
1106
1107 } /* (mb_x+left,mb_y) is unavailable */
1108
1109 if(!(u1_ny_avlblty & 4))
1110 {
1111 /* (mb_x,mb_y+top) is unavailable */
1112 WORD32 i4_xD, i4_yD;
1113 WORD32 i4_c_xD, i4_c_yD;
1114 UWORD8 *pu1_tmp_dst;
1115 UWORD8 u1_filled_samp;
1116
1117 i1_corner_samp_avlbl_flag = (u1_ny_avlblty & 2) >> 1;
1118
1119 i4_y0 = 9 + (i4_top << 3) + (i4_top);
1120 i4_x0 = 2;
1121 i4_ref_xD = 1;
1122 if(i4_left > 0)
1123 {
1124 i4_x0 += 8;
1125 i4_ref_xD = 18;
1126 }
1127
1128 i4_ref_yD = i4_y0 - i4_top - (i4_top >> 1);
1129
1130 i4_xD = i4_x0 - i4_ref_xD;
1131 i4_yD = i4_y0 - i4_ref_yD;
1132 i4_xc0 = i4_x0 >> 1;
1133 i4_yc0 = i4_y0 >> 1;
1134
1135 i4_c_ref_xD = i4_ref_xD >> 1;
1136 i4_c_ref_yD = i4_ref_yD >> 1;
1137 i4_c_xD = i4_xc0 - i4_c_ref_xD;
1138 i4_c_yD = i4_yc0 - i4_c_ref_yD;
1139
1140 if(!i1_corner_samp_avlbl_flag)
1141 {
1142 svcd_corner_samp_dyadic(i4_x0, i4_y0, i4_xD, i4_yD, pu1_refarray_luma,
1143 pu1_refarray_cb, pu1_refarray_cr);
1144 }
1145
1146 /* Call the diagonal construction for the 2 rows */
1147 if(i4_top == i4_left)
1148 {
1149 /* if top * left = 1 */
1150 /* (x0,y0) */
1151 u1_filled_samp = svcd_diagonal_construct_dyadic(i4_x0, i4_y0, i4_xD, i4_yD,
1152 pu1_refarray_luma, DYADIC_REF_W_Y);
1153
1154 pu1_tmp_dst = pu1_refarray_luma + ((i4_y0 + 1) * DYADIC_REF_W_Y);
1155
1156 /* (x0+1,y0), ..., (x0+7,y0) and */
1157 /* (x0,y0+1), ..., (x0+6,y0+1) */
1158 for(i4_x = i4_x0 + 1; i4_x < i4_x0 + 8; i4_x++)
1159 {
1160 i4_xD++;
1161 u1_filled_samp = svcd_diagonal_construct_dyadic(
1162 i4_x, i4_y0, i4_xD, i4_yD, pu1_refarray_luma, DYADIC_REF_W_Y);
1163 pu1_tmp_dst[i4_x - 1] = u1_filled_samp;
1164 }
1165
1166 /* (x0+7,y0+1) */
1167 u1_filled_samp = svcd_diagonal_construct_dyadic(
1168 i4_x0 + 7, i4_y0 + 1, i4_xD, i4_yD + 1, pu1_refarray_luma, DYADIC_REF_W_Y);
1169 }
1170 else
1171 {
1172 /* top * left = -1 */
1173 /* (x0,y0+1) */
1174 u1_filled_samp = svcd_diagonal_construct_dyadic(i4_x0, i4_y0 + 1, i4_xD, i4_yD + 1,
1175 pu1_refarray_luma, DYADIC_REF_W_Y);
1176
1177 pu1_tmp_dst = pu1_refarray_luma + ((i4_y0 + 1) * DYADIC_REF_W_Y);
1178
1179 /* (x0,y0), ..., (x0,y0+6) and */
1180 /* (x0+1,y0+1), ..., (x0+1,y0+7) */
1181 for(i4_x = i4_x0; i4_x < i4_x0 + 7; i4_x++)
1182 {
1183 u1_filled_samp = svcd_diagonal_construct_dyadic(
1184 i4_x, i4_y0, i4_xD, i4_yD, pu1_refarray_luma, DYADIC_REF_W_Y);
1185
1186 pu1_tmp_dst[i4_x + 1] = u1_filled_samp;
1187 i4_xD++;
1188 }
1189 /* (x0+7,y0) */
1190 u1_filled_samp = svcd_diagonal_construct_dyadic(i4_x0 + 7, i4_y0, i4_xD, i4_yD,
1191 pu1_refarray_luma, DYADIC_REF_W_Y);
1192 }
1193
1194 /* For Cb and Cr */
1195 for(i4_x = i4_xc0; i4_x < i4_xc0 + 4; i4_x++)
1196 {
1197 u1_filled_samp = svcd_diagonal_construct_dyadic(i4_x, i4_yc0, i4_c_xD, i4_c_yD,
1198 pu1_refarray_cb, DYADIC_REF_W_C);
1199 u1_filled_samp = svcd_diagonal_construct_dyadic(i4_x, i4_yc0, i4_c_xD, i4_c_yD,
1200 pu1_refarray_cr, DYADIC_REF_W_C);
1201 i4_c_xD++;
1202 }
1203
1204 } /* (mb_x,mb_y+top) is unavailable */
1205 } /* if (mb_x+left,mb_y+top) not available */
1206 else
1207 {
1208 UWORD8 *pu1_tmp_dst1, *pu1_tmp_dst2;
1209 UWORD8 *pu1_tmp_src1, *pu1_tmp_src2;
1210
1211 if(0x02 == (u1_ny_avlblty & 0x6))
1212 {
1213 /* (mb_x+left,mb_y) available, (mb_x,mb_y+top) unavailable */
1214 i4_x0 = 9 + (i4_left << 3) + i4_left;
1215 i4_y0 = 9 + (i4_top << 3) + i4_top;
1216 i4_ref_yD = i4_y0 - i4_top - (i4_top >> 1);
1217
1218 /* Copy (x0,ref_yD), (x0+1,ref_yD) to */
1219 /* (x0,y0), (x0+1,y0), and (x0,y0+1), (x0+1,y0+1) */
1220 pu1_tmp_src1 = pu1_refarray_luma + (i4_ref_yD * DYADIC_REF_W_Y);
1221 pu1_tmp_dst1 = pu1_refarray_luma + (i4_y0 * DYADIC_REF_W_Y);
1222 pu1_tmp_dst2 = pu1_tmp_dst1 + DYADIC_REF_W_Y;
1223
1224 pu1_tmp_dst1[i4_x0] = pu1_tmp_src1[i4_x0];
1225 pu1_tmp_dst2[i4_x0] = pu1_tmp_src1[i4_x0];
1226 pu1_tmp_dst1[i4_x0 + 1] = pu1_tmp_src1[i4_x0 + 1];
1227 pu1_tmp_dst2[i4_x0 + 1] = pu1_tmp_src1[i4_x0 + 1];
1228
1229 /* Cb and Cr copy */
1230 i4_xc0 = i4_x0 >> 1;
1231 i4_yc0 = i4_y0 >> 1;
1232 i4_c_ref_yD = i4_ref_yD >> 1;
1233
1234 pu1_tmp_src1 = pu1_refarray_cb + (i4_c_ref_yD * DYADIC_REF_W_C);
1235 pu1_tmp_dst1 = pu1_refarray_cb + (i4_yc0 * DYADIC_REF_W_C);
1236 pu1_tmp_src2 = pu1_refarray_cr + (i4_c_ref_yD * DYADIC_REF_W_C);
1237 pu1_tmp_dst2 = pu1_refarray_cr + (i4_yc0 * DYADIC_REF_W_C);
1238
1239 pu1_tmp_dst1[i4_xc0] = pu1_tmp_src1[i4_xc0];
1240 pu1_tmp_dst2[i4_xc0] = pu1_tmp_src2[i4_xc0];
1241
1242 } /* if (mb_x+left,mb_y) available, (mb_x,mb_y+top) unavailable */
1243 else if(0x04 == (u1_ny_avlblty & 0x6))
1244 {
1245 /* (mb_x+left,mb_y) unavailable, (mb_x,mb_y+top) available */
1246 i4_x0 = 9 + (i4_left << 3) + i4_left;
1247 i4_y0 = 9 + (i4_top << 3) + i4_top;
1248 i4_ref_xD = i4_x0 - i4_left - (i4_left >> 1);
1249
1250 /* Copy (ref_xD,y0) to (x0,y0) and (x0+1,y0) */
1251 /* copy (ref_xD,y0+1) to (x0,y0+1) and (x0+1,y0+1) */
1252 pu1_tmp_src1 = pu1_refarray_luma + (i4_y0 * DYADIC_REF_W_Y);
1253 pu1_tmp_dst1 = pu1_tmp_src1;
1254 pu1_tmp_src2 = pu1_tmp_src1 + DYADIC_REF_W_Y;
1255 pu1_tmp_dst2 = pu1_tmp_src2;
1256
1257 pu1_tmp_dst1[i4_x0] = pu1_tmp_src1[i4_ref_xD];
1258 pu1_tmp_dst1[i4_x0 + 1] = pu1_tmp_src1[i4_ref_xD];
1259 pu1_tmp_dst2[i4_x0] = pu1_tmp_src2[i4_ref_xD];
1260 pu1_tmp_dst2[i4_x0 + 1] = pu1_tmp_src2[i4_ref_xD];
1261
1262 /* Copy Cb and Cr */
1263 i4_xc0 = i4_x0 >> 1;
1264 i4_yc0 = i4_y0 >> 1;
1265 i4_c_ref_xD = i4_ref_xD >> 1;
1266
1267 pu1_tmp_src1 = pu1_refarray_cb + (i4_yc0 * DYADIC_REF_W_C);
1268 pu1_tmp_dst1 = pu1_tmp_src1;
1269 pu1_tmp_src2 = pu1_refarray_cr + (i4_yc0 * DYADIC_REF_W_C);
1270 pu1_tmp_dst2 = pu1_tmp_src2;
1271
1272 pu1_tmp_dst1[i4_xc0] = pu1_tmp_src1[i4_c_ref_xD];
1273 pu1_tmp_dst2[i4_xc0] = pu1_tmp_src2[i4_c_ref_xD];
1274
1275 } /* if (mb_x+left,mb_y) unavailable, (mb_x,mb_y+top) available */
1276 else if(0x6 == (u1_ny_avlblty & 0x6))
1277 {
1278 /* (mb_x+left,mb_y) available, (mb_x,mb_y+top) available */
1279 WORD32 i4_xD, i4_yD;
1280 WORD32 i4_c_xD, i4_c_yD;
1281 UWORD8 u1_filled_samp;
1282
1283 i4_y0 = 9 + (i4_top << 3) + i4_top;
1284 i4_x0 = 9 + (i4_left << 3) + i4_left;
1285
1286 i4_ref_xD = i4_x0 - i4_left - (i4_left >> 1);
1287 i4_ref_yD = i4_y0 - i4_top - (i4_top >> 1);
1288
1289 i4_xD = i4_x0 - i4_ref_xD;
1290 i4_yD = i4_y0 - i4_ref_yD;
1291 i4_xc0 = i4_x0 >> 1;
1292 i4_yc0 = i4_y0 >> 1;
1293
1294 i4_c_ref_xD = i4_ref_xD >> 1;
1295 i4_c_ref_yD = i4_ref_yD >> 1;
1296 i4_c_xD = i4_xc0 - i4_c_ref_xD;
1297 i4_c_yD = i4_yc0 - i4_c_ref_yD;
1298
1299 /* Call diagonal construction for luma */
1300 for(i4_y = i4_y0; i4_y < i4_y0 + 2; i4_y++)
1301 {
1302 for(i4_x = i4_x0; i4_x < i4_x0 + 2; i4_x++)
1303 {
1304 u1_filled_samp = svcd_diagonal_construct_dyadic(
1305 i4_x, i4_y, i4_xD, i4_yD, pu1_refarray_luma, DYADIC_REF_W_Y);
1306 i4_xD++;
1307 }
1308 i4_yD++;
1309 i4_xD -= 2;
1310 }
1311
1312 /* Call diagonal construction for chroma */
1313 u1_filled_samp = svcd_diagonal_construct_dyadic(i4_xc0, i4_yc0, i4_c_xD, i4_c_yD,
1314 pu1_refarray_cb, DYADIC_REF_W_C);
1315
1316 u1_filled_samp = svcd_diagonal_construct_dyadic(i4_xc0, i4_yc0, i4_c_xD, i4_c_yD,
1317 pu1_refarray_cr, DYADIC_REF_W_C);
1318
1319 } /* if (mb_x+left,mb_y) available, (mb_x,mb_y+top) available */
1320 } /* (mb_x+left,mb_y+top) available */
1321 return;
1322 }
1323 /*****************************************************************************/
1324 /* */
1325 /* Function Name : svcd_interpolate_base_luma_dyadic */
1326 /* */
1327 /* Description : This function takes the reference array buffer & performs*/
1328 /* intra resampling for dyadic scaling ratios */
1329 /* Inputs : pu1_inp_buf : ptr to the 12x12 reference sample buffer */
1330 /* pi2_tmp_filt_buf : ptr to the 12x16 buffer to hold the */
1331 /* vertically interpolated data */
1332 /* pu1_out_buf : output buffer pointer */
1333 /* i4_out_stride : output buffer stride */
1334 /* Globals : none */
1335 /* Processing : it does the interpolation in vertical direction followed */
1336 /* by horizontal direction */
1337 /* Outputs : resampled pixels */
1338 /* Returns : none */
1339 /* */
1340 /* Issues : none */
1341 /* */
1342 /* Revision History: */
1343 /* */
1344 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
1345 /* 03 12 2010 Nithya creation */
1346 /* */
1347 /*****************************************************************************/
svcd_interpolate_base_luma_dyadic(UWORD8 * pu1_inp_buf,WORD16 * pi2_tmp_filt_buf,UWORD8 * pu1_out_buf,WORD32 i4_out_stride)1348 void svcd_interpolate_base_luma_dyadic(UWORD8 *pu1_inp_buf, WORD16 *pi2_tmp_filt_buf,
1349 UWORD8 *pu1_out_buf, WORD32 i4_out_stride)
1350 {
1351 WORD32 i4_x, i4_y;
1352 WORD32 i4_coeff_0, i4_coeff_1, i4_coeff_2, i4_coeff_3;
1353 WORD32 i4_samp_0, i4_samp_1, i4_samp_2, i4_samp_3;
1354 WORD32 i4_rslt_1, i4_rslt_2;
1355 WORD32 i4_filt_stride, i4_src_stride;
1356 UWORD8 *pu1_inp, *pu1_out;
1357 WORD16 *pi2_tmp;
1358
1359 /* Filter coefficient values for phase 4 */
1360 i4_coeff_0 = -3;
1361 i4_coeff_1 = 28;
1362 i4_coeff_2 = 8;
1363 i4_coeff_3 = -1;
1364
1365 i4_filt_stride = 12;
1366 i4_src_stride = DYADIC_REF_W_Y;
1367 pu1_inp = pu1_inp_buf;
1368 pi2_tmp = pi2_tmp_filt_buf;
1369 pu1_out = pu1_out_buf;
1370
1371 /* Vertical interpolation */
1372 for(i4_x = 0; i4_x < 12; i4_x++)
1373 {
1374 /* y = 0, y_phase = 12 */
1375 i4_samp_0 = pu1_inp[i4_x];
1376 pu1_inp += i4_src_stride;
1377 i4_samp_1 = pu1_inp[i4_x];
1378 pu1_inp += i4_src_stride;
1379 i4_samp_2 = pu1_inp[i4_x];
1380 pu1_inp += i4_src_stride;
1381 i4_samp_3 = pu1_inp[i4_x];
1382 pu1_inp += i4_src_stride;
1383
1384 /* since y_phase 12 for y = 0 */
1385 i4_rslt_1 = i4_samp_0 * i4_coeff_3;
1386 i4_rslt_1 += i4_samp_1 * i4_coeff_2;
1387 i4_rslt_1 += i4_samp_2 * i4_coeff_1;
1388 i4_rslt_1 += i4_samp_3 * i4_coeff_0;
1389
1390 /* Store the output */
1391 pi2_tmp[i4_x] = i4_rslt_1;
1392
1393 /* Increment the output ptr */
1394 pi2_tmp += i4_filt_stride;
1395
1396 for(i4_y = 1; i4_y < 15; i4_y += 2)
1397 {
1398 i4_samp_0 = i4_samp_1;
1399 i4_samp_1 = i4_samp_2;
1400 i4_samp_2 = i4_samp_3;
1401 i4_samp_3 = pu1_inp[i4_x];
1402
1403 /* y_phase is 4 for odd values of y */
1404 /* and 12 for even values of y */
1405 i4_rslt_1 = i4_samp_0 * i4_coeff_0;
1406 i4_rslt_1 += i4_samp_1 * i4_coeff_1;
1407 i4_rslt_1 += i4_samp_2 * i4_coeff_2;
1408 i4_rslt_1 += i4_samp_3 * i4_coeff_3;
1409
1410 i4_rslt_2 = i4_samp_0 * i4_coeff_3;
1411 i4_rslt_2 += i4_samp_1 * i4_coeff_2;
1412 i4_rslt_2 += i4_samp_2 * i4_coeff_1;
1413 i4_rslt_2 += i4_samp_3 * i4_coeff_0;
1414
1415 /* Storing the results */
1416 pi2_tmp[i4_x] = i4_rslt_1;
1417 pi2_tmp += i4_filt_stride;
1418 pi2_tmp[i4_x] = i4_rslt_2;
1419
1420 /* Incrementing the pointers */
1421 pi2_tmp += i4_filt_stride;
1422 pu1_inp += i4_src_stride;
1423 } /* End of loop over y */
1424
1425 /* y = 15, y_phase = 4 */
1426 i4_samp_0 = i4_samp_1;
1427 i4_samp_1 = i4_samp_2;
1428 i4_samp_2 = i4_samp_3;
1429 i4_samp_3 = pu1_inp[i4_x];
1430 i4_rslt_1 = i4_samp_0 * i4_coeff_0;
1431 i4_rslt_1 += i4_samp_1 * i4_coeff_1;
1432 i4_rslt_1 += i4_samp_2 * i4_coeff_2;
1433 i4_rslt_1 += i4_samp_3 * i4_coeff_3;
1434
1435 /* Store the output */
1436 pi2_tmp[i4_x] = i4_rslt_1;
1437
1438 /* Reinitializing the ptrs */
1439 pu1_inp = pu1_inp_buf;
1440 pi2_tmp = pi2_tmp_filt_buf;
1441 } /* End of loop over x */
1442
1443 /* Horizontal interpolation */
1444 for(i4_y = 0; i4_y < 16; i4_y++)
1445 {
1446 /* x = 0, x_phase = 12 */
1447 i4_samp_0 = *pi2_tmp++;
1448 i4_samp_1 = *pi2_tmp++;
1449 i4_samp_2 = *pi2_tmp++;
1450 i4_samp_3 = *pi2_tmp++;
1451
1452 /* since x_phase 12 for x = 0 */
1453 i4_rslt_1 = i4_samp_0 * i4_coeff_3;
1454 i4_rslt_1 += i4_samp_1 * i4_coeff_2;
1455 i4_rslt_1 += i4_samp_2 * i4_coeff_1;
1456 i4_rslt_1 += i4_samp_3 * i4_coeff_0;
1457 i4_rslt_1 += 512;
1458 i4_rslt_1 >>= 10;
1459
1460 /* Store the output */
1461 pu1_out[0] = CLIPUCHAR(i4_rslt_1);
1462
1463 for(i4_x = 1; i4_x < 15; i4_x += 2)
1464 {
1465 i4_samp_0 = i4_samp_1;
1466 i4_samp_1 = i4_samp_2;
1467 i4_samp_2 = i4_samp_3;
1468 i4_samp_3 = *pi2_tmp++;
1469
1470 /* x_phase is 4 for odd values of x */
1471 /* and 12 for even values of x */
1472 i4_rslt_1 = i4_samp_0 * i4_coeff_0;
1473 i4_rslt_1 += i4_samp_1 * i4_coeff_1;
1474 i4_rslt_1 += i4_samp_2 * i4_coeff_2;
1475 i4_rslt_1 += i4_samp_3 * i4_coeff_3;
1476 i4_rslt_1 += 512;
1477
1478 i4_rslt_2 = i4_samp_0 * i4_coeff_3;
1479 i4_rslt_2 += i4_samp_1 * i4_coeff_2;
1480 i4_rslt_2 += i4_samp_2 * i4_coeff_1;
1481 i4_rslt_2 += i4_samp_3 * i4_coeff_0;
1482 i4_rslt_2 += 512;
1483
1484 i4_rslt_1 >>= 10;
1485 i4_rslt_2 >>= 10;
1486
1487 /* Store the output */
1488 pu1_out[i4_x] = CLIPUCHAR(i4_rslt_1);
1489 pu1_out[i4_x + 1] = CLIPUCHAR(i4_rslt_2);
1490 } /* End of loop over x */
1491
1492 /* x = 15 */
1493 i4_samp_0 = i4_samp_1;
1494 i4_samp_1 = i4_samp_2;
1495 i4_samp_2 = i4_samp_3;
1496 i4_samp_3 = *pi2_tmp++;
1497
1498 i4_rslt_1 = i4_samp_0 * i4_coeff_0;
1499 i4_rslt_1 += i4_samp_1 * i4_coeff_1;
1500 i4_rslt_1 += i4_samp_2 * i4_coeff_2;
1501 i4_rslt_1 += i4_samp_3 * i4_coeff_3;
1502 i4_rslt_1 += 512;
1503
1504 i4_rslt_1 >>= 10;
1505
1506 /* Store the output */
1507 pu1_out[i4_x] = CLIPUCHAR(i4_rslt_1);
1508
1509 /* Increment the output ptr */
1510 pu1_out += i4_out_stride;
1511 } /* End of loop over y */
1512
1513 } /* svcd_interpolate_base_luma_dyadic */
1514
1515 /*****************************************************************************/
1516 /* */
1517 /* Function Name : svcd_vert_interpol_chroma_dyadic_1 */
1518 /* */
1519 /* Description : This function takes the reference array buffer & performs*/
1520 /* vertical intra resampling for dyadic scaling ratios for */
1521 /* chroma for the following ref_lyr_chroma_phase_y_plus1 and*/
1522 /* chroma_phase_y_plus1: */
1523 /* ref_lyr cur_lyr */
1524 /* 0 0 */
1525 /* 1 0 */
1526 /* 1 1 */
1527 /* 1 2 */
1528 /* 2 1 */
1529 /* 2 2 */
1530 /* Inputs : pu1_inp_buf : ptr to the 6x6 reference sample buffer */
1531 /* pi2_tmp_filt_buf : ptr to the 6x8 buffer to hold the */
1532 /* vertically interpolated data */
1533 /* i4_phase_0 : y phase for even values of y */
1534 /* i4_phase_1 : y phase for odd values of y */
1535 /* Globals : none */
1536 /* Processing : it does the interpolation in vertical direction */
1537 /* Outputs : vertically resampled samples */
1538 /* Returns : none */
1539 /* */
1540 /* Issues : none */
1541 /* */
1542 /* Revision History: */
1543 /* */
1544 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
1545 /* 06 12 2010 Nithya creation */
1546 /* */
1547 /*****************************************************************************/
svcd_vert_interpol_chroma_dyadic_1(UWORD8 * pu1_inp_buf,WORD16 * pi2_tmp_filt_buf,WORD32 i4_phase_0,WORD32 i4_phase_1)1548 void svcd_vert_interpol_chroma_dyadic_1(UWORD8 *pu1_inp_buf, WORD16 *pi2_tmp_filt_buf,
1549 WORD32 i4_phase_0, WORD32 i4_phase_1)
1550 {
1551 WORD32 i4_x, i4_y;
1552 WORD32 i4_coeff_0, i4_coeff_1, i4_coeff_2, i4_coeff_3;
1553 WORD32 i4_samp_0, i4_samp_1;
1554 WORD32 i4_rslt_1, i4_rslt_2;
1555 WORD32 i4_filt_stride, i4_src_stride;
1556 UWORD8 *pu1_inp;
1557 WORD16 *pi2_tmp;
1558
1559 i4_coeff_0 = 8 - i4_phase_0;
1560 i4_coeff_1 = i4_phase_0;
1561 i4_coeff_2 = 8 - i4_phase_1;
1562 i4_coeff_3 = i4_phase_1;
1563
1564 pu1_inp = pu1_inp_buf;
1565 pi2_tmp = pi2_tmp_filt_buf;
1566 i4_filt_stride = 6;
1567 i4_src_stride = DYADIC_REF_W_C;
1568
1569 /* Vertical interpolation */
1570 for(i4_x = 0; i4_x < 6; i4_x++)
1571 {
1572 /* y = 0, y_phase = phase_0 */
1573 i4_samp_0 = pu1_inp[i4_x];
1574 pu1_inp += i4_src_stride;
1575 i4_samp_1 = pu1_inp[i4_x];
1576 pu1_inp += i4_src_stride;
1577
1578 /* since y_phase = phase_0 for y = 0 */
1579 i4_rslt_1 = i4_samp_0 * i4_coeff_0;
1580 i4_rslt_1 += i4_samp_1 * i4_coeff_1;
1581
1582 /* Store the output */
1583 pi2_tmp[i4_x] = i4_rslt_1;
1584
1585 /* Increment the output ptr */
1586 pi2_tmp += i4_filt_stride;
1587
1588 for(i4_y = 1; i4_y < 7; i4_y += 2)
1589 {
1590 i4_samp_0 = i4_samp_1;
1591 i4_samp_1 = pu1_inp[i4_x];
1592
1593 /* y_phase is phase_1 for odd values of y */
1594 /* and phase_0 for even values of y */
1595 i4_rslt_1 = i4_samp_0 * i4_coeff_2;
1596 i4_rslt_1 += i4_samp_1 * i4_coeff_3;
1597
1598 i4_rslt_2 = i4_samp_0 * i4_coeff_0;
1599 i4_rslt_2 += i4_samp_1 * i4_coeff_1;
1600
1601 /* Storing the results */
1602 pi2_tmp[i4_x] = i4_rslt_1;
1603 pi2_tmp += i4_filt_stride;
1604 pi2_tmp[i4_x] = i4_rslt_2;
1605
1606 /* Incrementing the pointers */
1607 pi2_tmp += i4_filt_stride;
1608 pu1_inp += i4_src_stride;
1609
1610 } /* End of loop over y */
1611
1612 /* y = 7, y_phase = phase_1 */
1613 i4_samp_0 = i4_samp_1;
1614 i4_samp_1 = pu1_inp[i4_x];
1615
1616 i4_rslt_1 = i4_samp_0 * i4_coeff_2;
1617 i4_rslt_1 += i4_samp_1 * i4_coeff_3;
1618
1619 /* Store the output */
1620 pi2_tmp[i4_x] = i4_rslt_1;
1621
1622 /* Reinitializing the ptrs */
1623 pu1_inp = pu1_inp_buf;
1624 pi2_tmp = pi2_tmp_filt_buf;
1625 } /* End of loop over x */
1626 } /* svcd_vert_interpol_chroma_dyadic_1 */
1627
1628 /*****************************************************************************/
1629 /* */
1630 /* Function Name : svcd_vert_interpol_chroma_dyadic_2 */
1631 /* */
1632 /* Description : This function takes the reference array buffer & performs*/
1633 /* vertical intra resampling for dyadic scaling ratios for */
1634 /* chroma for the following ref_lyr_chroma_phase_y_plus1 and*/
1635 /* chroma_phase_y_plus1: */
1636 /* ref_lyr cur_lyr */
1637 /* 0 1 */
1638 /* 0 2 */
1639 /* Inputs : pu1_inp_buf : ptr to the 6x6 reference sample buffer */
1640 /* pi2_tmp_filt_buf : ptr to the 6x8 buffer to hold the */
1641 /* vertically interpolated data */
1642 /* i4_phase_0 : y phase for even values of y */
1643 /* i4_phase_1 : y phase for odd values of y */
1644 /* Globals : none */
1645 /* Processing : it does the interpolation in vertical direction */
1646 /* Outputs : vertically resampled samples */
1647 /* Returns : none */
1648 /* */
1649 /* Issues : none */
1650 /* */
1651 /* Revision History: */
1652 /* */
1653 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
1654 /* 06 12 2010 Nithya creation */
1655 /* */
1656 /*****************************************************************************/
svcd_vert_interpol_chroma_dyadic_2(UWORD8 * pu1_inp_buf,WORD16 * pi2_tmp_filt_buf,WORD32 i4_phase_0,WORD32 i4_phase_1)1657 void svcd_vert_interpol_chroma_dyadic_2(UWORD8 *pu1_inp_buf, WORD16 *pi2_tmp_filt_buf,
1658 WORD32 i4_phase_0, WORD32 i4_phase_1)
1659 {
1660 WORD32 i4_x, i4_y;
1661 WORD32 i4_coeff_0, i4_coeff_1, i4_coeff_2, i4_coeff_3;
1662 WORD32 i4_samp_0, i4_samp_1;
1663 WORD32 i4_rslt_1, i4_rslt_2;
1664 WORD32 i4_filt_stride, i4_src_stride;
1665 UWORD8 *pu1_inp;
1666 WORD16 *pi2_tmp;
1667
1668 i4_coeff_0 = 8 - i4_phase_0;
1669 i4_coeff_1 = i4_phase_0;
1670 i4_coeff_2 = 8 - i4_phase_1;
1671 i4_coeff_3 = i4_phase_1;
1672
1673 pi2_tmp = pi2_tmp_filt_buf;
1674 i4_filt_stride = 6;
1675 i4_src_stride = DYADIC_REF_W_C;
1676 pu1_inp = pu1_inp_buf + i4_src_stride;
1677
1678 /* Vertical interpolation */
1679 for(i4_x = 0; i4_x < 6; i4_x++)
1680 {
1681 i4_samp_1 = pu1_inp[i4_x];
1682 pu1_inp += i4_src_stride;
1683
1684 for(i4_y = 0; i4_y < 8; i4_y += 2)
1685 {
1686 i4_samp_0 = i4_samp_1;
1687 i4_samp_1 = pu1_inp[i4_x];
1688
1689 /* y_phase is phase_1 for odd values of y */
1690 /* and phase_0 for even values of y */
1691 i4_rslt_1 = i4_samp_0 * i4_coeff_0;
1692 i4_rslt_1 += i4_samp_1 * i4_coeff_1;
1693
1694 i4_rslt_2 = i4_samp_0 * i4_coeff_2;
1695 i4_rslt_2 += i4_samp_1 * i4_coeff_3;
1696
1697 /* Storing the results */
1698 pi2_tmp[i4_x] = i4_rslt_1;
1699 pi2_tmp += i4_filt_stride;
1700 pi2_tmp[i4_x] = i4_rslt_2;
1701
1702 /* Incrementing the pointers */
1703 pi2_tmp += i4_filt_stride;
1704 pu1_inp += i4_src_stride;
1705
1706 } /* End of loop over y */
1707
1708 /* Reinitializing the ptrs */
1709 pu1_inp = pu1_inp_buf + i4_src_stride;
1710 pi2_tmp = pi2_tmp_filt_buf;
1711 } /* End of loop over x */
1712 } /* svcd_vert_interpol_chroma_dyadic_2 */
1713
1714 /*****************************************************************************/
1715 /* */
1716 /* Function Name : svcd_vert_interpol_chroma_dyadic_3 */
1717 /* */
1718 /* Description : This function takes the reference array buffer & performs*/
1719 /* vertical intra resampling for dyadic scaling ratios for */
1720 /* chroma for the following ref_lyr_chroma_phase_y_plus1 and*/
1721 /* chroma_phase_y_plus1: */
1722 /* ref_lyr cur_lyr */
1723 /* 2 0 */
1724 /* Inputs : pu1_inp_buf : ptr to the 6x6 reference sample buffer */
1725 /* pi2_tmp_filt_buf : ptr to the 6x8 buffer to hold the */
1726 /* vertically interpolated data */
1727 /* i4_phase_0 : y phase for even values of y */
1728 /* i4_phase_1 : y phase for odd values of y */
1729 /* Globals : none */
1730 /* Processing : it does the interpolation in vertical direction */
1731 /* Outputs : vertically resampled samples */
1732 /* Returns : none */
1733 /* */
1734 /* Issues : none */
1735 /* */
1736 /* Revision History: */
1737 /* */
1738 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
1739 /* 13 12 2010 Nithya creation */
1740 /* */
1741 /*****************************************************************************/
svcd_vert_interpol_chroma_dyadic_3(UWORD8 * pu1_inp_buf,WORD16 * pi2_tmp_filt_buf,WORD32 i4_phase_0,WORD32 i4_phase_1)1742 void svcd_vert_interpol_chroma_dyadic_3(UWORD8 *pu1_inp_buf, WORD16 *pi2_tmp_filt_buf,
1743 WORD32 i4_phase_0, WORD32 i4_phase_1)
1744 {
1745 WORD32 i4_x, i4_y;
1746 WORD32 i4_coeff_0, i4_coeff_1, i4_coeff_2, i4_coeff_3;
1747 WORD32 i4_samp_0, i4_samp_1;
1748 WORD32 i4_rslt_1, i4_rslt_2;
1749 WORD32 i4_filt_stride, i4_src_stride;
1750 UWORD8 *pu1_inp;
1751 WORD16 *pi2_tmp;
1752
1753 i4_coeff_0 = 8 - i4_phase_0;
1754 i4_coeff_1 = i4_phase_0;
1755 i4_coeff_2 = 8 - i4_phase_1;
1756 i4_coeff_3 = i4_phase_1;
1757
1758 pi2_tmp = pi2_tmp_filt_buf;
1759 i4_filt_stride = 6;
1760 i4_src_stride = DYADIC_REF_W_C;
1761 pu1_inp = pu1_inp_buf;
1762
1763 /* Vertical interpolation */
1764 for(i4_x = 0; i4_x < 6; i4_x++)
1765 {
1766 i4_samp_1 = pu1_inp[i4_x];
1767 pu1_inp += i4_src_stride;
1768
1769 for(i4_y = 0; i4_y < 8; i4_y += 2)
1770 {
1771 i4_samp_0 = i4_samp_1;
1772 i4_samp_1 = pu1_inp[i4_x];
1773
1774 /* y_phase is phase_1 for odd values of y */
1775 /* and phase_0 for even values of y */
1776 i4_rslt_1 = i4_samp_0 * i4_coeff_0;
1777 i4_rslt_1 += i4_samp_1 * i4_coeff_1;
1778
1779 i4_rslt_2 = i4_samp_0 * i4_coeff_2;
1780 i4_rslt_2 += i4_samp_1 * i4_coeff_3;
1781
1782 /* Storing the results */
1783 pi2_tmp[i4_x] = i4_rslt_1;
1784 pi2_tmp += i4_filt_stride;
1785 pi2_tmp[i4_x] = i4_rslt_2;
1786
1787 /* Incrementing the pointers */
1788 pi2_tmp += i4_filt_stride;
1789 pu1_inp += i4_src_stride;
1790
1791 } /* End of loop over y */
1792
1793 /* Reinitializing the ptrs */
1794 pu1_inp = pu1_inp_buf;
1795 pi2_tmp = pi2_tmp_filt_buf;
1796 } /* End of loop over x */
1797 } /* svcd_vert_interpol_chroma_dyadic_3 */
1798
1799 /*****************************************************************************/
1800 /* */
1801 /* Function Name : svcd_horz_interpol_chroma_dyadic_1 */
1802 /* */
1803 /* Description : This function takes the reference array buffer & performs*/
1804 /* horizontal intra resampling for dyadic scaling ratios for*/
1805 /* chroma with following ref_lyr_chroma_phase_x_plus1_flag */
1806 /* and chroma_phase_x_plus1_flag: */
1807 /* ref_lyr cur_lyr */
1808 /* 0 0 */
1809 /* 1 0 */
1810 /* 1 1 */
1811 /* Inputs : pi2_tmp_filt_buf : ptr to the 6x8 buffer containing the */
1812 /* vertically interpolated data */
1813 /* pu1_out_buf : pointer to the output buffer */
1814 /* i4_out_stride : output buffer stride */
1815 /* i4_phase_0 : x phase for even values of x */
1816 /* i4_phase_1 : x phase for odd values of x */
1817 /* Globals : none */
1818 /* Processing : it does the interpolation in vertical direction */
1819 /* Outputs : resampled samples */
1820 /* Returns : none */
1821 /* */
1822 /* Issues : none */
1823 /* */
1824 /* Revision History: */
1825 /* */
1826 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
1827 /* 06 12 2010 Nithya creation */
1828 /* */
1829 /*****************************************************************************/
svcd_horz_interpol_chroma_dyadic_1(WORD16 * pi2_tmp_filt_buf,UWORD8 * pu1_out_buf,WORD32 i4_out_stride,WORD32 i4_phase_0,WORD32 i4_phase_1)1830 void svcd_horz_interpol_chroma_dyadic_1(WORD16 *pi2_tmp_filt_buf, UWORD8 *pu1_out_buf,
1831 WORD32 i4_out_stride, WORD32 i4_phase_0, WORD32 i4_phase_1)
1832 {
1833 WORD32 i4_x, i4_y;
1834 WORD32 i4_coeff_0, i4_coeff_1, i4_coeff_2, i4_coeff_3;
1835 WORD32 i4_samp_0, i4_samp_1;
1836 WORD32 i4_rslt_1, i4_rslt_2;
1837 WORD32 i4_filt_stride, i4_dst_stride;
1838 UWORD8 *pu1_out;
1839 WORD16 *pi2_tmp;
1840
1841 i4_coeff_0 = 8 - i4_phase_0;
1842 i4_coeff_1 = i4_phase_0;
1843 i4_coeff_2 = 8 - i4_phase_1;
1844 i4_coeff_3 = i4_phase_1;
1845
1846 pu1_out = pu1_out_buf;
1847 pi2_tmp = pi2_tmp_filt_buf;
1848 i4_filt_stride = 6;
1849 i4_dst_stride = i4_out_stride;
1850
1851 /* Horizontal interpolation */
1852 for(i4_y = 0; i4_y < 8; i4_y++)
1853 {
1854 /* x = 0, x_phase = phase_0 */
1855 i4_samp_0 = *pi2_tmp++;
1856 i4_samp_1 = *pi2_tmp++;
1857
1858 /* since x_phase = phase_0 for x = 0 */
1859 i4_rslt_1 = i4_samp_0 * i4_coeff_0;
1860 i4_rslt_1 += i4_samp_1 * i4_coeff_1;
1861
1862 /* Round to 8-bit value */
1863 i4_rslt_1 += 32;
1864 i4_rslt_1 >>= 6;
1865
1866 /* Store the output */
1867 pu1_out[0] = i4_rslt_1;
1868
1869 for(i4_x = 1; i4_x < 7; i4_x += 2)
1870 {
1871 i4_samp_0 = i4_samp_1;
1872 i4_samp_1 = *pi2_tmp++;
1873
1874 /* x_phase is phase_1 for odd values of x */
1875 /* and phase_0 for even values of x */
1876 i4_rslt_1 = i4_samp_0 * i4_coeff_2;
1877 i4_rslt_1 += i4_samp_1 * i4_coeff_3;
1878
1879 i4_rslt_2 = i4_samp_0 * i4_coeff_0;
1880 i4_rslt_2 += i4_samp_1 * i4_coeff_1;
1881
1882 /* Rounding to 8-bit values */
1883 i4_rslt_1 += 32;
1884 i4_rslt_1 >>= 6;
1885 i4_rslt_2 += 32;
1886 i4_rslt_2 >>= 6;
1887
1888 /* Storing the results */
1889 pu1_out[2 * i4_x] = i4_rslt_1;
1890 pu1_out[2 * (i4_x + 1)] = i4_rslt_2;
1891
1892 } /* End of loop over y */
1893
1894 /* y = 7, y_phase = phase_1 */
1895 i4_samp_0 = i4_samp_1;
1896 i4_samp_1 = *pi2_tmp++;
1897
1898 /* since x_phase = phase_1 for x = 7 */
1899 i4_rslt_1 = i4_samp_0 * i4_coeff_2;
1900 i4_rslt_1 += i4_samp_1 * i4_coeff_3;
1901
1902 /* Round to 8-bit value */
1903 i4_rslt_1 += 32;
1904 i4_rslt_1 >>= 6;
1905
1906 /* Store the output */
1907 pu1_out[2 * 7] = i4_rslt_1;
1908
1909 /* Incrementing the output ptr */
1910 pu1_out += i4_dst_stride;
1911 } /* End of loop over x */
1912 } /* svcd_horz_interpol_chroma_dyadic_1 */
1913
1914 /*****************************************************************************/
1915 /* */
1916 /* Function Name : svcd_horz_interpol_chroma_dyadic_2 */
1917 /* */
1918 /* Description : This function takes the reference array buffer & performs*/
1919 /* horizontal intra resampling for dyadic scaling ratios for*/
1920 /* chroma with following ref_lyr_chroma_phase_x_plus1_flag */
1921 /* and chroma_phase_x_plus1_flag: */
1922 /* ref_lyr cur_lyr */
1923 /* 0 1 */
1924 /* Inputs : pi2_tmp_filt_buf : ptr to the 6x8 buffer containing the */
1925 /* vertically interpolated data */
1926 /* pu1_out_buf : pointer to the output buffer */
1927 /* i4_out_stride : output buffer stride */
1928 /* i4_phase_0 : x phase for even values of x */
1929 /* i4_phase_1 : x phase for odd values of x */
1930 /* Globals : none */
1931 /* Processing : it does the interpolation in vertical direction */
1932 /* Outputs : resampled samples */
1933 /* Returns : none */
1934 /* */
1935 /* Issues : none */
1936 /* */
1937 /* Revision History: */
1938 /* */
1939 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
1940 /* 06 12 2010 Nithya creation */
1941 /* */
1942 /*****************************************************************************/
svcd_horz_interpol_chroma_dyadic_2(WORD16 * pi2_tmp_filt_buf,UWORD8 * pu1_out_buf,WORD32 i4_out_stride,WORD32 i4_phase_0,WORD32 i4_phase_1)1943 void svcd_horz_interpol_chroma_dyadic_2(WORD16 *pi2_tmp_filt_buf, UWORD8 *pu1_out_buf,
1944 WORD32 i4_out_stride, WORD32 i4_phase_0, WORD32 i4_phase_1)
1945 {
1946 WORD32 i4_x, i4_y;
1947 WORD32 i4_coeff_0, i4_coeff_1, i4_coeff_2, i4_coeff_3;
1948 WORD32 i4_samp_0, i4_samp_1;
1949 WORD32 i4_rslt_1, i4_rslt_2;
1950 WORD32 i4_filt_stride, i4_dst_stride;
1951 UWORD8 *pu1_out;
1952 WORD16 *pi2_tmp;
1953
1954 i4_coeff_0 = 8 - i4_phase_0;
1955 i4_coeff_1 = i4_phase_0;
1956 i4_coeff_2 = 8 - i4_phase_1;
1957 i4_coeff_3 = i4_phase_1;
1958
1959 pu1_out = pu1_out_buf;
1960 pi2_tmp = pi2_tmp_filt_buf + 1;
1961 i4_filt_stride = 6;
1962 i4_dst_stride = i4_out_stride;
1963
1964 /* Horizontal interpolation */
1965 for(i4_y = 0; i4_y < 8; i4_y++)
1966 {
1967 /* x = 0, x_phase = phase_0 */
1968 i4_samp_1 = *pi2_tmp++;
1969
1970 for(i4_x = 0; i4_x < 8; i4_x += 2)
1971 {
1972 i4_samp_0 = i4_samp_1;
1973 i4_samp_1 = *pi2_tmp++;
1974
1975 /* x_phase is phase_1 for odd values of x */
1976 /* and phase_0 for even values of x */
1977 i4_rslt_1 = i4_samp_0 * i4_coeff_0;
1978 i4_rslt_1 += i4_samp_1 * i4_coeff_1;
1979
1980 i4_rslt_2 = i4_samp_0 * i4_coeff_2;
1981 i4_rslt_2 += i4_samp_1 * i4_coeff_3;
1982
1983 /* Rounding to 8-bit values */
1984 i4_rslt_1 += 32;
1985 i4_rslt_1 >>= 6;
1986 i4_rslt_2 += 32;
1987 i4_rslt_2 >>= 6;
1988
1989 /* Storing the results */
1990 pu1_out[2 * i4_x] = i4_rslt_1;
1991 pu1_out[2 * (i4_x + 1)] = i4_rslt_2;
1992
1993 } /* End of loop over x */
1994
1995 /* Incrementing the ptrs */
1996 pi2_tmp += 1;
1997 pu1_out += i4_dst_stride;
1998 } /* End of loop over y */
1999 } /* svcd_horz_interpol_chroma_dyadic_2 */
2000
2001 /*****************************************************************************/
2002 /* */
2003 /* Function Name : svcd_intra_samp_mb_dyadic */
2004 /* */
2005 /* Description : MB level function which performs the intra resampling */
2006 /* of data of an MB (luma and chroma inclusive) for dyadic */
2007 /* scaling ratios */
2008 /* */
2009 /* Inputs : pv_intra_samp_ctxt : intra sampling context */
2010 /* ps_ref_luma : reference layer luma data buffer desc */
2011 /* ps_ref_chroma : reference layer chroma data buffer desc */
2012 /* ps_ref_mb_mode_map : ref layer mb mode map buff desc */
2013 /* ps_curr_luma : current layer out luma buffer desc */
2014 /* ps_curr_chroma : current layer out chroma buffer desc */
2015 /* x,y : current mb coorinate */
2016 /* Globals : none */
2017 /* Processing : it calls the reference layer construction followed by */
2018 /* interpolation function for luma and cb and cr */
2019 /* Outputs : inter resampled data of current MB */
2020 /* Returns : none */
2021 /* */
2022 /* Issues : none */
2023 /* */
2024 /* Revision History: */
2025 /* */
2026 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
2027 /* 07 12 2010 Nithya creation */
2028 /* */
2029 /*****************************************************************************/
svcd_intra_samp_mb_dyadic(void * pv_intra_samp_ctxt,mem_element_t * ps_ref_luma,mem_element_t * ps_ref_chroma,mem_element_t * ps_ref_mb_mode_map,mem_element_t * ps_curr_luma,mem_element_t * ps_curr_chroma,UWORD16 u2_mb_x,UWORD16 u2_mb_y,void * pv_dec)2030 void svcd_intra_samp_mb_dyadic(void *pv_intra_samp_ctxt, mem_element_t *ps_ref_luma,
2031 mem_element_t *ps_ref_chroma, mem_element_t *ps_ref_mb_mode_map,
2032 mem_element_t *ps_curr_luma, mem_element_t *ps_curr_chroma,
2033 UWORD16 u2_mb_x, UWORD16 u2_mb_y, void *pv_dec)
2034 {
2035 /* --------------------------------------------------------------------- */
2036 /* I/O buffer params */
2037 /* --------------------------------------------------------------------- */
2038 UWORD8 *pu1_inp_luma, *pu1_inp_chroma;
2039 UWORD8 *pu1_out_luma, *pu1_out_chroma;
2040 UWORD8 *pu1_out_cb, *pu1_out_cr;
2041 UWORD8 *pu1_refarray_luma, *pu1_refarray_cb, *pu1_refarray_cr;
2042 WORD16 *pi2_tmp_filt_buf;
2043 WORD32 i4_inp_luma_stride, i4_inp_chroma_stride;
2044 WORD32 i4_out_luma_stride, i4_out_chroma_stride;
2045 UWORD16 u2_mb_x_ref, u2_mb_y_ref;
2046 dec_struct_t *ps_dec = (dec_struct_t *) pv_dec;
2047 dec_slice_params_t *ps_slice = ps_dec->ps_cur_slice;
2048 dec_slice_svc_ext_params_t *ps_svc_slice_params = NULL;
2049
2050 /* --------------------------------------------------------------------- */
2051 /* Intra resampling ctxt pointers */
2052 /* --------------------------------------------------------------------- */
2053 intra_sampling_ctxt_t *ps_ctxt;
2054 intra_samp_lyr_ctxt *ps_lyr_ctxt;
2055 res_prms_t *ps_res_prms;
2056
2057 /* --------------------------------------------------------------------- */
2058 /* reference and current layer MB coordinates */
2059 /* --------------------------------------------------------------------- */
2060 WORD32 i4_scaled_mb_x, i4_scaled_mb_y;
2061 WORD32 i4_top, i4_left;
2062
2063 ps_svc_slice_params = &ps_slice->s_svc_slice_params;
2064 /* --------------------------------------------------------------------- */
2065 /* Pointer derivation */
2066 /* --------------------------------------------------------------------- */
2067 ps_ctxt = (intra_sampling_ctxt_t *) pv_intra_samp_ctxt;
2068 ps_lyr_ctxt = &ps_ctxt->as_res_lyrs[ps_ctxt->i4_res_lyr_id];
2069 ps_res_prms = ps_ctxt->ps_res_prms;
2070
2071 /* --------------------------------------------------------------------- */
2072 /* MB coordinate derivation */
2073 /* --------------------------------------------------------------------- */
2074 i4_scaled_mb_x = u2_mb_x - (ps_svc_slice_params->i4_scaled_ref_layer_left_offset >> 4);
2075 // (ps_res_prms->s_ref_lyr_scaled_offset.i2_left >> 4); SVC_DEC_EXT_REVIEW
2076 i4_scaled_mb_y = u2_mb_y - (ps_svc_slice_params->i4_scaled_ref_layer_top_offset >> 4);
2077 //(ps_res_prms->s_ref_lyr_scaled_offset.i2_top >> 4); SVC_DEC_EXT_REVIEW
2078
2079 if(i4_scaled_mb_x & 0x1)
2080 {
2081 i4_left = 1;
2082 }
2083 else
2084 {
2085 i4_left = -1;
2086 }
2087 if(i4_scaled_mb_y & 0x1)
2088 {
2089 i4_top = 1;
2090 }
2091 else
2092 {
2093 i4_top = -1;
2094 }
2095
2096 u2_mb_x_ref = (i4_scaled_mb_x >> 1);
2097 u2_mb_y_ref = (i4_scaled_mb_y >> 1);
2098
2099 /* --------------------------------------------------------------------- */
2100 /* Reference Array Consrtuction - luma and chroma */
2101 /* --------------------------------------------------------------------- */
2102
2103 pu1_inp_luma = (UWORD8 *) ps_ref_luma->pv_buffer;
2104 pu1_inp_chroma = (UWORD8 *) ps_ref_chroma->pv_buffer;
2105
2106 i4_inp_luma_stride = ps_ref_luma->i4_num_element_stride;
2107 i4_inp_chroma_stride = ps_ref_chroma->i4_num_element_stride;
2108
2109 /* ------- Constructing refSampleArray ----------------------- */
2110 svcd_reflayer_construction_dyadic(pv_intra_samp_ctxt, ps_ref_mb_mode_map, pu1_inp_luma,
2111 pu1_inp_chroma, i4_inp_luma_stride, i4_inp_chroma_stride,
2112 i4_top, i4_left, u2_mb_x_ref, u2_mb_y_ref);
2113
2114 /* --------------------------------------------------------------------- */
2115 /* LUMA INTERPOLATION */
2116 /* --------------------------------------------------------------------- */
2117 pu1_refarray_luma = ps_ctxt->pu1_refarray_buffer;
2118 if(1 == i4_top)
2119 {
2120 pu1_refarray_luma += (DYADIC_REF_W_Y << 3);
2121 }
2122 if(1 == i4_left)
2123 {
2124 pu1_refarray_luma += 8;
2125 }
2126 pu1_out_luma = (UWORD8 *) ps_curr_luma->pv_buffer;
2127 i4_out_luma_stride = ps_curr_luma->i4_num_element_stride;
2128 pi2_tmp_filt_buf = (WORD16 *) ps_ctxt->pi4_temp_interpolation_buffer;
2129
2130 svcd_interpolate_base_luma_dyadic(pu1_refarray_luma, pi2_tmp_filt_buf, pu1_out_luma,
2131 i4_out_luma_stride);
2132
2133 /* --------------------------------------------------------------------- */
2134 /* CHROMA INTERPOLATION */
2135 /* --------------------------------------------------------------------- */
2136 pu1_out_chroma = (UWORD8 *) ps_curr_chroma->pv_buffer;
2137 i4_out_chroma_stride =
2138 ps_curr_chroma->i4_num_element_stride; // << 1; SVC_DEC_REVIEW_INTRA_RESAMPLE
2139
2140 /* CB */
2141 pu1_out_cb = pu1_out_chroma;
2142 pu1_refarray_cb = ps_ctxt->pu1_refarray_cb;
2143
2144 if(1 == i4_top)
2145 {
2146 pu1_refarray_cb += (DYADIC_REF_W_C << 2);
2147 }
2148 if(1 == i4_left)
2149 {
2150 pu1_refarray_cb += 4;
2151 }
2152
2153 /* Vertical interpolation */
2154 ps_lyr_ctxt->pf_vert_chroma_interpol(pu1_refarray_cb, pi2_tmp_filt_buf,
2155 ps_lyr_ctxt->i4_y_phase_0, ps_lyr_ctxt->i4_y_phase_1);
2156
2157 /* Horizontal interpolation */
2158 ps_lyr_ctxt->pf_horz_chroma_interpol(pi2_tmp_filt_buf, pu1_out_cb, i4_out_chroma_stride,
2159 ps_lyr_ctxt->i4_x_phase_0, ps_lyr_ctxt->i4_x_phase_1);
2160
2161 /* CR */
2162 pu1_out_cr = pu1_out_chroma + 1;
2163 // (i4_out_chroma_stride >> 1); SVC_DEC_REVIEW_INTRA_RESAMPLE
2164 pu1_refarray_cr = ps_ctxt->pu1_refarray_cr;
2165
2166 if(1 == i4_top)
2167 {
2168 pu1_refarray_cr += (DYADIC_REF_W_C << 2);
2169 }
2170 if(1 == i4_left)
2171 {
2172 pu1_refarray_cr += 4;
2173 }
2174
2175 /* Vertical interpolation */
2176 ps_lyr_ctxt->pf_vert_chroma_interpol(pu1_refarray_cr, pi2_tmp_filt_buf,
2177 ps_lyr_ctxt->i4_y_phase_0, ps_lyr_ctxt->i4_y_phase_1);
2178
2179 /* Horizontal interpolation */
2180 ps_lyr_ctxt->pf_horz_chroma_interpol(pi2_tmp_filt_buf, pu1_out_cr, i4_out_chroma_stride,
2181 ps_lyr_ctxt->i4_x_phase_0, ps_lyr_ctxt->i4_x_phase_1);
2182 return;
2183 }
2184
2185 /*****************************************************************************/
2186 /* */
2187 /* Function Name : svcd_residual_chroma_dyadic_alt */
2188 /* */
2189 /* Description : this fucntion does the upsampling of chroma residuals for*/
2190 /* Dyadic cases and specific chroma phase cases */
2191 /* */
2192 /* Inputs : pv_residual_samp_ctxt : Residual upsampling context */
2193 /* pu1_inp_data : input 8 bit data pointer */
2194 /* i4_inp_data_stride : input buffer stride */
2195 /* pi2_out_res : output 16 bit buffer pointer */
2196 /* i4_out_res_stride : Output buffer stride */
2197 /* pu1_inp_bitmap : input packed sign bit data pointer */
2198 /* i4_inp_bitmap_stride : sign bit buffer stride */
2199 /* i4_start_bit_pos : bit position in the byte of packed */
2200 /* sign values */
2201 /* Globals : none */
2202 /* Processing : it does the upsampling with intial phase values */
2203 /* */
2204 /* Outputs : Upsampled residuals for chroma */
2205 /* Returns : none */
2206 /* */
2207 /* Issues : none */
2208 /* */
2209 /* Revision History: */
2210 /* */
2211 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
2212 /* 25 09 2010 vijayakumar creation */
2213 /* */
2214 /*****************************************************************************/
svcd_residual_chroma_dyadic_alt(void * pv_residual_samp_ctxt,UWORD16 u2_mb_x,UWORD16 u2_mb_y,mem_element_t * ps_ref_mb_mode,UWORD8 * pu1_inp_data,WORD32 i4_inp_data_stride,WORD16 * pi2_out_res,WORD32 i4_out_res_stride,UWORD8 * pu1_inp_bitmap,WORD32 i4_inp_bitmap_stride,WORD32 i4_cr_flag)2215 void svcd_residual_chroma_dyadic_alt(void *pv_residual_samp_ctxt, UWORD16 u2_mb_x, UWORD16 u2_mb_y,
2216 mem_element_t *ps_ref_mb_mode, UWORD8 *pu1_inp_data,
2217 WORD32 i4_inp_data_stride, WORD16 *pi2_out_res,
2218 WORD32 i4_out_res_stride, UWORD8 *pu1_inp_bitmap,
2219 WORD32 i4_inp_bitmap_stride, WORD32 i4_cr_flag)
2220 {
2221 residual_sampling_ctxt_t *ps_ctxt;
2222 res_lyr_ctxt *ps_lyr_ctxt;
2223 ps_ctxt = (residual_sampling_ctxt_t *) pv_residual_samp_ctxt;
2224 ps_lyr_ctxt = &ps_ctxt->as_res_lyrs[ps_ctxt->i4_res_lyr_id];
2225 /* ----------------- Processing ------------------------------- */
2226 {
2227 ref_pixel_map_t *ps_pos_phase;
2228 residual_samp_map_ctxt_t *ps_chroma_map;
2229 ref_mb_map_t *ps_x_off_len_chroma;
2230 ref_mb_map_t *ps_y_off_len_chroma;
2231
2232 WORD32 i4_i;
2233 UWORD8 *pu1_ref_data_byte, *pu1_ref_sign_byte;
2234 WORD32 *pi4_ref_array;
2235 WORD32 i4_phase1, i4_phase2;
2236 WORD32 i4_start_bit_pos = 0;
2237 WORD32 i4_offset_x, i4_offset_y;
2238 WORD32 i4_chrm_horz_int_mode, i4_chrm_vert_int_mode;
2239 WORD32 i4_horz_intp_ctr = SUB_BLOCK_HEIGHT;
2240
2241 ps_chroma_map = &ps_lyr_ctxt->s_chroma_map_ctxt;
2242 ps_x_off_len_chroma = ps_chroma_map->ps_x_offset_length;
2243 ps_y_off_len_chroma = ps_chroma_map->ps_y_offset_length;
2244
2245 /* get the actual offset for the buffers */
2246 i4_offset_x = ps_x_off_len_chroma[u2_mb_x].i2_offset;
2247 i4_offset_y = ps_y_off_len_chroma[u2_mb_y].i2_offset;
2248
2249 {
2250 UWORD8 u1_mask;
2251 WORD32 i4_mb_x, i4_mb_y;
2252 WORD32 i4_chrm_nnz;
2253 WORD32 i4_num_element_stride;
2254 inter_lyr_mb_prms_t *ps_inter_lyr_mb_prms, *ps_inter_lyr_mb_prms_curr;
2255
2256 u1_mask = (SVCD_TRUE == i4_cr_flag) ? 0xF0 : 0x0F;
2257
2258 /* Top Left */
2259 i4_mb_x = i4_offset_x >> 3;
2260 i4_mb_y = i4_offset_y >> 3;
2261
2262 /* get the location of the byte which has the current mb mode */
2263 ps_inter_lyr_mb_prms = ps_ref_mb_mode->pv_buffer;
2264 i4_num_element_stride = ps_ref_mb_mode->i4_num_element_stride;
2265
2266 ps_inter_lyr_mb_prms_curr = ps_inter_lyr_mb_prms + i4_mb_x;
2267 ps_inter_lyr_mb_prms_curr += i4_mb_y * i4_num_element_stride;
2268
2269 i4_chrm_nnz = ps_inter_lyr_mb_prms_curr->u1_chroma_nnz & u1_mask;
2270
2271 /* Top Right */
2272 i4_mb_x = (i4_offset_x + 4) >> 3;
2273
2274 ps_inter_lyr_mb_prms_curr = ps_inter_lyr_mb_prms + i4_mb_x;
2275 ps_inter_lyr_mb_prms_curr += i4_mb_y * i4_num_element_stride;
2276
2277 i4_chrm_nnz |= ps_inter_lyr_mb_prms_curr->u1_chroma_nnz & u1_mask;
2278
2279 /* Bottom Left */
2280 i4_mb_x = i4_offset_x >> 3;
2281 i4_mb_y = (i4_offset_y + 4) >> 3;
2282
2283 ps_inter_lyr_mb_prms_curr = ps_inter_lyr_mb_prms + i4_mb_x;
2284 ps_inter_lyr_mb_prms_curr += i4_mb_y * i4_num_element_stride;
2285
2286 i4_chrm_nnz |= ps_inter_lyr_mb_prms_curr->u1_chroma_nnz & u1_mask;
2287
2288 /* Bottom Right */
2289 i4_mb_x = (i4_offset_x + 4) >> 3;
2290
2291 ps_inter_lyr_mb_prms_curr = ps_inter_lyr_mb_prms + i4_mb_x;
2292 ps_inter_lyr_mb_prms_curr += i4_mb_y * i4_num_element_stride;
2293
2294 i4_chrm_nnz |= ps_inter_lyr_mb_prms_curr->u1_chroma_nnz & u1_mask;
2295
2296 if(0 == i4_chrm_nnz)
2297 {
2298 return;
2299 }
2300 }
2301
2302 i4_chrm_horz_int_mode = ps_lyr_ctxt->i4_chrm_horz_int_mode;
2303 i4_chrm_vert_int_mode = ps_lyr_ctxt->i4_chrm_vert_int_mode;
2304
2305 if(0 == i4_chrm_horz_int_mode)
2306 {
2307 if(i4_offset_x >= 0)
2308 {
2309 pu1_inp_data++;
2310 if(0 == ((i4_offset_x + 1) & 7))
2311 {
2312 pu1_inp_bitmap++;
2313 }
2314 }
2315 }
2316
2317 if(0 == i4_chrm_vert_int_mode)
2318 {
2319 if(i4_offset_y >= 0)
2320 {
2321 pu1_inp_data += i4_inp_data_stride;
2322 pu1_inp_bitmap += i4_inp_bitmap_stride;
2323 }
2324 }
2325 else
2326 {
2327 /* extra additional row of interpolation required for this case */
2328 i4_horz_intp_ctr++;
2329 }
2330
2331 /* set the appropriate bit pos */
2332 if(1 == (u2_mb_x & 1))
2333 {
2334 i4_start_bit_pos = 4;
2335 }
2336
2337 /* ----------- Horizontal Interpolation ---------------- */
2338 pu1_ref_data_byte = pu1_inp_data;
2339 pu1_ref_sign_byte = pu1_inp_bitmap;
2340 ps_pos_phase = ps_lyr_ctxt->s_chroma_map_ctxt.ps_x_pos_phase;
2341
2342 pi4_ref_array = (WORD32 *) ps_ctxt->pi2_refarray_buffer;
2343 i4_phase1 = ps_pos_phase[0].i2_phase;
2344 i4_phase2 = (i4_phase1 + 8) & 0x0F;
2345
2346 /* interchange the phase values for corner case */
2347 if(1 == i4_chrm_horz_int_mode)
2348 {
2349 WORD32 i4_temp;
2350 i4_temp = i4_phase1;
2351 i4_phase1 = i4_phase2;
2352 i4_phase2 = i4_temp;
2353 }
2354
2355 for(i4_i = 0; i4_i < i4_horz_intp_ctr; i4_i++)
2356 {
2357 WORD16 i2_coeff1, i2_coeff2;
2358 UWORD8 u1_sign;
2359 UWORD8 u1_sign_byte = *pu1_ref_sign_byte;
2360
2361 i2_coeff1 = (WORD16) (pu1_ref_data_byte[0]);
2362 u1_sign = (UWORD8) GET_BIT(u1_sign_byte, i4_start_bit_pos);
2363
2364 /* if signed number */
2365 if(u1_sign)
2366 {
2367 i2_coeff1 |= 0xFF00;
2368 }
2369
2370 if(0 == i4_chrm_horz_int_mode)
2371 {
2372 /* populate the first inter sample */
2373 *pi4_ref_array++ = i2_coeff1 << 4;
2374 }
2375
2376 {
2377 /* unroll count 1 */
2378 i2_coeff2 = (WORD16) (pu1_ref_data_byte[1]);
2379 u1_sign = (UWORD8) GET_BIT(u1_sign_byte, (i4_start_bit_pos + 1));
2380
2381 /* if signed number */
2382 if(u1_sign)
2383 {
2384 i2_coeff2 |= 0xFF00;
2385 }
2386
2387 /* populate 2 samples based on current coeffs */
2388 *pi4_ref_array++ = ((16 - i4_phase2) * i2_coeff1 + i4_phase2 * i2_coeff2);
2389
2390 *pi4_ref_array++ = ((16 - i4_phase1) * i2_coeff1 + i4_phase1 * i2_coeff2);
2391
2392 /* unroll count 2 */
2393 i2_coeff1 = (WORD16) (pu1_ref_data_byte[2]);
2394 u1_sign = (UWORD8) GET_BIT(u1_sign_byte, (i4_start_bit_pos + 2));
2395
2396 /* if signed number */
2397 if(u1_sign)
2398 {
2399 i2_coeff1 |= 0xFF00;
2400 }
2401
2402 /* populate 2 samples based on current coeffs */
2403 *pi4_ref_array++ = ((16 - i4_phase2) * i2_coeff2 + i4_phase2 * i2_coeff1);
2404
2405 *pi4_ref_array++ = ((16 - i4_phase1) * i2_coeff2 + i4_phase1 * i2_coeff1);
2406
2407 /* unroll count 3 */
2408 i2_coeff2 = (WORD16) (pu1_ref_data_byte[3]);
2409 u1_sign = (UWORD8) GET_BIT(u1_sign_byte, (i4_start_bit_pos + 3));
2410
2411 /* if signed number */
2412 if(u1_sign)
2413 {
2414 i2_coeff2 |= 0xFF00;
2415 }
2416
2417 /* populate 2 samples based on current coeffs */
2418 *pi4_ref_array++ = ((16 - i4_phase2) * i2_coeff1 + i4_phase2 * i2_coeff2);
2419
2420 *pi4_ref_array++ = ((16 - i4_phase1) * i2_coeff1 + i4_phase1 * i2_coeff2);
2421 }
2422
2423 /* populate the last inter sample */
2424 *pi4_ref_array++ = i2_coeff2 << 4;
2425
2426 if(1 == i4_chrm_horz_int_mode)
2427 {
2428 WORD32 i4_bit_pos = i4_start_bit_pos + 4;
2429
2430 if(8 == i4_bit_pos)
2431 {
2432 u1_sign_byte = *(pu1_ref_sign_byte + 1);
2433 i4_bit_pos = 0;
2434 }
2435
2436 i2_coeff1 = (WORD16) (pu1_ref_data_byte[4]);
2437 u1_sign = (UWORD8) GET_BIT(u1_sign_byte, i4_bit_pos);
2438
2439 /* if signed number */
2440 if(u1_sign)
2441 {
2442 i2_coeff1 |= 0xFF00;
2443 }
2444
2445 /* populate the last inter sample */
2446 *pi4_ref_array++ = i2_coeff1 << 4;
2447 }
2448
2449 /* vertical loop updates */
2450 pu1_ref_data_byte = pu1_inp_data + ((i4_i + 1) * i4_inp_data_stride);
2451 pu1_ref_sign_byte += i4_inp_bitmap_stride;
2452 }
2453
2454 /* ----------- Vertical Interpolation ---------------- */
2455 pi4_ref_array = (WORD32 *) ps_ctxt->pi2_refarray_buffer;
2456 ps_pos_phase = ps_lyr_ctxt->s_chroma_map_ctxt.ps_y_pos_phase;
2457 i4_phase1 = ps_pos_phase[0].i2_phase;
2458 i4_phase2 = (i4_phase1 + 8) & 0x0F;
2459
2460 /* interchange the phase values for corner case */
2461 if(0 != i4_chrm_vert_int_mode)
2462 {
2463 WORD32 i4_temp;
2464 i4_temp = i4_phase1;
2465 i4_phase1 = i4_phase2;
2466 i4_phase2 = i4_temp;
2467 }
2468
2469 for(i4_i = 0; i4_i < BLOCK_WIDTH; i4_i++)
2470 {
2471 WORD16 *pi2_out;
2472 WORD32 *pi4_ref_array_temp;
2473 WORD32 i4_horz_samp_1, i4_horz_samp_2;
2474 pi2_out = pi2_out_res;
2475 pi4_ref_array_temp = pi4_ref_array;
2476
2477 /* populate the first inter sample */
2478 i4_horz_samp_1 = *pi4_ref_array_temp;
2479 pi4_ref_array_temp += BLOCK_WIDTH;
2480
2481 if(1 != i4_chrm_vert_int_mode)
2482 {
2483 *pi2_out = (i4_horz_samp_1 + 8) >> 4;
2484 pi2_out += i4_out_res_stride;
2485 }
2486
2487 if(2 == i4_chrm_vert_int_mode)
2488 {
2489 i4_horz_samp_1 = *pi4_ref_array_temp;
2490 pi4_ref_array_temp += BLOCK_WIDTH;
2491 *pi2_out = (i4_horz_samp_1 + 8) >> 4;
2492 pi2_out += i4_out_res_stride;
2493 }
2494
2495 {
2496 /* unroll count 1 */
2497 i4_horz_samp_2 = *pi4_ref_array_temp;
2498 pi4_ref_array_temp += BLOCK_WIDTH;
2499
2500 /* populate 2 samples based on current coeffs */
2501 *pi2_out =
2502 ((16 - i4_phase2) * i4_horz_samp_1 + i4_phase2 * i4_horz_samp_2 + 128) >> 8;
2503 pi2_out += i4_out_res_stride;
2504
2505 /* unroll count 2 */
2506 *pi2_out =
2507 ((16 - i4_phase1) * i4_horz_samp_1 + i4_phase1 * i4_horz_samp_2 + 128) >> 8;
2508 pi2_out += i4_out_res_stride;
2509
2510 /* unroll count 3 */
2511 i4_horz_samp_1 = *pi4_ref_array_temp;
2512 pi4_ref_array_temp += BLOCK_WIDTH;
2513
2514 /* populate 2 samples based on current coeffs */
2515 *pi2_out =
2516 ((16 - i4_phase2) * i4_horz_samp_2 + i4_phase2 * i4_horz_samp_1 + 128) >> 8;
2517 pi2_out += i4_out_res_stride;
2518
2519 /* unroll count 4 */
2520 *pi2_out =
2521 ((16 - i4_phase1) * i4_horz_samp_2 + i4_phase1 * i4_horz_samp_1 + 128) >> 8;
2522 pi2_out += i4_out_res_stride;
2523
2524 /* unroll count 5 */
2525 i4_horz_samp_2 = *pi4_ref_array_temp;
2526
2527 /* populate 2 samples based on current coeffs */
2528 *pi2_out =
2529 ((16 - i4_phase2) * i4_horz_samp_1 + i4_phase2 * i4_horz_samp_2 + 128) >> 8;
2530 pi2_out += i4_out_res_stride;
2531
2532 /* unroll count 6 */
2533 *pi2_out =
2534 ((16 - i4_phase1) * i4_horz_samp_1 + i4_phase1 * i4_horz_samp_2 + 128) >> 8;
2535 pi2_out += i4_out_res_stride;
2536 }
2537
2538 if(2 != i4_chrm_vert_int_mode)
2539 {
2540 /* populate the last inter sample */
2541 *pi2_out = (i4_horz_samp_2 + 8) >> 4;
2542
2543 if(1 == i4_chrm_vert_int_mode)
2544 {
2545 pi2_out += i4_out_res_stride;
2546 pi4_ref_array_temp += BLOCK_WIDTH;
2547 i4_horz_samp_1 = *pi4_ref_array_temp;
2548
2549 /* populate the last inter sample */
2550 *pi2_out = (i4_horz_samp_1 + 8) >> 4;
2551 }
2552 }
2553
2554 /* horizontal loop updates */
2555 pi4_ref_array++;
2556 pi2_out_res++;
2557 }
2558 }
2559 return;
2560 }
2561 /*****************************************************************************/
2562 /* */
2563 /* Function Name : svcd_residual_chroma_dyadic */
2564 /* */
2565 /* Description : this fucntion does the upsampling of chroma residuals for*/
2566 /* Dyadic cases */
2567 /* */
2568 /* Inputs : pv_residual_samp_ctxt : Residual upsampling context */
2569 /* pu1_inp_data : input 8 bit data pointer */
2570 /* i4_inp_data_stride : input buffer stride */
2571 /* pi2_out_res : output 16 bit buffer pointer */
2572 /* i4_out_res_stride : Output buffer stride */
2573 /* pu1_inp_bitmap : input packed sign bit data pointer */
2574 /* i4_inp_bitmap_stride : sign bit buffer stride */
2575 /* i4_start_bit_pos : bit position in the byte of packed */
2576 /* sign values */
2577 /* Globals : none */
2578 /* Processing : it does the upsampling with intial phase values */
2579 /* */
2580 /* Outputs : Upsampled residuals for chroma */
2581 /* Returns : none */
2582 /* */
2583 /* Issues : none */
2584 /* */
2585 /* Revision History: */
2586 /* */
2587 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
2588 /* 25 09 2010 vijayakumar creation */
2589 /* */
2590 /*****************************************************************************/
svcd_residual_chroma_dyadic(void * pv_residual_samp_ctxt,UWORD8 * pu1_inp_data,WORD32 i4_inp_data_stride,WORD16 * pi2_out_res,WORD32 i4_out_res_stride,UWORD8 * pu1_inp_bitmap,WORD32 i4_inp_bitmap_stride,WORD32 i4_start_bit_pos)2591 void svcd_residual_chroma_dyadic(void *pv_residual_samp_ctxt, UWORD8 *pu1_inp_data,
2592 WORD32 i4_inp_data_stride, WORD16 *pi2_out_res,
2593 WORD32 i4_out_res_stride, UWORD8 *pu1_inp_bitmap,
2594 WORD32 i4_inp_bitmap_stride, WORD32 i4_start_bit_pos)
2595 {
2596 residual_sampling_ctxt_t *ps_ctxt;
2597 res_lyr_ctxt *ps_lyr_ctxt;
2598 ps_ctxt = (residual_sampling_ctxt_t *) pv_residual_samp_ctxt;
2599 ps_lyr_ctxt = &ps_ctxt->as_res_lyrs[ps_ctxt->i4_res_lyr_id];
2600 /* ----------------- Processing ------------------------------- */
2601 {
2602 WORD32 i4_i;
2603 UWORD8 *pu1_ref_data_byte, *pu1_ref_sign_byte;
2604 WORD32 *pi4_ref_array;
2605 ref_pixel_map_t *ps_pos_phase;
2606 WORD32 i4_phase1, i4_phase2;
2607
2608 pu1_ref_data_byte = pu1_inp_data;
2609 pu1_ref_sign_byte = pu1_inp_bitmap;
2610 ps_pos_phase = ps_lyr_ctxt->s_chroma_map_ctxt.ps_x_pos_phase;
2611
2612 /* ----------- Horizontal Interpolation ---------------- */
2613 pi4_ref_array = (WORD32 *) ps_ctxt->pi2_refarray_buffer;
2614 i4_phase1 = ps_pos_phase[0].i2_phase;
2615 i4_phase2 = (i4_phase1 + 8) & 0x0F;
2616
2617 for(i4_i = 0; i4_i < SUB_BLOCK_HEIGHT; i4_i++)
2618 {
2619 WORD16 i2_coeff1, i2_coeff2;
2620 UWORD8 u1_sign;
2621 UWORD8 u1_sign_byte = *pu1_ref_sign_byte;
2622
2623 i2_coeff1 = (WORD16) (pu1_ref_data_byte[0]);
2624 u1_sign = (UWORD8) GET_BIT(u1_sign_byte, i4_start_bit_pos);
2625
2626 /* if signed number */
2627 if(u1_sign)
2628 {
2629 i2_coeff1 |= 0xFF00;
2630 }
2631
2632 /* populate the first inter sample */
2633 *pi4_ref_array++ = i2_coeff1 << 4;
2634
2635 {
2636 /* unroll count 1 */
2637 i2_coeff2 = (WORD16) (pu1_ref_data_byte[1]);
2638 u1_sign = (UWORD8) GET_BIT(u1_sign_byte, (i4_start_bit_pos + 1));
2639
2640 /* if signed number */
2641 if(u1_sign)
2642 {
2643 i2_coeff2 |= 0xFF00;
2644 }
2645
2646 /* populate 2 samples based on current coeffs */
2647 *pi4_ref_array++ = ((16 - i4_phase2) * i2_coeff1 + i4_phase2 * i2_coeff2);
2648
2649 /* unroll count 2 */
2650 *pi4_ref_array++ = ((16 - i4_phase1) * i2_coeff1 + i4_phase1 * i2_coeff2);
2651
2652 /* unroll count 3 */
2653 i2_coeff1 = (WORD16) (pu1_ref_data_byte[2]);
2654 u1_sign = (UWORD8) GET_BIT(u1_sign_byte, (i4_start_bit_pos + 2));
2655
2656 /* if signed number */
2657 if(u1_sign)
2658 {
2659 i2_coeff1 |= 0xFF00;
2660 }
2661
2662 /* populate 2 samples based on current coeffs */
2663 *pi4_ref_array++ = ((16 - i4_phase2) * i2_coeff2 + i4_phase2 * i2_coeff1);
2664
2665 /* unroll count 4 */
2666 *pi4_ref_array++ = ((16 - i4_phase1) * i2_coeff2 + i4_phase1 * i2_coeff1);
2667
2668 /* unroll count 5 */
2669 i2_coeff2 = (WORD16) (pu1_ref_data_byte[3]);
2670 u1_sign = (UWORD8) GET_BIT(u1_sign_byte, (i4_start_bit_pos + 3));
2671
2672 /* if signed number */
2673 if(u1_sign)
2674 {
2675 i2_coeff2 |= 0xFF00;
2676 }
2677
2678 /* populate 2 samples based on current coeffs */
2679 *pi4_ref_array++ = ((16 - i4_phase2) * i2_coeff1 + i4_phase2 * i2_coeff2);
2680
2681 /* unroll count 6 */
2682 *pi4_ref_array++ = ((16 - i4_phase1) * i2_coeff1 + i4_phase1 * i2_coeff2);
2683 }
2684
2685 /* populate the last inter sample */
2686 *pi4_ref_array++ = i2_coeff2 << 4;
2687
2688 /* vertical loop uopdates */
2689 pu1_ref_data_byte = pu1_inp_data + ((i4_i + 1) * i4_inp_data_stride);
2690 pu1_ref_sign_byte += i4_inp_bitmap_stride;
2691 }
2692
2693 /* ----------- Vertical Interpolation ---------------- */
2694 pi4_ref_array = (WORD32 *) ps_ctxt->pi2_refarray_buffer;
2695 ps_pos_phase = ps_lyr_ctxt->s_chroma_map_ctxt.ps_y_pos_phase;
2696 i4_phase1 = ps_pos_phase[0].i2_phase;
2697 i4_phase2 = (i4_phase1 + 8) & 0x0F;
2698
2699 for(i4_i = 0; i4_i < BLOCK_WIDTH; i4_i++)
2700 {
2701 WORD16 *pi2_out;
2702 WORD32 *pi4_ref_array_temp;
2703 WORD32 i4_horz_samp_1, i4_horz_samp_2;
2704 pi2_out = pi2_out_res;
2705 pi4_ref_array_temp = pi4_ref_array;
2706
2707 /* populate the first inter sample */
2708 i4_horz_samp_1 = *pi4_ref_array_temp;
2709 pi4_ref_array_temp += BLOCK_WIDTH;
2710 *pi2_out = (i4_horz_samp_1 + 8) >> 4;
2711 pi2_out += i4_out_res_stride;
2712
2713 {
2714 /* unroll count 1 */
2715 i4_horz_samp_2 = *pi4_ref_array_temp;
2716 pi4_ref_array_temp += BLOCK_WIDTH;
2717
2718 /* populate 2 samples based on current coeffs */
2719 *pi2_out =
2720 ((16 - i4_phase2) * i4_horz_samp_1 + i4_phase2 * i4_horz_samp_2 + 128) >> 8;
2721 pi2_out += i4_out_res_stride;
2722
2723 /* unroll count 2 */
2724 *pi2_out =
2725 ((16 - i4_phase1) * i4_horz_samp_1 + i4_phase1 * i4_horz_samp_2 + 128) >> 8;
2726 pi2_out += i4_out_res_stride;
2727
2728 /* unroll count 3 */
2729 i4_horz_samp_1 = *pi4_ref_array_temp;
2730 pi4_ref_array_temp += BLOCK_WIDTH;
2731
2732 /* populate 2 samples based on current coeffs */
2733 *pi2_out =
2734 ((16 - i4_phase2) * i4_horz_samp_2 + i4_phase2 * i4_horz_samp_1 + 128) >> 8;
2735 pi2_out += i4_out_res_stride;
2736
2737 /* unroll count 4 */
2738 *pi2_out =
2739 ((16 - i4_phase1) * i4_horz_samp_2 + i4_phase1 * i4_horz_samp_1 + 128) >> 8;
2740 pi2_out += i4_out_res_stride;
2741
2742 /* unroll count 5 */
2743 i4_horz_samp_2 = *pi4_ref_array_temp;
2744
2745 /* populate 2 samples based on current coeffs */
2746 *pi2_out =
2747 ((16 - i4_phase2) * i4_horz_samp_1 + i4_phase2 * i4_horz_samp_2 + 128) >> 8;
2748 pi2_out += i4_out_res_stride;
2749
2750 /* unroll count 6 */
2751 *pi2_out =
2752 ((16 - i4_phase1) * i4_horz_samp_1 + i4_phase1 * i4_horz_samp_2 + 128) >> 8;
2753 pi2_out += i4_out_res_stride;
2754 }
2755
2756 /* populate the last inter sample */
2757 *pi2_out = (i4_horz_samp_2 + 8) >> 4;
2758
2759 /* horizontal loop updates */
2760 pi4_ref_array++;
2761 pi2_out_res++;
2762 }
2763 }
2764 return;
2765 }
2766
2767 /*****************************************************************************/
2768 /* */
2769 /* Function Name : svcd_residual_luma_dyadic */
2770 /* */
2771 /* Description : this fucntion does the upsampling of luma residuals for */
2772 /* Dyadic cases */
2773 /* */
2774 /* Inputs : pv_residual_samp_ctxt : Residual upsampling context */
2775 /* pu1_inp_data : input 8 bit data pointer */
2776 /* i4_inp_data_stride : input buffer stride */
2777 /* pi2_out_res : output 16 bit buffer pointer */
2778 /* i4_out_res_stride : Output buffer stride */
2779 /* pu1_inp_bitmap : input packed sign bit data pointer */
2780 /* i4_inp_bitmap_stride : sign bit buffer stride */
2781 /* ps_ref_mb_mode : reference mb mode pointer of base layer */
2782 /* ps_coord : mb co-ordinate pointer */
2783 /* Globals : none */
2784 /* Processing : it does the upsampling with fixed phase values and */
2785 /* reference layer transform size */
2786 /* Outputs : Upsampled residuals for luma */
2787 /* Returns : none */
2788 /* */
2789 /* Issues : none */
2790 /* */
2791 /* Revision History: */
2792 /* */
2793 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
2794 /* 25 09 2010 vijayakumar creation */
2795 /* */
2796 /*****************************************************************************/
svcd_residual_luma_dyadic(void * pv_residual_samp_ctxt,UWORD8 * pu1_inp_data,WORD32 i4_inp_data_stride,WORD16 * pi2_out_res,WORD32 i4_out_res_stride,UWORD8 * pu1_inp_bitmap,WORD32 i4_inp_bitmap_stride,mem_element_t * ps_ref_mb_mode,UWORD16 u2_mb_x,UWORD16 u2_mb_y,WORD32 i4_ref_nnz,WORD32 i4_ref_tx_size)2797 void svcd_residual_luma_dyadic(void *pv_residual_samp_ctxt, UWORD8 *pu1_inp_data,
2798 WORD32 i4_inp_data_stride, WORD16 *pi2_out_res,
2799 WORD32 i4_out_res_stride, UWORD8 *pu1_inp_bitmap,
2800 WORD32 i4_inp_bitmap_stride, mem_element_t *ps_ref_mb_mode,
2801 UWORD16 u2_mb_x, UWORD16 u2_mb_y, WORD32 i4_ref_nnz,
2802 WORD32 i4_ref_tx_size)
2803
2804 {
2805 WORD16 *pi2_refarray_buffer;
2806 WORD32 i4_start_bit_pos = 0;
2807 WORD32 i4_blk_ctr;
2808 residual_sampling_ctxt_t *ps_ctxt;
2809
2810 ps_ctxt = (residual_sampling_ctxt_t *) pv_residual_samp_ctxt;
2811 pi2_refarray_buffer = ps_ctxt->pi2_refarray_buffer;
2812
2813 /* based on transform size the counter and interpolation width and */
2814 /* height are intialised as follows */
2815
2816 if((i4_ref_tx_size) && (0 != i4_ref_nnz))
2817 {
2818 UWORD8 *pu1_ref_data_byte, *pu1_ref_sign_byte;
2819 WORD32 *pi4_ref_array;
2820 WORD32 i4_i, i4_j;
2821
2822 pu1_ref_data_byte = pu1_inp_data;
2823 pu1_ref_sign_byte = pu1_inp_bitmap;
2824
2825 /* ----------- Horizontal Interpolation ---------------- */
2826 pi4_ref_array = (WORD32 *) pi2_refarray_buffer;
2827
2828 for(i4_i = 0; i4_i < BLOCK_HEIGHT; i4_i++)
2829 {
2830 WORD16 i2_coeff1, i2_coeff2;
2831 UWORD8 u1_sign;
2832 WORD32 i4_bit_pos = i4_start_bit_pos;
2833 UWORD8 u1_sign_byte = *pu1_ref_sign_byte;
2834
2835 i2_coeff1 = (WORD16) (*pu1_ref_data_byte++);
2836 u1_sign = (UWORD8) GET_BIT(u1_sign_byte, i4_bit_pos);
2837
2838 /* if signed number */
2839 if(u1_sign)
2840 {
2841 i2_coeff1 |= 0xFF00;
2842 }
2843
2844 /* populate the first inter sample */
2845 *pi4_ref_array++ = i2_coeff1 << 2;
2846
2847 for(i4_j = 0; i4_j < 14; i4_j += 2)
2848 {
2849 i4_bit_pos++;
2850 i2_coeff2 = (WORD16) (*pu1_ref_data_byte++);
2851 u1_sign = (UWORD8) GET_BIT(u1_sign_byte, i4_bit_pos);
2852
2853 /* if signed number */
2854 if(u1_sign)
2855 {
2856 i2_coeff2 |= 0xFF00;
2857 }
2858
2859 /* populate 2 samples based on current coeffs */
2860 *pi4_ref_array++ = ((i2_coeff1 << 1) + (i2_coeff1) + (i2_coeff2));
2861
2862 *pi4_ref_array++ = ((i2_coeff2 << 1) + (i2_coeff2) + (i2_coeff1));
2863
2864 /* store the coeff 2 to coeff 1 */
2865 /* (used in next iteration) */
2866 i2_coeff1 = i2_coeff2;
2867 }
2868
2869 /* populate the last inter sample */
2870 *pi4_ref_array++ = i2_coeff1 << 2;
2871
2872 /* vertical loop uopdates */
2873 pu1_ref_data_byte = pu1_inp_data + ((i4_i + 1) * i4_inp_data_stride);
2874 pu1_ref_sign_byte += i4_inp_bitmap_stride;
2875 }
2876
2877 /* ----------- Vertical Interpolation ---------------- */
2878 pi4_ref_array = (WORD32 *) pi2_refarray_buffer;
2879
2880 for(i4_i = 0; i4_i < MB_WIDTH; i4_i++)
2881 {
2882 WORD32 *pi4_ref_array_temp;
2883 WORD16 *pi2_out;
2884 WORD32 i4_horz_samp_1, i4_horz_samp_2;
2885
2886 pi4_ref_array_temp = pi4_ref_array;
2887 pi2_out = pi2_out_res;
2888 i4_horz_samp_1 = *pi4_ref_array_temp;
2889
2890 /* populate the first inter sample */
2891 *pi2_out = (i4_horz_samp_1 + 2) >> 2;
2892 pi2_out += i4_out_res_stride;
2893
2894 for(i4_j = 0; i4_j < 14; i4_j += 2)
2895 {
2896 pi4_ref_array_temp += MB_WIDTH;
2897 i4_horz_samp_2 = *pi4_ref_array_temp;
2898
2899 /* populate 2 samples based on current coeffs */
2900 *pi2_out = ((i4_horz_samp_1 << 1) + (i4_horz_samp_1) + (i4_horz_samp_2) + 8) >> 4;
2901 pi2_out += i4_out_res_stride;
2902
2903 *pi2_out = ((i4_horz_samp_2 << 1) + (i4_horz_samp_2) + (i4_horz_samp_1) + 8) >> 4;
2904 pi2_out += i4_out_res_stride;
2905
2906 /* store the coeff 2 to coeff 1 */
2907 /* (used in next iteration) */
2908 i4_horz_samp_1 = i4_horz_samp_2;
2909 }
2910
2911 /* populate the first inter sample */
2912 *pi2_out = (i4_horz_samp_1 + 2) >> 2;
2913
2914 /* horizontal loop updates */
2915 pi4_ref_array++;
2916 pi2_out_res++;
2917 }
2918 }
2919 else
2920 {
2921 /* ----------------------------------------------------------------- */
2922 /* LOOP over number of blocks */
2923 /* ----------------------------------------------------------------- */
2924 for(i4_blk_ctr = 0; i4_blk_ctr < 4; i4_blk_ctr++)
2925 {
2926 UWORD8 *pu1_ref_data_byte, *pu1_ref_sign_byte;
2927 WORD32 *pi4_ref_array;
2928 WORD32 i4_i;
2929
2930 /* if reference layer is not coded then no processing */
2931 if(0 != (i4_ref_nnz & 0x1))
2932 {
2933 pu1_ref_data_byte = pu1_inp_data;
2934 pu1_ref_sign_byte = pu1_inp_bitmap;
2935
2936 /* ----------- Horizontal Interpolation ---------------- */
2937 pi4_ref_array = (WORD32 *) pi2_refarray_buffer;
2938
2939 for(i4_i = 0; i4_i < SUB_BLOCK_HEIGHT; i4_i++)
2940 {
2941 WORD16 i2_coeff1, i2_coeff2;
2942 UWORD8 u1_sign;
2943 WORD32 i4_bit_pos = i4_start_bit_pos;
2944 UWORD8 u1_sign_byte = *pu1_ref_sign_byte;
2945 ;
2946
2947 i2_coeff1 = (WORD16) (*pu1_ref_data_byte++);
2948 u1_sign = (UWORD8) GET_BIT(u1_sign_byte, i4_bit_pos);
2949
2950 /* if signed number */
2951 if(u1_sign)
2952 {
2953 i2_coeff1 |= 0xFF00;
2954 }
2955
2956 /* populate the first inter sample */
2957 *pi4_ref_array++ = i2_coeff1 << 2;
2958
2959 {
2960 /* unroll count 1 */
2961 i4_bit_pos++;
2962 i2_coeff2 = (WORD16) (*pu1_ref_data_byte++);
2963 u1_sign = (UWORD8) GET_BIT(u1_sign_byte, i4_bit_pos);
2964
2965 /* if signed number */
2966 if(u1_sign)
2967 {
2968 i2_coeff2 |= 0xFF00;
2969 }
2970
2971 /* populate 2 samples based on current coeffs */
2972 *pi4_ref_array++ = ((i2_coeff1 << 1) + (i2_coeff1) + (i2_coeff2));
2973
2974 *pi4_ref_array++ = ((i2_coeff2 << 1) + (i2_coeff2) + (i2_coeff1));
2975
2976 /* unroll count 2 */
2977 i4_bit_pos++;
2978 i2_coeff1 = (WORD16) (*pu1_ref_data_byte++);
2979 u1_sign = (UWORD8) GET_BIT(u1_sign_byte, i4_bit_pos);
2980
2981 /* if signed number */
2982 if(u1_sign)
2983 {
2984 i2_coeff1 |= 0xFF00;
2985 }
2986
2987 /* populate 2 samples based on current coeffs */
2988 *pi4_ref_array++ = ((i2_coeff2 << 1) + (i2_coeff2) + (i2_coeff1));
2989
2990 *pi4_ref_array++ = ((i2_coeff1 << 1) + (i2_coeff1) + (i2_coeff2));
2991
2992 /* unroll count 3 */
2993 i4_bit_pos++;
2994 i2_coeff2 = (WORD16) (*pu1_ref_data_byte++);
2995 u1_sign = (UWORD8) GET_BIT(u1_sign_byte, i4_bit_pos);
2996
2997 /* if signed number */
2998 if(u1_sign)
2999 {
3000 i2_coeff2 |= 0xFF00;
3001 }
3002
3003 /* populate 2 samples based on current coeffs */
3004 *pi4_ref_array++ = ((i2_coeff1 << 1) + (i2_coeff1) + (i2_coeff2));
3005
3006 *pi4_ref_array++ = ((i2_coeff2 << 1) + (i2_coeff2) + (i2_coeff1));
3007 }
3008
3009 /* populate the last inter sample */
3010 *pi4_ref_array++ = i2_coeff2 << 2;
3011
3012 /* vertical loop uopdates */
3013 pu1_ref_data_byte = pu1_inp_data + ((i4_i + 1) * i4_inp_data_stride);
3014 pu1_ref_sign_byte += i4_inp_bitmap_stride;
3015 }
3016
3017 /* ----------- Vertical Interpolation ---------------- */
3018 pi4_ref_array = (WORD32 *) pi2_refarray_buffer;
3019
3020 for(i4_i = 0; i4_i < BLOCK_WIDTH; i4_i++)
3021 {
3022 WORD32 *pi4_ref_array_temp;
3023 WORD16 *pi2_out;
3024 WORD32 i4_horz_samp_1, i4_horz_samp_2;
3025
3026 pi4_ref_array_temp = pi4_ref_array;
3027 pi2_out = pi2_out_res;
3028 i4_horz_samp_1 = *pi4_ref_array_temp;
3029
3030 /* populate the first inter sample */
3031 *pi2_out = (i4_horz_samp_1 + 2) >> 2;
3032 pi2_out += i4_out_res_stride;
3033
3034 {
3035 /* unroll loop count 1 */
3036 pi4_ref_array_temp += BLOCK_WIDTH;
3037 i4_horz_samp_2 = *pi4_ref_array_temp;
3038
3039 /* populate 2 samples based on current coeffs */
3040 *pi2_out =
3041 ((i4_horz_samp_1 << 1) + (i4_horz_samp_1) + (i4_horz_samp_2) + 8) >> 4;
3042 pi2_out += i4_out_res_stride;
3043
3044 *pi2_out =
3045 ((i4_horz_samp_2 << 1) + (i4_horz_samp_2) + (i4_horz_samp_1) + 8) >> 4;
3046 pi2_out += i4_out_res_stride;
3047
3048 /* unroll loop count 2 */
3049 pi4_ref_array_temp += BLOCK_WIDTH;
3050 i4_horz_samp_1 = *pi4_ref_array_temp;
3051
3052 /* populate 2 samples based on current coeffs */
3053 *pi2_out =
3054 ((i4_horz_samp_2 << 1) + (i4_horz_samp_2) + (i4_horz_samp_1) + 8) >> 4;
3055 pi2_out += i4_out_res_stride;
3056
3057 *pi2_out =
3058 ((i4_horz_samp_1 << 1) + (i4_horz_samp_1) + (i4_horz_samp_2) + 8) >> 4;
3059 pi2_out += i4_out_res_stride;
3060
3061 /* unroll loop count 3 */
3062 pi4_ref_array_temp += BLOCK_WIDTH;
3063 i4_horz_samp_2 = *pi4_ref_array_temp;
3064
3065 /* populate 2 samples based on current coeffs */
3066 *pi2_out =
3067 ((i4_horz_samp_1 << 1) + (i4_horz_samp_1) + (i4_horz_samp_2) + 8) >> 4;
3068 pi2_out += i4_out_res_stride;
3069
3070 *pi2_out =
3071 ((i4_horz_samp_2 << 1) + (i4_horz_samp_2) + (i4_horz_samp_1) + 8) >> 4;
3072 pi2_out += i4_out_res_stride;
3073 }
3074
3075 /* populate the last inter sample */
3076 *pi2_out = (i4_horz_samp_2 + 2) >> 2;
3077
3078 /* horizontal loop updates */
3079 pi4_ref_array++;
3080 pi2_out_res++;
3081 }
3082 }
3083 else
3084 {
3085 pi2_out_res += BLOCK_WIDTH;
3086 }
3087
3088 /* Block level loop updates */
3089 if(1 == i4_blk_ctr)
3090 {
3091 i4_start_bit_pos = 0;
3092 pu1_inp_data -= SUB_BLOCK_WIDTH;
3093 pu1_inp_data += (i4_inp_data_stride * SUB_BLOCK_HEIGHT);
3094 pi2_out_res -= MB_WIDTH;
3095 pi2_out_res += (i4_out_res_stride * BLOCK_HEIGHT);
3096 pu1_inp_bitmap += (i4_inp_bitmap_stride * SUB_BLOCK_HEIGHT);
3097 i4_ref_nnz >>= 2;
3098 }
3099 else
3100 {
3101 pu1_inp_data += SUB_BLOCK_WIDTH;
3102 i4_start_bit_pos = SUB_BLOCK_WIDTH;
3103 }
3104
3105 i4_ref_nnz >>= 1;
3106 } /* end of loop over all the blocks */
3107 }
3108 return;
3109 }
3110 /*****************************************************************************/
3111 /* */
3112 /* Function Name : svcd_residual_samp_mb_dyadic */
3113 /* */
3114 /* Description : MB level function whcih perform the residual resampling */
3115 /* of data of an MB (luma and chroma insclusive) */
3116 /* for Dyadic cases */
3117 /* Inputs : pv_residual_samp_ctxt : residual sampling context */
3118 /* ps_ref_luma : reference layer luma data buffer desc */
3119 /* ps_ref_chroma : reference layer chroma data buffer desc */
3120 /* ps_ref_luma_bitmap : ref layer luma bit map buffer desc */
3121 /* ps_ref_chroma_bitmap : ref layer chroma bit map buff des */
3122 /* ps_ref_mb_mode : ref layer mb mode map buff desc */
3123 /* ps_out_luma : current layer out luma buffer desc */
3124 /* ps_out_chroma : current layer out chroma buffer desc */
3125 /* x,y : current mb coorinate */
3126 /* Globals : none */
3127 /* Processing : it calls the reference layer construction followed by */
3128 /* interplaotion function for luma and cb and cr */
3129 /* Outputs : inter resampled data of current MB */
3130 /* Returns : none */
3131 /* */
3132 /* Issues : none */
3133 /* */
3134 /* Revision History: */
3135 /* */
3136 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
3137 /* 26 06 2009 vijayakumar creation */
3138 /* */
3139 /*****************************************************************************/
svcd_residual_samp_mb_dyadic(void * pv_residual_samp_ctxt,mem_element_t * ps_ref_luma,mem_element_t * ps_ref_chroma,mem_element_t * ps_ref_luma_bitmap,mem_element_t * ps_ref_chroma_bitmap,mem_element_t * ps_ref_mb_mode,mem_element_t * ps_out_luma,mem_element_t * ps_out_chroma,UWORD16 u2_mb_x,UWORD16 u2_mb_y)3140 void svcd_residual_samp_mb_dyadic(void *pv_residual_samp_ctxt, mem_element_t *ps_ref_luma,
3141 mem_element_t *ps_ref_chroma, mem_element_t *ps_ref_luma_bitmap,
3142 mem_element_t *ps_ref_chroma_bitmap,
3143 mem_element_t *ps_ref_mb_mode, mem_element_t *ps_out_luma,
3144 mem_element_t *ps_out_chroma, UWORD16 u2_mb_x, UWORD16 u2_mb_y)
3145 {
3146 residual_sampling_ctxt_t *ps_ctxt;
3147 res_lyr_ctxt *ps_lyr_ctxt;
3148 /* --------------------------------------------------------------------- */
3149 /* I/O buffer params */
3150 /* --------------------------------------------------------------------- */
3151 UWORD8 *pu1_inp;
3152 UWORD8 *pu1_inp_bitmap;
3153 WORD16 *pi2_out;
3154 WORD32 i4_inp_stride;
3155 WORD32 i4_inp_bitmap_stride;
3156 WORD32 i4_out_stride;
3157 WORD32 i4_bit_pos = 0;
3158 WORD32 i4_luma_nnz;
3159 WORD32 i4_chroma_nnz;
3160 WORD32 i4_tx_size;
3161
3162 ps_ctxt = (residual_sampling_ctxt_t *) pv_residual_samp_ctxt;
3163 ps_lyr_ctxt = &ps_ctxt->as_res_lyrs[ps_ctxt->i4_res_lyr_id];
3164
3165 /* --------------------------------------------------------------------- */
3166 /* LUMA PROCESSING */
3167 /* --------------------------------------------------------------------- */
3168 pu1_inp = (UWORD8 *) ps_ref_luma->pv_buffer;
3169 pu1_inp_bitmap = (UWORD8 *) ps_ref_luma_bitmap->pv_buffer;
3170 pi2_out = (WORD16 *) ps_out_luma->pv_buffer;
3171
3172 i4_inp_stride = ps_ref_luma->i4_num_element_stride;
3173 i4_inp_bitmap_stride = ps_ref_luma_bitmap->i4_num_element_stride;
3174 i4_out_stride = ps_out_luma->i4_num_element_stride;
3175
3176 /* set the output buffer to 0 since not all block will be upsampled */
3177 svcd_2d_memset(pi2_out, (MB_WIDTH << 1), MB_HEIGHT, (i4_out_stride << 1), 0);
3178
3179 {
3180 WORD32 i4_offset_x, i4_offset_y;
3181 residual_samp_map_ctxt_t *ps_luma_map;
3182 ref_mb_map_t *ps_x_off_len_luma;
3183 ref_mb_map_t *ps_y_off_len_luma;
3184
3185 ps_luma_map = &ps_lyr_ctxt->s_luma_map_ctxt;
3186 ps_x_off_len_luma = ps_luma_map->ps_x_offset_length;
3187 ps_y_off_len_luma = ps_luma_map->ps_y_offset_length;
3188
3189 /* get the actual offset for the buffers */
3190 i4_offset_x = ps_x_off_len_luma[u2_mb_x].i2_offset;
3191 i4_offset_y = ps_y_off_len_luma[u2_mb_y].i2_offset;
3192
3193 {
3194 inter_lyr_mb_prms_t *ps_inter_lyr_mb_prms;
3195 WORD32 i4_mb_x, i4_mb_y;
3196 UWORD16 u2_luma_mask = 0x0033;
3197 UWORD8 u1_chrm_mask = 0x11;
3198 WORD32 i4_luma_rt_sft_amt = 0;
3199 WORD32 i4_chrm_rt_sft_amt = 0;
3200
3201 i4_mb_x = ((i4_offset_x + 1) >> MB_WIDTH_SHIFT);
3202 i4_mb_y = ((i4_offset_y + 1) >> MB_HEIGHT_SHIFT);
3203
3204 /* get the location of the byte which has the current mb mode */
3205 ps_inter_lyr_mb_prms = (inter_lyr_mb_prms_t *) ps_ref_mb_mode->pv_buffer;
3206 ps_inter_lyr_mb_prms += i4_mb_x;
3207 ps_inter_lyr_mb_prms += i4_mb_y * ps_ref_mb_mode->i4_num_element_stride;
3208
3209 /* get the approp block in base layer in horz direction */
3210 if(0 != ((i4_offset_x + 1) & 15))
3211 {
3212 u2_luma_mask <<= 2;
3213 i4_luma_rt_sft_amt += 2;
3214
3215 u1_chrm_mask <<= 1;
3216 i4_chrm_rt_sft_amt += 1;
3217 }
3218 /* get the approp block in base layer in vert direction */
3219 if(0 != ((i4_offset_y + 1) & 15))
3220 {
3221 u2_luma_mask <<= 8;
3222 i4_luma_rt_sft_amt += 8;
3223
3224 u1_chrm_mask <<= 2;
3225 i4_chrm_rt_sft_amt += 2;
3226 }
3227
3228 /* extract the nnz and store it */
3229 i4_luma_nnz = (ps_inter_lyr_mb_prms->u2_luma_nnz & u2_luma_mask) >> i4_luma_rt_sft_amt;
3230
3231 i4_chroma_nnz =
3232 (ps_inter_lyr_mb_prms->u1_chroma_nnz & u1_chrm_mask) >> i4_chrm_rt_sft_amt;
3233
3234 i4_tx_size = GET_BIT(ps_inter_lyr_mb_prms->i1_mb_mode, 1);
3235 }
3236
3237 /* since in dyadic case the window width and height will be 10x10 */
3238 /* and the window start offsets will be always 1 column left and */
3239 /* 1 row above the block boundary. so the pointer and the required */
3240 /* positions are appropriately modified */
3241 if(i4_offset_x >= 0)
3242 {
3243 pu1_inp++;
3244 pu1_inp_bitmap++;
3245 }
3246
3247 if(i4_offset_y >= 0)
3248 {
3249 pu1_inp += i4_inp_stride;
3250 pu1_inp_bitmap += i4_inp_bitmap_stride;
3251 }
3252
3253 svcd_residual_luma_dyadic(pv_residual_samp_ctxt, pu1_inp, i4_inp_stride, pi2_out,
3254 i4_out_stride, pu1_inp_bitmap, i4_inp_bitmap_stride,
3255 ps_ref_mb_mode, u2_mb_x, u2_mb_y, i4_luma_nnz, i4_tx_size);
3256 }
3257
3258 /* --------------------------------------------------------------------- */
3259 /* CHROMA PROCESSING */
3260 /* --------------------------------------------------------------------- */
3261 /* CB */
3262 pu1_inp = (UWORD8 *) ps_ref_chroma->pv_buffer;
3263 pu1_inp_bitmap = (UWORD8 *) ps_ref_chroma_bitmap->pv_buffer;
3264 pi2_out = (WORD16 *) ps_out_chroma->pv_buffer;
3265
3266 i4_inp_stride = ps_ref_chroma->i4_num_element_stride << 1;
3267 i4_inp_bitmap_stride = ps_ref_chroma_bitmap->i4_num_element_stride << 1;
3268 i4_out_stride = ps_out_chroma->i4_num_element_stride << 1;
3269
3270 /* set the output buffer to 0 since not all block will be upsampled */
3271 svcd_2d_memset(pi2_out, (BLOCK_WIDTH << 1), MB_HEIGHT, (i4_out_stride), 0);
3272
3273 /* choose the appropriate chroma processing routine */
3274 if(SVCD_FALSE == ps_lyr_ctxt->i4_chrm_alt_proc)
3275 {
3276 WORD32 i4_offset_x, i4_offset_y;
3277 residual_samp_map_ctxt_t *ps_chroma_map;
3278 ref_mb_map_t *ps_x_off_len_chroma;
3279 ref_mb_map_t *ps_y_off_len_chroma;
3280
3281 ps_chroma_map = &ps_lyr_ctxt->s_chroma_map_ctxt;
3282 ps_x_off_len_chroma = ps_chroma_map->ps_x_offset_length;
3283 ps_y_off_len_chroma = ps_chroma_map->ps_y_offset_length;
3284
3285 /* get the actual offset for the buffers */
3286 i4_offset_x = ps_x_off_len_chroma[u2_mb_x].i2_offset;
3287 i4_offset_y = ps_y_off_len_chroma[u2_mb_y].i2_offset;
3288
3289 /* since in dyadic case the window width and height will be 6x6 */
3290 /* and the window start offsets will be always 1 column left and */
3291 /* 1 row above the block boundary. so the pointer and the required */
3292 /* positions are appropriately modified */
3293 if(i4_offset_x >= 0)
3294 {
3295 pu1_inp++;
3296 if(0 == ((i4_offset_x + 1) & 7))
3297 {
3298 pu1_inp_bitmap++;
3299 }
3300 else
3301 {
3302 i4_bit_pos = 4;
3303 }
3304 }
3305
3306 if(i4_offset_y >= 0)
3307 {
3308 pu1_inp += i4_inp_stride;
3309 pu1_inp_bitmap += i4_inp_bitmap_stride;
3310 }
3311
3312 if(0 != (i4_chroma_nnz & 0x01))
3313 {
3314 svcd_residual_chroma_dyadic(pv_residual_samp_ctxt, pu1_inp, i4_inp_stride, pi2_out,
3315 i4_out_stride, pu1_inp_bitmap, i4_inp_bitmap_stride,
3316 i4_bit_pos);
3317 }
3318 }
3319 else
3320 {
3321 svcd_residual_chroma_dyadic_alt(pv_residual_samp_ctxt, u2_mb_x, u2_mb_y, ps_ref_mb_mode,
3322 pu1_inp, i4_inp_stride, pi2_out, i4_out_stride,
3323 pu1_inp_bitmap, i4_inp_bitmap_stride, SVCD_FALSE);
3324 }
3325
3326 /* CR */
3327 pu1_inp += (i4_inp_stride >> 1);
3328 pu1_inp_bitmap += (i4_inp_bitmap_stride >> 1);
3329 pi2_out += (i4_out_stride >> 1);
3330
3331 if(SVCD_FALSE == ps_lyr_ctxt->i4_chrm_alt_proc)
3332 {
3333 if(0 != (i4_chroma_nnz & 0x10))
3334 {
3335 svcd_residual_chroma_dyadic(pv_residual_samp_ctxt, pu1_inp, i4_inp_stride, pi2_out,
3336 i4_out_stride, pu1_inp_bitmap, i4_inp_bitmap_stride,
3337 i4_bit_pos);
3338 }
3339 }
3340 else
3341 {
3342 svcd_residual_chroma_dyadic_alt(pv_residual_samp_ctxt, u2_mb_x, u2_mb_y, ps_ref_mb_mode,
3343 pu1_inp, i4_inp_stride, pi2_out, i4_out_stride,
3344 pu1_inp_bitmap, i4_inp_bitmap_stride, SVCD_TRUE);
3345 }
3346 return;
3347 }
3348
3349 /*****************************************************************************/
3350 /* */
3351 /* Function Name : svc_intra_resamp_generate_segment_lookup */
3352 /* */
3353 /* Description : This function generates segment lookup used to derive */
3354 /* segments which have to be be intra resampled */
3355 /* */
3356 /* Inputs : pv_lookup_table : look up table */
3357 /* i4_dimension : dimension of the block which is used in*/
3358 /* resampling process. */
3359 /* i4_mb_size : size of the mb */
3360 /* Globals : None */
3361 /* Processing : This function generates segment lookup used to derive */
3362 /* segments which have to be be intra resampled */
3363 /* Outputs : none */
3364 /* Returns : none */
3365 /* */
3366 /* Issues : None */
3367 /* */
3368 /* Revision History: */
3369 /* */
3370 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
3371 /* 03 03 2011 A.D.Almeida Creation */
3372 /* */
3373 /*****************************************************************************/
svc_intra_resamp_generate_segment_lookup(seg_lookup_desc_t * ps_seg_lookup_table,WORD32 i4_dimension,WORD32 i4_mb_size,WORD32 i4_shift_val)3374 void svc_intra_resamp_generate_segment_lookup(seg_lookup_desc_t *ps_seg_lookup_table,
3375 WORD32 i4_dimension, WORD32 i4_mb_size,
3376 WORD32 i4_shift_val)
3377 {
3378 WORD32 i4_x;
3379 WORD32 i4_position, i4_dist_prev_mb, i4_dist_next_mb;
3380 UWORD8 u1_seg_dim;
3381 UWORD8 u1_num_sgmts;
3382 WORD32 i4_block_size = i4_mb_size >> 1;
3383 UWORD8 u1_offset = 0;
3384 seg_lookup_desc_t *ps_segments;
3385 seg_description_t *ps_seg_desc;
3386
3387 memset(ps_seg_lookup_table, 0, i4_mb_size * sizeof(seg_lookup_desc_t));
3388
3389 for(i4_x = 0; i4_x < i4_mb_size; i4_x++)
3390 {
3391 ps_segments = &ps_seg_lookup_table[i4_x];
3392 ps_seg_desc = ps_segments->s_segments;
3393 i4_position = i4_x;
3394
3395 if(i4_x >= i4_block_size)
3396 {
3397 /* set the fourth bit so that later it can be directly OR ed */
3398 ps_segments->u4_start_pos = 8;
3399 }
3400 else
3401 {
3402 ps_segments->u4_start_pos = 0;
3403 }
3404
3405 u1_num_sgmts = 0;
3406 u1_offset = 0;
3407
3408 while(i4_position < (i4_x + i4_dimension))
3409 {
3410 /* check and fill the nearest mb boundry flag */
3411 if((i4_position & (i4_mb_size - 1)) < i4_block_size)
3412 {
3413 ps_seg_desc->i1_nearst_mb_bdry = -1;
3414 }
3415 else
3416 {
3417 ps_seg_desc->i1_nearst_mb_bdry = 1;
3418 }
3419
3420 /* find the distance from the previous MB for start of segment*/
3421 i4_dist_prev_mb = (i4_position & (i4_mb_size - 1));
3422
3423 ps_seg_desc->i1_dist_idx =
3424 ((i4_dist_prev_mb >= i4_mb_size >> 1) ? (i4_mb_size - i4_dist_prev_mb)
3425 : -(i4_dist_prev_mb + 1));
3426
3427 /* find the size of the segment */
3428 u1_seg_dim = (i4_block_size - (i4_position & (i4_block_size - 1)));
3429 i4_position += u1_seg_dim;
3430 if(i4_position > (i4_x + i4_dimension))
3431 {
3432 i4_position = (i4_x + i4_dimension);
3433 u1_seg_dim = (i4_position & (i4_block_size - 1));
3434 }
3435
3436 /* find the distance from the next MB for end of segment */
3437 i4_dist_next_mb = (i4_position & (i4_mb_size - 1));
3438
3439 ps_seg_desc->u1_seg_dim = u1_seg_dim;
3440 ps_seg_desc->u1_seg_off = u1_offset;
3441
3442 /* check if the segment has a adjoining MB edge */
3443 if(i4_dist_prev_mb == 0)
3444 {
3445 if(0 == u1_num_sgmts)
3446 {
3447 ps_seg_desc->u1_mb_adjoin = 0;
3448 }
3449 else
3450 {
3451 ps_seg_desc->u1_mb_adjoin = 1 << i4_shift_val;
3452 }
3453 }
3454 else if(i4_dist_next_mb == 0)
3455 {
3456 if(i4_position == (i4_x + i4_dimension))
3457 {
3458 ps_seg_desc->u1_mb_adjoin = 0;
3459 }
3460 else
3461 {
3462 ps_seg_desc->u1_mb_adjoin = 1 << i4_shift_val;
3463 }
3464 }
3465 else
3466 {
3467 ps_seg_desc->u1_mb_adjoin = 0;
3468 }
3469
3470 /* Updations */
3471 u1_offset += u1_seg_dim;
3472 u1_num_sgmts++;
3473 ps_seg_desc++;
3474 }
3475
3476 /* fill the number of segments for this position */
3477 ps_segments->u1_num_segments = u1_num_sgmts;
3478 }
3479 }
3480
3481 /*****************************************************************************/
3482 /* */
3483 /* Function Name : svcd_intra_samp_populate_list */
3484 /* */
3485 /* Description : This is a seq or frame level init function which fills */
3486 /* all offsets, projected locations arrays based on */
3487 /* the two resolutions and cropping parameters */
3488 /* Inputs : refer ot doxygen comments below */
3489 /* Globals : none */
3490 /* Processing : it projects the locations and computes the values */
3491 /* */
3492 /* Outputs : none */
3493 /* Returns : none */
3494 /* */
3495 /* Issues : none */
3496 /* */
3497 /* Revision History: */
3498 /* */
3499 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
3500 /* 26 06 2009 vijayakumar creation */
3501 /* */
3502 /*****************************************************************************/
svcd_intra_samp_populate_list(intra_samp_map_ctxt_t * ps_map_ctxt,res_prms_t * ps_curr_res_prms,res_prms_t * ps_ref_res_prms,WORD32 i4_chroma_flag,dec_struct_t * ps_dec)3503 void svcd_intra_samp_populate_list(intra_samp_map_ctxt_t *ps_map_ctxt, res_prms_t *ps_curr_res_prms,
3504 res_prms_t *ps_ref_res_prms, WORD32 i4_chroma_flag,
3505 dec_struct_t *ps_dec)
3506 {
3507 /* --------------------------------------------------------------------- */
3508 /* Local variables required for finding the mapping between the layers */
3509 /* --------------------------------------------------------------------- */
3510 WORD32 i4_shift_x, i4_shift_y, i4_scale_x, i4_scale_y, i4_offset_x, i4_offset_y;
3511 WORD32 i4_add_x, i4_add_y, i4_delta_x, i4_delta_y, i4_refphase_x, i4_refphase_y;
3512 WORD32 i4_phase_x, i4_phase_y, i4_sub_wd, i4_sub_ht, i4_mb_wd, i4_mb_ht;
3513 WORD32 i4_horz_dim, i4_vert_dim, i4_tmp;
3514
3515 /* --------------------------------------------------------------------- */
3516 /* Local Pointer Declaration for arrays in Mapping context */
3517 /* --------------------------------------------------------------------- */
3518 ref_mb_map_t *ps_x_off_len, *ps_y_off_len;
3519 WORD32 i4_ref_wd, i4_ref_ht, i4_scaled_wd, i4_scaled_ht, i4_curr_lyr_width, i4_curr_lyr_height;
3520
3521 /* --------------------------------------------------------------------- */
3522 /* Local Flag Declaration */
3523 /* --------------------------------------------------------------------- */
3524 WORD32 i4_ref_layer_field_pic_flag, i4_field_pic_flag, i4_frame_mbs_only_flag;
3525 WORD32 i4_ref_layer_frame_Mbs_only_flag, i4_field_Mb_flag, i4_bot_field_flag;
3526
3527 /* --------------------------------------------------------------------- */
3528 /* Cropping Parameters Declaration */
3529 /* --------------------------------------------------------------------- */
3530 WORD32 i4_scaled_ref_layer_left_offset, i4_scaled_ref_layer_top_offset;
3531 WORD32 i4_scaled_ref_layer_right_offset, i4_scaled_ref_layer_bottom_offset;
3532 dec_seq_params_t *ps_sps;
3533 ps_sps = ps_dec->ps_cur_sps;
3534
3535 /* --------------------------------------------------------------------- */
3536 /* Hardcoding flag information (assuming no field support) */
3537 /* --------------------------------------------------------------------- */
3538 i4_ref_layer_field_pic_flag = SVCD_FALSE;
3539 i4_field_pic_flag = SVCD_FALSE;
3540 i4_frame_mbs_only_flag = SVCD_TRUE;
3541 i4_field_Mb_flag = SVCD_FALSE;
3542 i4_bot_field_flag = SVCD_FALSE;
3543 i4_ref_layer_frame_Mbs_only_flag = SVCD_TRUE;
3544 i4_horz_dim = 0;
3545 i4_vert_dim = 0;
3546
3547 /* --------------------------------------------------------------------- */
3548 /* Pointer and Paramater are intialized - Chroma and Luma */
3549 /* --------------------------------------------------------------------- */
3550 {
3551 WORD32 i4_base_width;
3552 WORD32 i4_base_height;
3553 WORD32 i4_ref_layer_chroma_phase_x_plus1_flag;
3554 WORD32 i4_ref_layer_chroma_phase_y_plus1;
3555 WORD32 i4_chroma_phase_x_plus1_flag;
3556 WORD32 i4_chroma_phase_y_plus1;
3557
3558 /* ------------------------------------------------------------- */
3559 /* HARD CODED FOR 420 */
3560 /* ------------------------------------------------------------- */
3561 WORD32 i4_sub_wd_chroma = 2;
3562 WORD32 i4_sub_ht_chroma = 2;
3563
3564 i4_base_width = ps_ref_res_prms->i4_res_width;
3565 i4_base_height = ps_ref_res_prms->i4_res_height;
3566
3567 i4_ref_layer_chroma_phase_x_plus1_flag =
3568 ps_curr_res_prms->i1_ref_lyr_chroma_phase_x_plus1_flag;
3569 i4_ref_layer_chroma_phase_y_plus1 = ps_curr_res_prms->i1_ref_lyr_chroma_phase_y_plus1;
3570 i4_chroma_phase_x_plus1_flag = ps_sps->s_sps_svc_ext.u1_chroma_phase_x_plus1_flag;
3571 i4_chroma_phase_y_plus1 = ps_sps->s_sps_svc_ext.u1_chroma_phase_y_plus1;
3572 i4_scaled_ref_layer_bottom_offset = ps_curr_res_prms->s_ref_lyr_scaled_offset.i2_bot;
3573 i4_scaled_ref_layer_left_offset = ps_curr_res_prms->s_ref_lyr_scaled_offset.i2_left;
3574 i4_scaled_ref_layer_top_offset = ps_curr_res_prms->s_ref_lyr_scaled_offset.i2_top;
3575 i4_scaled_ref_layer_right_offset = ps_curr_res_prms->s_ref_lyr_scaled_offset.i2_rt;
3576
3577 /* ----------------------------------------------------------------- */
3578 /* Computing Effective Frame Dimensions */
3579 /* ------------------------------------------------------------------*/
3580 i4_ref_wd = (i4_base_width >> i4_chroma_flag);
3581 i4_ref_ht = (i4_base_height >> i4_chroma_flag) * (1 + i4_ref_layer_field_pic_flag);
3582
3583 i4_scaled_wd = ps_curr_res_prms->u2_scaled_ref_width;
3584 i4_scaled_ht = ps_curr_res_prms->u2_scaled_ref_height;
3585
3586 i4_scaled_wd = (i4_scaled_wd >> i4_chroma_flag);
3587 i4_scaled_ht = (i4_scaled_ht >> i4_chroma_flag) * (1 + i4_field_pic_flag);
3588
3589 if(1 == i4_chroma_flag)
3590 {
3591 i4_refphase_x = i4_ref_layer_chroma_phase_x_plus1_flag - 1;
3592 i4_refphase_y = i4_ref_layer_chroma_phase_y_plus1 - 1;
3593 i4_phase_x = i4_chroma_phase_x_plus1_flag - 1;
3594 i4_phase_y = i4_chroma_phase_y_plus1 - 1;
3595 i4_sub_wd = i4_sub_wd_chroma;
3596 i4_sub_ht = i4_sub_ht_chroma;
3597 i4_mb_wd = MB_WIDTH >> 1;
3598 i4_mb_ht = MB_HEIGHT >> 1;
3599 }
3600 else
3601 {
3602 i4_refphase_x = 0;
3603 i4_refphase_y = 0;
3604 i4_phase_x = 0;
3605 i4_phase_y = 0;
3606 i4_sub_wd = 1;
3607 i4_sub_ht = 1;
3608 i4_mb_wd = MB_WIDTH;
3609 i4_mb_ht = MB_HEIGHT;
3610 }
3611 }
3612
3613 /* --------------------------------------------------------------------- */
3614 /* Derive shift x and y based on level idd */
3615 /* --------------------------------------------------------------------- */
3616 if(ps_sps->u1_level_idc <= 30)
3617 {
3618 i4_shift_x = 16;
3619 i4_shift_y = 16;
3620 }
3621 else
3622 {
3623 i4_shift_x = 31 - svcd_get_ceil_log2(i4_ref_wd);
3624 i4_shift_y = 31 - svcd_get_ceil_log2(i4_ref_ht);
3625 }
3626
3627 /* --------------------------------------------------------------------- */
3628 /* The following condition is not true in our case for time being */
3629 /* --------------------------------------------------------------------- */
3630 if((SVCD_FALSE == i4_frame_mbs_only_flag) || (SVCD_FALSE == i4_ref_layer_frame_Mbs_only_flag))
3631 {
3632 i4_phase_y = i4_phase_y + 4 * i4_bot_field_flag;
3633
3634 if(1 == i4_ref_layer_frame_Mbs_only_flag)
3635 i4_refphase_y = (2 * i4_refphase_y) + 2;
3636 else
3637 i4_refphase_y = i4_refphase_y + (4 * i4_bot_field_flag);
3638 }
3639
3640 /* --------------------------------------------------------------------- */
3641 /* Dx and Dy Computation - Ratio of the base and enhance layer width */
3642 /* --------------------------------------------------------------------- */
3643 i4_scale_x = ((i4_ref_wd << i4_shift_x) + (i4_scaled_wd >> 1)) / (i4_scaled_wd);
3644 i4_scale_y = ((i4_ref_ht << i4_shift_y) + (i4_scaled_ht >> 1)) / (i4_scaled_ht);
3645
3646 i4_offset_x = i4_scaled_ref_layer_left_offset / i4_sub_wd;
3647 i4_add_x = (((i4_ref_wd * (2 + i4_phase_x)) << (i4_shift_x - 2)) + (i4_scaled_wd >> 1)) /
3648 i4_scaled_wd +
3649 (1 << (i4_shift_x - 5));
3650 i4_delta_x = 4 * (2 + i4_refphase_x);
3651
3652 if((SVCD_TRUE == i4_frame_mbs_only_flag) && (SVCD_TRUE == i4_ref_layer_frame_Mbs_only_flag))
3653 {
3654 i4_offset_y = i4_scaled_ref_layer_top_offset / i4_sub_ht;
3655 i4_add_y = (((i4_ref_ht * (2 + i4_phase_y)) << (i4_shift_y - 2)) + (i4_scaled_ht >> 1)) /
3656 i4_scaled_ht +
3657 (1 << (i4_shift_y - 5));
3658 i4_delta_y = 4 * (2 + i4_refphase_y);
3659 }
3660 else
3661 {
3662 i4_offset_y = i4_scaled_ref_layer_top_offset / (2 * i4_sub_ht);
3663 i4_add_y = (((i4_ref_ht * (2 + i4_phase_y)) << (i4_shift_y - 3)) + (i4_scaled_ht >> 1)) /
3664 i4_scaled_ht +
3665 (1 << (i4_shift_y - 5));
3666 i4_delta_y = 2 * (2 + i4_refphase_y);
3667 }
3668
3669 /* --------------------------------------------------------------------- */
3670 /* Intializing Local Pointers - Chroma and Luma */
3671 /* --------------------------------------------------------------------- */
3672
3673 ps_x_off_len = ps_map_ctxt->ps_x_offset_length;
3674 ps_y_off_len = ps_map_ctxt->ps_y_offset_length;
3675
3676 i4_curr_lyr_width = ps_curr_res_prms->i4_res_width >> i4_chroma_flag;
3677 i4_curr_lyr_height = ps_curr_res_prms->i4_res_height >> i4_chroma_flag;
3678
3679 /* --------------------------------------------------------------------- */
3680 /* Dyadic Scaling Ratios Handling */
3681 /* --------------------------------------------------------------------- */
3682 if(1 == ps_curr_res_prms->u1_dyadic_flag)
3683 {
3684 WORD32 i4_refarray_wd, i4_x_offset;
3685 WORD32 i4_refarray_ht, i4_y_offset;
3686 WORD32 i4_crp_wd_lt, i4_crp_ht_top;
3687 WORD32 i4_crp_wd_rt, i4_crp_ht_bot;
3688 WORD32 i4_ref_lyr_wd, i4_ref_lyr_ht;
3689 WORD32 i4_ref_x, i4_ref_y;
3690 WORD32 i4_ofst;
3691 WORD32 i4_i, i4_j;
3692
3693 /* Hard coded for dyadic case */
3694 i4_refarray_wd = 20 >> i4_chroma_flag;
3695 i4_ofst = -2 >> i4_chroma_flag;
3696 i4_crp_wd_lt = i4_scaled_ref_layer_left_offset >> i4_chroma_flag;
3697 i4_crp_wd_rt = i4_scaled_ref_layer_right_offset >> i4_chroma_flag;
3698 i4_ref_lyr_wd = (i4_curr_lyr_width >> 1);
3699
3700 i4_ref_x = 0;
3701 for(i4_i = 0; i4_i < i4_curr_lyr_width; i4_i += (i4_mb_wd << 1))
3702 {
3703 i4_x_offset = MAX(i4_ofst, (i4_ref_x + i4_ofst));
3704 i4_x_offset = MIN(i4_x_offset, (i4_ref_lyr_wd - i4_ofst));
3705 ps_x_off_len->i2_offset = i4_x_offset;
3706 ps_x_off_len->i2_length = i4_refarray_wd;
3707 ps_x_off_len++;
3708 ps_x_off_len->i2_offset = i4_x_offset;
3709 ps_x_off_len->i2_length = i4_refarray_wd;
3710 ps_x_off_len++;
3711 if(i4_i >= i4_crp_wd_lt)
3712 {
3713 if(i4_i <= (i4_curr_lyr_width - i4_crp_wd_rt))
3714 {
3715 i4_ref_x += i4_mb_wd;
3716 }
3717 }
3718 }
3719
3720 i4_refarray_ht = 20 >> i4_chroma_flag;
3721 i4_crp_ht_top = i4_scaled_ref_layer_top_offset >> i4_chroma_flag;
3722 i4_crp_ht_bot = i4_scaled_ref_layer_bottom_offset >> i4_chroma_flag;
3723 i4_ref_lyr_ht = (i4_curr_lyr_height >> 1);
3724
3725 i4_ref_y = 0;
3726 for(i4_j = 0; i4_j < i4_curr_lyr_height; i4_j += (i4_mb_ht << 1))
3727 {
3728 i4_y_offset = MAX(i4_ofst, (i4_ref_y + i4_ofst));
3729 i4_y_offset = MIN(i4_y_offset, (i4_ref_lyr_ht - i4_ofst));
3730 ps_y_off_len->i2_offset = i4_y_offset;
3731 ps_y_off_len->i2_length = i4_refarray_ht;
3732 ps_y_off_len++;
3733 ps_y_off_len->i2_offset = i4_y_offset;
3734 ps_y_off_len->i2_length = i4_refarray_ht;
3735 ps_y_off_len++;
3736 if(i4_j >= i4_crp_ht_top)
3737 {
3738 if(i4_j <= (i4_curr_lyr_height - i4_crp_ht_bot))
3739 {
3740 i4_ref_y += i4_mb_ht;
3741 }
3742 }
3743 }
3744
3745 /* No need to process further, return */
3746 return;
3747 } /* If dyadic path */
3748
3749 /* Proposed Algo for Optimization */
3750 {
3751 WORD32 i4_max, i4_min;
3752 ref_min_max_map_t *ps_x_min_max;
3753 ref_min_max_map_t *ps_y_min_max;
3754 WORD32 i4_i, i4_j;
3755
3756 ps_x_min_max = ps_map_ctxt->ps_x_min_max;
3757 ps_y_min_max = ps_map_ctxt->ps_y_min_max;
3758 /* ----------------------------------------------------------------- */
3759 /* Computation of offsetX refArrayW Xmin and Xmax Lists */
3760 /* ----------------------------------------------------------------- */
3761 for(i4_i = 0; i4_i < i4_curr_lyr_width; i4_i = i4_i + i4_mb_wd)
3762 {
3763 WORD32 i4_refarray_wd, i4_xr_index;
3764 WORD32 i4_x_refmin16;
3765 WORD32 i4_x_refmax16;
3766 WORD32 i4_x_offset;
3767
3768 i4_x_refmin16 = (WORD64) (((WORD64) (i4_i - i4_offset_x) * i4_scale_x + i4_add_x) >>
3769 (i4_shift_x - 4)) -
3770 i4_delta_x;
3771
3772 i4_x_refmax16 =
3773 (WORD64) (((WORD64) (i4_i + i4_mb_wd - 1 - i4_offset_x) * i4_scale_x + i4_add_x) >>
3774 (i4_shift_x - 4)) -
3775 i4_delta_x;
3776
3777 /* ------------------------------------------------------------- */
3778 /* Modified AC205 */
3779 /* Minimum width required - So adding 2 pixels on each side */
3780 /* ------------------------------------------------------------- */
3781 i4_refarray_wd = ((i4_x_refmax16 + 15) >> 4) - (i4_x_refmin16 >> 4) + 1 + 4;
3782
3783 /* ------------------------------------------------------------- */
3784 /* Setting the offset 2 pixels before */
3785 /* ------------------------------------------------------------- */
3786 i4_x_offset = (i4_x_refmin16 >> 4) - 2;
3787
3788 /* ------------------------------------------------------------- */
3789 /* Modifying the values based on the location */
3790 /* ------------------------------------------------------------- */
3791 i4_min = i4_x_offset;
3792 i4_xr_index = i4_min - ((i4_min / i4_mb_wd) * i4_mb_wd);
3793
3794 if(i4_xr_index < (i4_mb_wd >> 1))
3795 {
3796 i4_refarray_wd = i4_refarray_wd + (i4_mb_wd >> 1);
3797 i4_x_offset = i4_x_offset - (i4_mb_wd >> 1);
3798 }
3799
3800 i4_max = ((i4_x_refmax16 + 15) >> 4) + 2;
3801 i4_xr_index = i4_max - ((i4_max / i4_mb_wd) * i4_mb_wd);
3802
3803 if(i4_xr_index >= (i4_mb_wd >> 1)) i4_refarray_wd = i4_refarray_wd + (i4_mb_wd >> 1);
3804
3805 /* ------------------------------------------------------------- */
3806 /* Filling the arrays with offset, min, max and refArray dim */
3807 /* ------------------------------------------------------------- */
3808 ps_x_off_len->i2_offset = i4_x_offset;
3809 ps_x_off_len->i2_length = i4_refarray_wd;
3810
3811 ps_x_min_max->i2_min_pos = (i4_x_refmin16 >> 4) - i4_x_offset;
3812 ps_x_min_max->i2_max_pos = ((i4_x_refmax16 + 15) >> 4) - i4_x_offset;
3813
3814 i4_tmp = (WORD32) (ps_x_min_max->i2_max_pos - ps_x_min_max->i2_min_pos) +
3815 (4 >> i4_chroma_flag);
3816 if(i4_tmp > i4_horz_dim)
3817 {
3818 i4_horz_dim = i4_tmp;
3819 }
3820
3821 /* increment the pointer */
3822 ps_x_off_len++;
3823 ps_x_min_max++;
3824
3825 } /* end of loop over scaled width */
3826
3827 /* ----------------------------------------------------------------- */
3828 /* Computation of offsetY refArrayH Ymin and Ymax Lists */
3829 /* ----------------------------------------------------------------- */
3830 for(i4_j = 0; i4_j < i4_curr_lyr_height; i4_j = i4_j + i4_mb_ht)
3831 {
3832 WORD32 i4_refarray_ht, i4_yr_index;
3833 WORD32 i4_y_refmin16;
3834 WORD32 i4_y_refmax16;
3835 WORD32 i4_y_offset;
3836
3837 i4_y_refmin16 = (WORD64) (((WORD64) (i4_j - i4_offset_y) * i4_scale_y + i4_add_y) >>
3838 (i4_shift_y - 4)) -
3839 i4_delta_y;
3840
3841 i4_y_refmax16 =
3842 (WORD64) (((WORD64) (i4_j + i4_mb_ht - 1 - i4_offset_y) * i4_scale_y + i4_add_y) >>
3843 (i4_shift_y - 4)) -
3844 i4_delta_y;
3845
3846 /* ------------------------------------------------------------- */
3847 /* Modified AC205 */
3848 /* Minimum width required - So adding 2 pixels on each side */
3849 /* ------------------------------------------------------------- */
3850 i4_refarray_ht = ((i4_y_refmax16 + 15) >> 4) - (i4_y_refmin16 >> 4) + 1 + 4;
3851
3852 /* ------------------------------------------------------------- */
3853 /* Setting the offset 2 pixels before */
3854 /* ------------------------------------------------------------- */
3855 i4_y_offset = (i4_y_refmin16 >> 4) - 2;
3856
3857 /* ------------------------------------------------------------- */
3858 /* Modifying the values based on the location */
3859 /* ------------------------------------------------------------- */
3860 i4_min = i4_y_offset;
3861
3862 i4_yr_index = i4_min - ((i4_min / i4_mb_ht) * i4_mb_ht);
3863
3864 if(i4_yr_index < (i4_mb_ht >> 1))
3865 {
3866 i4_refarray_ht = i4_refarray_ht + (i4_mb_ht >> 1);
3867 i4_y_offset = i4_y_offset - (i4_mb_ht >> 1);
3868 }
3869
3870 i4_max = ((i4_y_refmax16 + 15) >> 4) + 2;
3871 i4_yr_index = i4_max - ((i4_max / i4_mb_ht) * i4_mb_ht);
3872
3873 if(i4_yr_index >= (i4_mb_ht >> 1)) i4_refarray_ht = i4_refarray_ht + (i4_mb_ht >> 1);
3874
3875 /* ------------------------------------------------------------- */
3876 /* Filling the arrays with offset, min, max and refArray dim */
3877 /* ------------------------------------------------------------- */
3878 ps_y_off_len->i2_offset = i4_y_offset;
3879 ps_y_off_len->i2_length = i4_refarray_ht;
3880
3881 ps_y_min_max->i2_min_pos = (i4_y_refmin16 >> 4) - i4_y_offset;
3882 ps_y_min_max->i2_max_pos = ((i4_y_refmax16 + 15) >> 4) - i4_y_offset;
3883
3884 i4_tmp = (WORD32) (ps_y_min_max->i2_max_pos - ps_y_min_max->i2_min_pos) +
3885 (4 >> i4_chroma_flag);
3886 if(i4_tmp > i4_vert_dim)
3887 {
3888 i4_vert_dim = i4_tmp;
3889 }
3890
3891 /* increment the pointer */
3892 ps_y_off_len++;
3893 ps_y_min_max++;
3894 } /* end of loop over scaled height */
3895 }
3896
3897 /* --------------------------------------------------------------------- */
3898 /* Computation of Xref and Xphase List as per standard */
3899 /* --------------------------------------------------------------------- */
3900 ps_x_off_len = ps_map_ctxt->ps_x_offset_length;
3901 ps_y_off_len = ps_map_ctxt->ps_y_offset_length;
3902
3903 {
3904 ref_pixel_map_t *ps_x_pos_phase;
3905 WORD32 i4_xc;
3906 WORD32 i4_offset_x_index;
3907
3908 ps_x_pos_phase = ps_map_ctxt->ps_x_pos_phase;
3909
3910 for(i4_xc = 0; i4_xc < i4_curr_lyr_width; i4_xc++)
3911 {
3912 WORD32 i4_x_offset;
3913 WORD32 i4_x_ref16;
3914
3915 i4_offset_x_index = i4_xc / i4_mb_wd;
3916
3917 i4_x_offset = ps_x_off_len[i4_offset_x_index].i2_offset;
3918
3919 i4_x_ref16 = (WORD64) (((WORD64) (i4_xc - i4_offset_x) * i4_scale_x + i4_add_x) >>
3920 (i4_shift_x - 4)) -
3921 i4_delta_x;
3922
3923 /* store the values */
3924 ps_x_pos_phase->i2_ref_pos = (i4_x_ref16 >> 4) - i4_x_offset;
3925 ps_x_pos_phase->i2_phase = i4_x_ref16 & 15;
3926
3927 /* increment the pointer */
3928 ps_x_pos_phase++;
3929
3930 } /* end of loop over scaled width */
3931 }
3932
3933 /* --------------------------------------------------------------------- */
3934 /* Computation of Yref and Yphase List as per standard */
3935 /* --------------------------------------------------------------------- */
3936 {
3937 WORD32 i4_yc;
3938 ref_pixel_map_t *ps_y_pos_phase;
3939
3940 ps_y_pos_phase = ps_map_ctxt->ps_y_pos_phase;
3941
3942 for(i4_yc = 0; i4_yc < i4_curr_lyr_height; i4_yc++)
3943 {
3944 WORD32 i4_y_offset;
3945 WORD32 i4_y_ref16;
3946 WORD32 i4_offset_y_index;
3947
3948 i4_offset_y_index = i4_yc / i4_mb_ht;
3949
3950 i4_y_offset = ps_y_off_len[i4_offset_y_index].i2_offset;
3951
3952 if((SVCD_FALSE == i4_frame_mbs_only_flag) ||
3953 (SVCD_FALSE == i4_ref_layer_frame_Mbs_only_flag))
3954 {
3955 i4_yc = i4_yc >> (1 - i4_field_Mb_flag);
3956 }
3957
3958 i4_y_ref16 = (WORD64) (((WORD64) (i4_yc - i4_offset_y) * i4_scale_y + i4_add_y) >>
3959 (i4_shift_y - 4)) -
3960 i4_delta_y;
3961
3962 ps_y_pos_phase->i2_ref_pos = (i4_y_ref16 >> 4) - i4_y_offset;
3963 ps_y_pos_phase->i2_phase = i4_y_ref16 & 15;
3964
3965 /* increment the pointer */
3966 ps_y_pos_phase++;
3967
3968 } /* end of loop over scaled height */
3969 }
3970
3971 /* --------------------------------------------------------------------- */
3972 /* Computation of Corresponding Diagonal Location */
3973 /* --------------------------------------------------------------------- */
3974 {
3975 WORD16 *pi2_xd_index;
3976 WORD16 *pi2_yd_index;
3977 WORD16 *pi2_ya_index;
3978 WORD32 i4_i, i4_j;
3979
3980 pi2_xd_index = ps_map_ctxt->pi2_xd_index;
3981 pi2_yd_index = ps_map_ctxt->pi2_yd_index;
3982 pi2_ya_index = ps_map_ctxt->pi2_ya_index;
3983
3984 for(i4_i = 0; i4_i < i4_mb_wd; i4_i++)
3985 {
3986 *(pi2_xd_index + i4_i) = ((i4_i >= i4_mb_wd >> 1) ? (i4_i - i4_mb_wd) : (i4_i + 1));
3987
3988 } /* end of loop over MB width */
3989
3990 for(i4_j = 0; i4_j < i4_mb_ht; i4_j++)
3991 {
3992 *(pi2_yd_index + i4_j) = ((i4_j >= i4_mb_ht >> 1) ? (i4_j - i4_mb_ht) : (i4_j + 1));
3993
3994 *(pi2_ya_index + i4_j) =
3995 *(pi2_yd_index + i4_j) - ((i4_mb_ht >> 1 + 1) * (SIGN(*(pi2_yd_index + i4_j))));
3996
3997 } /* end of loop over MB height */
3998 }
3999
4000 /* generate the lookup to generate horizontal segments */
4001 svc_intra_resamp_generate_segment_lookup(ps_map_ctxt->ps_seg_lookup_horz, i4_horz_dim, i4_mb_wd,
4002 3);
4003
4004 /* generate the lookup to generate vertical segments */
4005 svc_intra_resamp_generate_segment_lookup(ps_map_ctxt->ps_seg_lookup_vert, i4_vert_dim, i4_mb_ht,
4006 4);
4007
4008 return;
4009 } /* end of function "svcd_intra_samp_populate_list"*/
4010
svcd_intra_samp_populate_res_prms(void * pv_dec)4011 void svcd_intra_samp_populate_res_prms(void *pv_dec)
4012
4013 {
4014 dec_struct_t *ps_dec = (dec_struct_t *) pv_dec;
4015 res_prms_t *ps_curr_lyr_res_prms;
4016 ps_curr_lyr_res_prms = &ps_dec->s_res_prms;
4017
4018 ps_curr_lyr_res_prms->i4_res_width = ps_dec->u2_pic_wd;
4019 ps_curr_lyr_res_prms->i4_res_height = ps_dec->u2_pic_ht;
4020 ps_curr_lyr_res_prms->s_ref_lyr_scaled_offset.i2_left =
4021 ps_dec->ps_cur_sps->s_sps_svc_ext.i4_seq_scaled_ref_layer_left_offset << 1;
4022 ps_curr_lyr_res_prms->s_ref_lyr_scaled_offset.i2_top =
4023 ps_dec->ps_cur_sps->s_sps_svc_ext.i4_seq_scaled_ref_layer_top_offset << 1;
4024 ps_curr_lyr_res_prms->s_ref_lyr_scaled_offset.i2_rt =
4025 ps_dec->ps_cur_sps->s_sps_svc_ext.i4_seq_scaled_ref_layer_right_offset << 1;
4026 ps_curr_lyr_res_prms->s_ref_lyr_scaled_offset.i2_bot =
4027 ps_dec->ps_cur_sps->s_sps_svc_ext.i4_seq_scaled_ref_layer_bottom_offset << 1;
4028 ps_curr_lyr_res_prms->u2_scaled_ref_width =
4029 (ps_dec->u2_frm_wd_in_mbs << 4) - (ps_curr_lyr_res_prms->s_ref_lyr_scaled_offset.i2_left +
4030 ps_curr_lyr_res_prms->s_ref_lyr_scaled_offset.i2_rt);
4031
4032 ps_curr_lyr_res_prms->u2_scaled_ref_height =
4033 (ps_dec->u2_frm_ht_in_mbs << 4) - (ps_curr_lyr_res_prms->s_ref_lyr_scaled_offset.i2_top +
4034 ps_curr_lyr_res_prms->s_ref_lyr_scaled_offset.i2_bot);
4035
4036 ps_curr_lyr_res_prms->u1_cropping_change_flag = 0;
4037 if(2 == ps_dec->ps_cur_sps->s_sps_svc_ext.u1_extended_spatial_scalability_idc)
4038 {
4039 ps_curr_lyr_res_prms->u1_cropping_change_flag = 1;
4040
4041 ps_curr_lyr_res_prms->s_ref_lyr_scaled_offset.i2_left =
4042 ps_dec->ps_cur_slice->s_svc_slice_params.i4_scaled_ref_layer_left_offset << 1;
4043
4044 ps_curr_lyr_res_prms->s_ref_lyr_scaled_offset.i2_top =
4045 ps_dec->ps_cur_slice->s_svc_slice_params.i4_scaled_ref_layer_top_offset << 1;
4046 ps_curr_lyr_res_prms->s_ref_lyr_scaled_offset.i2_rt =
4047 ps_dec->ps_cur_slice->s_svc_slice_params.i4_scaled_ref_layer_right_offset << 1;
4048 ps_curr_lyr_res_prms->s_ref_lyr_scaled_offset.i2_bot =
4049 ps_dec->ps_cur_slice->s_svc_slice_params.i4_scaled_ref_layer_bottom_offset << 1;
4050 ps_curr_lyr_res_prms->u2_scaled_ref_width =
4051 (ps_dec->u2_frm_wd_in_mbs << 4) -
4052 (ps_curr_lyr_res_prms->s_ref_lyr_scaled_offset.i2_left +
4053 ps_curr_lyr_res_prms->s_ref_lyr_scaled_offset.i2_rt);
4054
4055 ps_curr_lyr_res_prms->u2_scaled_ref_height =
4056 (ps_dec->u2_frm_ht_in_mbs << 4) -
4057 (ps_curr_lyr_res_prms->s_ref_lyr_scaled_offset.i2_top +
4058 ps_curr_lyr_res_prms->s_ref_lyr_scaled_offset.i2_bot);
4059 }
4060
4061 ps_curr_lyr_res_prms->u1_rstrct_res_change_flag = SVCD_TRUE;
4062
4063 ps_curr_lyr_res_prms->u1_disable_inter_lyr_dblk_filter_idc =
4064 ps_dec->ps_cur_slice->s_svc_slice_params.u4_disable_inter_layer_deblk_filter_idc;
4065 ps_curr_lyr_res_prms->i1_inter_lyr_alpha_c0_offset =
4066 ps_dec->ps_cur_slice->s_svc_slice_params.i4_inter_layer_slice_alpha_c0_offset_div2;
4067 ps_curr_lyr_res_prms->i1_inter_lyr_beta_offset =
4068 ps_dec->ps_cur_slice->s_svc_slice_params.i4_inter_layer_slice_beta_offset_div2;
4069 ps_curr_lyr_res_prms->i1_constrained_intra_rsmpl_flag =
4070 ps_dec->ps_cur_slice->s_svc_slice_params.u1_constrained_intra_resampling_flag;
4071 ps_curr_lyr_res_prms->i1_ref_lyr_chroma_phase_x_plus1_flag =
4072 ps_dec->ps_cur_sps->s_sps_svc_ext.u1_seq_ref_layer_chroma_phase_x_plus1_flag;
4073 ps_curr_lyr_res_prms->i1_ref_lyr_chroma_phase_y_plus1 =
4074 ps_dec->ps_cur_sps->s_sps_svc_ext.u1_seq_ref_layer_chroma_phase_y_plus1;
4075 ps_curr_lyr_res_prms->u1_direct_8x8_inference_flag =
4076 ps_dec->ps_cur_sps->u1_direct_8x8_inference_flag;
4077
4078 ps_curr_lyr_res_prms->u1_remap_req_flag = 1;
4079 ps_curr_lyr_res_prms->u1_dyadic_flag = ps_dec->u1_dyadic_flag;
4080 }
4081 /*****************************************************************************/
4082 /* */
4083 /* Function Name : svcd_intra_samp_res_init */
4084 /* */
4085 /* Description : this function calculates the scale factors and initialise*/
4086 /* the context structure */
4087 /* */
4088 /* Inputs : pv_intra_samp_ctxt: handle to private structure */
4089 /* ps_curr_lyr_res_prms: pointer to current resolution */
4090 /* params */
4091 /* ps_ref_lyr_res_prms : pointer to ref resolution params */
4092 /* Globals : none */
4093 /* Processing : it stores the layer dimensions */
4094 /* */
4095 /* Outputs : none */
4096 /* Returns : none */
4097 /* */
4098 /* Issues : none */
4099 /* */
4100 /* Revision History: */
4101 /* */
4102 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
4103 /* 26 06 2009 vijayakumar creation */
4104 /* */
4105 /*****************************************************************************/
svcd_intra_samp_res_init(void * pv_intra_samp_ctxt,res_prms_t * ps_curr_lyr_res_prms,ref_mb_map_t ** pps_luma_map_horz,ref_mb_map_t ** pps_chroma_map_horz,ref_mb_map_t ** pps_luma_map_vert,ref_mb_map_t ** pps_chroma_map_vert,void * pv_dec)4106 void svcd_intra_samp_res_init(void *pv_intra_samp_ctxt, res_prms_t *ps_curr_lyr_res_prms,
4107 ref_mb_map_t **pps_luma_map_horz, ref_mb_map_t **pps_chroma_map_horz,
4108 ref_mb_map_t **pps_luma_map_vert, ref_mb_map_t **pps_chroma_map_vert,
4109 void *pv_dec)
4110
4111 {
4112 intra_sampling_ctxt_t *ps_ctxt;
4113 intra_samp_lyr_ctxt *ps_lyr_ctxt;
4114 dec_seq_params_t *ps_sps;
4115 dec_struct_t *ps_dec = (dec_struct_t *) pv_dec;
4116 dec_struct_t *ps_dec_ref_layer;
4117 dec_slice_params_t *ps_slice = ps_dec->ps_cur_slice;
4118 dec_slice_svc_ext_params_t *ps_svc_slice_params = NULL;
4119 ps_svc_slice_params = &ps_slice->s_svc_slice_params;
4120 ps_sps = ps_dec->ps_cur_sps;
4121 ps_dec_ref_layer = ps_dec->ps_dec_ref_layer;
4122 ps_ctxt = (intra_sampling_ctxt_t *) pv_intra_samp_ctxt;
4123
4124 /* if called for base resolution store default values */
4125 if(SVCD_TRUE == ps_dec->u1_base_res_flag)
4126 {
4127 *pps_luma_map_horz = NULL;
4128 *pps_chroma_map_horz = NULL;
4129 *pps_luma_map_vert = NULL;
4130 *pps_chroma_map_vert = NULL;
4131 ps_ctxt->i4_res_lyr_id = -1;
4132 ps_ctxt->i4_ref_width = ps_dec->u2_pic_wd;
4133 ps_ctxt->i4_ref_height = ps_dec->u2_pic_ht;
4134
4135 /* Note: The stride option is provided for bringing in data at NMB */
4136 /* level. Hence to set a NMB level stride refSample array buffer */
4137 /* have to be increased */
4138 ps_ctxt->i4_refarray_stride = REF_ARRAY_WIDTH;
4139 return;
4140 }
4141
4142 /* derive the current sps */
4143
4144 /* store the res id appropriately */
4145 ps_ctxt->i4_res_lyr_id = ps_dec->u1_layer_id - 1;
4146
4147 /* store the resolution params */
4148 ps_ctxt->ps_res_prms = ps_curr_lyr_res_prms;
4149
4150 /* get the current layer ctxt */
4151 ps_lyr_ctxt = &ps_ctxt->as_res_lyrs[ps_dec->u1_layer_id - 1];
4152
4153 ps_ctxt->i4_res_lyr_id = ps_dec->u1_layer_id - 1;
4154 /* get the width and heights */
4155 ps_lyr_ctxt->i4_curr_width = ps_dec->u2_pic_wd;
4156 ps_lyr_ctxt->i4_curr_height = ps_dec->u2_pic_ht;
4157 ps_lyr_ctxt->i4_ref_width = ps_ctxt->i4_ref_width;
4158 ps_lyr_ctxt->i4_ref_height = ps_ctxt->i4_ref_height;
4159 ps_lyr_ctxt->i1_constrained_intra_rsmpl_flag =
4160 ps_svc_slice_params->u1_constrained_intra_resampling_flag;
4161
4162 /* store the structure pointer containing projected locations */
4163 *pps_luma_map_horz = ps_lyr_ctxt->s_luma_map_ctxt.ps_x_offset_length;
4164 *pps_chroma_map_horz = ps_lyr_ctxt->s_chroma_map_ctxt.ps_x_offset_length;
4165 *pps_luma_map_vert = ps_lyr_ctxt->s_luma_map_ctxt.ps_y_offset_length;
4166 *pps_chroma_map_vert = ps_lyr_ctxt->s_chroma_map_ctxt.ps_y_offset_length;
4167
4168 /* check for recomputation of mapping required */
4169 if(SVCD_TRUE == ps_curr_lyr_res_prms->u1_remap_req_flag)
4170 {
4171 res_prms_t s_ref_res_prms = {0};
4172 WORD32 i4_chroma_x_phase, i4_chroma_y_phase;
4173 WORD32 i4_ref_chroma_x_phase, i4_ref_chroma_y_phase;
4174 WORD32 i4_x_phase_0, i4_x_phase_1;
4175 WORD32 i4_y_phase_0, i4_y_phase_1;
4176 WORD32 i4_vert_flag;
4177
4178 /* store the reference layer resolution width and height */
4179 s_ref_res_prms.i4_res_width = ps_ctxt->i4_ref_width;
4180 s_ref_res_prms.i4_res_height = ps_ctxt->i4_ref_height;
4181
4182 /* call the frame level projections calculation function */
4183 svcd_intra_samp_populate_list(&ps_lyr_ctxt->s_luma_map_ctxt, ps_curr_lyr_res_prms,
4184 &s_ref_res_prms, 0, ps_dec);
4185
4186 svcd_intra_samp_populate_list(&ps_lyr_ctxt->s_chroma_map_ctxt, ps_curr_lyr_res_prms,
4187 &s_ref_res_prms, 1, ps_dec);
4188
4189 /* Compute the chroma xPhase and yPhase values */
4190 if(1 == ps_curr_lyr_res_prms->u1_dyadic_flag)
4191 {
4192 i4_ref_chroma_x_phase = ps_curr_lyr_res_prms->i1_ref_lyr_chroma_phase_x_plus1_flag;
4193 i4_ref_chroma_y_phase = ps_curr_lyr_res_prms->i1_ref_lyr_chroma_phase_y_plus1;
4194 i4_chroma_x_phase = ps_sps->s_sps_svc_ext.u1_chroma_phase_x_plus1_flag;
4195 i4_chroma_y_phase = ps_sps->s_sps_svc_ext.u1_chroma_phase_y_plus1;
4196
4197 i4_x_phase_0 = i4_chroma_x_phase - (i4_ref_chroma_x_phase << 1);
4198 i4_x_phase_1 = (3 + i4_x_phase_0) & 0x7;
4199 i4_x_phase_0 += 7;
4200 i4_x_phase_0 &= 0x7;
4201 i4_y_phase_0 = i4_chroma_y_phase - (i4_ref_chroma_y_phase << 1);
4202 i4_y_phase_1 = (3 + i4_y_phase_0) & 0x7;
4203 i4_y_phase_0 += 7;
4204 i4_y_phase_0 &= 0x7;
4205
4206 ps_lyr_ctxt->i4_x_phase_0 = i4_x_phase_0;
4207 ps_lyr_ctxt->i4_x_phase_1 = i4_x_phase_1;
4208 ps_lyr_ctxt->i4_y_phase_0 = i4_y_phase_0;
4209 ps_lyr_ctxt->i4_y_phase_1 = i4_y_phase_1;
4210
4211 /* Choose the appropriate chroma interpolation functions */
4212 if((0 == i4_ref_chroma_x_phase) && (1 == i4_chroma_x_phase))
4213 {
4214 ps_lyr_ctxt->pf_horz_chroma_interpol = (&svcd_horz_interpol_chroma_dyadic_2);
4215 }
4216 else
4217 {
4218 ps_lyr_ctxt->pf_horz_chroma_interpol = (&svcd_horz_interpol_chroma_dyadic_1);
4219 }
4220
4221 i4_vert_flag = 0;
4222 if(0 == i4_ref_chroma_y_phase)
4223 {
4224 if((1 == i4_chroma_y_phase) || (2 == i4_chroma_y_phase))
4225 {
4226 i4_vert_flag = 1;
4227 }
4228 }
4229 else if((2 == i4_ref_chroma_y_phase) && (0 == i4_chroma_y_phase))
4230 {
4231 i4_vert_flag = 2;
4232 }
4233
4234 if(1 == i4_vert_flag)
4235 {
4236 ps_lyr_ctxt->pf_vert_chroma_interpol = (&svcd_vert_interpol_chroma_dyadic_2);
4237 }
4238 else if(2 == i4_vert_flag)
4239 {
4240 ps_lyr_ctxt->pf_vert_chroma_interpol = (&svcd_vert_interpol_chroma_dyadic_3);
4241 }
4242 else
4243 {
4244 ps_lyr_ctxt->pf_vert_chroma_interpol = (&svcd_vert_interpol_chroma_dyadic_1);
4245 }
4246 }
4247 }
4248 else
4249 {
4250 /* should take false value */
4251 ASSERT(SVCD_FALSE == ps_curr_lyr_res_prms->u1_remap_req_flag);
4252 }
4253
4254 /* Set the border values of ref_mb_modes to 0xFF */
4255 {
4256 inter_lyr_mb_prms_t *ps_tmp_prms, *ps_tmp_prms_2;
4257 inter_lyr_mb_prms_t *ps_ref_mb_prms;
4258 WORD32 i4_stride;
4259 WORD32 i4_ref_ht_in_mbs, i4_ref_wd_in_mbs;
4260 WORD32 i4_i;
4261
4262 /* Derive the reference mb mode map */
4263
4264 ps_ref_mb_prms = ps_dec_ref_layer->ps_inter_lyr_mb_prms_frm_start;
4265 i4_stride =
4266 ps_dec_ref_layer->u2_inter_lyr_mb_prms_stride; // SVC_DEC_REVIEW_INTRA_RESAMPLE;
4267
4268 i4_ref_ht_in_mbs = (ps_lyr_ctxt->i4_ref_height >> 4);
4269 i4_ref_wd_in_mbs = (ps_lyr_ctxt->i4_ref_width >> 4);
4270
4271 /* Set the first border row to 0xFF */
4272 ps_tmp_prms = (ps_ref_mb_prms - 1 - i4_stride);
4273
4274 for(i4_i = 0; i4_i < (i4_ref_wd_in_mbs + 2); i4_i++)
4275 {
4276 ps_tmp_prms->i1_mb_mode = (WORD8) 0xFF;
4277 ps_tmp_prms += 1;
4278 }
4279
4280 /* Set the left and right border pixels of each row to 0 */
4281 ps_tmp_prms = ps_ref_mb_prms - 1;
4282
4283 for(i4_i = 0; i4_i < i4_ref_ht_in_mbs; i4_i++)
4284 {
4285 ps_tmp_prms->i1_mb_mode = (WORD8) 0xFF;
4286 ps_tmp_prms_2 = ps_tmp_prms + (i4_ref_wd_in_mbs + 1);
4287 ps_tmp_prms_2->i1_mb_mode = (WORD8) 0xFF;
4288 ps_tmp_prms += i4_stride;
4289 }
4290
4291 /* Set the last border row to 0xFF */
4292 for(i4_i = 0; i4_i < (i4_ref_wd_in_mbs + 2); i4_i++)
4293 {
4294 ps_tmp_prms->i1_mb_mode = (WORD8) 0xFF;
4295 ps_tmp_prms += 1;
4296 }
4297 }
4298
4299 /* store the current layer width and height to context */
4300 ps_ctxt->i4_ref_width = ps_curr_lyr_res_prms->i4_res_width;
4301 ps_ctxt->i4_ref_height = ps_curr_lyr_res_prms->i4_res_height;
4302
4303 return;
4304 }
4305