MCPcopy Create free account
hub / github.com/NVIDIAGameWorks/Falcor / loadDDS

Function loadDDS

Source/Falcor/Utils/Image/ImageIO.cpp:523–554  ·  view source on GitHub ↗

Loads the information and data for the specified image. This function does not handle creation of the texture for the image.

Source from the content-addressed store, hash-verified

521
522// Loads the information and data for the specified image. This function does not handle creation of the texture for the image.
523void loadDDS(const std::filesystem::path& path, bool loadAsSrgb, ImportData& data)
524{
525 MemoryMappedFile file(path, MemoryMappedFile::kWholeFile, MemoryMappedFile::AccessHint::SequentialScan);
526 if (!file.isOpen())
527 {
528 FALCOR_THROW("Failed to open file.");
529 }
530
531 if (file.getSize() < (sizeof(uint32_t) + sizeof(DDS_HEADER)))
532 {
533 FALCOR_THROW("Failed to read DDS header (file too small).");
534 }
535
536 // Read the DDS header
537 const size_t maxHeaderSize = sizeof(uint32_t) + sizeof(DDS_HEADER) + sizeof(DDS_HEADER_DXT10);
538 uint8_t header[maxHeaderSize] = {};
539 size_t headerSize = maxHeaderSize;
540
541 // The actual header size may be smaller than the max size; be sure not to read past the end of the file.
542 std::memcpy(header, file.getData(), std::min<size_t>(file.getSize(), headerSize));
543 readDDSHeader(data, header, headerSize, loadAsSrgb);
544
545 if (file.getSize() <= headerSize)
546 {
547 FALCOR_THROW("No image data after DDS header.");
548 }
549
550 // Read image data.
551 size_t imageSize = file.getSize() - headerSize;
552 data.imageData.resize(imageSize);
553 std::memcpy(data.imageData.data(), reinterpret_cast<const uint8_t*>(file.getData()) + headerSize, imageSize);
554}
555} // namespace
556
557Bitmap::UniqueConstPtr ImageIO::loadBitmapFromDDS(const std::filesystem::path& path)

Callers 2

loadBitmapFromDDSMethod · 0.85
loadTextureFromDDSMethod · 0.85

Calls 5

readDDSHeaderFunction · 0.85
getSizeMethod · 0.45
getDataMethod · 0.45
resizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected