39 #ifndef DOXYGEN_SHOULD_SKIP_THIS 41 #include <visp3/core/vpImageConvert.h> 42 #include <visp3/sensor/vpDirectShowSampleGrabberI.h> 44 #include <visp3/core/vpConfig.h> 45 #if (defined(VISP_HAVE_DIRECTSHOW)) 50 vpDirectShowSampleGrabberI::vpDirectShowSampleGrabberI()
51 : acqGrayDemand(false), acqRGBaDemand(false), specialMediaType(false), invertedSource(false)
54 copySem = CreateSemaphore(NULL, 0, 1, NULL);
60 vpDirectShowSampleGrabberI::~vpDirectShowSampleGrabberI()
66 STDMETHODIMP vpDirectShowSampleGrabberI::QueryInterface(REFIID riid,
void **ppvObject)
68 if (NULL == ppvObject)
70 if (riid == __uuidof(IUnknown)) {
71 *ppvObject =
static_cast<IUnknown *
>(
this);
74 if (riid == __uuidof(ISampleGrabberCB)) {
75 *ppvObject =
static_cast<ISampleGrabberCB *
>(
this);
86 STDMETHODIMP vpDirectShowSampleGrabberI::BufferCB(
double Time, BYTE *pBuffer,
long BufferLen)
89 if (acqGrayDemand || acqRGBaDemand) {
91 if (connectedMediaType.formattype == FORMAT_VideoInfo) {
93 VIDEOINFOHEADER *pVih =
reinterpret_cast<VIDEOINFOHEADER *
>(connectedMediaType.pbFormat);
94 BITMAPINFOHEADER bmpInfo = pVih->bmiHeader;
99 if (!specialMediaType)
100 flip = bmpInfo.biHeight >= 0;
102 else if (invertedSource)
109 if (connectedMediaType.subtype == MEDIASUBTYPE_RGB24) {
113 rgbaIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
118 acqRGBaDemand =
false;
122 grayIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
126 acqGrayDemand =
false;
129 unsigned long FourCC;
130 FourCC = ((bmpInfo.biCompression & 0xFF000000) >> 24) | ((bmpInfo.biCompression & 0x00FF0000) >> 8) |
131 ((bmpInfo.biCompression & 0x0000FF00) << 8) | (bmpInfo.biCompression & 0x000000FF) << 24;
133 if (connectedMediaType.subtype == MEDIASUBTYPE_IYUV || FourCC ==
'I420') {
137 rgbaIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
140 rgbaIm->getHeight());
142 acqRGBaDemand =
false;
146 grayIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
150 acqGrayDemand =
false;
153 }
else if (connectedMediaType.subtype == MEDIASUBTYPE_YV12) {
157 rgbaIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
160 rgbaIm->getHeight());
162 acqRGBaDemand =
false;
166 grayIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
170 acqGrayDemand =
false;
172 }
else if (connectedMediaType.subtype == MEDIASUBTYPE_YVU9) {
176 rgbaIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
179 rgbaIm->getHeight());
181 acqRGBaDemand =
false;
185 grayIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
189 acqGrayDemand =
false;
191 }
else if (connectedMediaType.subtype == MEDIASUBTYPE_YUY2 || connectedMediaType.subtype == MEDIASUBTYPE_YUYV) {
195 rgbaIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
198 rgbaIm->getWidth() * rgbaIm->getHeight());
200 acqRGBaDemand =
false;
204 grayIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
208 acqGrayDemand =
false;
210 }
else if (connectedMediaType.subtype == MEDIASUBTYPE_YVYU) {
214 rgbaIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
217 rgbaIm->getWidth() * rgbaIm->getHeight());
219 acqRGBaDemand =
false;
223 grayIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
227 acqGrayDemand =
false;
229 }
else if (connectedMediaType.subtype == MEDIASUBTYPE_UYVY) {
233 rgbaIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
236 rgbaIm->getWidth() * rgbaIm->getHeight());
238 acqRGBaDemand =
false;
242 grayIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
246 acqGrayDemand =
false;
248 }
else if (connectedMediaType.subtype == MEDIASUBTYPE_RGB32) {
252 rgbaIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
256 memcpy(rgbaIm->bitmap, pBuffer, 4 * rgbaIm->getWidth() * rgbaIm->getHeight());
258 acqRGBaDemand =
false;
262 grayIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
266 acqGrayDemand =
false;
273 ReleaseSemaphore(copySem, 1, NULL);
278 #elif !defined(VISP_BUILD_SHARED_LIBS) 281 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)