See header for documentation. */
| 502 | |
| 503 | /* See header for documentation. */ |
| 504 | astcenc_error astcenc_config_init( |
| 505 | astcenc_profile profile, |
| 506 | unsigned int block_x, |
| 507 | unsigned int block_y, |
| 508 | unsigned int block_z, |
| 509 | float quality, |
| 510 | unsigned int flags, |
| 511 | astcenc_config* configp |
| 512 | ) { |
| 513 | astcenc_error status; |
| 514 | |
| 515 | status = validate_cpu_float(); |
| 516 | if (status != ASTCENC_SUCCESS) |
| 517 | { |
| 518 | return status; |
| 519 | } |
| 520 | |
| 521 | // Zero init all config fields; although most of will be overwritten |
| 522 | astcenc_config& config = *configp; |
| 523 | std::memset(&config, 0, sizeof(config)); |
| 524 | |
| 525 | // Process the block size |
| 526 | // For 2D blocks Z==0 is accepted, but convert to 1 |
| 527 | block_z = astc::max(block_z, 1u); |
| 528 | status = validate_block_size(block_x, block_y, block_z); |
| 529 | if (status != ASTCENC_SUCCESS) |
| 530 | { |
| 531 | return status; |
| 532 | } |
| 533 | |
| 534 | config.block_x = block_x; |
| 535 | config.block_y = block_y; |
| 536 | config.block_z = block_z; |
| 537 | |
| 538 | float texels = static_cast<float>(block_x * block_y * block_z); |
| 539 | float ltexels = logf(texels) / logf(10.0f); |
| 540 | |
| 541 | // Process the performance quality level or preset; note that this must be done before we |
| 542 | // process any additional settings, such as color profile and flags, which may replace some of |
| 543 | // these settings with more use case tuned values |
| 544 | if (quality < ASTCENC_PRE_FASTEST || |
| 545 | quality > ASTCENC_PRE_EXHAUSTIVE) |
| 546 | { |
| 547 | return ASTCENC_ERR_BAD_QUALITY; |
| 548 | } |
| 549 | |
| 550 | static const std::array<astcenc_preset_config, 6>* preset_configs; |
| 551 | size_t texels_int = block_x * block_y * block_z; |
| 552 | if (texels_int < 25) |
| 553 | { |
| 554 | preset_configs = &preset_configs_high; |
| 555 | } |
| 556 | else if (texels_int < 64) |
| 557 | { |
| 558 | preset_configs = &preset_configs_mid; |
| 559 | } |
| 560 | else |
| 561 | { |