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

Function astcenc_context_alloc

Source/astcenc_entry.cpp:726–859  ·  view source on GitHub ↗

See header for documentation. */

Source from the content-addressed store, hash-verified

724
725/* See header for documentation. */
726astcenc_error astcenc_context_alloc(
727 const astcenc_config* configp,
728 unsigned int thread_count,
729 astcenc_context** context,
730 const astcenc_context* parent_context
731) {
732 astcenc_error status;
733
734 status = validate_cpu_float();
735 if (status != ASTCENC_SUCCESS)
736 {
737 return status;
738 }
739
740 if (thread_count == 0)
741 {
742 return ASTCENC_ERR_BAD_PARAM;
743 }
744
745#if defined(ASTCENC_DIAGNOSTICS)
746 // Force single threaded compressor use in diagnostic mode
747 if (thread_count != 1)
748 {
749 return ASTCENC_ERR_BAD_PARAM;
750 }
751#endif
752
753 // Exactly one of config or parent_context must be set
754 bool has_config = configp != nullptr;
755 bool has_parent = parent_context != nullptr;
756 if (!(has_config ^ has_parent))
757 {
758 return ASTCENC_ERR_BAD_PARAM;
759 }
760
761 if (has_parent)
762 {
763 configp = &parent_context->context.config;
764 }
765
766 const astcenc_config& config = *configp;
767 astcenc_context* ctxo = new astcenc_context;
768 astcenc_contexti* ctx = &ctxo->context;
769 ctx->thread_count = thread_count;
770 ctx->config = *configp;
771 ctx->working_buffers = nullptr;
772
773 // These are allocated per-compress, as they depend on image size
774 ctx->input_alpha_averages = nullptr;
775
776 // Copy the config first and validate the copy (we may modify it)
777 status = validate_config(ctx->config);
778 if (status != ASTCENC_SUCCESS)
779 {
780 delete ctxo;
781 return status;
782 }
783

Callers 8

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

Calls 6

validate_cpu_floatFunction · 0.85
validate_configFunction · 0.85
powFunction · 0.85
trace_add_dataFunction · 0.85
prepare_angular_tablesFunction · 0.85

Tested by 3

TESTFunction · 0.68
TESTFunction · 0.68
run_positive_testFunction · 0.68