Stefan Schuermans commited on 2011-09-11 09:49:29
Showing 3 changed files, with 78 additions and 5 deletions.
... | ... |
@@ -72,13 +72,13 @@ class Config |
72 | 72 |
dist = Constants.distriMaxCnt; // force error in next line |
73 | 73 |
} |
74 | 74 |
if (dist >= Constants.distriMaxCnt) |
75 |
- error("invalid distributor number \"" + settingPart2 + |
|
75 |
+ error("invalid distributor number \"" + settingPart2 + "\"" + |
|
76 | 76 |
String.format(" in line %d of config file", m_lineNo)); |
77 | 77 |
|
78 | 78 |
// get number of outputs and pixels |
79 | 79 |
px = PixelParser.parsePixel(value); // abuse for "outputs,pixels" |
80 | 80 |
if (px == null) |
81 |
- error("invalid distributor size \"" + value + |
|
81 |
+ error("invalid distributor size \"" + value + "\"" + |
|
82 | 82 |
String.format(" in line %d of config file", m_lineNo)); |
83 | 83 |
out = px.m_x; |
84 | 84 |
if (out >= Constants.outputMaxCnt) |
... | ... |
@@ -110,7 +110,75 @@ class Config |
110 | 110 |
void procMapping(String settingPart2, String value) |
111 | 111 |
throws Exception |
112 | 112 |
{ |
113 |
- // TODO |
|
113 |
+ Pattern pattern; |
|
114 |
+ Matcher matcher; |
|
115 |
+ String strDistri, strChannel, strBase, strFactor, strGamma; |
|
116 |
+ int dist; |
|
117 |
+ Distri distri; |
|
118 |
+ Mapping mapping = null; |
|
119 |
+ double base = 0.0, factor = 1.0, gamma = 1.0; |
|
120 |
+ |
|
121 |
+ // split setting part 2 into distributor and channel |
|
122 |
+ pattern = Pattern.compile("^([0-9]+) +([a-z]+)$"); |
|
123 |
+ matcher = pattern.matcher(settingPart2); |
|
124 |
+ if (!matcher.find()) |
|
125 |
+ error("invalid mapping specifier \"" + settingPart2 + "\"" + |
|
126 |
+ String.format(" in line %d of config file", m_lineNo)); |
|
127 |
+ strDistri = matcher.group(1); |
|
128 |
+ strChannel = matcher.group(2); |
|
129 |
+ |
|
130 |
+ // get distributor number |
|
131 |
+ try { |
|
132 |
+ dist = Integer.parseInt(strDistri); |
|
133 |
+ } catch (NumberFormatException e) { |
|
134 |
+ dist = Constants.distriMaxCnt; // force error in next line |
|
135 |
+ } |
|
136 |
+ if (dist >= Constants.distriMaxCnt) |
|
137 |
+ error("invalid distributor number \"" + strDistri + "\"" + |
|
138 |
+ String.format(" in line %d of config file", m_lineNo)); |
|
139 |
+ |
|
140 |
+ // get distributor |
|
141 |
+ distri = m_display.m_distris[dist]; |
|
142 |
+ if (distri == null) |
|
143 |
+ error(String.format("no distributor with number \"%d\"" + |
|
144 |
+ " in line %d of config file", dist, m_lineNo)); |
|
145 |
+ |
|
146 |
+ // get channel |
|
147 |
+ if (strChannel.equals("red")) |
|
148 |
+ mapping = distri.m_mapRed; |
|
149 |
+ else if (strChannel.equals("green")) |
|
150 |
+ mapping = distri.m_mapGreen; |
|
151 |
+ else if (strChannel.equals("blue")) |
|
152 |
+ mapping = distri.m_mapBlue; |
|
153 |
+ else |
|
154 |
+ error("invalid channel \"" + strChannel + "\"" + |
|
155 |
+ String.format(" in line %d of config file", m_lineNo)); |
|
156 |
+ |
|
157 |
+ // split mapping parameters |
|
158 |
+ pattern = Pattern.compile("^([-+.eE0-9]+) +([-+.eE0-9]+) +([-+.eE0-9]+)$"); |
|
159 |
+ matcher = pattern.matcher(value); |
|
160 |
+ if (!matcher.find()) |
|
161 |
+ error("invalid mapping parameters \"" + value + "\"" + |
|
162 |
+ String.format(" in line %d of config file", m_lineNo)); |
|
163 |
+ strBase = matcher.group(1); |
|
164 |
+ strFactor = matcher.group(2); |
|
165 |
+ strGamma = matcher.group(3); |
|
166 |
+ |
|
167 |
+ // parse mapping parameters |
|
168 |
+ try { |
|
169 |
+ base = Double.parseDouble(strBase); |
|
170 |
+ factor = Double.parseDouble(strFactor); |
|
171 |
+ gamma = Double.parseDouble(strGamma); |
|
172 |
+ } catch (NumberFormatException e) { |
|
173 |
+ error("invalid mapping parameters \"" + value + "\"" + |
|
174 |
+ String.format(" in line %d of config file", m_lineNo), e); |
|
175 |
+ } |
|
176 |
+ if (gamma <= 0.0) |
|
177 |
+ error(String.format("invalid gamma value \"%f\"" + |
|
178 |
+ " in line %d of config file", gamma, m_lineNo)); |
|
179 |
+ |
|
180 |
+ // update mapping parameters |
|
181 |
+ mapping.set(base, factor, gamma); |
|
114 | 182 |
} |
115 | 183 |
|
116 | 184 |
/** |
... | ... |
@@ -197,7 +265,7 @@ class Config |
197 | 265 |
} |
198 | 266 |
|
199 | 267 |
// unknown setting |
200 |
- warning("unknown setting \"" + setting + |
|
268 |
+ warning("unknown setting \"" + setting + "\"" + |
|
201 | 269 |
String.format(" in line %d of config file", m_lineNo) + |
202 | 270 |
", ignored"); |
203 | 271 |
} |
... | ... |
@@ -36,6 +36,11 @@ class Distri |
36 | 36 |
m_outputCnt = outputCnt; |
37 | 37 |
m_pixelCnt = pixelCnt; |
38 | 38 |
|
39 |
+ // allocate default mappings |
|
40 |
+ m_mapRed = new Mapping(); |
|
41 |
+ m_mapGreen = new Mapping(); |
|
42 |
+ m_mapBlue = new Mapping(); |
|
43 |
+ |
|
39 | 44 |
// allocate pixel array (no pixels configured yet) |
40 | 45 |
m_pixels = new Pixel [m_outputCnt * m_pixelCnt]; |
41 | 46 |
|