Coverage Report

Created: 2026-07-16 06:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libavc/decoder/svc/isvcd_intra_resamp.c
Line
Count
Source
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_intra_resamp.c
24
 *
25
 * @brief
26
 *  Contains routines that resample for SVC resampling
27
 *
28
 * @author
29
 *  Kishore
30
 *
31
 * @par List of Functions:
32
 *  - isvcd_get_ceil_log2()
33
 *  - isvcd_2d_memset()
34
 *  - isvcd_copy_data()
35
 *  - isvcd_copy_data_semiplanr()
36
 *  - isvcd_get_ref_layer_avlblty_dyadic()
37
 *  - isvcd_diagonal_construct_dyadic()
38
 *  - isvcd_left_right_padding()
39
 *  - isvcd_left_right_padding_chroma()
40
 *  - isvcd_top_bot_padding()
41
 *  - isvcd_top_bot_padding_chroma()
42
 *  - isvcd_diag_reconstruction()
43
 *  - isvcd_diag_reconstruction_chroma()
44
 *  - isvcd_diag_padding()
45
 *  - isvcd_diag_padding_chroma()
46
 *  - isvcd_corner_samp_dyadic()
47
 *  - isvcd_fill_non_avail_pixel()
48
 *  - isvcd_get_ref_layer_mbtype()
49
 *  - isvcd_reflayer_construction()
50
 *  - isvcd_reflayer_construction_dyadic()
51
 *  - isvcd_interpolate_base_luma_dyadic()
52
 *  - isvcd_vert_interpol_chroma_dyadic_1()
53
 *  - isvcd_vert_interpol_chroma_dyadic_2()
54
 *  - isvcd_vert_interpol_chroma_dyadic_3()
55
 *  - isvcd_horz_interpol_chroma_dyadic_1()
56
 *  - isvcd_horz_interpol_chroma_dyadic_2()
57
 *  - isvcd_intra_resamp_mb_dyadic()
58
 *  - isvcd_interpolate_intra_base()
59
 *  - isvcd_intra_resamp_mb()
60
 *  - isvcd_intra_resamp_generate_segment_lookup()
61
 *  - isvcd_intra_resamp_populate_list()
62
 *  - isvcd_populate_res_prms()
63
 *  - isvcd_crop_wnd_flag_res_int()
64
 *  - isvcd_intra_resamp_res_init()
65
 *
66
 * @remarks
67
 *  None
68
 *
69
 *******************************************************************************
70
 */
71
72
#include <assert.h>
73
#include <string.h>
74
75
#include "ih264_typedefs.h"
76
#include "ih264_macros.h"
77
#include "ih264_platform_macros.h"
78
#include "ih264d_bitstrm.h"
79
#include "ih264d_defs.h"
80
#include "ih264d_debug.h"
81
#include "isvcd_structs.h"
82
#include "ih264d_parse_cavlc.h"
83
#include "ih264d_mb_utils.h"
84
#include "ih264d_deblocking.h"
85
#include "ih264d_dpb_manager.h"
86
#include "ih264d_mvpred.h"
87
#include "ih264d_inter_pred.h"
88
#include "ih264d_process_pslice.h"
89
#include "ih264d_error_handler.h"
90
#include "ih264d_cabac.h"
91
#include "ih264d_tables.h"
92
#include "ih264d_parse_slice.h"
93
#include "ih264d_utils.h"
94
#include "ih264d_parse_islice.h"
95
#include "ih264d_process_bslice.h"
96
#include "ih264d_process_intra_mb.h"
97
#include "ih264_debug.h"
98
99
ftype_intra_samp_padding *gpf_lookup_fxns_luma[32] = {
100
    NULL,
101
    NULL,
102
    NULL,
103
    NULL,
104
    NULL,
105
    NULL,
106
    NULL,
107
    NULL,
108
    NULL,
109
    &isvcd_left_right_padding,
110
    NULL,
111
    &isvcd_diag_reconstruction,
112
    NULL,
113
    &isvcd_left_right_padding,
114
    NULL,
115
    &isvcd_diag_reconstruction,
116
    NULL,
117
    NULL,
118
    &isvcd_top_bot_padding,
119
    &isvcd_diag_reconstruction,
120
    NULL,
121
    NULL,
122
    &isvcd_top_bot_padding,
123
    &isvcd_diag_reconstruction,
124
    NULL,
125
    &isvcd_left_right_padding,
126
    &isvcd_top_bot_padding,
127
    &isvcd_diag_reconstruction,
128
    &isvcd_diag_padding,
129
    &isvcd_left_right_padding,
130
    &isvcd_top_bot_padding,
131
    &isvcd_diag_reconstruction,
132
};
133
134
ftype_intra_samp_padding *gpf_lookup_fxns_chroma[32] = {
135
    NULL,
136
    NULL,
137
    NULL,
138
    NULL,
139
    NULL,
140
    NULL,
141
    NULL,
142
    NULL,
143
    NULL,
144
    &isvcd_left_right_padding_chroma,
145
    NULL,
146
    &isvcd_diag_reconstruction_chroma,
147
    NULL,
148
    &isvcd_left_right_padding_chroma,
149
    NULL,
150
    &isvcd_diag_reconstruction_chroma,
151
    NULL,
152
    NULL,
153
    &isvcd_top_bot_padding_chroma,
154
    &isvcd_diag_reconstruction_chroma,
155
    NULL,
156
    NULL,
157
    &isvcd_top_bot_padding_chroma,
158
    &isvcd_diag_reconstruction_chroma,
159
    NULL,
160
    &isvcd_left_right_padding_chroma,
161
    &isvcd_top_bot_padding_chroma,
162
    &isvcd_diag_reconstruction_chroma,
163
    &isvcd_diag_padding_chroma,
164
    &isvcd_left_right_padding_chroma,
165
    &isvcd_top_bot_padding_chroma,
166
    &isvcd_diag_reconstruction_chroma,
167
};
168
169
const UWORD32 gu4_valid_segs_lookup[16] = {
170
    0x0F000000, 0xCF000000, 0x3F000000, 0xFF000000, 0x0F000000, 0xCF000000, 0x3F000000, 0xFF000000,
171
    0x0F000000, 0x8F000000, 0x6F000000, 0xEF000000, 0x1F000000, 0x9F000000, 0x7F000000, 0xFF000000};
172
173
const WORD8 g_ai1_interp_filter_luma[64] = {
174
    0,  -1, -2, -3, -3, -4, -4, -3, -3, -3, -2, -1, -1, -1, -1, -1, 32, 32, 31, 30, 28, 26,
175
    24, 22, 19, 16, 14, 11, 8,  6,  4,  2,  0,  2,  4,  6,  8,  11, 14, 16, 19, 22, 24, 26,
176
    28, 30, 31, 32, 0,  -1, -1, -1, -1, -1, -2, -3, -3, -3, -4, -4, -3, -3, -2, -1};
177
178
const UWORD8 g_au1_interp_filter_chroma[32] = {32, 30, 28, 26, 24, 22, 20, 18, 16, 14, 12,
179
                                               10, 8,  6,  4,  2,  0,  2,  4,  6,  8,  10,
180
                                               12, 14, 16, 18, 20, 22, 24, 26, 28, 30};
181
182
WORD32 ref_pos_luma[4][16] = {{10, 11, 12, 12, 13, 14, 14, 15, 16, 16, 17, 18, 18, 19, 20, 20},
183
                              {10, 10, 11, 12, 12, 13, 14, 14, 15, 16, 16, 17, 18, 18, 19, 20},
184
                              {2, 3, 3, 4, 5, 5, 6, 7, 7, 8, 9, 9, 10, 11, 11, 12},
185
                              {2, 3, 4, 4, 5, 6, 6, 7, 8, 8, 9, 10, 10, 11, 12, 12}};
186
WORD32 ref_pos_chroma[4][8] = {{6, 7, 8, 8, 9, 10, 10, 11},
187
                               {6, 7, 7, 8, 9, 9, 10, 11},
188
                               {6, 6, 7, 8, 8, 9, 10, 10},
189
                               {2, 3, 4, 4, 5, 6, 6, 7}};
190
191
WORD32 phase_luma[3][16] = {{13, 8, 3, 13, 8, 3, 13, 8, 3, 13, 8, 3, 13, 8, 3, 13},
192
                            {8, 3, 13, 8, 3, 13, 8, 3, 13, 8, 3, 13, 8, 3, 13, 8},
193
                            {3, 13, 8, 3, 13, 8, 3, 13, 8, 3, 13, 8, 3, 13, 8, 3}};
194
195
UWORD8 phase_luma_u8[3][16] = {{13, 8, 3, 13, 8, 3, 13, 8, 3, 13, 8, 3, 13, 8, 3, 13},
196
                               {8, 3, 13, 8, 3, 13, 8, 3, 13, 8, 3, 13, 8, 3, 13, 8},
197
                               {3, 13, 8, 3, 13, 8, 3, 13, 8, 3, 13, 8, 3, 13, 8, 3}};
198
199
WORD8 phase_luma_x86[6][16] = {{13, 8, 3, 13, 8, 3, 13, 8, 0, 0, 0, 0, 0, 0, 0, 0},
200
                               {3, 13, 8, 3, 13, 8, 3, 13, 0, 0, 0, 0, 0, 0, 0, 0},
201
                               {8, 3, 13, 8, 3, 13, 8, 3, 0, 0, 0, 0, 0, 0, 0, 0},
202
                               {13, 8, 3, 13, 8, 3, 13, 8, 0, 0, 0, 0, 0, 0, 0, 0},
203
                               {3, 13, 8, 3, 13, 8, 3, 13, 0, 0, 0, 0, 0, 0, 0, 0},
204
                               {8, 3, 13, 8, 3, 13, 8, 3, 0, 0, 0, 0, 0, 0, 0, 0}};
205
206
WORD32 phase_chroma[3][8] = {
207
    {13, 8, 3, 13, 8, 3, 13, 8}, {3, 13, 8, 3, 13, 8, 3, 13}, {8, 3, 13, 8, 3, 13, 8, 3}};
208
209
UWORD8 phase_chroma_u8[3][8] = {
210
    {13, 8, 3, 13, 8, 3, 13, 8}, {3, 13, 8, 3, 13, 8, 3, 13}, {8, 3, 13, 8, 3, 13, 8, 3}};
211
212
UWORD8 ref_pos_luma_mask_m48[8][16] = {{0, 1, 2, 3, 4, 5, 4, 5, 6, 7, 8, 9, 8, 9, 10, 11},
213
                                       {2, 3, 2, 3, 4, 5, 6, 7, 6, 7, 8, 9, 10, 11, 10, 11},
214
                                       {2, 3, 4, 5, 6, 7, 6, 7, 8, 9, 10, 11, 10, 11, 12, 13},
215
                                       {4, 5, 4, 5, 6, 7, 8, 9, 8, 9, 10, 11, 12, 13, 12, 13},
216
                                       {4, 5, 6, 7, 8, 9, 8, 9, 10, 11, 12, 13, 12, 13, 14, 15},
217
                                       {6, 7, 6, 7, 8, 9, 10, 11, 10, 11, 12, 13, 14, 15, 14, 15},
218
                                       {0, 1, 2, 3, 4, 5, 4, 5, 6, 7, 8, 9, 8, 9, 10, 11},
219
                                       {4, 5, 4, 5, 6, 7, 8, 9, 8, 9, 10, 11, 12, 13, 12, 13}};
220
221
UWORD8 ref_pos_luma_mask_m16[8][16] = {{0, 1, 2, 3, 2, 3, 4, 5, 6, 7, 6, 7, 8, 9, 10, 11},
222
                                       {0, 1, 2, 3, 4, 5, 4, 5, 6, 7, 8, 9, 8, 9, 10, 11},
223
                                       {2, 3, 4, 5, 4, 5, 6, 7, 8, 9, 8, 9, 10, 11, 12, 13},
224
                                       {2, 3, 4, 5, 6, 7, 6, 7, 8, 9, 10, 11, 10, 11, 12, 13},
225
                                       {4, 5, 6, 7, 6, 7, 8, 9, 10, 11, 10, 11, 12, 13, 14, 15},
226
                                       {4, 5, 6, 7, 8, 9, 8, 9, 10, 11, 12, 13, 12, 13, 14, 15},
227
                                       {0, 1, 2, 3, 2, 3, 4, 5, 6, 7, 6, 7, 8, 9, 10, 11},
228
                                       {2, 3, 4, 5, 6, 7, 6, 7, 8, 9, 10, 11, 10, 11, 12, 13}};
229
230
UWORD8 ref_pos_luma_mask_m32[8][16] = {{0, 1, 0, 1, 2, 3, 4, 5, 4, 5, 6, 7, 8, 9, 8, 9},
231
                                       {0, 1, 2, 3, 2, 3, 4, 5, 6, 7, 6, 7, 8, 9, 10, 11},
232
                                       {2, 3, 2, 3, 4, 5, 6, 7, 6, 7, 8, 9, 10, 11, 10, 11},
233
                                       {2, 3, 4, 5, 4, 5, 6, 7, 8, 9, 8, 9, 10, 11, 12, 13},
234
                                       {4, 5, 4, 5, 6, 7, 8, 9, 8, 9, 10, 11, 12, 13, 12, 13},
235
                                       {4, 5, 6, 7, 6, 7, 8, 9, 10, 11, 10, 11, 12, 13, 14, 15},
236
                                       {0, 1, 0, 1, 2, 3, 4, 5, 4, 5, 6, 7, 8, 9, 8, 9},
237
                                       {2, 3, 4, 5, 4, 5, 6, 7, 8, 9, 8, 9, 10, 11, 12, 13}};
238
239
UWORD8 ref_pos_chroma_mask_m24[2][16] = {{0, 1, 2, 3, 4, 5, 4, 5, 6, 7, 8, 9, 8, 9, 10, 11},
240
                                         {2, 3, 4, 5, 6, 7, 6, 7, 8, 9, 10, 11, 10, 11, 12, 13}};
241
UWORD8 ref_pos_chroma_mask_m8[2][16] = {{0, 1, 0, 1, 2, 3, 4, 5, 4, 5, 6, 7, 8, 9, 8, 9},
242
                                        {2, 3, 2, 3, 4, 5, 6, 7, 6, 7, 8, 9, 10, 11, 10, 11}};
243
UWORD8 ref_pos_chroma_mask_m16[2][16] = {{0, 1, 2, 3, 2, 3, 4, 5, 6, 7, 6, 7, 8, 9, 10, 11},
244
                                         {2, 3, 4, 5, 4, 5, 6, 7, 8, 9, 8, 9, 10, 11, 12, 13}};
245
246
/*****************************************************************************/
247
/*                                                                           */
248
/*  Function Name :  isvcd_get_ceil_log2                                      */
249
/*                                                                           */
250
/*  Description   : this function returns the CeilLog2 of the given number   */
251
/*                                                                           */
252
/*                                                                           */
253
/*  Inputs        : i4_input : input number                                  */
254
/*  Globals       : none                                                     */
255
/*  Processing    : it calculate the bits and returns it                     */
256
/*                                                                           */
257
/*  Outputs       : none                                                     */
258
/*  Returns       : ceil of log to base 2                                    */
259
/*                                                                           */
260
/*  Issues        : none                                                     */
261
/*                                                                           */
262
/*  Revision History:                                                        */
263
/*                                                                           */
264
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
265
/*         06 09 2021   vijayakumar          creation                        */
266
/*                                                                           */
267
/*****************************************************************************/
268
WORD32 isvcd_get_ceil_log2(WORD32 i4_input)
269
26.1k
{
270
26.1k
    WORD32 i4_bits = 0;
271
272
26.1k
    i4_input--;
273
167k
    while(i4_input > 0)
274
141k
    {
275
141k
        i4_bits++;
276
141k
        i4_input >>= 1;
277
141k
    }
278
26.1k
    return (i4_bits);
279
26.1k
}
280
281
/*****************************************************************************/
282
/*                                                                           */
283
/*  Function Name : isvcd_2d_memset                                           */
284
/*                                                                           */
285
/*  Description   : Function performs 2D memset operation                    */
286
/*                                                                           */
287
/*                                                                           */
288
/*  Inputs        : 1. Buffer pointer                                        */
289
/*                  2. width                                                 */
290
/*                  3. Height                                                */
291
/*                  4. Stride                                                */
292
/*                  5. value                                                 */
293
/*  Globals       : None                                                     */
294
/*  Processing    : calls memset fucntion                                    */
295
/*                                                                           */
296
/*  Outputs       : Updates the buffer                                       */
297
/*  Returns       : status                                                   */
298
/*                                                                           */
299
/*  Issues        : None                                                     */
300
/*                                                                           */
301
/*  Revision History:                                                        */
302
/*                                                                           */
303
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
304
/*         24 09 2021   Vijay           Draft                                */
305
/*                                                                           */
306
/*****************************************************************************/
307
void isvcd_2d_memset(void *pv_buf, WORD32 i4_width, WORD32 i4_ht, WORD32 i4_stride, WORD32 i4_val)
308
0
{
309
0
    WORD32 i4_y;
310
0
    UWORD8 *pu1_buf;
311
312
0
    pu1_buf = (UWORD8 *) pv_buf;
313
314
0
    for(i4_y = 0; i4_y < i4_ht; i4_y++)
315
0
    {
316
0
        memset(pu1_buf, i4_val, i4_width);
317
        /* Increment the pointer */
318
0
        pu1_buf += i4_stride;
319
0
    }
320
0
}
321
322
/*****************************************************************************/
323
/*                                                                           */
324
/*  Function Name : isvcd_copy_data                                           */
325
/*                                                                           */
326
/*  Description   : this module copies the data from source to destination   */
327
/*                  the amount of data to be copied is passed as input       */
328
/*                                                                           */
329
/*  Inputs        : pu1_src : pointer to the source buffer                   */
330
/*                  u2_src_stride : source buffer stride                     */
331
/*                  pu1_dst : pointer to the destination buffer              */
332
/*                  u2_dst_stride : destination buffer stride                */
333
/*                  u4_num_bytes : number of bytes to be copied              */
334
/*                  u4_num_lines : number of lines to be copied              */
335
/*  Globals       : none                                                     */
336
/*  Processing    : it does a memcpy from source to destination              */
337
/*                                                                           */
338
/*  Outputs       : none                                                     */
339
/*  Returns       : none                                                     */
340
/*  Issues        : both buffers are assumed to be 2-D buffers               */
341
/*                                                                           */
342
/*  Revision History:                                                        */
343
/*                                                                           */
344
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
345
/*         29 09 2021   vijayakumar          creation                        */
346
/*                                                                           */
347
/*****************************************************************************/
348
void isvcd_copy_data(UWORD8 *pu1_src, WORD32 i4_src_stride, UWORD8 *pu1_dst, WORD32 i4_dst_stride,
349
                     WORD32 i4_num_bytes, WORD32 i4_num_lines)
350
157k
{
351
157k
    WORD32 i4_vert_lines;
352
353
    /* loop for copy all the lines requried */
354
2.47M
    for(i4_vert_lines = 0; i4_vert_lines < i4_num_lines; i4_vert_lines++)
355
2.31M
    {
356
2.31M
        memcpy(pu1_dst, pu1_src, i4_num_bytes);
357
2.31M
        pu1_src += i4_src_stride;
358
2.31M
        pu1_dst += i4_dst_stride;
359
2.31M
    }
360
157k
    return;
361
157k
}
362
363
/*****************************************************************************/
364
/*                                                                           */
365
/*  Function Name : isvcd_copy_data_semiplanr                                 */
366
/*                                                                           */
367
/*  Description   : this module copies the data from source to destination   */
368
/*                  the amount of data to be copied is passed as input       */
369
/*                                                                           */
370
/*  Inputs        : pu1_src : pointer to the source buffer                   */
371
/*                  i4_src_stride : source buffer stride                     */
372
/*                  pu1_dst1 : pointer to the destination buffer 1           */
373
/*                  pu1_dst2 : pointer to the destination buffer 2           */
374
/*                  i4_dst_stride : destination buffer stride                */
375
/*                  i4_num_bytes : number of bytes to be copied              */
376
/*                  i4_num_lines : number of lines to be copied              */
377
/*  Globals       : none                                                     */
378
/*  Processing    : it does a memcpy from source to destination              */
379
/*                                                                           */
380
/*  Outputs       : none                                                     */
381
/*  Returns       : none                                                     */
382
/*  Issues        : both buffers are assumed to be 2-D buffers               */
383
/*                                                                           */
384
/*  Revision History:                                                        */
385
/*                                                                           */
386
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
387
/*         29 09 2021   vijayakumar          creation                        */
388
/*                                                                           */
389
/*****************************************************************************/
390
void isvcd_copy_data_semiplanr(UWORD8 *pu1_src, WORD32 i4_src_stride, UWORD8 *pu1_dst1,
391
                               UWORD8 *pu1_dst2, WORD32 i4_dst_stride, WORD32 i4_num_bytes,
392
                               WORD32 i4_num_lines)
393
97.7k
{
394
97.7k
    WORD32 i4_vert_lines, u4_i;
395
396
    /* loop for copy all the lines requried */
397
1.29M
    for(i4_vert_lines = 0; i4_vert_lines < i4_num_lines; i4_vert_lines++)
398
1.20M
    {
399
15.4M
        for(u4_i = 0; u4_i < i4_num_bytes; u4_i++)
400
14.2M
        {
401
14.2M
            *(pu1_dst1 + u4_i) = *(pu1_src + (2 * u4_i));
402
14.2M
            *(pu1_dst2 + u4_i) = *(pu1_src + (2 * u4_i) + 1);
403
14.2M
        }
404
405
1.20M
        pu1_src += i4_src_stride;
406
1.20M
        pu1_dst1 += i4_dst_stride;
407
1.20M
        pu1_dst2 += i4_dst_stride;
408
1.20M
    }
409
97.7k
    return;
410
97.7k
}
411
412
/*****************************************************************************/
413
/*                                                                           */
414
/*  Function Name : isvcd_get_ref_layer_avlblty_dyadic                        */
415
/*                                                                           */
416
/*  Description   : This function is used to find the mb type of the         */
417
/*                  corresponding MB in the reference layer for dyadic cases */
418
/*                                                                           */
419
/*  Inputs        : pv_intra_samp_ctxt : intra samp context                  */
420
/*                  pi1_ref_mb_modes : ref mb modes buffer pointer           */
421
/*                  i4_ref_mode_stride : mb mode buffer stride               */
422
/*                  i4_ref_mb_x : reference MB location X                    */
423
/*                  i4_ref_mb_y : reference MB location Y                    */
424
/*                  pi4_mb_type : pointer to store the mb type               */
425
/*                  i1_curr_slice_id : slice id of current MB                */
426
/*                  i1_cons_intr_samp_flag :constrained intra resampling flag*/
427
/*  Globals       : none                                                     */
428
/*  Processing    : it derives the bit corresponding to reference MB and     */
429
/*                  stores the mbtype as INTRA if the bit is set             */
430
/*  Outputs       : none                                                     */
431
/*  Returns       : none                                                     */
432
/*                                                                           */
433
/*  Issues        : none                                                     */
434
/*                                                                           */
435
/*  Revision History:                                                        */
436
/*                                                                           */
437
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
438
/*         26 09 2021   vijayakumar          creation                        */
439
/*                                                                           */
440
/*****************************************************************************/
441
void isvcd_get_ref_layer_avlblty_dyadic(WORD8 *pi1_ref_mb_modes, WORD32 i4_ref_mode_stride,
442
                                        WORD32 i4_element_size, WORD32 i4_ref_mb_x,
443
                                        WORD32 i4_ref_mb_y, WORD32 *pi4_avlblty,
444
                                        WORD8 i1_curr_slice_id, WORD8 i1_cons_intr_samp_flag)
445
294k
{
446
294k
    inter_lyr_mb_prms_t *ps_inter_lyr_mb_prms;
447
294k
    WORD8 i1_mb_mode;
448
449
    /* get the location of the byte which has the current mb mode */
450
294k
    pi1_ref_mb_modes += (i4_ref_mb_y * i4_ref_mode_stride * i4_element_size);
451
294k
    pi1_ref_mb_modes += (i4_ref_mb_x * i4_element_size);
452
294k
    ps_inter_lyr_mb_prms = (inter_lyr_mb_prms_t *) pi1_ref_mb_modes;
453
294k
    i1_mb_mode = ps_inter_lyr_mb_prms->i1_mb_mode;
454
455
294k
    if(i1_mb_mode <= SVC_INTER_MB)
456
247k
    {
457
        /* INTER */
458
247k
        *pi4_avlblty = 0;
459
247k
    }
460
46.8k
    else
461
46.8k
    {
462
        /* INTRA */
463
46.8k
        *pi4_avlblty = 1;
464
46.8k
    }
465
466
    /* if constrained intra flag is 1 then check for same slice id */
467
294k
    if(1 == i1_cons_intr_samp_flag)
468
156k
    {
469
156k
        if(1 == *pi4_avlblty)
470
21.3k
        {
471
            /* check for different slice idc */
472
21.3k
            if(ps_inter_lyr_mb_prms->i1_slice_id != i1_curr_slice_id)
473
3.04k
            {
474
                /* store the mode as not available for upsampling */
475
3.04k
                *pi4_avlblty = 0;
476
3.04k
            }
477
21.3k
        }
478
156k
    }
479
294k
}
480
/*****************************************************************************/
481
/*                                                                           */
482
/*  Function Name : isvcd_diagonal_construct_dyadic                           */
483
/*                                                                           */
484
/*  Description   : This function fills the unavaible pixels in the reference*/
485
/*                    array with diagonally constructed samples              */
486
/*  Inputs        : i4_x :current position in reference array X to be filled */
487
/*                  i4_y :current position in reference array Y to be filled */
488
/*                  i4_xd_index : diagonal index in horizontal direction     */
489
/*                  i4_yd_index : diagonal index in vertical direction       */
490
/*                  pu1_refarray : popinter to reference array               */
491
/*                  i4_refarray_wd: width of the reference array             */
492
/*  Globals       : none                                                     */
493
/*  Processing    : Fills the sample which is unavailable with filtered      */
494
/*                    diagonal samples                                       */
495
/*  Outputs       : pixel filled                                             */
496
/*  Returns       : constructed pixel                                        */
497
/*                                                                           */
498
/*  Issues        : none                                                     */
499
/*                                                                           */
500
/*  Revision History:                                                        */
501
/*                                                                           */
502
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
503
/*         06 09 2021   Kishore         creation                             */
504
/*                                                                           */
505
/*****************************************************************************/
506
UWORD8 isvcd_diagonal_construct_dyadic(WORD32 i4_x, WORD32 i4_y, WORD32 i4_xd_index,
507
                                       WORD32 i4_yd_index, UWORD8 *pu1_refarray,
508
                                       WORD32 i4_refarray_wd)
509
337k
{
510
337k
    WORD32 i4_diff_hor_ver, i4_sgn_xy;
511
337k
    WORD32 i4_xc, i4_yc;
512
337k
    WORD32 i4_samp1, i4_samp2, i4_samp3;
513
337k
    WORD32 i4_result;
514
337k
    UWORD8 *pu1_tmp;
515
516
337k
    i4_diff_hor_ver = ABS(i4_xd_index) - ABS(i4_yd_index);
517
337k
    i4_sgn_xy = SIGN(i4_xd_index * i4_yd_index);
518
519
337k
    if(i4_diff_hor_ver > 0)
520
137k
    {
521
137k
        i4_xc = i4_x - (i4_sgn_xy * i4_yd_index);
522
137k
        i4_yc = i4_y - i4_yd_index;
523
137k
        pu1_tmp = pu1_refarray + (i4_yc * i4_refarray_wd);
524
137k
        i4_samp1 = pu1_tmp[i4_xc - 1];
525
137k
        i4_samp2 = pu1_tmp[i4_xc];
526
137k
        i4_samp3 = pu1_tmp[i4_xc + 1];
527
137k
    }
528
199k
    else if(i4_diff_hor_ver < 0)
529
143k
    {
530
143k
        i4_xc = i4_x - i4_xd_index;
531
143k
        i4_yc = i4_y - (i4_sgn_xy * i4_xd_index);
532
143k
        pu1_tmp = pu1_refarray + ((i4_yc - 1) * i4_refarray_wd);
533
143k
        i4_samp1 = pu1_tmp[i4_xc];
534
143k
        pu1_tmp += i4_refarray_wd;
535
143k
        i4_samp2 = pu1_tmp[i4_xc];
536
143k
        pu1_tmp += i4_refarray_wd;
537
143k
        i4_samp3 = pu1_tmp[i4_xc];
538
143k
    }
539
55.9k
    else
540
55.9k
    {
541
55.9k
        WORD32 i4_ref_xd, i4_ref_yd;
542
543
55.9k
        i4_ref_xd = i4_x - i4_xd_index;
544
55.9k
        i4_ref_yd = i4_y - i4_yd_index;
545
55.9k
        i4_xc = i4_ref_xd + SIGN(i4_xd_index);
546
55.9k
        i4_yc = i4_ref_yd + SIGN(i4_yd_index);
547
55.9k
        pu1_tmp = pu1_refarray + (i4_ref_yd * i4_refarray_wd);
548
55.9k
        i4_samp1 = pu1_tmp[i4_xc];
549
55.9k
        i4_samp2 = pu1_tmp[i4_ref_xd];
550
55.9k
        pu1_tmp = pu1_refarray + (i4_yc * i4_refarray_wd);
551
55.9k
        i4_samp3 = pu1_tmp[i4_ref_xd];
552
55.9k
    }
553
554
337k
    i4_result = (i4_samp1 + (i4_samp2 << 1) + i4_samp3 + 2) >> 2;
555
337k
    pu1_tmp = pu1_refarray + (i4_y * i4_refarray_wd);
556
    /* Store the filled sample */
557
337k
    pu1_tmp[i4_x] = i4_result;
558
559
337k
    return (i4_result);
560
337k
}
561
562
/*****************************************************************************/
563
/*                                                                           */
564
/*  Function Name : isvcd_left_right_padding                                  */
565
/*  Description   :  This function does the left/right padding for intra     */
566
/*                      upsampling                                           */
567
/*                                                                           */
568
/*  Inputs        :                                                          */
569
/*  Globals       : none                                                     */
570
/*  Processing    : This function does the left/right padding for intra      */
571
/*                      upsampling                                           */
572
/*  Outputs       : none                                                     */
573
/*  Returns       : number of leading zeroes                                 */
574
/*  Issues        : none                                                     */
575
/*  Revision History:                                                        */
576
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
577
/*         06 09 2021   Vijay                creation                        */
578
/*****************************************************************************/
579
void isvcd_left_right_padding(WORD32 i4_x, WORD32 i4_y, WORD8 i1_xd_index, WORD8 i1_yd_index,
580
                              UWORD8 u1_seg_wd, UWORD8 u1_seg_ht, UWORD8 *pu1_refarray_1,
581
                              UWORD8 *pu1_refarray_2, WORD32 i4_refarray_stride,
582
                              WORD32 i4_mb_adjoin_x, WORD32 i4_mb_adjoin_y,
583
                              WORD32 i4_corner_pixel_available)
584
31.5k
{
585
31.5k
    WORD32 i4_idx_i;
586
31.5k
    UWORD8 *pu1_src, *pu1_dst;
587
588
31.5k
    UNUSED(i1_yd_index);
589
31.5k
    UNUSED(pu1_refarray_2);
590
31.5k
    UNUSED(i4_mb_adjoin_x);
591
31.5k
    UNUSED(i4_mb_adjoin_y);
592
31.5k
    UNUSED(i4_corner_pixel_available);
593
594
31.5k
    pu1_dst = pu1_refarray_1 + i4_x + (i4_y * i4_refarray_stride);
595
31.5k
    pu1_src = pu1_dst + i1_xd_index;
596
31.5k
    i1_xd_index = MIN(i1_xd_index, MAX_PIX_FILL_LUMA);
597
31.5k
    u1_seg_wd = MIN(u1_seg_wd, MAX_PIX_FILL_LUMA);
598
31.5k
    pu1_dst = pu1_src - i1_xd_index;
599
600
240k
    for(i4_idx_i = 0; i4_idx_i < u1_seg_ht; i4_idx_i++)
601
208k
    {
602
208k
        memset(pu1_dst, *pu1_src, u1_seg_wd);
603
208k
        pu1_dst += i4_refarray_stride;
604
208k
        pu1_src += i4_refarray_stride;
605
208k
    }
606
31.5k
}
607
/*****************************************************************************/
608
/*                                                                           */
609
/*  Function Name : isvcd_left_right_padding_chroma                           */
610
/*  Description   :  This function does the left/right padding for intra     */
611
/*                      upsampling for chroma                                */
612
/*                                                                           */
613
/*  Inputs        :                                                          */
614
/*  Globals       : none                                                     */
615
/*  Processing    : This function does the left/right padding for intra      */
616
/*                      upsampling for chroma                                */
617
/*  Outputs       : none                                                     */
618
/*  Returns       : none                                                     */
619
/*  Issues        : none                                                     */
620
/*  Revision History:                                                        */
621
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
622
/*         06 09 2011   Vijay                creation                        */
623
/*****************************************************************************/
624
void isvcd_left_right_padding_chroma(WORD32 i4_x, WORD32 i4_y, WORD8 i1_xd_index, WORD8 i1_yd_index,
625
                                     UWORD8 u1_seg_wd, UWORD8 u1_seg_ht, UWORD8 *pu1_refarray_1,
626
                                     UWORD8 *pu1_refarray_2, WORD32 i4_refarray_stride,
627
                                     WORD32 i4_mb_adjoin_x, WORD32 i4_mb_adjoin_y,
628
                                     WORD32 i4_corner_pixel_available)
629
31.8k
{
630
31.8k
    WORD32 i4_idx_i;
631
31.8k
    UWORD8 *pu1_src_cb, *pu1_dst_cb;
632
31.8k
    UWORD8 *pu1_src_cr, *pu1_dst_cr;
633
31.8k
    WORD32 i4_tmp;
634
635
31.8k
    UNUSED(i1_yd_index);
636
31.8k
    UNUSED(i4_mb_adjoin_x);
637
31.8k
    UNUSED(i4_mb_adjoin_y);
638
31.8k
    UNUSED(i4_corner_pixel_available);
639
640
31.8k
    i4_tmp = i4_x + (i4_y * i4_refarray_stride);
641
31.8k
    pu1_dst_cb = pu1_refarray_1 + i4_tmp;
642
31.8k
    pu1_src_cb = pu1_dst_cb + i1_xd_index;
643
31.8k
    pu1_dst_cr = pu1_refarray_2 + i4_tmp;
644
31.8k
    pu1_src_cr = pu1_dst_cr + i1_xd_index;
645
646
31.8k
    i1_xd_index = MIN(i1_xd_index, MAX_PIX_FILL_CHROMA);
647
31.8k
    u1_seg_wd = MIN(u1_seg_wd, MAX_PIX_FILL_CHROMA);
648
31.8k
    pu1_dst_cb = pu1_src_cb - i1_xd_index;
649
31.8k
    pu1_dst_cr = pu1_src_cr - i1_xd_index;
650
651
141k
    for(i4_idx_i = 0; i4_idx_i < u1_seg_ht; i4_idx_i++)
652
109k
    {
653
109k
        memset(pu1_dst_cb, *pu1_src_cb, u1_seg_wd);
654
109k
        pu1_dst_cb += i4_refarray_stride;
655
109k
        pu1_src_cb += i4_refarray_stride;
656
109k
        memset(pu1_dst_cr, *pu1_src_cr, u1_seg_wd);
657
109k
        pu1_dst_cr += i4_refarray_stride;
658
109k
        pu1_src_cr += i4_refarray_stride;
659
109k
    }
660
31.8k
}
661
662
/*****************************************************************************/
663
/*                                                                           */
664
/*  Function Name : isvcd_top_bot_padding                                     */
665
/*  Description   :  This function does the top/bottom padding for intra     */
666
/*                      upsampling for chroma                                */
667
/*                                                                           */
668
/*  Inputs        :                                                          */
669
/*  Globals       : none                                                     */
670
/*  Processing    : This function does the top/bottom padding for intra      */
671
/*                      upsampling for chroma                                */
672
/*  Outputs       : none                                                     */
673
/*  Returns       : none                                                     */
674
/*  Issues        : none                                                     */
675
/*  Revision History:                                                        */
676
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
677
/*         06 09 2021   Vijay                creation                        */
678
/*****************************************************************************/
679
void isvcd_top_bot_padding(WORD32 i4_x, WORD32 i4_y, WORD8 i1_xd_index, WORD8 i1_yd_index,
680
                           UWORD8 u1_seg_wd, UWORD8 u1_seg_ht, UWORD8 *pu1_refarray_1,
681
                           UWORD8 *pu1_refarray_2, WORD32 i4_refarray_stride, WORD32 i4_mb_adjoin_x,
682
                           WORD32 i4_mb_adjoin_y, WORD32 i4_corner_pixel_available)
683
27.1k
{
684
27.1k
    WORD32 i4_idx_i;
685
27.1k
    UWORD8 *pu1_src, *pu1_dst;
686
687
27.1k
    UNUSED(i1_xd_index);
688
27.1k
    UNUSED(pu1_refarray_2);
689
27.1k
    UNUSED(i4_mb_adjoin_x);
690
27.1k
    UNUSED(i4_mb_adjoin_y);
691
27.1k
    UNUSED(i4_corner_pixel_available);
692
693
27.1k
    pu1_dst = pu1_refarray_1 + i4_x + (i4_y * i4_refarray_stride);
694
27.1k
    pu1_src = pu1_dst + (i1_yd_index * i4_refarray_stride);
695
27.1k
    i1_yd_index = MIN(i1_yd_index, MAX_PIX_FILL_LUMA);
696
27.1k
    u1_seg_ht = MIN(u1_seg_ht, MAX_PIX_FILL_LUMA);
697
27.1k
    pu1_dst = pu1_src - (i1_yd_index * i4_refarray_stride);
698
699
112k
    for(i4_idx_i = 0; i4_idx_i < u1_seg_ht; i4_idx_i++)
700
85.7k
    {
701
85.7k
        memcpy(pu1_dst, pu1_src, u1_seg_wd);
702
85.7k
        pu1_dst += i4_refarray_stride;
703
85.7k
    }
704
27.1k
}
705
706
/*****************************************************************************/
707
/*                                                                           */
708
/*  Function Name : isvcd_top_bot_padding                                     */
709
/*  Description   :  This function does the top/bottom padding for intra     */
710
/*                      upsampling for chroma                                */
711
/*                                                                           */
712
/*  Inputs        :                                                          */
713
/*  Globals       : none                                                     */
714
/*  Processing    : This function does the top/bottom padding for intra      */
715
/*                      upsampling for chroma                                */
716
/*  Outputs       : none                                                     */
717
/*  Returns       : none                                                     */
718
/*  Issues        : none                                                     */
719
/*  Revision History:                                                        */
720
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
721
/*         06 09 2021   Vijay                creation                        */
722
/*****************************************************************************/
723
void isvcd_top_bot_padding_chroma(WORD32 i4_x, WORD32 i4_y, WORD8 i1_xd_index, WORD8 i1_yd_index,
724
                                  UWORD8 u1_seg_wd, UWORD8 u1_seg_ht, UWORD8 *pu1_refarray_1,
725
                                  UWORD8 *pu1_refarray_2, WORD32 i4_refarray_stride,
726
                                  WORD32 i4_mb_adjoin_x, WORD32 i4_mb_adjoin_y,
727
                                  WORD32 i4_corner_pixel_available)
728
27.1k
{
729
27.1k
    WORD32 i4_idx_i;
730
27.1k
    UWORD8 *pu1_src_cb, *pu1_dst_cb;
731
27.1k
    UWORD8 *pu1_src_cr, *pu1_dst_cr;
732
27.1k
    WORD32 i4_tmp;
733
734
27.1k
    UNUSED(i1_xd_index);
735
27.1k
    UNUSED(pu1_refarray_2);
736
27.1k
    UNUSED(i4_mb_adjoin_x);
737
27.1k
    UNUSED(i4_mb_adjoin_y);
738
27.1k
    UNUSED(i4_corner_pixel_available);
739
740
27.1k
    i4_tmp = i4_x + (i4_y * i4_refarray_stride);
741
27.1k
    pu1_dst_cb = pu1_refarray_1 + i4_tmp;
742
27.1k
    pu1_dst_cr = pu1_refarray_2 + i4_tmp;
743
744
27.1k
    i4_tmp = (i1_yd_index * i4_refarray_stride);
745
27.1k
    pu1_src_cb = pu1_dst_cb + i4_tmp;
746
27.1k
    pu1_src_cr = pu1_dst_cr + i4_tmp;
747
27.1k
    i1_yd_index = MIN(i1_yd_index, MAX_PIX_FILL_CHROMA);
748
27.1k
    u1_seg_ht = MIN(u1_seg_ht, MAX_PIX_FILL_CHROMA);
749
750
27.1k
    i4_tmp = (i1_yd_index * i4_refarray_stride);
751
27.1k
    pu1_dst_cb = pu1_src_cb - i4_tmp;
752
27.1k
    pu1_dst_cr = pu1_src_cr - i4_tmp;
753
754
74.1k
    for(i4_idx_i = 0; i4_idx_i < u1_seg_ht; i4_idx_i++)
755
47.0k
    {
756
47.0k
        memcpy(pu1_dst_cb, pu1_src_cb, u1_seg_wd);
757
47.0k
        pu1_dst_cb += i4_refarray_stride;
758
47.0k
        memcpy(pu1_dst_cr, pu1_src_cr, u1_seg_wd);
759
47.0k
        pu1_dst_cr += i4_refarray_stride;
760
47.0k
    }
761
27.1k
}
762
763
/*****************************************************************************/
764
/*                                                                           */
765
/*  Function Name : isvcd_diag_reconstruction                                 */
766
/*  Description   :  This function does the diagonal reconstuction for intra */
767
/*                      upsampling for luma                                  */
768
/*                                                                           */
769
/*  Inputs        :                                                          */
770
/*  Globals       : none                                                     */
771
/*  Processing    : This function does the diagonal reconstruction for intra */
772
/*                      upsampling for luma                                  */
773
/*  Outputs       : none                                                     */
774
/*  Returns       : none                                                     */
775
/*  Issues        : none                                                     */
776
/*  Revision History:                                                        */
777
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
778
/*         06 09 2021   Vijay                creation                        */
779
/*****************************************************************************/
780
void isvcd_diag_reconstruction(WORD32 i4_x, WORD32 i4_y, WORD8 i1_xd_index, WORD8 i1_yd_index,
781
                               UWORD8 u1_seg_wd, UWORD8 u1_seg_ht, UWORD8 *pu1_refarray_1,
782
                               UWORD8 *pu1_refarray_2, WORD32 i4_refarray_stride,
783
                               WORD32 i4_mb_adjoin_x, WORD32 i4_mb_adjoin_y,
784
                               WORD32 i4_corner_pixel_available)
785
23.6k
{
786
23.6k
    WORD32 i4_i;
787
23.6k
    UWORD8 *pu1_src_1, *pu1_src_2, *pu1_dst;
788
23.6k
    UWORD8 u1_filter_delay_buf[18] = {0};
789
23.6k
    UWORD8 u1_out_buf[16] = {0};
790
23.6k
    WORD32 i4_width, i4_height;
791
23.6k
    WORD32 i4_x_off, i4_y_off;
792
23.6k
    WORD32 i4_block_size = BLOCK_WIDTH;
793
794
23.6k
    UNUSED(pu1_refarray_2);
795
796
23.6k
    pu1_dst = pu1_refarray_1 + i4_x + (i4_y * i4_refarray_stride);
797
23.6k
    pu1_src_1 = pu1_dst + i1_xd_index;
798
23.6k
    pu1_src_2 = pu1_dst + (i1_yd_index * i4_refarray_stride);
799
800
23.6k
    i4_width = MAX(u1_seg_wd, (((i4_mb_adjoin_x >> 3) ^ 1) * i4_block_size));
801
23.6k
    i4_height = MAX(u1_seg_ht, (((i4_mb_adjoin_y >> 4) ^ 1) * i4_block_size));
802
23.6k
    i4_x_off = (i4_width - u1_seg_wd);
803
23.6k
    i4_y_off = (i4_height - u1_seg_ht);
804
805
23.6k
    if(i1_xd_index < 0 && i1_yd_index > 0)
806
5.95k
    {
807
        /* Quadrant 1 Processing load the pixel in the filter delay buffer */
808
52.6k
        for(i4_i = 0; i4_i < (i4_height + 1); i4_i++)
809
46.7k
        {
810
46.7k
            u1_filter_delay_buf[i4_i] = *pu1_src_1;
811
46.7k
            pu1_src_1 += i4_refarray_stride;
812
46.7k
        }
813
814
5.95k
        pu1_src_2 -= i4_x_off;
815
5.95k
        memcpy(&u1_filter_delay_buf[i4_i], pu1_src_2, i4_width);
816
817
5.95k
        if(0 == i4_corner_pixel_available)
818
5.56k
        {
819
            /* interpolate the unavailable corner pixel */
820
5.56k
            u1_filter_delay_buf[i4_i - 1] =
821
5.56k
                (u1_filter_delay_buf[i4_i] + u1_filter_delay_buf[i4_i - 2] + 1) >> 1;
822
5.56k
        }
823
824
84.0k
        for(i4_i = 0; i4_i < (i4_width + i4_height - 1); i4_i++)
825
78.1k
        {
826
            /* get the filtered output */
827
78.1k
            u1_out_buf[i4_i] = ((u1_filter_delay_buf[i4_i]) + (u1_filter_delay_buf[i4_i + 1] * 2) +
828
78.1k
                                (u1_filter_delay_buf[i4_i + 2]) + 2) >>
829
78.1k
                               2;
830
78.1k
        }
831
832
        /* fill the segment with diagonal reconstructed output */
833
40.5k
        for(i4_i = 0; i4_i < u1_seg_ht; i4_i++)
834
34.6k
        {
835
34.6k
            memcpy(pu1_dst, &u1_out_buf[i4_x_off + i4_i], u1_seg_wd);
836
34.6k
            pu1_dst += i4_refarray_stride;
837
34.6k
        }
838
5.95k
    }
839
17.7k
    else if(i1_xd_index > 0 && i1_yd_index > 0)
840
6.00k
    {
841
        /* Quadrant 2 Processing */
842
        /* load the pixel in the filter delay buffer  */
843
6.00k
        memcpy(&u1_filter_delay_buf[0], pu1_src_2, (i4_width + 1));
844
46.0k
        for(i4_i = i4_height; i4_i > 0; i4_i--)
845
39.9k
        {
846
39.9k
            u1_filter_delay_buf[i4_width + i4_i] = *pu1_src_1;
847
39.9k
            pu1_src_1 += i4_refarray_stride;
848
39.9k
        }
849
850
6.00k
        if(0 == i4_corner_pixel_available)
851
5.30k
        {
852
            /* interpolate the unavailable corner pixel */
853
5.30k
            u1_filter_delay_buf[i4_width] =
854
5.30k
                (u1_filter_delay_buf[i4_width - 1] + u1_filter_delay_buf[i4_width + 1] + 1) >> 1;
855
5.30k
        }
856
857
88.0k
        for(i4_i = 0; i4_i < (i4_width + i4_height - 1); i4_i++)
858
82.0k
        {
859
            /* get the filtered output */
860
82.0k
            u1_out_buf[i4_i] = ((u1_filter_delay_buf[i4_i]) + (u1_filter_delay_buf[i4_i + 1] * 2) +
861
82.0k
                                (u1_filter_delay_buf[i4_i + 2]) + 2) >>
862
82.0k
                               2;
863
82.0k
        }
864
865
        /* fill the segment with diagonal reconstructed output */
866
41.2k
        for(i4_i = 1; i4_i <= u1_seg_ht; i4_i++)
867
35.2k
        {
868
35.2k
            memcpy(pu1_dst, &u1_out_buf[i4_height - i4_i], u1_seg_wd);
869
35.2k
            pu1_dst += i4_refarray_stride;
870
35.2k
        }
871
6.00k
    }
872
11.7k
    else if(i1_xd_index > 0 && i1_yd_index < 0)
873
6.40k
    {
874
        /* Quadrant 3 Processing */
875
        /* load the pixel in the filter delay buffer  */
876
6.40k
        memcpy(&u1_filter_delay_buf[0], pu1_src_2, (i4_width + 1));
877
878
6.40k
        pu1_src_1 -= (i4_y_off * i4_refarray_stride);
879
45.7k
        for(i4_i = 1; i4_i <= i4_height; i4_i++)
880
39.3k
        {
881
39.3k
            u1_filter_delay_buf[i4_width + i4_i] = *pu1_src_1;
882
39.3k
            pu1_src_1 += i4_refarray_stride;
883
39.3k
        }
884
885
6.40k
        if(0 == i4_corner_pixel_available)
886
5.80k
        {
887
            /* interpolate the unavailable corner pixel */
888
5.80k
            u1_filter_delay_buf[i4_width] =
889
5.80k
                (u1_filter_delay_buf[i4_width - 1] + u1_filter_delay_buf[i4_width + 1] + 1) >> 1;
890
5.80k
        }
891
892
90.6k
        for(i4_i = 0; i4_i < (i4_width + i4_height - 1); i4_i++)
893
84.2k
        {
894
            /* get the filtered output */
895
84.2k
            u1_out_buf[i4_i] = ((u1_filter_delay_buf[i4_i]) + (u1_filter_delay_buf[i4_i + 1] * 2) +
896
84.2k
                                (u1_filter_delay_buf[i4_i + 2]) + 2) >>
897
84.2k
                               2;
898
84.2k
        }
899
900
        /* fill the segment with diagonal reconstructed output */
901
41.4k
        for(i4_i = 0; i4_i < u1_seg_ht; i4_i++)
902
35.0k
        {
903
35.0k
            memcpy(pu1_dst, &u1_out_buf[i4_y_off + i4_i], u1_seg_wd);
904
35.0k
            pu1_dst += i4_refarray_stride;
905
35.0k
        }
906
6.40k
    }
907
5.30k
    else
908
5.30k
    {
909
        /* Quadrant 4 Processing */
910
        /* load the pixel in the filter delay buffer  */
911
5.30k
        pu1_src_1 += ((u1_seg_ht - 1) * i4_refarray_stride);
912
42.7k
        for(i4_i = 0; i4_i <= i4_height; i4_i++)
913
37.4k
        {
914
37.4k
            u1_filter_delay_buf[i4_i] = *pu1_src_1;
915
37.4k
            pu1_src_1 -= i4_refarray_stride;
916
37.4k
        }
917
918
5.30k
        pu1_src_2 -= i4_x_off;
919
5.30k
        memcpy(&u1_filter_delay_buf[i4_i], pu1_src_2, i4_width);
920
921
5.30k
        if(0 == i4_corner_pixel_available)
922
4.87k
        {
923
            /* interpolate the unavailable corner pixel */
924
4.87k
            u1_filter_delay_buf[i4_i - 1] =
925
4.87k
                (u1_filter_delay_buf[i4_i] + u1_filter_delay_buf[i4_i - 2] + 1) >> 1;
926
4.87k
        }
927
928
71.0k
        for(i4_i = 0; i4_i < (i4_width + i4_height - 1); i4_i++)
929
65.7k
        {
930
            /* get the filtered output */
931
65.7k
            u1_out_buf[i4_i] = ((u1_filter_delay_buf[i4_i]) + (u1_filter_delay_buf[i4_i + 1] * 2) +
932
65.7k
                                (u1_filter_delay_buf[i4_i + 2]) + 2) >>
933
65.7k
                               2;
934
65.7k
        }
935
936
        /* fill the segment with diagonal reconstructed output */
937
34.7k
        for(i4_i = 1; i4_i <= u1_seg_ht; i4_i++)
938
29.4k
        {
939
29.4k
            memcpy(pu1_dst, &u1_out_buf[(u1_seg_ht + i4_x_off) - i4_i], u1_seg_wd);
940
29.4k
            pu1_dst += i4_refarray_stride;
941
29.4k
        }
942
5.30k
    }
943
23.6k
}
944
/*****************************************************************************/
945
/*                                                                           */
946
/*  Function Name : isvcd_diag_reconstruction_chroma                          */
947
/*  Description   :  This function does the diagonal reconstuction for intra */
948
/*                      upsampling for chroma                                */
949
/*                                                                           */
950
/*  Inputs        :                                                          */
951
/*  Globals       : none                                                     */
952
/*  Processing    : This function does the diagonal reconstruction for intra */
953
/*                      upsampling for chroma                                */
954
/*  Outputs       : none                                                     */
955
/*  Returns       : none                                                     */
956
/*  Issues        : none                                                     */
957
/*  Revision History:                                                        */
958
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
959
/*         06 09 2021   Vijay                creation                        */
960
/*****************************************************************************/
961
void isvcd_diag_reconstruction_chroma(WORD32 i4_x, WORD32 i4_y, WORD8 i1_xd_index,
962
                                      WORD8 i1_yd_index, UWORD8 u1_seg_wd, UWORD8 u1_seg_ht,
963
                                      UWORD8 *pu1_refarray_1, UWORD8 *pu1_refarray_2,
964
                                      WORD32 i4_refarray_stride, WORD32 i4_mb_adjoin_x,
965
                                      WORD32 i4_mb_adjoin_y, WORD32 i4_corner_pixel_available)
966
23.6k
{
967
23.6k
    WORD32 i4_i;
968
23.6k
    UWORD8 u1_filter_delay_buf_cb[18] = {0};
969
23.6k
    UWORD8 u1_filter_delay_buf_cr[18] = {0};
970
23.6k
    UWORD8 u1_out_buf_cb[16] = {0};
971
23.6k
    UWORD8 u1_out_buf_cr[16] = {0};
972
23.6k
    WORD32 i4_width, i4_height;
973
23.6k
    WORD32 i4_x_off, i4_y_off;
974
23.6k
    WORD32 i4_block_size = BLOCK_WIDTH >> 1;
975
23.6k
    UWORD8 *pu1_src_1_cb, *pu1_src_2_cb, *pu1_dst_cb;
976
23.6k
    UWORD8 *pu1_src_1_cr, *pu1_src_2_cr, *pu1_dst_cr;
977
23.6k
    WORD32 i4_tmp;
978
979
23.6k
    i4_tmp = i4_x + (i4_y * i4_refarray_stride);
980
23.6k
    pu1_dst_cb = pu1_refarray_1 + i4_tmp;
981
23.6k
    pu1_dst_cr = pu1_refarray_2 + i4_tmp;
982
983
23.6k
    pu1_src_1_cb = pu1_dst_cb + i1_xd_index;
984
23.6k
    pu1_src_1_cr = pu1_dst_cr + i1_xd_index;
985
23.6k
    i4_tmp = (i1_yd_index * i4_refarray_stride);
986
23.6k
    pu1_src_2_cb = pu1_dst_cb + i4_tmp;
987
23.6k
    pu1_src_2_cr = pu1_dst_cr + i4_tmp;
988
989
23.6k
    i4_width = MAX(u1_seg_wd, (((i4_mb_adjoin_x >> 3) ^ 1) * i4_block_size));
990
23.6k
    i4_height = MAX(u1_seg_ht, (((i4_mb_adjoin_y >> 4) ^ 1) * i4_block_size));
991
23.6k
    i4_x_off = (i4_width - u1_seg_wd);
992
23.6k
    i4_y_off = (i4_height - u1_seg_ht);
993
994
23.6k
    if(i1_xd_index < 0 && i1_yd_index > 0)
995
5.95k
    {
996
        /* Quadrant 1 Processing load the pixel in the filter delay buffer */
997
32.9k
        for(i4_i = 0; i4_i < (i4_height + 1); i4_i++)
998
27.0k
        {
999
27.0k
            u1_filter_delay_buf_cb[i4_i] = *pu1_src_1_cb;
1000
27.0k
            pu1_src_1_cb += i4_refarray_stride;
1001
27.0k
            u1_filter_delay_buf_cr[i4_i] = *pu1_src_1_cr;
1002
27.0k
            pu1_src_1_cr += i4_refarray_stride;
1003
27.0k
        }
1004
1005
5.95k
        pu1_src_2_cb -= i4_x_off;
1006
5.95k
        pu1_src_2_cr -= i4_x_off;
1007
5.95k
        memcpy(&u1_filter_delay_buf_cb[i4_i], pu1_src_2_cb, i4_width);
1008
5.95k
        memcpy(&u1_filter_delay_buf_cr[i4_i], pu1_src_2_cr, i4_width);
1009
1010
5.95k
        if(0 == i4_corner_pixel_available)
1011
5.56k
        {
1012
            /* interpolate the unavailable corner pixel */
1013
5.56k
            u1_filter_delay_buf_cb[i4_i - 1] =
1014
5.56k
                (u1_filter_delay_buf_cb[i4_i] + u1_filter_delay_buf_cb[i4_i - 2] + 1) >> 1;
1015
1016
5.56k
            u1_filter_delay_buf_cr[i4_i - 1] =
1017
5.56k
                (u1_filter_delay_buf_cr[i4_i] + u1_filter_delay_buf_cr[i4_i - 2] + 1) >> 1;
1018
5.56k
        }
1019
1020
44.8k
        for(i4_i = 0; i4_i < (i4_width + i4_height - 1); i4_i++)
1021
38.9k
        {
1022
            /* get the filtered output */
1023
38.9k
            u1_out_buf_cb[i4_i] =
1024
38.9k
                ((u1_filter_delay_buf_cb[i4_i]) + (u1_filter_delay_buf_cb[i4_i + 1] * 2) +
1025
38.9k
                 (u1_filter_delay_buf_cb[i4_i + 2]) + 2) >>
1026
38.9k
                2;
1027
1028
38.9k
            u1_out_buf_cr[i4_i] =
1029
38.9k
                ((u1_filter_delay_buf_cr[i4_i]) + (u1_filter_delay_buf_cr[i4_i + 1] * 2) +
1030
38.9k
                 (u1_filter_delay_buf_cr[i4_i + 2]) + 2) >>
1031
38.9k
                2;
1032
38.9k
        }
1033
1034
        /* fill the segment with diagonal reconstructed output */
1035
24.0k
        for(i4_i = 0; i4_i < u1_seg_ht; i4_i++)
1036
18.0k
        {
1037
18.0k
            memcpy(pu1_dst_cb, &u1_out_buf_cb[i4_x_off + i4_i], u1_seg_wd);
1038
18.0k
            pu1_dst_cb += i4_refarray_stride;
1039
18.0k
            memcpy(pu1_dst_cr, &u1_out_buf_cr[i4_x_off + i4_i], u1_seg_wd);
1040
18.0k
            pu1_dst_cr += i4_refarray_stride;
1041
18.0k
        }
1042
5.95k
    }
1043
17.7k
    else if(i1_xd_index > 0 && i1_yd_index > 0)
1044
6.00k
    {
1045
        /* Quadrant 2 Processing load the pixel in the filter delay buffer  */
1046
6.00k
        memcpy(&u1_filter_delay_buf_cb[0], pu1_src_2_cb, (i4_width + 1));
1047
6.00k
        memcpy(&u1_filter_delay_buf_cr[0], pu1_src_2_cr, (i4_width + 1));
1048
1049
26.7k
        for(i4_i = i4_height; i4_i > 0; i4_i--)
1050
20.7k
        {
1051
20.7k
            u1_filter_delay_buf_cb[i4_width + i4_i] = *pu1_src_1_cb;
1052
20.7k
            pu1_src_1_cb += i4_refarray_stride;
1053
1054
20.7k
            u1_filter_delay_buf_cr[i4_width + i4_i] = *pu1_src_1_cr;
1055
20.7k
            pu1_src_1_cr += i4_refarray_stride;
1056
20.7k
        }
1057
1058
6.00k
        if(0 == i4_corner_pixel_available)
1059
5.30k
        {
1060
            /* interpolate the unavailable corner pixel */
1061
5.30k
            u1_filter_delay_buf_cb[i4_width] =
1062
5.30k
                (u1_filter_delay_buf_cb[i4_width - 1] + u1_filter_delay_buf_cb[i4_width + 1] + 1) >>
1063
5.30k
                1;
1064
1065
5.30k
            u1_filter_delay_buf_cr[i4_width] =
1066
5.30k
                (u1_filter_delay_buf_cr[i4_width - 1] + u1_filter_delay_buf_cr[i4_width + 1] + 1) >>
1067
5.30k
                1;
1068
5.30k
        }
1069
1070
44.8k
        for(i4_i = 0; i4_i < (i4_width + i4_height - 1); i4_i++)
1071
38.7k
        {
1072
            /* get the filtered output */
1073
38.7k
            u1_out_buf_cb[i4_i] =
1074
38.7k
                ((u1_filter_delay_buf_cb[i4_i]) + (u1_filter_delay_buf_cb[i4_i + 1] * 2) +
1075
38.7k
                 (u1_filter_delay_buf_cb[i4_i + 2]) + 2) >>
1076
38.7k
                2;
1077
1078
38.7k
            u1_out_buf_cr[i4_i] =
1079
38.7k
                ((u1_filter_delay_buf_cr[i4_i]) + (u1_filter_delay_buf_cr[i4_i + 1] * 2) +
1080
38.7k
                 (u1_filter_delay_buf_cr[i4_i + 2]) + 2) >>
1081
38.7k
                2;
1082
38.7k
        }
1083
1084
        /* fill the segment with diagonal reconstructed output */
1085
24.3k
        for(i4_i = 1; i4_i <= u1_seg_ht; i4_i++)
1086
18.3k
        {
1087
18.3k
            memcpy(pu1_dst_cb, &u1_out_buf_cb[i4_height - i4_i], u1_seg_wd);
1088
18.3k
            pu1_dst_cb += i4_refarray_stride;
1089
1090
18.3k
            memcpy(pu1_dst_cr, &u1_out_buf_cr[i4_height - i4_i], u1_seg_wd);
1091
18.3k
            pu1_dst_cr += i4_refarray_stride;
1092
18.3k
        }
1093
6.00k
    }
1094
11.7k
    else if(i1_xd_index > 0 && i1_yd_index < 0)
1095
6.40k
    {
1096
        /* Quadrant 3 Processing load the pixel in the filter delay buffer  */
1097
6.40k
        memcpy(&u1_filter_delay_buf_cb[0], pu1_src_2_cb, (i4_width + 1));
1098
6.40k
        memcpy(&u1_filter_delay_buf_cr[0], pu1_src_2_cr, (i4_width + 1));
1099
1100
6.40k
        i4_tmp = (i4_y_off * i4_refarray_stride);
1101
6.40k
        pu1_src_1_cb -= i4_tmp;
1102
6.40k
        pu1_src_1_cr -= i4_tmp;
1103
27.3k
        for(i4_i = 1; i4_i <= i4_height; i4_i++)
1104
20.9k
        {
1105
20.9k
            u1_filter_delay_buf_cb[i4_width + i4_i] = *pu1_src_1_cb;
1106
20.9k
            pu1_src_1_cb += i4_refarray_stride;
1107
1108
20.9k
            u1_filter_delay_buf_cr[i4_width + i4_i] = *pu1_src_1_cr;
1109
20.9k
            pu1_src_1_cr += i4_refarray_stride;
1110
20.9k
        }
1111
1112
6.40k
        if(0 == i4_corner_pixel_available)
1113
5.80k
        {
1114
            /* interpolate the unavailable corner pixel */
1115
5.80k
            u1_filter_delay_buf_cb[i4_width] =
1116
5.80k
                (u1_filter_delay_buf_cb[i4_width - 1] + u1_filter_delay_buf_cb[i4_width + 1] + 1) >>
1117
5.80k
                1;
1118
1119
5.80k
            u1_filter_delay_buf_cr[i4_width] =
1120
5.80k
                (u1_filter_delay_buf_cr[i4_width - 1] + u1_filter_delay_buf_cr[i4_width + 1] + 1) >>
1121
5.80k
                1;
1122
5.80k
        }
1123
1124
46.5k
        for(i4_i = 0; i4_i < (i4_width + i4_height - 1); i4_i++)
1125
40.1k
        {
1126
            /* get the filtered output */
1127
40.1k
            u1_out_buf_cb[i4_i] =
1128
40.1k
                ((u1_filter_delay_buf_cb[i4_i]) + (u1_filter_delay_buf_cb[i4_i + 1] * 2) +
1129
40.1k
                 (u1_filter_delay_buf_cb[i4_i + 2]) + 2) >>
1130
40.1k
                2;
1131
1132
40.1k
            u1_out_buf_cr[i4_i] =
1133
40.1k
                ((u1_filter_delay_buf_cr[i4_i]) + (u1_filter_delay_buf_cr[i4_i + 1] * 2) +
1134
40.1k
                 (u1_filter_delay_buf_cr[i4_i + 2]) + 2) >>
1135
40.1k
                2;
1136
40.1k
        }
1137
1138
        /* fill the segment with diagonal reconstructed output */
1139
25.9k
        for(i4_i = 0; i4_i < u1_seg_ht; i4_i++)
1140
19.5k
        {
1141
19.5k
            memcpy(pu1_dst_cb, &u1_out_buf_cb[i4_y_off + i4_i], u1_seg_wd);
1142
19.5k
            pu1_dst_cb += i4_refarray_stride;
1143
19.5k
            memcpy(pu1_dst_cr, &u1_out_buf_cr[i4_y_off + i4_i], u1_seg_wd);
1144
19.5k
            pu1_dst_cr += i4_refarray_stride;
1145
19.5k
        }
1146
6.40k
    }
1147
5.31k
    else
1148
5.31k
    {
1149
        /* Quadrant 4 Processing load the pixel in the filter delay buffer  */
1150
5.31k
        i4_tmp = ((u1_seg_ht - 1) * i4_refarray_stride);
1151
5.31k
        pu1_src_1_cb += i4_tmp;
1152
5.31k
        pu1_src_1_cr += i4_tmp;
1153
1154
27.8k
        for(i4_i = 0; i4_i <= i4_height; i4_i++)
1155
22.5k
        {
1156
22.5k
            u1_filter_delay_buf_cb[i4_i] = *pu1_src_1_cb;
1157
22.5k
            pu1_src_1_cb -= i4_refarray_stride;
1158
1159
22.5k
            u1_filter_delay_buf_cr[i4_i] = *pu1_src_1_cr;
1160
22.5k
            pu1_src_1_cr -= i4_refarray_stride;
1161
22.5k
        }
1162
1163
5.31k
        pu1_src_2_cb -= i4_x_off;
1164
5.31k
        pu1_src_2_cr -= i4_x_off;
1165
5.31k
        memcpy(&u1_filter_delay_buf_cb[i4_i], pu1_src_2_cb, i4_width);
1166
5.31k
        memcpy(&u1_filter_delay_buf_cr[i4_i], pu1_src_2_cr, i4_width);
1167
1168
5.31k
        if(0 == i4_corner_pixel_available)
1169
4.88k
        {
1170
            /* interpolate the unavailable corner pixel */
1171
4.88k
            u1_filter_delay_buf_cb[i4_i - 1] =
1172
4.88k
                (u1_filter_delay_buf_cb[i4_i] + u1_filter_delay_buf_cb[i4_i - 2] + 1) >> 1;
1173
1174
4.88k
            u1_filter_delay_buf_cr[i4_i - 1] =
1175
4.88k
                (u1_filter_delay_buf_cr[i4_i] + u1_filter_delay_buf_cr[i4_i - 2] + 1) >> 1;
1176
4.88k
        }
1177
1178
38.4k
        for(i4_i = 0; i4_i < (i4_width + i4_height - 1); i4_i++)
1179
33.1k
        {
1180
            /* get the filtered output */
1181
33.1k
            u1_out_buf_cb[i4_i] =
1182
33.1k
                ((u1_filter_delay_buf_cb[i4_i]) + (u1_filter_delay_buf_cb[i4_i + 1] * 2) +
1183
33.1k
                 (u1_filter_delay_buf_cb[i4_i + 2]) + 2) >>
1184
33.1k
                2;
1185
1186
33.1k
            u1_out_buf_cr[i4_i] =
1187
33.1k
                ((u1_filter_delay_buf_cr[i4_i]) + (u1_filter_delay_buf_cr[i4_i + 1] * 2) +
1188
33.1k
                 (u1_filter_delay_buf_cr[i4_i + 2]) + 2) >>
1189
33.1k
                2;
1190
33.1k
        }
1191
1192
        /* fill the segment with diagonal reconstructed output */
1193
21.5k
        for(i4_i = 1; i4_i <= u1_seg_ht; i4_i++)
1194
16.2k
        {
1195
16.2k
            memcpy(pu1_dst_cb, &u1_out_buf_cb[(u1_seg_ht + i4_x_off) - i4_i], u1_seg_wd);
1196
16.2k
            pu1_dst_cb += i4_refarray_stride;
1197
16.2k
            memcpy(pu1_dst_cr, &u1_out_buf_cr[(u1_seg_ht + i4_x_off) - i4_i], u1_seg_wd);
1198
16.2k
            pu1_dst_cr += i4_refarray_stride;
1199
16.2k
        }
1200
5.31k
    }
1201
23.6k
}
1202
/*****************************************************************************/
1203
/*                                                                           */
1204
/*  Function Name : isvcd_diag_padding                                        */
1205
/*  Description   :  This function does the diagonal padding for intra       */
1206
/*                      upsampling for luma                                  */
1207
/*                                                                           */
1208
/*  Inputs        :                                                          */
1209
/*  Globals       : none                                                     */
1210
/*  Processing    : This function does the diagonal padding for intra        */
1211
/*                      upsampling for luma                                  */
1212
/*  Outputs       : none                                                     */
1213
/*  Returns       : none                                                     */
1214
/*  Issues        : none                                                     */
1215
/*  Revision History:                                                        */
1216
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1217
/*         06 09 2021   Vijay                creation                        */
1218
/*****************************************************************************/
1219
void isvcd_diag_padding(WORD32 i4_x, WORD32 i4_y, WORD8 i1_xd_index, WORD8 i1_yd_index,
1220
                        UWORD8 u1_seg_wd, UWORD8 u1_seg_ht, UWORD8 *pu1_refarray_1,
1221
                        UWORD8 *pu1_refarray_2, WORD32 i4_refarray_stride, WORD32 i4_mb_adjoin_x,
1222
                        WORD32 i4_mb_adjoin_y, WORD32 i4_corner_pixel_available)
1223
1224
18.7k
{
1225
18.7k
    WORD32 i4_idx_i;
1226
18.7k
    UWORD8 *pu1_src, *pu1_dst;
1227
1228
18.7k
    UNUSED(pu1_refarray_2);
1229
18.7k
    UNUSED(i4_mb_adjoin_x);
1230
18.7k
    UNUSED(i4_mb_adjoin_y);
1231
18.7k
    UNUSED(i4_corner_pixel_available);
1232
1233
18.7k
    pu1_dst = pu1_refarray_1 + i4_x + (i4_y * i4_refarray_stride);
1234
18.7k
    pu1_src = pu1_dst + i1_xd_index + (i1_yd_index * i4_refarray_stride);
1235
18.7k
    i1_xd_index = MIN(i1_xd_index, MAX_PIX_FILL_LUMA);
1236
18.7k
    u1_seg_wd = MIN(u1_seg_wd, MAX_PIX_FILL_LUMA);
1237
18.7k
    i1_yd_index = MIN(i1_yd_index, MAX_PIX_FILL_LUMA);
1238
18.7k
    u1_seg_ht = MIN(u1_seg_ht, MAX_PIX_FILL_LUMA);
1239
18.7k
    pu1_dst = pu1_src - i1_xd_index - (i1_yd_index * i4_refarray_stride);
1240
1241
78.9k
    for(i4_idx_i = 0; i4_idx_i < u1_seg_ht; i4_idx_i++)
1242
60.1k
    {
1243
60.1k
        memset(pu1_dst, *pu1_src, u1_seg_wd);
1244
60.1k
        pu1_dst += i4_refarray_stride;
1245
60.1k
    }
1246
18.7k
}
1247
1248
/*****************************************************************************/
1249
/*                                                                           */
1250
/*  Function Name : isvcd_diag_padding_chroma                                 */
1251
/*  Description   :  This function does the diagonal padding for intra       */
1252
/*                      upsampling for chroma                                */
1253
/*                                                                           */
1254
/*  Inputs        :                                                          */
1255
/*  Globals       : none                                                     */
1256
/*  Processing    : This function does the diagonal padding for intra        */
1257
/*                      upsampling for chroma                                */
1258
/*  Outputs       : none                                                     */
1259
/*  Returns       : none                                                     */
1260
/*  Issues        : none                                                     */
1261
/*  Revision History:                                                        */
1262
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1263
/*         06 09 2021   Vijay                creation                        */
1264
/*****************************************************************************/
1265
void isvcd_diag_padding_chroma(WORD32 i4_x, WORD32 i4_y, WORD8 i1_xd_index, WORD8 i1_yd_index,
1266
                               UWORD8 u1_seg_wd, UWORD8 u1_seg_ht, UWORD8 *pu1_refarray_1,
1267
                               UWORD8 *pu1_refarray_2, WORD32 i4_refarray_stride,
1268
                               WORD32 i4_mb_adjoin_x, WORD32 i4_mb_adjoin_y,
1269
                               WORD32 i4_corner_pixel_available)
1270
1271
18.7k
{
1272
18.7k
    WORD32 i4_idx_i;
1273
18.7k
    UWORD8 *pu1_src_cb, *pu1_dst_cb;
1274
18.7k
    UWORD8 *pu1_src_cr, *pu1_dst_cr;
1275
18.7k
    WORD32 i4_tmp;
1276
1277
18.7k
    UNUSED(i4_mb_adjoin_x);
1278
18.7k
    UNUSED(i4_mb_adjoin_y);
1279
18.7k
    UNUSED(i4_corner_pixel_available);
1280
1281
18.7k
    i4_tmp = i4_x + (i4_y * i4_refarray_stride);
1282
18.7k
    pu1_dst_cb = pu1_refarray_1 + i4_tmp;
1283
18.7k
    pu1_dst_cr = pu1_refarray_2 + i4_tmp;
1284
18.7k
    i4_tmp = i1_xd_index + (i1_yd_index * i4_refarray_stride);
1285
18.7k
    pu1_src_cb = pu1_dst_cb + i4_tmp;
1286
18.7k
    pu1_src_cr = pu1_dst_cr + i4_tmp;
1287
1288
18.7k
    i1_xd_index = MIN(i1_xd_index, MAX_PIX_FILL_LUMA);
1289
18.7k
    u1_seg_wd = MIN(u1_seg_wd, MAX_PIX_FILL_LUMA);
1290
18.7k
    i1_yd_index = MIN(i1_yd_index, MAX_PIX_FILL_LUMA);
1291
18.7k
    u1_seg_ht = MIN(u1_seg_ht, MAX_PIX_FILL_LUMA);
1292
1293
18.7k
    i4_tmp = (i1_xd_index + (i1_yd_index * i4_refarray_stride));
1294
18.7k
    pu1_dst_cb = pu1_src_cb - i4_tmp;
1295
18.7k
    pu1_dst_cr = pu1_src_cr - i4_tmp;
1296
1297
68.2k
    for(i4_idx_i = 0; i4_idx_i < u1_seg_ht; i4_idx_i++)
1298
49.4k
    {
1299
49.4k
        memset(pu1_dst_cb, *pu1_src_cb, u1_seg_wd);
1300
49.4k
        pu1_dst_cb += i4_refarray_stride;
1301
49.4k
        memset(pu1_dst_cr, *pu1_src_cr, u1_seg_wd);
1302
49.4k
        pu1_dst_cr += i4_refarray_stride;
1303
49.4k
    }
1304
18.7k
}
1305
/*****************************************************************************/
1306
/*                                                                           */
1307
/*  Function Name : isvcd_corner_samp_dyadic                                  */
1308
/*                                                                           */
1309
/*  Description   : This function fills the corner sample in the reference   */
1310
/*                    array with diagonally constructed samples              */
1311
/*  Inputs        : i4_x :current position in reference array X to be filled */
1312
/*                  i4_y :current position in reference array Y to be filled */
1313
/*                  i4_xd_index : diagonal index in horizontal direction     */
1314
/*                  i4_yd_index : diagonal index in vertical direction       */
1315
/*                  pu1_refarray_y : pointer to luma reference array         */
1316
/*                    pu1_refarray_cb : pointer to Cb reference array        */
1317
/*                    pu1_refarray_cr : pointer to Cr reference array        */
1318
/*  Globals       : none                                                     */
1319
/*  Processing    : Fills the sample which is unavailable with filtered      */
1320
/*                    diagonal samples                                       */
1321
/*  Outputs       : pixel filled                                             */
1322
/*  Returns       : none                                                     */
1323
/*                                                                           */
1324
/*  Issues        : none                                                     */
1325
/*                                                                           */
1326
/*  Revision History:                                                        */
1327
/*                                                                           */
1328
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1329
/*         06 09 2021   Vijay           creation                             */
1330
/*                                                                           */
1331
/*****************************************************************************/
1332
void isvcd_corner_samp_dyadic(WORD32 i4_x, WORD32 i4_y, WORD32 i4_xD, WORD32 i4_yD,
1333
                              UWORD8 *pu1_refarray_y, UWORD8 *pu1_refarray_cb,
1334
                              UWORD8 *pu1_refarray_cr)
1335
25.3k
{
1336
25.3k
    WORD32 i4_ref_xD, i4_ref_yD;
1337
25.3k
    WORD32 i4_c_ref_xD, i4_c_ref_yD;
1338
25.3k
    WORD32 i4_xc, i4_yc;
1339
25.3k
    WORD32 i4_c_xc, i4_c_yc;
1340
25.3k
    WORD32 i4_samp1, i4_samp2;
1341
25.3k
    UWORD8 *pu1_tmp_src, *pu1_tmp_dst;
1342
1343
25.3k
    i4_ref_xD = i4_x - i4_xD;
1344
25.3k
    i4_ref_yD = i4_y - i4_yD;
1345
25.3k
    i4_xc = i4_ref_xD + SIGN(i4_xD);
1346
25.3k
    i4_yc = i4_ref_yD + SIGN(i4_yD);
1347
1348
    /* Luma */
1349
25.3k
    pu1_tmp_src = pu1_refarray_y + (i4_yc * DYADIC_REF_W_Y);
1350
25.3k
    i4_samp1 = pu1_tmp_src[i4_ref_xD];
1351
25.3k
    pu1_tmp_src = pu1_refarray_y + (i4_ref_yD * DYADIC_REF_W_Y);
1352
25.3k
    i4_samp2 = pu1_tmp_src[i4_xc];
1353
25.3k
    pu1_tmp_dst = pu1_tmp_src;
1354
25.3k
    pu1_tmp_dst[i4_ref_xD] = (i4_samp1 + i4_samp2 + 1) >> 1;
1355
1356
    /* Chroma */
1357
25.3k
    i4_c_ref_xD = i4_ref_xD >> 1;
1358
25.3k
    i4_c_ref_yD = i4_ref_yD >> 1;
1359
25.3k
    i4_c_xc = i4_c_ref_xD + SIGN(i4_xD);
1360
25.3k
    i4_c_yc = i4_c_ref_yD + SIGN(i4_yD);
1361
1362
    /* Cb */
1363
25.3k
    pu1_tmp_src = pu1_refarray_cb + (i4_c_yc * DYADIC_REF_W_C);
1364
25.3k
    i4_samp1 = pu1_tmp_src[i4_c_ref_xD];
1365
25.3k
    pu1_tmp_src = pu1_refarray_cb + (i4_c_ref_yD * DYADIC_REF_W_C);
1366
25.3k
    i4_samp2 = pu1_tmp_src[i4_c_xc];
1367
25.3k
    pu1_tmp_dst = pu1_tmp_src;
1368
25.3k
    pu1_tmp_dst[i4_c_ref_xD] = (i4_samp1 + i4_samp2 + 1) >> 1;
1369
1370
    /* Cr */
1371
25.3k
    pu1_tmp_src = pu1_refarray_cr + (i4_c_yc * DYADIC_REF_W_C);
1372
25.3k
    i4_samp1 = pu1_tmp_src[i4_c_ref_xD];
1373
25.3k
    pu1_tmp_src = pu1_refarray_cr + (i4_c_ref_yD * DYADIC_REF_W_C);
1374
25.3k
    i4_samp2 = pu1_tmp_src[i4_c_xc];
1375
25.3k
    pu1_tmp_dst = pu1_tmp_src;
1376
25.3k
    pu1_tmp_dst[i4_c_ref_xD] = (i4_samp1 + i4_samp2 + 1) >> 1;
1377
25.3k
}
1378
1379
/*****************************************************************************/
1380
/*                                                                           */
1381
/*  Function Name : isvcd_fill_non_ava_pixel                                  */
1382
/*                                                                           */
1383
/*  Description   :  This function does the core pixel level processing      */
1384
/*                    while filling the non available pixel                  */
1385
/*                                                                           */
1386
/*  Inputs        : pv_intra_samp_ctxt : intra sampling context              */
1387
/*                  i4_refarray_wd : width of the reference array            */
1388
/*                  i4_refarray_ht : height of the reference array           */
1389
/*                  ps_mb_coord  : current mb coord structure                */
1390
/*                  i4_chroma_flag : chroam processing flag                  */
1391
/*  Globals       : none                                                     */
1392
/*  Processing    : based on the map buffer values the non available pixels  */
1393
/*                   are filled using border extension algorithm             */
1394
/*  Outputs       : none                                                     */
1395
/*  Returns       : none                                                     */
1396
/*                                                                           */
1397
/*  Issues        : none                                                     */
1398
/*                                                                           */
1399
/*  Revision History:                                                        */
1400
/*                                                                           */
1401
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1402
/*         06 09 2021   vijayakumar          creation                        */
1403
/*                                                                           */
1404
/*****************************************************************************/
1405
void isvcd_fill_non_avail_pixel(void *pv_map_ctxt, UWORD8 *pu1_refarray_1, UWORD8 *pu1_refarray_2,
1406
                                WORD32 i4_refarray_stride, mb_coord_t *ps_mb_coord,
1407
                                WORD32 i4_chroma_flag, UWORD8 u1_avail_map[4][4])
1408
82.6k
{
1409
    /* --------------------------------------------------------------------- */
1410
    /* Index Variables                                                         */
1411
    /* --------------------------------------------------------------------- */
1412
82.6k
    intra_samp_map_ctxt_t *ps_map_ctxt;
1413
82.6k
    ref_mb_map_t *ps_x_off_len;
1414
82.6k
    ref_mb_map_t *ps_y_off_len;
1415
82.6k
    WORD32 i4_x, i4_y;
1416
82.6k
    WORD32 i4_corner_pixel_available;
1417
1418
    /* --------------------------------------------------------------------- */
1419
    /* Local Pointer Declaration for Segment lookup                             */
1420
    /* --------------------------------------------------------------------- */
1421
82.6k
    seg_lookup_desc_t *ps_segments_x;
1422
82.6k
    seg_lookup_desc_t *ps_segments_y;
1423
82.6k
    seg_description_t *ps_seg_desc_x, *ps_seg_desc_y;
1424
82.6k
    seg_description_t *ps_seg_x_tmp, *ps_seg_y_tmp;
1425
82.6k
    UWORD8 u1_num_sgmts_x, u1_num_sgmts_y;
1426
1427
    /* --------------------------------------------------------------------- */
1428
    /* Temp Variables for Mapping context                                     */
1429
    /* --------------------------------------------------------------------- */
1430
82.6k
    WORD32 i4_x_offset;
1431
82.6k
    WORD32 i4_y_offset;
1432
82.6k
    WORD32 i4_refmb_wd;
1433
82.6k
    WORD32 i4_refmb_ht;
1434
82.6k
    WORD32 i4_mbaddr_x;
1435
82.6k
    WORD32 i4_mbaddr_y;
1436
82.6k
    WORD32 i4_xr_index, i4_yr_index;
1437
82.6k
    WORD32 i4_j, i4_i;
1438
82.6k
    WORD32 i4_cur_x;
1439
82.6k
    UWORD32 u4_lookup_4bit, u4_lookup_5bit, u4_4thbit;
1440
82.6k
    WORD32 i4_pad_size;
1441
82.6k
    WORD32 i4_x_min;
1442
82.6k
    WORD32 i4_y_min;
1443
82.6k
    WORD32 i4_x_start_pos, i4_y_start_pos;
1444
82.6k
    ref_min_max_map_t *ps_x_min_max;
1445
82.6k
    ref_min_max_map_t *ps_y_min_max;
1446
82.6k
    UWORD8 *pu1_ref_idx_x, *pu1_ref_idx_y;
1447
82.6k
    ftype_intra_samp_padding *pf_intra_samp_padding;
1448
82.6k
    ftype_intra_samp_padding **pf_intra_samp_lookup;
1449
1450
82.6k
    ps_map_ctxt = (intra_samp_map_ctxt_t *) pv_map_ctxt;
1451
82.6k
    ps_x_min_max = ps_map_ctxt->ps_x_min_max;
1452
82.6k
    ps_y_min_max = ps_map_ctxt->ps_y_min_max;
1453
82.6k
    ps_x_off_len = ps_map_ctxt->ps_x_offset_length;
1454
82.6k
    ps_y_off_len = ps_map_ctxt->ps_y_offset_length;
1455
82.6k
    i4_mbaddr_y = ps_mb_coord->u2_mb_y;
1456
82.6k
    i4_mbaddr_x = ps_mb_coord->u2_mb_x;
1457
82.6k
    i4_x_offset = ps_x_off_len[i4_mbaddr_x].i2_offset;
1458
82.6k
    i4_y_offset = ps_y_off_len[i4_mbaddr_y].i2_offset;
1459
82.6k
    i4_refmb_wd = (MB_WIDTH >> i4_chroma_flag) - 1;
1460
82.6k
    i4_refmb_ht = (MB_HEIGHT >> i4_chroma_flag) - 1;
1461
1462
82.6k
    if(0 == i4_chroma_flag)
1463
41.1k
    {
1464
41.1k
        pf_intra_samp_lookup = gpf_lookup_fxns_luma;
1465
41.1k
    }
1466
41.4k
    else
1467
41.4k
    {
1468
41.4k
        pf_intra_samp_lookup = gpf_lookup_fxns_chroma;
1469
41.4k
    }
1470
1471
    /* get the min and max positions */
1472
82.6k
    i4_x_min = ps_x_min_max[i4_mbaddr_x].i2_min_pos;
1473
82.6k
    i4_y_min = ps_y_min_max[i4_mbaddr_y].i2_min_pos;
1474
1475
    /* get the start position of the MB in reference layer */
1476
82.6k
    i4_pad_size = 2 >> i4_chroma_flag;
1477
82.6k
    i4_x_start_pos = (i4_x_min - i4_pad_size);
1478
82.6k
    i4_y_start_pos = (i4_y_min - i4_pad_size);
1479
82.6k
    i4_xr_index = (i4_x_start_pos + i4_x_offset) & i4_refmb_wd;
1480
82.6k
    i4_yr_index = (i4_y_start_pos + i4_y_offset) & i4_refmb_ht;
1481
1482
    /* Find the number of segments in x and y direction */
1483
82.6k
    ps_segments_x = (ps_map_ctxt->ps_seg_lookup_horz + i4_xr_index);
1484
82.6k
    ps_segments_y = (ps_map_ctxt->ps_seg_lookup_vert + i4_yr_index);
1485
82.6k
    u1_num_sgmts_x = ps_segments_x->u1_num_segments;
1486
82.6k
    u1_num_sgmts_y = ps_segments_y->u1_num_segments;
1487
82.6k
    ps_seg_desc_x = ps_segments_x->s_segments;
1488
82.6k
    ps_seg_desc_y = ps_segments_y->s_segments;
1489
82.6k
    pu1_ref_idx_x = ps_map_ctxt->pu1_refarray_x_idx;
1490
82.6k
    pu1_ref_idx_y = ps_map_ctxt->pu1_refarray_y_idx;
1491
82.6k
    i4_cur_x = pu1_ref_idx_x[i4_x_start_pos];
1492
82.6k
    u4_4thbit = ps_segments_x->u4_start_pos;
1493
1494
297k
    for(i4_j = 0; i4_j < u1_num_sgmts_y; i4_j++)
1495
215k
    {
1496
215k
        UWORD8 i4_idx_a, i4_idx_b;
1497
215k
        UWORD8 u1_seg_ht, u1_seg_wd;
1498
215k
        UWORD8 u1_mb_adjoin_x, u1_mb_adjoin_y;
1499
215k
        WORD8 i1_nearst_mb_bdry_x, i1_nearst_mb_bdry_y;
1500
215k
        UWORD32 u4_num_valid_segs;
1501
215k
        WORD32 i4_idx_a_plus_ny, i4_idx_b_plus_nx, i4_index;
1502
215k
        WORD8 i1_yd_index, i1_xd_index;
1503
1504
215k
        ps_seg_y_tmp = &ps_seg_desc_y[i4_j];
1505
215k
        i4_y = i4_y_start_pos + ps_seg_y_tmp->u1_seg_off;
1506
215k
        u1_seg_ht = ps_seg_y_tmp->u1_seg_dim;
1507
215k
        i1_yd_index = ps_seg_y_tmp->i1_dist_idx;
1508
215k
        i1_nearst_mb_bdry_y = ps_seg_y_tmp->i1_nearst_mb_bdry;
1509
215k
        u1_mb_adjoin_y = ps_seg_y_tmp->u1_mb_adjoin;
1510
215k
        i4_idx_a = pu1_ref_idx_y[i4_y];
1511
215k
        i4_idx_a_plus_ny = (i4_idx_a + i1_nearst_mb_bdry_y);
1512
1513
        /* Pack the availabilities of the next three horizontal MBs in 3bit
1514
           format and 4th bit indicating if the start position is greater than the mb_width/2 */
1515
215k
        u4_lookup_4bit = u4_4thbit | u1_avail_map[i4_idx_a][i4_cur_x + 2] << 2 |
1516
215k
                         u1_avail_map[i4_idx_a][i4_cur_x + 1] << 1 |
1517
215k
                         u1_avail_map[i4_idx_a][i4_cur_x];
1518
1519
215k
        u4_num_valid_segs = gu4_valid_segs_lookup[u4_lookup_4bit];
1520
215k
        i4_i = isvcd_left_most_bit_detect(u4_num_valid_segs);
1521
215k
        u4_num_valid_segs <<= (i4_i + 1);
1522
1523
617k
        for(; i4_i < u1_num_sgmts_x; i4_i++)
1524
402k
        {
1525
402k
            ps_seg_x_tmp = &ps_seg_desc_x[i4_i];
1526
402k
            i4_x = i4_x_start_pos + ps_seg_x_tmp->u1_seg_off;
1527
402k
            i4_idx_b = pu1_ref_idx_x[i4_x];
1528
402k
            u1_seg_wd = ps_seg_x_tmp->u1_seg_dim;
1529
402k
            i1_xd_index = ps_seg_x_tmp->i1_dist_idx;
1530
402k
            i1_nearst_mb_bdry_x = ps_seg_x_tmp->i1_nearst_mb_bdry;
1531
402k
            u1_mb_adjoin_x = ps_seg_x_tmp->u1_mb_adjoin;
1532
402k
            i4_idx_b_plus_nx = (i4_idx_b + i1_nearst_mb_bdry_x);
1533
1534
            /* Find the avalability of (x,y-Yd),(x-Xd,y),(x-Xd,y-Yd) and pack it to 3 bits */
1535
402k
            u4_lookup_5bit = u1_avail_map[i4_idx_a_plus_ny][i4_idx_b_plus_nx] << 2 |
1536
402k
                             u1_avail_map[i4_idx_a_plus_ny][i4_idx_b] << 1 |
1537
402k
                             u1_avail_map[i4_idx_a][i4_idx_b_plus_nx] | u1_mb_adjoin_x |
1538
402k
                             u1_mb_adjoin_y;
1539
1540
402k
            i4_corner_pixel_available = u1_avail_map[i4_idx_a_plus_ny][i4_idx_b_plus_nx];
1541
1542
            /* Function pointer table from lookup to get Left,Top,Bottom,Right,Diagonal padding */
1543
402k
            if(u4_lookup_5bit > 31)
1544
0
            {
1545
0
                u4_lookup_5bit = 0;
1546
0
            }
1547
402k
            pf_intra_samp_padding = pf_intra_samp_lookup[u4_lookup_5bit];
1548
1549
402k
            if(pf_intra_samp_padding != NULL)
1550
202k
            {
1551
202k
                pf_intra_samp_padding(i4_x, i4_y, i1_xd_index, i1_yd_index, u1_seg_wd, u1_seg_ht,
1552
202k
                                      pu1_refarray_1, pu1_refarray_2, i4_refarray_stride,
1553
202k
                                      u1_mb_adjoin_x, u1_mb_adjoin_y, i4_corner_pixel_available);
1554
202k
            }
1555
1556
            /* increment to the next unavailable segment */
1557
402k
            i4_index = isvcd_left_most_bit_detect(u4_num_valid_segs);
1558
402k
            u4_num_valid_segs <<= (i4_index + 1);
1559
402k
            i4_i += i4_index;
1560
1561
402k
        } /* end of loop over ref array width */
1562
1563
215k
    }     /* end of loop over ref array height */
1564
82.6k
    return;
1565
82.6k
}
1566
1567
/*****************************************************************************/
1568
/*                                                                           */
1569
/*  Function Name : isvcd_get_ref_layer_mbtype                                */
1570
/*                                                                           */
1571
/*  Description   : This function is used to find the mb type of the         */
1572
/*                    corresponding MB in the reference layer                */
1573
/*                                                                           */
1574
/*  Inputs        : pv_intra_samp_ctxt : intra samp context                  */
1575
/*                  pi1_ref_mb_modes : ref mb modes buffer pointer           */
1576
/*                  i4_ref_mode_stride : mb mode buffer stride               */
1577
/*                  i4_x_ref : reference location X                          */
1578
/*                  i4_y_ref : reference location Y                          */
1579
/*                  pi4_mb_type : pointer to store the mb type               */
1580
/*                  i4_chroma_flag : chroma flag                             */
1581
/*  Globals       : none                                                     */
1582
/*  Processing    : it derives the bit corresponding to reference MB and     */
1583
/*                  stores the mbtype as INTRA if the bit is set             */
1584
/*  Outputs       : none                                                     */
1585
/*  Returns       : none                                                     */
1586
/*                                                                           */
1587
/*  Issues        : none                                                     */
1588
/*                                                                           */
1589
/*  Revision History:                                                        */
1590
/*                                                                           */
1591
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1592
/*         06 09 2021   vijayakumar          creation                        */
1593
/*                                                                           */
1594
/*****************************************************************************/
1595
WORD8 isvcd_get_ref_layer_mbtype(WORD8 *pi1_ref_mb_modes, WORD32 *pi4_mb_type,
1596
                                 WORD8 i1_curr_slice_id, WORD8 i1_cons_intr_samp_flag)
1597
814k
{
1598
814k
    WORD8 i1_intra_slice_id;
1599
814k
    inter_lyr_mb_prms_t *ps_inter_lyr_mb_prms;
1600
814k
    WORD8 i1_mb_mode;
1601
1602
814k
    ps_inter_lyr_mb_prms = (inter_lyr_mb_prms_t *) pi1_ref_mb_modes;
1603
814k
    i1_mb_mode = ps_inter_lyr_mb_prms->i1_mb_mode;
1604
1605
814k
    if(i1_mb_mode <= SVC_INTER_MB)
1606
655k
    {
1607
        /* INTER */
1608
655k
        *pi4_mb_type = SVC_INTER_MB;
1609
655k
        i1_intra_slice_id = -1;
1610
655k
    }
1611
158k
    else
1612
158k
    {
1613
        /* INTRA */
1614
158k
        *pi4_mb_type = SVC_INTRA_MB;
1615
158k
        i1_intra_slice_id = ps_inter_lyr_mb_prms->i1_slice_id;
1616
1617
158k
        if(1 == i1_cons_intr_samp_flag)
1618
17.0k
        {
1619
            /* check for different slice idc */
1620
17.0k
            if(ps_inter_lyr_mb_prms->i1_slice_id != i1_curr_slice_id)
1621
4.88k
            {
1622
                /* store the mode as INTER (not available for upsampling) */
1623
4.88k
                *pi4_mb_type = SVC_INTER_MB;
1624
4.88k
            }
1625
17.0k
        }
1626
158k
    }
1627
1628
    /* if contarained intra flag is 1 then check for same mb mode */
1629
814k
    return (i1_intra_slice_id);
1630
814k
}
1631
/*****************************************************************************/
1632
/*                                                                           */
1633
/*  Function Name : isvcd_reflayer_construction                               */
1634
/*                                                                           */
1635
/*  Description   :  This function constructs the reference array buffer     */
1636
/*                    used for intra resampling of a component in an MB      */
1637
/*                                                                           */
1638
/*  Inputs        : pv_intra_samp_ctxt: intra sampling context               */
1639
/*                  pu1_inp : input (reference layer data)                   */
1640
/*                  i4_inp_stride : input buffer stride                      */
1641
/*                  ps_ref_mb_mode_map : ref layer mb mode buffer desc       */
1642
/*                  pi4_refarr_wd : pointer to store the reference array WD  */
1643
/*                  pi4_refarr_ht : pointer to store the reference array HT  */
1644
/*                  pi4_x_offset : pointer to store the reference X offset   */
1645
/*                  pi4_y_offset : pointer to store the reference Y offset   */
1646
/*                  ps_coord     : mb co-ordinate structure                  */
1647
/*                  i4_chroma_flag : chroma processing flag                  */
1648
/*  Globals       : none                                                     */
1649
/*  Processing    : it fills the reference layer data if they are falling in */
1650
/*                  INTRA MB region. If all the pixels are not filled  it    */
1651
/*                  calls the border extension algorithm to fill them        */
1652
/*  Outputs       : none                                                     */
1653
/*  Returns       : none                                                     */
1654
/*                                                                           */
1655
/*  Issues        : none                                                     */
1656
/*                                                                           */
1657
/*  Revision History:                                                        */
1658
/*                                                                           */
1659
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1660
/*         06 09 2021   vijayakumar          creation                        */
1661
/*****************************************************************************/
1662
WORD32 isvcd_reflayer_construction(void *pv_intra_samp_ctxt, UWORD8 *pu1_inp_1, UWORD8 *pu1_inp_2,
1663
                                   WORD32 i4_inp_stride, WORD32 i4_refarray_stride,
1664
                                   mem_element_t *ps_ref_mb_mode_map, mb_coord_t *ps_coord,
1665
                                   WORD32 i4_chroma_flag)
1666
82.9k
{
1667
82.9k
    WORD32 i4_x, i4_y;
1668
1669
    /* --------------------------------------------------------------------- */
1670
    /* Context and reference layer realted varaibles                         */
1671
    /* --------------------------------------------------------------------- */
1672
82.9k
    intra_sampling_ctxt_t *ps_ctxt;
1673
82.9k
    intra_samp_map_ctxt_t *ps_map_ctxt;
1674
82.9k
    intra_samp_lyr_ctxt *ps_lyr_ctxt;
1675
82.9k
    WORD8 *pi1_ref_mb_modes, *pi1_ref_mb_modes_bkp_1;
1676
82.9k
    WORD32 i4_ref_mode_stride;
1677
82.9k
    WORD32 i4_element_size;
1678
82.9k
    ref_mb_map_t *ps_x_off_len;
1679
82.9k
    ref_mb_map_t *ps_y_off_len;
1680
82.9k
    WORD32 i4_mbaddr_y;
1681
82.9k
    WORD32 i4_mbaddr_x;
1682
82.9k
    WORD32 i4_mb_ht, i4_mb_wd;
1683
82.9k
    UWORD8 u1_map_buf[4][4] = {0}; /*!< 4x4 mb grid buffer to store the mb availablity */
1684
    /* --------------------------------------------------------------------- */
1685
    /* Temp Variables for Mapping context                                     */
1686
    /* --------------------------------------------------------------------- */
1687
82.9k
    WORD32 i4_ref_wd;
1688
82.9k
    WORD32 i4_ref_ht;
1689
82.9k
    WORD32 i4_x_offset;
1690
82.9k
    WORD32 i4_y_offset;
1691
82.9k
    WORD32 i4_refarray_wd;
1692
82.9k
    WORD32 i4_refarray_ht;
1693
82.9k
    WORD32 i4_mb_type;
1694
82.9k
    WORD8 i1_cons_intr_samp_flag;
1695
82.9k
    WORD8 i1_slice_id = 0;
1696
82.9k
    WORD32 i4_mb_wd_sft, i4_mb_ht_sft;
1697
1698
    /* --------------------------------------------------------------------- */
1699
    /* Local Pointer Declaration for arrays in Mapping context                 */
1700
    /* --------------------------------------------------------------------- */
1701
1702
82.9k
    WORD32 i4_unfill_check;
1703
82.9k
    UWORD8 *pu1_refarray_1, *pu1_refarray_2;
1704
1705
82.9k
    UNUSED(pu1_inp_2);
1706
1707
82.9k
    ps_ctxt = (intra_sampling_ctxt_t *) pv_intra_samp_ctxt;
1708
82.9k
    ps_lyr_ctxt = &ps_ctxt->as_res_lyrs[ps_ctxt->i4_res_lyr_id];
1709
82.9k
    pi1_ref_mb_modes = (WORD8 *) ps_ref_mb_mode_map->pv_buffer;
1710
82.9k
    i4_ref_mode_stride = ps_ref_mb_mode_map->i4_num_element_stride;
1711
82.9k
    i4_element_size = ps_ref_mb_mode_map->i4_element_size;
1712
1713
    /* get the condtrained intra sampling flag */
1714
82.9k
    i1_cons_intr_samp_flag = ps_lyr_ctxt->i1_constrained_intra_rsmpl_flag;
1715
1716
82.9k
    if(NULL == pi1_ref_mb_modes)
1717
0
    {
1718
0
        return NOT_OK;
1719
0
    }
1720
1721
    /* --------------------------------------------------------------------- */
1722
    /* Based on Chroma and Luma, extracting the context information struct     */
1723
    /* --------------------------------------------------------------------- */
1724
82.9k
    if(1 == i4_chroma_flag)
1725
41.4k
        ps_map_ctxt = &ps_lyr_ctxt->s_chroma_map_ctxt;
1726
41.4k
    else
1727
41.4k
        ps_map_ctxt = &ps_lyr_ctxt->s_luma_map_ctxt;
1728
1729
82.9k
    ps_x_off_len = ps_map_ctxt->ps_x_offset_length;
1730
82.9k
    ps_y_off_len = ps_map_ctxt->ps_y_offset_length;
1731
1732
    /* --------------------------------------------------------------------- */
1733
    /* Deriving the parameters required for further processing                 */
1734
    /* --------------------------------------------------------------------- */
1735
82.9k
    {
1736
82.9k
        WORD32 i4_base_width = ps_lyr_ctxt->i4_ref_width;
1737
82.9k
        WORD32 i4_base_height = ps_lyr_ctxt->i4_ref_height;
1738
1739
82.9k
        i4_ref_wd = i4_base_width >> i4_chroma_flag;
1740
82.9k
        i4_ref_ht = i4_base_height >> i4_chroma_flag;
1741
82.9k
        i4_mb_wd_sft = (MB_WIDTH_SHIFT - i4_chroma_flag);
1742
82.9k
        i4_mb_ht_sft = (MB_HEIGHT_SHIFT - i4_chroma_flag);
1743
82.9k
    }
1744
1745
    /* --------------------------------------------------------------------- */
1746
    /* Local variables based on the MB address                                 */
1747
    /* --------------------------------------------------------------------- */
1748
82.9k
    i4_mbaddr_y = ps_coord->u2_mb_y;
1749
82.9k
    i4_mbaddr_x = ps_coord->u2_mb_x;
1750
82.9k
    i4_x_offset = ps_x_off_len[i4_mbaddr_x].i2_offset;
1751
82.9k
    i4_y_offset = ps_y_off_len[i4_mbaddr_y].i2_offset;
1752
82.9k
    i4_refarray_wd = ps_x_off_len[i4_mbaddr_x].i2_length;
1753
82.9k
    i4_refarray_ht = ps_y_off_len[i4_mbaddr_y].i2_length;
1754
82.9k
    i4_mb_wd = (MB_WIDTH >> i4_chroma_flag);
1755
82.9k
    i4_mb_ht = (MB_HEIGHT >> i4_chroma_flag);
1756
1757
    /* --------------------------------------------------------------------- */
1758
    /* Derivation of ref slice MB idc                                         */
1759
    /* --------------------------------------------------------------------- */
1760
82.9k
    if(1 == i1_cons_intr_samp_flag)
1761
31.6k
    {
1762
31.6k
        WORD32 i4_x_min, i4_x_max;
1763
31.6k
        WORD32 i4_y_min, i4_y_max;
1764
31.6k
        ref_min_max_map_t *ps_x_min_max;
1765
31.6k
        ref_min_max_map_t *ps_y_min_max;
1766
1767
31.6k
        ps_x_min_max = ps_map_ctxt->ps_x_min_max;
1768
31.6k
        ps_y_min_max = ps_map_ctxt->ps_y_min_max;
1769
1770
        /* get the min and max positions */
1771
31.6k
        i4_x_min = ps_x_min_max[i4_mbaddr_x].i2_min_pos;
1772
31.6k
        i4_x_max = ps_x_min_max[i4_mbaddr_x].i2_max_pos;
1773
31.6k
        i4_y_min = ps_y_min_max[i4_mbaddr_y].i2_min_pos;
1774
31.6k
        i4_y_max = ps_y_min_max[i4_mbaddr_y].i2_max_pos;
1775
1776
        /* default initialization */
1777
31.6k
        i4_mb_type = SVC_INTER_MB;
1778
1779
31.6k
        {
1780
31.6k
            WORD32 i4_x_ref;
1781
31.6k
            WORD32 i4_y_ref;
1782
31.6k
            WORD32 i4_mb_x, i4_mb_y;
1783
1784
31.6k
            i4_y_ref = (i4_y_min + 1) + i4_y_offset;
1785
31.6k
            i4_x_ref = (i4_x_min + 1) + i4_x_offset;
1786
31.6k
            i4_mb_x = (i4_x_ref >> i4_mb_wd_sft);
1787
31.6k
            i4_mb_y = (i4_y_ref >> i4_mb_ht_sft);
1788
31.6k
            pi1_ref_mb_modes = (WORD8 *) ps_ref_mb_mode_map->pv_buffer;
1789
1790
            /* get the location of the byte which has the current mb mode */
1791
31.6k
            pi1_ref_mb_modes += (i4_mb_y * i4_ref_mode_stride * i4_element_size);
1792
31.6k
            pi1_ref_mb_modes += (i4_mb_x * i4_element_size);
1793
31.6k
        }
1794
1795
66.4k
        for(i4_y = (i4_y_min + 1); i4_y <= (i4_y_max - 1);)
1796
41.9k
        {
1797
41.9k
            WORD32 i4_x_ref;
1798
41.9k
            WORD32 i4_y_ref;
1799
41.9k
            WORD32 i4_distleftX, i4_rangeX;
1800
41.9k
            WORD32 i4_disttopY, i4_rangeY;
1801
1802
41.9k
            i4_y_ref = (i4_y + i4_y_offset);
1803
41.9k
            i4_disttopY = (i4_y_ref) & (i4_mb_ht - 1);
1804
41.9k
            i4_rangeY = (i4_mb_ht - i4_disttopY);
1805
1806
41.9k
            pi1_ref_mb_modes_bkp_1 = pi1_ref_mb_modes;
1807
1808
90.0k
            for(i4_x = (i4_x_min + 1); i4_x <= (i4_x_max - 1);)
1809
55.2k
            {
1810
55.2k
                i4_x_ref = (i4_x + i4_x_offset);
1811
55.2k
                i4_distleftX = (i4_x_ref) & (i4_mb_wd - 1);
1812
55.2k
                i4_rangeX = (i4_mb_wd - i4_distleftX);
1813
1814
                /* get the referecne layer mb type */
1815
55.2k
                i1_slice_id =
1816
55.2k
                    isvcd_get_ref_layer_mbtype(pi1_ref_mb_modes_bkp_1, &i4_mb_type, i1_slice_id, 0);
1817
55.2k
                if(SVC_INTRA_MB == i4_mb_type)
1818
7.13k
                {
1819
                    /* if an Intra MB is returned then break the loop */
1820
7.13k
                    break;
1821
7.13k
                }
1822
1823
48.0k
                i4_x += i4_rangeX;
1824
48.0k
                pi1_ref_mb_modes_bkp_1 += i4_element_size;
1825
48.0k
            } /* end of loop in horizontal direction */
1826
1827
41.9k
            if(SVC_INTRA_MB == i4_mb_type)
1828
7.13k
            {
1829
                /* if an Intra MB is returned then break the loop */
1830
7.13k
                break;
1831
7.13k
            }
1832
1833
34.8k
            i4_y += i4_rangeY;
1834
34.8k
            pi1_ref_mb_modes += (i4_ref_mode_stride * i4_element_size);
1835
1836
34.8k
        } /* end of loop in vertical direction */
1837
31.6k
    }
1838
51.2k
    else
1839
51.2k
    {
1840
        /* set to non valid value */
1841
51.2k
        i1_slice_id = -1;
1842
51.2k
    }
1843
1844
82.9k
    i4_unfill_check = 0;
1845
1846
    /* --------------------------------------------------------------------- */
1847
    /* Copying the data from recon buffer to refSample Array.                */
1848
    /* NOTE: The copying of the data from recon buffer to refSample Array    */
1849
    /*       can be optimized by bring in data at N-MB level,thus taking     */
1850
    /*       advantage of the overlapping data which now gets copied every MB*/
1851
    /* --------------------------------------------------------------------- */
1852
82.9k
    {
1853
82.9k
        WORD32 i4_x_ref_start, i4_x_ref_end;
1854
82.9k
        WORD32 i4_y_ref_start, i4_y_ref_end;
1855
82.9k
        WORD32 i4_rangeW, i4_rangeH;
1856
82.9k
        WORD32 i4_offset;
1857
82.9k
        UWORD8 *pu1_src, *pu1_dst;
1858
82.9k
        UWORD8 *pu1_dst1, *pu1_dst2;
1859
1860
        /* Copy (refW x refH) dimension into reference sample array */
1861
82.9k
        i4_x_ref_start = MAX(0, MIN((i4_ref_wd - 1), i4_x_offset));
1862
82.9k
        i4_x_ref_end = MAX(0, MIN((i4_ref_wd - 1), (i4_refarray_wd - 1) + i4_x_offset));
1863
82.9k
        i4_y_ref_start = MAX(0, MIN((i4_ref_ht - 1), i4_y_offset));
1864
82.9k
        i4_y_ref_end = MAX(0, MIN((i4_ref_ht - 1), (i4_refarray_ht - 1) + i4_y_offset));
1865
1866
        /* find the actual data to be copied */
1867
82.9k
        i4_rangeW = (i4_x_ref_end - i4_x_ref_start + 1);
1868
82.9k
        i4_rangeH = (i4_y_ref_end - i4_y_ref_start + 1);
1869
1870
        /* get the reconbuffer pointer and ref sample array pointer */
1871
82.9k
        i4_offset =
1872
82.9k
            (i4_x_ref_start - i4_x_offset) + ((i4_y_ref_start - i4_y_offset) * i4_refarray_stride);
1873
1874
82.9k
        if(0 == i4_chroma_flag)
1875
41.4k
        {
1876
41.4k
            pu1_refarray_1 = ps_ctxt->pu1_refarray_buffer;
1877
41.4k
            pu1_refarray_2 = NULL;
1878
41.4k
            pu1_src = pu1_inp_1;
1879
41.4k
            pu1_dst = pu1_refarray_1 + i4_offset;
1880
1881
            /* Copy luma data into refsample array */
1882
41.4k
            isvcd_copy_data(pu1_src, i4_inp_stride, pu1_dst, i4_refarray_stride, i4_rangeW,
1883
41.4k
                            i4_rangeH);
1884
41.4k
        }
1885
41.4k
        else
1886
41.4k
        {
1887
41.4k
            pu1_refarray_1 = ps_ctxt->pu1_refarray_buffer;
1888
41.4k
            pu1_refarray_2 = ps_ctxt->pu1_refarray_cb;
1889
41.4k
            pu1_src = pu1_inp_1;
1890
41.4k
            pu1_dst1 = pu1_refarray_1 + i4_offset;
1891
41.4k
            pu1_dst2 = pu1_refarray_2 + i4_offset;
1892
41.4k
            isvcd_copy_data_semiplanr(pu1_src, i4_inp_stride, pu1_dst1, pu1_dst2,
1893
41.4k
                                      i4_refarray_stride, i4_rangeW, i4_rangeH);
1894
41.4k
        }
1895
82.9k
    }
1896
1897
    /* --------------------------------------------------------------------- */
1898
    /* Loop to fill ref sample array and corresponding map for interpolation */
1899
    /* --------------------------------------------------------------------- */
1900
82.9k
    {
1901
82.9k
        WORD32 i4_i, i4_j;
1902
82.9k
        UWORD8 *pu1_ref_idx_x, *pu1_ref_idx_y;
1903
82.9k
        WORD32 i4_x_ref;
1904
82.9k
        WORD32 i4_y_ref;
1905
82.9k
        WORD32 i4_mb_x, i4_mb_y;
1906
1907
82.9k
        i4_y_ref = i4_y_offset;
1908
82.9k
        i4_x_ref = i4_x_offset;
1909
82.9k
        i4_mb_x = (i4_x_ref >> i4_mb_wd_sft);
1910
82.9k
        i4_mb_y = (i4_y_ref >> i4_mb_ht_sft);
1911
82.9k
        pi1_ref_mb_modes = (WORD8 *) ps_ref_mb_mode_map->pv_buffer;
1912
1913
        /* get the location of the byte which has the current mb mode */
1914
82.9k
        pi1_ref_mb_modes += (i4_mb_y * i4_ref_mode_stride * i4_element_size);
1915
82.9k
        pi1_ref_mb_modes += (i4_mb_x * i4_element_size);
1916
82.9k
        pu1_ref_idx_x = ps_map_ctxt->pu1_refarray_x_idx;
1917
82.9k
        pu1_ref_idx_y = ps_map_ctxt->pu1_refarray_y_idx;
1918
1919
82.9k
        i4_j = 0;
1920
331k
        for(i4_y = 0; i4_y < i4_refarray_ht;)
1921
248k
        {
1922
248k
            WORD32 i4_x_ref;
1923
248k
            WORD32 i4_y_ref;
1924
248k
            WORD32 i4_distleftX, i4_rangeX;
1925
248k
            WORD32 i4_disttopY, i4_rangeY;
1926
1927
248k
            i4_y_ref = i4_y + i4_y_offset;
1928
248k
            i4_disttopY = (i4_y_ref) & (i4_mb_ht - 1);
1929
248k
            i4_rangeY = (i4_mb_ht - i4_disttopY);
1930
1931
            /* find the y-index lookup */
1932
248k
            memset(pu1_ref_idx_y, i4_j, i4_rangeY);
1933
248k
            pu1_ref_idx_y += i4_rangeY;
1934
1935
248k
            i4_i = 0;
1936
248k
            pi1_ref_mb_modes_bkp_1 = pi1_ref_mb_modes;
1937
1.00M
            for(i4_x = 0; i4_x < i4_refarray_wd;)
1938
758k
            {
1939
758k
                i4_x_ref = i4_x + i4_x_offset;
1940
758k
                i4_distleftX = (i4_x_ref) & (i4_mb_wd - 1);
1941
758k
                i4_rangeX = (i4_mb_wd - i4_distleftX);
1942
1943
758k
                if(0 == i4_j)
1944
248k
                {
1945
                    /* find the x-index lookup */
1946
248k
                    memset(pu1_ref_idx_x, i4_i, i4_rangeX);
1947
248k
                    pu1_ref_idx_x += i4_rangeX;
1948
248k
                }
1949
1950
                /* get the referecne layer mb type */
1951
758k
                isvcd_get_ref_layer_mbtype(pi1_ref_mb_modes_bkp_1, &i4_mb_type, i1_slice_id,
1952
758k
                                           i1_cons_intr_samp_flag);
1953
1954
758k
                if(SVC_INTRA_MB == i4_mb_type)
1955
146k
                {
1956
146k
                    u1_map_buf[i4_j][i4_i] = 1;
1957
146k
                }
1958
612k
                else
1959
612k
                {
1960
612k
                    i4_unfill_check = 1;
1961
612k
                }
1962
1963
758k
                i4_x = i4_x + i4_rangeX;
1964
758k
                i4_i++;
1965
758k
                pi1_ref_mb_modes_bkp_1 += i4_element_size;
1966
1967
758k
            } /* end of loop over ref array width */
1968
1969
248k
            i4_j++;
1970
248k
            i4_y = i4_y + i4_rangeY;
1971
248k
            pi1_ref_mb_modes += (i4_ref_mode_stride * i4_element_size);
1972
248k
        } /* end of loop over ref array height */
1973
82.9k
    }
1974
1975
    /* --------------------------------------------------------------------- */
1976
    /* Calling boundary extension algorithm to fill unfilled pixels             */
1977
    /* --------------------------------------------------------------------- */
1978
82.9k
    if(i4_unfill_check == 1)
1979
82.6k
    {
1980
82.6k
        isvcd_fill_non_avail_pixel(ps_map_ctxt, pu1_refarray_1, pu1_refarray_2, i4_refarray_stride,
1981
82.6k
                                   ps_coord, i4_chroma_flag, u1_map_buf);
1982
82.6k
    }
1983
82.9k
    return OK;
1984
82.9k
}
1985
1986
/*****************************************************************************/
1987
/*                                                                           */
1988
/*  Function Name : isvcd_reflayer_construction_dyadic                        */
1989
/*                                                                           */
1990
/*  Description   :  This function constructs the reference array buffer     */
1991
/*                   for dyadic cases used for intra resampling of a         */
1992
/*                     component in an MB                                    */
1993
/*                                                                           */
1994
/*  Inputs        : pv_intra_samp_ctxt : intra sampling context              */
1995
/*                  ps_ref_mb_mode_map : ref layer mb mode buffer desc       */
1996
/*                  pu1_inp_luma : luma input (reference layer data)         */
1997
/*                    pu1_inp_chroma : chroma input (reference layer data)   */
1998
/*                  i4_inp_luma_stride : luma input buffer stride            */
1999
/*                    i4_inp_chroma_stride : chroma input buffer stride      */
2000
/*                  i4_top : indicates whether the core 8x8 reference block  */
2001
/*                             is one of 0 and 1 or one of 2 and 3           */
2002
/*                    i4_left : indicates whether the core 8x8 ref block     */
2003
/*                             is one of 0 and 2 or one of 1 and 3           */
2004
/*                    ps_ref_mb_coord : coordinates of the reference MB      */
2005
/*  Globals       : none                                                     */
2006
/*  Processing    : it fills the reference layer data if they are falling in */
2007
/*                  INTRA MB region. If all the pixels are not filled  it    */
2008
/*                  calls the border extension algorithm to fill them        */
2009
/*  Outputs       : none                                                     */
2010
/*  Returns       : none                                                     */
2011
/*                                                                           */
2012
/*  Issues        : none                                                     */
2013
/*                                                                           */
2014
/*  Revision History:                                                        */
2015
/*                                                                           */
2016
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
2017
/*         06 09 2021   Vijay           creation                             */
2018
/*                                                                           */
2019
/*****************************************************************************/
2020
WORD32 isvcd_reflayer_construction_dyadic(void *pv_intra_samp_ctxt,
2021
                                          mem_element_t *ps_ref_mb_mode_map, UWORD8 *pu1_inp_luma,
2022
                                          UWORD8 *pu1_inp_chroma, WORD32 i4_inp_luma_stride,
2023
                                          WORD32 i4_inp_chroma_stride, WORD32 i4_top,
2024
                                          WORD32 i4_left, UWORD16 u2_mb_x, UWORD16 u2_mb_y)
2025
56.2k
{
2026
    /* Index variables */
2027
56.2k
    WORD32 i4_x, i4_y;
2028
56.2k
    WORD32 i4_x0, i4_y0;
2029
56.2k
    WORD32 i4_xc0, i4_yc0;
2030
56.2k
    WORD32 i4_ref_xD, i4_ref_yD;
2031
56.2k
    WORD32 i4_c_ref_xD, i4_c_ref_yD;
2032
2033
    /* --------------------------------------------------------------------- */
2034
    /* Context and reference layer related variables                         */
2035
    /* --------------------------------------------------------------------- */
2036
56.2k
    intra_sampling_ctxt_t *ps_ctxt;
2037
56.2k
    intra_samp_lyr_ctxt *ps_lyr_ctxt;
2038
56.2k
    WORD8 *pi1_ref_mb_modes;
2039
56.2k
    WORD32 i4_ref_mode_stride;
2040
56.2k
    WORD32 i4_element_size;
2041
56.2k
    WORD32 i4_mbaddr_y;
2042
56.2k
    WORD32 i4_mbaddr_x;
2043
2044
    /* --------------------------------------------------------------------- */
2045
    /* Temp Variables for Mapping context                                     */
2046
    /* --------------------------------------------------------------------- */
2047
56.2k
    WORD32 i4_refarray_wd_luma, i4_refarray_wd_chroma;
2048
56.2k
    WORD32 i4_refarray_ht_luma, i4_refarray_ht_chroma;
2049
56.2k
    WORD32 i4_avlblty;
2050
56.2k
    WORD8 i1_cons_intr_samp_flag;
2051
56.2k
    WORD8 i1_slice_id;
2052
56.2k
    WORD8 i1_corner_samp_avlbl_flag;
2053
56.2k
    UWORD8 u1_ny_avlblty;
2054
2055
    /* --------------------------------------------------------------------- */
2056
    /* Local Pointer Declaration for arrays in Mapping context                 */
2057
    /* --------------------------------------------------------------------- */
2058
56.2k
    UWORD8 *pu1_refarray_luma;
2059
56.2k
    UWORD8 *pu1_refarray_cb, *pu1_refarray_cr;
2060
2061
    /* --------------------------------------------------------------------- */
2062
    /* Derivation of local variables                                         */
2063
    /* --------------------------------------------------------------------- */
2064
56.2k
    ps_ctxt = (intra_sampling_ctxt_t *) pv_intra_samp_ctxt;
2065
56.2k
    ps_lyr_ctxt = &ps_ctxt->as_res_lyrs[ps_ctxt->i4_res_lyr_id];
2066
56.2k
    pi1_ref_mb_modes = (WORD8 *) ps_ref_mb_mode_map->pv_buffer;
2067
56.2k
    i4_ref_mode_stride = ps_ref_mb_mode_map->i4_num_element_stride;
2068
56.2k
    i4_element_size = ps_ref_mb_mode_map->i4_element_size;
2069
2070
    /* --------------------------------------------------------------------- */
2071
    /* get the constrained intra resampling flag                             */
2072
    /* --------------------------------------------------------------------- */
2073
56.2k
    i1_cons_intr_samp_flag = ps_lyr_ctxt->i1_constrained_intra_rsmpl_flag;
2074
56.2k
    if(NULL == pi1_ref_mb_modes)
2075
0
    {
2076
0
        return NOT_OK;
2077
0
    }
2078
2079
56.2k
    pu1_refarray_luma = ps_ctxt->pu1_refarray_buffer;
2080
56.2k
    pu1_refarray_cb = ps_ctxt->pu1_refarray_cb;
2081
56.2k
    pu1_refarray_cr = ps_ctxt->pu1_refarray_cr;
2082
2083
    /* --------------------------------------------------------------------- */
2084
    /* Get the coordinates of the reference layer MB                         */
2085
    /* --------------------------------------------------------------------- */
2086
56.2k
    i4_mbaddr_x = u2_mb_x;
2087
56.2k
    i4_mbaddr_y = u2_mb_y;
2088
2089
    /* --------------------------------------------------------------------- */
2090
    /* Getting the size of the valid area of ref array to be brought in         */
2091
    /* --------------------------------------------------------------------- */
2092
56.2k
    i4_refarray_wd_luma = 20;
2093
56.2k
    i4_refarray_ht_luma = 20;
2094
56.2k
    i4_refarray_wd_chroma = i4_refarray_wd_luma >> 1;
2095
56.2k
    i4_refarray_ht_chroma = i4_refarray_ht_luma >> 1;
2096
2097
    /* --------------------------------------------------------------------- */
2098
    /* Derivation of ref slice MB idc                                         */
2099
    /* --------------------------------------------------------------------- */
2100
56.2k
    if(1 == i1_cons_intr_samp_flag)
2101
30.0k
    {
2102
30.0k
        inter_lyr_mb_prms_t *ps_inter_lyr_mb_prms;
2103
30.0k
        WORD8 *pi1_ref_mb_mode_tmp;
2104
30.0k
        WORD8 i1_mb_mode;
2105
2106
        /* get the location of the byte which has the current mb mode */
2107
30.0k
        pi1_ref_mb_mode_tmp = pi1_ref_mb_modes;
2108
30.0k
        pi1_ref_mb_mode_tmp += (i4_mbaddr_y * i4_ref_mode_stride * i4_element_size);
2109
30.0k
        pi1_ref_mb_mode_tmp += (i4_mbaddr_x * i4_element_size);
2110
30.0k
        ps_inter_lyr_mb_prms = (inter_lyr_mb_prms_t *) pi1_ref_mb_mode_tmp;
2111
30.0k
        i1_mb_mode = ps_inter_lyr_mb_prms->i1_mb_mode;
2112
2113
        /* The reference layer MB should be intra */
2114
30.0k
        UNUSED(i1_mb_mode);
2115
2116
30.0k
        i1_slice_id = ps_inter_lyr_mb_prms->i1_slice_id;
2117
30.0k
    }
2118
26.2k
    else
2119
26.2k
    {
2120
        /* set to non valid value */
2121
26.2k
        i1_slice_id = -1;
2122
26.2k
    }
2123
2124
    /* --------------------------------------------------------------------- */
2125
    /* Bring in the reference array                                          */
2126
    /* --------------------------------------------------------------------- */
2127
56.2k
    {
2128
56.2k
        UWORD8 *pu1_src, *pu1_dst;
2129
56.2k
        WORD32 i4_src_stride, i4_dst_stride;
2130
2131
        /* Copy luma */
2132
56.2k
        i4_src_stride = i4_inp_luma_stride;
2133
56.2k
        i4_dst_stride = DYADIC_REF_W_Y;
2134
56.2k
        pu1_src = pu1_inp_luma;
2135
56.2k
        pu1_dst = pu1_refarray_luma;
2136
56.2k
        isvcd_copy_data(pu1_src, i4_src_stride, pu1_dst, i4_dst_stride, i4_refarray_wd_luma,
2137
56.2k
                        i4_refarray_ht_luma);
2138
        // Semi planar
2139
56.2k
        i4_src_stride = i4_inp_chroma_stride;
2140
56.2k
        i4_dst_stride = DYADIC_REF_W_C;
2141
56.2k
        pu1_src = pu1_inp_chroma;
2142
56.2k
        isvcd_copy_data_semiplanr(pu1_src, i4_src_stride, pu1_refarray_cb, pu1_refarray_cr,
2143
56.2k
                                  i4_dst_stride, i4_refarray_wd_chroma, i4_refarray_ht_chroma);
2144
56.2k
    }
2145
2146
    /* --------------------------------------------------------------------- */
2147
    /* Get the availability of 5 neighboring MBs                             */
2148
    /* --------------------------------------------------------------------- */
2149
56.2k
    {
2150
        /* mb_x + left, mb_y + top */
2151
56.2k
        isvcd_get_ref_layer_avlblty_dyadic(pi1_ref_mb_modes, i4_ref_mode_stride, i4_element_size,
2152
56.2k
                                           i4_mbaddr_x + i4_left, i4_mbaddr_y + i4_top, &i4_avlblty,
2153
56.2k
                                           i1_slice_id, i1_cons_intr_samp_flag);
2154
56.2k
        u1_ny_avlblty = i4_avlblty;
2155
2156
        /* mb_x + left, mb_y */
2157
56.2k
        isvcd_get_ref_layer_avlblty_dyadic(pi1_ref_mb_modes, i4_ref_mode_stride, i4_element_size,
2158
56.2k
                                           i4_mbaddr_x + i4_left, i4_mbaddr_y, &i4_avlblty,
2159
56.2k
                                           i1_slice_id, i1_cons_intr_samp_flag);
2160
56.2k
        u1_ny_avlblty += (i4_avlblty << 1);
2161
2162
        /* mb_x, mb_y + top */
2163
56.2k
        isvcd_get_ref_layer_avlblty_dyadic(pi1_ref_mb_modes, i4_ref_mode_stride, i4_element_size,
2164
56.2k
                                           i4_mbaddr_x, i4_mbaddr_y + i4_top, &i4_avlblty,
2165
56.2k
                                           i1_slice_id, i1_cons_intr_samp_flag);
2166
56.2k
        u1_ny_avlblty += (i4_avlblty << 2);
2167
2168
        /* mb_x - left, mb_y + top */
2169
56.2k
        isvcd_get_ref_layer_avlblty_dyadic(pi1_ref_mb_modes, i4_ref_mode_stride, i4_element_size,
2170
56.2k
                                           i4_mbaddr_x - i4_left, i4_mbaddr_y + i4_top, &i4_avlblty,
2171
56.2k
                                           i1_slice_id, i1_cons_intr_samp_flag);
2172
56.2k
        u1_ny_avlblty += (i4_avlblty << 3);
2173
2174
        /* mb_x + left, mb_y - top */
2175
56.2k
        isvcd_get_ref_layer_avlblty_dyadic(pi1_ref_mb_modes, i4_ref_mode_stride, i4_element_size,
2176
56.2k
                                           i4_mbaddr_x + i4_left, i4_mbaddr_y - i4_top, &i4_avlblty,
2177
56.2k
                                           i1_slice_id, i1_cons_intr_samp_flag);
2178
56.2k
        u1_ny_avlblty += (i4_avlblty << 4);
2179
56.2k
    }
2180
2181
    /* --------------------------------------------------------------------- */
2182
    /* Filling the unavailable samples, if any                                 */
2183
    /* --------------------------------------------------------------------- */
2184
56.2k
    if(0x7 == u1_ny_avlblty)
2185
352
    {
2186
        /* All are available, exit */
2187
352
        return OK;
2188
352
    }
2189
2190
55.9k
    if(!(u1_ny_avlblty & 0x7))
2191
36.0k
    {
2192
36.0k
        UWORD8 *pu1_tmp_src, *pu1_tmp_dst1, *pu1_tmp_dst2;
2193
36.0k
        UWORD8 *pu1_tmp_src1, *pu1_tmp_src2;
2194
2195
        /* Set the 4 corner samples to (x-xD,y-yD) */
2196
36.0k
        i4_x0 = 9 + (i4_left << 3) + i4_left;
2197
36.0k
        i4_y0 = 9 + (i4_top << 3) + i4_top;
2198
2199
36.0k
        i4_ref_xD = i4_x0 - i4_left - (i4_left >> 1);
2200
36.0k
        i4_ref_yD = i4_y0 - i4_top - (i4_top >> 1);
2201
2202
36.0k
        pu1_tmp_src = pu1_refarray_luma + (i4_ref_yD * DYADIC_REF_W_Y);
2203
36.0k
        pu1_tmp_dst1 = pu1_refarray_luma + (i4_y0 * DYADIC_REF_W_Y);
2204
36.0k
        pu1_tmp_dst2 = pu1_tmp_dst1 + DYADIC_REF_W_Y;
2205
36.0k
        pu1_tmp_dst1[i4_x0] = pu1_tmp_src[i4_ref_xD];
2206
36.0k
        pu1_tmp_dst1[i4_x0 + 1] = pu1_tmp_src[i4_ref_xD];
2207
36.0k
        pu1_tmp_dst2[i4_x0] = pu1_tmp_src[i4_ref_xD];
2208
36.0k
        pu1_tmp_dst2[i4_x0 + 1] = pu1_tmp_src[i4_ref_xD];
2209
2210
        /* Set the corner sample of Cb and Cr to (x-xD,y-yD) */
2211
36.0k
        i4_xc0 = i4_x0 >> 1;
2212
36.0k
        i4_yc0 = i4_y0 >> 1;
2213
36.0k
        i4_c_ref_yD = i4_ref_yD >> 1;
2214
36.0k
        i4_c_ref_xD = i4_ref_xD >> 1;
2215
36.0k
        pu1_tmp_src1 = pu1_refarray_cb + (i4_c_ref_yD * DYADIC_REF_W_C);
2216
36.0k
        pu1_tmp_dst1 = pu1_refarray_cb + (i4_yc0 * DYADIC_REF_W_C);
2217
36.0k
        pu1_tmp_dst1[i4_xc0] = pu1_tmp_src1[i4_c_ref_xD];
2218
36.0k
        pu1_tmp_src2 = pu1_refarray_cr + (i4_c_ref_yD * DYADIC_REF_W_C);
2219
36.0k
        pu1_tmp_dst2 = pu1_refarray_cr + (i4_yc0 * DYADIC_REF_W_C);
2220
36.0k
        pu1_tmp_dst2[i4_xc0] = pu1_tmp_src2[i4_c_ref_xD];
2221
36.0k
    }
2222
2223
55.9k
    if(!(u1_ny_avlblty & 0x5))
2224
38.2k
    {
2225
38.2k
        UWORD8 *pu1_tmp_src, *pu1_tmp_dst1, *pu1_tmp_dst2;
2226
38.2k
        UWORD8 *pu1_tmp_src1, *pu1_tmp_src2;
2227
2228
        /* Copy (x0,ref_yD), (x0+1,ref_yD), ..., (x0+7,ref_yD) to */
2229
        /* (x0,y0), (x0+1,y0), ..., (x0+7,y0) and   */
2230
        /* (x0,y0+1), (x0+1,y0+1), ..., (x0+7,y0+1) */
2231
38.2k
        i4_x0 = 2;
2232
38.2k
        i4_y0 = 9 + (i4_top << 3) + i4_top;
2233
38.2k
        if(i4_left > 0)
2234
18.7k
        {
2235
18.7k
            i4_x0 += 8;
2236
18.7k
        }
2237
38.2k
        i4_ref_yD = i4_y0 - i4_top - (i4_top >> 1);
2238
2239
38.2k
        pu1_tmp_src = pu1_refarray_luma + (i4_ref_yD * DYADIC_REF_W_Y);
2240
38.2k
        pu1_tmp_dst1 = pu1_refarray_luma + (i4_y0 * DYADIC_REF_W_Y);
2241
38.2k
        pu1_tmp_dst2 = pu1_tmp_dst1 + DYADIC_REF_W_Y;
2242
2243
344k
        for(i4_x = i4_x0; i4_x < i4_x0 + 8; i4_x++)
2244
306k
        {
2245
306k
            pu1_tmp_dst1[i4_x] = pu1_tmp_src[i4_x];
2246
306k
            pu1_tmp_dst2[i4_x] = pu1_tmp_src[i4_x];
2247
306k
        }
2248
2249
        /* Cb and Cr copy */
2250
38.2k
        i4_xc0 = i4_x0 >> 1;
2251
38.2k
        i4_yc0 = i4_y0 >> 1;
2252
38.2k
        i4_c_ref_yD = i4_ref_yD >> 1;
2253
38.2k
        pu1_tmp_src1 = pu1_refarray_cb + (i4_c_ref_yD * DYADIC_REF_W_C);
2254
38.2k
        pu1_tmp_dst1 = pu1_refarray_cb + (i4_yc0 * DYADIC_REF_W_C);
2255
38.2k
        pu1_tmp_src2 = pu1_refarray_cr + (i4_c_ref_yD * DYADIC_REF_W_C);
2256
38.2k
        pu1_tmp_dst2 = pu1_refarray_cr + (i4_yc0 * DYADIC_REF_W_C);
2257
2258
191k
        for(i4_x = i4_xc0; i4_x < i4_xc0 + 4; i4_x++)
2259
153k
        {
2260
153k
            pu1_tmp_dst1[i4_x] = pu1_tmp_src1[i4_x];
2261
153k
            pu1_tmp_dst2[i4_x] = pu1_tmp_src2[i4_x];
2262
153k
        }
2263
38.2k
    }
2264
2265
55.9k
    if(!(u1_ny_avlblty & 0x3))
2266
42.0k
    {
2267
42.0k
        UWORD8 *pu1_tmp_src, *pu1_tmp_dst1, *pu1_tmp_dst2;
2268
42.0k
        UWORD8 *pu1_tmp_src1, *pu1_tmp_src2;
2269
2270
        /* Copy (ref_xD,y0) to (x0,y0) and (x0+1,y0); */
2271
        /* copy (ref_xD,y0+1) to (x0,y0+1) and (x0+1,y0+1); ... ;*/
2272
        /* copy (ref_xD,y0+7) to (x0,y0+7) and (x0+1,y0+7) */
2273
42.0k
        i4_x0 = 9 + (i4_left << 3) + i4_left;
2274
42.0k
        i4_y0 = 2;
2275
42.0k
        if(i4_top > 0)
2276
20.0k
        {
2277
20.0k
            i4_y0 += 8;
2278
20.0k
        }
2279
42.0k
        i4_ref_xD = i4_x0 - i4_left - (i4_left >> 1);
2280
2281
42.0k
        pu1_tmp_src = pu1_refarray_luma + (i4_y0 * DYADIC_REF_W_Y);
2282
42.0k
        pu1_tmp_dst1 = pu1_tmp_src;
2283
2284
378k
        for(i4_y = i4_y0; i4_y < i4_y0 + 8; i4_y++)
2285
336k
        {
2286
336k
            pu1_tmp_dst1[i4_x0] = pu1_tmp_src[i4_ref_xD];
2287
336k
            pu1_tmp_dst1[i4_x0 + 1] = pu1_tmp_src[i4_ref_xD];
2288
336k
            pu1_tmp_src += DYADIC_REF_W_Y;
2289
336k
            pu1_tmp_dst1 += DYADIC_REF_W_Y;
2290
336k
        }
2291
2292
        /* Cb and Cr copy */
2293
42.0k
        i4_xc0 = i4_x0 >> 1;
2294
42.0k
        i4_yc0 = i4_y0 >> 1;
2295
42.0k
        i4_c_ref_xD = i4_ref_xD >> 1;
2296
42.0k
        pu1_tmp_src1 = pu1_refarray_cb + (i4_yc0 * DYADIC_REF_W_C);
2297
42.0k
        pu1_tmp_dst1 = pu1_tmp_src1;
2298
42.0k
        pu1_tmp_src2 = pu1_refarray_cr + (i4_yc0 * DYADIC_REF_W_C);
2299
42.0k
        pu1_tmp_dst2 = pu1_tmp_src2;
2300
2301
210k
        for(i4_y = i4_yc0; i4_y < i4_yc0 + 4; i4_y++)
2302
168k
        {
2303
168k
            pu1_tmp_dst1[i4_xc0] = pu1_tmp_src1[i4_c_ref_xD];
2304
168k
            pu1_tmp_dst2[i4_xc0] = pu1_tmp_src2[i4_c_ref_xD];
2305
168k
            pu1_tmp_src1 += DYADIC_REF_W_C;
2306
168k
            pu1_tmp_src2 += DYADIC_REF_W_C;
2307
168k
            pu1_tmp_dst1 += DYADIC_REF_W_C;
2308
168k
            pu1_tmp_dst2 += DYADIC_REF_W_C;
2309
168k
        }
2310
42.0k
    }
2311
2312
55.9k
    if(!(u1_ny_avlblty & 0x4))
2313
45.0k
    {
2314
45.0k
        if(!(u1_ny_avlblty & 0x8))
2315
38.3k
        {
2316
            /* (mb_x-left,mb_y+top) not available */
2317
38.3k
            UWORD8 *pu1_tmp_src, *pu1_tmp_dst;
2318
2319
38.3k
            i4_x0 = 9 - i4_left;
2320
38.3k
            i4_y0 = 9 + (i4_top << 3) + i4_top;
2321
2322
38.3k
            i4_ref_yD = i4_y0 - i4_top - (i4_top >> 1);
2323
2324
            /* Copy (x0,ref_yD) and (x0+1,ref_yD) to (x0,y0) and (x0+1,y0), and */
2325
            /* to (x0,y0+1) and (x0+1,y0+1) */
2326
38.3k
            pu1_tmp_src = pu1_refarray_luma + (i4_ref_yD * DYADIC_REF_W_Y);
2327
38.3k
            pu1_tmp_dst = pu1_refarray_luma + (i4_y0 * DYADIC_REF_W_Y);
2328
38.3k
            pu1_tmp_dst[i4_x0] = pu1_tmp_src[i4_x0];
2329
38.3k
            pu1_tmp_dst[i4_x0 + 1] = pu1_tmp_src[i4_x0 + 1];
2330
38.3k
            pu1_tmp_dst += DYADIC_REF_W_Y;
2331
38.3k
            pu1_tmp_dst[i4_x0] = pu1_tmp_src[i4_x0];
2332
38.3k
            pu1_tmp_dst[i4_x0 + 1] = pu1_tmp_src[i4_x0 + 1];
2333
2334
            /* Cb copy */
2335
38.3k
            i4_xc0 = i4_x0 >> 1;
2336
38.3k
            i4_yc0 = i4_y0 >> 1;
2337
38.3k
            i4_c_ref_yD = i4_ref_yD >> 1;
2338
38.3k
            pu1_tmp_src = pu1_refarray_cb + (i4_c_ref_yD * DYADIC_REF_W_C);
2339
38.3k
            pu1_tmp_dst = pu1_refarray_cb + (i4_yc0 * DYADIC_REF_W_C);
2340
38.3k
            pu1_tmp_dst[i4_xc0] = pu1_tmp_src[i4_xc0];
2341
2342
            /* Cr copy */
2343
38.3k
            pu1_tmp_src = pu1_refarray_cr + (i4_c_ref_yD * DYADIC_REF_W_C);
2344
38.3k
            pu1_tmp_dst = pu1_refarray_cr + (i4_yc0 * DYADIC_REF_W_C);
2345
38.3k
            pu1_tmp_dst[i4_xc0] = pu1_tmp_src[i4_xc0];
2346
2347
38.3k
        } /* if (mb_x-left,mb_y+top) not available */
2348
6.64k
        else
2349
6.64k
        {
2350
6.64k
            WORD32 i4_xD, i4_yD;
2351
6.64k
            WORD32 i4_c_xD, i4_c_yD;
2352
2353
6.64k
            isvcd_get_ref_layer_avlblty_dyadic(pi1_ref_mb_modes, i4_ref_mode_stride,
2354
6.64k
                                               i4_element_size, i4_mbaddr_x - i4_left, i4_mbaddr_y,
2355
6.64k
                                               &i4_avlblty, i1_slice_id, i1_cons_intr_samp_flag);
2356
6.64k
            i1_corner_samp_avlbl_flag = i4_avlblty;
2357
2358
6.64k
            i4_x0 = 9 - i4_left;
2359
6.64k
            i4_y0 = 9 + (i4_top << 3) + i4_top;
2360
6.64k
            i4_xc0 = i4_x0 >> 1;
2361
6.64k
            i4_yc0 = i4_y0 >> 1;
2362
6.64k
            i4_ref_yD = i4_y0 - i4_top - (i4_top >> 1);
2363
6.64k
            i4_ref_xD = i4_x0 - (i4_left * 7) - (i4_left >> 1);
2364
6.64k
            i4_c_ref_xD = i4_ref_xD >> 1;
2365
6.64k
            i4_c_ref_yD = i4_ref_yD >> 1;
2366
6.64k
            i4_xD = i4_x0 - i4_ref_xD;
2367
6.64k
            i4_yD = i4_y0 - i4_ref_yD;
2368
6.64k
            i4_c_xD = i4_xc0 - i4_c_ref_xD;
2369
6.64k
            i4_c_yD = i4_yc0 - i4_c_ref_yD;
2370
2371
            /* Fill corner sample if not available */
2372
6.64k
            if(!i1_corner_samp_avlbl_flag)
2373
6.36k
            {
2374
6.36k
                isvcd_corner_samp_dyadic(i4_x0, i4_y0, i4_xD, i4_yD, pu1_refarray_luma,
2375
6.36k
                                         pu1_refarray_cb, pu1_refarray_cr);
2376
6.36k
            }
2377
2378
            /* Call diagonal construction for luma */
2379
19.9k
            for(i4_y = i4_y0; i4_y < i4_y0 + 2; i4_y++)
2380
13.2k
            {
2381
39.8k
                for(i4_x = i4_x0; i4_x < i4_x0 + 2; i4_x++)
2382
26.5k
                {
2383
26.5k
                    isvcd_diagonal_construct_dyadic(i4_x, i4_y, i4_xD, i4_yD, pu1_refarray_luma,
2384
26.5k
                                                    DYADIC_REF_W_Y);
2385
26.5k
                    i4_xD++;
2386
26.5k
                }
2387
13.2k
                i4_yD++;
2388
13.2k
                i4_xD -= 2;
2389
13.2k
            }
2390
2391
            /* Call diagonal construction for chroma */
2392
6.64k
            isvcd_diagonal_construct_dyadic(i4_xc0, i4_yc0, i4_c_xD, i4_c_yD, pu1_refarray_cb,
2393
6.64k
                                            DYADIC_REF_W_C);
2394
2395
6.64k
            isvcd_diagonal_construct_dyadic(i4_xc0, i4_yc0, i4_c_xD, i4_c_yD, pu1_refarray_cr,
2396
6.64k
                                            DYADIC_REF_W_C);
2397
6.64k
        }
2398
45.0k
    }
2399
2400
55.9k
    if(!(u1_ny_avlblty & 0x2))
2401
49.2k
    {
2402
49.2k
        if(!(u1_ny_avlblty & 0x10))
2403
42.4k
        {
2404
42.4k
            UWORD8 *pu1_tmp_src, *pu1_tmp_dst;
2405
2406
42.4k
            i4_x0 = 9 + (i4_left << 3) + i4_left;
2407
42.4k
            i4_y0 = 9 - i4_top;
2408
42.4k
            i4_ref_xD = i4_x0 - i4_left - (i4_left >> 1);
2409
2410
            /* Copy (ref_xD,y0) to (x0,y0), (x0+1,y0), and  */
2411
            /* copy (ref_xD,y0+1) to (x0,y0+1), (x0+1,y0+1) */
2412
42.4k
            pu1_tmp_src = pu1_refarray_luma + (i4_y0 * DYADIC_REF_W_Y);
2413
42.4k
            pu1_tmp_dst = pu1_tmp_src;
2414
42.4k
            pu1_tmp_dst[i4_x0] = pu1_tmp_src[i4_ref_xD];
2415
42.4k
            pu1_tmp_dst[i4_x0 + 1] = pu1_tmp_src[i4_ref_xD];
2416
42.4k
            pu1_tmp_src += DYADIC_REF_W_Y;
2417
42.4k
            pu1_tmp_dst += DYADIC_REF_W_Y;
2418
42.4k
            pu1_tmp_dst[i4_x0] = pu1_tmp_src[i4_ref_xD];
2419
42.4k
            pu1_tmp_dst[i4_x0 + 1] = pu1_tmp_src[i4_ref_xD];
2420
2421
            /* Cb copy */
2422
42.4k
            i4_xc0 = i4_x0 >> 1;
2423
42.4k
            i4_yc0 = i4_y0 >> 1;
2424
42.4k
            i4_c_ref_xD = i4_ref_xD >> 1;
2425
42.4k
            pu1_tmp_src = pu1_refarray_cb + (i4_yc0 * DYADIC_REF_W_C);
2426
42.4k
            pu1_tmp_dst = pu1_tmp_src;
2427
42.4k
            pu1_tmp_dst[i4_xc0] = pu1_tmp_src[i4_c_ref_xD];
2428
2429
            /* Cr copy */
2430
42.4k
            pu1_tmp_src = pu1_refarray_cr + (i4_yc0 * DYADIC_REF_W_C);
2431
42.4k
            pu1_tmp_dst = pu1_tmp_src;
2432
42.4k
            pu1_tmp_dst[i4_xc0] = pu1_tmp_src[i4_c_ref_xD];
2433
2434
42.4k
        } /* if (mb_x+left,mb_y-top) not available */
2435
6.79k
        else
2436
6.79k
        {
2437
6.79k
            WORD32 i4_xD, i4_yD;
2438
6.79k
            WORD32 i4_c_xD, i4_c_yD;
2439
2440
6.79k
            isvcd_get_ref_layer_avlblty_dyadic(pi1_ref_mb_modes, i4_ref_mode_stride,
2441
6.79k
                                               i4_element_size, i4_mbaddr_x, i4_mbaddr_y - i4_top,
2442
6.79k
                                               &i4_avlblty, i1_slice_id, i1_cons_intr_samp_flag);
2443
6.79k
            i1_corner_samp_avlbl_flag = i4_avlblty;
2444
2445
6.79k
            i4_x0 = 9 + (i4_left << 3) + i4_left;
2446
6.79k
            i4_y0 = 9 - i4_top;
2447
6.79k
            i4_xc0 = i4_x0 >> 1;
2448
6.79k
            i4_yc0 = i4_y0 >> 1;
2449
6.79k
            i4_ref_xD = i4_x0 - i4_left - (i4_left >> 1);
2450
6.79k
            i4_ref_yD = i4_y0 - (i4_top * 7) - (i4_top >> 1);
2451
6.79k
            i4_c_ref_xD = i4_ref_xD >> 1;
2452
6.79k
            i4_c_ref_yD = i4_ref_yD >> 1;
2453
6.79k
            i4_xD = i4_x0 - i4_ref_xD;
2454
6.79k
            i4_yD = i4_y0 - i4_ref_yD;
2455
6.79k
            i4_c_xD = i4_xc0 - i4_c_ref_xD;
2456
6.79k
            i4_c_yD = i4_yc0 - i4_c_ref_yD;
2457
2458
6.79k
            if(!i1_corner_samp_avlbl_flag)
2459
6.08k
            {
2460
6.08k
                isvcd_corner_samp_dyadic(i4_x0, i4_y0, i4_xD, i4_yD, pu1_refarray_luma,
2461
6.08k
                                         pu1_refarray_cb, pu1_refarray_cr);
2462
6.08k
            }
2463
2464
            /* Call diagonal consrtuction for luma */
2465
20.3k
            for(i4_y = i4_y0; i4_y < i4_y0 + 2; i4_y++)
2466
13.5k
            {
2467
40.7k
                for(i4_x = i4_x0; i4_x < i4_x0 + 2; i4_x++)
2468
27.1k
                {
2469
27.1k
                    isvcd_diagonal_construct_dyadic(i4_x, i4_y, i4_xD, i4_yD, pu1_refarray_luma,
2470
27.1k
                                                    DYADIC_REF_W_Y);
2471
27.1k
                    i4_xD++;
2472
27.1k
                }
2473
13.5k
                i4_yD++;
2474
13.5k
                i4_xD -= 2;
2475
13.5k
            }
2476
2477
            /* Call diagonal construction for chroma */
2478
6.79k
            isvcd_diagonal_construct_dyadic(i4_xc0, i4_yc0, i4_c_xD, i4_c_yD, pu1_refarray_cb,
2479
6.79k
                                            DYADIC_REF_W_C);
2480
2481
6.79k
            isvcd_diagonal_construct_dyadic(i4_xc0, i4_yc0, i4_c_xD, i4_c_yD, pu1_refarray_cr,
2482
6.79k
                                            DYADIC_REF_W_C);
2483
6.79k
        }
2484
49.2k
    }
2485
2486
55.9k
    if(u1_ny_avlblty & 1)
2487
8.06k
    {
2488
8.06k
        if(!(u1_ny_avlblty & 2))
2489
7.14k
        {
2490
            /* (mb_x+left,mb_y) is unavailable */
2491
7.14k
            WORD32 i4_xD, i4_yD;
2492
7.14k
            WORD32 i4_c_xD, i4_c_yD;
2493
7.14k
            UWORD8 *pu1_tmp_dst;
2494
7.14k
            UWORD8 u1_filled_samp;
2495
2496
7.14k
            i1_corner_samp_avlbl_flag = (u1_ny_avlblty & 4) >> 2;
2497
2498
7.14k
            i4_x0 = 9 + (i4_left << 3) + i4_left;
2499
7.14k
            i4_y0 = 2;
2500
7.14k
            i4_ref_yD = 1;
2501
7.14k
            if(i4_top > 0)
2502
3.44k
            {
2503
3.44k
                i4_y0 += 8;
2504
3.44k
                i4_ref_yD = 18;
2505
3.44k
            }
2506
2507
7.14k
            i4_ref_xD = i4_x0 - (i4_left) - (i4_left >> 1);
2508
7.14k
            i4_xD = i4_x0 - i4_ref_xD;
2509
7.14k
            i4_yD = i4_y0 - i4_ref_yD;
2510
7.14k
            i4_xc0 = i4_x0 >> 1;
2511
7.14k
            i4_yc0 = i4_y0 >> 1;
2512
7.14k
            i4_c_ref_xD = i4_ref_xD >> 1;
2513
7.14k
            i4_c_ref_yD = i4_ref_yD >> 1;
2514
7.14k
            i4_c_xD = i4_xc0 - i4_c_ref_xD;
2515
7.14k
            i4_c_yD = i4_yc0 - i4_c_ref_yD;
2516
2517
            /* Fill corner sample if unavailable */
2518
7.14k
            if(!i1_corner_samp_avlbl_flag)
2519
6.44k
            {
2520
6.44k
                isvcd_corner_samp_dyadic(i4_x0, i4_y0, i4_xD, i4_yD, pu1_refarray_luma,
2521
6.44k
                                         pu1_refarray_cb, pu1_refarray_cr);
2522
6.44k
            }
2523
2524
            /* Call the diagonal construction for the 8 rows */
2525
7.14k
            if(i4_top == i4_left)
2526
3.65k
            {
2527
                /* if top * left = 1 (x0,y0) */
2528
3.65k
                u1_filled_samp = isvcd_diagonal_construct_dyadic(i4_x0, i4_y0, i4_xD, i4_yD,
2529
3.65k
                                                                 pu1_refarray_luma, DYADIC_REF_W_Y);
2530
2531
3.65k
                pu1_tmp_dst = pu1_refarray_luma + (i4_y0 * DYADIC_REF_W_Y);
2532
2533
                /* (x0,y0+1), ..., (x0,y0+7) and */
2534
                /* (x0+1,y0), ..., (x0+1,y0+6)   */
2535
29.2k
                for(i4_y = i4_y0 + 1; i4_y < i4_y0 + 8; i4_y++)
2536
25.5k
                {
2537
25.5k
                    i4_yD++;
2538
25.5k
                    u1_filled_samp = isvcd_diagonal_construct_dyadic(
2539
25.5k
                        i4_x0, i4_y, i4_xD, i4_yD, pu1_refarray_luma, DYADIC_REF_W_Y);
2540
25.5k
                    pu1_tmp_dst[i4_x0 + 1] = u1_filled_samp;
2541
25.5k
                    pu1_tmp_dst += DYADIC_REF_W_Y;
2542
25.5k
                }
2543
2544
                /* (x0+1,y0+7) */
2545
3.65k
                u1_filled_samp = isvcd_diagonal_construct_dyadic(
2546
3.65k
                    i4_x0 + 1, i4_y0 + 7, i4_xD + 1, i4_yD, pu1_refarray_luma, DYADIC_REF_W_Y);
2547
3.65k
            }
2548
3.48k
            else
2549
3.48k
            {
2550
                /* top * left = -1 (x0+1,y0) */
2551
3.48k
                u1_filled_samp = isvcd_diagonal_construct_dyadic(i4_x0 + 1, i4_y0, i4_xD + 1, i4_yD,
2552
3.48k
                                                                 pu1_refarray_luma, DYADIC_REF_W_Y);
2553
2554
3.48k
                pu1_tmp_dst = pu1_refarray_luma + (i4_y0 * DYADIC_REF_W_Y);
2555
2556
                /* (x0,y0), ..., (x0,y0+6) and   */
2557
                /* (x0+1,y0+1), ..., (x0+1,y0+7) */
2558
27.8k
                for(i4_y = i4_y0; i4_y < i4_y0 + 7; i4_y++)
2559
24.4k
                {
2560
24.4k
                    u1_filled_samp = isvcd_diagonal_construct_dyadic(
2561
24.4k
                        i4_x0, i4_y, i4_xD, i4_yD, pu1_refarray_luma, DYADIC_REF_W_Y);
2562
2563
24.4k
                    pu1_tmp_dst += DYADIC_REF_W_Y;
2564
24.4k
                    pu1_tmp_dst[i4_x0 + 1] = u1_filled_samp;
2565
24.4k
                    i4_yD++;
2566
24.4k
                }
2567
2568
                /* (x0,y0+7) */
2569
3.48k
                u1_filled_samp = isvcd_diagonal_construct_dyadic(i4_x0, i4_y0 + 7, i4_xD, i4_yD,
2570
3.48k
                                                                 pu1_refarray_luma, DYADIC_REF_W_Y);
2571
3.48k
            }
2572
2573
            /* For Cb and Cr */
2574
35.7k
            for(i4_y = i4_yc0; i4_y < i4_yc0 + 4; i4_y++)
2575
28.5k
            {
2576
28.5k
                u1_filled_samp = isvcd_diagonal_construct_dyadic(i4_xc0, i4_y, i4_c_xD, i4_c_yD,
2577
28.5k
                                                                 pu1_refarray_cb, DYADIC_REF_W_C);
2578
28.5k
                u1_filled_samp = isvcd_diagonal_construct_dyadic(i4_xc0, i4_y, i4_c_xD, i4_c_yD,
2579
28.5k
                                                                 pu1_refarray_cr, DYADIC_REF_W_C);
2580
28.5k
                i4_c_yD++;
2581
28.5k
            }
2582
2583
7.14k
        } /* (mb_x+left,mb_y) is unavailable */
2584
2585
8.06k
        if(!(u1_ny_avlblty & 4))
2586
6.72k
        {
2587
            /* (mb_x,mb_y+top) is unavailable */
2588
6.72k
            WORD32 i4_xD, i4_yD;
2589
6.72k
            WORD32 i4_c_xD, i4_c_yD;
2590
6.72k
            UWORD8 *pu1_tmp_dst;
2591
6.72k
            UWORD8 u1_filled_samp;
2592
2593
6.72k
            i1_corner_samp_avlbl_flag = (u1_ny_avlblty & 2) >> 1;
2594
6.72k
            i4_y0 = 9 + (i4_top << 3) + (i4_top);
2595
6.72k
            i4_x0 = 2;
2596
6.72k
            i4_ref_xD = 1;
2597
6.72k
            if(i4_left > 0)
2598
3.57k
            {
2599
3.57k
                i4_x0 += 8;
2600
3.57k
                i4_ref_xD = 18;
2601
3.57k
            }
2602
2603
6.72k
            i4_ref_yD = i4_y0 - i4_top - (i4_top >> 1);
2604
6.72k
            i4_xD = i4_x0 - i4_ref_xD;
2605
6.72k
            i4_yD = i4_y0 - i4_ref_yD;
2606
6.72k
            i4_xc0 = i4_x0 >> 1;
2607
6.72k
            i4_yc0 = i4_y0 >> 1;
2608
6.72k
            i4_c_ref_xD = i4_ref_xD >> 1;
2609
6.72k
            i4_c_ref_yD = i4_ref_yD >> 1;
2610
6.72k
            i4_c_xD = i4_xc0 - i4_c_ref_xD;
2611
6.72k
            i4_c_yD = i4_yc0 - i4_c_ref_yD;
2612
2613
6.72k
            if(!i1_corner_samp_avlbl_flag)
2614
6.44k
            {
2615
6.44k
                isvcd_corner_samp_dyadic(i4_x0, i4_y0, i4_xD, i4_yD, pu1_refarray_luma,
2616
6.44k
                                         pu1_refarray_cb, pu1_refarray_cr);
2617
6.44k
            }
2618
2619
            /* Call the diagonal construction for the 2 rows */
2620
6.72k
            if(i4_top == i4_left)
2621
3.39k
            {
2622
                /* if top * left = 1 (x0,y0) */
2623
3.39k
                u1_filled_samp = isvcd_diagonal_construct_dyadic(i4_x0, i4_y0, i4_xD, i4_yD,
2624
3.39k
                                                                 pu1_refarray_luma, DYADIC_REF_W_Y);
2625
2626
3.39k
                pu1_tmp_dst = pu1_refarray_luma + ((i4_y0 + 1) * DYADIC_REF_W_Y);
2627
2628
                /* (x0+1,y0), ..., (x0+7,y0) and */
2629
                /* (x0,y0+1), ..., (x0+6,y0+1)   */
2630
27.1k
                for(i4_x = i4_x0 + 1; i4_x < i4_x0 + 8; i4_x++)
2631
23.7k
                {
2632
23.7k
                    i4_xD++;
2633
23.7k
                    u1_filled_samp = isvcd_diagonal_construct_dyadic(
2634
23.7k
                        i4_x, i4_y0, i4_xD, i4_yD, pu1_refarray_luma, DYADIC_REF_W_Y);
2635
23.7k
                    pu1_tmp_dst[i4_x - 1] = u1_filled_samp;
2636
23.7k
                }
2637
2638
                /* (x0+7,y0+1) */
2639
3.39k
                u1_filled_samp = isvcd_diagonal_construct_dyadic(
2640
3.39k
                    i4_x0 + 7, i4_y0 + 1, i4_xD, i4_yD + 1, pu1_refarray_luma, DYADIC_REF_W_Y);
2641
3.39k
            }
2642
3.32k
            else
2643
3.32k
            {
2644
                /* top * left = -1 */
2645
                /* (x0,y0+1) */
2646
3.32k
                u1_filled_samp = isvcd_diagonal_construct_dyadic(i4_x0, i4_y0 + 1, i4_xD, i4_yD + 1,
2647
3.32k
                                                                 pu1_refarray_luma, DYADIC_REF_W_Y);
2648
2649
3.32k
                pu1_tmp_dst = pu1_refarray_luma + ((i4_y0 + 1) * DYADIC_REF_W_Y);
2650
2651
                /* (x0,y0), ..., (x0,y0+6) and   */
2652
                /* (x0+1,y0+1), ..., (x0+1,y0+7) */
2653
26.6k
                for(i4_x = i4_x0; i4_x < i4_x0 + 7; i4_x++)
2654
23.2k
                {
2655
23.2k
                    u1_filled_samp = isvcd_diagonal_construct_dyadic(
2656
23.2k
                        i4_x, i4_y0, i4_xD, i4_yD, pu1_refarray_luma, DYADIC_REF_W_Y);
2657
2658
23.2k
                    pu1_tmp_dst[i4_x + 1] = u1_filled_samp;
2659
23.2k
                    i4_xD++;
2660
23.2k
                }
2661
2662
                /* (x0+7,y0) */
2663
3.32k
                u1_filled_samp = isvcd_diagonal_construct_dyadic(i4_x0 + 7, i4_y0, i4_xD, i4_yD,
2664
3.32k
                                                                 pu1_refarray_luma, DYADIC_REF_W_Y);
2665
3.32k
            }
2666
2667
            /* For Cb and Cr */
2668
33.6k
            for(i4_x = i4_xc0; i4_x < i4_xc0 + 4; i4_x++)
2669
26.8k
            {
2670
26.8k
                u1_filled_samp = isvcd_diagonal_construct_dyadic(i4_x, i4_yc0, i4_c_xD, i4_c_yD,
2671
26.8k
                                                                 pu1_refarray_cb, DYADIC_REF_W_C);
2672
26.8k
                u1_filled_samp = isvcd_diagonal_construct_dyadic(i4_x, i4_yc0, i4_c_xD, i4_c_yD,
2673
26.8k
                                                                 pu1_refarray_cr, DYADIC_REF_W_C);
2674
26.8k
                i4_c_xD++;
2675
26.8k
            }
2676
2677
6.72k
        } /* (mb_x,mb_y+top) is unavailable */
2678
8.06k
    }     /* if (mb_x+left,mb_y+top) not available */
2679
47.8k
    else
2680
47.8k
    {
2681
47.8k
        UWORD8 *pu1_tmp_dst1, *pu1_tmp_dst2;
2682
47.8k
        UWORD8 *pu1_tmp_src1, *pu1_tmp_src2;
2683
2684
47.8k
        if(0x02 == (u1_ny_avlblty & 0x6))
2685
2.19k
        {
2686
            /* (mb_x+left,mb_y) available, (mb_x,mb_y+top) unavailable */
2687
2.19k
            i4_x0 = 9 + (i4_left << 3) + i4_left;
2688
2.19k
            i4_y0 = 9 + (i4_top << 3) + i4_top;
2689
2.19k
            i4_ref_yD = i4_y0 - i4_top - (i4_top >> 1);
2690
2691
            /* Copy (x0,ref_yD), (x0+1,ref_yD) to  */
2692
            /* (x0,y0), (x0+1,y0), and (x0,y0+1), (x0+1,y0+1) */
2693
2.19k
            pu1_tmp_src1 = pu1_refarray_luma + (i4_ref_yD * DYADIC_REF_W_Y);
2694
2.19k
            pu1_tmp_dst1 = pu1_refarray_luma + (i4_y0 * DYADIC_REF_W_Y);
2695
2.19k
            pu1_tmp_dst2 = pu1_tmp_dst1 + DYADIC_REF_W_Y;
2696
2.19k
            pu1_tmp_dst1[i4_x0] = pu1_tmp_src1[i4_x0];
2697
2.19k
            pu1_tmp_dst2[i4_x0] = pu1_tmp_src1[i4_x0];
2698
2.19k
            pu1_tmp_dst1[i4_x0 + 1] = pu1_tmp_src1[i4_x0 + 1];
2699
2.19k
            pu1_tmp_dst2[i4_x0 + 1] = pu1_tmp_src1[i4_x0 + 1];
2700
2701
            /* Cb and Cr copy */
2702
2.19k
            i4_xc0 = i4_x0 >> 1;
2703
2.19k
            i4_yc0 = i4_y0 >> 1;
2704
2.19k
            i4_c_ref_yD = i4_ref_yD >> 1;
2705
2.19k
            pu1_tmp_src1 = pu1_refarray_cb + (i4_c_ref_yD * DYADIC_REF_W_C);
2706
2.19k
            pu1_tmp_dst1 = pu1_refarray_cb + (i4_yc0 * DYADIC_REF_W_C);
2707
2.19k
            pu1_tmp_src2 = pu1_refarray_cr + (i4_c_ref_yD * DYADIC_REF_W_C);
2708
2.19k
            pu1_tmp_dst2 = pu1_refarray_cr + (i4_yc0 * DYADIC_REF_W_C);
2709
2.19k
            pu1_tmp_dst1[i4_xc0] = pu1_tmp_src1[i4_xc0];
2710
2.19k
            pu1_tmp_dst2[i4_xc0] = pu1_tmp_src2[i4_xc0];
2711
2712
2.19k
        } /* if (mb_x+left,mb_y) available, (mb_x,mb_y+top) unavailable */
2713
45.6k
        else if(0x04 == (u1_ny_avlblty & 0x6))
2714
5.97k
        {
2715
            /* (mb_x+left,mb_y) unavailable, (mb_x,mb_y+top) available */
2716
5.97k
            i4_x0 = 9 + (i4_left << 3) + i4_left;
2717
5.97k
            i4_y0 = 9 + (i4_top << 3) + i4_top;
2718
5.97k
            i4_ref_xD = i4_x0 - i4_left - (i4_left >> 1);
2719
2720
            /* Copy (ref_xD,y0) to (x0,y0) and (x0+1,y0) */
2721
            /* copy (ref_xD,y0+1) to (x0,y0+1) and (x0+1,y0+1) */
2722
5.97k
            pu1_tmp_src1 = pu1_refarray_luma + (i4_y0 * DYADIC_REF_W_Y);
2723
5.97k
            pu1_tmp_dst1 = pu1_tmp_src1;
2724
5.97k
            pu1_tmp_src2 = pu1_tmp_src1 + DYADIC_REF_W_Y;
2725
5.97k
            pu1_tmp_dst2 = pu1_tmp_src2;
2726
2727
5.97k
            pu1_tmp_dst1[i4_x0] = pu1_tmp_src1[i4_ref_xD];
2728
5.97k
            pu1_tmp_dst1[i4_x0 + 1] = pu1_tmp_src1[i4_ref_xD];
2729
5.97k
            pu1_tmp_dst2[i4_x0] = pu1_tmp_src2[i4_ref_xD];
2730
5.97k
            pu1_tmp_dst2[i4_x0 + 1] = pu1_tmp_src2[i4_ref_xD];
2731
2732
            /* Copy Cb and Cr */
2733
5.97k
            i4_xc0 = i4_x0 >> 1;
2734
5.97k
            i4_yc0 = i4_y0 >> 1;
2735
5.97k
            i4_c_ref_xD = i4_ref_xD >> 1;
2736
2737
5.97k
            pu1_tmp_src1 = pu1_refarray_cb + (i4_yc0 * DYADIC_REF_W_C);
2738
5.97k
            pu1_tmp_dst1 = pu1_tmp_src1;
2739
5.97k
            pu1_tmp_src2 = pu1_refarray_cr + (i4_yc0 * DYADIC_REF_W_C);
2740
5.97k
            pu1_tmp_dst2 = pu1_tmp_src2;
2741
2742
5.97k
            pu1_tmp_dst1[i4_xc0] = pu1_tmp_src1[i4_c_ref_xD];
2743
5.97k
            pu1_tmp_dst2[i4_xc0] = pu1_tmp_src2[i4_c_ref_xD];
2744
2745
5.97k
        } /* if (mb_x+left,mb_y) unavailable, (mb_x,mb_y+top) available */
2746
39.6k
        else if(0x6 == (u1_ny_avlblty & 0x6))
2747
3.59k
        {
2748
            /* (mb_x+left,mb_y) available, (mb_x,mb_y+top) available */
2749
3.59k
            WORD32 i4_xD, i4_yD;
2750
3.59k
            WORD32 i4_c_xD, i4_c_yD;
2751
2752
3.59k
            i4_y0 = 9 + (i4_top << 3) + i4_top;
2753
3.59k
            i4_x0 = 9 + (i4_left << 3) + i4_left;
2754
3.59k
            i4_ref_xD = i4_x0 - i4_left - (i4_left >> 1);
2755
3.59k
            i4_ref_yD = i4_y0 - i4_top - (i4_top >> 1);
2756
3.59k
            i4_xD = i4_x0 - i4_ref_xD;
2757
3.59k
            i4_yD = i4_y0 - i4_ref_yD;
2758
3.59k
            i4_xc0 = i4_x0 >> 1;
2759
3.59k
            i4_yc0 = i4_y0 >> 1;
2760
3.59k
            i4_c_ref_xD = i4_ref_xD >> 1;
2761
3.59k
            i4_c_ref_yD = i4_ref_yD >> 1;
2762
3.59k
            i4_c_xD = i4_xc0 - i4_c_ref_xD;
2763
3.59k
            i4_c_yD = i4_yc0 - i4_c_ref_yD;
2764
2765
            /* Call diagonal construction for luma */
2766
10.7k
            for(i4_y = i4_y0; i4_y < i4_y0 + 2; i4_y++)
2767
7.19k
            {
2768
21.5k
                for(i4_x = i4_x0; i4_x < i4_x0 + 2; i4_x++)
2769
14.3k
                {
2770
14.3k
                    isvcd_diagonal_construct_dyadic(i4_x, i4_y, i4_xD, i4_yD, pu1_refarray_luma,
2771
14.3k
                                                    DYADIC_REF_W_Y);
2772
14.3k
                    i4_xD++;
2773
14.3k
                }
2774
7.19k
                i4_yD++;
2775
7.19k
                i4_xD -= 2;
2776
7.19k
            }
2777
2778
            /* Call diagonal construction for chroma */
2779
3.59k
            isvcd_diagonal_construct_dyadic(i4_xc0, i4_yc0, i4_c_xD, i4_c_yD, pu1_refarray_cb,
2780
3.59k
                                            DYADIC_REF_W_C);
2781
2782
3.59k
            isvcd_diagonal_construct_dyadic(i4_xc0, i4_yc0, i4_c_xD, i4_c_yD, pu1_refarray_cr,
2783
3.59k
                                            DYADIC_REF_W_C);
2784
2785
3.59k
        } /* if (mb_x+left,mb_y) available, (mb_x,mb_y+top) available */
2786
47.8k
    }     /* (mb_x+left,mb_y+top) available */
2787
2788
55.9k
    return OK;
2789
56.2k
}
2790
/*****************************************************************************/
2791
/*                                                                           */
2792
/*  Function Name : isvcd_interpolate_base_luma_dyadic                        */
2793
/*                                                                           */
2794
/*  Description   : This function takes the reference array buffer & performs*/
2795
/*                  intra resampling for dyadic scaling ratios               */
2796
/*  Inputs        : pu1_inp_buf : ptr to the 12x12 reference sample buffer   */
2797
/*                    pi2_tmp_filt_buf : ptr to the 12x16 buffer to hold the */
2798
/*                        vertically interpolated data                       */
2799
/*                  pu1_out_buf : output buffer pointer                      */
2800
/*                  i4_out_stride : output buffer stride                     */
2801
/*  Globals       : none                                                     */
2802
/*  Processing    : it does the interpolation in vertical direction followed */
2803
/*                  by horizontal direction                                  */
2804
/*  Outputs       : resampled pixels                                         */
2805
/*  Returns       : none                                                     */
2806
/*                                                                           */
2807
/*  Issues        : none                                                     */
2808
/*                                                                           */
2809
/*  Revision History:                                                        */
2810
/*                                                                           */
2811
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
2812
/*         06 09 2021   Vijay           creation                             */
2813
/*                                                                           */
2814
/*****************************************************************************/
2815
void isvcd_interpolate_base_luma_dyadic(UWORD8 *pu1_inp_buf, WORD16 *pi2_tmp_filt_buf,
2816
                                        UWORD8 *pu1_out_buf, WORD32 i4_out_stride)
