37#ifndef DOXYGEN_SHOULD_SKIP_THIS
39#include <visp3/core/vpImageConvert.h>
40#include <visp3/sensor/vpDirectShowSampleGrabberI.h>
42#include <visp3/core/vpConfig.h>
43#if (defined(VISP_HAVE_DIRECTSHOW))
49vpDirectShowSampleGrabberI::vpDirectShowSampleGrabberI()
50 : acqGrayDemand(false), acqRGBaDemand(false), specialMediaType(false), invertedSource(false)
53 copySem = CreateSemaphore(
nullptr, 0, 1,
nullptr);
59vpDirectShowSampleGrabberI::~vpDirectShowSampleGrabberI()
65STDMETHODIMP vpDirectShowSampleGrabberI::QueryInterface(REFIID riid,
void **ppvObject)
67 if (
nullptr == ppvObject)
69 if (riid == __uuidof(IUnknown)) {
70 *ppvObject =
static_cast<IUnknown *
>(
this);
73 if (riid == __uuidof(ISampleGrabberCB)) {
74 *ppvObject =
static_cast<ISampleGrabberCB *
>(
this);
85STDMETHODIMP vpDirectShowSampleGrabberI::BufferCB(
double Time, BYTE *pBuffer,
long BufferLen)
88 if (acqGrayDemand || acqRGBaDemand) {
90 if (connectedMediaType.formattype == FORMAT_VideoInfo) {
92 VIDEOINFOHEADER *pVih =
reinterpret_cast<VIDEOINFOHEADER *
>(connectedMediaType.pbFormat);
93 BITMAPINFOHEADER bmpInfo = pVih->bmiHeader;
98 if (!specialMediaType)
99 flip = bmpInfo.biHeight >= 0;
101 else if (invertedSource)
108 if (connectedMediaType.subtype == MEDIASUBTYPE_RGB24) {
112 rgbaIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
117 acqRGBaDemand =
false;
122 grayIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
126 acqGrayDemand =
false;
130 unsigned long FourCC;
131 FourCC = ((bmpInfo.biCompression & 0xFF000000) >> 24) | ((bmpInfo.biCompression & 0x00FF0000) >> 8) |
132 ((bmpInfo.biCompression & 0x0000FF00) << 8) | (bmpInfo.biCompression & 0x000000FF) << 24;
134 if (connectedMediaType.subtype == MEDIASUBTYPE_IYUV || FourCC ==
'I420') {
138 rgbaIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
141 rgbaIm->getHeight());
143 acqRGBaDemand =
false;
148 grayIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
152 acqGrayDemand =
false;
156 else if (connectedMediaType.subtype == MEDIASUBTYPE_YV12) {
160 rgbaIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
163 rgbaIm->getHeight());
165 acqRGBaDemand =
false;
170 grayIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
174 acqGrayDemand =
false;
177 else if (connectedMediaType.subtype == MEDIASUBTYPE_YVU9) {
181 rgbaIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
184 rgbaIm->getHeight());
186 acqRGBaDemand =
false;
191 grayIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
195 acqGrayDemand =
false;
198 else if (connectedMediaType.subtype == MEDIASUBTYPE_YUY2 || connectedMediaType.subtype == MEDIASUBTYPE_YUYV) {
202 rgbaIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
205 rgbaIm->getWidth() * rgbaIm->getHeight());
207 acqRGBaDemand =
false;
212 grayIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
216 acqGrayDemand =
false;
219 else if (connectedMediaType.subtype == MEDIASUBTYPE_YVYU) {
223 rgbaIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
226 rgbaIm->getWidth() * rgbaIm->getHeight());
228 acqRGBaDemand =
false;
233 grayIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
237 acqGrayDemand =
false;
240 else if (connectedMediaType.subtype == MEDIASUBTYPE_UYVY) {
244 rgbaIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
247 rgbaIm->getWidth() * rgbaIm->getHeight());
249 acqRGBaDemand =
false;
254 grayIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
258 acqGrayDemand =
false;
261 else if (connectedMediaType.subtype == MEDIASUBTYPE_RGB32) {
265 rgbaIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
269 memcpy(rgbaIm->bitmap, pBuffer, 4 * rgbaIm->getWidth() * rgbaIm->getHeight());
271 acqRGBaDemand =
false;
276 grayIm->resize(abs(bmpInfo.biHeight), bmpInfo.biWidth);
280 acqGrayDemand =
false;
287 ReleaseSemaphore(copySem, 1,
nullptr);
292#elif !defined(VISP_BUILD_SHARED_LIBS)
295void 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)