BITMAPINFO + Colour video
-
Hi all, This is with reference to an old message posted by me which you can find here http://www.codeproject.com/script/Forums/View.aspx?fid=387159&msg=2452196[^] For the past one year this piece of code which Mr.Mark gave me; satisfied my requirements excellently. Now I have come up with a problem of displaying colour video. I will need help once again in modifying the code to colour mode. The main problem is how I should arrange the pixels and where to write it. What are the BITMAPINFO parameters that I have to change. Hope to get a reply at the earliest.
-
Hi all, This is with reference to an old message posted by me which you can find here http://www.codeproject.com/script/Forums/View.aspx?fid=387159&msg=2452196[^] For the past one year this piece of code which Mr.Mark gave me; satisfied my requirements excellently. Now I have come up with a problem of displaying colour video. I will need help once again in modifying the code to colour mode. The main problem is how I should arrange the pixels and where to write it. What are the BITMAPINFO parameters that I have to change. Hope to get a reply at the earliest.
How many bits per pixel (what's the pixel format)? Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
How many bits per pixel (what's the pixel format)? Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
8 bit per pixel in RGB format.I have three arrays of unsigned char for each R,G and B values.
So do you mean 24 bits per pixel? There's no 8bpp RGB format for Windows bitmaps... Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
So do you mean 24 bits per pixel? There's no 8bpp RGB format for Windows bitmaps... Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
Exactly 24bpp. But what I meant is I have 8 bits of R,8 bits of G and 8 bits of B seperately in seperate arrays. Now with respect to the routine what you have given me last time http://www.codeproject.com/script/Forums/View.aspx?fid=387159&msg=2452196[^] what are the modifications I have to do
-
Exactly 24bpp. But what I meant is I have 8 bits of R,8 bits of G and 8 bits of B seperately in seperate arrays. Now with respect to the routine what you have given me last time http://www.codeproject.com/script/Forums/View.aspx?fid=387159&msg=2452196[^] what are the modifications I have to do
To create the DIBSection, you can drop the palette and change the bmiHeader.biBitCount:
BITMAPINFO \*bm = (BITMAPINFO \*)new BYTE\[sizeof(BITMAPINFO)\]; bm->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bm->bmiHeader.biWidth = 176; bm->bmiHeader.biHeight = 144; bm->bmiHeader.biPlanes = 1; bm->bmiHeader.biBitCount = 24; bm->bmiHeader.biCompression = BI\_RGB; bm->bmiHeader.biSizeImage = 0; bm->bmiHeader.biXPelsPerMeter = 0; bm->bmiHeader.biYPelsPerMeter = 0; bm->bmiHeader.biClrUsed = 0; bm->bmiHeader.biClrImportant = 0; BYTE \*pBitmapBits; HBITMAP hBitmap = ::CreateDIBSection(NULL, bm, DIB\_RGB\_COLORS, (void\*\*)&pBitmapBits, NULL, 0); if (hBitmap) { // do your rendering stuff here! ::DeleteObject(hBitmap); } delete\[\] (BYTE \*)bm;
jossion wrote:
I have 8 bits of R,8 bits of G and 8 bits of B seperately in seperate arrays
The pixel data (pointed to by pBitmapBits) will now be a RGBTRIPLE struct for each pixel:
// From the docs:
typedef struct tagRGBTRIPLE {
BYTE rgbtBlue;
BYTE rgbtGreen;
BYTE rgbtRed;
} RGBTRIPLE;You'll need to take the individual RGB component bytes from the arrays and pack them in the RGBTRIPLE format - BGRBGRBGR... Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
To create the DIBSection, you can drop the palette and change the bmiHeader.biBitCount:
BITMAPINFO \*bm = (BITMAPINFO \*)new BYTE\[sizeof(BITMAPINFO)\]; bm->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bm->bmiHeader.biWidth = 176; bm->bmiHeader.biHeight = 144; bm->bmiHeader.biPlanes = 1; bm->bmiHeader.biBitCount = 24; bm->bmiHeader.biCompression = BI\_RGB; bm->bmiHeader.biSizeImage = 0; bm->bmiHeader.biXPelsPerMeter = 0; bm->bmiHeader.biYPelsPerMeter = 0; bm->bmiHeader.biClrUsed = 0; bm->bmiHeader.biClrImportant = 0; BYTE \*pBitmapBits; HBITMAP hBitmap = ::CreateDIBSection(NULL, bm, DIB\_RGB\_COLORS, (void\*\*)&pBitmapBits, NULL, 0); if (hBitmap) { // do your rendering stuff here! ::DeleteObject(hBitmap); } delete\[\] (BYTE \*)bm;
jossion wrote:
I have 8 bits of R,8 bits of G and 8 bits of B seperately in seperate arrays
The pixel data (pointed to by pBitmapBits) will now be a RGBTRIPLE struct for each pixel:
// From the docs:
typedef struct tagRGBTRIPLE {
BYTE rgbtBlue;
BYTE rgbtGreen;
BYTE rgbtRed;
} RGBTRIPLE;You'll need to take the individual RGB component bytes from the arrays and pack them in the RGBTRIPLE format - BGRBGRBGR... Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
I would suggest: bm->bmiHeader.biHeight = -144; instead of bm->bmiHeader.biHeight = 144; When height is positive, the bitmap is bottom-up oriented. In 99% our bitmap sources are up-bottom oriented.
That's fine....as long as the OP remembers to adjust his/her direct pixel access calculations accordingly :)
Mark Salsbery Microsoft MVP - Visual C++ :java: