1: // ccd_class.cpp
2: #include "ccd_class.h"
3:
4: CCDClass::CCDClass()
5: {
6: // initial variables
7: m_hCam = NULL;
8: m_hEvent = NULL;
9: m_sBufNr = -1;
10: m_imgBuf = 0;
11: m_wXResAct = 1392; // the default x resolution is 1392
12: m_wYResAct = 1040; // the default y resolution is 1040
13: m_imgRGB = new unsigned char[1392*1040*3];
14: }
15:
16: CCDClass::~CCDClass()
17: {
18: delete [] m_imgRGB;
19: imgRGB = 0;
20: }
21:
22: // Open camera
23: int CCDClass::OpenCamera()
24: {
25: PCO_OpenCamera(&m_hCam, 0); // default open successfully
26: return 0;
27: }
28:
29: // allocate buffer and set recording on
30: int CCDClass::InitialCamera()
31: {
32: m_sBufNr = -1; // mean the buffer will be a new buffer
33: PCO_ArmCamera(m_hCam);
34:
35: DWORD bufSize; // size of buffer in byte
36: int errCode;
37:
38: m_imgSize = m_wXResAct * m_wYResAct;
39: bufSize = 2*m_imgSize;
40: m_imgBuf = new WORD[m_imgSize];
41:
42: if (PCO_AllocateBuffer(m_hCam, &m_sBufNr, m_bufSize, &m_imgBuf, &m_hEvent) != 0) {
43: errCode = CloseCamera();
44: return errCode;
45: }
46:
47: if (PCO_SetRecordingState(m_hCam, 0x0001) != 0) {
48: errCode = CloseCamera();
49: return errCode;
50: }
51:
52: return 0;
53: }
54:
55: // record img in allocated buffer
56: int CCDClass::RunCamera()
57: {
58: if (PCO_AddBufferEx(m_hCam, 0, 0, m_sBufNr, m_wXResAct,
59: m_wYResAct, 14) != 0) { // 14 is bytes in one pixel
60: wxMessageBox(wxT("PCO_AddBufferEx"));
61: errCode = CloseCamera();
62: return errCode;
63: }
64:
65: return 0;
66: }
67:
68: // set recording off
69: int CCDClass::StopCamera()
70: {
71: if (PCO_SetRecordingState(m_hCam, 0x0000) != 0) {
72: errCode = CloseCamera();
73: return errCode;
74: }
75:
76: return 0;
77: }
78:
79: // close camera and free img buffer
80: int CCDClass::CloseCamera()
81: {
82: if (m_sBufNr >= 0) {
83: PCO_FreeBuffer(m_hCam, m_sBufNr);
84: }
85:
86: if (m_hCam != NULL) {
87: PCO_CloseCamera(m_hCam);
88: }
89: delete [] m_imgBuf;
90: m_imgBuf = 0;
91: return 999;
92: }
93:
94: // convert 16bit to 24bit rgb img
95: void CCDClass::Conv16to24()
96: {
97: unsigned char *m_cData = new unsigned char[m_imgSize];
98:
99: // convert 16bit img to 8bit
100: for (size_t i = 0; i < m_imgSize; ++i) {
101: m_cData[i] = (unsigned char)(m_imgBuf[i] >> 6);
102: }
103:
104: unsigned char *ptr1 = m_cData;
105: unsigned char *ptr2 = m_imgRBG;
106: for (size_t i = 0; i < m_imgSize; ++i) {
107: *ptr2++ = *ptr1;
108: *ptr2++ = *ptr1;
109: *ptr2++ = *ptr1++;
110: }
111:
112: delete [] m_cData;
113: m_cData = 0;
114: }
115:
116: HANDLE CCDClass::GethEvent()
117: {
118: return m_hEvent;
119: }
120:
121:
122: unsigned char* CCDClass::GetImgRGB()
123: {
124: return m_imgRGB;
125: }