-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
59 lines (47 loc) · 1.44 KB
/
main.cpp
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
#include <cstdio>
#include <cstring>
#include <string>
#include "decoder.h"
#include "encoder.h"
void call(const char *file_name) {
std::string file_in_name, file_out_name, file_out_out_name;
int len = strlen(file_name);
int point_idx = -1;
for (int i = len-1; i >= 0; --i) {
if (file_name[i] == '/' or
file_name[i] == '\\') break;
if (file_name[i] == '.') {
point_idx = i;
break;
}
}
file_in_name = file_out_name = file_out_out_name = file_name;
if (point_idx == -1) {
file_in_name += ".jpg";
file_out_name += ".bmp";
file_out_out_name += "_from_bmp.jpg";
} else {
file_out_name.replace(point_idx, 4, ".bmp");
file_out_out_name.replace(point_idx, 4, "_from_bmp.jpg");
}
printf("Input file name: %s\n", file_in_name.c_str());
try {
printf("Output jpeg->bmp file name: %s\n", file_out_name.c_str());
Decoder(file_in_name, file_out_name).solve();
printf("Output jpeg->bmp->jpeg file name: %s\n", file_out_out_name.c_str());
Encoder(file_out_name, file_out_out_name).solve();
} catch (const char *err_msg) {
puts(err_msg);
} catch (std::string str) {
puts(str.c_str());
}
}
int main(int argc, char *argv[]) {
if (argc == 1) {
call("monalisa");
} else {
for (int i = 1; i < argc; ++i)
call(argv[i]);
}
return 0;
}