-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakeAniV3.cpp
135 lines (115 loc) · 2.53 KB
/
makeAniV3.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include <iostream>
#include <Magick++.h>
//#include "makeAniV3.h"
#include "AniGIFMaker.h"
using std::cout;
using std::cin;
using std::endl;
using namespace Magick;
void parseArgs(double &tolerance, bool &cOption, char &mode, char **inputSize, char **outfilename, int *&files, const int argc, char **argv);//
bool isCompatible(const char *input);
int main(int argc, char** argv)
{
double tolerance=3;
bool cOption=false;
char mode='m';
char *outfilename=NULL;
char *inputSize=NULL;
int *files=new int[argc];
for(int i=0; i<argc; i++) {
files[i]=0;
}
Geometry imgGeo(0, 0);
Geometry pageGeo(0, 0);
parseArgs(tolerance, cOption, mode, &inputSize, &outfilename, files, argc, argv);
AniGIFMaker maker(tolerance, cOption, mode, inputSize);
int cnt=0;
while(files[cnt]!=0) {
cout << "argv : " << argv[files[cnt]] << endl;
maker.addToAniGIF(argv[files[cnt]]);
cnt++;
}
maker.makeAniGIF(outfilename);
//DEBUG
/*
cout << tolerance << " " << cOption << " " << mode << " ";
if(inputSize!=NULL) {
cout << *inputSize << " ";
} else {
cout << "NULL ";
}
if(outfilename!=NULL) {
cout << *outfilename << " ";
} else {
cout << "NONAME ";
}
cout << endl;
*/
/*
for(int i=0; i<argc; i++)
{
cout << files[i] << " ";
}
cout << endl;
*/
delete[] files;
return 0;
}
void parseArgs(double &tolerance, bool &cOption, char &mode, char **inputSize, char **outfilename, int *&files, const int argc, char **argv)
{
int fileCnt=0;
for(int i=1; i<argc; i++) {
if(argv[i][0]=='-') {
switch(argv[i][1]) {
case 'c':
cOption=true;
break;
case 'w':
case 'h':
case 'm':
case 'f':
case 'a':
mode=argv[i][1];
*inputSize=argv[i+1];
if(!isCompatible(*inputSize)) {
cout << "Incompatible Size Error. Exiting..." << endl;
exit(EXIT_FAILURE);
}
i++;
break;
case 't':
if(!isCompatible(argv[i+1])) {
cout << "Incompatible Tolerance Error. Exiting..." << endl;
exit(EXIT_FAILURE);
}
tolerance=atof(argv[i+1]);
if(tolerance<1) {
tolerance = 1/tolerance;
}
i++;
break;
case 'o':
*outfilename=argv[i+1];
i++;
break;
default:
cout << "Not In Option! Ignoring..." << endl;
break;
}
} else {
cout << "Default Argv : Consider it to Input Filename" << endl;
files[fileCnt++]=i;
}
}
}
bool isCompatible(const char *input)
{
char copy[21];
strncpy(copy, input, 20);
char *token=strtok(copy, "x");
double number=atof(token);
if(number<=0) {
return false;
}
return true;
}