-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathread_args.cpp
More file actions
213 lines (210 loc) · 5.79 KB
/
Copy pathread_args.cpp
File metadata and controls
213 lines (210 loc) · 5.79 KB
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
/*
* This file is part of Filmulator.
*
* Copyright 2013 Omer Mano and Carlo Vaccari
*
* Filmulator 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.
*
* Filmulator 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 Filmulator. If not, see <http://www.gnu.org/licenses/>
*/
#include "header.hpp"
#include <pwd.h>
#include <unistd.h>
int read_args(int argc, char* argv[],string &input_configuration,
std::vector<string> &input_filename_list,
std::vector<float> &input_exposure_compensation, int &hdr_count,
bool &hdr, bool &tiff, bool &jpeg_in, bool &set_whitepoint,
float &whitepoint, bool &jpeg_out, bool &tonecurve_out,
int &highlights)
{
int param_count = 1; //first param is program name
bool exposure_specified = false;
bool configuration_set = false;
for(int i=1; i < argc; i++)
{
if (!strcmp(argv[i],"-c")) //If argv[i] is '-c'
{
i++;
if (i < argc) //There is an argument right afterwards
{
input_configuration = argv[i];
configuration_set = true;
}
else
{
cout << "Configuration file not specified.\n";
return 1;
}
param_count += 2;
}
else if (!strcmp(argv[i],"-t"))
{
if(jpeg_in)
{
cout << "Input cannot be both tiff and jpeg.\n";
return 1;
}
tiff = true;
param_count++;
}
else if (!strcmp(argv[i],"-ji"))
{
if(tiff)
{
cout << "Input cannot be both tiff and jpeg.\n";
return 1;
}
jpeg_in = true;
param_count++;
}
else if (!strcmp(argv[i],"-h")) //HDR
{
hdr = true;
exposure_specified = true;
if (i+1 < argc)
{
hdr_count = atoi(argv[i+1]);
}
else
{
cout << "Insufficient arguments for HDR.\n";
return 1;
}
if(hdr_count < 2)
{
cout << "HDR must use two or more images. Make sure number of images is specified after \"-h\".\n";
return 1;
}
highlights = 0;
param_count +=2;
}
else if(!strcmp(argv[i],"-w")) //Set a white point
{
set_whitepoint = true;
if (i+1 < argc)
{
char * pEnd;
whitepoint = strtof(argv[i+1],&pEnd)/1000; //User inputs a value
if(pEnd == argv[i]) //100x greater than
{ //real whitepoint
cout << "Invalid white point specified.\n";
return 1;
}
}
else
{
cout << "White point not set\n";
return 1;
}
param_count += 2;
}
else if(!strcmp(argv[i],"-jo")) //JPEG output
{
jpeg_out = true;
param_count++;
}
else if(!strcmp(argv[i],"-n")) //Use tonecurve
{
tonecurve_out = true;
param_count++;
}
else if(!strcmp(argv[i],"-l")) //Set dcraw highlight recovery
{
if (i+1 < argc)
{
highlights = atoi(argv[i+1]);
}
else
{
cout << "Highlight recovery parameter missing" << endl;
return 1;
}
if(highlights<0 || highlights>9)
{
cout << "Highlight recovery parameter out of range; " <<
"Overriding to zero" << endl;
highlights = 0;
}
param_count += 2;
}
}
//Check that we have the correct number of arguments
if (hdr)
{
if(param_count + 2*hdr_count > argc)
{
cout << "Not enough images specified. For HDR, make sure each image has an exposure given.\n";
return 1;
}
if(param_count + 2*hdr_count < argc)
{
cout << "Too many arguments.\n";
return 1;
}
}
else
{
if(param_count + 1 > argc)
{
cout << "Image not specified.\n";
return 1;
}
else if(param_count + 1 == argc)
{
exposure_specified = false;
}
else if(param_count + 2 == argc)
{
exposure_specified = true;
}
else if(param_count + 2 < argc)
{
cout << "too many arguments.\n";
return 1;
}
}
if(configuration_set == false)
{
cout << "Using default configuration location" << endl;
//Here we need to grab the user's home directory
int myuid = getuid();
passwd *mypasswd = getpwuid(myuid);
input_configuration = string(mypasswd->pw_dir) +
"/.filmulator/configuration.txt";
}
for(int i = param_count; i < argc; i++)
{
//Load the filenames onto list.
input_filename_list.push_back(argv[i]);
if(exposure_specified)
{
char * pEnd;
float exposure_long;
float exposure;
i++;
exposure_long = strtof(argv[i],&pEnd);
//exposure_long = strtof(argv[i],&pEnd,10); didn't work
//If strtof gives an error and outputs nothing, then pEnd
//will equal the starting position, argv[i].
if(pEnd == argv[i])
{
cout << "Invalid exposure specified.\n";
return 1;
}
exposure = exposure_long;//In the future, might want to do this safely, doesn't seem too necessary now
input_exposure_compensation.push_back(exposure);
}
else
input_exposure_compensation.push_back(0);
}
return 0;
}