-
Notifications
You must be signed in to change notification settings - Fork 0
/
histogram.c
53 lines (44 loc) · 1.47 KB
/
histogram.c
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
#include "histogram.h"
void histogram_calculation( uint8_t * bufferIn , size_t bufferSize , histogram_dataCalc_t * histogram_dataCalc )
{
if( bufferIn == ( uint8_t * ) NULL )
{
return ;
}
if( histogram_dataCalc == ( histogram_dataCalc_t * ) NULL )
{
return ;
}
if( bufferSize == 0 )
{
return ;
}
for( uint16_t i = 0 ; i < 256 ; i++ )
{
histogram_dataCalc[ i ].data = ( uint8_t ) i ;
histogram_dataCalc[ i ].frequency = 0 ;
}
for( size_t count = 0 ; count < bufferSize ; count++ )
{
histogram_dataCalc[ bufferIn[ count ] ].frequency++ ;
}
}
void histogram_generateTable( histogram_dataCalc_t * histogram_dataCalc , uint8_t * tableOut )
{
for( uint16_t i = 0 ; i < 256 ; i++ )
{
for( uint16_t j = 0 ; j < 256 ; j++ )
{
if( histogram_dataCalc[ i ].frequency > histogram_dataCalc[ j ].frequency )
{
histogram_dataCalc_t histSwap ;
histSwap.data = histogram_dataCalc[ i ].data ;
histSwap.frequency = histogram_dataCalc[ i ].frequency ;
histogram_dataCalc[ i ].data = histogram_dataCalc[ j ].data ;
histogram_dataCalc[ i ].frequency = histogram_dataCalc[ j ].frequency ;
histogram_dataCalc[ i ].data = histSwap.data ;
histogram_dataCalc[ i ].frequency = histSwap.frequency ;
}
}
}
}