Coverage Report

Created: 2026-09-01 06:17

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