Coverage Report

Created: 2023-09-25 07:43

/src/libhevc/common/ihevc_weighted_pred.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
*
3
* Copyright (C) 2012 Ittiam Systems Pvt Ltd, Bangalore
4
*
5
* Licensed under the Apache License, Version 2.0 (the "License");
6
* you may not use this file except in compliance with the License.
7
* You may obtain a copy of the License at:
8
*
9
* http://www.apache.org/licenses/LICENSE-2.0
10
*
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
16
*
17
******************************************************************************/
18
/**
19
*******************************************************************************
20
* @file
21
*  ihevc_weighted_pred.c
22
*
23
* @brief
24
*  Contains function definitions for weighted prediction used in inter
25
* prediction
26
*
27
* @author
28
*  Srinivas T
29
*
30
* @par List of Functions:
31
*   - ihevc_weighted_pred_uni()
32
*   - ihevc_weighted_pred_bi()
33
*   - ihevc_weighted_pred_bi_default()
34
*   - ihevc_weighted_pred_chroma_uni()
35
*   - ihevc_weighted_pred_chroma_bi()
36
*   - ihevc_weighted_pred_chroma_bi_default()
37
*
38
* @remarks
39
*  None
40
*
41
*******************************************************************************
42
*/
43
/*****************************************************************************/
44
/* File Includes                                                             */
45
/*****************************************************************************/
46
#include "ihevc_typedefs.h"
47
#include "ihevc_defs.h"
48
#include "ihevc_macros.h"
49
#include "ihevc_platform_macros.h"
50
#include "ihevc_func_selector.h"
51
52
#include "ihevc_inter_pred.h"
53
54
/**
55
*******************************************************************************
56
*
57
* @brief
58
*  Does uni-weighted prediction on the array pointed by  pi2_src and stores
59
* it at the location pointed by pi2_dst
60
*
61
* @par Description:
62
*  dst = ( (src + lvl_shift) * wgt0 + (1 << (shift - 1)) )  >> shift +
63
* offset
64
*
65
* @param[in] pi2_src
66
*  Pointer to the source
67
*
68
* @param[out] pu1_dst
69
*  Pointer to the destination
70
*
71
* @param[in] src_strd
72
*  Source stride
73
*
74
* @param[in] dst_strd
75
*  Destination stride
76
*
77
* @param[in] wgt0
78
*  weight to be multiplied to the source
79
*
80
* @param[in] off0
81
*  offset to be added after rounding and
82
*
83
* @param[in] shifting
84
*
85
*
86
* @param[in] shift
87
*  (14 Bit depth) + log2_weight_denominator
88
*
89
* @param[in] lvl_shift
90
*  added before shift and offset
91
*
92
* @param[in] ht
93
*  height of the source
94
*
95
* @param[in] wd
96
*  width of the source
97
*
98
* @returns
99
*
100
* @remarks
101
*  None
102
*
103
*******************************************************************************
104
*/
105
106
void ihevc_weighted_pred_uni(WORD16 *pi2_src,
107
                             UWORD8 *pu1_dst,
108
                             WORD32 src_strd,
109
                             WORD32 dst_strd,
110
                             WORD32 wgt0,
111
                             WORD32 off0,
112
                             WORD32 shift,
113
                             WORD32 lvl_shift,
114
                             WORD32 ht,
115
                             WORD32 wd)
