1 //
2 //  libMallincamTest.h
3 //  libMallincamTest
4 //
5 //  Created by pufahl on 5/18/16.
6 //  Copyright (c) 2016 rD. All rights reserved.
7 //
8 
9 #ifndef libMallincamTest_libMallincamTest_h
10 #define libMallincamTest_libMallincamTest_h
11 
12 #ifdef _WIN32
13 #ifndef _INC_WINDOWS
14 #include <windows.h>
15 #endif
16 #endif
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 #ifdef _WIN32
23 
24 #pragma pack(push, 8)
25 #ifdef MALLINCAMCAM_EXPORTS
26 #define mallincam_ports(x)    __declspec(dllexport)   x   __stdcall
27 #elif !defined(MALLINCAM_NOIMPORTS)
28 #define mallincam_ports(x)    __declspec(dllimport)   x   __stdcall
29 #else
30 #define mallincam_ports(x)    x   __stdcall
31 #endif
32 
33 #else
34 
35 #define mallincam_ports(x)    x
36 
37 #ifndef MRESULT
38 #define MRESULT unsigned long
39 #endif
40 
41 #ifndef __stdcall
42 #define __stdcall
43 #endif
44 
45 #ifndef CALLBACK
46 #define CALLBACK
47 #endif
48 
49 #ifndef BOOL
50 #define BOOL int
51 #endif
52 
53 #ifndef __BITMAPINFOHEADER_DEFINED__
54 #define __BITMAPINFOHEADER_DEFINED__
55     typedef struct {
56         unsigned        biSize;
57         int             biWidth;
58         int             biHeight;
59         unsigned short  biPlanes;
60         unsigned short  biBitCount;
61         unsigned        biCompression;
62         unsigned        biSizeImage;
63         int             biXPelsPerMeter;
64         int             biYPelsPerMeter;
65         unsigned        biClrUsed;
66         unsigned        biClrImportant;
67     } BITMAPINFOHEADER;
68 #endif
69 
70 #ifndef __RECT_DEFINED__
71 #define __RECT_DEFINED__
72     typedef struct {
73         int left;
74         int top;
75         int right;
76         int bottom;
77     } RECT, *PRECT;
78 #endif
79 
80 #endif
81 
82     /* handle */
83     typedef struct MallincamT { int unused; } *HMallinCam;
84 
85 #define MALLINCAM_MAX                     16
86 
87 #define MALLINCAM_FLAG_CMOS               0x00000001  /* cmos sensor */
88 #define MALLINCAM_FLAG_CCD_PROGRESSIVE    0x00000002  /* progressive ccd sensor */
89 #define MALLINCAM_FLAG_CCD_INTERLACED     0x00000004  /* interlaced ccd sensor */
90 #define MALLINCAM_FLAG_ROI_HARDWARE       0x00000008  /* support hardware ROI */
91 #define MALLINCAM_FLAG_MONO               0x00000010  /* monochromatic */
92 #define MALLINCAM_FLAG_BINSKIP_SUPPORTED  0x00000020  /* support bin/skip mode, see Mallincam_put_Mode and Mallincam_get_Mode */
93 #define MALLINCAM_FLAG_USB30              0x00000040  /* USB 3.0 */
94 #define MALLINCAM_FLAG_TEC                0x00000080  /* Thermoelectric Cooler */
95 #define MALLINCAM_FLAG_USB30_OVER_USB20   0x00000100  /* usb3.0 camera connected to usb2.0 port */
96 #define MALLINCAM_FLAG_ST4                0x00000200  /* ST4 */
97 #define MALLINCAM_FLAG_GETTEMPERATURE     0x00000400  /* support to get the temperature of sensor */
98 #define MALLINCAM_FLAG_PUTTEMPERATURE     0x00000800  /* support to put the temperature of sensor */
99 #define MALLINCAM_FLAG_BITDEPTH10         0x00001000  /* Maximum Bit Depth = 10 */
100 #define MALLINCAM_FLAG_BITDEPTH12         0x00002000  /* Maximum Bit Depth = 12 */
101 #define MALLINCAM_FLAG_BITDEPTH14         0x00004000  /* Maximum Bit Depth = 14 */
102 #define MALLINCAM_FLAG_BITDEPTH16         0x00008000  /* Maximum Bit Depth = 16 */
103 #define MALLINCAM_FLAG_FAN                0x00010000  /* cooling fan */
104 #define MALLINCAM_FLAG_TEC_ONOFF          0x00020000  /* Thermoelectric Cooler can be turn on or off */
105 #define MALLINCAM_FLAG_ISP                0x00040000  /* Image Signal Processing supported */
106 #define MALLINCAM_FLAG_TRIGGER_SOFTWARE   0x00080000  /* support software trigger */
107 #define MALLINCAM_FLAG_TRIGGER_EXTERNAL   0x00100000  /* support external trigger */
108 #define MALLINCAM_FLAG_TRIGGER_SINGLE     0x00200000  /* only support trigger single: one trigger, one image */
109 
110 #define MALLINCAM_TEMP_DEF                6503
111 #define MALLINCAM_TEMP_MIN                2000
112 #define MALLINCAM_TEMP_MAX                15000
113 #define MALLINCAM_TINT_DEF                1000
114 #define MALLINCAM_TINT_MIN                200
115 #define MALLINCAM_TINT_MAX                2500
116 #define MALLINCAM_HUE_DEF                 0
117 #define MALLINCAM_HUE_MIN                 (-180)
118 #define MALLINCAM_HUE_MAX                 180
119 #define MALLINCAM_SATURATION_DEF          128
120 #define MALLINCAM_SATURATION_MIN          0
121 #define MALLINCAM_SATURATION_MAX          255
122 #define MALLINCAM_BRIGHTNESS_DEF          0
123 #define MALLINCAM_BRIGHTNESS_MIN          (-64)
124 #define MALLINCAM_BRIGHTNESS_MAX          64
125 #define MALLINCAM_CONTRAST_DEF            0
126 #define MALLINCAM_CONTRAST_MIN            (-100)
127 #define MALLINCAM_CONTRAST_MAX            100
128 #define MALLINCAM_GAMMA_DEF               100
129 #define MALLINCAM_GAMMA_MIN               20
130 #define MALLINCAM_GAMMA_MAX               180
131 #define MALLINCAM_AETARGET_DEF            120
132 #define MALLINCAM_AETARGET_MIN            16
133 #define MALLINCAM_AETARGET_MAX            235
134 #define MALLINCAM_WBGAIN_DEF              0
135 #define MALLINCAM_WBGAIN_MIN              (-128)
136 #define MALLINCAM_WBGAIN_MAX              128
137 
138     typedef struct{
139         unsigned    width;
140         unsigned    height;
141     }MallincamResolution;
142 
143     /* In Windows platform, we always use UNICODE wchar_t */
144     /* In Linux or OSX, we use char */
145     typedef struct{
146 #ifdef _WIN32
147         const wchar_t*      name;       /* model name */
148 #else
149         const char*         name;
150 #endif
151         unsigned            flag;       /* MALLINCAM_FLAG_xxx */
152         unsigned            maxspeed;   /* number of speed level, same as Mallincam_get_MaxSpeed(), the speed range = [0, maxspeed], closed interval */
153         unsigned            preview;    /* number of preview resolution, same as Mallincam_get_ResolutionNumber() */
154         unsigned            still;      /* number of still resolution, same as Mallincam_get_StillResolutionNumber() */
155         MallincamResolution   res[MALLINCAM_MAX];
156     }MallincamModel;
157 
158     typedef struct{
159 #ifdef _WIN32
160         wchar_t             displayname[64];    /* display name */
161         wchar_t             id[64];     /* unique and opaque id of a connected camera, for Mallincam_Open */
162 #else
163         char                displayname[64];    /* display name */
164         char                id[64];     /* unique and opaque id of a connected camera, for Mallincam_Open */
165 #endif
166         const MallincamModel* model;
167     }MallincamInst;
168 
169 
170     typedef enum MC_ERROR_CODE{ //ASI ERROR CODE
171         MC_SUCCESS=0,
172         MC_ERROR_INVALID_INDEX, //no camera connected or index value out of boundary
173         MC_ERROR_INVALID_ID, //invalid ID
174         MC_ERROR_INVALID_CONTROL_TYPE, //invalid control type
175         MC_ERROR_CAMERA_CLOSED, //camera didn't open
176         MC_ERROR_CAMERA_REMOVED, //failed to find the camera, maybe the camera has been removed
177         MC_ERROR_INVALID_PATH, //cannot find the path of the file
178         MC_ERROR_INVALID_FILEFORMAT,
179         MC_ERROR_INVALID_SIZE, //wrong video format size
180         MC_ERROR_INVALID_IMGTYPE, //unsupported image formate
181         MC_ERROR_OUTOF_BOUNDARY, //the image is out of boundary
182         MC_ERROR_TIMEOUT, //timeout
183         MC_ERROR_INVALID_SENQUENCE,//stop capture first
184         MC_ERROR_BUFFER_TOO_SMALL, //buffer size is not big enough
185         MC_ERROR_VIDEO_MODE_ACTIVE,
186         MC_ERROR_EXPOSURE_IN_PROGRESS,
187         MC_ERROR_GENERAL_ERROR,//general error, eg: value is out of valid range
188         MC_ERROR_END
189     }MC_ERROR_CODE;
190     typedef void (__stdcall*    PMALLINCAM_EVENT_CALLBACK)(unsigned nEvent, void* pCallbackCtx);
191 
192     typedef void (__stdcall*    PMALLINCAM_DATA_CALLBACK)(const void* pData, const BITMAPINFOHEADER* pHeader, BOOL bSnap, void* pCallbackCtx);
193 
194 
195     class  MallincamGuider
196     {
197     public:
198         HMallinCam m_Hmallincam;
199         MallincamInst m_ti[MALLINCAM_MAX];
200         int m_nIndex;
201         MallincamGuider();
202         ~MallincamGuider();
203 
204         //bool OpenDevice(const char* id);
205 #ifdef _WIN32
206         mallincam_ports(HMallinCam) Mallincam_Open(const wchar_t* id);
207 #else
208         mallincam_ports(HMallinCam) Mallincam_Open(const char* id);
209 #endif
210 
211         //int EnumCameras();
212         mallincam_ports(unsigned) Mallincam_Enum(MallincamInst pti[MALLINCAM_MAX]);
213 
214         //MC_ERROR_CODE StartPullModeWithCallback(HMallinCam h, PMALLINCAM_EVENT_CALLBACK pEventCallback, void* pCallbackContext);
215         mallincam_ports(MRESULT)      Mallincam_StartPullModeWithCallback(HMallinCam h, PMALLINCAM_EVENT_CALLBACK pEventCallback, void* pCallbackContext);
216 
217         MallincamModel GetCameraProperty(int i);
218 
219         MC_ERROR_CODE GetVideoData(int iCameraID, unsigned char* pBuffer, long lBuffSize, int iWaitms);
220 
221 
222         //MC_ERROR_CODE PullImage(HMallinCam h, void* pImageData, int bits, unsigned* pnWidth, unsigned* pnHeight);
223         mallincam_ports(MRESULT)      Mallincam_PullImage(HMallinCam h, void* pImageData, int bits, unsigned* pnWidth, unsigned* pnHeight);
224 
225         //MC_ERROR_CODE Stop(HMallinCam h);
226         mallincam_ports(MRESULT)  Mallincam_Stop(HMallinCam h);
227 
228         //MC_ERROR_CODE GetResolution(HMallinCam h, unsigned nResolutionIndex, int* pWidth, int* pHeight );
229         mallincam_ports(MRESULT)  Mallincam_get_Resolution(HMallinCam h, unsigned nResolutionIndex, int* pWidth, int* pHeight);
230 
231         mallincam_ports(MRESULT)  Mallincam_ST4PulseGuide(HMallinCam h, unsigned nDirect, unsigned nDuration);
232 
233         mallincam_ports(MRESULT)  Mallincam_get_ExpoAGainRange(HMallinCam h, unsigned short* nMin, unsigned short* nMax, unsigned short* nDef);
234 
235         mallincam_ports(MRESULT)  Mallincam_get_ExpoAGain(HMallinCam h, unsigned short* AGain); /* percent, such as 300 */
236         mallincam_ports(MRESULT)  Mallincam_put_ExpoAGain(HMallinCam h, unsigned short AGain); /* percent */
237         mallincam_ports(MRESULT)  Mallincam_get_ExpoTime(HMallinCam h, unsigned* Time); /* in microseconds */
238         mallincam_ports(MRESULT)  Mallincam_put_ExpoTime(HMallinCam h, unsigned Time); /* in microseconds */
239 
240          mallincam_ports(MRESULT)  Mallincam_StartPushMode(HMallinCam h, PMALLINCAM_DATA_CALLBACK pDataCallback, void* pCallbackCtx);
241 
242     };
243 
244     /*
245      get the version of this dll, which is: 1.8.7291.20160427
246      */
247 #ifdef _WIN32
248     mallincam_ports(const wchar_t*)   Mallincam_Version();
249 #else
250     mallincam_ports(const char*)      Mallincam_Version();
251 #endif
252     /*
253      enumerate the cameras connected to the computer, return the number of enumerated.
254 
255      MallincamInst arr[MALLINCAM_MAX];
256      unsigned cnt = Mallincam_Enum(arr);
257      for (unsigned i = 0; i < cnt; ++i)
258      ...
259 
260      if pti == NULL, then, only the number is returned.
261      */
262     mallincam_ports(unsigned) Mallincam_Enum(MallincamInst pti[MALLINCAM_MAX]);
263 
264     /* use the id of MallincamInst, which is enumerated by Mallincam_Enum.
265      if id is NULL, Mallincam_Open will open the first camera.
266      */
267 #ifdef _WIN32
268     mallincam_ports(HMallinCam) Mallincam_Open(const wchar_t* id);
269 #else
270     mallincam_ports(HMallinCam) Mallincam_Open(const char* id);
271 #endif
272 
273     /*
274      the same with Mallincam_Open, but use the index as the parameter. such as:
275      index == 0, open the first camera,
276      index == 1, open the second camera,
277      etc
278      */
279     mallincam_ports(HMallinCam) Mallincam_OpenByIndex(unsigned index);
280 
281     mallincam_ports(void)     Mallincam_Close(HMallinCam h); /* close the handle */
282 
283 #define MALLINCAM_EVENT_EXPOSURE      0x0001    /* exposure time changed */
284 #define MALLINCAM_EVENT_TEMPTINT      0x0002    /* white balance changed, Temp/Tint mode */
285 #define MALLINCAM_EVENT_CHROME        0x0003    /* reversed, do not use it */
286 #define MALLINCAM_EVENT_IMAGE         0x0004    /* live image arrived, use Mallincam_PullImage to get this image */
287 #define MALLINCAM_EVENT_STILLIMAGE    0x0005    /* snap (still) frame arrived, use Mallincam_PullStillImage to get this frame */
288 #define MALLINCAM_EVENT_WBGAIN        0x0006    /* white balance changed, RGB Gain mode */
289 #define MALLINCAM_EVENT_ERROR         0x0080    /* something error happens */
290 #define MALLINCAM_EVENT_DISCONNECTED  0x0081    /* camera disconnected */
291 
292 #ifdef _WIN32
293     mallincam_ports(MRESULT)      Mallincam_StartPullModeWithWndMsg(HMallinCam h, HWND hWnd, UINT nMsg);
294 #endif
295 
296     mallincam_ports(MRESULT)      Mallincam_StartPullModeWithCallback(HMallinCam h, PMALLINCAM_EVENT_CALLBACK pEventCallback, void* pCallbackContext);
297 
298     /*
299      bits: 24 (RGB24), 32 (RGB32), or 8 (Grey). Int RAW mode, this parameter is ignored.
300      pnWidth, pnHeight: OUT parameter
301      */
302     mallincam_ports(MRESULT)      Mallincam_PullImage(HMallinCam h, void* pImageData, int bits, unsigned* pnWidth, unsigned* pnHeight);
303     mallincam_ports(MRESULT)      Mallincam_PullStillImage(HMallinCam h, void* pImageData, int bits, unsigned* pnWidth, unsigned* pnHeight);
304 
305     /*
306      (NULL == pData) means that something is error
307      pCallbackCtx is the callback context which is passed by Mallincam_Start
308      bSnap: TRUE if Mallincam_Snap
309 
310      pDataCallback is callbacked by an internal thread of toupcam.dll, so please pay attention to multithread problem
311      */
312     typedef void (__stdcall*    PMALLINCAM_DATA_CALLBACK)(const void* pData, const BITMAPINFOHEADER* pHeader, BOOL bSnap, void* pCallbackCtx);
313     mallincam_ports(MRESULT)  Mallincam_StartPushMode(HMallinCam h, PMALLINCAM_DATA_CALLBACK pDataCallback, void* pCallbackCtx);
314 
315     mallincam_ports(MRESULT)  Mallincam_Stop(HMallinCam h);
316     mallincam_ports(MRESULT)  Mallincam_Pause(HMallinCam h, BOOL bPause);
317 
318     /*  for pull mode: MALLINCAM_EVENT_STILLIMAGE, and then Mallincam_PullStillImage
319      for push mode: the snapped image will be return by PMALLINCAM_DATA_CALLBACK, with the parameter 'bSnap' set to 'TRUE' */
320     mallincam_ports(MRESULT)  Mallincam_Snap(HMallinCam h, unsigned nResolutionIndex);  /* still image snap */
321 
322     /*
323      soft trigger:
324      nNumber:    0xffff:     trigger continuously
325      0:          cancel trigger
326      others:     number of images to be triggered
327      */
328     mallincam_ports(MRESULT)  Mallincam_Trigger(HMallinCam h, unsigned short nNumber);
329     /*
330      put_Size, put_eSize, can be used to set the video output resolution BEFORE ToupCam_Start.
331      put_Size use width and height parameters, put_eSize use the index parameter.
332      for example, UCMOS03100KPA support the following resolutions:
333      index 0:    2048,   1536
334      index 1:    1024,   768
335      index 2:    680,    510
336      so, we can use put_Size(h, 1024, 768) or put_eSize(h, 1). Both have the same effect.
337      */
338     mallincam_ports(MRESULT)  Mallincam_put_Size(HMallinCam h, int nWidth, int nHeight);
339     mallincam_ports(MRESULT)  Mallincam_get_Size(HMallinCam h, int* pWidth, int* pHeight);
340     mallincam_ports(MRESULT)  Mallincam_put_eSize(HMallinCam h, unsigned nResolutionIndex);
341     mallincam_ports(MRESULT)  Mallincam_get_eSize(HMallinCam h, unsigned* pnResolutionIndex);
342 
343     mallincam_ports(MRESULT)  Mallincam_get_ResolutionNumber(HMallinCam h);
344     mallincam_ports(MRESULT)  Mallincam_get_Resolution(HMallinCam h, unsigned nResolutionIndex, int* pWidth, int* pHeight);
345     mallincam_ports(MRESULT)  Mallincam_get_ResolutionRatio(HMallinCam h, unsigned nResolutionIndex, int* pNumerator, int* pDenominator);
346     mallincam_ports(MRESULT)  Mallincam_get_Field(HMallinCam h);
347 
348     /*
349      FourCC:
350      MAKEFOURCC('G', 'B', 'R', 'G')
351      MAKEFOURCC('R', 'G', 'G', 'B')
352      MAKEFOURCC('B', 'G', 'G', 'R')
353      MAKEFOURCC('G', 'R', 'B', 'G')
354      MAKEFOURCC('Y', 'U', 'Y', 'V')
355      MAKEFOURCC('Y', 'Y', 'Y', 'Y')
356      */
357     mallincam_ports(MRESULT)  Mallincam_get_RawFormat(HMallinCam h, unsigned* nFourCC, unsigned* bitdepth);
358 
359     /*
360      ------------------------------------------------------------------|
361      | Parameter               |   Range       |   Default             |
362      |-----------------------------------------------------------------|
363      | Auto Exposure Target    |   10~230      |   120                 |
364      | Temp                    |   2000~15000  |   6503                |
365      | Tint                    |   200~2500    |   1000                |
366      | LevelRange              |   0~255       |   Low = 0, High = 255 |
367      | Contrast                |   -100~100    |   0                   |
368      | Hue                     |   -180~180    |   0                   |
369      | Saturation              |   0~255       |   128                 |
370      | Brightness              |   -64~64      |   0                   |
371      | Gamma                   |   20~180      |   100                 |
372      | WBGain                  |   -128~128    |   0                   |
373      ------------------------------------------------------------------|
374      */
375 
376 #ifndef __MALLINCAM_CALLBACK_DEFINED__
377 #define __MALLINCAM_CALLBACK_DEFINED__
378     typedef void (__stdcall* PIMALLINCAM_EXPOSURE_CALLBACK)(void* pCtx);
379     typedef void (__stdcall* PIMALLINCAM_WHITEBALANCE_CALLBACK)(const int aGain[3], void* pCtx);
380     typedef void (__stdcall* PIMALLINCAM_TEMPTINT_CALLBACK)(const int nTemp, const int nTint, void* pCtx);
381     typedef void (__stdcall* PIMALLINCAM_HISTOGRAM_CALLBACK)(const float aHistY[256], const float aHistR[256], const float aHistG[256], const float aHistB[256], void* pCtx);
382     typedef void (__stdcall* PIMALLINCAM_CHROME_CALLBACK)(void* pCtx);
383 #endif
384 
385     mallincam_ports(MRESULT)  Mallincam_get_AutoExpoEnable(HMallinCam h, BOOL* bAutoExposure);
386     mallincam_ports(MRESULT)  Mallincam_put_AutoExpoEnable(HMallinCam h, BOOL bAutoExposure);
387     mallincam_ports(MRESULT)  Mallincam_get_AutoExpoTarget(HMallinCam h, unsigned short* Target);
388     mallincam_ports(MRESULT)  Mallincam_put_AutoExpoTarget(HMallinCam h, unsigned short Target);
389 
390     /*set the maximum auto exposure time and analog agin. The default maximum auto exposure time is 350ms */
391     mallincam_ports(MRESULT)  Mallincam_put_MaxAutoExpoTimeAGain(HMallinCam h, unsigned maxTime, unsigned short maxAGain);
392 
393     mallincam_ports(MRESULT)  Mallincam_get_ExpoTime(HMallinCam h, unsigned* Time); /* in microseconds */
394     mallincam_ports(MRESULT)  Mallincam_put_ExpoTime(HMallinCam h, unsigned Time); /* in microseconds */
395     mallincam_ports(MRESULT)  Mallincam_get_ExpTimeRange(HMallinCam h, unsigned* nMin, unsigned* nMax, unsigned* nDef);
396 
397     mallincam_ports(MRESULT)  Mallincam_get_ExpoAGain(HMallinCam h, unsigned short* AGain); /* percent, such as 300 */
398     mallincam_ports(MRESULT)  Mallincam_put_ExpoAGain(HMallinCam h, unsigned short AGain); /* percent */
399     mallincam_ports(MRESULT)  Mallincam_get_ExpoAGainRange(HMallinCam h, unsigned short* nMin, unsigned short* nMax, unsigned short* nDef);
400 
401     /* Auto White Balance, Temp/Tint Mode */
402     mallincam_ports(MRESULT)  Mallincam_AwbOnePush(HMallinCam h, PIMALLINCAM_TEMPTINT_CALLBACK fnTTProc, void* pTTCtx); /* auto white balance "one push". The function must be called AFTER Mallincam_StartXXXX */
403 
404     /* Auto White Balance, RGB Gain Mode */
405     mallincam_ports(MRESULT)  Mallincam_AwbInit(HMallinCam h, PIMALLINCAM_WHITEBALANCE_CALLBACK fnWBProc, void* pWBCtx);
406 
407     /* White Balance, Temp/Tint mode */
408     mallincam_ports(MRESULT)  Mallincam_put_TempTint(HMallinCam h, int nTemp, int nTint);
409     mallincam_ports(MRESULT)  Mallincam_get_TempTint(HMallinCam h, int* nTemp, int* nTint);
410 
411     /* White Balance, RGB Gain mode */
412     mallincam_ports(MRESULT)  Mallincam_put_WhiteBalanceGain(HMallinCam h, int aGain[3]);
413     mallincam_ports(MRESULT)  Mallincam_get_WhiteBalanceGain(HMallinCam h, int aGain[3]);
414 
415     mallincam_ports(MRESULT)  Mallincam_put_Hue(HMallinCam h, int Hue);
416     mallincam_ports(MRESULT)  Mallincam_get_Hue(HMallinCam h, int* Hue);
417     mallincam_ports(MRESULT)  Mallincam_put_Saturation(HMallinCam h, int Saturation);
418     mallincam_ports(MRESULT)  Mallincam_get_Saturation(HMallinCam h, int* Saturation);
419     mallincam_ports(MRESULT)  Mallincam_put_Brightness(HMallinCam h, int Brightness);
420     mallincam_ports(MRESULT)  Mallincam_get_Brightness(HMallinCam h, int* Brightness);
421     mallincam_ports(MRESULT)  Mallincam_get_Contrast(HMallinCam h, int* Contrast);
422     mallincam_ports(MRESULT)  Mallincam_put_Contrast(HMallinCam h, int Contrast);
423     mallincam_ports(MRESULT)  Mallincam_get_Gamma(HMallinCam h, int* Gamma); /* percent */
424     mallincam_ports(MRESULT)  Mallincam_put_Gamma(HMallinCam h, int Gamma);  /* percent */
425 
426     mallincam_ports(MRESULT)  Mallincam_get_Chrome(HMallinCam h, BOOL* bChrome);  /* monochromatic mode */
427     mallincam_ports(MRESULT)  Mallincam_put_Chrome(HMallinCam h, BOOL bChrome);
428 
429     mallincam_ports(MRESULT)  Mallincam_get_VFlip(HMallinCam h, BOOL* bVFlip);  /* vertical flip */
430     mallincam_ports(MRESULT)  Mallincam_put_VFlip(HMallinCam h, BOOL bVFlip);
431     mallincam_ports(MRESULT)  Mallincam_get_HFlip(HMallinCam h, BOOL* bHFlip);
432     mallincam_ports(MRESULT)  Mallincam_put_HFlip(HMallinCam h, BOOL bHFlip); /* horizontal flip */
433 
434     mallincam_ports(MRESULT)  Mallincam_get_Negative(HMallinCam h, BOOL* bNegative);  /* negative film */
435     mallincam_ports(MRESULT)  Mallincam_put_Negative(HMallinCam h, BOOL bNegative);
436 
437     mallincam_ports(MRESULT)  Mallincam_put_Speed(HMallinCam h, unsigned short nSpeed);
438     mallincam_ports(MRESULT)  Mallincam_get_Speed(HMallinCam h, unsigned short* pSpeed);
439     mallincam_ports(MRESULT)  Mallincam_get_MaxSpeed(HMallinCam h); /* get the maximum speed, see "Frame Speed Level", the speed range = [0, max], closed interval */
440 
441     mallincam_ports(MRESULT)  Mallincam_get_FanMaxSpeed(HMallinCam h); /* get the maximum fan speed, the fan speed range = [0, max], closed interval */
442 
443     mallincam_ports(MRESULT)  Mallincam_get_MaxBitDepth(HMallinCam h); /* get the max bit depth of this camera, such as 8, 10, 12, 14, 16 */
444 
445     /* power supply:
446      0 -> 60HZ AC
447      1 -> 50Hz AC
448      2 -> DC
449      */
450     mallincam_ports(MRESULT)  Mallincam_put_HZ(HMallinCam h, int nHZ);
451     mallincam_ports(MRESULT)  Mallincam_get_HZ(HMallinCam h, int* nHZ);
452 
453     mallincam_ports(MRESULT)  Mallincam_put_Mode(HMallinCam h, BOOL bSkip); /* skip or bin */
454     mallincam_ports(MRESULT)  Mallincam_get_Mode(HMallinCam h, BOOL* bSkip); /* If the model don't support bin/skip mode, return E_NOTIMPL */
455 
456     mallincam_ports(MRESULT)  Mallincam_put_AWBAuxRect(HMallinCam h, const RECT* pAuxRect); /* auto white balance ROI */
457     mallincam_ports(MRESULT)  Mallincam_get_AWBAuxRect(HMallinCam h, RECT* pAuxRect);
458     mallincam_ports(MRESULT)  Mallincam_put_AEAuxRect(HMallinCam h, const RECT* pAuxRect);  /* auto exposure ROI */
459     mallincam_ports(MRESULT)  Mallincam_get_AEAuxRect(HMallinCam h, RECT* pAuxRect);
460 
461     /*
462      S_FALSE:    color mode
463      S_OK:       mono mode, such as EXCCD00300KMA and UHCCD01400KMA
464      */
465     mallincam_ports(MRESULT)  Mallincam_get_MonoMode(HMallinCam h);
466 
467     mallincam_ports(MRESULT)  Mallincam_get_StillResolutionNumber(HMallinCam h);
468     mallincam_ports(MRESULT)  Mallincam_get_StillResolution(HMallinCam h, unsigned nResolutionIndex, int* pWidth, int* pHeight);
469 
470     /* default: FALSE */
471     mallincam_ports(MRESULT)  Mallincam_put_RealTime(HMallinCam h, BOOL bEnable);
472     mallincam_ports(MRESULT)  Mallincam_get_RealTime(HMallinCam h, BOOL* bEnable);
473 
474     mallincam_ports(MRESULT)  Mallincam_Flush(HMallinCam h);  /* discard the current internal frame cache */
475 
476     /* get the temperature of sensor, in 0.1 degrees Celsius (32 means 3.2 degrees Celsius)
477      return E_NOTIMPL if not supported
478      */
479     mallincam_ports(MRESULT)  Mallincam_get_Temperature(HMallinCam h, short* pTemperature);
480 
481     /* set the temperature of sensor, in 0.1 degrees Celsius (32 means 3.2 degrees Celsius)
482      return E_NOTIMPL if not supported
483      */
484     mallincam_ports(MRESULT)  Mallincam_put_Temperature(HMallinCam h, short nTemperature);
485 
486     /*
487      get the serial number which is always 32 chars which is zero-terminated such as "TP110826145730ABCD1234FEDC56787"
488      */
489     mallincam_ports(MRESULT)  Mallincam_get_SerialNumber(HMallinCam h, char sn[32]);
490 
491     /*
492      get the camera firmware version, such as: 3.2.1.20140922
493      */
494     mallincam_ports(MRESULT)  Mallincam_get_FwVersion(HMallinCam h, char fwver[16]);
495 
496     /*
497      get the camera hardware version, such as: 3.2.1.20140922
498      */
499     mallincam_ports(MRESULT)  Mallincam_get_HwVersion(HMallinCam h, char hwver[16]);
500 
501     /*
502      get the production date, such as: 20150327
503      */
504     mallincam_ports(MRESULT)  Mallincam_get_ProductionDate(HMallinCam h, char pdate[10]);
505 
506     /*
507      get the sensor pixel size, such as: 2.4um
508      */
509     mallincam_ports(MRESULT)  Mallincam_get_PixelSize(HMallinCam h, unsigned nResolutionIndex, float* x, float* y);
510 
511     mallincam_ports(MRESULT)  Mallincam_put_LevelRange(HMallinCam h, unsigned short aLow[4], unsigned short aHigh[4]);
512     mallincam_ports(MRESULT)  Mallincam_get_LevelRange(HMallinCam h, unsigned short aLow[4], unsigned short aHigh[4]);
513 
514     mallincam_ports(MRESULT)  Mallincam_put_ExpoCallback(HMallinCam h, PIMALLINCAM_EXPOSURE_CALLBACK fnExpoProc, void* pExpoCtx);
515     mallincam_ports(MRESULT)  Mallincam_put_ChromeCallback(HMallinCam h, PIMALLINCAM_CHROME_CALLBACK fnChromeProc, void* pChromeCtx);
516 
517     /*
518      The following functions must be called AFTER Mallincam_StartPushMode or Mallincam_StartPullModeWithWndMsg or Mallincam_StartPullModeWithCallback
519      */
520     mallincam_ports(MRESULT)  Mallincam_LevelRangeAuto(HMallinCam h);
521     mallincam_ports(MRESULT)  Mallincam_GetHistogram(HMallinCam h, PIMALLINCAM_HISTOGRAM_CALLBACK fnHistogramProc, void* pHistogramCtx);
522 
523     /* led state:
524      iLed: Led index, (0, 1, 2, ...)
525      iState: 1 -> Ever bright; 2 -> Flashing; other -> Off
526      iPeriod: Flashing Period (>= 500ms)
527      */
528     mallincam_ports(MRESULT)  Mallincam_put_LEDState(HMallinCam h, unsigned short iLed, unsigned short iState, unsigned short iPeriod);
529 
530     mallincam_ports(MRESULT)  Mallincam_write_EEPROM(HMallinCam h, unsigned addr, const unsigned char* pBuffer, unsigned nBufferLen);
531     mallincam_ports(MRESULT)  Mallincam_read_EEPROM(HMallinCam h, unsigned addr, unsigned char* pBuffer, unsigned nBufferLen);
532 
533     mallincam_ports(MRESULT)  Mallincam_write_UART(HMallinCam h, const unsigned char* pData, unsigned nDataLen);
534     mallincam_ports(MRESULT)  Mallincam_read_UART(HMallinCam h, unsigned char* pBuffer, unsigned nBufferLen);
535 
536 #define MALLINCAM_TEC_TARGET_MIN      -300 /* -30.0 degrees Celsius */
537 #define MALLINCAM_TEC_TARGET_DEF      -100 /* -10.0 degrees Celsius */
538 #define MALLINCAM_TEC_TARGET_MAX      300  /* 30.0 degrees Celsius */
539 
540 #define MALLINCAM_OPTION_NOFRAME_TIMEOUT      0x01    /* iValue: 1 = enable; 0 = disable. default: enable */
541 #define MALLINCAM_OPTION_THREAD_PRIORITY      0x02    /* set the priority of the internal thread which grab data from the usb device. iValue: 0 = THREAD_PRIORITY_NORMAL; 1 = THREAD_PRIORITY_ABOVE_NORMAL; 2 = THREAD_PRIORITY_HIGHEST; default: 0; see: msdn SetThreadPriority */
542 #define MALLINCAM_OPTION_PROCESSMODE          0x03    /*  0 = better image quality, more cpu usage. this is the default value
543 1 = lower image quality, less cpu usage */
544 #define MALLINCAM_OPTION_RAW                  0x04    /* raw mode, read the sensor data. This can be set only BEFORE Mallincam_StartXXX() */
545 #define MALLINCAM_OPTION_HISTOGRAM            0x05    /* 0 = only one, 1 = continue mode */
546 #define MALLINCAM_OPTION_BITDEPTH             0x06    /* 0 = 8 bits mode, 1 = 16 bits mode */
547 #define MALLINCAM_OPTION_FAN                  0x07    /* 0 = turn off the cooling fan, [1, max] = fan speed */
548 #define MALLINCAM_OPTION_TEC                  0x08    /* 0 = turn off the thermoelectric cooler, 1 = turn on the thermoelectric cooler */
549 #define MALLINCAM_OPTION_LINEAR               0x09    /* 0 = turn off the builtin linear tone mapping, 1 = turn on the builtin linear tone mapping, default value: 1 */
550 #define MALLINCAM_OPTION_CURVE                0x0a    /* 0 = turn off the builtin curve tone mapping, 1 = turn on the builtin curve tone mapping, default value: 1 */
551 #define MALLINCAM_OPTION_TRIGGER              0x0b    /* 0 = video mode, 1 = software or simulated trigger mode, 2 = external trigger mode, default value =  0 */
552 #define MALLINCAM_OPTION_RGB48                0x0c    /* enable RGB48 format when bitdepth > 8 */
553 #define MALLINCAM_OPTION_COLORMATIX           0x0d    /* enable or disable the builtin color matrix, default value: 1 */
554 #define MALLINCAM_OPTION_WBGAIN               0x0e    /* enable or disable the builtin white balance gain, default value: 1 */
555 #define MALLINCAM_OPTION_TECTARGET            0x0f    /* get or set the target temperature of the thermoelectric cooler, in 0.1 degree Celsius. For example, 125 means 12.5 degree Celsius */
556 #define MALLINCAM_OPTION_AGAIN                0x10    /* enable or disable adjusting the analog gain when auto exposure is enabled. default value: enable */
557 #define MALLINCAM_OPTION_FRAMERATE            0x11    /* limit the frame rate, range=[0, 63], the default value 0 means no limit. frame rate control is auto disabled in trigger mode */
558 
559     mallincam_ports(MRESULT)  Mallincam_put_Option(HMallinCam h, unsigned iOption, int iValue);
560     mallincam_ports(MRESULT)  Mallincam_get_Option(HMallinCam h, unsigned iOption, int* piValue);
561 
562     mallincam_ports(MRESULT)  Mallincam_put_Roi(HMallinCam h, unsigned xOffset, unsigned yOffset, unsigned xWidth, unsigned yHeight);
563     mallincam_ports(MRESULT)  Mallincam_get_Roi(HMallinCam h, unsigned* pxOffset, unsigned* pyOffset, unsigned* pxWidth, unsigned* pyHeight);
564 
565     /*
566      get the frame rate: framerate (fps) = Frame * 1000.0 / nTime
567      */
568     mallincam_ports(MRESULT)  Mallincam_get_FrameRate(HMallinCam h, unsigned* nFrame, unsigned* nTime, unsigned* nTotalFrame);
569 
570     /* astronomy: for ST4 guide, please see: ASCOM Platform Help ICameraV2.
571      nDirect: 0 = North, 1 = South, 2 = East, 3 = West, 4 = Stop
572      nDuration: in milliseconds
573      */
574     mallincam_ports(MRESULT)  Mallincam_ST4PulseGuide(HMallinCam h, unsigned nDirect, unsigned nDuration);
575 
576     /* S_OK: pulse guiding
577      S_FALSE: not pulse guiding
578      */
579     mallincam_ports(MRESULT)  Mallincam_ST4PlusGuideState(HMallinCam h);
580 
581     /*
582      calculate the clarity factor:
583      pImageData: pointer to the image data
584      bits: 8(Grey), 24 (RGB24), 32(RGB32)
585      nImgWidth, nImgHeight: the image width and height
586      */
587     mallincam_ports(double)   Mallincam_calc_ClarityFactor(const void* pImageData, int bits, unsigned nImgWidth, unsigned nImgHeight);
588 
589     mallincam_ports(void)     Mallincam_deBayer(unsigned nBayer, int nW, int nH, const void* input, void* output, unsigned char nBitDepth);
590 
591 #ifndef _WIN32
592 
593     typedef void (*PMALLINCAM_HOTPLUG)(void* pCallbackCtx);
594     mallincam_ports(void)   Mallincam_HotPlug(PMALLINCAM_HOTPLUG pHotPlugCallback, void* pCallbackCtx);
595 
596 #else
597     /*
598      strRegPath, such as: Software\xxxCompany\yyyApplication.
599      If we call this function to enable this feature, the camera parameters will be save in the Registry at HKEY_CURRENT_USER\Software\XxxCompany\yyyApplication\{CameraModelName} when we close the handle,
600      and then, the next time, we open the camera, the parameters will be loaded automatically.
601      */
602     mallincam_ports(void)     Mallincam_EnableReg(const wchar_t* strRegPath);
603 
604     /* Mallincam_Start is obsolete, it's a synonyms for Mallincam_StartPushMode. */
605     mallincam_ports(MRESULT)  Mallincam_Start(HMallinCam h, PMALLINCAM_DATA_CALLBACK pDataCallback, void* pCallbackCtx);
606 
607     /* Mallincam_put_TempTintInit is obsolete, it's a synonyms for Mallincam_AwbOnePush. */
608     mallincam_ports(MRESULT)  Mallincam_put_TempTintInit(HMallinCam h, PIMALLINCAM_TEMPTINT_CALLBACK fnTTProc, void* pTTCtx);
609 
610     /*
611      obsolete, please use Mallincam_put_Option or Mallincam_get_Option to set or get the process mode: MALLINCAM_PROCESSMODE_FULL or MALLINCAM_PROCESSMODE_FAST.
612      default is MALLINCAM_PROCESSMODE_FULL.
613      */
614 #ifndef __MALLINCAM_PROCESSMODE_DEFINED__
615 #define __MALLINCAM_PROCESSMODE_DEFINED__
616 #define MALLINCAM_PROCESSMODE_FULL        0x00    /* better image quality, more cpu usage. this is the default value */
617 #define MALLINCAM_PROCESSMODE_FAST        0x01    /* lower image quality, less cpu usage */
618 #endif
619 
620     mallincam_ports(MRESULT)  Mallincam_put_ProcessMode(HMallinCam h, unsigned nProcessMode);
621     mallincam_ports(MRESULT)  Mallincam_get_ProcessMode(HMallinCam h, unsigned* pnProcessMode);
622 
623 #endif
624 
625     /* obsolete, please use Mallincam_put_Roi and Mallincam_get_Roi */
626     mallincam_ports(MRESULT)  Mallincam_put_RoiMode(HMallinCam h, BOOL bRoiMode, int xOffset, int yOffset);
627     mallincam_ports(MRESULT)  Mallincam_get_RoiMode(HMallinCam h, BOOL* pbRoiMode, int* pxOffset, int* pyOffset);
628 
629     /* obsolete:
630      ------------------------------------------------------------|
631      | Parameter         |   Range       |   Default             |
632      |-----------------------------------------------------------|
633      | VidgetAmount      |   -100~100    |   0                   |
634      | VignetMidPoint    |   0~100       |   50                  |
635      -------------------------------------------------------------
636      */
637     mallincam_ports(MRESULT)  Mallincam_put_VignetEnable(HMallinCam h, BOOL bEnable);
638     mallincam_ports(MRESULT)  Mallincam_get_VignetEnable(HMallinCam h, BOOL* bEnable);
639     mallincam_ports(MRESULT)  Mallincam_put_VignetAmountInt(HMallinCam h, int nAmount);
640     mallincam_ports(MRESULT)  Mallincam_get_VignetAmountInt(HMallinCam h, int* nAmount);
641     mallincam_ports(MRESULT)  Mallincam_put_VignetMidPointInt(HMallinCam h, int nMidPoint);
642     mallincam_ports(MRESULT)  Mallincam_get_VignetMidPointInt(HMallinCam h, int* nMidPoint);
643 
644 #ifdef _WIN32
645 #pragma pack(pop)
646 #endif
647 
648 #ifdef __cplusplus
649 }
650 #endif
651 
652 #endif
653