* @memberof ktxTexture2 @private * @~English * @brief Inflate the data in a ktxTexture2 object using Zstandard. * * The texture's levelIndex, dataSize, DFD, data pointer, and supercompressionScheme will * all be updated after successful inflation to reflect the inflated data. * * @param[in] This pointer to the ktxTexture2 object of interest. * @param[in] pDeflatedData po
| 2769 | * @p pInflatedData. |
| 2770 | */ |
| 2771 | KTX_error_code |
| 2772 | ktxTexture2_inflateZstdInt(ktxTexture2* This, ktx_uint8_t* pDeflatedData, |
| 2773 | ktx_uint8_t* pInflatedData, |
| 2774 | ktx_size_t inflatedDataCapacity) |
| 2775 | { |
| 2776 | ktx_uint32_t levelIndexByteLength = |
| 2777 | This->numLevels * sizeof(ktxLevelIndexEntry); |
| 2778 | uint64_t levelOffset = 0; |
| 2779 | ktxLevelIndexEntry* cindex = This->_private->_levelIndex; |
| 2780 | ktxLevelIndexEntry* nindex = NULL; |
| 2781 | ktx_uint32_t uncompressedLevelAlignment; |
| 2782 | ktx_error_code_e result = KTX_SUCCESS; |
| 2783 | |
| 2784 | ZSTD_DCtx* dctx = NULL; |
| 2785 | |
| 2786 | if (pDeflatedData == NULL) |
| 2787 | return KTX_INVALID_VALUE; |
| 2788 | |
| 2789 | if (pInflatedData == NULL) |
| 2790 | return KTX_INVALID_VALUE; |
| 2791 | |
| 2792 | if (This->supercompressionScheme != KTX_SS_ZSTD) |
| 2793 | return KTX_INVALID_OPERATION; |
| 2794 | |
| 2795 | nindex = malloc(levelIndexByteLength); |
| 2796 | if (nindex == NULL) |
| 2797 | return KTX_OUT_OF_MEMORY; |
| 2798 | |
| 2799 | uncompressedLevelAlignment = |
| 2800 | ktxTexture2_calcPostInflationLevelAlignment(This); |
| 2801 | |
| 2802 | ktx_size_t inflatedByteLength = 0; |
| 2803 | dctx = ZSTD_createDCtx(); |
| 2804 | if (dctx == NULL) { |
| 2805 | result = KTX_OUT_OF_MEMORY; |
| 2806 | goto cleanup; |
| 2807 | } |
| 2808 | for (int32_t level = This->numLevels - 1; level >= 0; level--) { |
| 2809 | size_t levelByteLength = |
| 2810 | ZSTD_decompressDCtx(dctx, pInflatedData + levelOffset, |
| 2811 | inflatedDataCapacity, |
| 2812 | &pDeflatedData[cindex[level].byteOffset], |
| 2813 | cindex[level].byteLength); |
| 2814 | if (ZSTD_isError(levelByteLength)) { |
| 2815 | ZSTD_ErrorCode error = ZSTD_getErrorCode(levelByteLength); |
| 2816 | switch(error) { |
| 2817 | case ZSTD_error_dstSize_tooSmall: |
| 2818 | result = KTX_DECOMPRESS_LENGTH_ERROR; // inflatedDataCapacity too small. |
| 2819 | goto cleanup; |
| 2820 | case ZSTD_error_checksum_wrong: |
| 2821 | result = KTX_DECOMPRESS_CHECKSUM_ERROR; |
| 2822 | goto cleanup; |
| 2823 | case ZSTD_error_memory_allocation: |
| 2824 | result = KTX_OUT_OF_MEMORY; |
| 2825 | goto cleanup; |
| 2826 | default: |
| 2827 | result = KTX_FILE_DATA_ERROR; |
| 2828 | goto cleanup; |
no test coverage detected