@@ -10,6 +10,31 @@ const ll MAX = 4294967295;
10
10
ll lower[257 ];
11
11
vector <ll> low, high;
12
12
13
+ int parseLine (char * line){
14
+ // This assumes that a digit will be found and the line ends in " Kb".
15
+ int i = strlen (line);
16
+ const char * p = line;
17
+ while (*p <' 0' || *p > ' 9' ) p++;
18
+ line[i-3 ] = ' \0 ' ;
19
+ i = atoi (p);
20
+ return i;
21
+ }
22
+
23
+ int getValue (){ // Note: this value is in KB!
24
+ FILE* file = fopen (" /proc/self/status" , " r" );
25
+ int result = -1 ;
26
+ char line[128 ];
27
+
28
+ while (fgets (line, 128 , file) != NULL ){
29
+ if (strncmp (line, " VmRSS:" , 6 ) == 0 ){
30
+ result = parseLine (line);
31
+ break ;
32
+ }
33
+ }
34
+ fclose (file);
35
+ return result;
36
+ }
37
+
13
38
string write_bits (bool bit, int bit_to_fall){
14
39
string tmp;
15
40
tmp += to_string (bit);
@@ -55,6 +80,7 @@ ofstream out("arithmetic_encoded.txt");
55
80
56
81
string image_pixels = " " ;
57
82
string code = " " ;
83
+ uint8_t * rgb_image;
58
84
59
85
int main (int argc, char ** argv)
60
86
{
@@ -78,18 +104,18 @@ int main(int argc, char** argv)
78
104
num_channel = 3 ;
79
105
}
80
106
81
- // string filename;
82
- // cin>>filename;
107
+ string filename;
108
+ cin>>filename;
83
109
84
- uint8_t * rgb_image = stbi_load (" ./images/9.png" , &width, &height, &bpp, num_channel);
110
+ auto start = chrono::high_resolution_clock::now ();
111
+
112
+ rgb_image = stbi_load (filename.c_str (), &width, &height, &bpp, num_channel);
85
113
86
114
const ll ONE_QTR = MAX / 4 + 1 ;
87
115
const ll HALF = 2 * ONE_QTR;
88
116
const ll THREE_QTR = 3 * ONE_QTR;
89
117
90
118
int len = height*width*num_channel + 1 ;
91
- cout<<height<<" " <<width<<" " <<num_channel<<" \n " ;
92
- cout<<len<<" \n " ;
93
119
94
120
low.resize (len+1 );
95
121
high.resize (len+1 );
@@ -163,10 +189,18 @@ int main(int argc, char** argv)
163
189
out << lower[i] << " " ;
164
190
165
191
out << code << " \n " ;
166
-
167
- cout<<code.size ()<<" \n " ;
168
192
169
193
out << height << " " << width << " " << num_channel << " \n " ;
170
194
195
+ auto stop = chrono::high_resolution_clock::now ();
196
+ auto duration = chrono::duration_cast<chrono::microseconds>(stop - start);
197
+
198
+ cout<<filename<<" ," ;
199
+ float NoBpp = ((float )code.size ())/(height*width*num_channel);
200
+ float cp = (1 - ((float )code.size ())/(height*width*num_channel*8 ))*100 ;
201
+ cout<<height*width*num_channel<<" ," <<cp<<" ," ;
202
+ cout<<NoBpp<<" ," <<(duration.count ()/1000000.0 )<<" ," ;
203
+ cout<<getValue ()<<" ," ;
204
+
171
205
return 0 ;
172
206
}
0 commit comments