00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __TLDIGITIZERDX_H__
00018 #define __TLDIGITIZERDX_H__
00019
00020
00021
00022 #include "tlVision.h"
00023 #include "tlDigitizer.h"
00024
00025
00026 #ifndef __TLDIRECTXH__
00027 #define __TLDIRECTXH__
00028 #include <atlbase.h>
00029 #include <qedit.h>
00030 #include <dshow.h>
00031 #ifdef _TLIB_BUILD_
00032 #include <streams.h>
00033 #endif
00034 #endif
00035
00036
00037
00038 class SampleGrabberCallback : public ISampleGrabberCB
00039 {
00040 private:
00041 bool *ready;
00042
00043 public:
00044 SampleGrabberCallback (bool *imageReady) { ready = imageReady; };
00045 virtual ~SampleGrabberCallback () {return; };
00046 STDMETHODIMP_(ULONG) AddRef () { return 1; }
00047 STDMETHODIMP_(ULONG) Release () { return 2; }
00048
00049 STDMETHODIMP QueryInterface(REFIID riid, void **ppvObject) {
00050 if (NULL == ppvObject) return E_POINTER;
00051 if (riid == __uuidof(IUnknown)) {
00052 *ppvObject = static_cast<IUnknown*>(this);
00053 return S_OK;
00054 }
00055 if (riid == __uuidof(ISampleGrabberCB)) {
00056 *ppvObject = static_cast<ISampleGrabberCB*>(this);
00057 return S_OK;
00058 }
00059 return E_NOTIMPL;
00060 }
00061
00062 STDMETHODIMP SampleCB(double Time, IMediaSample *pSample) {
00063 return E_NOTIMPL;
00064 }
00065
00066 STDMETHODIMP BufferCB(double Time, BYTE *pBuffer, long BufferLen) {
00067 *ready = true;
00068 return S_OK;
00069 }
00070 };
00071
00072
00073
00074
00075 class tlDigitizerDX : public tlDigitizer
00076 {
00077 private:
00078 bool imageReady;
00079 SampleGrabberCallback *cb;
00080
00081 protected:
00082 ISampleGrabber *pGrabber;
00083 IGraphBuilder *pGraph;
00084 ICaptureGraphBuilder2 *pCapture;
00085 BYTE *buffer;
00086 IAMStreamConfig *pVConfig;
00087 IMediaEvent *pEvent;
00088 int index;
00089 int fps;
00090
00091 public:
00092 tlDigitizerDX ();
00093 tlDigitizerDX (int width, int height);
00094 virtual ~tlDigitizerDX ();
00095
00096 virtual int open (int index = 0);
00097 virtual int open (int width, int height, int index = 0);
00098 virtual int close ();
00099
00100 virtual int setSize (int width, int height);
00101
00102 virtual int grab (tlImage *image);
00103 virtual int grab (tlImage *image, tlRect *rect);
00104 virtual int grabQueued (tlImage *image);
00105 virtual int grabQueued (tlImage *image, tlRect *rect);
00106
00107 int setFrameRate (int fps);
00108 };
00109
00110
00111 #endif
00112