How To: Save image to BMP file from IBasicVideo or VMR windowless interface

A simple question being asked all over again. Given IBasicVideo, IBasicVideo2, IVMRWindowlessControl or IVMRWindowlessControl9, how to save image to file? It is easy. It is a bit easier with IBasicVideo because it is possible to query this interface directly from graph’s interface, such as IGraphBuilder, and the call will be forwarded to video renderer. This code assumes internal bitmap format is non-paletted, which I believe is always the case.

LONG nBufferSize = 0;
ATLENSURE_SUCCEEDED(pBasicVideo->GetCurrentImage(&nBufferSize, NULL));
CHeapPtr<BITMAPINFO> pBitmapInfo;
ATLENSURE_THROW(pBitmapInfo.AllocateBytes(nBufferSize), E_OUTOFMEMORY);
ATLENSURE_SUCCEEDED(pBasicVideo->GetCurrentImage(&nBufferSize, (LONG*) (BITMAPINFO*) pBitmapInfo));
const BYTE* pnData = (const BYTE*) (&pBitmapInfo->bmiHeader + 1);
// NOTE: You might wish to handle <=8 bpp bitmaps here
ATLASSERT(pBitmapInfo->bmiHeader.biBitCount > 8);
ATLASSERT(pBitmapInfo->bmiHeader.biCompression == BI_RGB);
ATLASSERT(pBitmapInfo->bmiHeader.biSizeImage);
BITMAPFILEHEADER BitmapFileHeader;
ZeroMemory(&BitmapFileHeader, sizeof BitmapFileHeader);
BitmapFileHeader.bfType = 'MB';
BitmapFileHeader.bfSize = (DWORD) (sizeof (BITMAPFILEHEADER) + pBitmapInfo->bmiHeader.biSize + pBitmapInfo->bmiHeader.biSizeImage);
BitmapFileHeader.bfOffBits = (DWORD) (sizeof (BITMAPFILEHEADER) + pBitmapInfo->bmiHeader.biSize);
ATLENSURE_SUCCEEDED(File.Write(&BitmapFileHeader, sizeof BitmapFileHeader));
ATLENSURE_SUCCEEDED(File.Write(&pBitmapInfo->bmiHeader, pBitmapInfo->bmiHeader.biSize));
ATLENSURE_SUCCEEDED(File.Write(pnData, (DWORD) pBitmapInfo->bmiHeader.biSizeImage));

How To: Dump CAtlRegExp regular expression variable on parse error

ATL regular expression code adds dump/debug capabilities with ATL_REGEXP_DUMP preprocessor definition defined (undocumented). Dump output is directed to stdout, so if the application is not console, it has to be redirected in advance, e.g. into a $(BinaryPath)$(BinaryName)-atlrx.h file.

	CAtlRegExp<> Expression; LPCTSTR pszPattern; BOOL bCaseSensitive;
#if defined(ATL_REGEXP_DUMP)
	REParseError Error = Expression.Parse(pszPattern, bCaseSensitive);
	if(Error != REPARSE_ERROR_OK)
	{
		FILE* pStream = NULL;
		if(!GetStdHandle(STD_OUTPUT_HANDLE))
		{
			TCHAR pszPath[MAX_PATH] = { 0 };
			ATLVERIFY(GetModuleFileName(_AtlBaseModule.GetModuleInstance(), pszPath, _countof(pszPath)));
			RemoveExtension(pszPath); // ATLPath::
			_tcscat_s(pszPath, _countof(pszPath), _T("-atlrx.txt"));
			ATLVERIFY(freopen_s(&pStream, CStringA(pszPath), "w", stdout) == 0);
		}
		_tprintf(_T("Error %d\n"), Error);
		Expression.Dump();
		if(pStream)
			ATLVERIFY(fclose(pStream) == 0);
		ATLASSERT(FALSE); // Break into debugger
	}
#else
	ATLVERIFY(Expression.Parse(pszPattern, bCaseSensitive) == REPARSE_ERROR_OK);
#endif // defined(ATL_REGEXP_DUMP)

There is also ATLRX_DEBUG definition, which enables other debug capabilities. CAtlRegExp object is given a virtual function OnDebugEvent through which it prints comments on CAtlRegExp::Match process, which can be also redirected to file similar way.

To the collection of crapware: Nokia PC Suite

Can there be any justification for a completely custom GUI replacing standard caption, buttons etc. and imitating Vista look on Windows XP? Vista look, but with unusual custom controls and still with a jerky Windows 3.11 style font (see prompt for installation path below).

I was about to write that unlike previous versions of Nokia PC Suite, this one at least does the very first thing it is expected to do… but nope, it crashed on… viewing contacts! And it crashes every time soon after contacts browsing is opened!

OK, this might be a “little glitch”, but the Suite is still losing USB cable connections just like it has been doing for a long long time, even when it did not yet have Vista look…

How many Windows processes is necessary for this type of application? I left Bluetooth and Infrared disabled as unneeded. Service context: ServiceLayer.exe which started NclMSBTSrv.exe, NclUSBSrv.exe, NclRSSrv.exe (thanks, because there is 4 more .exes in this Transports subdirectory); Desktop: PCSuite.exe and an application for any major task: ContentCopier.exe, ConnectionManager.exe, CommunicationCentre.exe. It makes an impression I have installed another operating system on top of Windows. I never thought that communication with a cellular phone might be such complex task, which requires so many applications started.

Nokia’s service is “ServiceLayer”, display name “ServiceLayer”, service description is missing…

How did they come to this software design? To implement custom look and feel, fully customized GUI and just not provide any descriptive name for the service, which is by the way starting automatically (well, service startup is Manual, but user applications auto-start by default and would start the service) and keeps bloating system even when the Suite is not being used.

How To: Dump DirectShow media samples

Given a DirectShow filter graph, what media samples are being sent through particular graph point? DumpMediaSamples utility gives a fast answer to this question. It prints out connection media type details (with details of VIDEOINFOHEADER, VIDEOINFOHEADER2 and WAVEFORMATEX structures corresponding to FORMAT_VideoInfo, FORMAT_VideoInfo2 and FORMAT_WaveFormatEx format types) and IMediaSample details obtained through AM_SAMPLE2_PROPERTIES structure. First of all, it is necessary to create a graph of interest using GraphEdit utility. At the point of interest it is necessary to insert [an uninitialized] Sample Grabber Filter with the filter name “SampleGrabber” (this is the default name but if you add second filter which will be given a different name and remove first filter then, the utility would fail). The graph may look like this:

Continue reading →

Mobotix cameras online (updated)

Mobotix cameras online, various models discovered by web spider bot, see previous list here:

Basic

D10D-Secure

D12D-Sec

Continue reading →