|
|
|
date: Sat, 5 Jul 2008 13:26:27 +0800,
group: microsoft.public.win32.programmer.directx.video
back
setting BITMAPINFO for RGB565
I need to create a RGB565 bitmap via CreateDIBSection. I set the header bit
mask using:
BITMAPINFO dibInfo;
dibInfo.bmiHeader.biBitCount = 16;
dibInfo.bmiHeader.biClrImportant = 0;
dibInfo.bmiHeader.biClrUsed = 0;
dibInfo.bmiHeader.biCompression = BI_BITFIELDS;
dibInfo.bmiHeader.biHeight = frameHeight;
dibInfo.bmiHeader.biWidth = frameWidth;
dibInfo.bmiHeader.biPlanes = 1;
dibInfo.bmiHeader.biSize = 40;
dibInfo.bmiHeader.biSizeImage = frameWidth*frameHeight*2;
//set bitmap bits to indicate RGB 565
unsigned long *ptr = (unsigned long *)(dibInfo.bmiColors);
ptr[0] = 0xf800;
ptr[1] = 0x07e0;
ptr[2] = 0x001f;
The bitmasks value of 0xf800 (red), 0x07e0 (green) and 0x001f(blue) are
taken from MSDN. After first looking at the documentation, a very obvious
way would be setting dibInfo.bmiColors->rgbBlue, etc. However, this could
not work because the values are too large for rgbBlue, which is BYTE. After
googling, I came up with above approach.
This works only if CreateDIBSection is called immediately after the
assignment to ptr[2]. After a while, the assignments for ptr[0], ptr[1],
ptr[2] seems to have some side effects on other variables, e.g. random
change of variable values and eventually access violations.
Any ideas how I can avoid this? Maybe assigning some other specific values
to dibInfo.bmiColors->rgbBlue , instead of setting them via pointer?
date: Sat, 5 Jul 2008 13:26:27 +0800
author: minhdanh
Re: setting BITMAPINFO for RGB565
"Roman Ryl..." wrote:
>> >If you are using ATL, it could be a bit easier:
>>
>> >CTempBuffer<BITMAPINFOHEADER> pBitmapInfoHeader(sizeof
>> >(BITMAPINFOHEADER) + sizeof (DWORD) * 3);
>>
>> Have you tried that? It doesn't do what you think it does. That will
>> allocate enough space for 52 copies of a BITMAPINFOHEADER (2080 bytes),
>> *NOT* 52 bytes.
>>
>> However, this would work:
>>
>> CTempBuffer<BITMAPINFOHEADER,
>> sizeof(BITMAPINFOHEADER) + sizeof(DWORD) * 3> pBitmapInfoHeader( 0 );
>
>You are correct, original allocation is incorrect. However yours is
>also not quite how it should be (it creates sufficient buffer on stack
>but request zero bytes to be "allocated" from it).
Actually, if the requested allocation is less than the "minimum" size in
the second template parameter, it uses the "minimum" size, so my code will
work. However...
>It should be this way:
>
>CTempBuffer<BITMAPINFOHEADER> pBitmapInfoHeader;
>ATLVERIFY(pBitmapInfoHeader.AllocateBytes(sizeof(BITMAPINFOHEADER) +
>sizeof(DWORD) * 3));
...I had not noticed CTempBuffer before this week. After I made my post, I
dug in more thoroughly and came to the same conclusion you did. Both our
schemes will work, but I believe yours is more sensible.
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
date: Mon, 07 Jul 2008 21:41:27 -0700
author: Tim Roberts
|
|