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

Function ktxTexture1_LoadImageData

lib/texture1.c:1301–1386  ·  view source on GitHub ↗

* @memberof ktxTexture1 * @~English * @brief Load all the image data from the ktxTexture1's source. * * The data is loaded into the provided buffer or to an internally allocated * buffer, if @p pBuffer is @c NULL. * * @param[in] This pointer to the ktxTexture object of interest. * @param[in] pBuffer pointer to the buffer in which to load the image data. * @param[in] bufSize size of the bu

Source from the content-addressed store, hash-verified

1299 * @exception KTX_OUT_OF_MEMORY Insufficient memory for the image data.
1300 */
1301KTX_error_code
1302ktxTexture1_LoadImageData(ktxTexture1* This,
1303 ktx_uint8_t* pBuffer, ktx_size_t bufSize)
1304{
1305 DECLARE_PROTECTED(ktxTexture);
1306 DECLARE_PRIVATE(ktxTexture1);
1307 ktx_uint32_t miplevel;
1308 ktx_uint8_t* pDest;
1309 ktx_uint8_t* pDestEnd;
1310 KTX_error_code result = KTX_SUCCESS;
1311
1312 if (This == NULL)
1313 return KTX_INVALID_VALUE;
1314
1315 if (prtctd->_stream.data.file == NULL)
1316 // This Texture not created from a stream or images already loaded;
1317 return KTX_INVALID_OPERATION;
1318
1319 if (pBuffer == NULL) {
1320 This->pData = malloc(This->dataSize);
1321 if (This->pData == NULL)
1322 return KTX_OUT_OF_MEMORY;
1323 pDest = This->pData;
1324 pDestEnd = pDest + This->dataSize;
1325 } else if (bufSize < This->dataSize) {
1326 return KTX_INVALID_VALUE;
1327 } else {
1328 pDest = pBuffer;
1329 pDestEnd = pBuffer + bufSize;
1330 }
1331
1332 // Need to loop through for correct byte swapping
1333 for (miplevel = 0; miplevel < This->numLevels; ++miplevel)
1334 {
1335 ktx_uint32_t faceLodSize;
1336 ktx_uint32_t faceLodSizePadded;
1337 ktx_uint32_t face;
1338 ktx_uint32_t innerIterations;
1339
1340 result = prtctd->_stream.read(&prtctd->_stream, &faceLodSize,
1341 sizeof(ktx_uint32_t));
1342 if (result != KTX_SUCCESS) {
1343 goto cleanup;
1344 }
1345 if (private->_needSwap) {
1346 _ktxSwapEndian32(&faceLodSize, 1);
1347 }
1348#if (KTX_GL_UNPACK_ALIGNMENT != 4)
1349 faceLodSizePadded = _KTX_PAD4(faceLodSize);
1350#else
1351 faceLodSizePadded = faceLodSize;
1352#endif
1353
1354 if (This->isCubemap && !This->isArray)
1355 innerIterations = This->numFaces;
1356 else
1357 innerIterations = 1;
1358 for (face = 0; face < innerIterations; ++face)

Calls 4

_ktxSwapEndian32Function · 0.85
_ktxSwapEndian16Function · 0.85
readMethod · 0.45
destructMethod · 0.45

Tested by

no test coverage detected