Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CesiumGltf/include/CesiumGltf/ImageAsset.h
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remember to update CHANGES.md!

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ struct CESIUMGLTF_API ImageAssetMipPosition {
* @brief The size in bytes of this mip.
*/
size_t byteSize;

/**
* @brief The pitch (or stride) between rows of this mip in bytes.
*/
size_t rowPitch;
};

/**
Expand Down
17 changes: 12 additions & 5 deletions CesiumGltfReader/src/ImageDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,10 @@ ImageReaderResult ImageDecoder::readImage(
&imageOffset);
ktx_size_t imageSize =
ktxTexture_GetImageSize(ktxTexture(pTexture), level);
ktx_uint32_t rowPitch =
ktxTexture_GetRowPitch(ktxTexture(pTexture), level);

image.mipPositions[level] = {imageOffset, imageSize};
image.mipPositions[level] = {imageOffset, imageSize, rowPitch};
}
} else {
CESIUM_ASSERT(pTexture->numLevels == 1);
Expand Down Expand Up @@ -390,13 +392,16 @@ std::optional<std::string> ImageDecoder::generateMipMaps(ImageAsset& image) {
totalPixelCount += mipWidth * mipHeight;
}

const size_t imageRowPitch =
static_cast<size_t>(image.width * image.channels * image.bytesPerChannel);
// Byte size of the base image.
const size_t imageByteSize = static_cast<size_t>(
image.width * image.height * image.channels * image.bytesPerChannel);
const size_t imageByteSize =
imageRowPitch * static_cast<size_t>(image.height);

image.mipPositions.resize(mipCount);
image.mipPositions[0].byteOffset = 0;
image.mipPositions[0].byteSize = imageByteSize;
image.mipPositions[0].rowPitch = imageRowPitch;

image.pixelData.resize(static_cast<size_t>(
totalPixelCount * image.channels * image.bytesPerChannel));
Expand All @@ -421,11 +426,13 @@ std::optional<std::string> ImageDecoder::generateMipMaps(ImageAsset& image) {
mipHeight >>= 1;
}

byteSize = static_cast<size_t>(
mipWidth * mipHeight * image.channels * image.bytesPerChannel);
size_t rowPitch =
static_cast<size_t>(mipWidth * image.channels * image.bytesPerChannel);
byteSize = rowPitch * static_cast<size_t>(mipHeight);

image.mipPositions[mipIndex].byteOffset = byteOffset;
image.mipPositions[mipIndex].byteSize = byteSize;
image.mipPositions[mipIndex].rowPitch = rowPitch;

if (!ImageDecoder::unsafeResize(
&image.pixelData[lastByteOffset],
Expand Down
6 changes: 4 additions & 2 deletions CesiumRasterOverlays/src/GeoJsonDocumentRasterOverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -601,11 +601,13 @@ class CESIUMRASTEROVERLAYS_API GeoJsonDocumentRasterOverlayTileProvider final
for (uint32_t i = 0; i < mipLevels; i++) {
const int32_t width = std::max(textureSize.x >> i, 1);
const int32_t height = std::max(textureSize.y >> i, 1);
const int32_t rowPitch = width * result.pImage->channels *
result.pImage->bytesPerChannel;
result.pImage->mipPositions.emplace_back(
CesiumGltf::ImageAssetMipPosition{
totalSize,
(size_t)(width * height * result.pImage->channels *
result.pImage->bytesPerChannel)});
size_t(rowPitch * height),
size_t(rowPitch)});
totalSize += result.pImage->mipPositions[i].byteSize;
}
result.pImage->pixelData.resize(totalSize, std::byte{0});
Expand Down
5 changes: 4 additions & 1 deletion CesiumVectorData/test/TestVectorRasterizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,10 @@ TEST_CASE("VectorRasterizer::rasterize") {
for (size_t i = 0; i < 4; i++) {
int32_t width = 256 >> i;
int32_t height = 256 >> i;
asset->mipPositions[i] = {totalSize, (size_t)(width * height * 4)};
asset->mipPositions[i] = {
totalSize,
size_t(width * height * 4),
size_t(width * 4)};
totalSize += asset->mipPositions[i].byteSize;
}

Expand Down
Loading