-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cpp
97 lines (88 loc) · 2.56 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
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
#include "SeamCarving.hpp"
#include <iostream>
void arg3Behavior(int argc, char *argv[], int n=100) {
if(strcmp(argv[2],"-v") == 0) {
SeamCarvingVertical sm(argv[1],n);
sm.showImage();
}
else if(strcmp(argv[2],"-h") == 0) {
SeamCarvingHorizontal sm(argv[1],n);
sm.showImage();
}
else {
std::cout << "usage ./exec <image>.png -h|-v" << std::endl;
}
}
void arg6Behavior(int argc, char *argv[]) {
int verticle = 0;
int grow = 0;
int numberSeams = 0;
char* imgPath = argv[1];
std::cout << imgPath << std::endl;
for (int i = 2; i < argc; i++) {
char* curParam = argv[i];
if( strcmp(argv[i],"-h") == 0 ) {
verticle = false;
}
else if ( strcmp(argv[i],"-v") == 0 ) {
verticle = true;
}
else if ( strcmp(argv[i],"-g") == 0 ) {
grow = true;
}
else if ( strcmp(argv[i],"-r") == 0 ) {
grow = false;
}
else if ( strcmp(argv[i],"-n") == 0 ) {
int n = atoi(argv[++i]);
if(n != 0) {
numberSeams = n;
} else {
std::cout << "error: value after -n is not a number" << std::endl;
std::cout << "usage ./exec <image>.png -h|-v -n <number>" << std::endl;
}
}
else {
std::cout << "error: unrecognized parameter" << std::endl;
std::cout << "usage ./exec <image>.png -h|-v -r|-g -n <number>" << std::endl;
}
}
if ( verticle ) {
SeamCarvingVertical sm(imgPath, numberSeams, grow);
sm.showImage();
}
else {
SeamCarvingHorizontal sm(imgPath, numberSeams, grow);
sm.showImage();
}
}
int main(int argc, char *argv[]) {
if(argc == 6) {
arg6Behavior(argc, argv);
}
else if( argc == 5) {
if(strcmp(argv[3],"-n") == 0) {
int n = atoi(argv[4]);
if(n != 0) {
arg3Behavior(argc,argv,n);
} else {
std::cout << "error: value after -n is not a number" << std::endl;
std::cout << "usage ./exec <image>.png -h|-v -n <number>" << std::endl;
}
}
else {
std::cout << "usage ./exec <image>.png -h|-v -n <number>" << std::endl;
}
}
else if( argc == 3) {
arg3Behavior(argc,argv);
}
else if( argc == 2)
{
SeamCarvingHorizontal sm(argv[1]);
sm.showImage();
} else {
std::cout << "usage ./exec <image>.png" << std::endl;
}
return 0;
}