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))
51 vpDirectShowSampleGrabberI::vpDirectShowSampleGrabberI()
52 : acqGrayDemand(false), acqRGBaDemand(false), specialMediaType(false), invertedSource(false)
55 copySem = CreateSemaphore(
nullptr, 0, 1,
nullptr);
61 vpDirectShowSampleGrabberI::~vpDirectShowSampleGrabberI()
67 STDMETHODIMP vpDirectShowSampleGrabberI::QueryInterface(REFIID riid,
void **ppvObject)
69 if (
nullptr == ppvObject)
71 if (riid == __uuidof(IUnknown)) {
72 *ppvObject =
static_cast<IUnknown *
>(
this);
75 if (riid == __uuidof(ISampleGrabberCB)) {
76 *ppvObject =
static_cast<ISampleGrabberCB *
>(
this);
87 STDMETHODIMP vpDirectShowSampleGrabberI::BufferCB(
double Time, BYTE *pBuffer,
long BufferLen)
90 if (acqGrayDemand || acqRGBaDemand) {
92 if (connectedMediaType.formattype == FORMAT_VideoInfo) {
94 VIDEOINFOHEADER *pVih =
reinterpret_cast<VIDEOINFOHEADER *
>(connectedMediaType.pbFormat);
95 BITMAPINFOHEADER bmpInfo = pVih->bmiHeader;
100 if (!specialMediaType)
101 flip = bmpInfo.biHeight >= 0;
103 else if (invertedSource)
110 if (connectedMediaType.subtype == MEDIASUBTYPE_RGB24) {
114 rgbaIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
119 acqRGBaDemand =
false;
124 grayIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
128 acqGrayDemand =
false;
132 unsigned long FourCC;
133 FourCC = ((bmpInfo.biCompression & 0xFF000000) >> 24) | ((bmpInfo.biCompression & 0x00FF0000) >> 8) |
134 ((bmpInfo.biCompression & 0x0000FF00) << 8) | (bmpInfo.biCompression & 0x000000FF) << 24;
136 if (connectedMediaType.subtype == MEDIASUBTYPE_IYUV || FourCC ==
'I420') {
140 rgbaIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
143 rgbaIm->getHeight());
145 acqRGBaDemand =
false;
150 grayIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
154 acqGrayDemand =
false;
158 else if (connectedMediaType.subtype == MEDIASUBTYPE_YV12) {
162 rgbaIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
165 rgbaIm->getHeight());
167 acqRGBaDemand =
false;
172 grayIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
176 acqGrayDemand =
false;
179 else if (connectedMediaType.subtype == MEDIASUBTYPE_YVU9) {
183 rgbaIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
186 rgbaIm->getHeight());
188 acqRGBaDemand =
false;
193 grayIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
197 acqGrayDemand =
false;
200 else if (connectedMediaType.subtype == MEDIASUBTYPE_YUY2 || connectedMediaType.subtype == MEDIASUBTYPE_YUYV) {
204 rgbaIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
207 rgbaIm->getWidth() * rgbaIm->getHeight());
209 acqRGBaDemand =
false;
214 grayIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
218 acqGrayDemand =
false;
221 else if (connectedMediaType.subtype == MEDIASUBTYPE_YVYU) {
225 rgbaIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
228 rgbaIm->getWidth() * rgbaIm->getHeight());
230 acqRGBaDemand =
false;
235 grayIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
239 acqGrayDemand =
false;
242 else if (connectedMediaType.subtype == MEDIASUBTYPE_UYVY) {
246 rgbaIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
249 rgbaIm->getWidth() * rgbaIm->getHeight());
251 acqRGBaDemand =
false;
256 grayIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
260 acqGrayDemand =
false;
263 else if (connectedMediaType.subtype == MEDIASUBTYPE_RGB32) {
267 rgbaIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
271 memcpy(rgbaIm->bitmap, pBuffer, 4 * rgbaIm->getWidth() * rgbaIm->getHeight());
273 acqRGBaDemand =
false;
278 grayIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
282 acqGrayDemand =
false;
289 ReleaseSemaphore(copySem, 1,
nullptr);
294 #elif !defined(VISP_BUILD_SHARED_LIBS)
297 void dummy_vpDirectShowSampleGrabberI() { };
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 YUV420ToRGBa(unsigned char *yuv, unsigned char *rgba, unsigned int width, unsigned int height)
static void YUV420ToGrey(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 RGBaToGrey(unsigned char *rgba, unsigned char *grey, unsigned int width, unsigned int height, unsigned int nThreads=0)
static void YCrCbToRGBa(unsigned char *ycrcb, unsigned char *rgb, unsigned int size)
static void YUV422ToRGBa(unsigned char *yuv, unsigned char *rgba, unsigned int size)
static void BGRToGrey(unsigned char *bgr, unsigned char *grey, unsigned int width, unsigned int height, bool flip=false, unsigned int nThreads=0)
static void BGRToRGBa(unsigned char *bgr, unsigned char *rgba, unsigned int width, unsigned int height, bool flip=false)