1 /** \file
2  * \brief Video Capture
3  *
4  * See Copyright Notice in im.h
5  */
6 module im.im_capture;
7 
8 version(IM) :
9 version(Windows) :
10 version(D_LP64) :
11 
12 version(DigitalMars) { pragma(lib, "im_capture.lib"); } // found in Win64 package only
13 version(DigitalMars) { pragma(lib, "strmiids.lib"); } // link with the "strmiids.lib" library on Windows. Visual C ?
14 
15 extern(C) @nogc nothrow {
16 
17 /** \defgroup capture Image Capture 
18  * \par
19  * Functions to capture images from live video devices.
20  * \par
21  * See \ref im_capture.h
22  */
23 
24 /** \brief Video Capture Structure (Private).
25  * \ingroup capture */
26 struct _imVideoCapture;
27 alias imVideoCapture = _imVideoCapture;
28 
29 /** Returns the number of available devices.
30  *
31  * \verbatim im.VideoCaptureDeviceCount() -> count: number [in Lua 5] \endverbatim
32  * \ingroup capture */
33 int imVideoCaptureDeviceCount();
34 
35 /** Returns the device description. Returns NULL only if it is an invalid device.
36  *
37  * \verbatim im.VideoCaptureDeviceDesc(device: number) -> desc: string [in Lua 5] \endverbatim
38  * \ingroup capture */
39 const(char)* imVideoCaptureDeviceDesc(int device);
40 
41 /** Returns the extendend device description. May return NULL.
42  *
43  * \verbatim im.VideoCaptureDeviceExDesc(device: number) -> desc: string [in Lua 5] \endverbatim
44  * \ingroup capture */
45 const(char)* imVideoCaptureDeviceExDesc(int device);
46 
47 /** Returns the device path configuration. This is a unique string. 
48  *
49  * \verbatim im.VideoCaptureDevicePath(device: number) -> desc: string [in Lua 5] \endverbatim
50  * \ingroup capture */
51 const(char)* imVideoCaptureDevicePath(int device);
52 
53 /** Returns the vendor information. May return NULL.
54  *
55  * \verbatim im.VideoCaptureDeviceVendorInfo(device: number) -> desc: string [in Lua 5] \endverbatim
56  * \ingroup capture */
57 const(char)* imVideoCaptureDeviceVendorInfo(int device);
58 
59 /** Reload the device list. The devices can be dynamically removed or added to the system.
60  * Returns the number of available devices.
61  *
62  * \verbatim im.imVideoCaptureReloadDevices() -> count: number [in Lua 5] \endverbatim
63  * \ingroup capture */
64 int imVideoCaptureReloadDevices();
65 
66 /** Release the device list. Usefull is you need to track leak erros in your application.
67  *
68  * \verbatim im.imVideoCaptureReleaseDevices() [in Lua 5] \endverbatim
69  * \ingroup capture */
70 void imVideoCaptureReleaseDevices();
71 
72 /** Creates a new imVideoCapture object. \n
73  * Returns NULL if there is no capture device available. \n
74  * In Windows returns NULL if DirectX version is older than 8. \n
75  * In Lua the IM videocapture metatable name is "imVideoCapture".
76  * When converted to a string will return "imVideoCapture(%p)" where %p is replaced by the userdata address.
77  * If the videocapture is already destroyed by im.VideoCaptureDestroy, then it will return also the suffix "-destroyed".
78  *
79  * \verbatim im.VideoCaptureCreate() -> vc: imVideoCapture [in Lua 5] \endverbatim
80  * \ingroup capture */
81 imVideoCapture* imVideoCaptureCreate();
82 
83 /** Destroys a imVideoCapture object. \n
84  * In Lua if this function is not called, the videocapture is destroyed by the garbage collector.
85  *
86  * \verbatim im.VideoCaptureDestroy(vc: imVideoCapture) [in Lua 5] \endverbatim
87  * \verbatim vc:Destroy() [in Lua 5] \endverbatim
88  * \ingroup capture */
89 void imVideoCaptureDestroy(imVideoCapture* vc);
90 
91 /** Connects to a capture device. 
92  * More than one imVideoCapture object can be created
93  * but they must be connected to different devices.  \n
94  * If the object is conected it will disconnect first. \n
95  * Use -1 to return the current connected device, 
96  * in this case returns -1 if not connected. \n
97  * Returns zero if failed.
98  *
99  * \verbatim vc:Connect([device: number]) -> ret: number [in Lua 5] \endverbatim
100  * \ingroup capture */
101 int imVideoCaptureConnect(imVideoCapture* vc, int device);
102 
103 /** Disconnect from a capture device.
104  *
105  * \verbatim vc:Disconnect() [in Lua 5] \endverbatim
106  * \ingroup capture */
107 void imVideoCaptureDisconnect(imVideoCapture* vc);
108 
109 /** Returns the number of available configuration dialogs.
110  *
111  * \verbatim vc:DialogCount() -> count: number [in Lua 5] \endverbatim
112  * \ingroup capture */
113 int imVideoCaptureDialogCount(imVideoCapture* vc);
114 
115 /** Displays a configuration modal dialog of the connected device. \n
116  * In Windows, the capturing will be stopped in some cases. \n
117  * In Windows parent is a HWND of a parent window, it can be NULL. \n
118  * dialog can be from 0 to \ref imVideoCaptureDialogCount. \n
119  * Returns zero if failed.
120  *
121  * \verbatim vc:ShowDialog(dialog: number, parent: userdata) -> error: boolean [in Lua 5] \endverbatim
122  * \ingroup capture */
123 int imVideoCaptureShowDialog(imVideoCapture* vc, int dialog, void* parent);
124 
125 /** Returns the description of a configuration dialog.
126  * dialog can be from 0 to \ref imVideoCaptureDialogCount. \n
127  *
128  * \verbatim vc:DialogDesc(dialog: number) -> desc: string [in Lua 5] \endverbatim
129  * \ingroup capture */
130 const(char)* imVideoCaptureDialogDesc(imVideoCapture* vc, int dialog);
131 
132 /** Allows to control the input and output of devices that have multiple input and outputs.
133  * The cross index controls in which stage the input/output will be set. Usually use 1, but some capture boards
134  * has a second stage. In Direct X it controls the crossbars.
135  *
136  * \verbatim vc:SetInOut(input, output, cross: number) -> error: boolean [in Lua 5] \endverbatim
137  * \ingroup capture */
138 int imVideoCaptureSetInOut(imVideoCapture* vc, int input, int output, int cross);
139 
140 /** Returns the number of available video formats. \n
141  * Returns zero if failed.
142  *
143  * \verbatim vc:FormatCount() -> count: number [in Lua 5] \endverbatim
144  * \ingroup capture */
145 int imVideoCaptureFormatCount(imVideoCapture* vc);
146 
147 /** Returns information about the video format. \n
148  * format can be from 0 to \ref imVideoCaptureFormatCount. \n
149  * desc should be of size 10. \n
150  * The image size is usually the maximum size for that format. 
151  * Other sizes can be available using \ref imVideoCaptureSetImageSize. \n
152  * Returns zero if failed.
153  *
154  * \verbatim vc:GetFormat(format: number) -> error: boolean, width: number, height: number, desc: string [in Lua 5] \endverbatim
155  * \ingroup capture */
156 int imVideoCaptureGetFormat(imVideoCapture* vc, int format, int* width, int* height, char* desc);
157 
158 /** Changes the video format of the connected device. \n 
159  * Should NOT work for DV devices. Use \ref imVideoCaptureSetImageSize only. \n
160  * Use -1 to return the current format, in this case returns -1 if failed. \n
161  * When the format is changed in the dialog, for some formats 
162  * the returned format is the preferred format, not the current format. \n
163  * This will not affect color_mode of the capture image. \n
164  * Returns zero if failed.
165  *
166  * \verbatim vc:SetFormat([format: number]) -> error: boolean | format: number [in Lua 5] \endverbatim
167  * \ingroup capture */
168 int imVideoCaptureSetFormat(imVideoCapture* vc, int format);
169 
170 /** Returns the current image size of the connected device. \n
171  *  width and height returns 0 if not connected.
172  *
173  * \verbatim vc:GetImageSize() -> width: number, height: number [in Lua 5] \endverbatim
174  * \ingroup capture */
175 void imVideoCaptureGetImageSize(imVideoCapture* vc, int* width, int* height);
176 
177 /** Changes the image size of the connected device. \n 
178  * Similar to \ref imVideoCaptureSetFormat, but changes only the size. \n
179  * Valid sizes can be obtained with  \ref imVideoCaptureGetFormat. \n
180  * Returns zero if failed.
181  *
182  * \verbatim vc:SetImageSize(width: number, height: number) -> error: boolean [in Lua 5] \endverbatim
183  * \ingroup capture */
184 int imVideoCaptureSetImageSize(imVideoCapture* vc, int width, int height);
185 
186 /** Returns a new captured frame. Use -1 for infinite timeout. \n
187  * Color space can be IM_RGB or IM_GRAY, and mode can be packed (IM_PACKED) or not. \n
188  * Data type is always IM_BYTE. \n
189  * It can not have an alpha channel and orientation is always bottom up. \n
190  * Returns zero if failed or timeout expired, the buffer is not changed.
191  *
192  * \verbatim vc:Frame(image: imImage, timeout: number) -> error: boolean [in Lua 5] \endverbatim
193  * \ingroup capture */
194 int imVideoCaptureFrame(imVideoCapture* vc, ubyte* data, int color_mode, int timeout);
195 
196 /** Start capturing, returns the new captured frame and stop capturing.  \n
197  * This is more usefull if you are switching between devices. \n
198  * Data format is the same as imVideoCaptureFrame. \n
199  * Returns zero if failed.
200  *
201  * \verbatim vc:OneFrame(image: imImage) -> error: boolean [in Lua 5] \endverbatim
202  * \ingroup capture */
203 int imVideoCaptureOneFrame(imVideoCapture* vc, ubyte* data, int color_mode);
204 
205 /** Start capturing. \n
206  * Use -1 to return the current state. \n
207  * Returns zero if failed.
208  *
209  * \verbatim vc:Live([live: number]) -> error: boolean | live: number [in Lua 5] \endverbatim
210  * \ingroup capture */
211 int imVideoCaptureLive(imVideoCapture* vc, int live); 
212 
213 /** Resets a camera or video attribute to the default value or 
214  * to the automatic setting. \n
215  * Not all attributes support automatic modes. \n
216  * Returns zero if failed.
217  *
218  * \verbatim vc:ResetAttribute(attrib: string, fauto: boolean) -> error: boolean [in Lua 5] \endverbatim
219  * \ingroup capture */
220 int imVideoCaptureResetAttribute(imVideoCapture* vc, const(char)* attrib, int fauto);
221 
222 /** Returns a camera or video attribute in percentage of the valid range value. \n
223  * Returns zero if failed or attribute not supported.
224  *
225  * \verbatim vc:GetAttribute(attrib: string) -> error: boolean, percent: number [in Lua 5] \endverbatim
226  * \ingroup capture */
227 int imVideoCaptureGetAttribute(imVideoCapture* vc, const(char)* attrib, float* percent);
228 
229 /** Changes a camera or video attribute in percentage of the valid range value. \n
230  * Returns zero if failed or attribute not supported.
231  *
232  * \verbatim vc:SetAttribute(attrib: string, percent: number) -> error: boolean [in Lua 5] \endverbatim
233  * \ingroup capture */
234 int imVideoCaptureSetAttribute(imVideoCapture* vc, const(char)* attrib, float percent);
235 
236 /** Returns a list of the description of the valid attributes for the device class. \n
237  * But each device may still not support some of the returned attributes. \n
238  * Use the return value of \ref imVideoCaptureGetAttribute to check if the attribute is supported.
239  *
240  * \verbatim vc:GetAttributeList() -> attrib_list: table of strings [in Lua 5] \endverbatim
241  * \ingroup capture */
242 const(char)** imVideoCaptureGetAttributeList(imVideoCapture* vc, int* num_attrib);
243 
244 
245 /** \defgroup winattrib Windows Attributes Names
246  * Not all attributes are supported by each device.
247  * Use the return value of \ref imVideoCaptureGetAttribute to check if the attribute is supported.
248 \verbatim
249   VideoBrightness - Specifies the brightness, also called the black level. 
250   VideoContrast - Specifies the contrast, expressed as gain factor. 
251   VideoHue - Specifies the hue angle. 
252   VideoSaturation - Specifies the saturation.
253   VideoSharpness - Specifies the sharpness. 
254   VideoGamma - Specifies the gamma. 
255   VideoColorEnable - Specifies the color enable setting. (0/100)
256   VideoWhiteBalance - Specifies the white balance, as a color temperature in degrees Kelvin. 
257   VideoBacklightCompensation - Specifies the backlight compensation setting. (0/100)
258   VideoGain - Specifies the gain adjustment.
259   CameraPanAngle - Specifies the camera's pan angle. To 100 rotate right, To 0 rotate left (view from above).
260   CameraTiltAngle - Specifies the camera's tilt angle.  To 100 rotate up, To 0 rotate down.
261   CameraRollAngle - Specifies the camera's roll angle. To 100 rotate right, To 0 rotate left.
262   CameraLensZoom - Specifies the camera's zoom setting. 
263   CameraExposure - Specifies the exposure setting. 
264   CameraIris - Specifies the camera's iris setting. 
265   CameraFocus - Specifies the camera's focus setting, as the distance to the optimally focused target. 
266   FlipHorizontal - Specifies the video will be flipped in the horizontal direction.
267   FlipVertical - Specifies the video will be flipped in the vertical direction.
268   AnalogFormat - Specifies the video format standard NTSC, PAL, etc. Valid values:
269       NTSC_M     = 0 
270       NTSC_M_J   = 1  
271       NTSC_433   = 2
272       PAL_B      = 3
273       PAL_D      = 4
274       PAL_H      = 5
275       PAL_I      = 6
276       PAL_M      = 7
277       PAL_N      = 8
278       PAL_60     = 9
279       SECAM_B    = 10
280       SECAM_D    = 11
281       SECAM_G    = 12
282       SECAM_H    = 13
283       SECAM_K    = 14
284       SECAM_K1   = 15
285       SECAM_L    = 16
286       SECAM_L1   = 17
287       PAL_N_COMBO = 18
288 \endverbatim
289  * \ingroup capture */
290 
291 } // extern(C) @nogc nothrow
292 
293 
294 /** \brief Video Capture Wrapper Class
295  *
296  * DEPRECATED API. USE NAMESPACE BASED CLASSES.
297  *
298  * \ingroup capture */
299 
300 //extern(C++) there doesn't seem to be interaction with C++ -code, thus it may have D linkage
301 deprecated("USE NAMESPACE BASED CLASSES.")
302 class imCapture
303 {
304 public:
305   this() 
306     { vc = imVideoCaptureCreate(); }
307   
308   ~this() 
309     { if (vc) imVideoCaptureDestroy(vc); }
310   
311   int Failed() 
312     { if (!vc) return 0; else return 1; }
313   
314   int Connect(int device) 
315     { return imVideoCaptureConnect(vc, device); }
316   
317   void Disconnect() 
318     { imVideoCaptureDisconnect(vc); }
319   
320   int DialogCount() 
321     { return imVideoCaptureDialogCount(vc); }
322   
323   int ShowDialog(int dialog, void* parent) 
324     { return imVideoCaptureShowDialog(vc, dialog, parent); }
325   
326   const(char)* DialogDescription(int dialog) 
327     { return imVideoCaptureDialogDesc(vc, dialog); }
328 
329   int FormatCount()
330     { return imVideoCaptureFormatCount(vc); }
331 
332   int GetFormat(int format, int *width, int *height, char* desc)
333     { return imVideoCaptureGetFormat(vc, format, width, height, desc); }
334 
335   int SetFormat(int format)
336     { return imVideoCaptureSetFormat(vc, format); }
337   
338   void GetImageSize(int *width, int *height) 
339     { imVideoCaptureGetImageSize(vc, width, height); }
340   
341   int SetImageSize(int width, int height) 
342     { return imVideoCaptureSetImageSize(vc, width, height); }
343   
344   int GetFrame(ubyte* data, int color_mode, int timeout) 
345     { return imVideoCaptureFrame(vc, data, color_mode, timeout); }
346   
347   int GetOneFrame(ubyte* data, int color_mode) 
348     { return imVideoCaptureOneFrame(vc, data, color_mode); }
349   
350   int Live(int live) 
351     { return imVideoCaptureLive(vc, live); }
352   
353   int ResetAttribute(const(char)* attrib, int fauto) 
354     { return imVideoCaptureResetAttribute(vc, attrib, fauto); }
355   
356   int GetAttribute(const(char)* attrib, float *percent) 
357     { return imVideoCaptureGetAttribute(vc, attrib, percent); }
358   
359   int SetAttribute(const(char)* attrib, float percent) 
360     { return imVideoCaptureSetAttribute(vc, attrib, percent); }
361   
362   const(char)** GetAttributeList(int *num_attrib) 
363     { return imVideoCaptureGetAttributeList(vc, num_attrib); }
364   
365 protected:
366   imVideoCapture* vc;
367 }