-
Notifications
You must be signed in to change notification settings - Fork 0
/
loop_inversion_unroll_3.c
156 lines (129 loc) · 2.59 KB
/
loop_inversion_unroll_3.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#define N 200 /* frame dimension for QCIF format */
#define M 200 /* frame dimension for QCIF format */
#define filename "sunflower_200x200_444.yuv"
#define file_yuv "sunflower_444_yuv_output.yuv"
/* code for armulator*/
#pragma arm section zidata="manual"
int new_y[N][M];
int current_y[N][M];
#pragma arm section zidata="sram"
int buffer1[M];
int buffer2[M];
int buffer3[M];
int i,j,k;
#pragma arm section
int current_u[N][M];
int current_v[N][M];
void read()
{
FILE *frame_c;
if((frame_c=fopen(filename,"rb"))==NULL)
{
printf("current frame doesn't exist\n");
exit(-1);
}
for(i=0;i<N;i++)
{
for(j=0;j<M;j++)
{
current_y[i][j]=fgetc(frame_c);
}
}
for(i=0;i<N;i++)
{
for(j=0;j<M;j++)
{
current_u[i][j]=fgetc(frame_c);
}
}
for(i=0;i<N;i++)
{
for(j=0;j<M;j++)
{
current_v[i][j]=fgetc(frame_c);
}
}
fclose(frame_c);
}
void write()
{
FILE *frame_yuv;
frame_yuv=fopen(file_yuv,"wb");
for(i=0;i<N;i++)
{
for(j=0;j<M;j++)
{
fputc(new_y[i][j],frame_yuv);
}
}
for(i=0;i<N;i++)
{
for(j=0;j<M;j++)
{
fputc(current_u[i][j],frame_yuv);
}
}
for(i=0;i<N;i++)
{
for(j=0;j<M;j++)
{
fputc(current_v[i][j],frame_yuv);
}
}
fclose(frame_yuv);
}
void filtering () {
for (i=0; i<N; i++)
{
if(i==0) {
for(k=0;k<M;k++) {
buffer1[k]=current_y[0][k];
buffer2[k]=current_y[1][k];
buffer3[k]=current_y[2][k];
}
}else{
for(k=0;k<M;k++){
buffer1[k]=buffer2[k];
buffer2[k]=buffer3[k];
buffer3[k]=current_y[i][j];
}
}
}
}
int main()
{
int i;
int j;
double g;
double noisyImage_y[N][M];
int k=3;
read();
filtering();
i = 0;
j = 0;
if(i<N){
if(j<M){
do{
g = buffer1[j];
noisyImage_y[i][j] = ((exp(-g))*(g*g*g))/ ((k-2)*(k-1)*(k));
new_y[i][j] =noisyImage_y[i][j];
g = buffer1[j+1];
noisyImage_y[i+1][j+1] = ((exp(-g))*(g*g*g))/ ((k-2)*(k-1)*(k));
new_y[i+1][j+1] =noisyImage_y[i+1][j+1];
g = buffer1[j+2];
noisyImage_y[i+2][j+2] = ((exp(-g))*(g*g*g))/ ((k-2)*(k-1)*(k));
new_y[i+2][j+2] =noisyImage_y[i+2][j+2];
g = buffer1[j+3];
noisyImage_y[i+3][j+3] = ((exp(-g))*(g*g*g))/ ((k-2)*(k-1)*(k));
new_y[i+3][j+3] =noisyImage_y[i+3][j+3];
i=i+4;
j=j+4;
} while( j<M);
} while(i<N);
}
write();
}