MCPcopy Create free account
hub / github.com/GPUOpen-Tools/compressonator / LoadDDSFile

Function LoadDDSFile

examples/common/dds_helpers.cpp:381–453  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

379static const DWORD DDS_HEADER = MAKEFOURCC('D', 'D', 'S', ' ');
380
381bool LoadDDSFile(const char* pszFile, CMP_Texture& texture)
382{
383 FILE* pSourceFile = fopen(pszFile, ("rb"));
384
385 if (!pSourceFile)
386 return false;
387
388 DWORD dwFileHeader;
389 fread(&dwFileHeader, sizeof(DWORD), 1, pSourceFile);
390 if (dwFileHeader != DDS_HEADER)
391 {
392 printf("Source file is not a valid DDS.\n");
393 fclose(pSourceFile);
394 return false;
395 }
396
397 DDSD2 ddsd;
398 fread(&ddsd, sizeof(DDSD2), 1, pSourceFile);
399
400 memset(&texture, 0, sizeof(texture));
401 texture.dwSize = sizeof(texture);
402 texture.dwWidth = ddsd.dwWidth;
403 texture.dwHeight = ddsd.dwHeight;
404 texture.dwPitch = ddsd.lPitch;
405
406 if (ddsd.ddpfPixelFormat.dwRGBBitCount == 32)
407 {
408 // Visual Studio reports as 32bpp RGBA
409 if ((ddsd.ddpfPixelFormat.dwRBitMask == 0x000000ff) && (ddsd.ddpfPixelFormat.dwGBitMask == 0x0000ff00) &&
410 (ddsd.ddpfPixelFormat.dwBBitMask == 0x00ff0000) && (ddsd.ddpfPixelFormat.dwRGBAlphaBitMask == 0xff000000))
411 {
412 texture.format = CMP_FORMAT_RGBA_8888;
413 }
414 else
415 // Visual Studio reports as 32bpp BGRA
416 if ((ddsd.ddpfPixelFormat.dwRBitMask == 0x00ff0000) && (ddsd.ddpfPixelFormat.dwGBitMask == 0x0000ff00) &&
417 (ddsd.ddpfPixelFormat.dwBBitMask == 0x000000ff) && (ddsd.ddpfPixelFormat.dwRGBAlphaBitMask == 0xff000000))
418 {
419 texture.format = CMP_FORMAT_BGRA_8888;
420 }
421 }
422 else if (ddsd.ddpfPixelFormat.dwRGBBitCount == 24)
423 {
424 // assumptions is made here should check all channel locations
425 if (ddsd.ddpfPixelFormat.dwRBitMask == 0xff)
426 {
427 texture.format = CMP_FORMAT_RGB_888;
428 }
429 else
430 {
431 texture.format = CMP_FORMAT_BGR_888;
432 }
433 }
434 else if (GetFormat(ddsd.ddpfPixelFormat.dwPrivateFormatBitCount) != CMP_FORMAT_Unknown)
435 texture.format = GetFormat(ddsd.ddpfPixelFormat.dwPrivateFormatBitCount);
436 else if (GetFormat(ddsd.ddpfPixelFormat.dwFourCC) != CMP_FORMAT_Unknown)
437 texture.format = GetFormat(ddsd.ddpfPixelFormat.dwFourCC);
438 else

Callers 3

mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85

Calls 3

memsetFunction · 0.85
CMP_CalculateBufferSizeFunction · 0.85
GetFormatFunction · 0.70

Tested by

no test coverage detected