取自《Focus On 3D Terrain Programming》中的一段:
//--------------------------------------------------------------
// Name: CIMAGE::LoadUncompressedTGA - private
// Description: Load an uncompressed targa (TGA)
// Arguments: None
// Return Value: A boolean variable: -true: TGA was loaded
// -false: TGA was not loaded
//--------------------------------------------------------------
bool CIMAGE::LoadUncompressedTGA( void )
{
........
....
pTGAinfo.m_uiBytesPerPixel= m_uiBPP/;
pTGAinfo.m_uiImageSize = ( pTGAinfo.m_uiBytesPerPixel*m_uiWidth*m_uiHeight ); //copy the image data
memcpy( m_ucpData, ucpFile, pTGAinfo.m_uiImageSize ); //byte swapping ( optimized by Steve Thomas )
for( uiCSwap=; uiCSwap<( int )pTGAinfo.m_uiImageSize; uiCSwap+=pTGAinfo.m_uiBytesPerPixel )
{
m_ucpData[uiCSwap]^= m_ucpData[uiCSwap+]^=m_ucpData[uiCSwap]^= m_ucpData[uiCSwap+];
} //the uncompressed TGA has been successfully loaded
return true;
}
===============
开开眼界,把BGR转换为RGB的交换代码,过于高大上了,直接操作的硬件,可以提高一定的速度,对大图片有用。
m_ucpData[uiCSwap]^= m_ucpData[uiCSwap+2]^=m_ucpData[uiCSwap]^= m_ucpData[uiCSwap+2];