116
18.3k
{
117
18.3k
    WORD32 row, col;
118
18.3k
    WORD32 i4_tmp;
119
120
169k
    for(row = 0; row < ht; row++)
121
150k
    {
122
1.66M
        for(col = 0; col < wd; col++)
123
1.51M
        {
124
1.51M
            i4_tmp = (pi2_src[col] + lvl_shift) * wgt0;
125
1.51M
            i4_tmp += 1 << (shift - 1);
126
1.51M
            i4_tmp = (i4_tmp >> shift) + off0;
127
128
1.51M
            pu1_dst[col] = CLIP_U8(i4_tmp);
129
1.51M
        }
130
131
150k
        pi2_src += src_strd;
132
150k
        pu1_dst += dst_strd;
133
150k
    }
134
18.3k
}
135
//WEIGHTED_PRED_UNI
136
137
/**
138
*******************************************************************************
139
*
140
* @brief
141
* Does chroma uni-weighted prediction on array pointed by pi2_src and stores
142
* it at the location pointed by pi2_dst
143
*
144
* @par Description:
145
*  dst = ( (src + lvl_shift) * wgt0 + (1 << (shift - 1)) )  >> shift +
146
* offset
147
*
148
* @param[in] pi2_src
149
*  Pointer to the source
150
*
151
* @param[out] pu1_dst
152
*  Pointer to the destination
153
*
154
* @param[in] src_strd
155
*  Source stride
156
*
157
* @param[in] dst_strd
158
*  Destination stride
159
*
160
* @param[in] wgt0
161
*  weight to be multiplied to the source
162
*
163
* @param[in] off0
164
*  offset to be added after rounding and
165
*
166
* @param[in] shifting
167
*
168
*
169
* @param[in] shift
170
*  (14 Bit depth) + log2_weight_denominator
171
*
172
* @param[in] lvl_shift
173
*  added before shift and offset
174
*
175
* @param[in] ht
176
*  height of the source
177
*
178
* @param[in] wd
179
*  width of the source (each colour component)
180
*
181
* @returns
182
*
183
* @remarks
184
*  None
185
*
186
*******************************************************************************
187
*/
188
189
void ihevc_weighted_pred_chroma_uni(WORD16 *pi2_src,
190
                                    UWORD8 *pu1_dst,
191
                                    WORD32 src_strd,
192
                                    WORD32 dst_strd,
193
                                    WORD32 wgt0_cb,
194
                                    WORD32 wgt0_cr,
195
                                    WORD32 off0_cb,
196
                                    WORD32 off0_cr,
197
                                    WORD32 shift,
198
                                    WORD32 lvl_shift,
199
                                    WORD32 ht,
200
                                    WORD32 wd)
201
18.3k
{
202
18.3k
    WORD32 row, col;
203
18.3k
    WORD32 i4_tmp;
204
205
94.5k
    for(row = 0; row < ht; row++)
206
76.1k
    {
207
459k
        for(col = 0; col < 2 * wd; col += 2)
208
383k
        {
209
383k
            i4_tmp = (pi2_src[col] + lvl_shift) * wgt0_cb;
210
383k
            i4_tmp += 1 << (shift - 1);
211
383k
            i4_tmp = (i4_tmp >> shift) + off0_cb;
212
213
383k
            pu1_dst[col] = CLIP_U8(i4_tmp);
214
215
383k
            i4_tmp = (pi2_src[col + 1] + lvl_shift) * wgt0_cr;
216
383k
            i4_tmp += 1 << (shift - 1);
217
383k
            i4_tmp = (i4_tmp >> shift) + off0_cr;
218
219
383k
            pu1_dst[col + 1] = CLIP_U8(i4_tmp);
220
383k
        }
221
222
76.1k
        pi2_src += src_strd;
223
76.1k
        pu1_dst += dst_strd;
224
76.1k
    }
225
18.3k
}
226
//WEIGHTED_PRED_CHROMA_UNI
227
228
/**
229
*******************************************************************************
230
*
231
* @brief
232
*  Does bi-weighted prediction on the arrays pointed by  pi2_src1 and
233
* pi2_src2 and stores it at location pointed  by pi2_dst
234
*
235
* @par Description:
236
*  dst = ( (src1 + lvl_shift1)*wgt0 +  (src2 + lvl_shift2)*wgt1 +  (off0 +
237
* off1 + 1) << (shift - 1) ) >> shift
238
*
239
* @param[in] pi2_src1
240
*  Pointer to source 1
241
*
242
* @param[in] pi2_src2
243
*  Pointer to source 2
244
*
245
* @param[out] pu1_dst
246
*  Pointer to destination
247
*
248
* @param[in] src_strd1
249
*  Source stride 1
250
*
251
* @param[in] src_strd2
252
*  Source stride 2
253
*
254
* @param[in] dst_strd
255
*  Destination stride
256
*
257
* @param[in] wgt0
258
*  weight to be multiplied to source 1
259
*
260
* @param[in] off0
261
*  offset 0
262
*
263
* @param[in] wgt1
264
*  weight to be multiplied to source 2
265
*
266
* @param[in] off1
267
*  offset 1
268
*
269
* @param[in] shift
270
*  (14 Bit depth) + log2_weight_denominator
271
*
272
* @param[in] lvl_shift1
273
*  added before shift and offset
274
*
275
* @param[in] lvl_shift2
276
*  added before shift and offset
277
*
278
* @param[in] ht
279
*  height of the source
280
*
281
* @param[in] wd
282
*  width of the source
283
*
284
* @returns
285
*
286
* @remarks
287
*  None
288
*
289
*******************************************************************************
290
*/
291
292
void ihevc_weighted_pred_bi(WORD16 *pi2_src1,
293
                            WORD16 *pi2_src2,
294
                            UWORD8 *pu1_dst,
295
                            WORD32 src_strd1,
296
                            WORD32 src_strd2,
297
                            WORD32 dst_strd,
298
                            WORD32 wgt0,
299
                            WORD32 off0,
300
                            WORD32 wgt1,
301
                            WORD32 off1,
302
                            WORD32 shift,
303
                            WORD32 lvl_shift1,
304
                            WORD32 lvl_shift2,
305
                            WORD32 ht,
306
                            WORD32 wd)
