diff --git a/Source/astcenc.h b/Source/astcenc.h index ffce903e1c5134a867ade6ae81a5adc81ecfc3bc..4d8836d88c6a2246665de138fe829e68310dc345 100644 --- a/Source/astcenc.h +++ b/Source/astcenc.h @@ -264,7 +264,10 @@ enum astcenc_error { ASTCENC_ERR_DTRACE_FAILURE, #endif #if QUALITY_CONTROL - ASTCENC_ERR_BAD_QUALITY_CHECK + ASTCENC_ERR_BAD_QUALITY_CHECK, +#endif +#ifdef ASTC_CUSTOMIZED_ENABLE + ASTCENC_ERR_DLOPEN_FAILED #endif }; @@ -938,6 +941,7 @@ public: if (!astcCustomizedSoOpened_ || astcCustomizedSoHandle_ == nullptr) { printf("astcenc customized so is not be opened when dlclose!\n"); + return; } #if defined(_WIN32) && !defined(__CYGWIN__) if (!FreeLibrary(astcCustomizedSoHandle_)) diff --git a/Source/astcenc_block_sizes.cpp b/Source/astcenc_block_sizes.cpp index 9e53ff28730f819a82072b2c1df3902abba315d9..e7b5348aa0b65c0731d0b20418af4adaa3490ca4 100644 --- a/Source/astcenc_block_sizes.cpp +++ b/Source/astcenc_block_sizes.cpp @@ -789,7 +789,11 @@ static void construct_dt_entry_2d( * @param mode_cutoff Percentile cutoff in range [0,1]. Low values more likely to be used. * @param[out] bsd The block size descriptor to populate. */ +#ifdef ASTC_CUSTOMIZED_ENABLE +static bool construct_block_size_descriptor_2d( +#else static void construct_block_size_descriptor_2d( +#endif QualityProfile privateProfile, unsigned int x_texels, unsigned int y_texels, @@ -858,15 +862,22 @@ static void construct_block_size_descriptor_2d( continue; } #ifdef ASTC_CUSTOMIZED_ENABLE - if (!g_astcCustomizedSoManager.LoadSutCustomizedSo() || - g_astcCustomizedSoManager.isCustomizedBlockModeFunc_ == nullptr) + if (privateProfile == CUSTOMIZED_PROFILE) { - printf("astcenc customized so dlopen failed or isCustomizedBlockModeFunc_ is nullptr!\n"); - return; - } - if ((privateProfile == CUSTOMIZED_PROFILE) && (!g_astcCustomizedSoManager.isCustomizedBlockModeFunc_(i))) - { - continue; + if (!g_astcCustomizedSoManager.LoadSutCustomizedSo() || + g_astcCustomizedSoManager.isCustomizedBlockModeFunc_ == nullptr) + { + printf("astcenc customized so dlopen failed or isCustomizedBlockModeFunc_ is nullptr!\n"); + delete wb; +#if !defined(ASTCENC_DECOMPRESS_ONLY) + delete[] percentiles; +#endif + return false; + } + if (!g_astcCustomizedSoManager.isCustomizedBlockModeFunc_(i)) + { + continue; + } } #endif // Decode parameters @@ -997,6 +1008,9 @@ static void construct_block_size_descriptor_2d( assign_kmeans_texels(bsd); delete wb; +#ifdef ASTC_CUSTOMIZED_ENABLE + return true; +#endif } /** @@ -1182,7 +1196,11 @@ static void construct_block_size_descriptor_3d( } /* See header for documentation. */ +#ifdef ASTC_CUSTOMIZED_ENABLE +bool init_block_size_descriptor( +#else void init_block_size_descriptor( +#endif QualityProfile privateProfile, unsigned int x_texels, unsigned int y_texels, @@ -1198,8 +1216,18 @@ void init_block_size_descriptor( } else { +#ifdef ASTC_CUSTOMIZED_ENABLE + if (!construct_block_size_descriptor_2d(privateProfile, x_texels, y_texels, can_omit_modes, mode_cutoff, bsd)) + { + return false; + } +#else construct_block_size_descriptor_2d(privateProfile, x_texels, y_texels, can_omit_modes, mode_cutoff, bsd); +#endif } init_partition_tables(bsd, can_omit_modes, partition_count_cutoff); +#ifdef ASTC_CUSTOMIZED_ENABLE + return true; +#endif } diff --git a/Source/astcenc_entry.cpp b/Source/astcenc_entry.cpp index 212658873e0b8379e86b62c4524588dd1f363e65..5a1ad96a212224ce5f0ccba105ef38740cfc3aa3 100644 --- a/Source/astcenc_entry.cpp +++ b/Source/astcenc_entry.cpp @@ -706,11 +706,25 @@ astcenc_error astcenc_context_alloc( } bool can_omit_modes = static_cast(config.flags & ASTCENC_FLG_SELF_DECOMPRESS_ONLY); +#ifdef ASTC_CUSTOMIZED_ENABLE + if (!init_block_size_descriptor(ctx->config.privateProfile, config.block_x, config.block_y, config.block_z, + can_omit_modes, + config.tune_partition_count_limit, + static_cast(config.tune_block_mode_limit) / 100.0f, + *ctx->bsd)) + { + aligned_free(ctx->bsd); + delete ctxo; + *context = nullptr; + return ASTCENC_ERR_DLOPEN_FAILED; + } +#else init_block_size_descriptor(ctx->config.privateProfile, config.block_x, config.block_y, config.block_z, can_omit_modes, config.tune_partition_count_limit, static_cast(config.tune_block_mode_limit) / 100.0f, *ctx->bsd); +#endif #if !defined(ASTCENC_DECOMPRESS_ONLY) // Do setup only needed by compression diff --git a/Source/astcenc_internal.h b/Source/astcenc_internal.h index 4d31a5f111df6b24d41ca44122dc79d26f7ee97a..03a0b72d1e9491c34e9f70c6eda3a8686ada9ff3 100644 --- a/Source/astcenc_internal.h +++ b/Source/astcenc_internal.h @@ -1262,7 +1262,11 @@ struct astcenc_contexti * @param mode_cutoff The block mode percentile cutoff [0-1]. * @param[out] bsd The descriptor to initialize. */ +#ifdef ASTC_CUSTOMIZED_ENABLE +bool init_block_size_descriptor( +#else void init_block_size_descriptor( +#endif QualityProfile privateProfile, unsigned int x_texels, unsigned int y_texels,