Coverage Report

Created: 2026-12-01 07:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libhevc/common/ihevc_hbd_itrans_recon_8x8.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_itrans_recon_8x8.c
22
 *
23
 * @brief
24
 *  Contains function definitions for inverse transform  and reconstruction 8x8
25
 *
26
 *
27
 * @author
28
 *  Ittiam
29
 *
30
 * @par List of Functions:
31
 *  - ihevc_itrans_recon_8x8()
32
 *
33
 * @remarks
34
 *  None
35
 *
36
 *******************************************************************************
37
 */
38
#include <stdio.h>
39
#include <string.h>
40
#include "ihevc_typedefs.h"
41
#include "ihevc_macros.h"
42
#include "ihevc_platform_macros.h"
43
#include "ihevc_defs.h"
44
#include "ihevc_trans_tables.h"
45
#include "ihevc_itrans_recon.h"
46
#include "ihevc_trans_macros.h"
47
48
/**
49
 *******************************************************************************
50
 *
51
 * @brief
52
 *  This function performs Inverse transform  and reconstruction for 8x8
53
 * input block
54
 *
55
 * @par Description:
56
 *  Performs inverse transform and adds the prediction  data and clips output
57
 * to 8 bit
58
 *
59
 * @param[in] pi2_src
60
 *  Input 8x8 coefficients
61
 *
62
 * @param[in] pi2_tmp
63
 *  Temporary 8x8 buffer for storing inverse
64
 *
65
 *  transform
66
 *  1st stage output
67
 *
68
 * @param[in] pu2_pred
69
 *  Prediction 8x8 block
70
 *
71
 * @param[out] pu2_dst
72
 *  Output 8x8 block
73
 *
74
 * @param[in] src_strd
75
 *  Input stride
76
 *
77
 * @param[in] pred_strd
78
 *  Prediction stride
79
 *
80
 * @param[in] dst_strd
81
 *  Output Stride
82
 *
83
 * @param[in] shift
84
 *  Output shift
85
 *
86
 * @param[in] zero_cols
87
 *  Zero columns in pi2_src
88
 *
89
 * @returns  Void
90
 *
91
 * @remarks
92
 *  None
93
 *
94
 *******************************************************************************
95
 */
96
void ihevc_hbd_itrans_recon_8x8(WORD16 *pi2_src,
97
                                WORD16 *pi2_tmp,
98
                                UWORD16 *pu2_pred,
99
                                UWORD16 *pu2_dst,
100
                                WORD32 src_strd,
101
                                WORD32 pred_strd,
102
                                WORD32 dst_strd,
103
                                WORD32 zero_cols,
104
                                WORD32 zero_rows,
105
                                UWORD8 u1_bit_depth)
