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
#pragma once
 
#include <deque>
#include "../../EdgeInspector_App/Define/Global_Define.h"
 
class AFX_EXT_CLASS CMultiBuffer    // ´ÙÁß ¹öÆÛ ¼³Á¤, m_nBuff °³ÀÇ ¹öÆÛ¸¦ »ý¼º ¹× °ü¸®(¿©·¯ °³ÀÇ ½ºÄµ ¹öÆÛ ÀúÀå)
{    
    BYTE*    m_pTotalBuff;    // m_BuffCnt °³¼ö ¸¸Å­ÀÇ ¹öÆÛ¸¦ ÇѲ¨¹ø¿¡ ÇÒ´ç.
    int        m_BuffCnt;        // ¹öÆÛÀÇ °³¼ö
    SIZE_T    m_BuffSize;        // °³º° ¹öÆÛÀÇ Å©±â (frameWidth * frameHeight * frameCnt
 
                            // ¹öÆÛ´Â n°³ÀÇ Frame À¸·Î »ý¼º : Width * Height * Cnt
    int        m_FrameWidth, m_FrameHeight;
    int        m_FrameCnt;
public:
    int        GetFrameWidth() { return m_FrameWidth; }
    int        GetFrameHeight() { return m_FrameHeight; }
    int        GetFrameCount() { return m_FrameCnt; }
    int        GetBuffCount() { return m_BuffCnt; }
    SIZE_T    GetFrameSize() { return GetFrameWidth()*GetFrameHeight(); }
 
public:
    CMultiBuffer() { m_BuffCnt = 0; m_pTotalBuff = NULL; m_FrameWidth = m_FrameHeight = m_FrameCnt = 0; }
    ~CMultiBuffer()
    {
        if (m_pTotalBuff)
        {
            VirtualFree(m_pTotalBuff, 0, MEM_RELEASE);
            m_pTotalBuff = NULL;
        }
    }
    BYTE*    GetMultiBuffData(int id) { return m_pTotalBuff + m_BuffSize*id; }
    int        CreateMultiBuff(int buffCnt, int frameWidth, int frameHeight, int frameCnt)
    {
        m_BuffCnt = buffCnt;
        m_FrameWidth = frameWidth;
        m_FrameHeight = frameHeight;
        m_FrameCnt = frameCnt;
        m_BuffSize = (SIZE_T)frameWidth*frameHeight*frameCnt;
 
        SIZE_T frameSize = frameWidth* frameHeight;
        SIZE_T TotalBufferSize = frameSize*frameCnt*buffCnt;
 
        m_pTotalBuff = (BYTE*)VirtualAlloc(NULL, TotalBufferSize, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
        if (m_pTotalBuff == NULL)
        {
            return FALSE;
        }
 
        ZeroMemory(m_pTotalBuff, sizeof(BYTE)*TotalBufferSize);
 
        return TRUE;
    }
 
    void    ClearBuffer()
    {
        SIZE_T frameSize = m_FrameWidth * m_FrameHeight;
        SIZE_T TotalBufferSize = frameSize * m_FrameCnt*m_BuffCnt;
 
        ZeroMemory(m_pTotalBuff, sizeof(BYTE)*TotalBufferSize);
    }
};
 
class AFX_EXT_CLASS CFrameBufferController
{
public:
    CFrameBufferController(void);
    virtual ~CFrameBufferController(void);
 
public:
    void            ClearBuffer();
    BOOL            CreateBuffer(int iCamera, int nFrameWidth, int nFrameHeight, int nFrameCnt, int nBufferCnt = 1);
    CMultiBuffer*    GetMultiBuffer() { return &m_MultiBuffer; }
    BYTE            *GetMultiBuffData(int id) { return m_MultiBuffer.GetMultiBuffData(id); }
 
    void            SetMutualEx(BOOL bEnter)
    {
        if (bEnter == TRUE)
            EnterCriticalSection(&m_csProcBuffer);
        else
            LeaveCriticalSection(&m_csProcBuffer);
    }
 
    int                GetCameraIdx() { return m_nCameraIdx; }
    LPBYTE            GetFrameBuferHeader(int iScan, int iFrame);
    BOOL            CheckProcFrame(int iFrame);
    BOOL            SetFrameBuffer(int iScan, int iFrame, LPBYTE lpBuffer);
    LPBYTE            GetFrameHeaderLine(int iScan, int nLine = 0);
    LPBYTE            GetFrameHeader_Line_FromStartLine(int iScan, int iFrame, int nStartLine = 0);
    int                GetFrameWidth() { return GetMultiBuffer()->GetFrameWidth(); }
    int                GetFrameHeight() { return GetMultiBuffer()->GetFrameHeight(); }
    int                GetFrameCount() { return GetMultiBuffer()->GetFrameCount(); }
    int                GetFrameSize() { return (int)GetMultiBuffer()->GetFrameSize(); }
 
protected:
    CRITICAL_SECTION    m_csProcBuffer;    // Critical Section
    CMultiBuffer    m_MultiBuffer;
    int                m_nCameraIdx;
};
 
struct stFrameIndex
{
    stFrameIndex()
    {
        nScanIdx = -1;
        nFrameIdx = -1;
    }
    stFrameIndex(const stFrameIndex &rhs)
    {
        this->nScanIdx = rhs.nScanIdx;
        this->nFrameIdx = rhs.nFrameIdx;
    }
    stFrameIndex(int nScan, int nGrab)
    {
        nScanIdx = nScan;
        nFrameIdx = nGrab;
    }
 
    int nScanIdx;
    int nFrameIdx;
};
 
typedef deque<stFrameIndex> dqGrabIdx;
typedef deque<stFrameIndex>::iterator dqGrabIdxIt;