Loads the information and data for the specified image. This function does not handle creation of the texture for the image.
| 521 | |
| 522 | // Loads the information and data for the specified image. This function does not handle creation of the texture for the image. |
| 523 | void 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 | |
| 557 | Bitmap::UniqueConstPtr ImageIO::loadBitmapFromDDS(const std::filesystem::path& path) |
no test coverage detected