307
531k
{
308
531k
    WORD32 row, col;
309
531k
    WORD32 i4_tmp;
310
311
4.73M
    for(row = 0; row < ht; row++)
312
4.20M
    {
313
38.5M
        for(col = 0; col < wd; col++)
314
34.3M
        {
315
34.3M
            i4_tmp = (pi2_src1[col] + lvl_shift1) * wgt0;
316
34.3M
            i4_tmp += (pi2_src2[col] + lvl_shift2) * wgt1;
317
34.3M
            i4_tmp += (off0 + off1 + 1) << (shift - 1);
318
319
34.3M
            pu1_dst[col] = CLIP_U8(i4_tmp >> shift);
320
34.3M
        }
321
322
4.20M
        pi2_src1 += src_strd1;
323
4.20M
        pi2_src2 += src_strd2;
324
4.20M
        pu1_dst += dst_strd;
325
4.20M
    }
326
531k
}
327
//WEIGHTED_PRED_BI
328
329
/**
330
*******************************************************************************
331
*
332
* @brief
333
* Does chroma bi-weighted prediction on the arrays pointed by  pi2_src1 and
334
* pi2_src2 and stores it at location pointed  by pi2_dst
335
*
336
* @par Description:
337
*  dst = ( (src1 + lvl_shift1)*wgt0 +  (src2 + lvl_shift2)*wgt1 +  (off0 +
338
* off1 + 1) << (shift - 1) ) >> shift
339
*
340
* @param[in] pi2_src1
341
*  Pointer to source 1
342
*
343
* @param[in] pi2_src2
344
*  Pointer to source 2
345
*
346
* @param[out] pu1_dst
347
*  Pointer to destination
348
*
349
* @param[in] src_strd1
350
*  Source stride 1
351
*
352
* @param[in] src_strd2
353
*  Source stride 2
354
*
355
* @param[in] dst_strd
356
*  Destination stride
357
*
358
* @param[in] wgt0
359
*  weight to be multiplied to source 1
360
*
361
* @param[in] off0
362
*  offset 0
363
*
364
* @param[in] wgt1
365
*  weight to be multiplied to source 2
366
*
367
* @param[in] off1
368
*  offset 1
369
*
370
* @param[in] shift
371
*  (14 Bit depth) + log2_weight_denominator
372
*
373
* @param[in] lvl_shift1
374
*  added before shift and offset
375
*
376
* @param[in] lvl_shift2
377
*  added before shift and offset
378
*
379
* @param[in] ht
380
*  height of the source
381
*
382
* @param[in] wd
383
*  width of the source (each colour component)
384
*
385
* @returns
386
*
387
* @remarks
388
*  None
389
*
390
*******************************************************************************
391
*/
392
393
void ihevc_weighted_pred_chroma_bi(WORD16 *pi2_src1,
394
                                   WORD16 *pi2_src2,
395
                                   UWORD8 *pu1_dst,
396
                                   WORD32 src_strd1,
397
                                   WORD32 src_strd2,
398
                                   WORD32 dst_strd,
399
                                   WORD32 wgt0_cb,
400
                                   WORD32 wgt0_cr,
401
                                   WORD32 off0_cb,
402
                                   WORD32 off0_cr,
403
                                   WORD32 wgt1_cb,
404
                                   WORD32 wgt1_cr,
405
                                   WORD32 off1_cb,
406
                                   WORD32 off1_cr,
407
                                   WORD32 shift,
408
                                   WORD32 lvl_shift1,
409
                                   WORD32 lvl_shift2,
410
                                   WORD32 ht,
411
                                   WORD32 wd)
