Skip to content

Commit

Permalink
Merge pull request #8 from TAServers/data-offset-fixes
Browse files Browse the repository at this point in the history
Data offset fixes
  • Loading branch information
Derpius authored Nov 10, 2024
2 parents 1b598c1 + e999b47 commit 5a85ab4
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/vtf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,19 @@ namespace VtfParser {
size_t getSliceSizeBytes(const ImageSizeInfo& sizeInfo) {
switch (sizeInfo.format) {
case ImageFormat::DXT1:
case ImageFormat::DXT1_ONEBITALPHA:
return ((sizeInfo.width + 3u) >> 2u) * ((sizeInfo.height + 3u) >> 2u) * 8u;
case ImageFormat::DXT1_ONEBITALPHA: {
const auto width = std::max<size_t>(sizeInfo.width, 4);
const auto height = std::max<size_t>(sizeInfo.height, 4);

return ((width + 3u) >> 2u) * ((height + 3u) >> 2u) * 8u;
}
case ImageFormat::DXT3:
case ImageFormat::DXT5:
return ((sizeInfo.width + 3u) >> 2u) * ((sizeInfo.height + 3u) >> 2u) * 16u;
case ImageFormat::DXT5: {
const auto width = std::max<size_t>(sizeInfo.width, 4);
const auto height = std::max<size_t>(sizeInfo.height, 4);

return ((width + 3u) >> 2u) * ((height + 3u) >> 2u) * 16u;
}
default:
return sizeInfo.width * sizeInfo.height * getPixelSizeBytes(sizeInfo.format);
}
Expand Down Expand Up @@ -168,8 +176,8 @@ namespace VtfParser {
}
}
} else {
lowResImageData = dataView.subspan(sizeof(Header), lowResImageDataSize);
highResImageData = dataView.subspan(sizeof(Header) + lowResImageDataSize, highResImageDataSize);
lowResImageData = dataView.subspan(header.headerSize, lowResImageDataSize);
highResImageData = dataView.subspan(header.headerSize + lowResImageDataSize, highResImageDataSize);
}
}

Expand Down

0 comments on commit 5a85ab4

Please sign in to comment.