| 99 | } // namespace |
| 100 | |
| 101 | void decodeDataUrls( |
| 102 | GltfReaderResult& readGltf, |
| 103 | const GltfReaderOptions& options) { |
| 104 | CESIUM_TRACE("CesiumGltfReader::decodeDataUrls"); |
| 105 | if (!readGltf.model) { |
| 106 | return; |
| 107 | } |
| 108 | |
| 109 | CesiumGltf::Model& model = readGltf.model.value(); |
| 110 | |
| 111 | for (CesiumGltf::Buffer& buffer : model.buffers) { |
| 112 | if (!buffer.uri) { |
| 113 | continue; |
| 114 | } |
| 115 | |
| 116 | std::optional<DecodeResult> decoded = tryDecode(buffer.uri.value()); |
| 117 | if (!decoded) { |
| 118 | continue; |
| 119 | } |
| 120 | |
| 121 | buffer.cesium.data = std::move(decoded.value().data); |
| 122 | |
| 123 | if (options.clearDecodedDataUrls) { |
| 124 | buffer.uri.reset(); |
| 125 | } |
| 126 | |
| 127 | if (buffer.byteLength != int64_t(buffer.cesium.data.size())) { |
| 128 | readGltf.warnings.emplace_back(fmt::format( |
| 129 | "The size of the data decoded from a `data:` URL ({} bytes) " |
| 130 | "does not match the declared byteLength of the buffer " |
| 131 | "({} bytes). The byteLength has been updated to match.", |
| 132 | buffer.cesium.data.size(), |
| 133 | buffer.byteLength)); |
| 134 | buffer.byteLength = int64_t(buffer.cesium.data.size()); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | for (CesiumGltf::Image& image : model.images) { |
| 139 | if (!image.uri) { |
| 140 | continue; |
| 141 | } |
| 142 | |
| 143 | std::optional<DecodeResult> decoded = tryDecode(image.uri.value()); |
| 144 | if (!decoded) { |
| 145 | continue; |
| 146 | } |
| 147 | |
| 148 | ImageReaderResult imageResult = ImageDecoder::readImage( |
| 149 | decoded.value().data, |
| 150 | options.ktx2TranscodeTargets); |
| 151 | |
| 152 | if (!imageResult.pImage) { |
| 153 | continue; |
| 154 | } |
| 155 | |
| 156 | image.pAsset = imageResult.pImage; |
| 157 | |
| 158 | if (options.clearDecodedDataUrls) { |
no test coverage detected