-
Notifications
You must be signed in to change notification settings - Fork 5
/
ImageTest.h
182 lines (165 loc) · 7.62 KB
/
ImageTest.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
/****************************************************************************
* Operator Console - an extensible user interface for the Imatest IT *
* library *
* Copyright (C) 2013 Imatest LLC. *
* *
* 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/>. *
****************************************************************************/
#pragma once
#include <string>
#include <string.h>
#include "Config.h"
#include "CriticalCString.h"
#include "imatest_library.h"
#include "ThreadControl.h"
#include "Timer.h"
#include "Timestamp.h"
#include "libjson.h"
#include "jsonhelpers.h"
#include "libjson.h"
#include "jsonhelpers.h"
#include "JSON\JSONDefs.h"
using namespace std;
#define INI_RAW_JSON_MODE "-17"
///
/// This struct is used for figuring out which test(s) failed in class ImageTest.
///
typedef struct TestID
{
const char *key; //!< JSON key value for the test
const char *name; //!< our own name for the test (displayed to user)
} TestID;
//
// This typedef defines ImatestShellFunc, which is a pointer to an Imatest Library shell function (sfrplus_shell, blemish_shell, etc.)
//
typedef LIB_imatest_library_CPP_API void (MW_CALL_CONV *ImatestShellFunc)(int nargout, mwArray& nret, const mwArray& inputFile, const mwArray& rootDir, const mwArray& inputKeys, const mwArray& opMode, const mwArray& varargin);
///////////////////////////////////////////////////////////////////////
/// An abstract class that defines an image test to be performed.
///
/// ImageTest is an abstract class that defines an image test to be performed (e.g. blemish,
/// SFRplus). To use this class, create a subclass and implement the ParseResults() method.
///
/// Some member variables are used by more than 1 thread. To prevent these variables from being accessed
/// simultaneously from multiple threads, they are protected by critical sections, which limit access to one
/// thread at a time.
///
/// In theory there shouldn't be a case where both threads are trying to access the variable simultaneously,
/// but theory is often different than the real world. The sequence of events in the threads is as follows:
///
/// The main thread signals the ImageTest thread to run its test once.
///
/// The test runs once
/// It sets the values of the shared member variables
/// It sends a "done" message to the main thread
/// It waits for a signal to run again
/// Repeat
///
/// The main thread receives the "done" message
/// It makes copies of the shared member variables
/// It signals the ImageTest thread to run once
/// Repeat
///
/// In this scenario, the main thread only accesses the shared data when it has received the "done"
/// message (i.e. after the ImageTest thread is finished using the shared data), and the ImageTest
/// thread only accesses the shared data while the main thread is doing other things.
///////////////////////////////////////////////////////////////////////
class ImageTest
{
public:
ImageTest(void);
virtual ~ImageTest(void);
virtual void ParseResults(std::string &results) = 0; //!< This must be implemented by subclass
virtual void Run();
virtual void Run(void *raw_pixels, int width, int height, const Config *config);
void GetLog(CString &dst) {m_log.Get(dst);}
void GetFailInfo(CString &dst) {m_failInfo.Get(dst);}
void GetJSON(CString &dst) {m_jsonResults.Get(dst);}
void GetName(CString &name) {name = m_name;}
void GetSummary(CString &dst) {m_summary.Get(dst);}
void Init(void *raw_pixels, int width, int height, const Config *config);
bool Passed() {return m_passed;}
void SetBuffer(void *buf) {m_rawPixels = buf;}
static UINT __cdecl ThreadProc(void *param); //!< param must be a pointer to a ThreadControl object; param->m_data must point to an ImageTest object
protected:
bool AllocateRGB();
void AppendLog(CString &log) {m_log.Append(log);}
void ClearLog() {m_log.Clear();}
void ClearJSON() {m_jsonResults.Clear();}
void ClearFailInfo() {m_failInfo.Clear();}
void ClearSummary() {m_summary.Clear();}
void DeleteRGB();
bool GetDataNode(std::string &results, JSONNode &data, bool logErrors=true);
bool GetPassFailNode(JSONNode &data, JSONNode &passFail, bool logErrors=true);
void PlanesFromRGB();
void GetString(JSONNode &node, const char *name, json_string &string, bool logErrors=true);
void InitResults();
void ParseFailures(const JSONNode *data);
void RGBFromPlanes(UINT *rgb);
void SaveImage(RGBQUAD *buf, const char *filename);
void SetJSON(std::string &src) {m_jsonResults.Set(src);}
void SetSummary(CString &src) {m_summary.Set(src);}
public:
int m_width;
int m_height;
int m_ncolors; //<! gets passed to library (1 = raw data, 3 = rgb)
const char *m_extension;
const char *m_fileroot;
const char *m_serialNumber;
const char *m_partNumber;
const char *m_iniFilePathName;
const char *m_programPath;
const char *m_name; //<! the test name (e.g. Blemish or SFRplus)
long long m_elapsed; //<! number of milliseconds it took to run the test
CString m_elapsedStr;
Timestamp m_timestamp;
protected:
const void *m_rawPixels; //<! pointer to buffer containing raw pixels on which to perform the test
unsigned char *m_rgb;
bool m_passed; //<! did image pass the test
const TestID *m_tests; //<! pointer to array of TestID values (pointer to static array)
int m_numTests; //<! number of elements in m_tests array
Timer m_time;
ImatestShellFunc m_imatestFunc; //<! pointer to imatest library function to call
///////////////////////////////
//
// Some member variables are used by more than 1 thread. To prevent these variables from being accessed
// simultaneously from multiple threads, they are protected by critical sections, which limit access to one
// thread at a time.
//
// In theory there shouldn't be a case where both threads are trying to access the variable simultaneously,
// but theory is often different than the real world. The sequence of events in the threads is as follows:
//
// The main thread signals the ImageTest thread to run its test once.
//
// The test runs once
// It sets the values of the shared member variables
// It sends a "done" message to the main thread
// It waits for a signal to run again
// Repeat
//
// The main thread receives the "done" message
// It makes copies of the shared member variables
// It signals the ImageTest thread to run once
// Repeat
//
// In this scenario, the main thread only accesses the shared data when it has received the "done"
// message (i.e. after the ImageTest thread is finished using the shared data), and the ImageTest
// thread only accesses the shared data while the main thread is doing other things.
//
/////////////////////////////////
CriticalCString m_jsonResults; //!< the full results of the test in JSON format
CriticalCString m_summary; //!< the summary results of the test (these get displayed in the dialog)
CriticalCString m_failInfo; //!< reasons that image failed the test
CriticalCString m_log; //!< log message(s)
};