Archived

This topic is now archived and is closed to further replies.

Pixel Format Encodings?

This topic is 6010 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m currently making a 2D sprite engine game and have two questions on the tip of my tong that I just can''t find answers for, concerning pixel formats. Q1. When setting the display mode to RGB 16bit colour, I know that to find out how many bits are used per pixel for the RGB components you check the value of the dwRGBBitCount member of a DDPIXELFORMAT structure. My question is this, if the hardware is using 5.5.5 bit encoding for 16bit RGB pixels, will dwRGBBitCount return the value 15 or 16. Q2. When loading in 16bit .bmp files, how can you tell whether the pixels for the bitmap being loaded have been encoded in a 5.5.5 or 5.6.5 pixel format. Thankz level10boy

Share this post


Link to post
Share on other sites
16-bit bmp files will have the compression in the header set to BI_BITFIELDS. Then the palette section will have 3 DWORD bitmasks for the RGB.

As for your first question, I don''t know (I doubt it), but just work it out from the pixelformat structure, it''ll be more flexible.

Waassaap!!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
5.5.5 and 5.6.5 are both considered 16bit modes by DirectX. You need to check the actual number of bits in the green pixel mask.
which is the dwGBitMask member of DDPIXELFORMAT structure.

heres the code to count the number of pixels set in agiven bitmask... (copied straight from the dx docs)

WORD GetNumberOfBits( DWORD dwMask )
{
WORD wBits = 0;
while( dwMask )
{
dwMask = dwMask & ( dwMask - 1 );
wBits++;
}
return wBits;
}

Share this post


Link to post
Share on other sites
Just checking the green bits is very risky......

Suppose some user has a card whose designers felt having twice as many shades of blue would be better than having twice as many green. Then, you''d have a problem.

Unlikely, but you should still code to handle it.

Share this post


Link to post
Share on other sites
Agreed!

Check all the colours - its not just how many bits are in R and B which is a problem. Consider this - what would your code do if the card reported a BGR format ?!

Some very old cards stored in BGR format!, as do some high-end CAD cards... And its looking likely that some unreleased cards will be using BGR natively too (based on what I''ve read in some some beta+NDA''d docs).

--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites