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
 
#include "stdafx.h"
 
#include "BlobStorage.h"
#include "ASGInspection.h"
 
#include "StopWatch3.h"
 
#include "Pad.h"
 
 
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
 
#define CONV_SPR_MULTI    16
#define CONV_SPR_SHIFT    4
 
 
#include "SISAssem.h"
//#include "Memory.h"
#include "AssemParam.h"
 
 
 
 
extern "C"{
 
    int ConvFloatE(BYTE* pImgBuff, short* pConBuff, __int64 maxDefect, __int64 nDefect
        , __int64 left, __int64 right, __int64 top, __int64 bottom
        , int* DefectX, int* DefectY, short* DefectType, short* DefectValue
        , __int64 frameWidth, __int64 piPitch, __int64 pfSPR, __int64 psSPR
        , __int64 Threshold, __int64 Suppress, __int64 SPR, __int64 ShiftCount
        );
    int ConvFloatDPCE(BYTE* pImgBuff, short* pConBuff, __int64 maxDefect, __int64 nDefect
        , __int64 left, __int64 right, __int64 top, __int64 bottom
        , int* DefectX, int* DefectY, short* DefectType, short* DefectValue
        , __int64 frameWidth, short* piPitch, short* pfSPR, short* psSPR
        , __int64 Threshold, __int64 Suppress, __int64 SPR, __int64 ShiftCount
        , __int64 iPitch
        );
 
    int ConvPixelE(BYTE *pImgBuff, __int64 Threshold, __int64 maxDefect, __int64 nDefect
        , __int64 left, __int64 right, __int64 top, __int64 bottom
        , int* DefectX, int* DefectY, short* DefectType, short* DefectValue
        , int* pGraySrc, int* pGrayCmp, int* pZoneID, int* pZoneTh
        , __int64 frameWidth, __int64 iPitch, __int64 fSPR, __int64 sSPR
        , __int64 Suppress, __int64 DTH_StartThreshold, __int64 DTH_Gradient, __int64 DTH_SectionStart
        , __int64 ShiftCount
        );
    int ConvPixelE2(BYTE *pImgBuff, __int64 Threshold, __int64 maxDefect, __int64 nDefect
        , __int64 left, __int64 right, __int64 top, __int64 bottom
        , int* DefectX, int* DefectY, short* DefectType, short* DefectValue
        , int* pGraySrc, int* pGrayCmp, int* pZoneID, int* pZoneTh
        , __int64 frameWidth, __int64 iPitch, __int64 fSPR, __int64 sSPR
        , __int64 Suppress, __int64 DTH_StartThreshold, __int64 DTH_Gradient, __int64 DTH_SectionStart
        , __int64 ShiftCount
        );
    int ConvPixelDPCE(BYTE *pImgBuff, __int64 Threshold, __int64 maxDefect, __int64 nDefect
        , __int64 left, __int64 right, __int64 top, __int64 bottom
        , int* DefectX, int* DefectY, short* DefectType, short* DefectValue
        , int* pGraySrc, int* pGrayCmp, int* pZoneID, int* pZoneTh
        , __int64 frameWidth, short* piPitch, short* pfSPR, short* psSPR
        , __int64 Suppress, __int64 DTH_StartThreshold, __int64 DTH_Gradient, __int64 DTH_SectionStart
        , __int64 ShiftCount, __int64 iPitch
        );
 
    int ConvZone(BYTE *pImgBuff, __int64 Threshold, __int64 maxDefect, __int64 nDefect
        , __int64 left, __int64 right, __int64 top, __int64 bottom
        , int* DefectX, int* DefectY, short* DefectType, short* DefectValue
        , int* pGraySrc, int* pGrayCmp, int* pZoneID, int* pZoneTh
        , __int64 frameWidth, __int64 iPitch, __int64 fSPR, __int64 sSPR
        , short* ZoneThTable, short* ZoneIdTable, __int64 ZoneTableWidth, void* pMatchTable
        , CDefectPair *pDefectdPair, __int64 StartPair, __int64 MaxPair, __int64 PairSize
        , __int64 dxPattern, __int64 dyPattern, __int64 yZoneByte,  __int64 bReverseFilter
        );
    int ConvZoneDPC(BYTE *pImgBuff, __int64 Threshold, __int64 maxDefect, __int64 nDefect
        , __int64 left, __int64 right, __int64 top, __int64 bottom
        , int* DefectX, int* DefectY, short* DefectType, short* DefectValue
        , int* pGraySrc, int* pGrayCmp, int* pZoneID, int* pZoneTh
        , __int64 frameWidth, short* iPitch, short* fSPR, short* sSPR
        , short* ZoneThTable, short* ZoneIdTable, __int64 ZoneTableWidth, void* pMatchTable
        , CDefectPair *pDefectdPair, __int64 StartPair, __int64 MaxPair, __int64 PairSize
        , __int64 dxPattern, __int64 dyPattern, __int64 bReverseFilter, __int64 iPitch16
        , __int64 yZoneByte
        );
    int ConvZoneVert(BYTE *pImgBuff, __int64 Threshold, __int64 maxDefect, __int64 nDefect
        , __int64 left, __int64 right, __int64 top, __int64 bottom
        , int* DefectX, int* DefectY, short* DefectType, short* DefectValue
        , int* pGraySrc, int* pGrayCmp, int* pZoneID, int* pZoneTh
        , __int64 frameWidth, __int64 iPitch16, __int64 fSPR, __int64 sSPR
        , short* ZoneThTable, short* ZoneIdTable, __int64 ZoneTableWidth, void* pMatchTable
        , CDefectPair *pDefectdPair, __int64 StartPair, __int64 MaxPair, __int64 PairSize
        , __int64 dxPattern, __int64 dyPattern, __int64 yZoneByte, __int64 bReverseFilter
        );
 
 
    int ConvZoneE(BYTE *pImgBuff, __int64 Threshold, __int64 maxDefect, __int64 nDefect
        , __int64 left, __int64 right, __int64 top, __int64 bottom
        , int* DefectX, int* DefectY, short* DefectType, short* DefectValue
        , int* pGraySrc, int* pGrayCmp, int* pZoneID, int* pZoneTh
        , __int64 frameWidth, __int64 iPitch, __int64 fSPR, __int64 sSPR
        , __int64 Suppress, __int64 DTH_StartThreshold, __int64 DTH_Gradient, __int64 DTH_SectionStart
        , __int64 ShiftCount, short* ZoneThTable, short* ZoneIdTable, __int64 ZoneTableWidth
        , __int64 ZoneTableX, __int64 ZoneTableY
        );
    int ConvZoneDPCE(BYTE *pImgBuff, __int64 Threshold, __int64 maxDefect, __int64 nDefect
        , __int64 left, __int64 right, __int64 top, __int64 bottom
        , int* DefectX, int* DefectY, short* DefectType, short* DefectValue
        , int* pGraySrc, int* pGrayCmp, int* pZoneID, int* pZoneTh
        , __int64 frameWidth, short* piPitch, short* pfSPR, short* psSPR
        , __int64 Suppress, __int64 DTH_StartThreshold, __int64 DTH_Gradient, __int64 DTH_SectionStart
        , __int64 ShiftCount, short* ZoneThTable, short* ZoneIdTable, __int64 ZoneTableWidth
        , __int64 ZoneTableX, __int64 ZoneTableY, __int64 iPitch
        );
 
    int ConvFloat2(BYTE* pImgBuff, short* pConBuff, __int64 maxDefect, __int64 nDefect
        , __int64 left, __int64 right, __int64 top, __int64 bottom
        , int* DefectX, int* DefectY, short* DefectType, short* DefectValue
        , CDefectPair *pDefectdPair, __int64 StartPair, __int64 MaxPair, __int64 PairSize
        , __int64 iPitch16, __int64 BuffWidth, __int64 Threshold, __int64 Suppress
        , BYTE* pIndexBuff, __int64 IndexWidth, __int64 IndexHeight, __int64 iIndex
        , __int64 IndexLeft, __int64 IndexTop
        , short* piPitch, short* pfSpr, short* psSpr
        );
};
 
 
 
