Coverage Report

Created: 2025-11-24 06:46

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libhevc/encoder/hme_common_utils.c
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2018 The Android Open Source Project
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
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
21
/*****************************************************************************/
22
/* File Includes                                                             */
23
/*****************************************************************************/
24
/* System include files */
25
#include <stdio.h>
26
#include <assert.h>
27
#include <stdlib.h>
28
#include <math.h>
29
#include <time.h>
30
31
/* User include files */
32
#include "ihevc_typedefs.h"
33
#include "ihevc_macros.h"
34
#include "ihevc_debug.h"
35
#include "ihevc_platform_macros.h"
36
37
#include "hme_datatype.h"
38
#include "hme_common_defs.h"
39
40
/*****************************************************************************/
41
/* Function Definitions                                                      */
42
/*****************************************************************************/
43
44
/**
45
********************************************************************************
46
*  @fn     S16 median4_s16(S16 i2_n1, S16 i2_n2, S16 i2_n3, S16 i2_n4);
47
*
48
*  @brief  Returns median4 of 4 16 bits signed nubers
49
*
50
*  @param[in] i2_n1 : first number
51
*
52
*  @param[in] i2_n2 : 2nd number
53
*
54
*  @param[in] i2_n3 : 3rd number
55
*
56
*  @param[in] i2_n4 : 4th number (order does not matter)
57
*
58
*  @return range of the number
59
********************************************************************************
60
*/
61
S16 median4_s16(S16 i2_n1, S16 i2_n2, S16 i2_n3, S16 i2_n4)
62
0
{
63
0
    S16 i2_max, i2_min;
64
65
0
    i2_max = MAX(i2_n1, i2_n2);
66
0
    i2_max = MAX(i2_max, i2_n3);
67
0
    i2_max = MAX(i2_max, i2_n4);
68
69
0
    i2_min = MIN(i2_n1, i2_n2);
70
0
    i2_min = MIN(i2_min, i2_n3);
71
0
    i2_min = MIN(i2_min, i2_n4);
72
73
0
    return ((S16)((i2_n1 + i2_n2 + i2_n3 + i2_n4 - i2_max - i2_min) >> 1));
74
0
}
75
76
U32 hme_compute_2d_sum_u08(U08 *pu1_inp, S32 i4_wd, S32 i4_ht, S32 i4_stride)
77
0
{
78
0
    S32 i, j;
79
0
    U32 u4_sum = 0;
80
81
0
    for(i = 0; i < i4_ht; i++)
82
0
    {
83
0
        for(j = 0; j < i4_wd; j++)
84
0
            u4_sum += (U32)pu1_inp[j];
85
86
0
        pu1_inp += i4_stride;
87
0
    }
88
89
0
    return (u4_sum);
90
0
}
91
U32 hme_compute_2d_sum_u16(U16 *pu2_inp, S32 i4_wd, S32 i4_ht, S32 i4_stride)
92
0
{
93
0
    S32 i, j;
94
0
    U32 u4_sum = 0;
95
96
0
    for(i = 0; i < i4_ht; i++)
97
0
    {
98
0
        for(j = 0; j < i4_wd; j++)
99
0
            u4_sum += (U32)pu2_inp[j];
100
101
0
        pu2_inp += i4_stride;
102
0
    }
103
104
0
    return (u4_sum);
105
0
}
106
U32 hme_compute_2d_sum_u32(U32 *pu4_inp, S32 i4_wd, S32 i4_ht, S32 i4_stride)
107
70.4M
{
108
70.4M
    S32 i, j;
109
70.4M
    U32 u4_sum = 0;
110
111
422M
    for(i = 0; i < i4_ht; i++)
112
352M
    {
113
2.11G
        for(j = 0; j < i4_wd; j++)
114
1.76G
            u4_sum += (U32)pu4_inp[j];
115
116
352M
        pu4_inp += i4_stride;
117
352M
    }
118
119
70.4M
    return (u4_sum);
120
70.4M
}
121
/**
122
********************************************************************************
123
*  @fn     S32 hme_compute_2d_sum_unsigned(void *pv_inp,
124
*                                       S32 i4_blk_wd,
125
*                                       S32 i4_blk_ht,
126
*                                   S32 i4_stride,
127
*                                   S32 i4_datatype)
128
*
129
*  @brief  Computes and returns 2D sum of a unsigned 2d buffer, with datatype
130
*          equal to 8/16/32 bit.
131
*
132
*  @param[in] pv_inp : input pointer
133
*
134
*  @param[in] i4_blk_wd : block width
135
*
136
*  @param[in] i4_blk_ht : block ht
137
*
138
*  @param[in] i4_stride : stride
139
*
140
*  @param[in] i4_datatype : datatype 1 - 8 bit, 2 - 16 bit, 4 - 32 bit
141
*
142
*  @return sum of i4_blk_wd * i4_blk_ht number of entries starting at pv_inp
143
********************************************************************************
144
*/
145
146
U32 hme_compute_2d_sum_unsigned(
147
    void *pv_inp, S32 i4_blk_wd, S32 i4_blk_ht, S32 i4_stride, S32 i4_datatype)
148
70.4M
{
149
70.4M
    if(i4_datatype == sizeof(U08))
150
0
        return (hme_compute_2d_sum_u08((U08 *)pv_inp, i4_blk_wd, i4_blk_ht, i4_stride));
151
70.4M
    else if(i4_datatype == sizeof(U16))
152
0
        return (hme_compute_2d_sum_u16((U16 *)pv_inp, i4_blk_wd, i4_blk_ht, i4_stride));
153
70.4M
    else if(i4_datatype == sizeof(U32))
154
70.4M
        return (hme_compute_2d_sum_u32((U32 *)pv_inp, i4_blk_wd, i4_blk_ht, i4_stride));
155
0
    else
156
70.4M
        ASSERT(0);
157
158
0
    return 0;
159
70.4M
}
160
161
/**
162
********************************************************************************
163
*  @fn     S32 get_rand_num(S32 low, S32 high)
164
*
165
*  @brief  returns a radom integer in the closed interval [low, high - 1]
166
*
167
*  @param[in] low : lower limit
168
*
169
*  @param[in] high : higher limit
170
*
171
*  @return S32 result: the random number
172
********************************************************************************
173
*/
174
S32 get_rand_num(S32 low, S32 high)
175
0
{
176
0
    double num;
177
0
    S32 result;
178
0
    num = (double)rand() / (double)RAND_MAX;
179
0
    num = num * (high - low) + low;
180
181
0
    result = (S32)floor((num + 0.5));
182
0
    if(result < low)
183
0
        result = low;
184
0
    if(result >= high)
185
0
        result = high - 1;
186
187
0
    return (result);
188
0
}