@@ -58,23 +58,23 @@ static_assert(sizeof(SGIHeader) == 512, "must be 512 bytes");
5858} // namespace
5959
6060// http://paulbourke.net/dataformats/sgirgb/sgiversion.html
61- bool LoadSGI (const IDataBlob* pSGIData,
62- IDataBlob* pDstPixels,
63- ImageDesc* pDstImgDesc)
61+ bool LoadSGI (const void * pSGIData,
62+ size_t DataSize,
63+ IDataBlob* pDstPixels,
64+ ImageDesc* pDstImgDesc)
6465{
65- VERIFY_EXPR (pSGIData != nullptr && pDstPixels != nullptr && pDstImgDesc != nullptr );
66- const Uint8* pDataStart = pSGIData->GetConstDataPtr <Uint8>();
67- const size_t Size = pSGIData->GetSize ();
68- const Uint8* pDataEnd = pDataStart + Size;
66+ VERIFY_EXPR (pSGIData != nullptr && pDstImgDesc != nullptr );
67+ const Uint8* pDataStart = static_cast <const Uint8*>(pSGIData);
68+ const Uint8* pDataEnd = pDataStart + DataSize;
6969 const Uint8* pSrcPtr = pDataStart;
7070
71- if (Size < sizeof (SGIHeader))
71+ if (DataSize < sizeof (SGIHeader))
7272 {
73- LOG_ERROR_MESSAGE (" The SGI data size (" , Size , " ) is smaller than the size of required SGI header (" , sizeof (SGIHeader), " )." );
73+ LOG_ERROR_MESSAGE (" The SGI data size (" , DataSize , " ) is smaller than the size of required SGI header (" , sizeof (SGIHeader), " )." );
7474 return false ;
7575 }
7676
77- const auto & Header = reinterpret_cast <const SGIHeader&>(*pSrcPtr);
77+ const SGIHeader & Header = reinterpret_cast <const SGIHeader&>(*pSrcPtr);
7878 pSrcPtr += sizeof (SGIHeader);
7979
8080 constexpr Uint16 SGIMagic = 0xda01u ;
@@ -111,6 +111,9 @@ bool LoadSGI(const IDataBlob* pSGIData,
111111 return false ;
112112 }
113113
114+ if (pDstPixels == nullptr )
115+ return true ;
116+
114117 pDstImgDesc->RowStride = Width * NumChannels * BytesPerChannel;
115118 pDstPixels->Resize (size_t {Height} * pDstImgDesc->RowStride );
116119 Uint8* pDstPtr = pDstPixels->GetDataPtr <Uint8>();
@@ -151,14 +154,14 @@ bool LoadSGI(const IDataBlob* pSGIData,
151154 // RLE-compressed SGI image
152155
153156 // Offsets table starts at byte 512 and is Height * NumChannels * 4 bytes long.
154- const auto TableSize = sizeof (Uint32) * Height * NumChannels;
155- const auto * OffsetTableBE = reinterpret_cast <const Uint32*>(pSrcPtr);
157+ const size_t TableSize = sizeof (Uint32) * Height * NumChannels;
158+ const Uint32 * OffsetTableBE = reinterpret_cast <const Uint32*>(pSrcPtr);
156159 pSrcPtr += TableSize;
157160 if (pSrcPtr > pDataEnd)
158161 return false ;
159162
160163 // Length table follows the offsets table and is the same size.
161- const auto * LengthTableBE = reinterpret_cast <const Uint32*>(pSrcPtr);
164+ const Uint32 * LengthTableBE = reinterpret_cast <const Uint32*>(pSrcPtr);
162165 pSrcPtr += TableSize;
163166 if (pSrcPtr > pDataEnd)
164167 return false ;
@@ -207,11 +210,11 @@ bool LoadSGI(const IDataBlob* pSGIData,
207210 {
208211 // Each unsigned int in the offset table is the offset (from the file start) to the
209212 // start of the compressed data of each scanline for each channel.
210- const auto RleOff = PlatformMisc::SwapBytes (OffsetTableBE[y + c * Height]);
213+ const Uint32 RleOff = PlatformMisc::SwapBytes (OffsetTableBE[y + c * Height]);
211214 // The size table tells the size of the compressed data (unsigned int) of each scanline.
212- const auto RleLen = PlatformMisc::SwapBytes (LengthTableBE[y + c * Height]);
215+ const Uint32 RleLen = PlatformMisc::SwapBytes (LengthTableBE[y + c * Height]);
213216
214- auto * DstLine = pDstPtr + y * size_t {pDstImgDesc->RowStride } + c;
217+ Uint8 * DstLine = pDstPtr + y * size_t {pDstImgDesc->RowStride } + c;
215218 if (!ReadLine (DstLine, pDataStart + RleOff, pSrcPtr + RleOff + RleLen))
216219 return false ;
217220 }
@@ -230,10 +233,11 @@ bool LoadSGI(const IDataBlob* pSGIData,
230233
231234extern " C"
232235{
233- void Diligent_LoadSGI (const Diligent::IDataBlob* pSGIData,
234- Diligent::IDataBlob* pDstPixels,
235- Diligent::ImageDesc* pDstImgDesc)
236+ void Diligent_LoadSGI (const void * pSGIData,
237+ size_t DataSize,
238+ Diligent::IDataBlob* pDstPixels,
239+ Diligent::ImageDesc* pDstImgDesc)
236240 {
237- Diligent::LoadSGI (pSGIData, pDstPixels, pDstImgDesc);
241+ Diligent::LoadSGI (pSGIData, DataSize, pDstPixels, pDstImgDesc);
238242 }
239243}
0 commit comments