use memcpy instead of union

This commit is contained in:
Julien Valentin 2019-08-18 17:56:51 +02:00 committed by Robert Osfield
parent bd50af117b
commit 16b5dd5115

View File

@ -989,7 +989,7 @@ osg::Image* ReadDDSFile(std::istream& _istream, bool flipDDSRead)
}
}
OSG_INFO<<"ReadDDS, dataType = 0x"<<std::hex<<dataType<<std::endl;
OSG_INFO<<"ReadDDS, dataType = 0x"<<std::hex<<dataType<<std::endl;
unsigned char palette [1024];
if (ddsd.ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED8)
@ -1030,13 +1030,12 @@ osg::Image* ReadDDSFile(std::istream& _istream, bool flipDDSRead)
if (ddsd.ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED8)
{
// Now we need to substitute the indexed image data with full RGBA image data.
unsigned char* convertedData = new unsigned char [sizeWithMipmaps * 4];
unsigned char * convertedData = new unsigned char [sizeWithMipmaps * 4];
unsigned char * pconvertedData = convertedData;
for (unsigned int i = 0; i < sizeWithMipmaps; i++)
{
convertedData[i * 4 + 0] = palette[imageData[i] * 4 + 0];
convertedData[i * 4 + 1] = palette[imageData[i] * 4 + 1];
convertedData[i * 4 + 2] = palette[imageData[i] * 4 + 2];
convertedData[i * 4 + 3] = palette[imageData[i] * 4 + 3];
memcpy(pconvertedData, &palette[ imageData[i] * 4], sizeof(unsigned char) * 4 );
pconvertedData += 4;
}
delete [] imageData;
for (unsigned int i = 0; i < mipmap_offsets.size(); i++)