-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
118 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#pragma once | ||
|
||
#include "CesiumGltf/ImageAsset.h" | ||
#include "CesiumGltfReader/Library.h" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#include <CesiumGltfReader/ImageDecoder.h> | ||
#include <CesiumNativeTests/readFile.h> | ||
|
||
#include <catch2/catch.hpp> | ||
|
||
#include <filesystem> | ||
|
||
using namespace CesiumGltf; | ||
using namespace CesiumGltfReader; | ||
|
||
TEST_CASE("CesiumGltfReader::ImageDecoder") { | ||
SECTION("Can correctly interpret mipmaps in KTX2 files") { | ||
{ | ||
// This KTX2 file has a single mip level and no further mip levels should | ||
// be generated. `mipPositions` should reflect this single mip level. | ||
std::filesystem::path ktx2File = CesiumGltfReader_TEST_DATA_DIR; | ||
ktx2File /= "ktx2/kota-onelevel.ktx2"; | ||
std::vector<std::byte> data = readFile(ktx2File.string()); | ||
ImageReaderResult imageResult = | ||
ImageDecoder::readImage(data, Ktx2TranscodeTargets{}); | ||
REQUIRE(imageResult.pImage); | ||
|
||
const ImageAsset& image = *imageResult.pImage; | ||
REQUIRE(image.mipPositions.size() == 1); | ||
CHECK(image.mipPositions[0].byteOffset == 0); | ||
CHECK(image.mipPositions[0].byteSize > 0); | ||
CHECK( | ||
image.mipPositions[0].byteSize == | ||
size_t(image.width * image.height * image.channels)); | ||
CHECK(image.mipPositions[0].byteSize == image.pixelData.size()); | ||
} | ||
|
||
{ | ||
// This KTX2 file has only a base image but further mip levels can be | ||
// generated. This image effectively has no mip levels. | ||
std::filesystem::path ktx2File = CesiumGltfReader_TEST_DATA_DIR; | ||
ktx2File /= "ktx2/kota-automipmap.ktx2"; | ||
std::vector<std::byte> data = readFile(ktx2File.string()); | ||
ImageReaderResult imageResult = | ||
ImageDecoder::readImage(data, Ktx2TranscodeTargets{}); | ||
REQUIRE(imageResult.pImage); | ||
|
||
const ImageAsset& image = *imageResult.pImage; | ||
REQUIRE(image.mipPositions.size() == 0); | ||
CHECK(image.pixelData.size() > 0); | ||
} | ||
|
||
{ | ||
// This KTX2 file has a complete mip chain. | ||
std::filesystem::path ktx2File = CesiumGltfReader_TEST_DATA_DIR; | ||
ktx2File /= "ktx2/kota-mipmaps.ktx2"; | ||
std::vector<std::byte> data = readFile(ktx2File.string()); | ||
ImageReaderResult imageResult = | ||
ImageDecoder::readImage(data, Ktx2TranscodeTargets{}); | ||
REQUIRE(imageResult.pImage); | ||
|
||
const ImageAsset& image = *imageResult.pImage; | ||
REQUIRE(image.mipPositions.size() == 9); | ||
CHECK(image.mipPositions[0].byteSize > 0); | ||
CHECK( | ||
image.mipPositions[0].byteSize == | ||
size_t(image.width * image.height * image.channels)); | ||
CHECK(image.mipPositions[0].byteSize < image.pixelData.size()); | ||
|
||
size_t smallerThan = image.mipPositions[0].byteSize; | ||
for (size_t i = 1; i < image.mipPositions.size(); ++i) { | ||
CHECK(image.mipPositions[i].byteSize < smallerThan); | ||
smallerThan = image.mipPositions[i].byteSize; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters