MCPcopy Create free account
hub / github.com/GarageGames/Torque3D / readHeader

Method readHeader

Engine/source/gfx/bitmap/ddsLoader.cpp:237–545  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

235}
236
237bool DDSFile::readHeader(Stream &s)
238{
239 U32 tmp;
240
241 // Read the FOURCC
242 s.read(&tmp);
243
244 if(tmp != MakeFourCC('D', 'D', 'S', ' '))
245 {
246 Con::errorf("DDSFile::readHeader - unexpected magic number, wanted 'DDS '!");
247 return false;
248 }
249
250 // Read the size of the header.
251 s.read(&tmp);
252
253 if(tmp != 124)
254 {
255 Con::errorf("DDSFile::readHeader - incorrect header size. Expected 124 bytes.");
256 return false;
257 }
258
259 // Read some flags...
260 U32 ddsdFlags;
261 s.read(&ddsdFlags);
262
263 // "Always include DDSD_CAPS, DDSD_PIXELFORMAT, DDSD_WIDTH, DDSD_HEIGHT."
264 if(!(ddsdFlags & (DDSDCaps | DDSDPixelFormat | DDSDWidth | DDSDHeight)))
265 {
266 Con::errorf("DDSFile::readHeader - incorrect surface description flags.");
267 return false;
268 }
269
270 // Read height and width (always present)
271 s.read(&mHeight);
272 s.read(&mWidth);
273
274 // Read pitch or linear size.
275
276 // First make sure we have valid flags (either linear size or pitch).
277 if((ddsdFlags & (DDSDLinearSize | DDSDPitch)) == (DDSDLinearSize | DDSDPitch))
278 {
279 // Both are invalid!
280 Con::errorf("DDSFile::readHeader - encountered both DDSD_LINEARSIZE and DDSD_PITCH!");
281 return false;
282 }
283
284 // Ok, some flags are set, so let's do some reading.
285 s.read(&mPitchOrLinearSize);
286
287 if(ddsdFlags & DDSDLinearSize)
288 {
289 mFlags.set(LinearSizeFlag); // ( mHeight / 4 ) * ( mWidth / 4 ) * DDSSIZE
290 }
291 else if (ddsdFlags & DDSDPitch)
292 {
293 mFlags.set(PitchSizeFlag); // ( mWidth / 4 ) * DDSSIZE ???
294 }

Callers

nothing calls this directly

Calls 3

errorfFunction · 0.85
readMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected