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

#include "ihevc_inter_pred.h"

/**
*******************************************************************************
*
* @brief
*  Does uni-weighted prediction on the array pointed by  pi2_src and stores
* it at the location pointed by pi2_dst
*
* @par Description:
*  dst = ( (src + lvl_shift) * wgt0 + (1 << (shift - 1)) )  >> shift +
* offset
*
* @param[in] pi2_src
*  Pointer to the source
*
* @param[out] pu1_dst
*  Pointer to the destination
*
* @param[in] src_strd
*  Source stride
*
* @param[in] dst_strd
*  Destination stride
*
* @param[in] wgt0
*  weight to be multiplied to the source
*
* @param[in] off0
*  offset to be added after rounding and
*
* @param[in] shifting
*
*
* @param[in] shift
*  (14 Bit depth) + log2_weight_denominator
*
* @param[in] lvl_shift
*  added before shift and offset
*
* @param[in] ht
*  height of the source
*
* @param[in] wd
*  width of the source
*
* @returns
*
* @remarks
*  None
*
*******************************************************************************
*/

void ihevc_weighted_pred_uni(WORD16 *pi2_src,
                             UWORD8 *pu1_dst,
                             WORD32 src_strd,
                             WORD32 dst_strd,
                             WORD32 wgt0,
                             WORD32 off0,
                             WORD32 shift,
                             WORD32 lvl_shift,
                             WORD32 ht,
                             WORD32 wd)
{
    WORD32 row, col;
    WORD32 i4_tmp;

    for(row = 0; row < ht; row++)
    {
        for(col = 0; col < wd; col++)
        {
            i4_tmp = (pi2_src[col] + lvl_shift) * wgt0;
            i4_tmp += 1 << (shift - 1);
            i4_tmp = (i4_tmp >> shift) + off0;

            pu1_dst[col] = CLIP_U8(i4_tmp);
        }

        pi2_src += src_strd;
        pu1_dst += dst_strd;
    }
}
//WEIGHTED_PRED_UNI

/**
*******************************************************************************
*
* @brief
* Does chroma uni-weighted prediction on array pointed by pi2_src and stores
* it at the location pointed by pi2_dst
*
* @par Description:
*  dst = ( (src + lvl_shift) * wgt0 + (1 << (shift - 1)) )  >> shift +
* offset
*
* @param[in] pi2_src
*  Pointer to the source
*
* @param[out] pu1_dst
*  Pointer to the destination
*
* @param[in] src_strd
*  Source stride
*
* @param[in] dst_strd
*  Destination stride
*
* @param[in] wgt0
*  weight to be multiplied to the source
*
* @param[in] off0
*  offset to be added after rounding and
*
* @param[in] shifting
*
*
* @param[in] shift
*  (14 Bit depth) + log2_weight_denominator
*
* @param[in] lvl_shift
*  added before shift and offset
*
* @param[in] ht
*  height of the source
*
* @param[in] wd
*  width of the source (each colour component)
*
* @returns
*
* @remarks
*  None
*
*******************************************************************************
*/

void ihevc_weighted_pred_chroma_uni(WORD16 *pi2_src,
                                    UWORD8 *pu1_dst,
                                    WORD32 src_strd,
                                    WORD32 dst_strd,
                                    WORD32 wgt0_cb,
                                    WORD32 wgt0_cr,
                                    WORD32 off0_cb,
                                    WORD32 off0_cr,
                                    WORD32 shift,
                                    WORD32 lvl_shift,
                                    WORD32 ht,
                                    WORD32 wd)
{
    WORD32 row, col;
    WORD32 i4_tmp;

    for(row = 0; row < ht; row++)
    {
        for(col = 0; col < 2 * wd; col += 2)
        {
            i4_tmp = (pi2_src[col] + lvl_shift) * wgt0_cb;
            i4_tmp += 1 << (shift - 1);
            i4_tmp = (i4_tmp >> shift) + off0_cb;

            pu1_dst[col] = CLIP_U8(i4_tmp);

            i4_tmp = (pi2_src[col + 1] + lvl_shift) * wgt0_cr;
            i4_tmp += 1 << (shift - 1);
            i4_tmp = (i4_tmp >> shift) + off0_cr;

            pu1_dst[col + 1] = CLIP_U8(i4_tmp);
        }

        pi2_src += src_strd;
        pu1_dst += dst_strd;
    }
}
//WEIGHTED_PRED_CHROMA_UNI

