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
#if !defined(AFX_SLIMSCROLLVIEW_H__08F7FD45_AE99_43B5_85BC_41CC19F62C8E__INCLUDED_)
#define AFX_SLIMSCROLLVIEW_H__08F7FD45_AE99_43B5_85BC_41CC19F62C8E__INCLUDED_
 
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// SampleView.h : header file
//
 
#define MSG_SCANVIEW (WM_USER+105)
#define MSG_SCANVIEW_MOUSEPOS (WM_USER+106)
#define MSG_SCANVIEW_POS_ADD (WM_USER+107)//20140528
#define MSG_SCANVIEW_POS_MOD (WM_USER+108)//20140528
 
enum SLIM_MODECOMMAND{SLIM_MODE_ZOOMIN=0,SLIM_MODE_ZOOMOUT,SLIM_MODE_NORMAL,SLIM_MODE_POINT};
 
#define SLIM_MAXZOOMIN     10       // Maximum zoom-in factor
#define SLIM_MAXZOOMOUT    2
 
 
const LONG SLIM_IMG_MAX_WIDTH = 200;
const LONG SLIM_IMG_MAX_HEIGHT = 120;
const double SLIM_SCALE_FACTOR = 1;
 
//Region of interest (ROI)
#ifndef _FV_ROI_
#define _FV_ROI_
typedef struct {
    LONG    u1;
    LONG    v1;
    LONG    u2;
    LONG    v2;
} FV_ROI, *FV_LPROI;
#endif
 
 
 
#ifndef RANGEIN
#define RANGEIN(a, r1, r2)        (((a>=r1)&&(a<=r2)) ? (1) : (0))
#endif
 
//////////////////////////////////////////////////////////////////////////
// °á°ú¿µ»ó ¹× °á°ú¸¦ µð½ºÇ÷¹ÀÌÇØÁØ´Ù.
//////////////////////////////////////////////////////////////////////////
class CSlimScrollView : public CScrollView
{
public:
    CSlimScrollView();           // protected constructor used by dynamic creation    
    virtual ~CSlimScrollView();
    DECLARE_DYNCREATE(CSlimScrollView)
 
public:        
    void            SetBrightHwnd(CWnd *pWnd){m_pBrightHWnd=pWnd;}
    void            SetOrgImgSize(int width, int height)
                    {m_ImageWidth=m_ScaleWidth=width,m_ImageHeight=m_ScaleHeight=height,m_zoomScale=1.0,m_pDispBuf=m_pSetupIMG;}
    CSize            GetOrgImgSize(){return CSize(m_ImageWidth,m_ImageHeight);}
    void            SetDrawRect(BOOL bDraw){m_bDrawRect=bDraw;}
    void            SetDrawNotchInsPos(BOOL bDraw){m_bDrawNotchInsPos=bDraw;}//20140528
    void            SetRectPoint(CPoint point){m_pRectPoint=point;}    
    BOOL            InitGDI(int width, int height, bool bColor);
    void            SetHWnd(CWnd *pWnd){m_pParents=pWnd;}
    LPBYTE            GetBuffer(){return m_pSetupIMG;}    
    void            DrawRefresh();
    void            SetMode(SLIM_MODECOMMAND nMode);
    void            SetDefectRect(CRect* a_rtDefect){ if(a_rtDefect) m_rtDefect.SetRect(a_rtDefect->left,a_rtDefect->top,a_rtDefect->right,a_rtDefect->bottom);}
    void            SetDrawDefect(bool bDraw){m_bDefect = bDraw;}
    void            SetSendMessage(bool bMessage){m_bMessage = bMessage;}
    void            SetZoomMode(bool bZoom){m_bZoomMode = bZoom;}
    void            ResetImgBuf(){ ZeroMemory(m_pSetupIMG,sizeof(BYTE)*m_width*m_height); m_pDispBuf = m_pSetupIMG;}
    void            ReleaseMemory();    
    void            SetMarkPos(CPoint origin,CPoint offset){m_OriginPos=origin,m_OffsetPos=offset;}    
    CRect            GetDrawRect();    
    void            SetSplinePosition(std::multimap<int, CSplinePoint> *pPoint,CPoint pointOffset);
    std::multimap<int, CSplinePoint>    *GetSplinePos(){return &m_pSplinePos;}    
    CPoint            GetSplineOffset(){return m_pointSplineOffset;}
 
