1 #ifndef DOXYGEN_SHOULD_SKIP_THIS
3 #include <visp/vpDirectShowSampleGrabberI.h>
4 #include <visp/vpImageConvert.h>
6 #include <visp/vpConfig.h>
7 #if ( defined(VISP_HAVE_DIRECTSHOW) )
14 vpDirectShowSampleGrabberI::vpDirectShowSampleGrabberI()
15 : acqGrayDemand(false), acqRGBaDemand(false), specialMediaType(false), invertedSource(false)
18 copySem = CreateSemaphore (NULL,0,1,NULL);
24 vpDirectShowSampleGrabberI::~vpDirectShowSampleGrabberI()
31 STDMETHODIMP vpDirectShowSampleGrabberI::QueryInterface(REFIID riid,
void **ppvObject)
33 if (NULL == ppvObject)
return E_POINTER;
34 if (riid == __uuidof(IUnknown))
36 *ppvObject =
static_cast<IUnknown*
>(
this);
39 if (riid == __uuidof(ISampleGrabberCB))
41 *ppvObject =
static_cast<ISampleGrabberCB*
>(
this);
52 STDMETHODIMP vpDirectShowSampleGrabberI::BufferCB(
double Time, BYTE *pBuffer,
long BufferLen)
55 if(acqGrayDemand || acqRGBaDemand)
58 if(connectedMediaType.formattype==FORMAT_VideoInfo)
61 VIDEOINFOHEADER *pVih =
reinterpret_cast<VIDEOINFOHEADER*
>(connectedMediaType.pbFormat);
62 BITMAPINFOHEADER bmpInfo = pVih->bmiHeader;
68 flip = bmpInfo.biHeight>=0;
70 else if(invertedSource)
77 if(connectedMediaType.subtype==MEDIASUBTYPE_RGB24)
83 rgbaIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
86 rgbaIm->getWidth() , rgbaIm->getHeight(), flip);
88 acqRGBaDemand =
false;
93 grayIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
96 grayIm->getWidth(), grayIm->getHeight(), flip);
98 acqGrayDemand =
false;
103 unsigned long FourCC;
104 FourCC = ((bmpInfo.biCompression&0xFF000000)>>24) |
105 ((bmpInfo.biCompression&0x00FF0000)>>8) |
106 ((bmpInfo.biCompression&0x0000FF00)<<8) |
107 (bmpInfo.biCompression&0x000000FF)<<24;
109 if(connectedMediaType.subtype==MEDIASUBTYPE_IYUV || FourCC ==
'I420')
115 rgbaIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
118 rgbaIm->getWidth() , rgbaIm->getHeight());
120 acqRGBaDemand =
false;
125 grayIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
128 grayIm->getWidth() * grayIm->getHeight());
130 acqGrayDemand =
false;
134 else if(connectedMediaType.subtype==MEDIASUBTYPE_YV12)
140 rgbaIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
143 rgbaIm->getWidth() , rgbaIm->getHeight());
145 acqRGBaDemand =
false;
150 grayIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
153 grayIm->getWidth() * grayIm->getHeight());
155 acqGrayDemand =
false;
158 else if(connectedMediaType.subtype==MEDIASUBTYPE_YVU9)
164 rgbaIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
167 rgbaIm->getWidth() , rgbaIm->getHeight());
169 acqRGBaDemand =
false;
174 grayIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
177 grayIm->getWidth() * grayIm->getHeight());
179 acqGrayDemand =
false;
182 else if(connectedMediaType.subtype==MEDIASUBTYPE_YUY2 ||
183 connectedMediaType.subtype==MEDIASUBTYPE_YUYV)
189 rgbaIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
192 rgbaIm->getWidth()*rgbaIm->getHeight());
194 acqRGBaDemand =
false;
199 grayIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
202 grayIm->getWidth() * grayIm->getHeight());
204 acqGrayDemand =
false;
207 else if(connectedMediaType.subtype==MEDIASUBTYPE_YVYU)
213 rgbaIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
216 rgbaIm->getWidth()*rgbaIm->getHeight());
218 acqRGBaDemand =
false;
223 grayIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
226 grayIm->getWidth() * grayIm->getHeight());
228 acqGrayDemand =
false;
231 else if(connectedMediaType.subtype==MEDIASUBTYPE_UYVY)
237 rgbaIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
240 rgbaIm->getWidth()*rgbaIm->getHeight());
242 acqRGBaDemand =
false;
247 grayIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
250 grayIm->getWidth() * grayIm->getHeight());
252 acqGrayDemand =
false;
255 else if(connectedMediaType.subtype==MEDIASUBTYPE_RGB32)
261 rgbaIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
264 memcpy(rgbaIm->bitmap,pBuffer ,4*rgbaIm->getWidth()*rgbaIm->getHeight());
266 acqRGBaDemand =
false;
271 grayIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
274 grayIm->getWidth() * grayIm->getHeight());
276 acqGrayDemand =
false;
283 ReleaseSemaphore(copySem, 1, NULL);
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 BGRToGrey(unsigned char *bgr, unsigned char *grey, unsigned int width, unsigned int height, bool flip)
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)
static void BGRToRGBa(unsigned char *bgr, unsigned char *rgba, unsigned int width, unsigned int height, bool flip)