Magick++: Can't open UYVY BMP

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
jpardos

Magick++: Can't open UYVY BMP

Post by jpardos »

Hello,
I am trying to read a blob from memory which has a 16 bpp BMP encoded in UYVY.
I'm using it in directshow; I read the BimapInfoHeader from a IMediaSample, write my own BITMAPFILEHEADER, then copy the BITMAPINFOHEADER as follows.

Code: Select all

	const int SZ_BMP_HEADER = 54;
	[...]
	//BITMAPFILEHEADER
	_this->m_pDatos[0] = 'B'; _this->m_pDatos[1] = 'M';
	*((int*) &_this->m_pDatos[2]) = _this->m_szDatos + SZ_BMP_HEADER;
	*((short*) &_this->m_pDatos[6]) = 0;
	*((short*) &_this->m_pDatos[8]) = 0;
	*((int*) &_this->m_pDatos[10]) = SZ_BMP_HEADER;

	//BITMAPINFOHEADER
	*((int*) &_this->m_pDatos[14]) = _this->m_BMIHeader.biSize;
	*((int*) &_this->m_pDatos[18]) = _this->m_BMIHeader.biWidth;
	*((int*) &_this->m_pDatos[22]) = _this->m_BMIHeader.biHeight;
	*((short*) &_this->m_pDatos[26]) = _this->m_BMIHeader.biPlanes;
	*((short*) &_this->m_pDatos[28]) = _this->m_BMIHeader.biBitCount;
	*((int*) &_this->m_pDatos[30]) = _this->m_BMIHeader.biCompression;
	*((int*) &_this->m_pDatos[34]) = _this->m_BMIHeader.biSizeImage;
	*((int*) &_this->m_pDatos[38]) = _this->m_BMIHeader.biXPelsPerMeter;
	*((int*) &_this->m_pDatos[42]) = _this->m_BMIHeader.biYPelsPerMeter;
	*((int*) &_this->m_pDatos[46]) = _this->m_BMIHeader.biClrUsed;
	*((int*) &_this->m_pDatos[50]) = _this->m_BMIHeader.biClrImportant;
When converting the Blob to an Image, I get an exception, which says:
SYSTEM32: unrecognized compression `' @ bmp.c/ReadBMPImage/805
If I write a 0 in m_pDatos[30], then everything works fine m_BMIHeader contains 'YVYU' )
I'm using ImageMagick-6.4.9-Q8 on Windows XP
Do I need a plugin or something?
Thanks.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Magick++: Can't open UYVY BMP

Post by magick »

Can you write your image to disk and post a URL so we can download it? The problem is simple. Either your BMP image is corrupt and it is compressed with an algorithm that ImageMagick does not recognize. ImageMagick handles compression values of 0, 1, 2, or 3.
jpardos

Re: Magick++: Can't open UYVY BMP

Post by jpardos »

That's the problem, then. It has a compression value of 'UYVY' (0x59565955), which really is not a compression format but an encoding one ( http://msdn.microsoft.com/en-us/library ... 85%29.aspx ) so if I change it for a 0x0, ImageMagick recognizes it correctly, but the colors are wrong. I need to read it from memory and write it compressed as JPEG. Isn't there any workaround?

Thanks anyway for your quick response
Post Reply