MCPcopy Create free account
hub / github.com/ARM-software/astc-encoder / astcenc_decompress_image

Function astcenc_decompress_image

Source/astcenc_entry.cpp:1274–1390  ·  view source on GitHub ↗

See header for documentation. */

Source from the content-addressed store, hash-verified

1272
1273/* See header for documentation. */
1274astcenc_error astcenc_decompress_image(
1275 astcenc_context* ctxo,
1276 const uint8_t* data,
1277 size_t data_len,
1278 astcenc_image* image_outp,
1279 const astcenc_swizzle* swizzle,
1280 unsigned int thread_index
1281) {
1282 astcenc_error status;
1283 astcenc_image& image_out = *image_outp;
1284 astcenc_contexti* ctx = &ctxo->context;
1285
1286 // Today this doesn't matter (working set on stack) but might in future ...
1287 if (thread_index >= ctx->thread_count)
1288 {
1289 return ASTCENC_ERR_BAD_PARAM;
1290 }
1291
1292 status = validate_decompression_swizzle(*swizzle);
1293 if (status != ASTCENC_SUCCESS)
1294 {
1295 return status;
1296 }
1297
1298 size_t dim_x = image_out.dim_x;
1299 size_t dim_y = image_out.dim_y;
1300 size_t dim_z = image_out.dim_z;
1301
1302 size_t texel_count = get_texels_count(dim_x, dim_y, dim_z);
1303 // Cumulative texel sizes would overflow a size_t
1304 if (texel_count == 0)
1305 {
1306 return ASTCENC_ERR_BAD_PARAM;
1307 }
1308
1309 size_t block_x = ctx->config.block_x;
1310 size_t block_y = ctx->config.block_y;
1311 size_t block_z = ctx->config.block_z;
1312
1313 size_t blocks_x = astc::get_block_count_safe(dim_x, block_x);
1314 size_t blocks_y = astc::get_block_count_safe(dim_y, block_y);
1315 size_t blocks_z = astc::get_block_count_safe(dim_z, block_z);
1316
1317 size_t block_count = get_blocks_count(blocks_x, blocks_y, blocks_z);
1318 // Cumulative block sizes would overflow a size_t
1319 if (block_count == 0)
1320 {
1321 return ASTCENC_ERR_BAD_PARAM;
1322 }
1323
1324 // Check we have enough output space, size_needed calc cannot overflow as
1325 // get_blocks_count() already validated that a byte count would fit
1326 size_t size_needed = block_count * 16;
1327 if (data_len < size_needed)
1328 {
1329 return ASTCENC_ERR_OUT_OF_MEM;
1330 }
1331

Callers 6

mainFunction · 0.85
astcenc_mainFunction · 0.85
LLVMFuzzerTestOneInputFunction · 0.85
TESTFunction · 0.85
test_decode.cppFile · 0.85

Calls 11

get_texels_countFunction · 0.85
get_block_count_safeFunction · 0.85
get_blocks_countFunction · 0.85
astcenc_decompress_resetFunction · 0.85
physical_to_symbolicFunction · 0.85
store_image_blockFunction · 0.85
initMethod · 0.80
get_task_assignmentMethod · 0.80

Tested by 1

TESTFunction · 0.68