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

Function ktxTexture2_loadImageDataInt

lib/texture2.c:2554–2671  ·  view source on GitHub ↗

* @memberof ktxTexture2 * @internal * @~English * @brief Load all the image data from the ktxTexture2's source. * * The data will be inflated if requested and supercompressionScheme == @c KTX_SS_ZSTD * or @c KTX_SS_ZLIB. * The data is loaded into the provided buffer or to an internally allocated * buffer, if @p pBuffer is @c NULL. Callers providing their own buffer must * ensure the buffe

Source from the content-addressed store, hash-verified

2552 * @exception KTX_OUT_OF_MEMORY Insufficient memory for the image data.
2553 */
2554ktx_error_code_e
2555ktxTexture2_loadImageDataInt(ktxTexture2* This,
2556 ktx_uint8_t* pBuffer, ktx_size_t bufSize,
2557 ktxTexture2InflateFlagEnum inflateHandling)
2558{
2559 DECLARE_PROTECTED(ktxTexture);
2560 DECLARE_PRIVATE(ktxTexture2);
2561 ktx_uint8_t* pDest;
2562 ktx_uint8_t* pDeflatedData = NULL;
2563 ktx_uint8_t* pReadBuf;
2564 KTX_error_code result = KTX_SUCCESS;
2565 ktx_size_t outputDataCapacity;
2566 ktx_bool_t doInflate = false;
2567
2568 if (This == NULL)
2569 return KTX_INVALID_VALUE;
2570
2571 if (This->pData != NULL)
2572 return KTX_INVALID_OPERATION; // Data already loaded.
2573
2574 if (prtctd->_stream.data.file == NULL)
2575 // This Texture not created from a stream or images already loaded;
2576 return KTX_INVALID_OPERATION;
2577
2578 if (inflateHandling == LOADDATA_INFLATE_ON_LOAD) {
2579 outputDataCapacity = ktxTexture2_GetDataSizeUncompressed(This);
2580 if (This->supercompressionScheme == KTX_SS_ZSTD || This->supercompressionScheme == KTX_SS_ZLIB)
2581 doInflate = true;
2582 } else {
2583 outputDataCapacity = This->dataSize;
2584 }
2585
2586 if (pBuffer == NULL) {
2587 This->pData = malloc(outputDataCapacity);
2588 if (This->pData == NULL)
2589 return KTX_OUT_OF_MEMORY;
2590 pDest = This->pData;
2591 } else if (bufSize < outputDataCapacity) {
2592 return KTX_INVALID_VALUE;
2593 } else {
2594 pDest = pBuffer;
2595 }
2596
2597 if (doInflate) {
2598 // Create buffer to hold deflated data.
2599 pDeflatedData = malloc(This->dataSize);
2600 if (pDeflatedData == NULL)
2601 return KTX_OUT_OF_MEMORY;
2602 pReadBuf = pDeflatedData;
2603 } else {
2604 pReadBuf = pDest;
2605 }
2606
2607 // Seek to data for first level as there may be padding between the
2608 // metadata/sgd and the image data.
2609
2610 result = prtctd->_stream.setpos(&prtctd->_stream,
2611 private->_firstLevelFileOffset);

Callers 2

Calls 11

assertFunction · 0.85
_ktxSwapEndian16Function · 0.85
_ktxSwapEndian32Function · 0.85
_ktxSwapEndian64Function · 0.85
setposMethod · 0.45
readMethod · 0.45
destructMethod · 0.45

Tested by

no test coverage detected