    void            SetNotchInsPosition(std::multimap<int, CPoint> *pPoint);//20140528
    void            SetNotchInsListIdx(int Idx){m_nNotchInsListIdx = Idx;}//20140528
    void            SetNotchInsPosMod(BOOL bMod){m_bNotchInsPosMod = bMod;}//20140528
    void            SetNotchCadCenterPos(int nPosX, int nPosY);//20140528
 
protected:
    void            EnlargeImage(BYTE *pInBuff, LONG wSrcWidth, LONG wSrcHeight, 
                                 BYTE *pOutBuff, LONG wDestWidth, LONG wDestHeight,double scale);
    BYTE            CalcWeightedColor(BYTE* pPixels, CSize size, double dX, double dY);
    void            ShrinkImage(BYTE *pInBuff, LONG wSrcWidth, LONG wSrcHeight, 
                                BYTE *pOutBuff, LONG wDestWidth, LONG wDestHeight,double scale);
    BOOL            CalcScaleSize();
    BOOL            DoZoomInOut();
    void            DisplayError();
    void            DrawImage(LPBYTE pImg);
    void            DrawRectangle(CRect rect,COLORREF color);
    void            DrawMark();
    void            DrawLine(long sx, long sy, long ex, long ey, COLORREF color,int nStyle=PS_SOLID);
    void            DrawPoint();
    void            DrawSpline();
    void            DrawNotchInsPos();//20140528
 
    void            DoOrigin();
    CString            GetMoneyRule(CString strMoney, int nRuleSpace/*=0*/);
 
 
private:
    
    HDC            m_hMemDC;
    HDC            m_hMainDC;
    CDC*        m_pDC;
    BITMAPINFO    *m_pBMI;
    
    HWND        m_hImageWnd;
    CWnd        *m_pParents;
    LPBYTE        m_pSetupIMG;
    LPBYTE        m_pScaleIMg;
    LPBYTE        m_pDispBuf;
    HBITMAP        m_hBitmap;    
    
    CPoint        m_pRectPoint;
    BOOL        m_bDrawRect;
    BOOL        m_bDrawNotchInsPos;//20140528
 
    SLIM_MODECOMMAND    m_nCurMode;
    HCURSOR        m_pCursor;
    
    LONG        m_ImageWidth;
    LONG        m_ImageHeight;
    LONG        m_ScaleWidth;    
    LONG        m_ScaleHeight;
    double        m_zoomScale;
    CWnd*        m_pBrightHWnd;
    CRect        m_rtDefect;
    bool        m_bDefect;
    CRect        m_rtRect;
    bool        m_bRect;    
    
 
    bool        m_bMessage;
    int            m_width;
    int            m_height;
 
    CPoint        m_OriginPos;
    CPoint        m_OffsetPos;
    CPoint        m_MousePoint;
 
    bool        m_bZoomMode;        // Áß¿ä ÁÜ ¸ðµå¿Í ³ë¸» ¸ðµå¸¦ ±¸ºÐ    
    std::multimap<int, CSplinePoint> m_pSplinePos;    
    CPoint        m_pointSplineOffset;
 
    std::multimap<int, CPoint> m_pNotchInsPos;//20140528    
    int            m_nNotchInsListIdx;//20140528
    BOOL        m_bNotchInsPosMod;//20140528
    int            m_nNotchCadCenterX;//20140528
    int            m_nNotchCadCenterY;//20140528
// Operations
public:
 
// Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CSlimScrollView)
    public:
    virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL);
    virtual BOOL DestroyWindow();
    protected:
    virtual void OnDraw(CDC* pDC);      // overridden to draw this view
    virtual void OnInitialUpdate();     // first time after construct
    virtual void PostNcDestroy();
    //}}AFX_VIRTUAL
    
#ifdef _DEBUG
    virtual void AssertValid() const;
    virtual void Dump(CDumpContext& dc) const;
#endif
 
    // Generated message map functions
    //{{AFX_MSG(CSlimScrollView)
    afx_msg void OnMouseMove(UINT nFlags, CPoint point);
    afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
    afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
    afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
    afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
    //}}AFX_MSG
    afx_msg BOOL OnEraseBkgnd(CDC* pDC);
    afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
    afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
    afx_msg int OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message);
    DECLARE_MESSAGE_MAP()
public:
    afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);//20140528
};
 
/////////////////////////////////////////////////////////////////////////////
 
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
 
#endif // !defined(AFX_SAMPLEVIEW_H__08F7FD45_AE99_43B5_85BC_41CC19F62C8E__INCLUDED_)