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

Function validate_config

Source/astcenc_entry.cpp:434–501  ·  view source on GitHub ↗

* Validate that an incoming configuration is in-spec. * * This function can respond in two ways: * * * Numerical inputs that have valid ranges are clamped to those valid ranges. No error is thrown * for out-of-range inputs in this case. * * Numerical inputs and logic inputs are are logically invalid and which make no sense * algorithmically will return an error. * * @param[in,

Source from the content-addressed store, hash-verified

432 * @return Return @c ASTCENC_SUCCESS if validated, otherwise an error on failure.
433 */
434static astcenc_error validate_config(
435 astcenc_config &config
436) {
437 astcenc_error status;
438
439 status = validate_profile(config.profile);
440 if (status != ASTCENC_SUCCESS)
441 {
442 return status;
443 }
444
445 status = validate_flags(config.profile, config.flags);
446 if (status != ASTCENC_SUCCESS)
447 {
448 return status;
449 }
450
451 status = validate_block_size(config.block_x, config.block_y, config.block_z);
452 if (status != ASTCENC_SUCCESS)
453 {
454 return status;
455 }
456
457#if defined(ASTCENC_DECOMPRESS_ONLY)
458 // Decompress-only builds only support decompress-only contexts
459 if (!(config.flags & ASTCENC_FLG_DECOMPRESS_ONLY))
460 {
461 return ASTCENC_ERR_BAD_PARAM;
462 }
463#endif
464
465 config.rgbm_m_scale = astc::max(config.rgbm_m_scale, 1.0f);
466
467 config.tune_partition_count_limit = astc::clamp(config.tune_partition_count_limit, 1u, 4u);
468 config.tune_2partition_index_limit = astc::clamp(config.tune_2partition_index_limit, 1u, BLOCK_MAX_PARTITIONINGS);
469 config.tune_3partition_index_limit = astc::clamp(config.tune_3partition_index_limit, 1u, BLOCK_MAX_PARTITIONINGS);
470 config.tune_4partition_index_limit = astc::clamp(config.tune_4partition_index_limit, 1u, BLOCK_MAX_PARTITIONINGS);
471 config.tune_block_mode_limit = astc::clamp(config.tune_block_mode_limit, 1u, 100u);
472 config.tune_refinement_limit = astc::max(config.tune_refinement_limit, 1u);
473 config.tune_candidate_limit = astc::clamp(config.tune_candidate_limit, 1u, TUNE_MAX_TRIAL_CANDIDATES);
474 config.tune_2partitioning_candidate_limit = astc::clamp(config.tune_2partitioning_candidate_limit, 1u, TUNE_MAX_PARTITIONING_CANDIDATES);
475 config.tune_3partitioning_candidate_limit = astc::clamp(config.tune_3partitioning_candidate_limit, 1u, TUNE_MAX_PARTITIONING_CANDIDATES);
476 config.tune_4partitioning_candidate_limit = astc::clamp(config.tune_4partitioning_candidate_limit, 1u, TUNE_MAX_PARTITIONING_CANDIDATES);
477 config.tune_db_limit = astc::max(config.tune_db_limit, 0.0f);
478 config.tune_mse_overshoot = astc::max(config.tune_mse_overshoot, 1.0f);
479 config.tune_2partition_early_out_limit_factor = astc::max(config.tune_2partition_early_out_limit_factor, 0.0f);
480 config.tune_3partition_early_out_limit_factor = astc::max(config.tune_3partition_early_out_limit_factor, 0.0f);
481 config.tune_2plane_early_out_limit_correlation = astc::max(config.tune_2plane_early_out_limit_correlation, 0.0f);
482
483 // Specifying a zero weight color component is not allowed; force to small value
484 float max_weight = astc::max(astc::max(config.cw_r_weight, config.cw_g_weight),
485 astc::max(config.cw_b_weight, config.cw_a_weight));
486 if (max_weight > 0.0f)
487 {
488 max_weight /= 1000.0f;
489 config.cw_r_weight = astc::max(config.cw_r_weight, max_weight);
490 config.cw_g_weight = astc::max(config.cw_g_weight, max_weight);
491 config.cw_b_weight = astc::max(config.cw_b_weight, max_weight);

Callers 1

astcenc_context_allocFunction · 0.85

Calls 5

validate_profileFunction · 0.85
validate_flagsFunction · 0.85
validate_block_sizeFunction · 0.85
maxFunction · 0.70
clampFunction · 0.70

Tested by

no test coverage detected