Pixel Format Encodings?
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
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!!
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!!
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;
}
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;
}
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.
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.
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement