forked from JokerEyeAdas/HDR-ISP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse.cpp
197 lines (171 loc) · 5.41 KB
/
parse.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
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
/**
* @file parse.cpp
* @author joker.mao ([email protected])
* @brief
* @version 0.1
* @date 2023-07-29
*
* Copyright (c) of ADAS_EYES 2023
*
*/
#include "common/common.h"
#include "modules/modules.h"
#include "json.hpp"
#include <fstream>
using json = nlohmann::json;
std::list<std::string> split(const std::string &str, const std::string &pattern)
{
std::list<std::string> res;
if (str == "")
return res;
std::string strs = str + pattern;
size_t pos = strs.find(pattern);
while (pos != strs.npos)
{
std::string temp = strs.substr(0, pos);
res.push_back(temp);
strs = strs.substr(pos + 1, strs.size());
pos = strs.find(pattern);
}
return res;
}
int ParseIspCfgFile(const std::string cfg_file_path, IspPrms &isp_prm)
{
std::ifstream fs(cfg_file_path);
if (!fs.is_open())
{
LOG(ERROR) << cfg_file_path << " open failed";
return -1;
}
json j_root;
fs >> j_root;
// raw path
isp_prm.raw_file = j_root["raw_file"];
isp_prm.out_file_path = j_root["out_file_path"];
// sensor info
isp_prm.sensor_name = j_root["info"]["sensor_name"];
LOG(INFO) << "Sensor Name: " << isp_prm.sensor_name;
auto cfa_str = j_root["info"]["cfa"];
if (cfa_str == "RGGB")
{
isp_prm.info.cfa = CfaTypes::RGGB;
}
else if (cfa_str == "BGGR")
{
isp_prm.info.cfa = CfaTypes::BGGR;
}
else if (cfa_str == "GBRG")
{
isp_prm.info.cfa = CfaTypes::GBRG;
}
else if (cfa_str == "GRBG")
{
isp_prm.info.cfa = CfaTypes::GRBG;
}
LOG(INFO) << "Sensor CFA: " << cfa_str;
auto raw_type_str = j_root["info"]["data_type"];
if (raw_type_str == "RAW10")
{
isp_prm.info.dt = RawDataTypes::RAW10;
}
else if (raw_type_str == "RAW12")
{
isp_prm.info.dt = RawDataTypes::RAW12;
}
else if (raw_type_str == "RAW14")
{
isp_prm.info.dt = RawDataTypes::RAW14;
}
else if (raw_type_str == "RAW16")
{
isp_prm.info.dt = RawDataTypes::RAW16;
}
LOG(INFO) << "Sensor DT: " << raw_type_str;
isp_prm.info.bpp = static_cast<int>(j_root["info"]["bpp"]);
int max_bit = int(j_root["info"]["max_bit"]);
isp_prm.info.max_val = (1 << max_bit) - 1;
isp_prm.info.width = static_cast<int>(j_root["info"]["width"]);
isp_prm.info.height = static_cast<int>(j_root["info"]["height"]);
isp_prm.info.mipi_packed = static_cast<int>(j_root["info"]["mipi_packed"]);
LOG(INFO) << "Sensor Resolution: " << isp_prm.info.width << "*" << isp_prm.info.height;
//
std::string pipeline = j_root["pipe"];
isp_prm.pipe = std::move(split(pipeline, "|"));
// blc
isp_prm.blc = j_root["blc"];
// wbgain
auto d65_gains = j_root["wb_gain"]["d65_gain"];
if (d65_gains.size() != 4)
{
LOG(ERROR) << "d65 gains size error";
return -1;
}
for (int i = 0; i < d65_gains.size(); ++i)
{
isp_prm.wb_gains.d65_gain[i] = d65_gains[i];
//LOG(INFO) << "d65" << isp_prm.wb_gains.d65_gain[i];
}
auto d50_gains = j_root["wb_gain"]["d50_gain"];
if (d50_gains.size() != 4)
{
LOG(ERROR) << "d50 gains size error";
return -1;
}
for (int i = 0; i < d50_gains.size(); ++i)
{
isp_prm.wb_gains.d50_gain[i] = d50_gains[i];
}
// pwl
isp_prm.depwl_prm.pedestal = j_root["depwl"]["pedestal"];
isp_prm.depwl_prm.pwl_nums = j_root["depwl"]["pwl_nums"];
auto pwl_x = j_root["depwl"]["pwl_x"];
auto pwl_y = j_root["depwl"]["pwl_y"];
auto pwl_slope = j_root["depwl"]["slope"];
if ((pwl_x.size() != isp_prm.depwl_prm.pwl_nums) || (pwl_y.size() != isp_prm.depwl_prm.pwl_nums) || (pwl_slope.size() != isp_prm.depwl_prm.pwl_nums))
{
LOG(ERROR) << "pwl input prms error";
return -1;
}
for (int i = 0; i < isp_prm.depwl_prm.pwl_nums; ++i)
{
isp_prm.depwl_prm.x_cood[i] = pwl_x[i];
isp_prm.depwl_prm.y_cood[i] = pwl_y[i];
isp_prm.depwl_prm.slope[i] = pwl_slope[i];
}
// pwl
isp_prm.ltm_prms.constrast = j_root["ltm"]["constrast"];
isp_prm.ltm_prms.in_bits = j_root["ltm"]["in_bit"];
isp_prm.ltm_prms.out_bits = j_root["ltm"]["out_bit"];
isp_prm.rgb_gamma.nums = j_root["rgbgamma"]["gammalut_nums"];
isp_prm.rgb_gamma.in_bits = j_root["rgbgamma"]["in_bit"];
isp_prm.rgb_gamma.out_bits = j_root["rgbgamma"]["out_bit"];
auto gamma_curve = j_root["rgbgamma"]["gammalut"];
if (gamma_curve.size() != isp_prm.rgb_gamma.nums)
{
LOG(ERROR) << "rgb gamma input prms error";
return -1;
}
for (int i = 0; i < gamma_curve.size(); ++i)
{
isp_prm.rgb_gamma.curve[i] = gamma_curve[i];
}
isp_prm.y_gamma.nums = j_root["ygamma"]["gammalut_nums"];
isp_prm.y_gamma.in_bits = j_root["ygamma"]["in_bit"];
isp_prm.y_gamma.out_bits = j_root["ygamma"]["out_bit"];
gamma_curve = j_root["ygamma"]["gammalut"];
if (gamma_curve.size() != isp_prm.y_gamma.nums)
{
LOG(ERROR) << "y gamma input prms error";
return -1;
}
for (int i = 0; i < gamma_curve.size(); ++i)
{
isp_prm.y_gamma.curve[i] = gamma_curve[i];
}
isp_prm.sat_prms.rotate_angle = j_root["saturation"]["rotate_angle"];
isp_prm.contrast_prms.ratio = j_root["contrast"]["ratio"];
isp_prm.sharpen_prms.ratio = j_root["sharpen"]["ratio"];
fs.close();
LOG(INFO) << "parse exit";
return 0;
}