rem: val = bitspixel[1] + (bitspixel[1] << 8);
add: val = bitspixel[1] + (bitspixel[0] << 8);
context: translate_from_bits_to_bmp24(BPositionIO *inSource,BPositionIO *outDestination, color_space fromspace, MSInfoHeader &msheader){	int32 bitsBytesPerPixel = 0;	switch (fromspace) {		case B_RGB32:		case B_RGB32_BIG:		case B_RGBA32:		case B_RGBA32_BIG:		case B_CMY32:		case B_CMYA32:		case B_CMYK32:			bitsBytesPerPixel = 4;			break;					case B_RGB24:		case B_RGB24_BIG:		case B_CMY24:			bitsBytesPerPixel = 3;			break;					case B_RGB16:		case B_RGB16_BIG:		case B_RGBA15:		case B_RGBA15_BIG:		case B_RGB15:		case B_RGB15_BIG:			bitsBytesPerPixel = 2;			break;					case B_CMAP8:		case B_GRAY8:			bitsBytesPerPixel = 1;			break;					default:			return B_ERROR;	}	int32 bitsRowBytes = msheader.width * bitsBytesPerPixel;	int32 bmpBytesPerPixel = msheader.bitsperpixel / 8;	int32 padding = (msheader.width * bmpBytesPerPixel) % 4;	if (padding)		padding = 4 - padding;	int32 bmpRowBytes = (msheader.width * bmpBytesPerPixel) + padding;	uint32 bmppixrow = 0;	off_t bitsoffset = ((msheader.height - 1) * bitsRowBytes);	inSource->Seek(bitsoffset, SEEK_CUR);	uint8 *bmpRowData = new uint8[bmpRowBytes];	if (!bmpRowData)		return B_ERROR;	uint8 *bitsRowData = new uint8[bitsRowBytes];	if (!bitsRowData) {		delete[] bmpRowData;		return B_ERROR;	}	for (int32 i = 1; i <= padding; i++)		bmpRowData[bmpRowBytes - i] = 0;	ssize_t rd = inSource->Read(bitsRowData, bitsRowBytes);	const color_map *pmap = system_colors();	while (rd == bitsRowBytes) {			for (uint32 i = 0; i < msheader.width; i++) {			uint8 *bitspixel, *bmppixel;			uint16 val;			switch (fromspace) {				case B_RGB32:				case B_RGBA32:				case B_RGB24:					memcpy(bmpRowData + (i * 3),						bitsRowData + (i * bitsBytesPerPixel), 3);					break;									case B_RGB16:				case B_RGB16_BIG:					bitspixel = bitsRowData + (i * bitsBytesPerPixel);					bmppixel = bmpRowData + (i * 3);					if (fromspace == B_RGB16)						val = bitspixel[0] + (bitspixel[1] << 8);					else						val = bitspixel[1] + (bitspixel[1] << 8);					bmppixel[0] =						((val & 0x1f) << 3) | ((val & 0x1f) >> 2);					bmppixel[1] =						((val & 0x7e0) >> 3) | ((val & 0x7e0) >> 9);					bmppixel[2] =						((val & 0xf800) >> 8) | ((val & 0xf800) >> 13);					break;				case B_RGB15:				case B_RGB15_BIG:				case B_RGBA15:				case B_RGBA15_BIG:					// NOTE: the alpha data for B_RGBA15* is not used					bitspixel = bitsRowData + (i * bitsBytesPerPixel);					bmppixel = bmpRowData + (i * 3);					if (fromspace == B_RGB15 || fromspace == B_RGBA15)						val = bitspixel[0] + (bitspixel[1] << 8);					else						val = bitspixel[1] + (bitspixel[0] << 8);					bmppixel[0] = 						((val & 0x1f) << 3) | ((val & 0x1f) >> 2);					bmppixel[1] =						((val & 0x3e0) >> 2) | ((val & 0x3e0) >> 7);					bmppixel[2] =						((val & 0x7c00) >> 7) | ((val & 0x7c00) >> 12);					break;										case B_RGB32_BIG:				case B_RGBA32_BIG:					bitspixel = bitsRowData + (i * bitsBytesPerPixel);					bmppixel = bmpRowData + (i * 3);					bmppixel[0] = bitspixel[3];					bmppixel[1] = bitspixel[2];					bmppixel[2] = bitspixel[1];					break;										case B_RGB24_BIG:					bitspixel = bitsRowData + (i * bitsBytesPerPixel);					bmppixel = bmpRowData + (i * 3);					bmppixel[0] = bitspixel[2];					bmppixel[1] = bitspixel[1];					bmppixel[2] = bitspixel[0];					break;								case B_CMAP8:					bitspixel = bitsRowData + (i * bitsBytesPerPixel);					bmppixel = bmpRowData + (i * 3);					rgb_color c = pmap->color_list[bitspixel[0]];					bmppixel[0] = c.blue;					bmppixel[1] = c.green;					bmppixel[2] = c.red;					break;									case B_GRAY8:					bitspixel = bitsRowData + (i * bitsBytesPerPixel);					bmppixel = bmpRowData + (i * 3);					bmppixel[0] = bitspixel[0];					bmppixel[1] = bitspixel[0];					bmppixel[2] = bitspixel[0];					break;									case B_CMYK32:				{					bitspixel = bitsRowData + (i * bitsBytesPerPixel);					bmppixel = bmpRowData + (i * 3);										int32 comp = 255 - bitspixel[2] - bitspixel[3];					bmppixel[0] = (comp < 0) ? 0 : comp;										comp = 255 - bitspixel[1] - bitspixel[3];					bmppixel[1] = (comp < 0) ? 0 : comp;										comp = 255 - bitspixel[0] - bitspixel[3];					bmppixel[2] = (comp < 0) ? 0 : comp;					break;				}								case B_CMY32:				case B_CMYA32:				case B_CMY24:					bitspixel = bitsRowData + (i * bitsBytesPerPixel);					bmppixel = bmpRowData + (i * 3);					bmppixel[0] = 255 - bitspixel[2];					bmppixel[1] = 255 - bitspixel[1];					bmppixel[2] = 255 - bitspixel[0];					break;										default:					break;			} // switch (fromspace)		} // for for (uint32 i = 0; i < msheader.width; i++)						outDestination->Write(bmpRowData, bmpRowBytes);		bmppixrow++;		// if I've read all of the pixel data, break		// out of the loop so I don't try to read 		// non-pixel data		if (bmppixrow == msheader.height)			break;		inSource->Seek(-(bitsRowBytes * 2), SEEK_CUR);		rd = inSource->Read(bitsRowData, bitsRowBytes);	} // while (rd == bitsRowBytes)		delete[] bmpRowData;	delete[] bitsRowData;	return B_OK;}