void    CSISAssem::Compare_Zone()
{
    double xpitch= m_Param.GetRealConvPitch();
    double ypitch= m_Param.GetRealScanPitch();
    int        oldBlob;
        oldBlob= m_nBlob;
 
    if(m_Param.m_ConvDir == ConvDir_Vert)
    {
        m_nPair= ConvZoneVert(m_Param.s_lpBuffer, m_Param.s_nThreshold, m_maxPixel, m_nPixel// 4
            , m_Param.s_RectConv.left, m_Param.s_RectConv.right, m_Param.s_RectConv.top, m_Param.s_RectConv.bottom
            , m_pPixelX, m_pPixelY, m_pPixelType, m_pPixelValue            // 4
            , m_pGraySrc, m_pGrayCmp, m_pZoneID, m_pZoneTh// 4
            , m_Param.s_nFrameWidth, (__int64)(ypitch*16), 0, 0                // 4
            , m_Param.s_psZoneThTable, m_Param.s_psZoneTable, m_Param.s_nThresTableWidth, m_Param.m_pGammaTable
            , m_pPairDefect, m_nPair, m_maxPair, sizeof(CDefectPair)
            , (__int64) m_Param.GetZoneConvPitch(), (__int64) m_Param.GetZoneScanPitch(), m_Param.m_nGammaXCount*8, (__int64) m_Param.s_bReverseFilter
            );
        CBlobStorage::BlobDefectVert();
        CBlobStorage::MergeDivision(oldBlob, m_Param.m_nDefectMergePixel);
        CBlobStorage::ShadowFilterVert(oldBlob, m_Param.GetRealScanPitch());
        return;
    }
 
    if(m_Param.m_pPitch)
    {
        m_nPair= ConvZoneDPC(m_Param.s_lpBuffer, m_Param.s_nThreshold, m_maxPixel, m_nPixel// 4
            , m_Param.s_RectConv.left, m_Param.s_RectConv.right, m_Param.s_RectConv.top, m_Param.s_RectConv.bottom
            , m_pPixelX, m_pPixelY, m_pPixelType, m_pPixelValue            // 4
            , m_pGraySrc, m_pGrayCmp, m_pZoneID, m_pZoneTh// 4 
            , m_Param.s_nFrameWidth, m_Param.m_pPitch, m_Param.m_pfSPR, m_Param.m_psSPR                // 4
            , m_Param.s_psZoneThTable, m_Param.s_psZoneTable, m_Param.s_nThresTableWidth, m_Param.m_pGammaTable
            , m_pPairDefect, m_nPair, m_maxPair, sizeof(CDefectPair)
            , (__int64)xpitch, (__int64)ypitch, m_Param.s_bReverseFilter, (__int64)(xpitch*16)
            , m_Param.m_nGammaXCount*8
            );
/*
        m_nPixel= ConvZoneDPC(m_Param.s_lpBuffer, m_Param.s_nThreshold, m_maxPixel, m_nPixel// 4
            , m_Param.s_RectConv.left, m_Param.s_RectConv.right, m_Param.s_RectConv.top, m_Param.s_RectConv.bottom
            , m_pPixelX, m_pPixelY, m_pPixelType, m_pPixelValue            // 4
            , m_pGraySrc, m_pGrayCmp, m_pZoneID, m_pZoneTh// 4
            , m_Param.s_nFrameWidth, m_Param.m_pPitch, m_Param.m_pfSPR, m_Param.m_psSPR                // 4
            , m_Param.s_nThresholdSupress, m_Param.s_nAddThreshold, m_Param.s_nAddGradient, m_Param.s_nAddThresLevel
            , CONV_SPR_SHIFT, m_Param.s_psZoneThTable, m_Param.s_psZoneTable, m_Param.s_nThresTableWidth
            , m_Param.s_nThresTableStartX, m_Param.s_nThresTableStartY, (__int64)(xpitch+ 0.5), (__int64) m_Param.s_bReverseFilter
            );
        CPairStorage::PairingPlus_Pixel(xpitch);
*/
    }else
    {
        m_nPair= ConvZone(m_Param.s_lpBuffer, m_Param.s_nThreshold, m_maxPixel, m_nPixel// 4
            , m_Param.s_RectConv.left, m_Param.s_RectConv.right, m_Param.s_RectConv.top, m_Param.s_RectConv.bottom
            , m_pPixelX, m_pPixelY, m_pPixelType, m_pPixelValue            // 4
            , m_pGraySrc, m_pGrayCmp, m_pZoneID, m_pZoneTh// 4
            , m_Param.s_nFrameWidth, (__int64)(xpitch*16), 0, 0                // 4
            , m_Param.s_psZoneThTable, m_Param.s_psZoneTable, m_Param.s_nThresTableWidth, m_Param.m_pGammaTable
            , m_pPairDefect, m_nPair, m_maxPair, sizeof(CDefectPair)
            , (__int64)xpitch, (__int64)ypitch, m_Param.m_nGammaXCount*8, m_Param.s_bReverseFilter
            );
    }
    CBlobStorage::BlobDefect();
    CBlobStorage::MergeDivision(oldBlob, m_Param.m_nDefectMergePixel);
    CBlobStorage::ShadowFilter(oldBlob, m_Param.GetRealConvPitch());
    return;
}
 
 
DIT_RESULT    CAssemControl::ASGVertConvolution(int iThread, CConvParam *pParam)
{
    if(iThread >= m_nThread || iThread < 0)
        return DIT_CONV_INVALIDPARAM;
    return GetSISAssem(iThread)->ASGVertConvolution(pParam);
}
 
 
DIT_RESULT    CSISAssem::ASGVertConvolution(CConvParam *pParam)
{
    // ÀÌ ÇÔ¼ö ¾È ¾¹´Ï´Ù..
    // È£Ãâ ÇÏÁö ¸¶¼¼¿ä..
    // ³ªÁß¿¡ Á¤¸® ÇÒ °Ì´Ï´Ù.
    DIT_RESULT rslt= DIT_CONV_SUCCESS;
 
    // copy prameter to member variable
    SetConvParam(pParam);
 
    BOOL bPassInspect;
    rslt= CheckParameter_Vert(bPassInspect);
    if(rslt != DIT_CONV_SUCCESS)
        return rslt;
 
    // Reset 3 Storage (Blob, Pair, Pixel)
    ResetSISAssem();
 
 
 
    // SupPixel Á¤¹Ðµµ¸¦ 1/8(3½Â¹è) °ú 1/16(4½Â¹è) µÑÁß¿¡ Çϳª·Î ¼±ÅÃÇØ¾ß ÇÑ´Ù..
 
    //Compare_Vert();    //¹Ú°úÀå ÄÚµå
 
 
    if (m_Param.s_uiProcessing & DIT_CONV_PPAIRING)
    {
        DIT_RESULT PairResu;
        PairResu = CPairStorage::PairingPlus_Vert(m_Param.s_dPitchScanReal * m_Param.s_nPitchCycleScan);    
 
        if (PairResu != DIT_CONV_SUCCESS)
        {
            if (rslt == DIT_CONV_FRAMEOVERFLOW)
                return rslt;
            else
                return PairResu;
        }
 
        if (m_Param.s_uiProcessing & DIT_CONV_MPAIRING)// && FALSE)
        {            
            PairResu = CPairStorage::PairingMinus_Vert(m_Param.s_dPitchScanReal * m_Param.s_nPitchCycleScan);        
 
            if (PairResu != DIT_CONV_SUCCESS)
            {
                if (rslt == DIT_CONV_FRAMEOVERFLOW)
                    return rslt;
                else
                    return PairResu;
            }
        }
 
        //////////////////////////////////////////////////////////////////////////
        // Blobing
        if (m_Param.s_uiProcessing & DIT_CONV_BLOBING)
        {
            int nBlobStart = m_nBlob;
            DIT_RESULT PairResu= DIT_CONV_SUCCESS;
    //        PairResu = CBlobStorage::BlobDefect2();
            ////Debug_test();
            if (PairResu != DIT_CONV_SUCCESS)
            {
                if (rslt == DIT_CONV_FRAMEOVERFLOW)
                    return rslt;
                else
                    return PairResu;
            }
 
            //////////////////////////////////////////////////////////////////////////
            // Unpair Blobing
            if (m_Param.s_uiProcessing & DIT_CONV_UNPAIRBLOB)// && FALSE)
            {
//                PairResu = CBlobStorage::BlobUnpairDefect();
                //Debug_test();
                if (PairResu != DIT_CONV_SUCCESS)
                {
                    if (rslt == DIT_CONV_FRAMEOVERFLOW)
                        return rslt;
                    else
                        return PairResu;
                }
            }
            //                TRACE("Blobing %d\n", GetTickCount() - dwTick);
            //                dwTick = GetTickCount();
 
            //////////////////////////////////////////////////////////////////////////
            // Defect Classification
            if (m_Param.s_uiProcessing & DIT_CONV_CLASSIFY)
            {
                PairResu = CBlobStorage::ClassificationDefectVert(nBlobStart);
                //Debug_test();
                if (PairResu != DIT_CONV_SUCCESS)
                {
                    if (rslt == DIT_CONV_FRAMEOVERFLOW)
                        return rslt;
                    else
                        return PairResu;
                }
            }
 
            //                TRACE("ClassificationDefect %d\n", GetTickCount() - dwTick);
            //                dwTick = GetTickCount();
            //////////////////////////////////////////////////////////////////////////
            // Merge Defect
            int nDefectMergePixel= m_Param.m_nDefectMergePixel;
            if (m_Param.s_uiProcessing & DIT_CONV_MERGE_DIVISION && nDefectMergePixel > 0)
            {
                PairResu = CBlobStorage::MergeDivision(nBlobStart, nDefectMergePixel);
                //Debug_test();
                if (PairResu != DIT_CONV_SUCCESS)
                {
                    if (rslt == DIT_CONV_FRAMEOVERFLOW)
                        return rslt;
                    else
                        return PairResu;
                }
            }
            else if (m_Param.s_uiProcessing & DIT_CONV_MERGE_MIX && nDefectMergePixel > 0)
            {
                PairResu = CBlobStorage::MergeMix(nBlobStart, nDefectMergePixel);
                //Debug_test();
                if (PairResu != DIT_CONV_SUCCESS)
                {
                    if (rslt == DIT_CONV_FRAMEOVERFLOW)
                        return rslt;
                    else
                        return PairResu;
                }
            }
            //                TRACE("Merging %d\n", GetTickCount() - dwTick);
            //                dwTick = GetTickCount();
        }
    }
    return rslt;
}