-
Notifications
You must be signed in to change notification settings - Fork 1
/
settings.cpp
executable file
·152 lines (142 loc) · 3.54 KB
/
settings.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// settings definitions
#include "settings.h"
#include <cstdlib>
#include <iostream>
// bailOut function
void Settings::bailOut(const char err[]) {
std::cout << "Command line parameters: " << std::endl;
std::cout << " " << err << std::endl;
exit(-2);
}
// checks whenever params are OK to go
// exits app when something wrong
void Settings::checkUsability() {
// mode 1: read file, output file
if(!(inputImage.empty() || outputImage.empty())) {
mode = imageToImage;
// mode 2: read file, save to bitstream
} else if(!(inputImage.empty() || bitStreamFile.empty())) {
mode = imageToBitstream;
// mode 3: read bitstream, save to file
} else if(!(outputImage.empty() || bitStreamFile.empty())) {
mode = bitstreamToImage;
// all other choices ==> error
} else {
bailOut("Unsupported mode of operation. Read ReadMe.txt and specify files correctly!");
}
}
// class Settings constructor
Settings::Settings(int arc, char** arv)
: computeDeepVariance(COMPUTE_DEEP_VARIANCE), biasCR(BIAS_CR), biasCB(BIAS_CB) {
// setting default values
inputImage = std::string("");
outputImage = std::string("");
bitStreamFile = std::string("");
cspihtFlag = false;
dspihtFlag = false;
levels = 3;
colorShift = 0;
varianceDepth = 0;
bits = 2048;
bpp = 0.0;
mode = notDefined;
// outputs
printDebug = false;
printTiming = false;
printExtended = false;
// parse the arguments
if(arc > 1) {
unsigned i=1;
while(i < (unsigned) arc) {
if(arv[i][0] == '-') {
switch(arv[i][1]) {
case 'i':
if(++i < (unsigned) arc) {
inputImage.assign(arv[i]);
} else {
bailOut("Input image file not specified.");
}
break;
case 'o':
if(++i < (unsigned) arc) {
outputImage.assign(arv[i]);
} else {
bailOut("Output image file not specified.");
}
break;
case 'b':
if(++i < (unsigned) arc) {
bitStreamFile.assign(arv[i]);
} else {
bailOut("Bitstream file not specified.");
}
break;
case 'c':
cspihtFlag = true;
break;
case 'D':
printDebug = true;
break;
case 'E':
printExtended = true;
break;
case 'T':
printTiming = true;
break;
case 'd':
dspihtFlag = true;
break;
case 'l':
if(++i < (unsigned) arc) {
levels = (unsigned) atoi(arv[i]);
if(levels == 0) {
bailOut("Levels must be positive and nonzero.");
}
} else {
bailOut("Levels number not specified.");
}
break;
case 'S':
if(++i < (unsigned) arc) {
colorShift = (unsigned) atoi(arv[i]);
if(colorShift < 0) {
bailOut("Colorshift must be positive.");
}
} else {
bailOut("Colorshift number not specified.");
}
break;
case 'v':
if(++i < (unsigned) arc) {
varianceDepth = (unsigned) atoi(arv[i]);
} else {
bailOut("Variance depth number not specified.");
}
break;
case 'B':
if(++i < (unsigned) arc) {
bits = (unsigned) atoi(arv[i]);
} else {
bailOut("Bits number not specified.");
}
break;
case 'p':
if(++i < (unsigned) arc) {
bpp = (float) atof(arv[i]);
if(bpp <= 0) {
bailOut("Bpp must be a floating-point number greater than zero (0.0).");
}
} else {
bailOut("Bpp number not specified.");
}
break;
}
} else {
bailOut("Invalid specification. See ReadMe.txt for parameter layout.");
}
// increment
i++;
}
}
checkUsability();
}