Ahhh, now i got the inital question.
These bitfields are effectively masks. You can make it this way:
(pixel & mask) >> (mask_zero_bits);
However, this format is (very very) rarely used, and it’s not compatible to windows 9x.
Here’s some code for that:
unsigned char *CImage::LoadBMP16bppBIT( FILE *sFileHandle, BITMAPINFOHEADER *spInfoHeader )
{
int i,j;
//
// read and process the three color masks
//
unsigned short uintColorMasks[3];
int iColorShifts[3];
uintColorMasks[0] = file_read_uint( sFileHandle );
uintColorMasks[1] = file_read_uint( sFileHandle );
uintColorMasks[2] = file_read_uint( sFileHandle );
for( i=0; i<3; i++ ) {
for( j=0; !((uintColorMasks[i]>>j) & 1) && (j < 16); j++ );
iColorShifts[i]=j;
}
//
// Skip Palette following color masks, if any
//
int iNumPaletteEntries = spInfoHeader->biClrUsed;
fseek( sFileHandle, iNumPaletteEntries * sizeof( RGBQUAD ), SEEK_CUR );
//
// read index array from bitmap file
//
int iNumPixels = spInfoHeader->biWidth * spInfoHeader->biHeight;
int iImageBytes = iNumPixels*2;
int iReadRowBytes = spInfoHeader->biWidth * 2;
unsigned short ushortpColorArray = (unsigned short ) malloc( iImageBytes );
if( iReadRowBytes%4 ) {
// padded lines
for( i=0; ibiHeight; i++ ) {
fread( ushortpColorArray + i*iReadRowBytes, 1, iReadRowBytes, sFileHandle );
fseek( sFileHandle, 4-(iReadRowBytes%4), SEEK_CUR );
}
} else {
// unpadded lines
fread( ushortpColorArray, 1, iImageBytes, sFileHandle );
}
//
// build BGR array
//
unsigned char *ucpImageArray = (unsigned char *) malloc( iNumPixels * 3 );
for( i=0; i<iNumPixels; i++ ) {
for( j=0; j<3; j++ ) {
ucpImageArray[ i*3+j ] = (ushortpColorArray[i]&uintColorMasks[j])>>iColorShifts[j];
}
}
//
// free up and return
//
free( ushortpColorArray );
return ucpImageArray;
}
unsigned char *CImage::LoadBMP32bppBIT( FILE *sFileHandle, BITMAPINFOHEADER *spInfoHeader )
{
int i,j;
//
// read and process the three color masks
//
unsigned int uintColorMasks[3];
int iColorShifts[3];
uintColorMasks[0] = file_read_uint( sFileHandle );
uintColorMasks[1] = file_read_uint( sFileHandle );
uintColorMasks[2] = file_read_uint( sFileHandle );
for( i=0; i<3; i++ ) {
for( j=0; !((uintColorMasks[i]>>j) & 1) && j<32; j++ );
iColorShifts[i]=j;
}
//
// Skip Palette if necessary
//
int iNumPaletteEntries = spInfoHeader->biClrUsed;
fseek( sFileHandle, iNumPaletteEntries * sizeof( RGBQUAD ), SEEK_CUR );
//
// read index array from bitmap file
//
int iNumPixels = spInfoHeader->biWidth * spInfoHeader->biHeight;
int iReadBytes = iNumPixels*4;
unsigned int uintpColorArray = (unsigned int ) malloc( iReadBytes );
fread( uintpColorArray, 1, iReadBytes, sFileHandle );
//
// build BGR array
//
unsigned char *ucpImageArray = (unsigned char *) malloc( iNumPixels * 3 );
for( i=0; i<iNumPixels; i++ ) {
for( j=0; j<3; j++ ) {
ucpImageArray[ i*3+j ] = (uintpColorArray[i]&uintColorMasks[j])>>iColorShifts[j];
}
}
//
// free up and return
//
free( uintpColorArray );
return ucpImageArray;
}
[This message has been edited by Michael Steinberg (edited 06-27-2002).]
[This message has been edited by Michael Steinberg (edited 06-27-2002).]