106
748k
{
107
748k
    WORD32 j, k;
108
748k
    WORD32 e[4], o[4];
109
748k
    WORD32 ee[2], eo[2];
110
748k
    WORD32 add;
111
748k
    WORD32 shift;
112
748k
    WORD16 *pi2_tmp_orig;
113
748k
    WORD32 trans_size;
114
748k
    WORD32 zero_rows_2nd_stage = zero_cols;
115
748k
    WORD32 row_limit_2nd_stage;
116
748k
    WORD16 clip_limit;
117
118
748k
    trans_size = TRANS_SIZE_8;
119
748k
    clip_limit = (1 << u1_bit_depth) - 1;
120
121
748k
    pi2_tmp_orig = pi2_tmp;
122
123
748k
    if((zero_cols & 0xF0) == 0xF0)
124
541k
        row_limit_2nd_stage = 4;
125
206k
    else
126
206k
        row_limit_2nd_stage = TRANS_SIZE_8;
127
128
129
748k
    if((zero_rows & 0xF0) == 0xF0) /* First 4 rows of input are non-zero */
130
482k
    {
131
        /************************************************************************************************/
132
        /**********************************START - IT_RECON_8x8******************************************/
133
        /************************************************************************************************/
134
135
        /* Inverse Transform 1st stage */
136
482k
        shift = IT_SHIFT_STAGE_1;
137
482k
        add = 1 << (shift - 1);
138
139
2.92M
        for(j = 0; j < row_limit_2nd_stage; j++)
140
2.44M
        {
141
            /* Checking for Zero Cols */
142
2.44M
            if((zero_cols & 1) == 1)
143
1.13M
            {
144
1.13M
                memset(pi2_tmp, 0, trans_size * sizeof(WORD16));
145
1.13M
            }
146
1.31M
            else
147
1.31M
            {
148
                /* Utilizing symmetry properties to the maximum to minimize the number of multiplications */
149
6.58M
                for(k = 0; k < 4; k++)
150
5.27M
                {
151
5.27M
                    o[k] = g_ai2_ihevc_trans_8[1][k] * pi2_src[src_strd]
152
5.27M
                                    + g_ai2_ihevc_trans_8[3][k]
153
5.27M
                                                    * pi2_src[3 * src_strd];
154
5.27M
                }
155
1.31M
                eo[0] = g_ai2_ihevc_trans_8[2][0] * pi2_src[2 * src_strd];
156
1.31M
                eo[1] = g_ai2_ihevc_trans_8[2][1] * pi2_src[2 * src_strd];
157
1.31M
                ee[0] = g_ai2_ihevc_trans_8[0][0] * pi2_src[0];
158
1.31M
                ee[1] = g_ai2_ihevc_trans_8[0][1] * pi2_src[0];
159
160
                /* Combining e and o terms at each hierarchy levels to calculate the final spatial domain vector */
161
1.31M
                e[0] = ee[0] + eo[0];
162
1.31M
                e[3] = ee[0] - eo[0];
163
1.31M
                e[1] = ee[1] + eo[1];
164
1.31M
                e[2] = ee[1] - eo[1];
165
6.58M
                for(k = 0; k < 4; k++)
166
5.27M
                {
167
5.27M
                    pi2_tmp[k] =
168
5.27M
                                    CLIP_S16( ((e[k] + o[k] + add)>>shift) );
169
5.27M
                    pi2_tmp[k + 4] =
170
5.27M
                                    CLIP_S16( ((e[3-k] - o[3-k] + add)>>shift) );
171
5.27M
                }
172
1.31M
            }
173
2.44M
            pi2_src++;
174
2.44M
            pi2_tmp += trans_size;
175
2.44M
            zero_cols = zero_cols >> 1;
176
2.44M
        }
177
178
482k
        pi2_tmp = pi2_tmp_orig;
179
180
        /* Inverse Transform 2nd stage */
181
482k
        shift = 20 - u1_bit_depth;
182
482k
        add = 1 << (shift - 1);
183
482k
        if((zero_rows_2nd_stage & 0xF0) == 0xF0) /* First 4 rows of output of 1st stage are non-zero */
184
350k
        {
185
3.11M
            for(j = 0; j < trans_size; j++)
186
2.76M
            {
187
                /* Utilizing symmetry properties to the maximum to minimize the number of multiplications */
188
13.8M
                for(k = 0; k < 4; k++)
189
11.0M
                {
190
11.0M
                    o[k] = g_ai2_ihevc_trans_8[1][k] * pi2_tmp[trans_size]
191
11.0M
                                    + g_ai2_ihevc_trans_8[3][k] * pi2_tmp[3 * trans_size];
192
11.0M
                }
193
2.76M
                eo[0] = g_ai2_ihevc_trans_8[2][0] * pi2_tmp[2 * trans_size];
194
2.76M
                eo[1] = g_ai2_ihevc_trans_8[2][1] * pi2_tmp[2 * trans_size];
195
2.76M
                ee[0] = g_ai2_ihevc_trans_8[0][0] * pi2_tmp[0];
196
2.76M
                ee[1] = g_ai2_ihevc_trans_8[0][1] * pi2_tmp[0];
197
198
                /* Combining e and o terms at each hierarchy levels to calculate the final spatial domain vector */
199
2.76M
                e[0] = ee[0] + eo[0];
200
2.76M
                e[3] = ee[0] - eo[0];
201
2.76M
                e[1] = ee[1] + eo[1];
202
2.76M
                e[2] = ee[1] - eo[1];
203
13.7M
                for(k = 0; k < 4; k++)
204
11.0M
                {
205
11.0M
                    WORD32 itrans_out;
206
11.0M
                    itrans_out =
207
11.0M
                                    CLIP_S16( ((e[k] + o[k] + add)>>shift ) );
208
11.0M
                    pu2_dst[k] = CLIP3((itrans_out + pu2_pred[k]), 0, clip_limit);
209
11.0M
                    itrans_out =
210
11.0M
                                    CLIP_S16( ((e[3-k] - o[3-k] + add)>>shift ) );
211
11.0M
                    pu2_dst[k + 4] = CLIP3((itrans_out + pu2_pred[k + 4] ), 0, clip_limit);
212
11.0M
                }
213
2.76M
                pi2_tmp++;
214
2.76M
                pu2_pred += pred_strd;
215
2.76M
                pu2_dst += dst_strd;
216
2.76M
            }
217
350k
        }
218
131k
        else /* All rows of output of 1st stage are non-zero */
219
131k
        {
220
1.16M
            for(j = 0; j < trans_size; j++)
221
1.03M
            {
222
                /* Utilizing symmetry properties to the maximum to minimize the number of multiplications */
223
5.17M
                for(k = 0; k < 4; k++)
224
4.14M
                {
225
4.14M
                    o[k] = g_ai2_ihevc_trans_8[1][k] * pi2_tmp[trans_size]
226
4.14M
                                    + g_ai2_ihevc_trans_8[3][k]
227
4.14M
                                                    * pi2_tmp[3 * trans_size]
228
4.14M
                                    + g_ai2_ihevc_trans_8[5][k]
229
4.14M
                                                    * pi2_tmp[5 * trans_size]
230
4.14M
                                    + g_ai2_ihevc_trans_8[7][k]
231
4.14M
                                                    * pi2_tmp[7 * trans_size];
232
4.14M
                }
233
234
1.03M
                eo[0] = g_ai2_ihevc_trans_8[2][0] * pi2_tmp[2 * trans_size]
235
1.03M
                                + g_ai2_ihevc_trans_8[6][0] * pi2_tmp[6 * trans_size];
236
1.03M
                eo[1] = g_ai2_ihevc_trans_8[2][1] * pi2_tmp[2 * trans_size]
237
1.03M
                                + g_ai2_ihevc_trans_8[6][1] * pi2_tmp[6 * trans_size];
238
1.03M
                ee[0] = g_ai2_ihevc_trans_8[0][0] * pi2_tmp[0]
239
1.03M
                                + g_ai2_ihevc_trans_8[4][0] * pi2_tmp[4 * trans_size];
240
1.03M
                ee[1] = g_ai2_ihevc_trans_8[0][1] * pi2_tmp[0]
241
1.03M
                                + g_ai2_ihevc_trans_8[4][1] * pi2_tmp[4 * trans_size];
242
243
                /* Combining e and o terms at each hierarchy levels to calculate the final spatial domain vector */
244
1.03M
                e[0] = ee[0] + eo[0];
245
1.03M
                e[3] = ee[0] - eo[0];
246
1.03M
                e[1] = ee[1] + eo[1];
247
1.03M
                e[2] = ee[1] - eo[1];
248
5.15M
                for(k = 0; k < 4; k++)
249
4.12M
                {
250
4.12M
                    WORD32 itrans_out;
251
4.12M
                    itrans_out =
252
4.12M
                                    CLIP_S16( ((e[k] + o[k] + add)>>shift ) );
253
4.12M
                    pu2_dst[k] = CLIP3((itrans_out + pu2_pred[k]), 0, clip_limit);
254
4.12M
                    itrans_out =
255
4.12M
                                    CLIP_S16( ((e[3-k] - o[3-k] + add)>>shift ) );
256
4.12M
                    pu2_dst[k + 4] = CLIP3((itrans_out + pu2_pred[k + 4] ), 0, clip_limit);
257
4.12M
                }
258
1.03M
                pi2_tmp++;
259
1.03M
                pu2_pred += pred_strd;
260
1.03M
                pu2_dst += dst_strd;
261
1.03M
            }
262
131k
        }
263
        /************************************************************************************************/
264
        /************************************END - IT_RECON_8x8******************************************/
265
        /************************************************************************************************/
266
482k
    }
267
266k
    else /* All rows of input are non-zero */
268
266k
    {
269
        /************************************************************************************************/
270
        /**********************************START - IT_RECON_8x8******************************************/
271
        /************************************************************************************************/
272
273
        /* Inverse Transform 1st stage */
274
266k
        shift = IT_SHIFT_STAGE_1;
275
266k
        add = 1 << (shift - 1);
276
277
1.63M
        for(j = 0; j < row_limit_2nd_stage; j++)
278
1.36M
        {
279
            /* Checking for Zero Cols */
280
1.36M
            if((zero_cols & 1) == 1)
281
502k
            {
282
502k
                memset(pi2_tmp, 0, trans_size * sizeof(WORD16));
283
502k
            }
284
864k
            else
285
864k
            {
286
                /* Utilizing symmetry properties to the maximum to minimize the number of multiplications */
287
4.32M
                for(k = 0; k < 4; k++)
288
3.46M
                {
289
3.46M
                    o[k] = g_ai2_ihevc_trans_8[1][k] * pi2_src[src_strd]
290
3.46M
                                    + g_ai2_ihevc_trans_8[3][k]
291
3.46M
                                                    * pi2_src[3 * src_strd]
292
3.46M
                                    + g_ai2_ihevc_trans_8[5][k]
293
3.46M
                                                    * pi2_src[5 * src_strd]
294
3.46M
                                    + g_ai2_ihevc_trans_8[7][k]
295
3.46M
                                                    * pi2_src[7 * src_strd];
296
3.46M
                }
297
298
864k
                eo[0] = g_ai2_ihevc_trans_8[2][0] * pi2_src[2 * src_strd]
299
864k
                                + g_ai2_ihevc_trans_8[6][0] * pi2_src[6 * src_strd];
300
864k
                eo[1] = g_ai2_ihevc_trans_8[2][1] * pi2_src[2 * src_strd]
301
864k
                                + g_ai2_ihevc_trans_8[6][1] * pi2_src[6 * src_strd];
302
864k
                ee[0] = g_ai2_ihevc_trans_8[0][0] * pi2_src[0]
303
864k
                                + g_ai2_ihevc_trans_8[4][0] * pi2_src[4 * src_strd];
304
864k
                ee[1] = g_ai2_ihevc_trans_8[0][1] * pi2_src[0]
305
864k
                                + g_ai2_ihevc_trans_8[4][1] * pi2_src[4 * src_strd];
306
307
                /* Combining e and o terms at each hierarchy levels to calculate the final spatial domain vector */
308
864k
                e[0] = ee[0] + eo[0];
309
864k
                e[3] = ee[0] - eo[0];
310
864k
                e[1] = ee[1] + eo[1];
311
864k
                e[2] = ee[1] - eo[1];
312
4.32M
                for(k = 0; k < 4; k++)
313
3.46M
                {
314
3.46M
                    pi2_tmp[k] =
315
3.46M
                                    CLIP_S16( ((e[k] + o[k] + add)>>shift) );
316
3.46M
                    pi2_tmp[k + 4] =
317
3.46M
                                    CLIP_S16( ((e[3-k] - o[3-k] + add)>>shift) );
318
3.46M
                }
319
864k
            }
320
1.36M
            pi2_src++;
321
1.36M
            pi2_tmp += trans_size;
322
1.36M
            zero_cols = zero_cols >> 1;
323
1.36M
        }
324
325
266k
        pi2_tmp = pi2_tmp_orig;
326
327
        /* Inverse Transform 2nd stage */
328
266k
        shift = 20 - u1_bit_depth;
329
266k
        add = 1 << (shift - 1);
330
266k
        if((zero_rows_2nd_stage & 0xF0) == 0xF0) /* First 4 rows of output of 1st stage are non-zero */
331
191k
        {
332
1.69M
            for(j = 0; j < trans_size; j++)
333
1.49M
            {
334
                /* Utilizing symmetry properties to the maximum to minimize the number of multiplications */
335
7.49M
                for(k = 0; k < 4; k++)
336
5.99M
                {
337
5.99M
                    o[k] = g_ai2_ihevc_trans_8[1][k] * pi2_tmp[trans_size]
338
5.99M
                                    + g_ai2_ihevc_trans_8[3][k] * pi2_tmp[3 * trans_size];
339
5.99M
                }
340
1.49M
                eo[0] = g_ai2_ihevc_trans_8[2][0] * pi2_tmp[2 * trans_size];
341
1.49M
                eo[1] = g_ai2_ihevc_trans_8[2][1] * pi2_tmp[2 * trans_size];
342
1.49M
                ee[0] = g_ai2_ihevc_trans_8[0][0] * pi2_tmp[0];
343
1.49M
                ee[1] = g_ai2_ihevc_trans_8[0][1] * pi2_tmp[0];
344
345
                /* Combining e and o terms at each hierarchy levels to calculate the final spatial domain vector */
346
1.49M
                e[0] = ee[0] + eo[0];
347
1.49M
                e[3] = ee[0] - eo[0];
348
1.49M
                e[1] = ee[1] + eo[1];
349
1.49M
                e[2] = ee[1] - eo[1];
350
7.48M
                for(k = 0; k < 4; k++)
351
5.98M
                {
352
5.98M
                    WORD32 itrans_out;
353
5.98M
                    itrans_out =
354
5.98M
                                    CLIP_S16( ((e[k] + o[k] + add)>>shift ) );
355
5.98M
                    pu2_dst[k] = CLIP3((itrans_out + pu2_pred[k]), 0, clip_limit);
356
5.98M
                    itrans_out =
357
5.98M
                                    CLIP_S16( ((e[3-k] - o[3-k] + add)>>shift ) );
358
5.98M
                    pu2_dst[k + 4] = CLIP3((itrans_out + pu2_pred[k + 4] ), 0, clip_limit);
359
5.98M
                }
360
1.49M
                pi2_tmp++;
361
1.49M
                pu2_pred += pred_strd;
362
1.49M
                pu2_dst += dst_strd;
363
1.49M
            }
364
191k
        }
365
75.2k
        else /* All rows of output of 1st stage are non-zero */
366
75.2k
        {
367
680k
            for(j = 0; j < trans_size; j++)
368
605k
            {
369
                /* Utilizing symmetry properties to the maximum to minimize the number of multiplications */
370
3.02M
                for(k = 0; k < 4; k++)
371
2.42M
                {
372
2.42M
                    o[k] = g_ai2_ihevc_trans_8[1][k] * pi2_tmp[trans_size]
373
2.42M
                                    + g_ai2_ihevc_trans_8[3][k]
374
2.42M
                                                    * pi2_tmp[3 * trans_size]
375
2.42M
                                    + g_ai2_ihevc_trans_8[5][k]
376
2.42M
                                                    * pi2_tmp[5 * trans_size]
377
2.42M
                                    + g_ai2_ihevc_trans_8[7][k]
378
2.42M
                                                    * pi2_tmp[7 * trans_size];
379
2.42M
                }
380
381
605k
                eo[0] = g_ai2_ihevc_trans_8[2][0] * pi2_tmp[2 * trans_size]
382
605k
                                + g_ai2_ihevc_trans_8[6][0] * pi2_tmp[6 * trans_size];
383
605k
                eo[1] = g_ai2_ihevc_trans_8[2][1] * pi2_tmp[2 * trans_size]
384
605k
                                + g_ai2_ihevc_trans_8[6][1] * pi2_tmp[6 * trans_size];
385
605k
                ee[0] = g_ai2_ihevc_trans_8[0][0] * pi2_tmp[0]
386
605k
                                + g_ai2_ihevc_trans_8[4][0] * pi2_tmp[4 * trans_size];
387
605k
                ee[1] = g_ai2_ihevc_trans_8[0][1] * pi2_tmp[0]
388
605k
                                + g_ai2_ihevc_trans_8[4][1] * pi2_tmp[4 * trans_size];
389
390
                /* Combining e and o terms at each hierarchy levels to calculate the final spatial domain vector */
391
605k
                e[0] = ee[0] + eo[0];
392
605k
                e[3] = ee[0] - eo[0];
393
605k
                e[1] = ee[1] + eo[1];
394
605k
                e[2] = ee[1] - eo[1];
395
3.02M
                for(k = 0; k < 4; k++)
396
2.41M
                {
397
2.41M
                    WORD32 itrans_out;
398
2.41M
                    itrans_out =
399
2.41M
                                    CLIP_S16( ((e[k] + o[k] + add)>>shift ) );
400
2.41M
                    pu2_dst[k] = CLIP3((itrans_out + pu2_pred[k]), 0, clip_limit);
401
2.41M
                    itrans_out =
402
2.41M
                                    CLIP_S16( ((e[3-k] - o[3-k] + add)>>shift ) );
403
2.41M
                    pu2_dst[k + 4] = CLIP3((itrans_out + pu2_pred[k + 4] ), 0, clip_limit);
404
2.41M
                }
405
605k
                pi2_tmp++;
406
605k
                pu2_pred += pred_strd;
407
605k
                pu2_dst += dst_strd;
408
605k
            }
409
75.2k
        }
410
        /************************************************************************************************/
411
        /************************************END - IT_RECON_8x8******************************************/
412
        /************************************************************************************************/
413
266k
    }
414
748k
}