-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCartridgeFinder.cpp
444 lines (399 loc) · 14.4 KB
/
CartridgeFinder.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
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
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
#include "StdAfx.h"
#include "CartridgeFinder.h"
//////////////////////////////////////////////////////////////////////////
const BOOL CartridgeFinder::Reconstr(CString& bkColor, CString& PointTotal, CString& MsrPointIndex, CString& Parameter)
{
if (color(bkColor) & pointTotal(PointTotal) & msrIndex(MsrPointIndex) & para(Parameter))
return TRUE;
else
return FALSE;
}
const BOOL CartridgeFinder::ReconstrKeyWord(CString& bkColor, CString& PointTotal, CString& MsrPointIndex, CString& Parameter)
{
if (color(bkColor) | pointTotal(PointTotal) | msrIndex(MsrPointIndex) | para(Parameter))
return TRUE;
else
return FALSE;
}
const BOOL CartridgeFinder::Reconstr(CString& sample)
{
CString clr = sample;
CString pt = sample;
CString mi = sample;
CString pr = sample;
if (Reconstr(clr, pt, mi, pr))
{
sample.Format("%s%s%s%s", clr, pt, mi, pr);
return TRUE;
}
else
return FALSE;
}
//////////////////////////////////////////////////////////////////////////
const int CartridgeFinder::color(CString& strResult)
{
int colorName(0);
switch(reColor(strResult))
{
case rCL_Se: reColorSe(strResult); return TRUE;
case rCL_ShortCode: reColorShortCode(strResult); return TRUE;
case rCL_CrossTalk: reColorCrossTalk(strResult); return TRUE;
case rCL_Nits: reColorNits(strResult); return TRUE;
default:
// ASSERT(0);
return FALSE;
}
}
const reColorType CartridgeFinder::reColor(CString strResult)
{
if ( (strResult.Find("Cross") >= 0) || (strResult.Find("cross") >= 0) )
return rCL_CrossTalk;
else if ( (strResult.Find("Nits") >= 0) || (strResult.Find("nits") >= 0) )
return rCL_Nits;
else if ( strResult.Find("色") >= 0)
return rCL_Se;
else if ( ((strResult.Find("白") >= 0)||
(strResult.Find("紅") >= 0)||
(strResult.Find("綠") >= 0)||
(strResult.Find("藍") >= 0)||
(strResult.Find("黑") >= 0)) && (strResult.GetLength() == 2) )
return rCL_ShortCode;
else
{
strResult.Empty();
return rCL_NoMatch;
}
}
void CartridgeFinder::reColorCrossTalk(CString& strResult)
{
if ( (strResult.Find("W") >= 0) || (strResult.Find("w") >= 0))
strResult.Format("CrossTalk白矩形");
else if ( (strResult.Find("D") >= 0) || (strResult.Find("d") >= 0))
strResult.Format("CrossTalk黑矩形");
else
strResult.Format("CrossTalk無矩形");
}
void CartridgeFinder::reColorNits(CString& strResult)
{ strResult.Format("Nits"); }
void CartridgeFinder::reColorSe(CString& strResult)
{ strResult.Format("%s色", strResult.Left(strResult.Find("色")) ); }
void CartridgeFinder::reColorShortCode(CString& strResult)
{
strResult += "色";
}
//////////////////////////////////////////////////////////////////////////
const BOOL CartridgeFinder::pointTotal(CString& strResult)
{
switch(rePointTotal(strResult))
{
case rPT_Normal: rePointTotalNormal(strResult); return TRUE;
case rPT_Gamma: rePointTotalGamma(strResult); return TRUE;
case rPT_Center: rePointTotalCenter(strResult); return TRUE;
case rPT_PureDigital: rePointTotalPureDig(strResult); return TRUE;
case rPT_Word: rePointTotalWord(strResult); return TRUE;
default:
return FALSE;
}
}
const rePtTotalType CartridgeFinder::rePointTotal(CString strResult)
{
int dianIndex(0);
if ( (strResult.Find("Gamma") >= 0) || (strResult.Find("gamma") >= 0) )
return rPT_Gamma;
else if ( strResult.Find("點") >= 0)
{
dianIndex = strResult.Find("點");
// 中心點;
// 1點;
// 12點;
// 三點;
CString centerSample = strResult.Mid(dianIndex-6, 6);
CString oneSample = strResult.Mid(dianIndex-2, 2);
CString wordSample = strResult.Mid(dianIndex-2, 2);
if ( (atoi(oneSample) == 1) || (centerSample.Find("中心") >= 0) )
return rPT_Center;
else if (atoi(wordSample) == 0)
return rPT_Word;
else
return rPT_Normal;
}
//分開的
else if (isNumber(strResult))
return rPT_PureDigital;
else
{
strResult.Empty();
return rPT_NoMatch;
}
// if ( atoi(strResult.Mid(strResult.Find("點")-2, 2)) == 0 )
// return rPT_Word;
// else if ( ((strResult.Find("中心點") >= 0)&&(strResult.GetLength() == 6)) ||
// ((strResult.Find("1點") >= 0)&&(strResult.GetLength() == 3)) )
// {
// strResult.Mid(strResult.Find("點"))
// return rPT_Center;
// }
// else if ( strResult.Find("點") >= 0)
// return rPT_Normal;
}
void CartridgeFinder::rePointTotalGamma(CString& strResult)
{ strResult.Format("Gamma"); }
void CartridgeFinder::rePointTotalCenter(CString& strResult)
{ strResult.Format("中心點"); }
void CartridgeFinder::rePointTotalNormal(CString& strResult)
{
const int colorName(strResult.Find("點"));
int digitsCount(0);
if (strResult.Left(colorName).GetLength() > 3)
{
//字串在三位數字前有別的字,用轉成數字判斷
if ( atoi(strResult.Mid(colorName-(3), 3)) >100)
digitsCount = 3;
else if ( atoi(strResult.Mid(colorName-(2), 2)) >10)
digitsCount = 2;
else if ( atoi(strResult.Mid(colorName-(1), 1)) > 0)
digitsCount = 1;
}
else
//三位數以內
digitsCount = strResult.Left(colorName).GetLength();
strResult.Format("%3s點", strResult.Mid(colorName-(digitsCount), digitsCount) );
}
void CartridgeFinder::rePointTotalWord(CString& strResult)
{
const int DianIndex(strResult.Find("點"));
CString Word;
Word.Format("%s", strResult.Left(DianIndex));
if ( (DianIndex - Word.Find("一") == 2) && (Word.Find("一") >= 0) ) strResult.Format("中心點");
else if ( (DianIndex - Word.Find("二") == 2) && (Word.Find("二") >= 0) ) strResult.Format("2點");
else if ( (DianIndex - Word.Find("三") == 2) && (Word.Find("三") >= 0) ) strResult.Format("3點");
else if ( (DianIndex - Word.Find("四") == 2) && (Word.Find("四") >= 0) ) strResult.Format("4點");
else if ( (DianIndex - Word.Find("五") == 2) && (Word.Find("五") >= 0) ) strResult.Format("5點");
else if ( (DianIndex - Word.Find("六") == 2) && (Word.Find("六") >= 0) ) strResult.Format("6點");
else if ( (DianIndex - Word.Find("七") == 2) && (Word.Find("七") >= 0) ) strResult.Format("7點");
else if ( (DianIndex - Word.Find("八") == 2) && (Word.Find("八") >= 0) ) strResult.Format("8點");
else if ( (DianIndex - Word.Find("九") == 2) && (Word.Find("九") >= 0) ) strResult.Format("9點");
else if ( (DianIndex - Word.Find("十") == 2) && (Word.Find("十") >= 0) ) strResult.Format("10點");
else
strResult.Format("");
}
void CartridgeFinder::rePointTotalPureDig(CString& strResult)
{
int Digital = atoi(strResult);
if (Digital == 1)
strResult.Format("中心點");
else
strResult.Format("%3d點", Digital);
}
//////////////////////////////////////////////////////////////////////////
const BOOL CartridgeFinder::msrIndex(CString& strResult)
{
switch( reMsrIndex(strResult) )
{
case rMI_Dian:
reMsrIndexDian(strResult);
return TRUE;
case rMI_Normal:
reMsrIndexNormal(strResult);
return TRUE;
case rMI_PureDigital:
reMsrIndexPureDig(strResult);
return TRUE;
case rMI_NoMatch:
default:
return FALSE;
}
}
const reMrIndexType CartridgeFinder::reMsrIndex(CString strResult)
{
//白色9點第3點
const int DeeIndex(strResult.Find("第"));
strResult = strResult.Right(strResult.GetLength() - DeeIndex); //第x點
// DeeLength = strResult.Right(DeeIndex+2).GetLength();
if ( strResult.Find("第") >= 0 )
{
if ( (strResult.FindOneOf("第") < strResult.FindOneOf("點")) &&
(strResult.FindOneOf("點") >= 0) )
return rMI_Dian;
else
return rMI_Normal;
}
else if (isNumber(strResult))
return rMI_PureDigital;
else
{
strResult.Empty();
return rMI_NoMatch;
}
}
void CartridgeFinder::reMsrIndexDian(CString& strResult)
{
strResult = strResult.Right(strResult.GetLength() - strResult.Find("第")); //第x點
const int deeIndex(strResult.Find("第"));
const int dianIndex( strResult.Find("點") );
strResult.Format(", 第%s點", strResult.Mid(deeIndex +2, dianIndex-deeIndex -2) );
}
void CartridgeFinder::reMsrIndexNormal(CString& strResult)
{
int colorName( strResult.FindOneOf("第") );
colorName += 2;
int digitsCount(0);
if ( atoi(strResult.Mid(colorName, 3) ) >100)
digitsCount = 3;
else if ( atoi(strResult.Mid(colorName, 2) ) >10)
digitsCount = 2;
else if ( atoi(strResult.Mid(colorName, 1) ) )
digitsCount = 1;
strResult.Format(", 第%s點", strResult.Mid(colorName, digitsCount) );
}
void CartridgeFinder::reMsrIndexPureDig(CString& strResult)
{
int Digital = atoi(strResult);
strResult.Format(", 第%d點", Digital);
}
//////////////////////////////////////////////////////////////////////////
const BOOL CartridgeFinder::para(CString& strResult)
{
switch( rePara(strResult) )
{
case rPM_Over: reParaOver(strResult); return TRUE;
case rPM_Length: reParaLength(strResult); return TRUE;
case rPM_NoPara: reParaNoPara(strResult); return TRUE;
case rPM_Nits: reParaNits(strResult); return TRUE;
case rPM_Welt: strResult.Format("_貼邊"); return TRUE;
case rPM_paraGamma: reParaGamma(strResult); return TRUE;
case rPM_PureDigital: reParaPureDig(strResult); return TRUE;
case rMI_NoMatch:
default:
return FALSE;
}
}
const reParaType CartridgeFinder::rePara(CString strResult)
{
strResult = strResult.Right(strResult.GetLength() - strResult.Find("_"));
if ( (strResult.GetLength() == 1) && ((strResult.Find("_") >= 0)||(strResult.Find(" ") >= 0)))
{ return rPM_NoPara; }
else if (strResult.Find("離邊") >= 0)
{
strResult = strResult.Right(strResult.GetLength() - strResult.Find("離邊") -6);
if ( (strResult.Find("1/") >= 0) && (isNumber(strResult.Right(strResult.GetLength() - strResult.Find("1/") -2))) )
{ return rPM_Over; }
else if (isNumber(strResult))
{ return rPM_Length; }
}
else if ((strResult.Find("貼邊") >= 0) || ((strResult.GetLength() == 1) && (strResult.Find("0") >= 0)))
{ return rPM_Welt; }
else if ( (strResult.Find("平分") >= 0) && (strResult.Find("~") >= 0))
{ return rPM_paraGamma; }
else if ((strResult.Find("+") >= 0) || (strResult.Find("↑") >= 0) || (strResult.Find("-") >= 0) || (strResult.Find("↓") >= 0) )
{ return rPM_Nits; }
else if ( (strResult.Find("1/") >= 0) && (isNumber(strResult.Right(strResult.GetLength() - strResult.Find("1/") -2))) )
{ return rPM_Over; }
//分開的
else if ( strResult.Right(strResult.GetLength() - (strResult.Find(" ")+1)).Find(" ") >= 0 )
{ return rPM_paraGamma; }
else if (isNumber(strResult))
{ return rPM_PureDigital; }
//(strResult.Find(" ") >= 0) != (strResult.FindOneOf(" ") >= 0)
strResult.Format(" ");
return rPM_NoMatch;
}
BOOL CartridgeFinder::isNumber(const CString& strResult)
{
if (atoi(strResult) >= 1000 && strResult.GetLength() == 4)
return TRUE;
else if (atoi(strResult) >= 100 && strResult.GetLength() == 3)
return TRUE;
else if (atoi(strResult) >= 10 && strResult.GetLength() == 2)
return TRUE;
else if (atoi(strResult) > 0 && strResult.GetLength() == 1)
return TRUE;
else if (strResult.Find("0") >= 0)
{
// ASSERT(0);
return TRUE;
}
else
return FALSE;
}
void CartridgeFinder::reParaOver(CString& strResult)
{
strResult = strResult.Right(strResult.GetLength() - strResult.Find("/") -1);
strResult.Format("_離邊: 1/%s", strResult.Right(strResult.GetLength() - strResult.Find("/") -1));
}
void CartridgeFinder::reParaLength(CString& strResult)
{
strResult = strResult.Right(strResult.GetLength() - strResult.Find("離邊") -6);
strResult.Format("_離邊: %dmm", atoi(strResult));
}
void CartridgeFinder::reParaNits(CString& strResult)
{
int signIndex(0);
CString sign;
if ( strResult.Find("+") >= 0 )
{
signIndex = strResult.Find("+");
sign.Format("↑");
}
else if ( strResult.Find("↑") >= 0 )
{
signIndex = strResult.Find("↑");
sign.Format("↑");
}
else if ( strResult.Find("-") >= 0 )
{
signIndex = strResult.Find("-");
sign.Format("↓");
}
else if ( strResult.Find("↓") >= 0 )
{
signIndex = strResult.Find("↓");
sign.Format("↓");
}
int grayLevel(0);
if ( atoi(strResult.Mid(signIndex-3, 3)) >= 100 )
grayLevel = atoi(strResult.Mid(signIndex-3, 3));
else if ( atoi(strResult.Mid(signIndex-2, 2)) >= 10 )
grayLevel = atoi(strResult.Mid(signIndex-2, 2));
else if ( atoi(strResult.Mid(signIndex-1, 1)) > 0 )
grayLevel = atoi(strResult.Mid(signIndex-1, 1));
if ( signIndex && grayLevel)
strResult.Format("_灰階: %d%s",grayLevel, sign);
else
strResult.Format("誤判成Nits參數");
}
void CartridgeFinder::reParaNoPara(CString& strResult)
{
strResult.Format("_");
}
void CartridgeFinder::reParaGamma(CString& strResult)
{
//0~255, 平分255
int fristIndex(0), secondIndex(0);
CString fristSign(" ");
CString secondSign(" ");
if ( (strResult.Find("平分") >= 0) && (strResult.Find("~") >= 0))
{
strResult = strResult.Right(strResult.GetLength() - strResult.Find("_"));
fristSign = "~";
secondSign = ", 平分";
fristIndex = strResult.Find(fristSign);
secondIndex = strResult.Find(secondSign);
}
//0 255 255
else if ( strResult.Right(strResult.GetLength() - (strResult.Find(" ")+1)).Find(" ") >= 0 )
{
fristSign = " ";
secondSign = " ";
fristIndex = strResult.Find(fristSign);
secondIndex = strResult.Right(strResult.GetLength() - (fristIndex+fristSign.GetLength())).Find(" ") + fristIndex+fristSign.GetLength();
}
int numberBegin = atoi(strResult.Left(fristIndex));
int numberEnd = atoi(strResult.Mid(fristIndex+fristSign.GetLength(), secondIndex-(fristIndex+fristSign.GetLength())));
int numberDiv = atoi(strResult.Mid(secondIndex+secondSign.GetLength()));
strResult.Format("_%d~%d, 平分%d", numberBegin, numberEnd, numberDiv);
}
void CartridgeFinder::reParaPureDig(CString& strResult)
{
strResult.Format("_離邊: %dmm", atoi(strResult));
}