Merge pull request #822 from mp3butcher/patch-32

optimize indexed color DDS conversion
This commit is contained in:
OpenSceneGraph git repository 2019-12-11 16:47:44 +00:00 committed by GitHub
commit 6477397b95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -989,9 +989,10 @@ 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)
{
if (!_istream.read((char*)palette, 1024))
@ -1030,13 +1031,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++)