MCPcopy Create free account
hub / github.com/KhronosGroup/KTX-Software / ktxTexture2_IterateLoadLevelFaces

Function ktxTexture2_IterateLoadLevelFaces

lib/texture2.c:2320–2506  ·  view source on GitHub ↗

* @memberof ktxTexture2 * @~English * @brief Iterate over the images in a ktxTexture2 object while loading the * image data. * * This operates similarly to ktxTexture_IterateLevelFaces() except that it * loads the images from the ktxTexture2's source to a temporary buffer * while iterating. If supercompressionScheme == KTX_SS_ZSTD or KTX_SS_ZLIB, * it will inflate the data before pa

Source from the content-addressed store, hash-verified

2318 * hold the base level image.
2319 */
2320KTX_error_code
2321ktxTexture2_IterateLoadLevelFaces(ktxTexture2* This, PFNKTXITERCB iterCb,
2322 void* userdata)
2323{
2324 DECLARE_PROTECTED(ktxTexture);
2325 ktxStream* stream = (ktxStream *)&prtctd->_stream;
2326 ktxLevelIndexEntry* levelIndex;
2327 ktx_size_t dataSize = 0, uncompressedDataSize = 0;
2328 KTX_error_code result = KTX_SUCCESS;
2329 ktx_uint8_t* dataBuf = NULL;
2330 ktx_uint8_t* uncompressedDataBuf = NULL;
2331 ktx_uint8_t* pData;
2332 ZSTD_DCtx* dctx = NULL;
2333
2334 if (This == NULL)
2335 return KTX_INVALID_VALUE;
2336
2337 if (This->classId != ktxTexture2_c)
2338 return KTX_INVALID_OPERATION;
2339
2340 if (This->supercompressionScheme != KTX_SS_NONE &&
2341 This->supercompressionScheme != KTX_SS_ZSTD &&
2342 This->supercompressionScheme != KTX_SS_ZLIB)
2343 return KTX_INVALID_OPERATION;
2344
2345 if (iterCb == NULL)
2346 return KTX_INVALID_VALUE;
2347
2348 if (prtctd->_stream.data.file == NULL)
2349 // This Texture not created from a stream or images are already loaded.
2350 return KTX_INVALID_OPERATION;
2351
2352 levelIndex = This->_private->_levelIndex;
2353
2354 // Allocate memory sufficient for the base level
2355 dataSize = levelIndex[0].byteLength;
2356 dataBuf = malloc(dataSize);
2357 if (!dataBuf)
2358 return KTX_OUT_OF_MEMORY;
2359 if (This->supercompressionScheme == KTX_SS_ZSTD || This->supercompressionScheme == KTX_SS_ZLIB) {
2360 uncompressedDataSize = levelIndex[0].uncompressedByteLength;
2361 uncompressedDataBuf = malloc(uncompressedDataSize);
2362 if (!uncompressedDataBuf) {
2363 result = KTX_OUT_OF_MEMORY;
2364 goto cleanup;
2365 }
2366 if (This->supercompressionScheme == KTX_SS_ZSTD) {
2367 dctx = ZSTD_createDCtx();
2368 }
2369 pData = uncompressedDataBuf;
2370 } else {
2371 pData = dataBuf;
2372 }
2373
2374 for (ktx_int32_t level = This->numLevels - 1; level >= 0; --level)
2375 {
2376 ktx_size_t levelSize;
2377 GLsizei width, height, depth;

Callers

nothing calls this directly

Calls 13

ZSTD_createDCtxFunction · 0.85
ZSTD_decompressDCtxFunction · 0.85
ZSTD_isErrorFunction · 0.85
ZSTD_getErrorCodeFunction · 0.85
ktxUncompressZLIBIntFunction · 0.85
_ktxSwapEndian16Function · 0.85
_ktxSwapEndian32Function · 0.85
_ktxSwapEndian64Function · 0.85
ZSTD_freeDCtxFunction · 0.85
setposMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected