38 #ifndef DOXYGEN_SHOULD_SKIP_THIS
40 #include <visp3/sensor/vpDirectShowSampleGrabberI.h>
41 #include <visp3/core/vpImageConvert.h>
43 #include <visp3/core/vpConfig.h>
44 #if ( defined(VISP_HAVE_DIRECTSHOW) )
51 vpDirectShowSampleGrabberI::vpDirectShowSampleGrabberI()
52 : acqGrayDemand(false), acqRGBaDemand(false), specialMediaType(false), invertedSource(false)
55 copySem = CreateSemaphore (NULL,0,1,NULL);
61 vpDirectShowSampleGrabberI::~vpDirectShowSampleGrabberI()
68 STDMETHODIMP vpDirectShowSampleGrabberI::QueryInterface(REFIID riid,
void **ppvObject)
70 if (NULL == ppvObject)
return E_POINTER;
71 if (riid == __uuidof(IUnknown))
73 *ppvObject =
static_cast<IUnknown*
>(
this);
76 if (riid == __uuidof(ISampleGrabberCB))
78 *ppvObject =
static_cast<ISampleGrabberCB*
>(
this);
89 STDMETHODIMP vpDirectShowSampleGrabberI::BufferCB(
double Time, BYTE *pBuffer,
long BufferLen)
92 if(acqGrayDemand || acqRGBaDemand)
95 if(connectedMediaType.formattype==FORMAT_VideoInfo)
98 VIDEOINFOHEADER *pVih =
reinterpret_cast<VIDEOINFOHEADER*
>(connectedMediaType.pbFormat);
99 BITMAPINFOHEADER bmpInfo = pVih->bmiHeader;
104 if(!specialMediaType)
105 flip = bmpInfo.biHeight>=0;
107 else if(invertedSource)
114 if(connectedMediaType.subtype==MEDIASUBTYPE_RGB24)
120 rgbaIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
123 rgbaIm->getWidth() , rgbaIm->getHeight(), flip);
125 acqRGBaDemand =
false;
130 grayIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
133 grayIm->getWidth(), grayIm->getHeight(), flip);
135 acqGrayDemand =
false;
140 unsigned long FourCC;
141 FourCC = ((bmpInfo.biCompression&0xFF000000)>>24) |
142 ((bmpInfo.biCompression&0x00FF0000)>>8) |
143 ((bmpInfo.biCompression&0x0000FF00)<<8) |
144 (bmpInfo.biCompression&0x000000FF)<<24;
146 if(connectedMediaType.subtype==MEDIASUBTYPE_IYUV || FourCC ==
'I420')
152 rgbaIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
155 rgbaIm->getWidth() , rgbaIm->getHeight());
157 acqRGBaDemand =
false;
162 grayIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
165 grayIm->getWidth() * grayIm->getHeight());
167 acqGrayDemand =
false;
171 else if(connectedMediaType.subtype==MEDIASUBTYPE_YV12)
177 rgbaIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
180 rgbaIm->getWidth() , rgbaIm->getHeight());
182 acqRGBaDemand =
false;
187 grayIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
190 grayIm->getWidth() * grayIm->getHeight());
192 acqGrayDemand =
false;
195 else if(connectedMediaType.subtype==MEDIASUBTYPE_YVU9)
201 rgbaIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
204 rgbaIm->getWidth() , rgbaIm->getHeight());
206 acqRGBaDemand =
false;
211 grayIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
214 grayIm->getWidth() * grayIm->getHeight());
216 acqGrayDemand =
false;
219 else if(connectedMediaType.subtype==MEDIASUBTYPE_YUY2 ||
220 connectedMediaType.subtype==MEDIASUBTYPE_YUYV)
226 rgbaIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
229 rgbaIm->getWidth()*rgbaIm->getHeight());
231 acqRGBaDemand =
false;
236 grayIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
239 grayIm->getWidth() * grayIm->getHeight());
241 acqGrayDemand =
false;
244 else if(connectedMediaType.subtype==MEDIASUBTYPE_YVYU)
250 rgbaIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
253 rgbaIm->getWidth()*rgbaIm->getHeight());
255 acqRGBaDemand =
false;
260 grayIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
263 grayIm->getWidth() * grayIm->getHeight());
265 acqGrayDemand =
false;
268 else if(connectedMediaType.subtype==MEDIASUBTYPE_UYVY)
274 rgbaIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
277 rgbaIm->getWidth()*rgbaIm->getHeight());
279 acqRGBaDemand =
false;
284 grayIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
287 grayIm->getWidth() * grayIm->getHeight());
289 acqGrayDemand =
false;
292 else if(connectedMediaType.subtype==MEDIASUBTYPE_RGB32)
298 rgbaIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
301 memcpy(rgbaIm->bitmap,pBuffer ,4*rgbaIm->getWidth()*rgbaIm->getHeight());
303 acqRGBaDemand =
false;
308 grayIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
311 grayIm->getWidth() * grayIm->getHeight());
313 acqGrayDemand =
false;
320 ReleaseSemaphore(copySem, 1, NULL);
325 #elif !defined(VISP_BUILD_SHARED_LIBS)
327 void dummy_vpDirectShowSampleGrabberI() {};
static void BGRToRGBa(unsigned char *bgr, unsigned char *rgba, unsigned int width, unsigned int height, bool flip=false)
static void BGRToGrey(unsigned char *bgr, unsigned char *grey, unsigned int width, unsigned int height, bool flip=false)
static void YUV420ToGrey(unsigned char *yuv, unsigned char *grey, unsigned int size)
static void YUV422ToRGBa(unsigned char *yuv, unsigned char *rgba, unsigned int size)
static void YUV420ToRGBa(unsigned char *yuv, unsigned char *rgba, unsigned int width, unsigned int height)
static void YVU9ToRGBa(unsigned char *yuv, unsigned char *rgba, unsigned int width, unsigned int height)
static void YUV422ToGrey(unsigned char *yuv, unsigned char *grey, unsigned int size)
static void YV12ToRGBa(unsigned char *yuv, unsigned char *rgba, unsigned int width, unsigned int height)
static void YCbCrToGrey(unsigned char *ycbcr, unsigned char *grey, unsigned int size)
static void YCbCrToRGBa(unsigned char *ycbcr, unsigned char *rgb, unsigned int size)
static void YCrCbToRGBa(unsigned char *ycbcr, unsigned char *rgb, unsigned int size)
static void RGBaToGrey(unsigned char *rgba, unsigned char *grey, unsigned int size)