See header for documentation. */
| 1272 | |
| 1273 | /* See header for documentation. */ |
| 1274 | astcenc_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 |