2817
35.5k
{
2818
35.5k
    WORD32 i4_x, i4_y;
2819
35.5k
    WORD32 i4_coeff_0, i4_coeff_1, i4_coeff_2, i4_coeff_3;
2820
35.5k
    WORD32 i4_samp_0, i4_samp_1, i4_samp_2, i4_samp_3;
2821
35.5k
    WORD32 i4_rslt_1, i4_rslt_2;
2822
35.5k
    WORD32 i4_filt_stride, i4_src_stride;
2823
35.5k
    UWORD8 *pu1_inp, *pu1_out;
2824
35.5k
    WORD16 *pi2_tmp;
2825
2826
    /* Filter coefficient values for phase 4 */
2827
35.5k
    i4_coeff_0 = -3;
2828
35.5k
    i4_coeff_1 = 28;
2829
35.5k
    i4_coeff_2 = 8;
2830
35.5k
    i4_coeff_3 = -1;
2831
35.5k
    i4_filt_stride = 12;
2832
35.5k
    i4_src_stride = DYADIC_REF_W_Y;
2833
35.5k
    pu1_inp = pu1_inp_buf;
2834
35.5k
    pi2_tmp = pi2_tmp_filt_buf;
2835
35.5k
    pu1_out = pu1_out_buf;
2836
2837
    /* Vertical interpolation */
2838
461k
    for(i4_x = 0; i4_x < 12; i4_x++)
2839
426k
    {
2840
        /* y = 0, y_phase = 12 */
2841
426k
        i4_samp_0 = pu1_inp[i4_x];
2842
426k
        pu1_inp += i4_src_stride;
2843
426k
        i4_samp_1 = pu1_inp[i4_x];
2844
426k
        pu1_inp += i4_src_stride;
2845
426k
        i4_samp_2 = pu1_inp[i4_x];
2846
426k
        pu1_inp += i4_src_stride;
2847
426k
        i4_samp_3 = pu1_inp[i4_x];
2848
426k
        pu1_inp += i4_src_stride;
2849
2850
        /* since y_phase 12 for y = 0 */
2851
426k
        i4_rslt_1 = i4_samp_0 * i4_coeff_3;
2852
426k
        i4_rslt_1 += i4_samp_1 * i4_coeff_2;
2853
426k
        i4_rslt_1 += i4_samp_2 * i4_coeff_1;
2854
426k
        i4_rslt_1 += i4_samp_3 * i4_coeff_0;
2855
2856
        /* Store the output */
2857
426k
        pi2_tmp[i4_x] = i4_rslt_1;
2858
        /* Increment the output ptr */
2859
426k
        pi2_tmp += i4_filt_stride;
2860
2861
3.41M
        for(i4_y = 1; i4_y < 15; i4_y += 2)
2862
2.98M
        {
2863
2.98M
            i4_samp_0 = i4_samp_1;
2864
2.98M
            i4_samp_1 = i4_samp_2;
2865
2.98M
            i4_samp_2 = i4_samp_3;
2866
2.98M
            i4_samp_3 = pu1_inp[i4_x];
2867
2868
            /* y_phase is 4 for odd values of y */
2869
            /* and 12 for even values of y    */
2870
2.98M
            i4_rslt_1 = i4_samp_0 * i4_coeff_0;
2871
2.98M
            i4_rslt_1 += i4_samp_1 * i4_coeff_1;
2872
2.98M
            i4_rslt_1 += i4_samp_2 * i4_coeff_2;
2873
2.98M
            i4_rslt_1 += i4_samp_3 * i4_coeff_3;
2874
2.98M
            i4_rslt_2 = i4_samp_0 * i4_coeff_3;
2875
2.98M
            i4_rslt_2 += i4_samp_1 * i4_coeff_2;
2876
2.98M
            i4_rslt_2 += i4_samp_2 * i4_coeff_1;
2877
2.98M
            i4_rslt_2 += i4_samp_3 * i4_coeff_0;
2878
2879
            /* Storing the results */
2880
2.98M
            pi2_tmp[i4_x] = i4_rslt_1;
2881
2.98M
            pi2_tmp += i4_filt_stride;
2882
2.98M
            pi2_tmp[i4_x] = i4_rslt_2;
2883
2884
            /* Incrementing the pointers */
2885
2.98M
            pi2_tmp += i4_filt_stride;
2886
2.98M
            pu1_inp += i4_src_stride;
2887
2888
2.98M
        } /* End of loop over y */
2889
2890
        /* y = 15, y_phase = 4 */
2891
426k
        i4_samp_0 = i4_samp_1;
2892
426k
        i4_samp_1 = i4_samp_2;
2893
426k
        i4_samp_2 = i4_samp_3;
2894
426k
        i4_samp_3 = pu1_inp[i4_x];
2895
2896
426k
        i4_rslt_1 = i4_samp_0 * i4_coeff_0;
2897
426k
        i4_rslt_1 += i4_samp_1 * i4_coeff_1;
2898
426k
        i4_rslt_1 += i4_samp_2 * i4_coeff_2;
2899
426k
        i4_rslt_1 += i4_samp_3 * i4_coeff_3;
2900
2901
        /* Store the output */
2902
426k
        pi2_tmp[i4_x] = i4_rslt_1;
2903
2904
        /* Reinitializing the ptrs */
2905
426k
        pu1_inp = pu1_inp_buf;
2906
426k
        pi2_tmp = pi2_tmp_filt_buf;
2907
426k
    }
2908
2909
    /* Horizontal interpolation */
2910
604k
    for(i4_y = 0; i4_y < 16; i4_y++)
2911
568k
    {
2912
        /* x = 0, x_phase = 12 */
2913
568k
        i4_samp_0 = *pi2_tmp++;
2914
568k
        i4_samp_1 = *pi2_tmp++;
2915
568k
        i4_samp_2 = *pi2_tmp++;
2916
568k
        i4_samp_3 = *pi2_tmp++;
2917
2918
        /* since x_phase 12 for x = 0 */
2919
568k
        i4_rslt_1 = i4_samp_0 * i4_coeff_3;
2920
568k
        i4_rslt_1 += i4_samp_1 * i4_coeff_2;
2921
568k
        i4_rslt_1 += i4_samp_2 * i4_coeff_1;
2922
568k
        i4_rslt_1 += i4_samp_3 * i4_coeff_0;
2923
568k
        i4_rslt_1 += 512;
2924
2925
568k
        i4_rslt_1 >>= 10;
2926
2927
        /* Store the output */
2928
568k
        pu1_out[0] = CLIPUCHAR(i4_rslt_1);
2929
2930
4.54M
        for(i4_x = 1; i4_x < 15; i4_x += 2)
2931
3.98M
        {
2932
3.98M
            i4_samp_0 = i4_samp_1;
2933
3.98M
            i4_samp_1 = i4_samp_2;
2934
3.98M
            i4_samp_2 = i4_samp_3;
2935
3.98M
            i4_samp_3 = *pi2_tmp++;
2936
2937
            /* x_phase is 4 for odd values of x */
2938
            /* and 12 for even values of x    */
2939
3.98M
            i4_rslt_1 = i4_samp_0 * i4_coeff_0;
2940
3.98M
            i4_rslt_1 += i4_samp_1 * i4_coeff_1;
2941
3.98M
            i4_rslt_1 += i4_samp_2 * i4_coeff_2;
2942
3.98M
            i4_rslt_1 += i4_samp_3 * i4_coeff_3;
2943
3.98M
            i4_rslt_1 += 512;
2944
2945
3.98M
            i4_rslt_2 = i4_samp_0 * i4_coeff_3;
2946
3.98M
            i4_rslt_2 += i4_samp_1 * i4_coeff_2;
2947
3.98M
            i4_rslt_2 += i4_samp_2 * i4_coeff_1;
2948
3.98M
            i4_rslt_2 += i4_samp_3 * i4_coeff_0;
2949
3.98M
            i4_rslt_2 += 512;
2950
2951
3.98M
            i4_rslt_1 >>= 10;
2952
3.98M
            i4_rslt_2 >>= 10;
2953
2954
            /* Store the output */
2955
3.98M
            pu1_out[i4_x] = CLIPUCHAR(i4_rslt_1);
2956
3.98M
            pu1_out[i4_x + 1] = CLIPUCHAR(i4_rslt_2);
2957
3.98M
        }
2958
2959
        /* x = 15 */
2960
568k
        i4_samp_0 = i4_samp_1;
2961
568k
        i4_samp_1 = i4_samp_2;
2962
568k
        i4_samp_2 = i4_samp_3;
2963
568k
        i4_samp_3 = *pi2_tmp++;
2964
2965
568k
        i4_rslt_1 = i4_samp_0 * i4_coeff_0;
2966
568k
        i4_rslt_1 += i4_samp_1 * i4_coeff_1;
2967
568k
        i4_rslt_1 += i4_samp_2 * i4_coeff_2;
2968
568k
        i4_rslt_1 += i4_samp_3 * i4_coeff_3;
2969
568k
        i4_rslt_1 += 512;
2970
2971
568k
        i4_rslt_1 >>= 10;
2972
2973
        /* Store the output */
2974
568k
        pu1_out[i4_x] = CLIPUCHAR(i4_rslt_1);
2975
2976
        /* Increment the output ptr */
2977
568k
        pu1_out += i4_out_stride;
2978
2979
568k
    } /* End of loop over y */
2980
35.5k
} /* isvcd_interpolate_base_luma_dyadic */
2981
2982
/*****************************************************************************/
2983
/*                                                                           */
2984
/*  Function Name : isvcd_vert_interpol_chroma_dyadic_1                       */
2985
/*                                                                           */
2986
/*  Description   : This function takes the reference array buffer & performs*/
2987
/*                  vertical intra resampling for dyadic scaling ratios for  */
2988
/*                    chroma for the following ref_lyr_chroma_phase_y_plus1  */
2989
/*                    chroma_phase_y_plus1:                                  */
2990
/*                        ref_lyr        cur_lyr                             */
2991
/*                            0            0                                 */
2992
/*                            1            0                                 */
2993
/*                            1            1                                 */
2994
/*                            1            2                                 */
2995
/*                            2            1                                 */
2996
/*                            2            2                                 */
2997
/*  Inputs        : pu1_inp_buf : ptr to the 6x6 reference sample buffer     */
2998
/*                    pi2_tmp_filt_buf : ptr to the 6x8 buffer to hold the   */
2999
/*                        vertically interpolated data                       */
3000
/*                    i4_phase_0 : y phase for even values of y              */
3001
/*                    i4_phase_1 : y phase for odd values of y               */
3002
/*  Globals       : none                                                     */
3003
/*  Processing    : it does the interpolation in vertical direction          */
3004
/*  Outputs       : vertically resampled samples                             */
3005
/*  Returns       : none                                                     */
3006
/*                                                                           */
3007
/*  Issues        : none                                                     */
3008
/*                                                                           */
3009
/*  Revision History:                                                        */
3010
/*                                                                           */
3011
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
3012
/*         06 09 2021   Vijay           creation                             */
3013
/*                                                                           */
3014
/*****************************************************************************/
3015
void isvcd_vert_interpol_chroma_dyadic_1(UWORD8 *pu1_inp_buf, WORD16 *pi2_tmp_filt_buf,
3016
                                         WORD32 i4_phase_0, WORD32 i4_phase_1)
3017
68.1k
{
3018
68.1k
    WORD32 i4_x, i4_y;
3019
68.1k
    WORD32 i4_coeff_0, i4_coeff_1, i4_coeff_2, i4_coeff_3;
3020
68.1k
    WORD32 i4_samp_0, i4_samp_1;
3021
68.1k
    WORD32 i4_rslt_1, i4_rslt_2;
3022
68.1k
    WORD32 i4_filt_stride, i4_src_stride;
3023
68.1k
    UWORD8 *pu1_inp;
3024
68.1k
    WORD16 *pi2_tmp;
3025
3026
68.1k
    i4_coeff_0 = 8 - i4_phase_0;
3027
68.1k
    i4_coeff_1 = i4_phase_0;
3028
68.1k
    i4_coeff_2 = 8 - i4_phase_1;
3029
68.1k
    i4_coeff_3 = i4_phase_1;
3030
3031
68.1k
    pu1_inp = pu1_inp_buf;
3032
68.1k
    pi2_tmp = pi2_tmp_filt_buf;
3033
68.1k
    i4_filt_stride = 6;
3034
68.1k
    i4_src_stride = DYADIC_REF_W_C;
3035
3036
    /* Vertical interpolation */
3037
477k
    for(i4_x = 0; i4_x < 6; i4_x++)
3038
409k
    {
3039
        /* y = 0, y_phase = phase_0 */
3040
409k
        i4_samp_0 = pu1_inp[i4_x];
3041
409k
        pu1_inp += i4_src_stride;
3042
409k
        i4_samp_1 = pu1_inp[i4_x];
3043
409k
        pu1_inp += i4_src_stride;
3044
3045
        /* since y_phase = phase_0 for y = 0 */
3046
409k
        i4_rslt_1 = i4_samp_0 * i4_coeff_0;
3047
409k
        i4_rslt_1 += i4_samp_1 * i4_coeff_1;
3048
3049
        /* Store the output */
3050
409k
        pi2_tmp[i4_x] = i4_rslt_1;
3051
3052
        /* Increment the output ptr */
3053
409k
        pi2_tmp += i4_filt_stride;
3054
3055
1.63M
        for(i4_y = 1; i4_y < 7; i4_y += 2)
3056
1.22M
        {
3057
1.22M
            i4_samp_0 = i4_samp_1;
3058
1.22M
            i4_samp_1 = pu1_inp[i4_x];
3059
3060
            /* y_phase is phase_1 for odd values of y */
3061
            /* and phase_0 for even values of y          */
3062
1.22M
            i4_rslt_1 = i4_samp_0 * i4_coeff_2;
3063
1.22M
            i4_rslt_1 += i4_samp_1 * i4_coeff_3;
3064
1.22M
            i4_rslt_2 = i4_samp_0 * i4_coeff_0;
3065
1.22M
            i4_rslt_2 += i4_samp_1 * i4_coeff_1;
3066
3067
            /* Storing the results */
3068
1.22M
            pi2_tmp[i4_x] = i4_rslt_1;
3069
1.22M
            pi2_tmp += i4_filt_stride;
3070
1.22M
            pi2_tmp[i4_x] = i4_rslt_2;
3071
3072
            /* Incrementing the pointers */
3073
1.22M
            pi2_tmp += i4_filt_stride;
3074
1.22M
            pu1_inp += i4_src_stride;
3075
3076
1.22M
        } /* End of loop over y */
3077
3078
        /* y = 7, y_phase = phase_1 */
3079
409k
        i4_samp_0 = i4_samp_1;
3080
409k
        i4_samp_1 = pu1_inp[i4_x];
3081
3082
409k
        i4_rslt_1 = i4_samp_0 * i4_coeff_2;
3083
409k
        i4_rslt_1 += i4_samp_1 * i4_coeff_3;
3084
3085
        /* Store the output */
3086
409k
        pi2_tmp[i4_x] = i4_rslt_1;
3087
3088
        /* Reinitializing the ptrs */
3089
409k
        pu1_inp = pu1_inp_buf;
3090
409k
        pi2_tmp = pi2_tmp_filt_buf;
3091
3092
409k
    } /* End of loop over x */
3093
68.1k
} /* isvcd_vert_interpol_chroma_dyadic_1 */
3094
3095
/*****************************************************************************/
3096
/*                                                                           */
3097
/*  Function Name : isvcd_vert_interpol_chroma_dyadic_2                       */
3098
/*                                                                           */
3099
/*  Description   : This function takes the reference array buffer & performs*/
3100
/*                  vertical intra resampling for dyadic scaling ratios for  */
3101
/*                    chroma for the following ref_lyr_chroma_phase_y_plus1  */
3102
/*                    chroma_phase_y_plus1:                                  */
3103
/*                        ref_lyr        cur_lyr                             */
3104
/*                            0            1                                 */
3105
/*                            0            2                                 */
3106
/*  Inputs        : pu1_inp_buf : ptr to the 6x6 reference sample buffer     */
3107
/*                    pi2_tmp_filt_buf : ptr to the 6x8 buffer to hold the   */
3108
/*                        vertically interpolated data                       */
3109
/*                    i4_phase_0 : y phase for even values of y              */
3110
/*                    i4_phase_1 : y phase for odd values of y               */
3111
/*  Globals       : none                                                     */
3112
/*  Processing    : it does the interpolation in vertical direction          */
3113
/*  Outputs       : vertically resampled samples                             */
3114
/*  Returns       : none                                                     */
3115
/*                                                                           */
3116
/*  Issues        : none                                                     */
3117
/*                                                                           */
3118
/*  Revision History:                                                        */
3119
/*                                                                           */
3120
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
3121
/*         06 09 2021   Vijay           creation                             */
3122
/*                                                                           */
3123
/*****************************************************************************/
3124
void isvcd_vert_interpol_chroma_dyadic_2(UWORD8 *pu1_inp_buf, WORD16 *pi2_tmp_filt_buf,
3125
                                         WORD32 i4_phase_0, WORD32 i4_phase_1)
3126
1.42k
{
3127
1.42k
    WORD32 i4_x, i4_y;
3128
1.42k
    WORD32 i4_coeff_0, i4_coeff_1, i4_coeff_2, i4_coeff_3;
3129
1.42k
    WORD32 i4_samp_0, i4_samp_1;
3130
1.42k
    WORD32 i4_rslt_1, i4_rslt_2;
3131
1.42k
    WORD32 i4_filt_stride, i4_src_stride;
3132
1.42k
    UWORD8 *pu1_inp;
3133
1.42k
    WORD16 *pi2_tmp;
3134
3135
1.42k
    i4_coeff_0 = 8 - i4_phase_0;
3136
1.42k
    i4_coeff_1 = i4_phase_0;
3137
1.42k
    i4_coeff_2 = 8 - i4_phase_1;
3138
1.42k
    i4_coeff_3 = i4_phase_1;
3139
3140
1.42k
    pi2_tmp = pi2_tmp_filt_buf;
3141
1.42k
    i4_filt_stride = 6;
3142
1.42k
    i4_src_stride = DYADIC_REF_W_C;
3143
1.42k
    pu1_inp = pu1_inp_buf + i4_src_stride;
3144
3145
    /* Vertical interpolation */
3146
9.98k
    for(i4_x = 0; i4_x < 6; i4_x++)
3147
8.55k
    {
3148
8.55k
        i4_samp_1 = pu1_inp[i4_x];
3149
8.55k
        pu1_inp += i4_src_stride;
3150
3151
42.7k
        for(i4_y = 0; i4_y < 8; i4_y += 2)
3152
34.2k
        {
3153
34.2k
            i4_samp_0 = i4_samp_1;
3154
34.2k
            i4_samp_1 = pu1_inp[i4_x];
3155
3156
            /* y_phase is phase_1 for odd values of y and phase_0 for even values of y */
3157
34.2k
            i4_rslt_1 = i4_samp_0 * i4_coeff_0;
3158
34.2k
            i4_rslt_1 += i4_samp_1 * i4_coeff_1;
3159
3160
34.2k
            i4_rslt_2 = i4_samp_0 * i4_coeff_2;
3161
34.2k
            i4_rslt_2 += i4_samp_1 * i4_coeff_3;
3162
3163
            /* Storing the results */
3164
34.2k
            pi2_tmp[i4_x] = i4_rslt_1;
3165
34.2k
            pi2_tmp += i4_filt_stride;
3166
34.2k
            pi2_tmp[i4_x] = i4_rslt_2;
3167
3168
            /* Incrementing the pointers */
3169
34.2k
            pi2_tmp += i4_filt_stride;
3170
34.2k
            pu1_inp += i4_src_stride;
3171
3172
34.2k
        } /* End of loop over y */
3173
3174
        /* Reinitializing the ptrs */
3175
8.55k
        pu1_inp = pu1_inp_buf + i4_src_stride;
3176
8.55k
        pi2_tmp = pi2_tmp_filt_buf;
3177
3178
8.55k
    } /* End of loop over x */
3179
1.42k
} /* isvcd_vert_interpol_chroma_dyadic_2 */
3180
3181
/*****************************************************************************/
3182
/*                                                                           */
3183
/*  Function Name : isvcd_vert_interpol_chroma_dyadic_3                       */
3184
/*                                                                           */
3185
/*  Description   : This function takes the reference array buffer & performs*/
3186
/*                  vertical intra resampling for dyadic scaling ratios for  */
3187
/*                    chroma for the following ref_lyr_chroma_phase_y_plus1  */
3188
/*                    chroma_phase_y_plus1:                                  */
3189
/*                        ref_lyr        cur_lyr                             */
3190
/*                            2            0                                 */
3191
/*  Inputs        : pu1_inp_buf : ptr to the 6x6 reference sample buffer     */
3192
/*                    pi2_tmp_filt_buf : ptr to the 6x8 buffer to hold the   */
3193
/*                        vertically interpolated data                       */
3194
/*                    i4_phase_0 : y phase for even values of y              */
3195
/*                    i4_phase_1 : y phase for odd values of y               */
3196
/*  Globals       : none                                                     */
3197
/*  Processing    : it does the interpolation in vertical direction          */
3198
/*  Outputs       : vertically resampled samples                             */
3199
/*  Returns       : none                                                     */
3200
/*                                                                           */
3201
/*  Issues        : none                                                     */
3202
/*                                                                           */
3203
/*  Revision History:                                                        */
3204
/*                                                                           */
3205
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
3206
/*         06 09 2021   Vijay           creation                             */
3207
/*                                                                           */
3208
/*****************************************************************************/
3209
void isvcd_vert_interpol_chroma_dyadic_3(UWORD8 *pu1_inp_buf, WORD16 *pi2_tmp_filt_buf,
3210
                                         WORD32 i4_phase_0, WORD32 i4_phase_1)
