Coverage Report

Created: 2026-08-13 06:16

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libhevc/common/ihevc_chroma_recon.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_chroma_recon.c
22
 *
23
 * @brief
24
 *  Functions definitions reconstruction  of chroma interleaved data.
25
 *
26
 * @author
27
 *  100470
28
 *
29
 * @par List of Functions:
30
 *  - ihevc_chroma_recon_4x4()
31
 *  - ihevc_chroma_recon_8x8()
32
 *  - ihevc_chroma_recon_16x16()
33
 *
34
 * @remarks
35
 *  None
36
 *
37
 *******************************************************************************
38
 */
39
40
#include <stdio.h>
41
#include <string.h>
42
#include "ihevc_typedefs.h"
43
#include "ihevc_macros.h"
44
#include "ihevc_platform_macros.h"
45
#include "ihevc_defs.h"
46
#include "ihevc_trans_tables.h"
47
#include "ihevc_chroma_recon.h"
48
#include "ihevc_trans_macros.h"
49
50
/* All the functions work one component(U or V) of interleaved data depending upon pointers passed to it */
51
/* Data visualization */
52
/* U V U V U V U V */
53
/* U V U V U V U V */
54
/* U V U V U V U V */
55
/* U V U V U V U V */
56
/* If the pointer points to first byte of above stream (U) , functions will operate on U component */
57
/* If the pointer points to second byte of above stream (V) , functions will operate on V component */
58
59
/**
60
 *******************************************************************************
61
 *
62
 * @brief
63
 *  This function performs reconstruction for  4x4 input block
64
 *
65
 * @par Description:
66
 *  Performs reconstruction of 4x4 input block by adding  adding prediction
67
 * data to input and clipping it to 8 bit
68
 *
69
 * @param[in] pi2_src
70
 *  Input 4x4 coefficients
71
 *
72
 * @param[in] pu1_pred
73
 *  Prediction 4x4 block
74
 *
75
 * @param[out] pu1_dst
76
 *  Output 4x4 block
77
 *
78
 * @param[in] src_strd
79
 *  Input stride
80
 *
81
 * @param[in] pred_strd
82
 *  Prediction stride
83
 *
84
 * @param[in] dst_strd
85
 *  Output Stride
86
 *
87
 * @param[in] shift
88
 *  Output shift
89
 *
90
 * @param[in] zero_cols
91
 *  Zero columns in pi2_tmp
92
 *
93
 * @returns  Void
94
 *
95
 * @remarks
96
 *  None
97
 *
98
 *******************************************************************************
99
 */
100
101
102
void ihevc_chroma_recon_4x4(WORD16 *pi2_src,
103
                            UWORD8 *pu1_pred,
104
                            UWORD8 *pu1_dst,
105
                            WORD32 src_strd,
106
                            WORD32 pred_strd,
107
                            WORD32 dst_strd,
108
                            WORD32 zero_cols)
109
0
{
110
0
    WORD32 i, j;
111
0
    WORD32 trans_size;
112
113
0
    trans_size = TRANS_SIZE_4;
114
115
    /* Reconstruction */
116
117
0
    for(i = 0; i < trans_size; i++)
118
0
    {
119
        /* Checking for Zero Cols */
120
0
        if((zero_cols & 1) == 1)
121
0
        {
122
0
            for(j = 0; j < trans_size; j++)
123
0
            {
124
0
                pu1_dst[j * dst_strd] = pu1_pred[j * pred_strd];
125
0
            }
126
0
        }
127
0
        else
128
0
        {
129
0
            for(j = 0; j < trans_size; j++)
130
0
            {
131
0
                pu1_dst[j * dst_strd] =
132
0
                                CLIP_U8(pi2_src[j * src_strd] + pu1_pred[j * pred_strd]);
133
0
            }
134
0
        }
135
0
        pi2_src++;
136
0
        pu1_dst += 2;
137
0
        pu1_pred += 2;
138
0
        zero_cols = zero_cols >> 1;
139
0
    }
140
0
}
141
142
/**
143
 *******************************************************************************
144
 *
145
 * @brief
146
 *  This function performs reconstruction for 8x8 input block
147
 *
148
 * @par Description:
149
 *  Performs reconstruction of 8x8 input block by adding  adding prediction
150
 * data to input and clipping it to 8 bit
151
 *
152
 * @param[in] pi2_src
153
 *  Input 8x8 coefficients
154
 *
155
 * @param[in] pu1_pred
156
 *  Prediction 8x8 block
157
 *
158
 * @param[out] pu1_dst
159
 *  Output 8x8 block
160
 *
161
 * @param[in] src_strd
162
 *  Input stride
163
 *
164
 * @param[in] pred_strd
165
 *  Prediction stride
166
 *
167
 * @param[in] dst_strd
168
 *  Output Stride
169
 *
170
 * @param[in] shift
171
 *  Output shift
172
 *
173
 * @param[in] zero_cols
174
 *  Zero columns in pi2_tmp
175
 *
176
 * @returns  Void
177
 *
178
 * @remarks
179
 *  None
180
 *
181
 *******************************************************************************
182
 */
183
184
185
void ihevc_chroma_recon_8x8(WORD16 *pi2_src,
186
                            UWORD8 *pu1_pred,
187
                            UWORD8 *pu1_dst,
188
                            WORD32 src_strd,
189
                            WORD32 pred_strd,
190
                            WORD32 dst_strd,
191
                            WORD32 zero_cols)
192
0
{
193
0
    WORD32 i, j;
194
0
    WORD32 trans_size;
195
196
0
    trans_size = TRANS_SIZE_8;
197
198
    /* Reconstruction */
199
200
0
    for(i = 0; i < trans_size; i++)
201
0
    {
202
        /* Checking for Zero Cols */
203
0
        if((zero_cols & 1) == 1)
204
0
        {
205
0
            for(j = 0; j < trans_size; j++)
206
0
            {
207
0
                pu1_dst[j * dst_strd] = pu1_pred[j * pred_strd];
208
0
            }
209
0
        }
210
0
        else
211
0
        {
212
0
            for(j = 0; j < trans_size; j++)
213
0
            {
214
0
                pu1_dst[j * dst_strd] =
215
0
                                CLIP_U8(pi2_src[j * src_strd] + pu1_pred[j * pred_strd]);
216
0
            }
217
0
        }
218
0
        pi2_src++;
219
0
        pu1_dst += 2;
220
0
        pu1_pred += 2;
221
0
        zero_cols = zero_cols >> 1;
222
0
    }
223
0
}
224
225
/**
226
 *******************************************************************************
227
 *
228
 * @brief
229
 *  This function performs reconstruction for  16x16 input block
230
 *
231
 * @par Description:
232
 *  Performs reconstruction of 16x16 input block by adding  adding prediction
233
 * data to input and clipping it to 8 bit
234
 *
235
 * @param[in] pi2_src
236
 *  Input 16x16 coefficients
237
 *
238
 * @param[in] pu1_pred
239
 *  Prediction 16x16 block
240
 *
241
 * @param[out] pu1_dst
242
 *  Output 16x16 block
243
 *
244
 * @param[in] src_strd
245
 *  Input stride
246
 *
247
 * @param[in] pred_strd
248
 *  Prediction stride
249
 *
250
 * @param[in] dst_strd
251
 *  Output Stride
252
 *
253
 * @param[in] shift
254
 *  Output shift
255
 *
256
 * @param[in] zero_cols
257
 *  Zero columns in pi2_tmp
258
 *
259
 * @returns  Void
260
 *
261
 * @remarks
262
 *  None
263
 *
264
 *******************************************************************************
265
 */
266
267
268
void ihevc_chroma_recon_16x16(WORD16 *pi2_src,
269
                              UWORD8 *pu1_pred,
270
                              UWORD8 *pu1_dst,
271
                              WORD32 src_strd,
272
                              WORD32 pred_strd,
273
                              WORD32 dst_strd,
274
                              WORD32 zero_cols)
275
0
{
276
0
    WORD32 i, j;
277
0
    WORD32 trans_size;
278
279
0
    trans_size = TRANS_SIZE_16;
280
281
    /* Reconstruction */
282
283
0
    for(i = 0; i < trans_size; i++)
284
0
    {
285
        /* Checking for Zero Cols */
286
0
        if((zero_cols & 1) == 1)
287
0
        {
288
0
            for(j = 0; j < trans_size; j++)
289
0
            {
290
0
                pu1_dst[j * dst_strd] = pu1_pred[j * pred_strd];
291
0
            }
292
0
        }
293
0
        else
294
0
        {
295
0
            for(j = 0; j < trans_size; j++)
296
0
            {
297
0
                pu1_dst[j * dst_strd] =
298
0
                                CLIP_U8(pi2_src[j * src_strd] + pu1_pred[j * pred_strd]);
299
0
            }
300
0
        }
301
0
        pi2_src++;
302
0
        pu1_dst += 2;
303
0
        pu1_pred += 2;
304
0
        zero_cols = zero_cols >> 1;
305
0
    }
306
0
}
307
308
/**
309
 *******************************************************************************
310
 *
311
 * @brief
312
 *  This function performs reconstruction for 32x32 input block
313
 *
314
 * @par Description:
315
 *  Performs reconstruction of 32x32 input block by adding adding prediction
316
 * data to input and clipping it to 8 bit
317
 *
318
 * @param[in] pi2_src
319
 *  Input 32x32 coefficients
320
 *
321
 * @param[in] pu1_pred
322
 *  Prediction 32x32 block
323
 *
324
 * @param[out] pu1_dst
325
 *  Output 32x32 block
326
 *
327
 * @param[in] src_strd
328
 *  Input stride
329
 *
330
 * @param[in] pred_strd
331
 *  Prediction stride
332
 *
333
 * @param[in] dst_strd
334
 *  Output Stride
335
 *
336
 * @param[in] shift
337
 *  Output shift
338
 *
339
 * @param[in] zero_cols
340
 *  Zero columns in pi2_tmp
341
 *
342
 * @returns  Void
343
 *
344
 * @remarks
345
 *  None
346
 *
347
 *******************************************************************************
348
 */
349
350
351
void ihevc_chroma_recon_32x32(WORD16 *pi2_src,
352
                              UWORD8 *pu1_pred,
353
                              UWORD8 *pu1_dst,
354
                              WORD32 src_strd,
355
                              WORD32 pred_strd,
356
                              WORD32 dst_strd,
357
                              WORD32 zero_cols)
358
0
{
359
0
    WORD32 i, j;
360
0
    WORD32 trans_size;
361
362
0
    trans_size = TRANS_SIZE_32;
363
364
    /* Reconstruction */
365
366
0
    for(i = 0; i < trans_size; i++)
367
0
    {
368
        /* Checking for Zero Cols */
369
0
        if((zero_cols & 1) == 1)
370
0
        {
371
0
            for(j = 0; j < trans_size; j++)
372
0
            {
373
0
                pu1_dst[j * dst_strd] = pu1_pred[j * pred_strd];
374
0
            }
375
0
        }
376
0
        else
377
0
        {
378
0
            for(j = 0; j < trans_size; j++)
379
0
            {
380
0
                pu1_dst[j * dst_strd] =
381
0
                                CLIP_U8(pi2_src[j * src_strd] + pu1_pred[j * pred_strd]);
382
0
            }
383
0
        }
384
0
        pi2_src++;
385
0
        pu1_dst += 2;
386
0
        pu1_pred += 2;
387
0
        zero_cols = zero_cols >> 1;
388
0
    }
389
0
}
390
391
/**
392
 ******************************************************************************
393
 *
394
 * @brief Constructs chroma recon with Cross Component Prediction (CCP)
395
 *
396
 * @par   Description
397
 * This routine uses reconstructed luma residual samples to predict chroma
398
 * residual samples as per HEVC Specification Section 8.6.6. It scales the
399
 * luma residual by a signaled alpha value and adds it to the chroma residual
400
 * prior to final reconstruction.
401
 *
402
 * @param[in]   pi2_luma_res
403
 * pointer to the luma residual
404
 *
405
 * @param[in] pi2_chroma_res
406
 * pointer to the chroma residual
407
 *
408
 * @param[in] pu1_pred
409
 * prediction block
410
 *
411
 * @param[in] pu1_dst
412
 * destination block
413
 *
414
 * @param[in]   alpha
415
 * scaling factor for the luma residual
416
 *
417
 * @param[in]   trans_size
418
 * transform size
419
 *
420
 * @param[in]   luma_res_stride
421
 * stride of the luma residual buffer
422
 *
423
 * @param[in]   chroma_res_stride
424
 * stride of the chroma residual buffer
425
 *
426
 * @param[in] pred_strd
427
 *  Prediction stride
428
 *
429
 * @param[in] dst_strd
430
 *  Output Stride
431
 *
432
 * @return      success or failure error code
433
 *
434
 ******************************************************************************
435
 */
436
void ihevc_chroma_recon_nxn_ccp(WORD16 *pi2_luma_res,
437
                                WORD16 *pi2_chroma_res,
438
                                UWORD8 *pu1_pred,
439
                                UWORD8 *pu1_dst,
440
                                WORD32 alpha,
441
                                WORD32 trans_size,
442
                                WORD32 luma_res_stride,
443
                                WORD32 chroma_res_stride,
444
                                WORD32 pred_stride,
445
                                WORD32 dst_stride)
446
0
{
447
0
    WORD32 i, j;
448
449
0
    for(i = 0; i < trans_size; i++)
450
0
    {
451
0
        for(j = 0; j < trans_size; j++)
452
0
        {
453
0
            WORD32 res = (alpha * pi2_luma_res[j]) >> 3;
454
0
            pu1_dst[j * 2] = CLIP_U8(pu1_pred[j * 2] + (pi2_chroma_res[j] + res));
455
0
        }
456
0
        pi2_luma_res += luma_res_stride;
457
0
        pi2_chroma_res += chroma_res_stride;
458
0
        pu1_dst += dst_stride;
459
0
        pu1_pred += pred_stride;
460
0
    }
461
0
}