@@ -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);
@@ -24,6 +49,7 @@ ofstream out("arithmetic_encoded.txt");
24
49
25
50
string image_pixels = " " ;
26
51
string code = " " ;
52
+ uint8_t * rgb_image;
27
53
28
54
int main (int argc, char ** argv)
29
55
{
@@ -47,18 +73,18 @@ int main(int argc, char** argv)
47
73
num_channel = 3 ;
48
74
}
49
75
50
- // string filename;
51
- // cin>>filename;
76
+ string filename;
77
+ cin>>filename;
52
78
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);
54
82
55
83
const ll ONE_QTR = MAX / 4 + 1 ;
56
84
const ll HALF = 2 * ONE_QTR;
57
85
const ll THREE_QTR = 3 * ONE_QTR;
58
86
59
87
int len = height*width*num_channel + 1 ;
60
- cout<<height<<" " <<width<<" " <<num_channel<<" \n " ;
61
- cout<<len<<" \n " ;
62
88
63
89
low.resize (len+1 );
64
90
high.resize (len+1 );
@@ -132,10 +158,18 @@ int main(int argc, char** argv)
132
158
out << lower[i] << " " ;
133
159
134
160
out << code << " \n " ;
135
-
136
- cout<<code.size ()<<" \n " ;
137
161
138
162
out << height << " " << width << " " << num_channel << " \n " ;
139
163
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
+
140
174
return 0 ;
141
175
}
0 commit comments