3211
1.47k
{
3212
1.47k
    WORD32 i4_x, i4_y;
3213
1.47k
    WORD32 i4_coeff_0, i4_coeff_1, i4_coeff_2, i4_coeff_3;
3214
1.47k
    WORD32 i4_samp_0, i4_samp_1;
3215
1.47k
    WORD32 i4_rslt_1, i4_rslt_2;
3216
1.47k
    WORD32 i4_filt_stride, i4_src_stride;
3217
1.47k
    UWORD8 *pu1_inp;
3218
1.47k
    WORD16 *pi2_tmp;
3219
3220
1.47k
    i4_coeff_0 = 8 - i4_phase_0;
3221
1.47k
    i4_coeff_1 = i4_phase_0;
3222
1.47k
    i4_coeff_2 = 8 - i4_phase_1;
3223
1.47k
    i4_coeff_3 = i4_phase_1;
3224
3225
1.47k
    pi2_tmp = pi2_tmp_filt_buf;
3226
1.47k
    i4_filt_stride = 6;
3227
1.47k
    i4_src_stride = DYADIC_REF_W_C;
3228
1.47k
    pu1_inp = pu1_inp_buf;
3229
3230
    /* Vertical interpolation */
3231
10.3k
    for(i4_x = 0; i4_x < 6; i4_x++)
3232
8.84k
    {
3233
8.84k
        i4_samp_1 = pu1_inp[i4_x];
3234
8.84k
        pu1_inp += i4_src_stride;
3235
3236
44.2k
        for(i4_y = 0; i4_y < 8; i4_y += 2)
3237
35.3k
        {
3238
35.3k
            i4_samp_0 = i4_samp_1;
3239
35.3k
            i4_samp_1 = pu1_inp[i4_x];
3240
3241
            /* y_phase is phase_1 for odd values of y */
3242
            /* and phase_0 for even values of y          */
3243
35.3k
            i4_rslt_1 = i4_samp_0 * i4_coeff_0;
3244
35.3k
            i4_rslt_1 += i4_samp_1 * i4_coeff_1;
3245
3246
35.3k
            i4_rslt_2 = i4_samp_0 * i4_coeff_2;
3247
35.3k
            i4_rslt_2 += i4_samp_1 * i4_coeff_3;
3248
3249
            /* Storing the results */
3250
35.3k
            pi2_tmp[i4_x] = i4_rslt_1;
3251
35.3k
            pi2_tmp += i4_filt_stride;
3252
35.3k
            pi2_tmp[i4_x] = i4_rslt_2;
3253
3254
            /* Incrementing the pointers */
3255
35.3k
            pi2_tmp += i4_filt_stride;
3256
35.3k
            pu1_inp += i4_src_stride;
3257
3258
35.3k
        } /* End of loop over y */
3259
3260
        /* Reinitializing the ptrs */
3261
8.84k
        pu1_inp = pu1_inp_buf;
3262
8.84k
        pi2_tmp = pi2_tmp_filt_buf;
3263
3264
8.84k
    } /* End of loop over x */
3265
1.47k
} /* isvcd_vert_interpol_chroma_dyadic_3 */
3266
3267
/*****************************************************************************/
3268
/*                                                                           */
3269
/*  Function Name : isvcd_horz_interpol_chroma_dyadic_1                       */
3270
/*                                                                           */
3271
/*  Description   : This function takes the reference array buffer & performs*/
3272
/*                  horizontal intra resampling for dyadic scaling ratios for*/
3273
/*                    chroma with following ref_lyr_chroma_phase_x_plus1_flag*/
3274
/*                    and chroma_phase_x_plus1_flag:                         */
3275
/*                        ref_lyr        cur_lyr                             */
3276
/*                            0            0                                 */
3277
/*                            1            0                                 */
3278
/*                            1            1                                 */
3279
/*  Inputs        : pi2_tmp_filt_buf : ptr to the 6x8 buffer containing the  */
3280
/*                        vertically interpolated data                       */
3281
/*                    pu1_out_buf : pointer to the output buffer             */
3282
/*                    i4_out_stride : output buffer stride                   */
3283
/*                    i4_phase_0 : x phase for even values of x              */
3284
/*                    i4_phase_1 : x phase for odd values of x               */
3285
/*  Globals       : none                                                     */
3286
/*  Processing    : it does the interpolation in vertical direction          */
3287
/*  Outputs       : resampled samples                                        */
3288
/*  Returns       : none                                                     */
3289
/*                                                                           */
3290
/*  Issues        : none                                                     */
3291
/*                                                                           */
3292
/*  Revision History:                                                        */
3293
/*                                                                           */
3294
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
3295
/*         06 09 2021   Vijay           creation                             */
3296
/*                                                                           */
3297
/*****************************************************************************/
3298
void isvcd_horz_interpol_chroma_dyadic_1(WORD16 *pi2_tmp_filt_buf, UWORD8 *pu1_out_buf,
3299
                                         WORD32 i4_out_stride, WORD32 i4_phase_0, WORD32 i4_phase_1)
3300
42.9k
{
3301
42.9k
    WORD32 i4_x, i4_y;
3302
42.9k
    WORD32 i4_coeff_0, i4_coeff_1, i4_coeff_2, i4_coeff_3;
3303
42.9k
    WORD32 i4_samp_0, i4_samp_1;
3304
42.9k
    WORD32 i4_rslt_1, i4_rslt_2;
3305
42.9k
    WORD32 i4_dst_stride;
3306
42.9k
    UWORD8 *pu1_out;
3307
42.9k
    WORD16 *pi2_tmp;
3308
3309
42.9k
    i4_coeff_0 = 8 - i4_phase_0;
3310
42.9k
    i4_coeff_1 = i4_phase_0;
3311
42.9k
    i4_coeff_2 = 8 - i4_phase_1;
3312
42.9k
    i4_coeff_3 = i4_phase_1;
3313
3314
42.9k
    pu1_out = pu1_out_buf;
3315
42.9k
    pi2_tmp = pi2_tmp_filt_buf;
3316
42.9k
    i4_dst_stride = i4_out_stride;
3317
3318
    /* Horizontal interpolation */
3319
386k
    for(i4_y = 0; i4_y < 8; i4_y++)
3320
343k
    {
3321
        /* x = 0, x_phase = phase_0 */
3322
343k
        i4_samp_0 = *pi2_tmp++;
3323
343k
        i4_samp_1 = *pi2_tmp++;
3324
3325
        /* since x_phase = phase_0 for x = 0 */
3326
343k
        i4_rslt_1 = i4_samp_0 * i4_coeff_0;
3327
343k
        i4_rslt_1 += i4_samp_1 * i4_coeff_1;
3328
3329
        /* Round to 8-bit value */
3330
343k
        i4_rslt_1 += 32;
3331
343k
        i4_rslt_1 >>= 6;
3332
3333
        /* Store the output */
3334
343k
        pu1_out[0] = i4_rslt_1;
3335
3336
1.37M
        for(i4_x = 1; i4_x < 7; i4_x += 2)
3337
1.03M
        {
3338
1.03M
            i4_samp_0 = i4_samp_1;
3339
1.03M
            i4_samp_1 = *pi2_tmp++;
3340
3341
            /* x_phase is phase_1 for odd values of x and phase_0 for even values of x */
3342
1.03M
            i4_rslt_1 = i4_samp_0 * i4_coeff_2;
3343
1.03M
            i4_rslt_1 += i4_samp_1 * i4_coeff_3;
3344
1.03M
            i4_rslt_2 = i4_samp_0 * i4_coeff_0;
3345
1.03M
            i4_rslt_2 += i4_samp_1 * i4_coeff_1;
3346
3347
            /* Rounding to 8-bit values */
3348
1.03M
            i4_rslt_1 += 32;
3349
1.03M
            i4_rslt_1 >>= 6;
3350
1.03M
            i4_rslt_2 += 32;
3351
1.03M
            i4_rslt_2 >>= 6;
3352
3353
            /* Storing the results */
3354
1.03M
            pu1_out[2 * i4_x] = i4_rslt_1;
3355
1.03M
            pu1_out[2 * (i4_x + 1)] = i4_rslt_2;
3356
3357
1.03M
        } /* End of loop over y */
3358
3359
        /* y = 7, y_phase = phase_1 */
3360
343k
        i4_samp_0 = i4_samp_1;
3361
343k
        i4_samp_1 = *pi2_tmp++;
3362
3363
        /* since x_phase = phase_1 for x = 7 */
3364
343k
        i4_rslt_1 = i4_samp_0 * i4_coeff_2;
3365
343k
        i4_rslt_1 += i4_samp_1 * i4_coeff_3;
3366
3367
        /* Round to 8-bit value */
3368
343k
        i4_rslt_1 += 32;
3369
343k
        i4_rslt_1 >>= 6;
3370
3371
        /* Store the output */
3372
343k
        pu1_out[2 * 7] = i4_rslt_1;
3373
3374
        /* Incrementing the output ptr */
3375
343k
        pu1_out += i4_dst_stride;
3376
3377
343k
    } /* End of loop over x */
3378
42.9k
} /* isvcd_horz_interpol_chroma_dyadic_1 */
3379
3380
/*****************************************************************************/
3381
/*                                                                           */
3382
/*  Function Name : isvcd_horz_interpol_chroma_dyadic_2                       */
3383
/*                                                                           */
3384
/*  Description   : This function takes the reference array buffer & performs*/
3385
/*                  horizontal intra resampling for dyadic scaling ratios for*/
3386
/*                    chroma with following ref_lyr_chroma_phase_x_plus1_flag*/
3387
/*                    and chroma_phase_x_plus1_flag:                         */
3388
/*                        ref_lyr        cur_lyr                             */
3389
/*                            0            1                                 */
3390
/*  Inputs        : pi2_tmp_filt_buf : ptr to the 6x8 buffer containing the  */
3391
/*                        vertically interpolated data                       */
3392
/*                    pu1_out_buf : pointer to the output buffer             */
3393
/*                    i4_out_stride : output buffer stride                   */
3394
/*                    i4_phase_0 : x phase for even values of x              */
3395
/*                    i4_phase_1 : x phase for odd values of x               */
3396
/*  Globals       : none                                                     */
3397
/*  Processing    : it does the interpolation in vertical direction          */
3398
/*  Outputs       : resampled samples                                        */
3399
/*  Returns       : none                                                     */
3400
/*                                                                           */
3401
/*  Issues        : none                                                     */
3402
/*                                                                           */
3403
/*  Revision History:                                                        */
3404
/*                                                                           */
3405
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
3406
/*         06 09 2021   Vijay           creation                             */
3407
/*                                                                           */
3408
/*****************************************************************************/
3409
void isvcd_horz_interpol_chroma_dyadic_2(WORD16 *pi2_tmp_filt_buf, UWORD8 *pu1_out_buf,
3410
                                         WORD32 i4_out_stride, WORD32 i4_phase_0, WORD32 i4_phase_1)
3411
28.1k
{
3412
28.1k
    WORD32 i4_x, i4_y;
3413
28.1k
    WORD32 i4_coeff_0, i4_coeff_1, i4_coeff_2, i4_coeff_3;
3414
28.1k
    WORD32 i4_samp_0, i4_samp_1;
3415
28.1k
    WORD32 i4_rslt_1, i4_rslt_2;
3416
28.1k
    WORD32 i4_dst_stride;
3417
28.1k
    UWORD8 *pu1_out;
3418
28.1k
    WORD16 *pi2_tmp;
3419
3420
28.1k
    i4_coeff_0 = 8 - i4_phase_0;
3421
28.1k
    i4_coeff_1 = i4_phase_0;
3422
28.1k
    i4_coeff_2 = 8 - i4_phase_1;
3423
28.1k
    i4_coeff_3 = i4_phase_1;
3424
3425
28.1k
    pu1_out = pu1_out_buf;
3426
28.1k
    pi2_tmp = pi2_tmp_filt_buf + 1;
3427
28.1k
    i4_dst_stride = i4_out_stride;
3428
3429
    /* Horizontal interpolation */
3430
252k
    for(i4_y = 0; i4_y < 8; i4_y++)
3431
224k
    {
3432
        /* x = 0, x_phase = phase_0 */
3433
224k
        i4_samp_1 = *pi2_tmp++;
3434
3435
1.12M
        for(i4_x = 0; i4_x < 8; i4_x += 2)
3436
899k
        {
3437
899k
            i4_samp_0 = i4_samp_1;
3438
899k
            i4_samp_1 = *pi2_tmp++;
3439
3440
            /* x_phase is phase_1 for odd values of x */
3441
            /* and phase_0 for even values of x          */
3442
899k
            i4_rslt_1 = i4_samp_0 * i4_coeff_0;
3443
899k
            i4_rslt_1 += i4_samp_1 * i4_coeff_1;
3444
3445
899k
            i4_rslt_2 = i4_samp_0 * i4_coeff_2;
3446
899k
            i4_rslt_2 += i4_samp_1 * i4_coeff_3;
3447
3448
            /* Rounding to 8-bit values */
3449
899k
            i4_rslt_1 += 32;
3450
899k
            i4_rslt_1 >>= 6;
3451
899k
            i4_rslt_2 += 32;
3452
899k
            i4_rslt_2 >>= 6;
3453
3454
            /* Storing the results */
3455
899k
            pu1_out[2 * i4_x] = i4_rslt_1;
3456
899k
            pu1_out[2 * (i4_x + 1)] = i4_rslt_2;
3457
3458
899k
        } /* End of loop over x */
3459
3460
        /* Incrementing the ptrs */
3461
224k
        pi2_tmp += 1;
3462
224k
        pu1_out += i4_dst_stride;
3463
3464
224k
    } /* End of loop over y */
3465
28.1k
} /* isvcd_horz_interpol_chroma_dyadic_2 */
3466
3467
/*****************************************************************************/
3468
/*                                                                           */
3469
/*  Function Name :  isvcd_intra_resamp_mb_dyadic                               */
3470
/*                                                                           */
3471
/*  Description   : MB level function which performs the intra resampling    */
3472
/*                  of data of an MB (luma and chroma inclusive) for dyadic  */
3473
/*                    scaling ratios                                         */
3474
/*                                                                           */
3475
/*  Inputs        : pv_intra_samp_ctxt : intra sampling context              */
3476
/*                  ps_ref_luma : reference layer luma data buffer desc      */
3477
/*                  ps_ref_chroma : reference layer chroma data buffer desc  */
3478
/*                  ps_ref_mb_mode_map : ref layer mb mode map buff desc     */
3479
/*                  ps_curr_luma : current layer out luma buffer desc        */
3480
/*                  ps_curr_chroma : current layer out chroma buffer desc    */
3481
/*                  x,y : current mb coorinate                               */
3482
/*  Globals       : none                                                     */
3483
/*  Processing    : it calls the reference layer construction followed by    */
3484
/*                   interpolation function for luma and cb and cr           */
3485
/*  Outputs       : inter resampled data of current MB                       */
3486
/*  Returns       : none                                                     */
3487
/*                                                                           */
3488
/*  Issues        : none                                                     */
3489
/*                                                                           */
3490
/*  Revision History:                                                        */
3491
/*                                                                           */
3492
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
3493
/*         06 09 2021   Vijay           creation                             */
3494
/*                                                                           */
3495
/*****************************************************************************/
3496
WORD32 isvcd_intra_resamp_mb_dyadic(void *pv_intra_samp_ctxt, mem_element_t *ps_ref_luma,
3497
                                    mem_element_t *ps_ref_chroma, mem_element_t *ps_ref_mb_mode_map,
3498
                                    mem_element_t *ps_curr_luma, mem_element_t *ps_curr_chroma,
3499
                                    mb_coord_t *ps_mb_coord, void *pv_svc_dec)
3500
56.2k
{
3501
    /* --------------------------------------------------------------------- */
3502
    /* I/O buffer params                                                     */
3503
    /* --------------------------------------------------------------------- */
3504
56.2k
    UWORD8 *pu1_inp_luma, *pu1_inp_chroma;
3505
56.2k
    UWORD8 *pu1_out_luma, *pu1_out_chroma;
3506
56.2k
    UWORD8 *pu1_out_cb, *pu1_out_cr;
3507
56.2k
    UWORD8 *pu1_refarray_luma, *pu1_refarray_cb, *pu1_refarray_cr;
3508
56.2k
    WORD16 *pi2_tmp_filt_buf;
3509
56.2k
    WORD32 i4_inp_luma_stride, i4_inp_chroma_stride;
3510
56.2k
    WORD32 i4_out_luma_stride, i4_out_chroma_stride;
3511
56.2k
    UWORD16 u2_mb_x_ref, u2_mb_y_ref;
3512
56.2k
    svc_dec_lyr_struct_t *ps_svc_lyr_dec = (svc_dec_lyr_struct_t *) pv_svc_dec;
3513
56.2k
    dec_slice_svc_ext_params_t *ps_svc_slice_params = NULL;
3514
3515
    /* --------------------------------------------------------------------- */
3516
    /* Intra resampling ctxt pointers                                         */
3517
    /* --------------------------------------------------------------------- */
3518
56.2k
    intra_sampling_ctxt_t *ps_ctxt;
3519
56.2k
    intra_samp_lyr_ctxt *ps_lyr_ctxt;
3520
3521
    /* --------------------------------------------------------------------- */
3522
    /* reference and current layer MB coordinates                             */
3523
    /* --------------------------------------------------------------------- */
3524
56.2k
    WORD32 i4_scaled_mb_x, i4_scaled_mb_y;
3525
56.2k
    WORD32 i4_top, i4_left;
3526
56.2k
    WORD32 ret;
3527
3528
56.2k
    ps_svc_slice_params = &ps_svc_lyr_dec->s_svc_slice_params;
3529
    /* --------------------------------------------------------------------- */
3530
    /* Pointer derivation                                                     */
3531
    /* --------------------------------------------------------------------- */
3532
56.2k
    ps_ctxt = (intra_sampling_ctxt_t *) pv_intra_samp_ctxt;
3533
56.2k
    ps_lyr_ctxt = &ps_ctxt->as_res_lyrs[ps_ctxt->i4_res_lyr_id];
3534
3535
    /* --------------------------------------------------------------------- */
3536
    /* MB coordinate derivation                                                 */
3537
    /* --------------------------------------------------------------------- */
3538
56.2k
    i4_scaled_mb_x =
3539
56.2k
        ps_mb_coord->u2_mb_x - (ps_svc_slice_params->i4_scaled_ref_layer_left_offset >> 4);
3540
56.2k
    i4_scaled_mb_y =
3541
56.2k
        ps_mb_coord->u2_mb_y - (ps_svc_slice_params->i4_scaled_ref_layer_top_offset >> 4);
3542
3543
56.2k
    if(i4_scaled_mb_x & 0x1)
3544
27.9k
    {
3545
27.9k
        i4_left = 1;
3546
27.9k
    }
3547
28.3k
    else
3548
28.3k
    {
3549
28.3k
        i4_left = -1;
3550
28.3k
    }
3551
56.2k
    if(i4_scaled_mb_y & 0x1)
3552
26.8k
    {
3553
26.8k
        i4_top = 1;
3554
26.8k
    }
3555
29.4k
    else
3556
29.4k
    {
3557
29.4k
        i4_top = -1;
3558
29.4k
    }
3559
3560
56.2k
    u2_mb_x_ref = (i4_scaled_mb_x >> 1);
3561
56.2k
    u2_mb_y_ref = (i4_scaled_mb_y >> 1);
3562
3563
    /* --------------------------------------------------------------------- */
3564
    /* Reference Array Consrtuction - luma and chroma                         */
3565
    /* --------------------------------------------------------------------- */
3566
56.2k
    pu1_inp_luma = (UWORD8 *) ps_ref_luma->pv_buffer;
3567
56.2k
    pu1_inp_chroma = (UWORD8 *) ps_ref_chroma->pv_buffer;
3568
56.2k
    i4_inp_luma_stride = ps_ref_luma->i4_num_element_stride;
3569
56.2k
    i4_inp_chroma_stride = ps_ref_chroma->i4_num_element_stride;
3570
3571
    /* ------- Constructing refSampleArray ----------------------- */
3572
56.2k
    ret = isvcd_reflayer_construction_dyadic(
3573
56.2k
        pv_intra_samp_ctxt, ps_ref_mb_mode_map, pu1_inp_luma, pu1_inp_chroma, i4_inp_luma_stride,
3574
56.2k
        i4_inp_chroma_stride, i4_top, i4_left, u2_mb_x_ref, u2_mb_y_ref);
3575
3576
56.2k
    if(ret != OK)
3577
0
    {
3578
0
        return NOT_OK;
3579
0
    }
3580
    /* --------------------------------------------------------------------- */
3581
    /* LUMA INTERPOLATION                                                       */
3582
    /* --------------------------------------------------------------------- */
3583
56.2k
    pu1_refarray_luma = ps_ctxt->pu1_refarray_buffer;
3584
56.2k
    if(1 == i4_top)
3585
26.8k
    {
3586
26.8k
        pu1_refarray_luma += (DYADIC_REF_W_Y << 3);
3587
26.8k
    }
3588
56.2k
    if(1 == i4_left)
3589
27.9k
    {
3590
27.9k
        pu1_refarray_luma += 8;
3591
27.9k
    }
3592
56.2k
    pu1_out_luma = (UWORD8 *) ps_curr_luma->pv_buffer;
3593
56.2k
    i4_out_luma_stride = ps_curr_luma->i4_num_element_stride;
3594
56.2k
    pi2_tmp_filt_buf = (WORD16 *) ps_ctxt->pi4_temp_interpolation_buffer;
3595
3596
56.2k
    ps_ctxt->pf_interpolate_base_luma_dyadic(pu1_refarray_luma, pi2_tmp_filt_buf, pu1_out_luma,
3597
56.2k
                                             i4_out_luma_stride);
3598
3599
    /* --------------------------------------------------------------------- */
3600
    /* CHROMA INTERPOLATION                                                     */
3601
    /* --------------------------------------------------------------------- */
3602
56.2k
    pu1_out_chroma = (UWORD8 *) ps_curr_chroma->pv_buffer;
3603
56.2k
    i4_out_chroma_stride = ps_curr_chroma->i4_num_element_stride;
3604
3605
    /* CB */
3606
56.2k
    pu1_out_cb = pu1_out_chroma;
3607
56.2k
    pu1_refarray_cb = ps_ctxt->pu1_refarray_cb;
3608
3609
56.2k
    if(1 == i4_top)
3610
26.8k
    {
3611
26.8k
        pu1_refarray_cb += (DYADIC_REF_W_C << 2);
3612
26.8k
    }
3613
56.2k
    if(1 == i4_left)
3614
27.9k
    {
3615
27.9k
        pu1_refarray_cb += 4;
3616
27.9k
    }
3617
3618
    /* Vertical interpolation */
3619
56.2k
    ps_lyr_ctxt->pf_vert_chroma_interpol(pu1_refarray_cb, pi2_tmp_filt_buf,
3620
56.2k
                                         ps_lyr_ctxt->i4_y_phase_0, ps_lyr_ctxt->i4_y_phase_1);
3621
3622
    /* Horizontal interpolation */
3623
56.2k
    ps_lyr_ctxt->pf_horz_chroma_interpol(pi2_tmp_filt_buf, pu1_out_cb, i4_out_chroma_stride,
3624
56.2k
                                         ps_lyr_ctxt->i4_x_phase_0, ps_lyr_ctxt->i4_x_phase_1);
3625
3626
    /* CR */
3627
56.2k
    pu1_out_cr = pu1_out_chroma + 1;
3628
56.2k
    pu1_refarray_cr = ps_ctxt->pu1_refarray_cr;
3629
3630
56.2k
    if(1 == i4_top)
3631
26.8k
    {
3632
26.8k
        pu1_refarray_cr += (DYADIC_REF_W_C << 2);
3633
26.8k
    }
3634
56.2k
    if(1 == i4_left)
3635
27.9k
    {
3636
27.9k
        pu1_refarray_cr += 4;
3637
27.9k
    }
3638
3639
    /* Vertical interpolation */
3640
56.2k
    ps_lyr_ctxt->pf_vert_chroma_interpol(pu1_refarray_cr, pi2_tmp_filt_buf,
3641
56.2k
                                         ps_lyr_ctxt->i4_y_phase_0, ps_lyr_ctxt->i4_y_phase_1);
3642
3643
    /* Horizontal interpolation */
3644
56.2k
    ps_lyr_ctxt->pf_horz_chroma_interpol(pi2_tmp_filt_buf, pu1_out_cr, i4_out_chroma_stride,
3645
56.2k
                                         ps_lyr_ctxt->i4_x_phase_0, ps_lyr_ctxt->i4_x_phase_1);
3646
56.2k
    return OK;
3647
56.2k
}
3648
3649
/*****************************************************************************/
3650
/*                                                                           */
3651
/*  Function Name : isvcd_interpolate_intra_base                              */
3652
/*                                                                           */
3653
/*  Description   : This function takes the reference array buffer & performs*/
3654
/*                    interpolation of a component to find the intra         */
3655
/*                     resampled value                                       */
3656
/*  Inputs        : pv_intra_samp_ctxt : intra sampling context              */
3657
/*                  pu1_out : output buffer pointer                          */
3658
/*                  i4_out_stride : output buffer stride                     */
3659
/*                  i4_refarray_wd : reference array width                   */
3660
/*                  i4_x_offset : offset in reference layer in horz direction*/
3661
/*                  ps_coord : current mb co-ordinate                        */
3662
/*                  i4_chroma_flag : chroma processing flag                  */
3663
/*  Globals       : none                                                     */
3664
/*  Processing    : it does the interpolation in vertical direction followed */
3665
/*                  by horizontal direction                                  */
3666
/*  Outputs       : resampled pixels                                         */
3667
/*  Returns       : none                                                     */
3668
/*                                                                           */
3669
/*  Issues        : none                                                     */
3670
/*                                                                           */
3671
/*  Revision History:                                                        */
3672
/*                                                                           */
3673
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
3674
/*         26 09 2021   vijayakumar          creation                        */
3675
/*                                                                           */
3676
/*****************************************************************************/
3677
void isvcd_interpolate_intra_base(void *pv_intra_samp_ctxt, UWORD8 *pu1_out, WORD32 i4_out_stride,
3678
                                  WORD32 i4_refarray_wd, WORD32 i4_mb_x, WORD32 i4_mb_y,
3679
                                  WORD32 i4_chroma_flag, WORD32 i4_refarray_flag)
3680
74.4k
{
3681
    /* --------------------------------------------------------------------- */
3682
    /* Index Parameters                                                         */
3683
    /* --------------------------------------------------------------------- */
3684
74.4k
    intra_sampling_ctxt_t *ps_ctxt;
3685
74.4k
    intra_samp_map_ctxt_t *ps_map_ctxt;
3686
74.4k
    intra_samp_lyr_ctxt *ps_lyr_ctxt;
3687
74.4k
    WORD32 i4_x, i4_y;
3688
74.4k
    WORD32 i4_frm_mb_x, i4_frm_mb_y;
3689
74.4k
    ref_pixel_map_t *ps_x_pos_phase;
3690
74.4k
    ref_pixel_map_t *ps_y_pos_phase;
3691
3692
74.4k
    WORD32 i4_temp_array_ht;
3693
74.4k
    WORD32 *pi4_interp_buff;
3694
74.4k
    WORD32 *pi4_interp_buff_temp;
3695
74.4k
    WORD32 i4_mb_wd;
3696
74.4k
    WORD32 i4_mb_ht;
3697
74.4k
    WORD32 i4_x_min, i4_x_max;
3698
74.4k
    ref_min_max_map_t *ps_x_min_max;
3699
74.4k
    UWORD8 *pu1_refarray = NULL;
3700
3701
    /* --------------------------------------------------------------------- */
3702
    /* Extracting pointers from the  context                                  */
3703
    /* --------------------------------------------------------------------- */
3704
74.4k
    ps_ctxt = (intra_sampling_ctxt_t *) pv_intra_samp_ctxt;
3705
74.4k
    ps_lyr_ctxt = &ps_ctxt->as_res_lyrs[ps_ctxt->i4_res_lyr_id];
3706
3707
74.4k
    if(0 == i4_refarray_flag)
3708
49.6k
    {
3709
49.6k
        pu1_refarray = ps_ctxt->pu1_refarray_buffer;
3710
49.6k
    }
3711
24.8k
    else if(1 == i4_refarray_flag)
3712
24.8k
    {
3713
24.8k
        pu1_refarray = ps_ctxt->pu1_refarray_cb;
3714
24.8k
    }
3715
3716
    /* --------------------------------------------------------------------- */
3717
    /* LUMA    or CHROMA */
3718
    /* --------------------------------------------------------------------- */
3719
74.4k
    if(1 == i4_chroma_flag)
3720
49.6k
        ps_map_ctxt = &(ps_lyr_ctxt->s_chroma_map_ctxt);
3721
24.8k
    else
3722
24.8k
        ps_map_ctxt = &(ps_lyr_ctxt->s_luma_map_ctxt);
3723
3724
74.4k
    i4_mb_wd = MB_WIDTH >> i4_chroma_flag;
3725
74.4k
    i4_mb_ht = MB_HEIGHT >> i4_chroma_flag;
3726
74.4k
    ps_x_min_max = ps_map_ctxt->ps_x_min_max;
3727
74.4k
    i4_frm_mb_y = i4_mb_y * i4_mb_ht;
3728
74.4k
    i4_frm_mb_x = i4_mb_x * i4_mb_wd;
3729
3730
    /* get the min and max positions */
3731
74.4k
    i4_x_min = ps_x_min_max[i4_mb_x].i2_min_pos;
3732
74.4k
    i4_x_max = ps_x_min_max[i4_mb_x].i2_max_pos;
3733
3734
    /* --------------------------------------------------------------------- */
3735
    /* Projected frame level pointers                                        */
3736
    /* --------------------------------------------------------------------- */
3737
74.4k
    ps_x_pos_phase = ps_map_ctxt->ps_x_pos_phase;
3738
74.4k
    ps_y_pos_phase = ps_map_ctxt->ps_y_pos_phase;
3739
3740
    /* --------------------------------------------------------------------- */
3741
    /* Pointers and Dimenstion of the temporary buffer                         */
3742
    /* --------------------------------------------------------------------- */
3743
74.4k
    i4_temp_array_ht = i4_mb_ht;
3744
74.4k
    pi4_interp_buff = ps_ctxt->pi4_temp_interpolation_buffer;
3745
74.4k
    pi4_interp_buff_temp = pi4_interp_buff;
3746
3747
    /* --------------------------------------------------------------------- */
3748
    /* Loop for interpolation in vertical direction                             */
3749
    /* --------------------------------------------------------------------- */
3750
868k
    for(i4_y = 0; i4_y < (i4_temp_array_ht); i4_y++)
3751
793k
    {
3752
10.5M
        for(i4_x = (i4_x_min - 1); i4_x <= (i4_x_max + 2); i4_x++)
3753
9.75M
        {
3754
9.75M
            UWORD8 *pu1_refarray_temp;
3755
9.75M
            WORD32 i4_y_ref;
3756
9.75M
            WORD32 i4_y_phase;
3757
            /* ------------------------------------------------------------ */
3758
            /* Finding the offset                                            */
3759
            /* ------------------------------------------------------------ */
3760
9.75M
            i4_y_ref = ps_y_pos_phase[i4_y + i4_frm_mb_y].i2_ref_pos;
3761
9.75M
            i4_y_phase = ps_y_pos_phase[i4_y + i4_frm_mb_y].i2_phase;
3762
9.75M
            pu1_refarray_temp = pu1_refarray + i4_x + (i4_y_ref * i4_refarray_wd);
3763
3764
            /* ------------------------------------------------------------ */
3765
            /* Check for Luma/Chroma Processing                                */
3766
            /* ------------------------------------------------------------ */
3767
9.75M
            if(0 == i4_chroma_flag)
3768
5.95M
            {
3769
5.95M
                *(pi4_interp_buff + i4_x) =
3770
5.95M
                    (g_ai1_interp_filter_luma[i4_y_phase]) *
3771
5.95M
                        (*(pu1_refarray_temp - i4_refarray_wd)) +
3772
3773
5.95M
                    (g_ai1_interp_filter_luma[16 + i4_y_phase]) * (*(pu1_refarray_temp)) +
3774
3775
5.95M
                    (g_ai1_interp_filter_luma[32 + i4_y_phase]) *
3776
5.95M
                        (*(pu1_refarray_temp + i4_refarray_wd)) +
3777
3778
5.95M
                    (g_ai1_interp_filter_luma[48 + i4_y_phase]) *
3779
5.95M
                        (*(pu1_refarray_temp + (2 * i4_refarray_wd)));
3780
5.95M
            }
3781
3.80M
            else
3782
3.80M
            {
3783
3.80M
                *(pi4_interp_buff + i4_x) =
3784
3.80M
                    (g_au1_interp_filter_chroma[i4_y_phase]) * (*(pu1_refarray_temp)) +
3785
3786
3.80M
                    (g_au1_interp_filter_chroma[16 + i4_y_phase]) *
3787
3.80M
                        (*(pu1_refarray_temp + i4_refarray_wd));
3788
3.80M
            }
3789
3790
9.75M
        } /* end of loop over array  width */
3791
793k
        pi4_interp_buff = pi4_interp_buff + i4_refarray_wd;
3792
793k
    }     /* end of loop over temp array height*/
3793
3794
74.4k
    pi4_interp_buff = pi4_interp_buff_temp;
3795
3796
    /* --------------------------------------------------------------------- */
3797
    /* Loop for interpolation in horizontal direction                         */
3798
    /* --------------------------------------------------------------------- */
3799
868k
    for(i4_y = 0; i4_y < i4_temp_array_ht; i4_y++)
3800
793k
    {
3801
10.3M
        for(i4_x = 0; i4_x < i4_mb_wd; i4_x++)
3802
9.52M
        {
3803
9.52M
            WORD32 i4_x_ref;
3804
9.52M
            WORD32 i4_x_phase;
3805
            /* ------------------------------------------------------------- */
3806
            /* Finding the offset                                             */
3807
            /* ------------------------------------------------------------- */
3808
9.52M
            i4_x_ref = ps_x_pos_phase[i4_x + i4_frm_mb_x].i2_ref_pos;
3809
9.52M
            i4_x_phase = ps_x_pos_phase[i4_x + i4_frm_mb_x].i2_phase;
3810
9.52M
            pi4_interp_buff_temp = pi4_interp_buff + i4_x_ref;
3811
3812
            /* ------------------------------------------------------------- */
3813
            /* Check for Luma/Chroma Processing                                 */
3814
            /* ------------------------------------------------------------- */
3815
9.52M
            if(0 == i4_chroma_flag)
3816
6.35M
            {
3817
6.35M
                *(pu1_out + i4_x + (i4_y * i4_out_stride)) =
3818
3819
6.35M
                    CLIPUCHAR(
3820
6.35M
                        ((g_ai1_interp_filter_luma[i4_x_phase]) * (*(pi4_interp_buff_temp - 1)) +
3821
6.35M
                         (g_ai1_interp_filter_luma[16 + i4_x_phase]) * (*(pi4_interp_buff_temp)) +
3822
6.35M
                         (g_ai1_interp_filter_luma[32 + i4_x_phase]) *
3823
6.35M
                             (*(pi4_interp_buff_temp + 1)) +
3824
6.35M
                         (g_ai1_interp_filter_luma[48 + i4_x_phase]) *
3825
6.35M
                             (*(pi4_interp_buff_temp + 2)) +
3826
6.35M
                         512) >>
3827
6.35M
                        10);
3828
6.35M
            }
3829
3.17M
            else
3830
3.17M
            {
3831
3.17M
                *(pu1_out + (2 * i4_x) + (i4_y * i4_out_stride)) = CLIPUCHAR(
3832
3.17M
                    ((g_au1_interp_filter_chroma[i4_x_phase]) * (*(pi4_interp_buff_temp)) +
3833
3.17M
                     (g_au1_interp_filter_chroma[16 + i4_x_phase]) * (*(pi4_interp_buff_temp + 1)) +
3834
3.17M
                     512) >>
3835
3.17M
                    10);
3836
3.17M
            }
3837
3838
9.52M
        } /* end of loop over array width */
3839
793k
        pi4_interp_buff = pi4_interp_buff + i4_refarray_wd;
3840
793k
    }     /* end of loop over MB height */
3841
3842
74.4k
    return;
3843
74.4k
} /* End of Interpolation Function */
3844
/*****************************************************************************/
3845
/*                                                                           */
3846
/*  Function Name :  isvcd_intra_resamp_mb                                      */
3847
/*                                                                           */
3848
/*  Description   : MB level function whcih perform the intra resampling     */
3849
/*                  of data of an MB (luma and chroma insclusive)            */
3850
/*                                                                           */
3851
/*  Inputs        : pv_intra_samp_ctxt : intra sampling context              */
3852
/*                  ps_ref_luma : reference layer luma data buffer desc      */
3853
/*                  ps_ref_chroma : reference layer chroma data buffer desc  */
3854
/*                  ps_ref_mb_mode_map : ref layer mb mode map buff desc     */
3855
/*                  ps_curr_luma : current layer out luma buffer desc        */
3856
/*                  ps_curr_chroma : current layer out chroma buffer desc    */
3857
/*                  ps_mb_coord : current mb coorinate                       */
3858
/*  Globals       : none                                                     */
3859
/*  Processing    : it calls the reference layer construction followed by    */
3860
/*                   interpolation function for luma and cb and cr           */
3861
/*  Outputs       : inter resampled data of current MB                       */
3862
/*  Returns       : none                                                     */
3863
/*                                                                           */
3864
/*  Issues        : none                                                     */
3865
/*                                                                           */
3866
/*  Revision History:                                                        */
3867
/*                                                                           */
3868
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
3869
/*         06 09 2021   Vijay                creation                        */
3870
/*                                                                           */
3871
/*****************************************************************************/
3872
WORD32 isvcd_intra_resamp_mb(void *pv_intra_samp_ctxt, mem_element_t *ps_ref_luma,
3873
                             mem_element_t *ps_ref_chroma, mem_element_t *ps_ref_mb_mode_map,
3874
                             mem_element_t *ps_curr_luma, mem_element_t *ps_curr_chroma,
3875
                             mb_coord_t *ps_mb_coord)
3876
41.4k
{
3877
    /* --------------------------------------------------------------------- */
3878
    /* I/O buffer params                                                     */
3879
    /* --------------------------------------------------------------------- */
3880
41.4k
    intra_sampling_ctxt_t *ps_ctxt;
3881
41.4k
    UWORD8 *pu1_inp_luma, *pu1_inp_cb, *pu1_inp_cr;
3882
41.4k
    UWORD8 *pu1_out_luma, *pu1_out_cb, *pu1_out_cr;
3883
41.4k
    WORD32 i4_inp_stride;
3884
41.4k
    WORD32 i4_out_stride;
3885
41.4k
    WORD32 i4_refarray_stride;
3886
3887
    /* --------------------------------------------------------------------- */
3888
    /* ref sample array and corresponding parametrs                             */
3889
    /* --------------------------------------------------------------------- */
3890
41.4k
    WORD32 i4_chroma_flag, ret;
3891
3892
41.4k
    ps_ctxt = (intra_sampling_ctxt_t *) pv_intra_samp_ctxt;
3893
    /* needs to be populated at proper place */
3894
41.4k
    i4_refarray_stride = ps_ctxt->i4_refarray_stride;
3895
3896
    /* --------------------------------------------------------------------- */
3897
    /* LUMA PROCESSING                                                        */
3898
    /* --------------------------------------------------------------------- */
3899
41.4k
    pu1_inp_luma = (UWORD8 *) ps_ref_luma->pv_buffer;
3900
41.4k
    pu1_out_luma = (UWORD8 *) ps_curr_luma->pv_buffer;
3901
41.4k
    i4_inp_stride = ps_ref_luma->i4_num_element_stride;
3902
41.4k
    i4_out_stride = ps_curr_luma->i4_num_element_stride;
3903
41.4k
    i4_chroma_flag = 0;
3904
3905
    /* ------- Constructing refSampleArray ----------------------- */
3906
41.4k
    ret = isvcd_reflayer_construction(pv_intra_samp_ctxt, pu1_inp_luma, NULL, i4_inp_stride,
3907
41.4k
                                      i4_refarray_stride, ps_ref_mb_mode_map, ps_mb_coord,
3908
41.4k
                                      i4_chroma_flag);
3909
3910
41.4k
    if(ret != OK)
3911
0
    {
3912
0
        return NOT_OK;
3913
0
    }
3914
    /* ---- Interpolation process for Intra_Base prediction     ------ */
3915
41.4k
    ps_ctxt->pf_interpolate_intra_base(pv_intra_samp_ctxt, pu1_out_luma, i4_out_stride,
3916
41.4k
                                       i4_refarray_stride, ps_mb_coord->u2_mb_x,
3917
41.4k
                                       ps_mb_coord->u2_mb_y, i4_chroma_flag, 0);
3918
3919
    /* --------------------------------------------------------------------- */
3920
    /* CHROMA PROCESSING                                                       */
3921
    /* --------------------------------------------------------------------- */
3922
    /* CB */
3923
41.4k
    i4_inp_stride = ps_ref_chroma->i4_num_element_stride;
3924
41.4k
    pu1_inp_cb = (UWORD8 *) ps_ref_chroma->pv_buffer;
3925
41.4k
    pu1_inp_cr = pu1_inp_cb + 1;
3926
41.4k
    i4_chroma_flag = 1;
3927
3928
    /* ------- Constructing refSampleArray ----------------------- */
3929
41.4k
    ret = isvcd_reflayer_construction(pv_intra_samp_ctxt, pu1_inp_cb, pu1_inp_cr, i4_inp_stride,
3930
41.4k
                                      i4_refarray_stride, ps_ref_mb_mode_map, ps_mb_coord,
3931
41.4k
                                      i4_chroma_flag);
3932
3933
41.4k
    if(ret != OK)
3934
0
    {
3935
0
        return NOT_OK;
3936
0
    }
3937
41.4k
    i4_out_stride = ps_curr_chroma->i4_num_element_stride;
3938
41.4k
    pu1_out_cb = (UWORD8 *) ps_curr_chroma->pv_buffer;
3939
41.4k
    pu1_out_cr = pu1_out_cb + 1;
3940
3941
    /* ---- Cb Interpolation process for Intra_Base prediction     ------ */
3942
41.4k
    ps_ctxt->pf_interpolate_intra_base(pv_intra_samp_ctxt, pu1_out_cb, i4_out_stride,
3943
41.4k
                                       i4_refarray_stride, ps_mb_coord->u2_mb_x,
3944
41.4k
                                       ps_mb_coord->u2_mb_y, i4_chroma_flag, 0);
3945
3946
    /* ---- Cr Interpolation process for Intra_Base prediction     ------ */
3947
41.4k
    ps_ctxt->pf_interpolate_intra_base(pv_intra_samp_ctxt, pu1_out_cr, i4_out_stride,
3948
41.4k
                                       i4_refarray_stride, ps_mb_coord->u2_mb_x,
3949
41.4k
                                       ps_mb_coord->u2_mb_y, i4_chroma_flag, 1);
3950
41.4k
    return OK;
3951
41.4k
}
3952
3953
/*****************************************************************************/
3954
/*                                                                           */
3955
/*  Function Name : isvcd_intra_resamp_generate_segment_lookup                */
3956
/*                                                                           */
3957
/*  Description   : This function generates segment lookup used to derive    */
3958
/*                    segments which have to be be intra resampled           */
3959
/*                                                                           */
3960
/*  Inputs        : pv_lookup_table : look up table                          */
3961
/*                  i4_dimension    : dimension of the block which is used in*/
3962
/*                                      resampling process.                  */
3963
/*                  i4_mb_size        : size of the mb                       */
3964
/*  Globals       : None                                                     */
3965
/*  Processing    : This function generates segment lookup used to derive    */
3966
/*                    segments which have to be be intra resampled           */
3967
/*  Outputs          : none                                                  */
3968
/*  Returns          : none                                                  */
3969
/*                                                                           */
3970
/*  Issues       : None                                                      */
3971
/*                                                                           */
3972
/*  Revision History:                                                        */
3973
/*                                                                           */
3974
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
3975
/*         06 09 2021   Vijay           Creation                             */
3976
/*                                                                           */
3977
/*****************************************************************************/
3978
void isvcd_intra_resamp_generate_segment_lookup(seg_lookup_desc_t *ps_seg_lookup_table,
3979
                                                WORD32 i4_dimension, WORD32 i4_mb_size,
3980
                                                WORD32 i4_shift_val)
3981
66.3k
{
3982
66.3k
    WORD32 i4_x;
3983
66.3k
    WORD32 i4_position, i4_dist_prev_mb, i4_dist_next_mb;
3984
66.3k
    UWORD8 u1_seg_dim;
3985
66.3k
    UWORD8 u1_num_sgmts;
3986
66.3k
    WORD32 i4_block_size = i4_mb_size >> 1;
3987
66.3k
    UWORD8 u1_offset = 0;
3988
66.3k
    seg_lookup_desc_t *ps_segments;
3989
66.3k
    seg_description_t *ps_seg_desc;
3990
3991
66.3k
    memset(ps_seg_lookup_table, 0, i4_mb_size * sizeof(seg_lookup_desc_t));
3992
3993
862k
    for(i4_x = 0; i4_x < i4_mb_size; i4_x++)
3994
796k
    {
3995
796k
        ps_segments = &ps_seg_lookup_table[i4_x];
3996
796k
        ps_seg_desc = ps_segments->s_segments;
3997
796k
        i4_position = i4_x;
3998
3999
796k
        if(i4_x >= i4_block_size)
4000
398k
        {
4001
            /* set the fourth bit so that later it can be directly OR ed */
4002
398k
            ps_segments->u4_start_pos = 8;
4003
398k
        }
4004
398k
        else
4005
398k
        {
4006
398k
            ps_segments->u4_start_pos = 0;
4007
398k
        }
4008
4009
796k
        u1_num_sgmts = 0;
4010
796k
        u1_offset = 0;
4011
4012
2.98M
        while(i4_position < (i4_x + i4_dimension))
4013
2.19M
        {
4014
            /* check and fill the nearest mb boundry flag */
4015
2.19M
            if((i4_position & (i4_mb_size - 1)) < i4_block_size)
4016
1.09M
            {
4017
1.09M
                ps_seg_desc->i1_nearst_mb_bdry = -1;
4018
1.09M
            }
4019
1.09M
            else
4020
1.09M
            {
4021
1.09M
                ps_seg_desc->i1_nearst_mb_bdry = 1;
4022
1.09M
            }
4023
4024
            /* find the distance from the previous MB for start of segment*/
4025
2.19M
            i4_dist_prev_mb = (i4_position & (i4_mb_size - 1));
4026
4027
2.19M
            ps_seg_desc->i1_dist_idx =
4028
2.19M
                ((i4_dist_prev_mb >= i4_mb_size >> 1) ? (i4_mb_size - i4_dist_prev_mb)
4029
2.19M
                                                      : -(i4_dist_prev_mb + 1));
4030
4031
            /* find the size of the segment */
4032
2.19M
            u1_seg_dim = (i4_block_size - (i4_position & (i4_block_size - 1)));
4033
2.19M
            i4_position += u1_seg_dim;
4034
2.19M
            if(i4_position > (i4_x + i4_dimension))
4035
663k
            {
4036
663k
                i4_position = (i4_x + i4_dimension);
4037
663k
                u1_seg_dim = (i4_position & (i4_block_size - 1));
4038
663k
            }
4039
4040
            /* find the distance from the next MB for end of segment */
4041
2.19M
            i4_dist_next_mb = (i4_position & (i4_mb_size - 1));
4042
2.19M
            ps_seg_desc->u1_seg_dim = u1_seg_dim;
4043
2.19M
            ps_seg_desc->u1_seg_off = u1_offset;
4044
4045
            /* check if the segment has a adjoining MB edge */
4046
2.19M
            if(i4_dist_prev_mb == 0)
4047
763k
            {
4048
763k
                if(0 == u1_num_sgmts)
4049
66.3k
                {
4050
66.3k
                    ps_seg_desc->u1_mb_adjoin = 0;
4051
66.3k
                }
4052
696k
                else
4053
696k
                {
4054
696k
                    ps_seg_desc->u1_mb_adjoin = 1 << i4_shift_val;
4055
696k
                }
4056
763k
            }
4057
1.42M
            else if(i4_dist_next_mb == 0)
4058
763k
            {
4059
763k
                if(i4_position == (i4_x + i4_dimension))
4060
66.3k
                {
4061
66.3k
                    ps_seg_desc->u1_mb_adjoin = 0;
4062
66.3k
                }
4063
696k
                else
4064
696k
                {
4065
696k
                    ps_seg_desc->u1_mb_adjoin = 1 << i4_shift_val;
4066
696k
                }
4067
763k
            }
4068
663k
            else
4069
663k
            {
4070
663k
                ps_seg_desc->u1_mb_adjoin = 0;
4071
663k
            }
4072
4073
            /* Updations */
4074
2.19M
            u1_offset += u1_seg_dim;
4075
2.19M
            u1_num_sgmts++;
4076
2.19M
            ps_seg_desc++;
4077
2.19M
        }
4078
4079
        /* fill the number of segments for this position */
4080
796k
        ps_segments->u1_num_segments = u1_num_sgmts;
4081
796k
    }
4082
66.3k
}
4083
4084
/*****************************************************************************/
4085
/*                                                                           */
4086
/*  Function Name : isvcd_intra_resamp_populate_list                            */
4087
/*                                                                           */
4088
/*  Description   : This is a seq or frame level init function which fills   */
4089
/*                  all offsets, projected locations arrays based on         */
4090
/*                  the two resolutions  and cropping parameters             */
4091
/*  Inputs        : refer ot doxygen comments below                          */
4092
/*  Globals       : none                                                     */
4093
/*  Processing    : it projects the locations and computes the values        */
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
/*****************************************************************************/
4106
void isvcd_intra_resamp_populate_list(intra_samp_map_ctxt_t *ps_map_ctxt,
4107
                                      res_prms_t *ps_curr_res_prms, res_prms_t *ps_ref_res_prms,
4108
                                      WORD32 i4_chroma_flag, svc_dec_lyr_struct_t *ps_svc_lyr_dec)
4109
69.1k
{
4110
    /* --------------------------------------------------------------------- */
4111
    /* Local variables required for finding the mapping between the layers     */
4112
    /* --------------------------------------------------------------------- */
4113
69.1k
    UWORD32 i4_shift_x, i4_shift_y, i4_scale_x, i4_scale_y;
4114
69.1k
    WORD32 i4_offset_x, i4_offset_y;
4115
69.1k
    WORD32 i4_add_x, i4_add_y, i4_delta_x, i4_delta_y, i4_refphase_x, i4_refphase_y;
4116
69.1k
    WORD32 i4_phase_x, i4_phase_y, i4_sub_wd, i4_sub_ht, i4_mb_wd, i4_mb_ht;
4117
69.1k
    WORD32 i4_horz_dim, i4_vert_dim, i4_tmp;
4118
69.1k
    dec_struct_t *ps_dec = &ps_svc_lyr_dec->s_dec;
4119
    /* --------------------------------------------------------------------- */
4120
    /* Local Pointer Declaration for arrays in Mapping context                 */
4121
    /* --------------------------------------------------------------------- */
4122
69.1k
    ref_mb_map_t *ps_x_off_len, *ps_y_off_len;
4123
69.1k
    UWORD32 i4_ref_wd, i4_ref_ht, i4_scaled_wd, i4_scaled_ht, i4_curr_lyr_width, i4_curr_lyr_height;
4124
4125
    /* --------------------------------------------------------------------- */
4126
    /* Local Flag Declaration                                                 */
4127
    /* --------------------------------------------------------------------- */
4128
69.1k
    WORD32 i4_ref_layer_field_pic_flag, i4_field_pic_flag, i4_frame_mbs_only_flag;
4129
69.1k
    WORD32 i4_ref_layer_frame_Mbs_only_flag, i4_field_Mb_flag, i4_bot_field_flag;
4130
4131
    /* --------------------------------------------------------------------- */
4132
    /* Cropping Parameters Declaration                                         */
4133
    /* --------------------------------------------------------------------- */
4134
69.1k
    WORD32 i4_scaled_ref_layer_left_offset, i4_scaled_ref_layer_top_offset;
4135
69.1k
    WORD32 i4_scaled_ref_layer_right_offset, i4_scaled_ref_layer_bottom_offset;
4136
69.1k
    dec_seq_params_t *ps_sps;
4137
69.1k
    dec_svc_seq_params_t *ps_subset_sps;
4138
69.1k
    ps_sps = ps_dec->ps_cur_sps;
4139
69.1k
    ps_subset_sps = ps_svc_lyr_dec->ps_cur_subset_sps;
4140
4141
    /* --------------------------------------------------------------------- */
4142
    /* Hardcoding flag information    (assuming no field support) */
4143
    /* --------------------------------------------------------------------- */
4144
69.1k
    i4_ref_layer_field_pic_flag = SVCD_FALSE;
4145
69.1k
    i4_field_pic_flag = SVCD_FALSE;
4146
69.1k
    i4_frame_mbs_only_flag = SVCD_TRUE;
4147
69.1k
    i4_field_Mb_flag = SVCD_FALSE;
4148
69.1k
    i4_bot_field_flag = SVCD_FALSE;
4149
69.1k
    i4_ref_layer_frame_Mbs_only_flag = SVCD_TRUE;
4150
69.1k
    i4_horz_dim = 0;
4151
69.1k
    i4_vert_dim = 0;
4152
4153
    /* --------------------------------------------------------------------- */
4154
    /* Pointer and Paramater are intialized    - Chroma and Luma */
4155
    /* --------------------------------------------------------------------- */
4156
69.1k
    {
4157
69.1k
        WORD32 i4_base_width;
4158
69.1k
        WORD32 i4_base_height;
4159
69.1k
        WORD32 i4_ref_layer_chroma_phase_x_plus1_flag;
4160
69.1k
        WORD32 i4_ref_layer_chroma_phase_y_plus1;
4161
69.1k
        WORD32 i4_chroma_phase_x_plus1_flag;
4162
69.1k
        WORD32 i4_chroma_phase_y_plus1;
4163
4164
        /* ------------------------------------------------------------- */
4165
        /* HARD CODED FOR 420                                             */
4166
        /* ------------------------------------------------------------- */
4167
69.1k
        WORD32 i4_sub_wd_chroma = 2;
4168
69.1k
        WORD32 i4_sub_ht_chroma = 2;
4169
4170
69.1k
        i4_base_width = ps_ref_res_prms->i4_res_width;
4171
69.1k
        i4_base_height = ps_ref_res_prms->i4_res_height;
4172
4173
69.1k
        i4_ref_layer_chroma_phase_x_plus1_flag =
4174
69.1k
            ps_curr_res_prms->i1_ref_lyr_chroma_phase_x_plus1_flag;
4175
4176
69.1k
        i4_ref_layer_chroma_phase_y_plus1 = ps_curr_res_prms->i1_ref_lyr_chroma_phase_y_plus1;
4177
69.1k
        i4_chroma_phase_x_plus1_flag = ps_subset_sps->s_sps_svc_ext.u1_chroma_phase_x_plus1_flag;
4178
69.1k
        i4_chroma_phase_y_plus1 = ps_subset_sps->s_sps_svc_ext.u1_chroma_phase_y_plus1;
4179
69.1k
        i4_scaled_ref_layer_bottom_offset = ps_curr_res_prms->s_ref_lyr_scaled_offset.i2_bot;
4180
69.1k
        i4_scaled_ref_layer_left_offset = ps_curr_res_prms->s_ref_lyr_scaled_offset.i2_left;
4181
69.1k
        i4_scaled_ref_layer_top_offset = ps_curr_res_prms->s_ref_lyr_scaled_offset.i2_top;
4182
69.1k
        i4_scaled_ref_layer_right_offset = ps_curr_res_prms->s_ref_lyr_scaled_offset.i2_rt;
4183
4184
        /* ----------------------------------------------------------------- */
4185
        /* Computing Effective Frame Dimensions                                 */
4186
        /* ------------------------------------------------------------------*/
4187
69.1k
        i4_ref_wd = (i4_base_width >> i4_chroma_flag);
4188
69.1k
        i4_ref_ht = (i4_base_height >> i4_chroma_flag) * (1 + i4_ref_layer_field_pic_flag);
4189
4190
69.1k
        i4_scaled_wd = ps_curr_res_prms->u2_scaled_ref_width;
4191
69.1k
        i4_scaled_ht = ps_curr_res_prms->u2_scaled_ref_height;
4192
69.1k
        i4_scaled_wd = (i4_scaled_wd >> i4_chroma_flag);
4193
69.1k
        i4_scaled_ht = (i4_scaled_ht >> i4_chroma_flag) * (1 + i4_field_pic_flag);
4194
4195
69.1k
        if(1 == i4_chroma_flag)
4196
34.5k
        {
4197
34.5k
            i4_refphase_x = i4_ref_layer_chroma_phase_x_plus1_flag - 1;
4198
34.5k
            i4_refphase_y = i4_ref_layer_chroma_phase_y_plus1 - 1;
4199
34.5k
            i4_phase_x = i4_chroma_phase_x_plus1_flag - 1;
4200
34.5k
            i4_phase_y = i4_chroma_phase_y_plus1 - 1;
4201
34.5k
            i4_sub_wd = i4_sub_wd_chroma;
4202
34.5k
            i4_sub_ht = i4_sub_ht_chroma;
4203
34.5k
            i4_mb_wd = MB_WIDTH >> 1;
4204
34.5k
            i4_mb_ht = MB_HEIGHT >> 1;
4205
34.5k
        }
4206
34.5k
        else
4207
34.5k
        {
4208
34.5k
            i4_refphase_x = 0;
4209
34.5k
            i4_refphase_y = 0;
4210
34.5k
            i4_phase_x = 0;
4211
34.5k
            i4_phase_y = 0;
4212
34.5k
            i4_sub_wd = 1;
4213
34.5k
            i4_sub_ht = 1;
4214
34.5k
            i4_mb_wd = MB_WIDTH;
4215
34.5k
            i4_mb_ht = MB_HEIGHT;
4216
34.5k
        }
4217
69.1k
    }
4218
4219
    /* --------------------------------------------------------------------- */
4220
    /* Derive shift x and y based on level idd                               */
4221
    /* --------------------------------------------------------------------- */
4222
69.1k
    if(ps_sps->u1_level_idc <= 30)
4223
63.9k
    {
4224
63.9k
        i4_shift_x = 16;
4225
63.9k
        i4_shift_y = 16;
4226
63.9k
    }
4227
5.23k
    else
4228
5.23k
    {
4229
5.23k
        i4_shift_x = 31 - isvcd_get_ceil_log2(i4_ref_wd);
4230
5.23k
        i4_shift_y = 31 - isvcd_get_ceil_log2(i4_ref_ht);
4231
5.23k
    }
4232
4233
    /* --------------------------------------------------------------------- */
4234
    /* The following condition is not true in our case for time being         */
4235
    /* --------------------------------------------------------------------- */
4236
69.1k
    if((SVCD_FALSE == i4_frame_mbs_only_flag) || (SVCD_FALSE == i4_ref_layer_frame_Mbs_only_flag))
4237
0
    {
4238
0
        i4_phase_y = i4_phase_y + 4 * i4_bot_field_flag;
4239
4240
0
        if(1 == i4_ref_layer_frame_Mbs_only_flag)
4241
0
            i4_refphase_y = (2 * i4_refphase_y) + 2;
4242
0
        else
4243
0
            i4_refphase_y = i4_refphase_y + (4 * i4_bot_field_flag);
4244
0
    }
4245
4246
    /* --------------------------------------------------------------------- */
4247
    /* Dx and Dy Computation - Ratio of the base and enhance layer width     */
4248
    /* --------------------------------------------------------------------- */
4249
69.1k
    i4_scale_x = ((i4_ref_wd << i4_shift_x) + (i4_scaled_wd >> 1)) / (i4_scaled_wd);
4250
69.1k
    i4_scale_y = ((i4_ref_ht << i4_shift_y) + (i4_scaled_ht >> 1)) / (i4_scaled_ht);
4251
4252
69.1k
    i4_offset_x = i4_scaled_ref_layer_left_offset / i4_sub_wd;
4253
69.1k
    i4_add_x = (((i4_ref_wd * (2 + i4_phase_x)) << (i4_shift_x - 2)) + (i4_scaled_wd >> 1)) /
4254
69.1k
                   i4_scaled_wd +
4255
69.1k
               (1 << (i4_shift_x - 5));
4256
69.1k
    i4_delta_x = 4 * (2 + i4_refphase_x);
4257
4258
69.1k
    if((SVCD_TRUE == i4_frame_mbs_only_flag) && (SVCD_TRUE == i4_ref_layer_frame_Mbs_only_flag))
4259
69.1k
    {
4260
69.1k
        i4_offset_y = i4_scaled_ref_layer_top_offset / i4_sub_ht;
4261
69.1k
        i4_add_y = (((i4_ref_ht * (2 + i4_phase_y)) << (i4_shift_y - 2)) + (i4_scaled_ht >> 1)) /
4262
69.1k
                       i4_scaled_ht +
4263
69.1k
                   (1 << (i4_shift_y - 5));
4264
69.1k
        i4_delta_y = 4 * (2 + i4_refphase_y);
4265
69.1k
    }
4266
0
    else
4267
0
    {
4268
0
        i4_offset_y = i4_scaled_ref_layer_top_offset / (2 * i4_sub_ht);
4269
0
        i4_add_y = (((i4_ref_ht * (2 + i4_phase_y)) << (i4_shift_y - 3)) + (i4_scaled_ht >> 1)) /
4270
0
                       i4_scaled_ht +
4271
0
                   (1 << (i4_shift_y - 5));
4272
0
        i4_delta_y = 2 * (2 + i4_refphase_y);
4273
0
    }
4274
4275
    /* --------------------------------------------------------------------- */
4276
    /* Intializing Local Pointers    - Chroma and Luma                         */
4277
    /* --------------------------------------------------------------------- */
4278
69.1k
    ps_x_off_len = ps_map_ctxt->ps_x_offset_length;
4279
69.1k
    ps_y_off_len = ps_map_ctxt->ps_y_offset_length;
4280
69.1k
    i4_curr_lyr_width = ps_curr_res_prms->i4_res_width >> i4_chroma_flag;
4281
69.1k
    i4_curr_lyr_height = ps_curr_res_prms->i4_res_height >> i4_chroma_flag;
4282
4283
    /* --------------------------------------------------------------------- */
4284
    /* Dyadic Scaling Ratios Handling                                         */
4285
    /* --------------------------------------------------------------------- */
4286
69.1k
    if(1 == ps_curr_res_prms->u1_dyadic_flag)
4287
36.0k
    {
4288
36.0k
        WORD32 i4_refarray_wd, i4_x_offset;
4289
36.0k
        WORD32 i4_refarray_ht, i4_y_offset;
4290
36.0k
        WORD32 i4_crp_wd_lt, i4_crp_ht_top;
4291
36.0k
        WORD32 i4_crp_wd_rt, i4_crp_ht_bot;
4292
36.0k
        WORD32 i4_ref_lyr_wd, i4_ref_lyr_ht;
4293
36.0k
        WORD32 i4_ref_x, i4_ref_y;
4294
36.0k
        WORD32 i4_ofst;
4295
36.0k
        WORD32 i4_i, i4_j;
4296
4297
        /* Hard coded for dyadic case */
4298
36.0k
        i4_refarray_wd = 20 >> i4_chroma_flag;
4299
36.0k
        i4_ofst = -2 >> i4_chroma_flag;
4300
36.0k
        i4_crp_wd_lt = i4_scaled_ref_layer_left_offset >> i4_chroma_flag;
4301
36.0k
        i4_crp_wd_rt = i4_scaled_ref_layer_right_offset >> i4_chroma_flag;
4302
36.0k
        i4_ref_lyr_wd = (i4_curr_lyr_width >> 1);
4303
4304
36.0k
        i4_ref_x = 0;
4305
108k
        for(i4_i = 0; i4_i < (WORD32) i4_curr_lyr_width; i4_i += (i4_mb_wd << 1))
4306
72.1k
        {
4307
72.1k
            i4_x_offset = MAX(i4_ofst, (i4_ref_x + i4_ofst));
4308
72.1k
            i4_x_offset = MIN(i4_x_offset, (i4_ref_lyr_wd - i4_ofst));
4309
72.1k
            ps_x_off_len->i2_offset = i4_x_offset;
4310
72.1k
            ps_x_off_len->i2_length = i4_refarray_wd;
4311
72.1k
            ps_x_off_len++;
4312
72.1k
            ps_x_off_len->i2_offset = i4_x_offset;
4313
72.1k
            ps_x_off_len->i2_length = i4_refarray_wd;
4314
72.1k
            ps_x_off_len++;
4315
72.1k
            if(i4_i >= i4_crp_wd_lt)
4316
72.1k
            {
4317
72.1k
                if(i4_i <= (WORD32) (i4_curr_lyr_width - i4_crp_wd_rt))
4318
72.1k
                {
4319
72.1k
                    i4_ref_x += i4_mb_wd;
4320
72.1k
                }
4321
72.1k
            }
4322
72.1k
        }
4323
4324
36.0k
        i4_refarray_ht = 20 >> i4_chroma_flag;
4325
36.0k
        i4_crp_ht_top = i4_scaled_ref_layer_top_offset >> i4_chroma_flag;
4326
36.0k
        i4_crp_ht_bot = i4_scaled_ref_layer_bottom_offset >> i4_chroma_flag;
4327
36.0k
        i4_ref_lyr_ht = (i4_curr_lyr_height >> 1);
4328
4329
36.0k
        i4_ref_y = 0;
4330
206k
        for(i4_j = 0; i4_j < (WORD32) i4_curr_lyr_height; i4_j += (i4_mb_ht << 1))
4331
170k
        {
4332
170k
            i4_y_offset = MAX(i4_ofst, (i4_ref_y + i4_ofst));
4333
170k
            i4_y_offset = MIN(i4_y_offset, (i4_ref_lyr_ht - i4_ofst));
4334
170k
            ps_y_off_len->i2_offset = i4_y_offset;
4335
170k
            ps_y_off_len->i2_length = i4_refarray_ht;
4336
170k
            ps_y_off_len++;
4337
170k
            ps_y_off_len->i2_offset = i4_y_offset;
4338
170k
            ps_y_off_len->i2_length = i4_refarray_ht;
4339
170k
            ps_y_off_len++;
4340
170k
            if(i4_j >= i4_crp_ht_top)
4341
170k
            {
4342
170k
                if(i4_j <= (WORD32) (i4_curr_lyr_height - i4_crp_ht_bot))
4343
170k
                {
4344
170k
                    i4_ref_y += i4_mb_ht;
4345
170k
                }
4346
170k
            }
4347
170k
        }
4348
        /* No need to process further, return */
4349
36.0k
        return;
4350
36.0k
    } /* If dyadic path */
4351
4352
    /* Proposed Algo for Optimization */
4353
33.1k
    {
4354
33.1k
        WORD32 i4_max, i4_min;
4355
33.1k
        ref_min_max_map_t *ps_x_min_max;
4356
33.1k
        ref_min_max_map_t *ps_y_min_max;
4357
33.1k
        WORD32 i4_i, i4_j;
4358
4359
33.1k
        ps_x_min_max = ps_map_ctxt->ps_x_min_max;
4360
33.1k
        ps_y_min_max = ps_map_ctxt->ps_y_min_max;
4361
        /* ----------------------------------------------------------------- */
4362
        /* Computation of offsetX refArrayW Xmin and Xmax Lists                 */
4363
        /* ----------------------------------------------------------------- */
4364
132k
        for(i4_i = 0; i4_i < (WORD32) i4_curr_lyr_width; i4_i = i4_i + i4_mb_wd)
4365
99.5k
        {
4366
99.5k
            WORD32 i4_refarray_wd, i4_xr_index;
4367
99.5k
            WORD32 i4_x_refmin16;
4368
99.5k
            WORD32 i4_x_refmax16;
4369
99.5k
            WORD32 i4_x_offset;
4370
4371
99.5k
            i4_x_refmin16 = (WORD64) (((WORD64) (i4_i - i4_offset_x) * i4_scale_x + i4_add_x) >>
4372
99.5k
                                      ((WORD32) (i4_shift_x - 4))) -
4373
99.5k
                            i4_delta_x;
4374
4375
99.5k
            i4_x_refmax16 =
4376
99.5k
                (WORD64) (((WORD64) (i4_i + i4_mb_wd - 1 - i4_offset_x) * i4_scale_x + i4_add_x) >>
4377
99.5k
                          ((WORD32) (i4_shift_x - 4))) -
4378
99.5k
                i4_delta_x;
4379
4380
            /* ------------------------------------------------------------- */
4381
            /* Modified AC205                                                 */
4382
            /* Minimum width required - So adding 2 pixels on each side         */
4383
            /* ------------------------------------------------------------- */
4384
99.5k
            i4_refarray_wd = ((i4_x_refmax16 + 15) >> 4) - (i4_x_refmin16 >> 4) + 1 + 4;
4385
4386
            /* ------------------------------------------------------------- */
4387
            /* Setting the offset 2 pixels before                             */
4388
            /* ------------------------------------------------------------- */
4389
99.5k
            i4_x_offset = (i4_x_refmin16 >> 4) - 2;
4390
4391
            /* ------------------------------------------------------------- */
4392
            /* Modifying the values based on the location                     */
4393
            /* ------------------------------------------------------------- */
4394
99.5k
            i4_min = i4_x_offset;
4395
99.5k
            i4_xr_index = i4_min - ((i4_min / i4_mb_wd) * i4_mb_wd);
4396
4397
99.5k
            if(i4_xr_index < (i4_mb_wd >> 1))
4398
82.9k
            {
4399
82.9k
                i4_refarray_wd = i4_refarray_wd + (i4_mb_wd >> 1);
4400
82.9k
                i4_x_offset = i4_x_offset - (i4_mb_wd >> 1);
4401
82.9k
            }
4402
4403
99.5k
            i4_max = ((i4_x_refmax16 + 15) >> 4) + 2;
4404
99.5k
            i4_xr_index = i4_max - ((i4_max / i4_mb_wd) * i4_mb_wd);
4405
4406
99.5k
            if(i4_xr_index >= (i4_mb_wd >> 1)) i4_refarray_wd = i4_refarray_wd + (i4_mb_wd >> 1);
4407
4408
            /* ------------------------------------------------------------- */
4409
            /* Filling the arrays with offset, min, max and refArray dim     */
4410
            /* ------------------------------------------------------------- */
4411
99.5k
            ps_x_off_len->i2_offset = i4_x_offset;
4412
99.5k
            ps_x_off_len->i2_length = i4_refarray_wd;
4413
4414
99.5k
            ps_x_min_max->i2_min_pos = (i4_x_refmin16 >> 4) - i4_x_offset;
4415
99.5k
            ps_x_min_max->i2_max_pos = ((i4_x_refmax16 + 15) >> 4) - i4_x_offset;
4416
4417
99.5k
            i4_tmp = (WORD32) (ps_x_min_max->i2_max_pos - ps_x_min_max->i2_min_pos) +
4418
99.5k
                     (4 >> i4_chroma_flag);
4419
99.5k
            if(i4_tmp > i4_horz_dim)
4420
33.5k
            {
4421
33.5k
                i4_horz_dim = i4_tmp;
4422
33.5k
            }
4423
4424
            /* increment the pointer */
4425
99.5k
            ps_x_off_len++;
4426
99.5k
            ps_x_min_max++;
4427
99.5k
        } /* end of loop over scaled width */
4428
4429
        /* ----------------------------------------------------------------- */
4430
        /* Computation of offsetY refArrayH Ymin and Ymax Lists                 */
4431
        /* ----------------------------------------------------------------- */
4432
331k
        for(i4_j = 0; i4_j < (WORD32) i4_curr_lyr_height; i4_j = i4_j + i4_mb_ht)
4433
298k
        {
4434
298k
            WORD32 i4_refarray_ht, i4_yr_index;
4435
298k
            WORD32 i4_y_refmin16;
4436
298k
            WORD32 i4_y_refmax16;
4437
298k
            WORD32 i4_y_offset;
4438
4439
298k
            i4_y_refmin16 = (WORD64) (((WORD64) (i4_j - i4_offset_y) * i4_scale_y + i4_add_y) >>
4440
298k
                                      ((WORD32) (i4_shift_y - 4))) -
4441
298k
                            i4_delta_y;
4442
4443
298k
            i4_y_refmax16 =
4444
298k
                (WORD64) (((WORD64) (i4_j + i4_mb_ht - 1 - i4_offset_y) * i4_scale_y + i4_add_y) >>
4445
298k
                          ((WORD32) (i4_shift_y - 4))) -
4446
298k
                i4_delta_y;
4447
4448
            /* ------------------------------------------------------------- */
4449
            /* Modified AC205                                                 */
4450
            /* Minimum width required - So adding 2 pixels on each side            */
4451
            /* ------------------------------------------------------------- */
4452
298k
            i4_refarray_ht = ((i4_y_refmax16 + 15) >> 4) - (i4_y_refmin16 >> 4) + 1 + 4;
4453
4454
            /* ------------------------------------------------------------- */
4455
            /* Setting the offset 2 pixels before                             */
4456
            /* ------------------------------------------------------------- */
4457
298k
            i4_y_offset = (i4_y_refmin16 >> 4) - 2;
4458
4459
            /* ------------------------------------------------------------- */
4460
            /* Modifying the values based on the location                     */
4461
            /* ------------------------------------------------------------- */
4462
298k
            i4_min = i4_y_offset;
4463
298k
            i4_yr_index = i4_min - ((i4_min / i4_mb_ht) * i4_mb_ht);
4464
298k
            if(i4_yr_index < (i4_mb_ht >> 1))
4465
182k
            {
4466
182k
                i4_refarray_ht = i4_refarray_ht + (i4_mb_ht >> 1);
4467
182k
                i4_y_offset = i4_y_offset - (i4_mb_ht >> 1);
4468
182k
            }
4469
4470
298k
            i4_max = ((i4_y_refmax16 + 15) >> 4) + 2;
4471
298k
            i4_yr_index = i4_max - ((i4_max / i4_mb_ht) * i4_mb_ht);
4472
298k
            if(i4_yr_index >= (i4_mb_ht >> 1)) i4_refarray_ht = i4_refarray_ht + (i4_mb_ht >> 1);
4473
4474
            /* ------------------------------------------------------------- */
4475
            /* Filling the arrays with offset, min, max and refArray dim     */
4476
            /* ------------------------------------------------------------- */
4477
298k
            ps_y_off_len->i2_offset = i4_y_offset;
4478
298k
            ps_y_off_len->i2_length = i4_refarray_ht;
4479
298k
            ps_y_min_max->i2_min_pos = (i4_y_refmin16 >> 4) - i4_y_offset;
4480
298k
            ps_y_min_max->i2_max_pos = ((i4_y_refmax16 + 15) >> 4) - i4_y_offset;
4481
4482
298k
            i4_tmp = (WORD32) (ps_y_min_max->i2_max_pos - ps_y_min_max->i2_min_pos) +
4483
298k
                     (4 >> i4_chroma_flag);
4484
298k
            if(i4_tmp > i4_vert_dim)
4485
33.5k
            {
4486
33.5k
                i4_vert_dim = i4_tmp;
4487
33.5k
            }
4488
4489
            /* increment the pointer */
4490
298k
            ps_y_off_len++;
4491
298k
            ps_y_min_max++;
4492
298k
        } /* end of loop over scaled height */
4493
33.1k
    }
4494
4495
    /* --------------------------------------------------------------------- */
4496
    /* Computation of Xref and Xphase List as per standard                     */
4497
    /* --------------------------------------------------------------------- */
4498
33.1k
    ps_x_off_len = ps_map_ctxt->ps_x_offset_length;
4499
33.1k
    ps_y_off_len = ps_map_ctxt->ps_y_offset_length;
4500
4501
33.1k
    {
4502
33.1k
        ref_pixel_map_t *ps_x_pos_phase;
4503
33.1k
        WORD32 i4_xc;
4504
33.1k
        WORD32 i4_offset_x_index;
4505
4506
33.1k
        ps_x_pos_phase = ps_map_ctxt->ps_x_pos_phase;
4507
4508
1.22M
        for(i4_xc = 0; i4_xc < (WORD32) i4_curr_lyr_width; i4_xc++)
4509
1.19M
        {
4510
1.19M
            WORD32 i4_x_offset;
4511
1.19M
            WORD32 i4_x_ref16;
4512
4513
1.19M
            i4_offset_x_index = i4_xc / i4_mb_wd;
4514
4515
1.19M
            i4_x_offset = ps_x_off_len[i4_offset_x_index].i2_offset;
4516
4517
1.19M
            i4_x_ref16 = (WORD64) (((WORD64) (i4_xc - i4_offset_x) * i4_scale_x + i4_add_x) >>
4518
1.19M
                                   ((WORD32) (i4_shift_x - 4))) -
4519
1.19M
                         i4_delta_x;
4520
4521
            /* store the values */
4522
1.19M
            ps_x_pos_phase->i2_ref_pos = (i4_x_ref16 >> 4) - i4_x_offset;
4523
1.19M
            ps_x_pos_phase->i2_phase = i4_x_ref16 & 15;
4524
4525
            /* increment the pointer */
4526
1.19M
            ps_x_pos_phase++;
4527
4528
1.19M
        } /* end of loop over scaled width */
4529
33.1k
    }
4530
4531
    /* --------------------------------------------------------------------- */
4532
    /* Computation of Yref and Yphase List as per standard                     */
4533
    /* --------------------------------------------------------------------- */
4534
33.1k
    {
4535
33.1k
        WORD32 i4_yc;
4536
33.1k
        ref_pixel_map_t *ps_y_pos_phase;
4537
4538
33.1k
        ps_y_pos_phase = ps_map_ctxt->ps_y_pos_phase;
4539
4540
3.61M
        for(i4_yc = 0; i4_yc < (WORD32) i4_curr_lyr_height; i4_yc++)
4541
3.58M
        {
4542
3.58M
            WORD32 i4_y_offset;
4543
3.58M
            WORD32 i4_y_ref16;
4544
3.58M
            WORD32 i4_offset_y_index;
4545
4546
3.58M
            i4_offset_y_index = i4_yc / i4_mb_ht;
4547
4548
3.58M
            i4_y_offset = ps_y_off_len[i4_offset_y_index].i2_offset;
4549
4550
3.58M
            if((SVCD_FALSE == i4_frame_mbs_only_flag) ||
4551
3.58M
               (SVCD_FALSE == i4_ref_layer_frame_Mbs_only_flag))
4552
0
            {
4553
0
                i4_yc = i4_yc >> (1 - i4_field_Mb_flag);
4554
0
            }
4555
4556
3.58M
            i4_y_ref16 = (WORD64) (((WORD64) (i4_yc - i4_offset_y) * i4_scale_y + i4_add_y) >>
4557
3.58M
                                   ((WORD32) (i4_shift_y - 4))) -
4558
3.58M
                         i4_delta_y;
4559
3.58M
            ps_y_pos_phase->i2_ref_pos = (i4_y_ref16 >> 4) - i4_y_offset;
4560
3.58M
            ps_y_pos_phase->i2_phase = i4_y_ref16 & 15;
4561
4562
            /* increment the pointer */
4563
3.58M
            ps_y_pos_phase++;
4564
4565
3.58M
        } /* end of loop over scaled height */
4566
33.1k
    }
4567
4568
    /* --------------------------------------------------------------------- */
4569
    /* Computation of Corresponding Diagonal Location                         */
4570
    /* --------------------------------------------------------------------- */
4571
33.1k
    {
4572
33.1k
        WORD16 *pi2_xd_index;
4573
33.1k
        WORD16 *pi2_yd_index;
4574
33.1k
        WORD16 *pi2_ya_index;
4575
33.1k
        WORD32 i4_i, i4_j;
4576
4577
33.1k
        pi2_xd_index = ps_map_ctxt->pi2_xd_index;
4578
33.1k
        pi2_yd_index = ps_map_ctxt->pi2_yd_index;
4579
33.1k
        pi2_ya_index = ps_map_ctxt->pi2_ya_index;
4580
4581
431k
        for(i4_i = 0; i4_i < i4_mb_wd; i4_i++)
4582
398k
        {
4583
398k
            *(pi2_xd_index + i4_i) = ((i4_i >= i4_mb_wd >> 1) ? (i4_i - i4_mb_wd) : (i4_i + 1));
4584
4585
398k
        } /* end of loop over MB width */
4586
4587
431k
        for(i4_j = 0; i4_j < i4_mb_ht; i4_j++)
4588
398k
        {
4589
398k
            *(pi2_yd_index + i4_j) = ((i4_j >= i4_mb_ht >> 1) ? (i4_j - i4_mb_ht) : (i4_j + 1));
4590
4591
398k
            *(pi2_ya_index + i4_j) =
4592
398k
                *(pi2_yd_index + i4_j) - (((i4_mb_ht >> 1) + 1) * (SIGN(*(pi2_yd_index + i4_j))));
4593
4594
398k
        } /* end of loop over MB height */
4595
33.1k
    }
4596
4597
    /* generate the lookup to generate horizontal segments */
4598
33.1k
    isvcd_intra_resamp_generate_segment_lookup(ps_map_ctxt->ps_seg_lookup_horz, i4_horz_dim,
4599
33.1k
                                               i4_mb_wd, 3);
4600
4601
    /* generate the lookup to generate vertical segments */
4602
33.1k
    isvcd_intra_resamp_generate_segment_lookup(ps_map_ctxt->ps_seg_lookup_vert, i4_vert_dim,
4603
33.1k
                                               i4_mb_ht, 4);
4604
4605
33.1k
    return;
4606
69.1k
} /* end of function "isvcd_intra_resamp_populate_list"*/
4607
4608
/*****************************************************************************/
4609
/*                                                                           */
4610
/*  Function Name : isvcd_populate_res_prms                                   */
4611
/*                                                                           */
4612
/*  Description   :this function populates the current layer params          */
4613
/*                 from the base layer and decoder context                   */
4614
/*  Inputs        :                                                          */
4615
/*  Globals       : none                                                     */
4616
/*  Processing    :                                                          */
4617
/*                                                                           */
4618
/*  Outputs       : none                                                     */
4619
/*  Returns       : none                                                     */
4620
/*                                                                           */
4621
/*  Issues        : none                                                     */
4622
/*                                                                           */
4623
/*  Revision History:                                                        */
4624
/*                                                                           */
4625
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
4626
/*         25 11 2021   Kishore               creation                       */
4627
/*                                                                           */
4628
/*****************************************************************************/
4629
4630
WORD32 isvcd_populate_res_prms(void *pv_svc_dec)
4631
137k
{
4632
137k
    svc_dec_lyr_struct_t *ps_svc_lyr_dec = (svc_dec_lyr_struct_t *) pv_svc_dec;
4633
137k
    dec_struct_t *ps_dec = &ps_svc_lyr_dec->s_dec;
4634
137k
    res_prms_t *ps_curr_lyr_res_prms;
4635
137k
    svc_dec_lyr_struct_t *ps_svc_ref_lyr_dec;
4636
137k
    ps_svc_ref_lyr_dec = ps_svc_lyr_dec->ps_dec_svc_ref_layer;
4637
137k
    ps_curr_lyr_res_prms = &ps_svc_lyr_dec->s_res_prms;
4638
4639
137k
    ps_curr_lyr_res_prms->i4_res_width = ps_dec->u2_pic_wd;
4640
137k
    ps_curr_lyr_res_prms->i4_res_height = ps_dec->u2_pic_ht;
4641
137k
    ps_curr_lyr_res_prms->s_ref_lyr_scaled_offset.i2_left =
4642
137k
        ps_svc_lyr_dec->ps_cur_subset_sps->s_sps_svc_ext.i4_seq_scaled_ref_layer_left_offset << 1;
4643
137k
    ps_curr_lyr_res_prms->s_ref_lyr_scaled_offset.i2_top =
4644
137k
        ps_svc_lyr_dec->ps_cur_subset_sps->s_sps_svc_ext.i4_seq_scaled_ref_layer_top_offset << 1;
4645
137k
    ps_curr_lyr_res_prms->s_ref_lyr_scaled_offset.i2_rt =
4646
137k
        ps_svc_lyr_dec->ps_cur_subset_sps->s_sps_svc_ext.i4_seq_scaled_ref_layer_right_offset << 1;
4647
137k
    ps_curr_lyr_res_prms->s_ref_lyr_scaled_offset.i2_bot =
4648
137k
        ps_svc_lyr_dec->ps_cur_subset_sps->s_sps_svc_ext.i4_seq_scaled_ref_layer_bottom_offset << 1;
4649
137k
    ps_curr_lyr_res_prms->u2_scaled_ref_width =
4650
137k
        (ps_dec->u2_frm_wd_in_mbs << 4) - (ps_curr_lyr_res_prms->s_ref_lyr_scaled_offset.i2_left +
4651
137k
                                           ps_curr_lyr_res_prms->s_ref_lyr_scaled_offset.i2_rt);
4652
4653
137k
    ps_curr_lyr_res_prms->u2_scaled_ref_height =
4654
137k
        (ps_dec->u2_frm_ht_in_mbs << 4) - (ps_curr_lyr_res_prms->s_ref_lyr_scaled_offset.i2_top +
4655
137k
                                           ps_curr_lyr_res_prms->s_ref_lyr_scaled_offset.i2_bot);
4656
4657
137k
    ps_curr_lyr_res_prms->u1_cropping_change_flag = 0;
4658
137k
    if(2 == ps_svc_lyr_dec->ps_cur_subset_sps->s_sps_svc_ext.u1_extended_spatial_scalability_idc)
4659
79
    {
4660
79
        ps_curr_lyr_res_prms->u1_cropping_change_flag = 1;
4661
4662
79
        ps_curr_lyr_res_prms->s_ref_lyr_scaled_offset.i2_left =
4663
79
            ps_svc_lyr_dec->s_svc_slice_params.i4_scaled_ref_layer_left_offset << 1;
4664
4665
79
        ps_curr_lyr_res_prms->s_ref_lyr_scaled_offset.i2_top =
4666
79
            ps_svc_lyr_dec->s_svc_slice_params.i4_scaled_ref_layer_top_offset << 1;
4667
79
        ps_curr_lyr_res_prms->s_ref_lyr_scaled_offset.i2_rt =
4668
79
            ps_svc_lyr_dec->s_svc_slice_params.i4_scaled_ref_layer_right_offset << 1;
4669
79
        ps_curr_lyr_res_prms->s_ref_lyr_scaled_offset.i2_bot =
4670
79
            ps_svc_lyr_dec->s_svc_slice_params.i4_scaled_ref_layer_bottom_offset << 1;
4671
79
        ps_curr_lyr_res_prms->u2_scaled_ref_width =
4672
79
            (ps_dec->u2_frm_wd_in_mbs << 4) -
4673
79
            (ps_curr_lyr_res_prms->s_ref_lyr_scaled_offset.i2_left +
4674
79
             ps_curr_lyr_res_prms->s_ref_lyr_scaled_offset.i2_rt);
4675
4676
79
        ps_curr_lyr_res_prms->u2_scaled_ref_height =
4677
79
            (ps_dec->u2_frm_ht_in_mbs << 4) -
4678
79
            (ps_curr_lyr_res_prms->s_ref_lyr_scaled_offset.i2_top +
4679
79
             ps_curr_lyr_res_prms->s_ref_lyr_scaled_offset.i2_bot);
4680
4681
79
        return NOT_OK;
4682
79
    }
4683
4684
137k
    ps_curr_lyr_res_prms->u1_rstrct_res_change_flag = SVCD_TRUE;
4685
4686
137k
    ps_curr_lyr_res_prms->u1_disable_inter_lyr_dblk_filter_idc =
4687
137k
        ps_svc_lyr_dec->s_svc_slice_params.u4_disable_inter_layer_deblk_filter_idc;
4688
137k
    ps_curr_lyr_res_prms->i1_inter_lyr_alpha_c0_offset =
4689
137k
        ps_svc_lyr_dec->s_svc_slice_params.i4_inter_layer_slice_alpha_c0_offset_div2;
4690
137k
    ps_curr_lyr_res_prms->i1_inter_lyr_beta_offset =
4691
137k
        ps_svc_lyr_dec->s_svc_slice_params.i4_inter_layer_slice_beta_offset_div2;
4692
137k
    ps_curr_lyr_res_prms->i1_constrained_intra_rsmpl_flag =
4693
137k
        ps_svc_lyr_dec->s_svc_slice_params.u1_constrained_intra_resampling_flag;
4694
137k
    ps_curr_lyr_res_prms->i1_ref_lyr_chroma_phase_x_plus1_flag =
4695
137k
        ps_svc_lyr_dec->ps_cur_subset_sps->s_sps_svc_ext.u1_seq_ref_layer_chroma_phase_x_plus1_flag;
4696
137k
    ps_curr_lyr_res_prms->i1_ref_lyr_chroma_phase_y_plus1 =
4697
137k
        ps_svc_lyr_dec->ps_cur_subset_sps->s_sps_svc_ext.u1_seq_ref_layer_chroma_phase_y_plus1;
4698
137k
    ps_curr_lyr_res_prms->u1_direct_8x8_inference_flag =
4699
137k
        ps_dec->ps_cur_sps->u1_direct_8x8_inference_flag;
4700
4701
137k
    ps_curr_lyr_res_prms->u1_remap_req_flag = 1;
4702
137k
    ps_curr_lyr_res_prms->u1_dyadic_flag = ps_svc_lyr_dec->u1_dyadic_flag;
4703
4704
    /* Derive the reference layer width and height */
4705
4706
137k
    if(SVCD_TRUE != ps_svc_lyr_dec->u1_base_res_flag)
4707
34.9k
    {
4708
34.9k
        WORD32 i4_ref_lyr_width;
4709
34.9k
        WORD32 i4_ref_lyr_ht;
4710
34.9k
        WORD32 i4_dyadic_flag = SVCD_FALSE;
4711
34.9k
        i4_ref_lyr_width = ps_svc_ref_lyr_dec->s_res_prms.i4_res_width;
4712
34.9k
        i4_ref_lyr_ht = ps_svc_ref_lyr_dec->s_res_prms.i4_res_height;
4713
4714
        /* set the Restricted Spatial Resolution change flag */
4715
34.9k
        ps_curr_lyr_res_prms->u1_rstrct_res_change_flag = SVCD_TRUE;
4716
4717
34.9k
        if(0 == ((ps_curr_lyr_res_prms->u2_scaled_ref_width == i4_ref_lyr_width) ||
4718
34.8k
                 (ps_curr_lyr_res_prms->u2_scaled_ref_width == (i4_ref_lyr_width << 1))))
4719
16.7k
        {
4720
16.7k
            ps_curr_lyr_res_prms->u1_rstrct_res_change_flag = SVCD_FALSE;
4721
16.7k
        }
4722
4723
34.9k
        if(0 == ((ps_curr_lyr_res_prms->u2_scaled_ref_height == i4_ref_lyr_ht) ||
4724
34.8k
                 (ps_curr_lyr_res_prms->u2_scaled_ref_height == (i4_ref_lyr_ht << 1))))
4725
16.8k
        {
4726
16.8k
            ps_curr_lyr_res_prms->u1_rstrct_res_change_flag = SVCD_FALSE;
4727
16.8k
        }
4728
4729
34.9k
        if(0 != (ps_curr_lyr_res_prms->s_ref_lyr_scaled_offset.i2_left & 15))
4730
0
        {
4731
0
            ps_curr_lyr_res_prms->u1_rstrct_res_change_flag = SVCD_FALSE;
4732
0
        }
4733
4734
34.9k
        if(0 != (ps_curr_lyr_res_prms->s_ref_lyr_scaled_offset.i2_top & 15))
4735
0
        {
4736
0
            ps_curr_lyr_res_prms->u1_rstrct_res_change_flag = SVCD_FALSE;
4737
0
        }
4738
4739
        /* populate the dyadic status */
4740
4741
34.9k
        if((ps_curr_lyr_res_prms->u2_scaled_ref_width == (i4_ref_lyr_width << 1)) &&
4742
18.0k
           (ps_curr_lyr_res_prms->u2_scaled_ref_height == (i4_ref_lyr_ht << 1)))
4743
18.0k
        {
4744
18.0k
            i4_dyadic_flag = SVCD_TRUE;
4745
18.0k
        }
4746
16.9k
        else if((ps_curr_lyr_res_prms->u2_scaled_ref_width != ((i4_ref_lyr_width * 3) >> 1)) ||
4747
16.7k
                (ps_curr_lyr_res_prms->u2_scaled_ref_height != ((i4_ref_lyr_ht * 3) >> 1)))
4748
363
        {
4749
363
            ps_curr_lyr_res_prms->u1_dyadic_flag = i4_dyadic_flag;
4750
363
            ps_svc_lyr_dec->u1_dyadic_flag = ps_curr_lyr_res_prms->u1_dyadic_flag;
4751
363
            return NOT_OK;
4752
363
        }
4753
4754
        /* check if cropping is MB aligned */
4755
34.5k
        if(SVCD_TRUE == i4_dyadic_flag)
4756
18.0k
        {
4757
18.0k
            if((0 != (ps_curr_lyr_res_prms->s_ref_lyr_scaled_offset.i2_left & 15)) ||
4758
18.0k
               (0 != (ps_curr_lyr_res_prms->s_ref_lyr_scaled_offset.i2_top & 15)))
4759
0
            {
4760
0
                i4_dyadic_flag = SVCD_FALSE;
4761
0
            }
4762
18.0k
        }
4763
4764
34.5k
        ps_curr_lyr_res_prms->u1_dyadic_flag = i4_dyadic_flag;
4765
34.5k
        ps_svc_lyr_dec->u1_dyadic_flag = ps_curr_lyr_res_prms->u1_dyadic_flag;
4766
34.5k
    }
4767
4768
137k
    {
4769
137k
        inter_lyr_mb_prms_t *ps_tmp_prms, *ps_tmp_prms_2;
4770
137k
        inter_lyr_mb_prms_t *ps_ref_mb_prms;
4771
137k
        WORD32 i4_stride;
4772
137k
        WORD32 i4_ht_in_mbs, i4_wd_in_mbs;
4773
137k
        WORD32 i4_i;
4774
4775
        /* Derive the reference mb mode map */
4776
4777
137k
        ps_ref_mb_prms = ps_svc_lyr_dec->ps_inter_lyr_mb_prms_frm_start;
4778
137k
        i4_stride = ps_svc_lyr_dec->u2_inter_lyr_mb_prms_stride;
4779
4780
137k
        i4_ht_in_mbs = ps_dec->u2_frm_ht_in_mbs;
4781
137k
        i4_wd_in_mbs = ps_dec->u2_frm_wd_in_mbs;
4782
4783
        /* Set the first border row to 0xFF */
4784
137k
        ps_tmp_prms = (ps_ref_mb_prms - 1 - i4_stride);
4785
4786
137k
        memset(ps_svc_lyr_dec->ps_inter_lyr_mb_prms_base, -1,
4787
137k
               ps_svc_lyr_dec->u4_inter_lyr_mb_prms_size);
4788
137k
        memset(ps_svc_lyr_dec->pu1_svc_base_mode_flag, 0,
4789
137k
               ps_svc_lyr_dec->i4_frm_svc_base_mode_cabac_size);
4790
4791
1.18M
        for(i4_i = 0; i4_i < (i4_wd_in_mbs + 2); i4_i++)
4792
1.04M
        {
4793
1.04M
            ps_tmp_prms->i1_mb_mode = (WORD8) 0xFF;
4794
1.04M
            ps_tmp_prms += 1;
4795
1.04M
        }
4796
4797
        /* Set the left and right border pixels of each row to 0 */
4798
137k
        ps_tmp_prms = ps_ref_mb_prms - 1;
4799
4800
2.55M
        for(i4_i = 0; i4_i < i4_ht_in_mbs; i4_i++)
4801
2.42M
        {
4802
2.42M
            ps_tmp_prms->i1_mb_mode = (WORD8) 0xFF;
4803
2.42M
            ps_tmp_prms_2 = ps_tmp_prms + (i4_wd_in_mbs + 1);
4804
2.42M
            ps_tmp_prms_2->i1_mb_mode = (WORD8) 0xFF;
4805
2.42M
            ps_tmp_prms += i4_stride;
4806
2.42M
        }
4807
4808
        /* Set the last border row to 0xFF */
4809
1.18M
        for(i4_i = 0; i4_i < (i4_wd_in_mbs + 2); i4_i++)
4810
1.04M
        {
4811
1.04M
            ps_tmp_prms->i1_mb_mode = (WORD8) 0xFF;
4812
1.04M
            ps_tmp_prms += 1;
4813
1.04M
        }
4814
137k
    }
4815
4816
    /* reset residual luma, chroma buffer*/
4817
137k
    memset(ps_svc_lyr_dec->pi2_il_residual_resample_luma_base, 0,
4818
137k
           ps_svc_lyr_dec->u4_residual_resample_luma_size);
4819
137k
    memset(ps_svc_lyr_dec->pi2_il_residual_resample_chroma_base, 0,
4820
137k
           ps_svc_lyr_dec->u4_residual_resample_chroma_size);
4821
4822
137k
    return OK;
4823
137k
}
4824
4825
/*****************************************************************************/
4826
/*                                                                           */
4827
/*  Function Name : isvcd_crop_wnd_flag_res_int                               */
4828
/*                                                                           */
4829
/*  Description   : This routine computes the crop window flag for entire    */
4830
/*                  dependency layer and places it in the crop window flag   */
4831
/*                  buffer                                                   */
4832
/*  Inputs        : 1. ECD context structure                                 */
4833
/*                  2. Crop offset structure                                 */
4834
/*  Globals       : None                                                     */
4835
/*  Processing    : For Mbs within the crop window, flag set to 1 and for    */
4836
/*                  others it is set to 0                                    */
4837
/*                                                                           */
4838
/*  Outputs       : Updates crop window flag buffer                          */
4839
/*  Returns       : status                                                   */
4840
/*                                                                           */
4841
/*  Issues        : None                                                     */
4842
/*                                                                           */
4843
/*  Revision History:                                                        */
4844
/*                                                                           */
4845
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
4846
/*         06 09 2021   Vijay      Draft                                     */
4847
/*                                                                           */
4848
/*****************************************************************************/
4849
void isvcd_crop_wnd_flag_res_int(void *pv_svc_dec)
4850
137k
{
4851
137k
    UWORD8 *pu1_crop_wnd_flag;
4852
137k
    WORD32 i4_num_mbs;
4853
137k
    WORD32 i4_crop_mbs_x;
4854
137k
    WORD32 i4_crop_mbs_y;
4855
137k
    WORD32 i4_cnt;
4856
137k
    WORD32 i4_left_offset, i4_rt_offset;
4857
137k
    WORD32 i4_top_offset, i4_bot_offset;
4858
137k
    WORD32 i4_frm_wd_in_mbs;
4859
137k
    WORD32 i4_frm_ht_in_mbs;
4860
137k
    dec_struct_t *ps_dec;
4861
137k
    svc_dec_lyr_struct_t *ps_svc_lyr_dec;
4862
137k
    res_prms_t *ps_res_prms;
4863
4864
137k
    ps_svc_lyr_dec = (svc_dec_lyr_struct_t *) pv_svc_dec;
4865
137k
    ps_dec = &ps_svc_lyr_dec->s_dec;
4866
137k
    ps_res_prms = &ps_svc_lyr_dec->s_res_prms;
4867
137k
    i4_frm_wd_in_mbs = ps_dec->u2_frm_wd_in_mbs;
4868
137k
    i4_frm_ht_in_mbs = ps_dec->u2_frm_ht_in_mbs;
4869
4870
    /* Initializations */
4871
137k
    pu1_crop_wnd_flag = ps_svc_lyr_dec->pu1_crop_wnd_flag;
4872
137k
    i4_num_mbs = i4_frm_wd_in_mbs * i4_frm_ht_in_mbs;
4873
4874
    /* bottom most layer in a resolution */
4875
137k
    if(ps_res_prms->s_ref_lyr_scaled_offset.i2_left >= 0)
4876
137k
    {
4877
        /* check for offset greater than 0 */
4878
137k
        i4_left_offset = (ps_res_prms->s_ref_lyr_scaled_offset.i2_left + 15) >> 4;
4879
137k
    }
4880
0
    else
4881
0
    {
4882
        /* if negative set it to 0*/
4883
0
        i4_left_offset = 0;
4884
0
    }
4885
4886
137k
    if(ps_res_prms->s_ref_lyr_scaled_offset.i2_rt >= 0)
4887
137k
    {
4888
        /* check for offset greater than 0 */
4889
137k
        i4_rt_offset =
4890
137k
            (ps_res_prms->i4_res_width - ps_res_prms->s_ref_lyr_scaled_offset.i2_rt) >> 4;
4891
137k
    }
4892
0
    else
4893
0
    {
4894
        /* if negative set it to framewidth in MBs */
4895
0
        i4_rt_offset = (ps_res_prms->i4_res_width >> 4);
4896
0
    }
4897
4898
137k
    if(ps_res_prms->s_ref_lyr_scaled_offset.i2_top >= 0)
4899
137k
    {
4900
        /* check for offset greater than 0 */
4901
137k
        i4_top_offset = (ps_res_prms->s_ref_lyr_scaled_offset.i2_top + 15) >> 4;
4902
137k
    }
4903
0
    else
4904
0
    {
4905
        /* if negative set it to 0 */
4906
0
        i4_top_offset = 0;
4907
0
    }
4908
4909
137k
    if(ps_res_prms->s_ref_lyr_scaled_offset.i2_bot >= 0)
4910
137k
    {
4911
        /* check for offset greater than 0 */
4912
137k
        i4_bot_offset =
4913
137k
            (ps_res_prms->i4_res_height - ps_res_prms->s_ref_lyr_scaled_offset.i2_bot) >> 4;
4914
137k
    }
4915
72
    else
4916
72
    {
4917
        /* if negative set it to frameheight in MBs */
4918
72
        i4_bot_offset = (ps_res_prms->i4_res_height >> 4);
4919
72
    }
4920
4921
137k
    i4_crop_mbs_x = i4_rt_offset - i4_left_offset;
4922
137k
    i4_crop_mbs_y = i4_bot_offset - i4_top_offset;
4923
4924
    /* Set crop window flag to 0 for all mbs */
4925
137k
    memset(pu1_crop_wnd_flag, 0, i4_num_mbs);
4926
4927
137k
    pu1_crop_wnd_flag += (i4_frm_wd_in_mbs * i4_top_offset);
4928
137k
    pu1_crop_wnd_flag += i4_left_offset;
4929
    /* Loop over MBs in crop window */
4930
2.55M
    for(i4_cnt = 0; i4_cnt < i4_crop_mbs_y; i4_cnt++)
4931
2.41M
    {
4932
2.41M
        memset(pu1_crop_wnd_flag, 1, i4_crop_mbs_x);
4933
2.41M
        pu1_crop_wnd_flag += i4_frm_wd_in_mbs;
4934
2.41M
    }
4935
137k
}
4936
4937
/*****************************************************************************/
4938
/*                                                                           */
4939
/*  Function Name : isvcd_intra_resamp_res_init                                 */
4940
/*                                                                           */
4941
/*  Description   : this function calculates the scale factors and initialise*/
4942
/*                  the context structure                                    */
4943
/*                                                                           */
4944
/*  Inputs        : pv_intra_samp_ctxt: handle to private structure          */
4945
/*                  ps_curr_lyr_res_prms: pointer to current resolution      */
4946
/*                                               params                      */
4947
/*                  ps_ref_lyr_res_prms : pointer to ref resolution params   */
4948
/*  Globals       : none                                                     */
4949
/*  Processing    : it stores the layer dimensions                           */
4950
/*                                                                           */
4951
/*  Outputs       : none                                                     */
4952
/*  Returns       : none                                                     */
4953
/*                                                                           */
4954
/*  Issues        : none                                                     */
4955
/*                                                                           */
4956
/*  Revision History:                                                        */
4957
/*                                                                           */
4958
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
4959
/*         26 08 2021   vijayakumar          creation                        */
4960
/*                                                                           */
4961
/*****************************************************************************/
4962
void isvcd_intra_resamp_res_init_update_flags(void *pv_svc_dec)
4963
26.4k
{
4964
26.4k
    intra_sampling_ctxt_t *ps_ctxt;
4965
26.4k
    intra_samp_lyr_ctxt *ps_lyr_ctxt;
4966
26.4k
    svc_dec_lyr_struct_t *ps_svc_lyr_dec = (svc_dec_lyr_struct_t *) pv_svc_dec;
4967
4968
26.4k
    ps_ctxt = (intra_sampling_ctxt_t *) ps_svc_lyr_dec->pv_intra_sample_ctxt;;
4969
    /* get the current layer ctxt */
4970
26.4k
    ps_lyr_ctxt = &ps_ctxt->as_res_lyrs[ps_svc_lyr_dec->u1_layer_id - 1];
4971
4972
26.4k
    ps_lyr_ctxt->i1_constrained_intra_rsmpl_flag =
4973
26.4k
        ps_svc_lyr_dec->s_svc_slice_params.u1_constrained_intra_resampling_flag;
4974
26.4k
}
4975
4976
/*****************************************************************************/
4977
/*                                                                           */
4978
/*  Function Name : isvcd_intra_resamp_res_init                                 */
4979
/*                                                                           */
4980
/*  Description   : this function calculates the scale factors and initialise*/
4981
/*                  the context structure                                    */
4982
/*                                                                           */
4983
/*  Inputs        : pv_intra_samp_ctxt: handle to private structure          */
4984
/*                  ps_curr_lyr_res_prms: pointer to current resolution      */
4985
/*                                               params                      */
4986
/*                  ps_ref_lyr_res_prms : pointer to ref resolution params   */
4987
/*  Globals       : none                                                     */
4988
/*  Processing    : it stores the layer dimensions                           */
4989
/*                                                                           */
4990
/*  Outputs       : none                                                     */
4991
/*  Returns       : none                                                     */
4992
/*                                                                           */
4993
/*  Issues        : none                                                     */
4994
/*                                                                           */
4995
/*  Revision History:                                                        */
4996
/*                                                                           */
4997
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
4998
/*         26 08 2021   vijayakumar          creation                        */
4999
/*                                                                           */
5000
/*****************************************************************************/
5001
WORD32 isvcd_intra_resamp_res_init(void *pv_svc_dec)
5002
137k
{
5003
137k
    intra_sampling_ctxt_t *ps_ctxt;
5004
137k
    intra_samp_lyr_ctxt *ps_lyr_ctxt;
5005
137k
    dec_svc_seq_params_t *ps_cur_subset_sps;
5006
137k
    svc_dec_lyr_struct_t *ps_svc_lyr_dec = (svc_dec_lyr_struct_t *) pv_svc_dec;
5007
137k
    dec_struct_t *ps_dec = &ps_svc_lyr_dec->s_dec;
5008
137k
    dec_slice_svc_ext_params_t *ps_svc_slice_params = NULL;
5009
5010
137k
    void *pv_intra_samp_ctxt = ps_svc_lyr_dec->pv_intra_sample_ctxt;
5011
137k
    res_prms_t *ps_curr_lyr_res_prms = &ps_svc_lyr_dec->s_res_prms;
5012
137k
    ref_mb_map_t **pps_luma_map_horz = &ps_svc_lyr_dec->ps_intsam_luma_map_horz;
5013
137k
    ref_mb_map_t **pps_chroma_map_horz = &ps_svc_lyr_dec->ps_intsam_chroma_map_horz;
5014
137k
    ref_mb_map_t **pps_luma_map_vert = &ps_svc_lyr_dec->ps_intsam_luma_map_vert;
5015
137k
    ref_mb_map_t **pps_chroma_map_vert = &ps_svc_lyr_dec->ps_intsam_chroma_map_vert;
5016
5017
137k
    ps_svc_slice_params = &ps_svc_lyr_dec->s_svc_slice_params;
5018
137k
    ps_cur_subset_sps = ps_svc_lyr_dec->ps_cur_subset_sps;
5019
5020
137k
    ps_ctxt = (intra_sampling_ctxt_t *) pv_intra_samp_ctxt;
5021
5022
    /* if called for base resolution store default values */
5023
137k
    if(SVCD_TRUE == ps_svc_lyr_dec->u1_base_res_flag)
5024
102k
    {
5025
102k
        *pps_luma_map_horz = NULL;
5026
102k
        *pps_chroma_map_horz = NULL;
5027
102k
        *pps_luma_map_vert = NULL;
5028
102k
        *pps_chroma_map_vert = NULL;
5029
102k
        ps_ctxt->i4_res_lyr_id = -1;
5030
102k
        ps_ctxt->i4_ref_width = ps_dec->u2_pic_wd;
5031
102k
        ps_ctxt->i4_ref_height = ps_dec->u2_pic_ht;
5032
5033
        /* Note: The stride option is provided for bringing in data at NMB */
5034
        /* level. Hence to set a NMB level stride refSample array buffer   */
5035
        /* have to be increased                                            */
5036
102k
        ps_ctxt->i4_refarray_stride = REF_ARRAY_WIDTH;
5037
102k
        return OK;
5038
102k
    }
5039
5040
    /* derive the current sps */
5041
    /* store the res id appropriately */
5042
34.5k
    ps_ctxt->i4_res_lyr_id = ps_svc_lyr_dec->u1_layer_id - 1;
5043
5044
    /* store the resolution params */
5045
34.5k
    ps_ctxt->ps_res_prms = ps_curr_lyr_res_prms;
5046
5047
    /* get the current layer ctxt */
5048
34.5k
    ps_lyr_ctxt = &ps_ctxt->as_res_lyrs[ps_svc_lyr_dec->u1_layer_id - 1];
5049
5050
34.5k
    ps_ctxt->i4_res_lyr_id = ps_svc_lyr_dec->u1_layer_id - 1;
5051
    /* get the width and heights */
5052
34.5k
    ps_lyr_ctxt->i4_curr_width = ps_dec->u2_pic_wd;
5053
34.5k
    ps_lyr_ctxt->i4_curr_height = ps_dec->u2_pic_ht;
5054
34.5k
    ps_lyr_ctxt->i4_ref_width = ps_ctxt->i4_ref_width;
5055
34.5k
    ps_lyr_ctxt->i4_ref_height = ps_ctxt->i4_ref_height;
5056
34.5k
    ps_lyr_ctxt->i1_constrained_intra_rsmpl_flag =
5057
34.5k
        ps_svc_slice_params->u1_constrained_intra_resampling_flag;
5058
5059
    /* store the structure pointer containing projected locations */
5060
34.5k
    *pps_luma_map_horz = ps_lyr_ctxt->s_luma_map_ctxt.ps_x_offset_length;
5061
34.5k
    *pps_chroma_map_horz = ps_lyr_ctxt->s_chroma_map_ctxt.ps_x_offset_length;
5062
34.5k
    *pps_luma_map_vert = ps_lyr_ctxt->s_luma_map_ctxt.ps_y_offset_length;
5063
34.5k
    *pps_chroma_map_vert = ps_lyr_ctxt->s_chroma_map_ctxt.ps_y_offset_length;
5064
5065
    /* check for recomputation of mapping required */
5066
34.5k
    if(SVCD_TRUE == ps_curr_lyr_res_prms->u1_remap_req_flag)
5067
34.5k
    {
5068
34.5k
        res_prms_t s_ref_res_prms = {0};
5069
34.5k
        WORD32 i4_chroma_x_phase, i4_chroma_y_phase;
5070
34.5k
        WORD32 i4_ref_chroma_x_phase, i4_ref_chroma_y_phase;
5071
34.5k
        WORD32 i4_x_phase_0, i4_x_phase_1;
5072
34.5k
        WORD32 i4_y_phase_0, i4_y_phase_1;
5073
34.5k
        WORD32 i4_vert_flag;
5074
5075
        /* store the reference layer resolution width and height */
5076
34.5k
        s_ref_res_prms.i4_res_width = ps_ctxt->i4_ref_width;
5077
34.5k
        s_ref_res_prms.i4_res_height = ps_ctxt->i4_ref_height;
5078
5079
        /* call the frame level projections calculation function */
5080
34.5k
        isvcd_intra_resamp_populate_list(&ps_lyr_ctxt->s_luma_map_ctxt, ps_curr_lyr_res_prms,
5081
34.5k
                                         &s_ref_res_prms, 0, ps_svc_lyr_dec);
5082
5083
34.5k
        isvcd_intra_resamp_populate_list(&ps_lyr_ctxt->s_chroma_map_ctxt, ps_curr_lyr_res_prms,
5084
34.5k
                                         &s_ref_res_prms, 1, ps_svc_lyr_dec);
5085
5086
        /* Compute the chroma xPhase and yPhase values */
5087
34.5k
        if(1 == ps_curr_lyr_res_prms->u1_dyadic_flag)
5088
18.0k
        {
5089
18.0k
            i4_ref_chroma_x_phase = ps_curr_lyr_res_prms->i1_ref_lyr_chroma_phase_x_plus1_flag;
5090
18.0k
            i4_ref_chroma_y_phase = ps_curr_lyr_res_prms->i1_ref_lyr_chroma_phase_y_plus1;
5091
18.0k
            i4_chroma_x_phase = ps_cur_subset_sps->s_sps_svc_ext.u1_chroma_phase_x_plus1_flag;
5092
18.0k
            i4_chroma_y_phase = ps_cur_subset_sps->s_sps_svc_ext.u1_chroma_phase_y_plus1;
5093
5094
18.0k
            i4_x_phase_0 = i4_chroma_x_phase - (i4_ref_chroma_x_phase << 1);
5095
18.0k
            i4_x_phase_1 = (3 + i4_x_phase_0) & 0x7;
5096
18.0k
            i4_x_phase_0 += 7;
5097
18.0k
            i4_x_phase_0 &= 0x7;
5098
18.0k
            i4_y_phase_0 = i4_chroma_y_phase - (i4_ref_chroma_y_phase << 1);
5099
18.0k
            i4_y_phase_1 = (3 + i4_y_phase_0) & 0x7;
5100
18.0k
            i4_y_phase_0 += 7;
5101
18.0k
            i4_y_phase_0 &= 0x7;
5102
5103
18.0k
            ps_lyr_ctxt->i4_x_phase_0 = i4_x_phase_0;
5104
18.0k
            ps_lyr_ctxt->i4_x_phase_1 = i4_x_phase_1;
5105
18.0k
            ps_lyr_ctxt->i4_y_phase_0 = i4_y_phase_0;
5106
18.0k
            ps_lyr_ctxt->i4_y_phase_1 = i4_y_phase_1;
5107
5108
            /* Choose the appropriate chroma interpolation functions */
5109
18.0k
            if((0 == i4_ref_chroma_x_phase) && (1 == i4_chroma_x_phase))
5110
1.10k
            {
5111
1.10k
                ps_lyr_ctxt->pf_horz_chroma_interpol = ps_ctxt->pf_horz_chroma_interpol[1];
5112
1.10k
            }
5113
16.9k
            else
5114
16.9k
            {
5115
16.9k
                ps_lyr_ctxt->pf_horz_chroma_interpol = ps_ctxt->pf_horz_chroma_interpol[0];
5116
16.9k
            }
5117
5118
18.0k
            i4_vert_flag = 0;
5119
18.0k
            if(0 == i4_ref_chroma_y_phase)
5120
1.87k
            {
5121
1.87k
                if((1 == i4_chroma_y_phase) || (2 == i4_chroma_y_phase))
5122
185
                {
5123
185
                    i4_vert_flag = 1;
5124
185
                }
5125
1.87k
            }
5126
16.1k
            else if((2 == i4_ref_chroma_y_phase) && (0 == i4_chroma_y_phase))
5127
679
            {
5128
679
                i4_vert_flag = 2;
5129
679
            }
5130
5131
18.0k
            if(1 == i4_vert_flag)
5132
185
            {
5133
185
                ps_lyr_ctxt->pf_vert_chroma_interpol = ps_ctxt->pf_vert_chroma_interpol[1];
5134
185
            }
5135
17.8k
            else if(2 == i4_vert_flag)
5136
679
            {
5137
679
                ps_lyr_ctxt->pf_vert_chroma_interpol = ps_ctxt->pf_vert_chroma_interpol[2];
5138
679
            }
5139
17.1k
            else
5140
17.1k
            {
5141
17.1k
                ps_lyr_ctxt->pf_vert_chroma_interpol = ps_ctxt->pf_vert_chroma_interpol[0];
5142
17.1k
            }
5143
18.0k
        }
5144
34.5k
    }
5145
0
    else
5146
0
    {
5147
        /* should take false value */
5148
0
        if(SVCD_FALSE != ps_curr_lyr_res_prms->u1_remap_req_flag)
5149
0
        {
5150
0
            return NOT_OK;
5151
0
        }
5152
0
    }
5153
5154
    /* store the current layer width and height to context */
5155
34.5k
    ps_ctxt->i4_ref_width = ps_curr_lyr_res_prms->i4_res_width;
5156
34.5k
    ps_ctxt->i4_ref_height = ps_curr_lyr_res_prms->i4_res_height;
5157
5158
34.5k
    return OK;
5159
34.5k
}