/**
*******************************************************************************
*
* @brief
*  Does bi-weighted prediction on the arrays pointed by  pi2_src1 and
* pi2_src2 and stores it at location pointed  by pi2_dst
*
* @par Description:
*  dst = ( (src1 + lvl_shift1)*wgt0 +  (src2 + lvl_shift2)*wgt1 +  (off0 +
* off1 + 1) << (shift - 1) ) >> shift
*
* @param[in] pi2_src1
*  Pointer to source 1
*
* @param[in] pi2_src2
*  Pointer to source 2
*
* @param[out] pu1_dst
*  Pointer to destination
*
* @param[in] src_strd1
*  Source stride 1
*
* @param[in] src_strd2
*  Source stride 2
*
* @param[in] dst_strd
*  Destination stride
*
* @param[in] wgt0
*  weight to be multiplied to source 1
*
* @param[in] off0
*  offset 0
*
* @param[in] wgt1
*  weight to be multiplied to source 2
*
* @param[in] off1
*  offset 1
*
* @param[in] shift
*  (14 Bit depth) + log2_weight_denominator
*
* @param[in] lvl_shift1
*  added before shift and offset
*
* @param[in] lvl_shift2
*  added before shift and offset
*
* @param[in] ht
*  height of the source
*
* @param[in] wd
*  width of the source
*
* @returns
*
* @remarks
*  None
*
*******************************************************************************
*/

void ihevc_weighted_pred_bi(WORD16 *pi2_src1,
                            WORD16 *pi2_src2,
                            UWORD8 *pu1_dst,
                            WORD32 src_strd1,
                            WORD32 src_strd2,
                            WORD32 dst_strd,
                            WORD32 wgt0,
                            WORD32 off0,
                            WORD32 wgt1,
                            WORD32 off1,
                            WORD32 shift,
                            WORD32 lvl_shift1,
                            WORD32 lvl_shift2,
                            WORD32 ht,
                            WORD32 wd)
{
    WORD32 row, col;
    WORD32 i4_tmp;

    for(row = 0; row < ht; row++)
    {
        for(col = 0; col < wd; col++)
        {
            i4_tmp = (pi2_src1[col] + lvl_shift1) * wgt0;
            i4_tmp += (pi2_src2[col] + lvl_shift2) * wgt1;
            i4_tmp += (off0 + off1 + 1) << (shift - 1);

            pu1_dst[col] = CLIP_U8(i4_tmp >> shift);
        }

        pi2_src1 += src_strd1;
        pi2_src2 += src_strd2;
        pu1_dst += dst_strd;
    }
}
//WEIGHTED_PRED_BI

/**
*******************************************************************************
*
* @brief
* Does chroma bi-weighted prediction on the arrays pointed by  pi2_src1 and
* pi2_src2 and stores it at location pointed  by pi2_dst
*
* @par Description:
*  dst = ( (src1 + lvl_shift1)*wgt0 +  (src2 + lvl_shift2)*wgt1 +  (off0 +
* off1 + 1) << (shift - 1) ) >> shift
*
* @param[in] pi2_src1
*  Pointer to source 1
*
* @param[in] pi2_src2
*  Pointer to source 2
*
* @param[out] pu1_dst
*  Pointer to destination
*
* @param[in] src_strd1
*  Source stride 1
*
* @param[in] src_strd2
*  Source stride 2
*
* @param[in] dst_strd
*  Destination stride
*
* @param[in] wgt0
*  weight to be multiplied to source 1
*
* @param[in] off0
*  offset 0
*
* @param[in] wgt1
*  weight to be multiplied to source 2
*
* @param[in] off1
*  offset 1
*
* @param[in] shift
*  (14 Bit depth) + log2_weight_denominator
*
* @param[in] lvl_shift1
*  added before shift and offset
*
* @param[in] lvl_shift2
*  added before shift and offset
*
* @param[in] ht
*  height of the source
*
* @param[in] wd
*  width of the source (each colour component)
*
* @returns
*
* @remarks
*  None
*
*******************************************************************************
*/

void ihevc_weighted_pred_chroma_bi(WORD16 *pi2_src1,
                                   WORD16 *pi2_src2,
                                   UWORD8 *pu1_dst,
                                   WORD32 src_strd1,
                                   WORD32 src_strd2,
                                   WORD32 dst_strd,
                                   WORD32 wgt0_cb,
                                   WORD32 wgt0_cr,
                                   WORD32 off0_cb,
                                   WORD32 off0_cr,
                                   WORD32 wgt1_cb,
                                   WORD32 wgt1_cr,
                                   WORD32 off1_cb,
                                   WORD32 off1_cr,
                                   WORD32 shift,
                                   WORD32 lvl_shift1,
                                   WORD32 lvl_shift2,
                                   WORD32 ht,
                                   WORD32 wd)
{
    WORD32 row, col;
    WORD32 i4_tmp;

    for(row = 0; row < ht; row++)
    {
        for(col = 0; col < 2 * wd; col += 2)
        {
            i4_tmp = (pi2_src1[col] + lvl_shift1) * wgt0_cb;
            i4_tmp += (pi2_src2[col] + lvl_shift2) * wgt1_cb;
            i4_tmp += (off0_cb + off1_cb + 1) << (shift - 1);

            pu1_dst[col] = CLIP_U8(i4_tmp >> shift);

            i4_tmp = (pi2_src1[col + 1] + lvl_shift1) * wgt0_cr;
            i4_tmp += (pi2_src2[col + 1] + lvl_shift2) * wgt1_cr;
            i4_tmp += (off0_cr + off1_cr + 1) << (shift - 1);

            pu1_dst[col + 1] = CLIP_U8(i4_tmp >> shift);
        }

        pi2_src1 += src_strd1;
        pi2_src2 += src_strd2;
        pu1_dst += dst_strd;
    }
}
//WEIGHTED_PRED_CHROMA_BI

/**
*******************************************************************************
*
* @brief
*  Does default bi-weighted prediction on the arrays pointed by pi2_src1 and
* pi2_src2 and stores it at location  pointed by pi2_dst
*
* @par Description:
*  dst = ( (src1 + lvl_shift1) +  (src2 + lvl_shift2) +  1 << (shift - 1) )
* >> shift  where shift = 15 - BitDepth
*
* @param[in] pi2_src1
*  Pointer to source 1
*
* @param[in] pi2_src2
*  Pointer to source 2
*
* @param[out] pu1_dst
*  Pointer to destination
*
* @param[in] src_strd1
*  Source stride 1
*
* @param[in] src_strd2
*  Source stride 2
*
* @param[in] dst_strd
*  Destination stride
*
* @param[in] lvl_shift1
*  added before shift and offset
*
* @param[in] lvl_shift2
*  added before shift and offset
*
* @param[in] ht
*  height of the source
*
* @param[in] wd
*  width of the source
*
* @returns
*
* @remarks
*  None
*
*******************************************************************************
*/

void ihevc_weighted_pred_bi_default(WORD16 *pi2_src1,
                                    WORD16 *pi2_src2,
                                    UWORD8 *pu1_dst,
                                    WORD32 src_strd1,
                                    WORD32 src_strd2,
                                    WORD32 dst_strd,
                                    WORD32 lvl_shift1,
                                    WORD32 lvl_shift2,
                                    WORD32 ht,
                                    WORD32 wd)
{
    WORD32 row, col;
    WORD32 i4_tmp;
    WORD32 shift;

    shift = SHIFT_14_MINUS_BIT_DEPTH + 1;
    for(row = 0; row < ht; row++)
    {
        for(col = 0; col < wd; col++)
        {
            i4_tmp = pi2_src1[col] + lvl_shift1;
            i4_tmp += pi2_src2[col] + lvl_shift2;
            i4_tmp += 1 << (shift - 1);

            pu1_dst[col] = CLIP_U8(i4_tmp >> shift);
        }

        pi2_src1 += src_strd1;
        pi2_src2 += src_strd2;
        pu1_dst += dst_strd;
    }
}
//WEIGHTED_PRED_BI_DEFAULT

/**
*******************************************************************************
*
* @brief
*  Does chroma default bi-weighted prediction on arrays pointed by pi2_src1 and
* pi2_src2 and stores it at location  pointed by pi2_dst
*
* @par Description:
*  dst = ( (src1 + lvl_shift1) +  (src2 + lvl_shift2) +  1 << (shift - 1) )
* >> shift  where shift = 15 - BitDepth
*
* @param[in] pi2_src1
*  Pointer to source 1
*
* @param[in] pi2_src2
*  Pointer to source 2
*
* @param[out] pu1_dst
*  Pointer to destination
*
* @param[in] src_strd1
*  Source stride 1
*
* @param[in] src_strd2
*  Source stride 2
*
* @param[in] dst_strd
*  Destination stride
*
* @param[in] lvl_shift1
*  added before shift and offset
*
* @param[in] lvl_shift2
*  added before shift and offset
*
* @param[in] ht
*  height of the source
*
* @param[in] wd
*  width of the source (each colour component)
*
* @returns
*
* @remarks
*  None
*
*******************************************************************************
*/

void ihevc_weighted_pred_chroma_bi_default(WORD16 *pi2_src1,
                                           WORD16 *pi2_src2,
                                           UWORD8 *pu1_dst,
                                           WORD32 src_strd1,
                                           WORD32 src_strd2,
                                           WORD32 dst_strd,
                                           WORD32 lvl_shift1,
                                           WORD32 lvl_shift2,
                                           WORD32 ht,
                                           WORD32 wd)
{
    WORD32 row, col;
    WORD32 i4_tmp;
    WORD32 shift;

    shift = SHIFT_14_MINUS_BIT_DEPTH + 1;
    for(row = 0; row < ht; row++)
    {
        for(col = 0; col < 2 * wd; col++)
        {
            i4_tmp = pi2_src1[col] + lvl_shift1;
            i4_tmp += pi2_src2[col] + lvl_shift2;
            i4_tmp += 1 << (shift - 1);

            pu1_dst[col] = CLIP_U8(i4_tmp >> shift);
        }

        pi2_src1 += src_strd1;
        pi2_src2 += src_strd2;
        pu1_dst += dst_strd;
    }
}
//WEIGHTED_PRED_CHROMA_BI_DEFAULT