412
535k
{
413
535k
    WORD32 row, col;
414
535k
    WORD32 i4_tmp;
415
416
2.68M
    for(row = 0; row < ht; row++)
417
2.14M
    {
418
10.9M
        for(col = 0; col < 2 * wd; col += 2)
419
8.82M
        {
420
8.82M
            i4_tmp = (pi2_src1[col] + lvl_shift1) * wgt0_cb;
421
8.82M
            i4_tmp += (pi2_src2[col] + lvl_shift2) * wgt1_cb;
422
8.82M
            i4_tmp += (off0_cb + off1_cb + 1) << (shift - 1);
423
424
8.82M
            pu1_dst[col] = CLIP_U8(i4_tmp >> shift);
425
426
8.82M
            i4_tmp = (pi2_src1[col + 1] + lvl_shift1) * wgt0_cr;
427
8.82M
            i4_tmp += (pi2_src2[col + 1] + lvl_shift2) * wgt1_cr;
428
8.82M
            i4_tmp += (off0_cr + off1_cr + 1) << (shift - 1);
429
430
8.82M
            pu1_dst[col + 1] = CLIP_U8(i4_tmp >> shift);
431
8.82M
        }
432
433
2.14M
        pi2_src1 += src_strd1;
434
2.14M
        pi2_src2 += src_strd2;
435
2.14M
        pu1_dst += dst_strd;
436
2.14M
    }
437
535k
}
438
//WEIGHTED_PRED_CHROMA_BI
439
440
/**
441
*******************************************************************************
442
*
443
* @brief
444
*  Does default bi-weighted prediction on the arrays pointed by pi2_src1 and
445
* pi2_src2 and stores it at location  pointed by pi2_dst
446
*
447
* @par Description:
448
*  dst = ( (src1 + lvl_shift1) +  (src2 + lvl_shift2) +  1 << (shift - 1) )
449
* >> shift  where shift = 15 - BitDepth
450
*
451
* @param[in] pi2_src1
452
*  Pointer to source 1
453
*
454
* @param[in] pi2_src2
455
*  Pointer to source 2
456
*
457
* @param[out] pu1_dst
458
*  Pointer to destination
459
*
460
* @param[in] src_strd1
461
*  Source stride 1
462
*
463
* @param[in] src_strd2
464
*  Source stride 2
465
*
466
* @param[in] dst_strd
467
*  Destination stride
468
*
469
* @param[in] lvl_shift1
470
*  added before shift and offset
471
*
472
* @param[in] lvl_shift2
473
*  added before shift and offset
474
*
475
* @param[in] ht
476
*  height of the source
477
*
478
* @param[in] wd
479
*  width of the source
480
*
481
* @returns
482
*
483
* @remarks
484
*  None
485
*
486
*******************************************************************************
487
*/
488
489
void ihevc_weighted_pred_bi_default(WORD16 *pi2_src1,
490
                                    WORD16 *pi2_src2,
491
                                    UWORD8 *pu1_dst,
492
                                    WORD32 src_strd1,
493
                                    WORD32 src_strd2,
494
                                    WORD32 dst_strd,
495
                                    WORD32 lvl_shift1,
496
                                    WORD32 lvl_shift2,
497
                                    WORD32 ht,
498
                                    WORD32 wd)
