@@ -10,6 +10,31 @@ const ll MAX = 4294967295;
1010ll lower[257 ];
1111vector <ll> low, high;
1212
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+
1338string write_bits (bool bit, int bit_to_fall){
1439 string tmp;
1540 tmp += to_string (bit);
@@ -24,6 +49,7 @@ ofstream out("arithmetic_encoded.txt");
2449
2550string image_pixels = " " ;
2651string code = " " ;
52+ uint8_t * rgb_image;
2753
2854int main (int argc, char ** argv)
2955{
@@ -47,18 +73,18 @@ int main(int argc, char** argv)
4773 num_channel = 3 ;
4874 }
4975
50- // string filename;
51- // cin>>filename;
76+ string filename;
77+ cin>>filename;
5278
53- uint8_t * rgb_image = stbi_load (" ./images/9.png" , &width, &height, &bpp, num_channel);
79+ auto start = chrono::high_resolution_clock::now ();
80+
81+ rgb_image = stbi_load (filename.c_str (), &width, &height, &bpp, num_channel);
5482
5583 const ll ONE_QTR = MAX / 4 + 1 ;
5684 const ll HALF = 2 * ONE_QTR;
5785 const ll THREE_QTR = 3 * ONE_QTR;
5886
5987 int len = height*width*num_channel + 1 ;
60- cout<<height<<" " <<width<<" " <<num_channel<<" \n " ;
61- cout<<len<<" \n " ;
6288
6389 low.resize (len+1 );
6490 high.resize (len+1 );
@@ -132,10 +158,18 @@ int main(int argc, char** argv)
132158 out << lower[i] << " " ;
133159
134160 out << code << " \n " ;
135-
136- cout<<code.size ()<<" \n " ;
137161
138162 out << height << " " << width << " " << num_channel << " \n " ;
139163
164+ auto stop = chrono::high_resolution_clock::now ();
165+ auto duration = chrono::duration_cast<chrono::microseconds>(stop - start);
166+
167+ cout<<filename<<" ," ;
168+ float NoBpp = ((float )code.size ())/(height*width*num_channel);
169+ float cp = (1 - ((float )code.size ())/(height*width*num_channel*8 ))*100 ;
170+ cout<<height*width*num_channel<<" ," <<cp<<" ," ;
171+ cout<<NoBpp<<" ," <<(duration.count ()/1000000.0 )<<" ," ;
172+ cout<<getValue ()<<" ," ;
173+
140174 return 0 ;
141175}
0 commit comments