forked from 4lex4/scantailor-advanced
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommandLine.h
357 lines (223 loc) · 10.9 KB
/
CommandLine.h
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
/*
Scan Tailor - Interactive post-processing tool for scanned pages.
CommandLine - Interface for ScanTailor's parameters provided on CL.
Copyright (C) 2011 Petr Kovar <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef COMMANDLINE_H_
#define COMMANDLINE_H_
#include <QMap>
#include <QRectF>
#include <QStringList>
#include <iostream>
#include "AutoManualMode.h"
#include "Despeckle.h"
#include "Dpi.h"
#include "ImageFileInfo.h"
#include "Margins.h"
#include "filters/output/ColorParams.h"
#include "filters/output/DepthPerception.h"
#include "filters/output/DespeckleLevel.h"
#include "filters/output/DewarpingOptions.h"
#include "filters/output/Params.h"
#include "filters/page_layout/Alignment.h"
#include "filters/page_layout/Settings.h"
#include "filters/page_split/LayoutType.h"
namespace page_layout {
class Alignment;
}
/**
* CommandLine is a singleton simulation.
* use CommandLine::get() to get access to global class
* use CommandLine::set(const CommandLine&) to set the global class
*/
class CommandLine {
// Member-wise copying is OK.
public:
enum Orientation { TOP, LEFT, RIGHT, UPSIDEDOWN };
static const CommandLine& get() { return m_globalInstance; }
static void set(const CommandLine& cl);
explicit CommandLine(const QStringList& argv, bool g = true)
: m_error(false), m_gui(g), m_global(false), m_defaultNull(false) {
CommandLine::parseCli(argv);
}
bool isGui() const { return m_gui; }
bool isVerbose() const { return contains("verbose"); }
bool isError() const { return m_error; }
const std::vector<ImageFileInfo>& images() const { return m_images; }
const QString& outputDirectory() const { return m_outputDirectory; }
const QString& projectFile() const { return m_projectFile; }
const QString& outputProjectFile() const { return m_outputProjectFile; }
bool isContentDetectionEnabled() const { return !contains("disable-content-detection"); }
bool isPageDetectionEnabled() const { return contains("enable-page-detection"); }
bool isForcePageDetectionDisabled() const { return contains("force-disable-page-detection"); }
bool isFineTuningEnabled() const { return contains("enable-fine-tuning"); }
bool isAutoMarginsEnabled() const { return contains("enable-auto-margins"); }
bool hasMargins(QString base = "margins") const;
bool hasPageBorders() const { return hasMargins("page-borders"); }
bool hasAlignment() const;
bool hasOutputDpi() const;
bool hasLanguage() const;
bool hasHelp() const { return contains("help"); }
bool hasOutputProject() const { return contains("output-project") && !m_options["output-project"].isEmpty(); }
bool hasLayout() const { return contains("layout") && !m_options["layout"].isEmpty(); }
bool hasLayoutDirection() const { return contains("layout-direction") && !m_options["layout-direction"].isEmpty(); }
bool hasStartFilterIdx() const { return contains("start-filter") && !m_options["start-filter"].isEmpty(); }
bool hasEndFilterIdx() const { return contains("end-filter") && !m_options["end-filter"].isEmpty(); }
bool hasOrientation() const { return contains("orientation") && !m_options["orientation"].isEmpty(); }
bool hasDeskewAngle() const { return contains("rotate") && !m_options["rotate"].isEmpty(); }
bool hasDeskew() const { return contains("deskew") && !m_options["deskew"].isEmpty(); }
bool hasSkewDeviation() const { return contains("skew-deviation") && !m_options["skew-deviation"].isEmpty(); }
bool hasContentRect() const { return contains("content-box") && !m_options["content-box"].isEmpty(); }
bool hasContentDeviation() const {
return contains("content-deviation") && !m_options["content-deviation"].isEmpty();
}
bool hasContentDetection() const { return !contains("disable-content-detection"); }
bool hasContentText() const { return !contains("disable-content-text-mask"); }
bool hasColorMode() const { return contains("color-mode") && !m_options["color-mode"].isEmpty(); }
bool hasDefaultColorMode() const {
return contains("default-color-mode") && !m_options["default-color-mode"].isEmpty();
}
bool hasPictureShape() const { return contains("picture-shape") && !m_options["picture-shape"].isEmpty(); }
bool hasFillMargins() const { return contains("fill-margins"); }
bool hasNormalizeIllumination() const { return contains("normalize-illumination"); }
bool hasThreshold() const { return contains("threshold") && !m_options["threshold"].isEmpty(); }
bool hasDespeckle() const { return contains("despeckle") && !m_options["despeckle"].isEmpty(); }
bool hasDewarping() const { return contains("dewarping"); }
bool hasMatchLayoutTolerance() const {
return contains("match-layout-tolerance") && !m_options["match-layout-tolerance"].isEmpty();
}
bool hasDepthPerception() const { return contains("depth-perception") && !m_options["depth-perception"].isEmpty(); }
bool hasTiffForceRGB() const { return contains("tiff-force-rgb"); }
bool hasTiffForceGrayscale() const { return contains("tiff-force-grayscale"); }
bool hasTiffForceKeepColorSpace() const { return contains("tiff-force-keep-color-space"); }
bool hasWindowTitle() const { return contains("window-title") && !m_options["window-title"].isEmpty(); }
bool hasPageDetectionBox() const {
return contains("page-detection-box") && !m_options["page-detection-box"].isEmpty();
}
bool hasPageDetectionTolerance() const {
return contains("page-detection-tolerance") && !m_options["page-detection-tolerance"].isEmpty();
}
bool hasDisableCheckOutput() const { return contains("disable-check-output"); }
page_split::LayoutType getLayout() const { return m_layoutType; }
Qt::LayoutDirection getLayoutDirection() const { return m_layoutDirection; }
output::ColorMode getColorMode() const { return m_colorMode; }
output::ColorMode getDefaultColorMode() const { return m_defaultColorMode; }
output::PictureShape getPictureShape() const { return m_pictureShape; }
Dpi getInputDpi() const { return m_dpi; }
Dpi getOutputDpi() const { return m_outputDpi; }
Dpi getDefaultOutputDpi() const { return m_defaultOutputDpi; }
Margins getMargins() const { return m_margins; }
Margins getDefaultMargins() const { return m_defaultMargins; }
Margins getPageBorders() const { return m_pageBorders; }
page_layout::Alignment getAlignment() const { return m_alignment; }
Despeckle::Level getContentDetection() const { return m_contentDetection; }
QRectF getContentRect() const { return m_contentRect; }
double getContentDeviation() const { return m_contentDeviation; }
Orientation getOrientation() const { return m_orientation; }
int getThreshold() const { return m_threshold; }
double getDeskewAngle() const { return m_deskewAngle; }
AutoManualMode getDeskewMode() const { return m_deskewMode; }
double getSkewDeviation() const { return m_skewDeviation; }
int getStartFilterIdx() const { return m_startFilterIdx; }
int getEndFilterIdx() const { return m_endFilterIdx; }
output::DewarpingOptions getDewarpingMode() const { return m_dewarpingOptions; }
double getDespeckleLevel() const { return m_despeckleLevel; }
output::DepthPerception getDepthPerception() const { return m_depthPerception; }
float getMatchLayoutTolerance() const { return m_matchLayoutTolerance; }
QString getLanguage() const { return m_language; }
QString getWindowTitle() const { return m_windowTitle; }
QSizeF getPageDetectionBox() const { return m_pageDetectionBox; }
double getPageDetectionTolerance() const { return m_pageDetectionTolerance; }
bool getDefaultNull() const { return m_defaultNull; }
bool help() { return m_options.contains("help"); }
void printHelp();
private:
CommandLine() : m_gui(true), m_global(false) {}
static CommandLine m_globalInstance;
bool m_error;
bool m_gui;
bool m_global;
QString m_language;
QString m_windowTitle;
QSizeF m_pageDetectionBox;
double m_pageDetectionTolerance{0.1};
bool m_defaultNull;
bool isGlobal() { return m_global; }
void setGlobal() { m_global = true; }
bool contains(const QString& key) const { return m_options.contains(key); }
QMap<QString, QString> m_options;
QString m_projectFile;
QString m_outputProjectFile;
std::vector<QFileInfo> m_files;
std::vector<ImageFileInfo> m_images;
QString m_outputDirectory;
page_split::LayoutType m_layoutType;
Qt::LayoutDirection m_layoutDirection;
output::ColorMode m_colorMode;
output::ColorMode m_defaultColorMode;
output::PictureShape m_pictureShape;
Dpi m_dpi;
Dpi m_outputDpi;
Dpi m_defaultOutputDpi;
Margins m_margins;
Margins m_defaultMargins;
Margins m_pageBorders;
page_layout::Alignment m_alignment;
Despeckle::Level m_contentDetection;
QRectF m_contentRect;
double m_contentDeviation{1.0};
Orientation m_orientation;
int m_threshold{0};
double m_deskewAngle{0.0};
AutoManualMode m_deskewMode;
double m_skewDeviation{5.0};
int m_startFilterIdx{0};
int m_endFilterIdx{5};
output::DewarpingOptions m_dewarpingOptions;
double m_despeckleLevel{2.0};
output::DepthPerception m_depthPerception;
float m_matchLayoutTolerance{0.2f};
bool parseCli(const QStringList& argv);
void addImage(const QString& path);
void setup();
page_split::LayoutType fetchLayoutType();
output::ColorMode fetchColorMode();
output::ColorMode fetchDefaultColorMode();
output::PictureShape fetchPictureShape();
Qt::LayoutDirection fetchLayoutDirection();
Dpi fetchDpi(QString oname = "dpi");
Margins fetchMargins(QString base = "margins", Margins def = Margins(10.0, 5.0, 10.0, 5.0));
Margins fetchPageBorders() { return fetchMargins("page-borders", Margins(0, 0, 0, 0)); }
page_layout::Alignment fetchAlignment();
Despeckle::Level fetchContentDetection();
QRectF fetchContentRect();
double fetchContentDeviation();
Orientation fetchOrientation();
QString fetchOutputProjectFile();
int fetchThreshold();
double fetchDeskewAngle();
AutoManualMode fetchDeskewMode();
double fetchSkewDeviation();
int fetchStartFilterIdx();
int fetchEndFilterIdx();
output::DewarpingMode fetchDewarpingMode();
double fetchDespeckleLevel();
output::DepthPerception fetchDepthPerception();
float fetchMatchLayoutTolerance();
QString fetchLanguage() const;
QString fetchWindowTitle() const;
QSizeF fetchPageDetectionBox() const;
double fetchPageDetectionTolerance() const;
bool fetchDefaultNull();
};
#endif // ifndef COMMANDLINE_H_