From 5516f86f9eede6bfe4f8e6aa9e0e10f332fdcf4d Mon Sep 17 00:00:00 2001 From: Julien Valentin Date: Sun, 18 Aug 2019 17:56:51 +0200 Subject: [PATCH] use memcpy instead of union --- src/osgPlugins/dds/ReaderWriterDDS.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/osgPlugins/dds/ReaderWriterDDS.cpp b/src/osgPlugins/dds/ReaderWriterDDS.cpp index 569e62013..b854b887d 100644 --- a/src/osgPlugins/dds/ReaderWriterDDS.cpp +++ b/src/osgPlugins/dds/ReaderWriterDDS.cpp @@ -990,16 +990,12 @@ osg::Image* ReadDDSFile(std::istream& _istream, bool flipDDSRead) } OSG_INFO<<"ReadDDS, dataType = 0x"<c8, 1024)) + if (!_istream.read((char*)palette, 1024)) { OSG_WARN << "ReadDDSFile warning: couldn't read palette" << std::endl; return NULL; @@ -1035,16 +1031,19 @@ 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. - PaletteWord* convertedData = new PaletteWord [sizeWithMipmaps]; - PaletteWord* pconvertedData = convertedData; + unsigned char * convertedData = new unsigned char [sizeWithMipmaps * 4]; + unsigned char * pconvertedData = convertedData; for (unsigned int i = 0; i < sizeWithMipmaps; i++) - pconvertedData++->f32 = palette[imageData[i]].f32; + { + memcpy(pconvertedData, &palette[ imageData[i] * 4], sizeof(unsigned char) * 4 ); + pconvertedData += 4; + } delete [] imageData; for (unsigned int i = 0; i < mipmap_offsets.size(); i++) mipmap_offsets[i] *= 4; internalFormat = GL_RGBA; pixelFormat = GL_RGBA; - osgImage->setImage(s,t,r, internalFormat, pixelFormat, dataType, convertedData->c8, osg::Image::USE_NEW_DELETE, packing); + osgImage->setImage(s,t,r, internalFormat, pixelFormat, dataType, convertedData, osg::Image::USE_NEW_DELETE, packing); } else {