499
627k
{
500
627k
    WORD32 row, col;
501
627k
    WORD32 i4_tmp;
502
627k
    WORD32 shift;
503
504
627k
    shift = SHIFT_14_MINUS_BIT_DEPTH + 1;
505
5.02M
    for(row = 0; row < ht; row++)
506
4.39M
    {
507
68.5M
        for(col = 0; col < wd; col++)
508
64.1M
        {
509
64.1M
            i4_tmp = pi2_src1[col] + lvl_shift1;
510
64.1M
            i4_tmp += pi2_src2[col] + lvl_shift2;
511
64.1M
            i4_tmp += 1 << (shift - 1);
512
513
64.1M
            pu1_dst[col] = CLIP_U8(i4_tmp >> shift);
514
64.1M
        }
515
516
4.39M
        pi2_src1 += src_strd1;
517
4.39M
        pi2_src2 += src_strd2;
518
4.39M
        pu1_dst += dst_strd;
519
4.39M
    }
520
627k
}
521
//WEIGHTED_PRED_BI_DEFAULT
522
523
/**
524
*******************************************************************************
525
*
526
* @brief
527
*  Does chroma default bi-weighted prediction on arrays pointed by pi2_src1 and
528
* pi2_src2 and stores it at location  pointed by pi2_dst
529
*
530
* @par Description:
531
*  dst = ( (src1 + lvl_shift1) +  (src2 + lvl_shift2) +  1 << (shift - 1) )
532
* >> shift  where shift = 15 - BitDepth
533
*
534
* @param[in] pi2_src1
535
*  Pointer to source 1
536
*
537
* @param[in] pi2_src2
538
*  Pointer to source 2
539
*
540
* @param[out] pu1_dst
541
*  Pointer to destination
542
*
543
* @param[in] src_strd1
544
*  Source stride 1
545
*
546
* @param[in] src_strd2
547
*  Source stride 2
548
*
549
* @param[in] dst_strd
550
*  Destination stride
551
*
552
* @param[in] lvl_shift1
553
*  added before shift and offset
554
*
555
* @param[in] lvl_shift2
556
*  added before shift and offset
557
*
558
* @param[in] ht
559
*  height of the source
560
*
561
* @param[in] wd
562
*  width of the source (each colour component)
563
*
564
* @returns
565
*
566
* @remarks
567
*  None
568
*
569
*******************************************************************************
570
*/
571
572
void ihevc_weighted_pred_chroma_bi_default(WORD16 *pi2_src1,
573
                                           WORD16 *pi2_src2,
574
                                           UWORD8 *pu1_dst,
575
                                           WORD32 src_strd1,
576
                                           WORD32 src_strd2,
577
                                           WORD32 dst_strd,
578
                                           WORD32 lvl_shift1,
579
                                           WORD32 lvl_shift2,
580
                                           WORD32 ht,
581
                                           WORD32 wd)
582
0
{
583
0
    WORD32 row, col;
584
0
    WORD32 i4_tmp;
585
0
    WORD32 shift;
586
587
0
    shift = SHIFT_14_MINUS_BIT_DEPTH + 1;
588
0
    for(row = 0; row < ht; row++)
589
0
    {
590
0
        for(col = 0; col < 2 * wd; col++)
591
0
        {
592
0
            i4_tmp = pi2_src1[col] + lvl_shift1;
593
0
            i4_tmp += pi2_src2[col] + lvl_shift2;
594
0
            i4_tmp += 1 << (shift - 1);
595
596
0
            pu1_dst[col] = CLIP_U8(i4_tmp >> shift);
597
0
        }
598
599
0
        pi2_src1 += src_strd1;
600
0
        pi2_src2 += src_strd2;
601
0
        pu1_dst += dst_strd;
602
0
    }
603
0
}
604
//WEIGHTED_PRED_CHROMA_BI_DEFAULT