private PixelFormat ConvertPixelFormat(UInt32 rgbBits, UInt32 rMask, UInt32 gMask, UInt32 bMask, UInt32 aMask)
{
// General search through pixel formats
for ( int i = (int)PixelFormat.Unknown + 1; i < (int)PixelFormat.Count; ++i )
{
PixelFormat pf = (PixelFormat)( i );
if ( PixelUtil.GetNumElemBits( pf ) == rgbBits )
{
UInt32[] testMasks = PixelUtil.GetBitMasks( pf );
int[] testBits = PixelUtil.GetBitDepths( pf );
if ( testMasks[ 0 ] == rMask && testMasks[ 1 ] == gMask &&
testMasks[ 2 ] == bMask &&
// for alpha, deal with 'X8' formats by checking bit counts
( testMasks[ 3 ] == aMask || ( aMask == 0 && testBits[ 3 ] == 0 ) ) )
{
return pf;
}
}
}
throw new AxiomException( "Cannot determine pixel format" );
}