-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdsp_test_omx.c
102 lines (87 loc) · 2.76 KB
/
dsp_test_omx.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
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
#include "dsp.c"
#define NUM_ITER 30
#define IMG_SIZE 4096
#define HISTO_SIZE 256
#define NUM_TOTAL_THREADS 5
int* histo[NUM_TOTAL_THREADS] ;
int dsp_histo[HISTO_SIZE] ;
int dsp_gray_level_mapping[HISTO_SIZE] ;
void* compute_histo(int* image, int* histo, int img_start_indx, int img_end_indx)
{
int i, j ;
for (i = 0 ; i < HISTO_SIZE ; i++) {
histo[0*HISTO_SIZE+i] = 0;
}
for (i = img_start_indx ; i < img_end_indx ; i++) {
for (j = 0; j < IMG_SIZE; ++j) {
image[i*IMG_SIZE+j] = (i*j) % 255 ;
}
}
/* Compute the image's histogram */
for (i = img_start_indx ; i < img_end_indx ; i++) {
for (j = 0; j < IMG_SIZE; ++j) {
int pix = image[i*IMG_SIZE+j] ;
histo[0*HISTO_SIZE+pix] += 1;
}
}
return NULL ;
}
void* compute_image(int* image, int* gray_level_mapping, int img_start_indx, int img_end_indx)
{
int i, j ;
/* Map the old gray levels in the original image to the new gray levels. */
for (i = img_start_indx ; i < img_end_indx ; i++) {
for (j = 0; j < IMG_SIZE; ++j) {
int pix = image[i*IMG_SIZE+j] ;
image[i*IMG_SIZE+j] = gray_level_mapping[pix];
}
}
return NULL ;
}
void compute_gray_level_mapping()
{
int j, k ;
float cdf, pixels ;
for(j=0 ; j<NUM_TOTAL_THREADS ; j++) {
for(k=0 ; k<HISTO_SIZE ; k++) {
if(j==0)
dsp_histo[k] = (histo[j])[k] ;
else
dsp_histo[k] += (histo[j])[k] ;
}
}
cdf = 0.0 ;
pixels = (float)(IMG_SIZE * IMG_SIZE) ;
for(j=0 ; j<HISTO_SIZE ; j++) {
cdf += ((float)(dsp_histo[j]))/pixels ;
dsp_gray_level_mapping[j] = (int)(255.0 * cdf) ;
}
}
Int32 fxnTest1(UInt32 size, UInt32 *data)
{
UInt32 start_indx,end_indx;
FxnArgs *args = (FxnArgs *)((UInt32)data + sizeof(map_info_type));
start_indx = args->start_indx;
end_indx = args->end_indx;
#if CHATTER
System_printf("fxnInit : Executing fxnTest1\n");
#endif
int* image = (int*)(args->a) ;
int* tmp_histo = (int*)(args->f) ;
histo[0] = (int*)(args->b) ;
histo[1] = (int*)(args->c) ;
histo[2] = (int*)(args->d) ;
histo[3] = (int*)(args->e) ;
histo[4] = (int*)(args->f) ;
int i ;
for(i=0 ; i<NUM_ITER ; i++) {
callBarrier(0, /*lock_id=*/4) ;
compute_histo(image, tmp_histo, start_indx, end_indx) ;
Cache_wbInv (tmp_histo, HISTO_SIZE*4, Cache_Type_ALL, FALSE);
callBarrier(1, /*lock_id=*/4) ;
compute_gray_level_mapping() ;
compute_image(image, dsp_gray_level_mapping, start_indx, end_indx) ;
Cache_wbInv (image, IMG_SIZE*IMG_SIZE*4, Cache_Type_ALL, FALSE);
}
return 1 ;
}