diff --git a/Source/astcenc.h b/Source/astcenc.h index ffce903e1c5134a867ade6ae81a5adc81ecfc3bc..c948112fee19a69db5d3befdd537d80ee5e14204 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 }; @@ -913,6 +916,8 @@ ASTCENC_PUBLIC const char* astcenc_get_error_string( #ifdef ASTC_CUSTOMIZED_ENABLE #if defined(_WIN32) && !defined(__CYGWIN__) const LPCSTR g_astcCustomizedSo = "libastcCustomizedEncode.dll"; +#elif defined(__APPLE__) +const std::string g_astcCustomizedSo = "libastcCustomizedEncode.dylib"; #elif defined(BUILD_HMOS_SDK) const std::string g_astcCustomizedSo = "libastcCustomizedEncode.so"; #else diff --git a/Source/astcenc_block_sizes.cpp b/Source/astcenc_block_sizes.cpp index 9e53ff28730f819a82072b2c1df3902abba315d9..23623e65189fc7d81547825966436fc05e5f6ee7 100644 --- a/Source/astcenc_block_sizes.cpp +++ b/Source/astcenc_block_sizes.cpp @@ -789,7 +789,7 @@ 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. */ -static void construct_block_size_descriptor_2d( +static bool construct_block_size_descriptor_2d( QualityProfile privateProfile, unsigned int x_texels, unsigned int y_texels, @@ -862,7 +862,11 @@ static void construct_block_size_descriptor_2d( g_astcCustomizedSoManager.isCustomizedBlockModeFunc_ == nullptr) { printf("astcenc customized so dlopen failed or isCustomizedBlockModeFunc_ is nullptr!\n"); - return; + delete wb; +#if !defined(ASTCENC_DECOMPRESS_ONLY) + delete[] percentiles; +#endif + return false; } if ((privateProfile == CUSTOMIZED_PROFILE) && (!g_astcCustomizedSoManager.isCustomizedBlockModeFunc_(i))) { @@ -997,6 +1001,7 @@ static void construct_block_size_descriptor_2d( assign_kmeans_texels(bsd); delete wb; + return true; } /** @@ -1182,7 +1187,7 @@ static void construct_block_size_descriptor_3d( } /* See header for documentation. */ -void init_block_size_descriptor( +bool init_block_size_descriptor( QualityProfile privateProfile, unsigned int x_texels, unsigned int y_texels, @@ -1198,8 +1203,12 @@ void init_block_size_descriptor( } else { - construct_block_size_descriptor_2d(privateProfile, x_texels, y_texels, can_omit_modes, mode_cutoff, bsd); + if (!construct_block_size_descriptor_2d(privateProfile, x_texels, y_texels, can_omit_modes, mode_cutoff, bsd)) + { + return false; + } } init_partition_tables(bsd, can_omit_modes, partition_count_cutoff); + return true; } diff --git a/Source/astcenc_compress_symbolic.cpp b/Source/astcenc_compress_symbolic.cpp index df55d053e690dc0ba068d29e142654917a3bdf77..f1617a54736ee116f166debe14254eab40e5fdbd 100644 --- a/Source/astcenc_compress_symbolic.cpp +++ b/Source/astcenc_compress_symbolic.cpp @@ -1175,7 +1175,7 @@ static float prepare_block_statistics( } /* See header for documentation. */ -void compress_block( +bool compress_block( const astcenc_contexti& ctx, const image_block& blk, uint8_t pcb[16], @@ -1219,7 +1219,7 @@ void compress_block( g_astcCustomizedSoManager.customizedMaxPartitionsFunc_ == nullptr) { printf("astcenc customized so dlopen failed or customizedMaxPartitionsFunc_ is nullptr!\n"); - return; + return false; } max_partitions = g_astcCustomizedSoManager.customizedMaxPartitionsFunc_(); } @@ -1299,7 +1299,7 @@ void compress_block( g_astcCustomizedSoManager.customizedBlockModeFunc_ == nullptr) { printf("astcenc customized so dlopen failed or customizedBlockModeFunc_ is nullptr!\n"); - return; + return false; } scb.block_mode = g_astcCustomizedSoManager.customizedBlockModeFunc_(); } @@ -1322,7 +1322,7 @@ void compress_block( *mseBlock[R_COM] = *mseBlock[G_COM] = *mseBlock[B_COM] = *mseBlock[A_COM] = 0; } #endif - return; + return true; } #if !defined(ASTCENC_DIAGNOSTICS) @@ -1556,6 +1556,7 @@ END_OF_TESTS: *mseBlock[A_COM] = colorSumDiff.lane<3>(); } #endif + return true; } #endif diff --git a/Source/astcenc_entry.cpp b/Source/astcenc_entry.cpp index 212658873e0b8379e86b62c4524588dd1f363e65..dc98655e04d3ee8092101fd1d879c03a35e3dbd3 100644 --- a/Source/astcenc_entry.cpp +++ b/Source/astcenc_entry.cpp @@ -706,11 +706,15 @@ astcenc_error astcenc_context_alloc( } bool can_omit_modes = static_cast(config.flags & ASTCENC_FLG_SELF_DECOMPRESS_ONLY); - init_block_size_descriptor(ctx->config.privateProfile, config.block_x, config.block_y, config.block_z, + 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); + *ctx->bsd)) + { + delete ctxo; + return ASTCENC_ERR_DLOPEN_FAILED; + } #if !defined(ASTCENC_DECOMPRESS_ONLY) // Do setup only needed by compression @@ -788,7 +792,7 @@ void astcenc_context_free( * @param swizzle The input swizzle. * @param[out] buffer The output array for the compressed data. */ -static void compress_image( +static bool compress_image( astcenc_context& ctxo, unsigned int thread_index, const astcenc_image& image, @@ -947,14 +951,21 @@ static void compress_image( mseBlock[B_COM] = mse[B_COM] + offset; mseBlock[A_COM] = mse[A_COM] + offset; } - compress_block(ctx, blk, bp, temp_buffers, calQualityEnable, mseBlock); + if (!compress_block(ctx, blk, bp, temp_buffers, calQualityEnable, mseBlock)) + { + return false; + } #else - compress_block(ctx, blk, bp, temp_buffers); + if (!compress_block(ctx, blk, bp, temp_buffers)) + { + return false; + } #endif } ctxo.manage_compress.complete_task_assignment(count); } + return true; } /** @@ -1108,9 +1119,15 @@ astcenc_error astcenc_compress_image( // Wait for compute_averages to complete before compressing ctxo->manage_avg.wait(); #if QUALITY_CONTROL - compress_image(*ctxo, thread_index, image, *swizzle, data_out, calQualityEnable, mse); + if (!compress_image(*ctxo, thread_index, image, *swizzle, data_out, calQualityEnable, mse)) + { + return ASTCENC_ERR_DLOPEN_FAILED; + } #else - compress_image(*ctxo, thread_index, image, *swizzle, data_out); + if (!compress_image(*ctxo, thread_index, image, *swizzle, data_out)) + { + return ASTCENC_ERR_DLOPEN_FAILED; + } #endif // Wait for compress to complete before freeing memory ctxo->manage_compress.wait(); diff --git a/Source/astcenc_internal.h b/Source/astcenc_internal.h index 4d31a5f111df6b24d41ca44122dc79d26f7ee97a..eee376b6f0593c480203c019797283ed6b58e1ee 100644 --- a/Source/astcenc_internal.h +++ b/Source/astcenc_internal.h @@ -1262,7 +1262,7 @@ struct astcenc_contexti * @param mode_cutoff The block mode percentile cutoff [0-1]. * @param[out] bsd The descriptor to initialize. */ -void init_block_size_descriptor( +bool init_block_size_descriptor( QualityProfile privateProfile, unsigned int x_texels, unsigned int y_texels, @@ -2056,7 +2056,7 @@ void compute_angular_endpoints_2planes( * @param[out] pcb The physical compressed block output. * @param[out] tmpbuf Preallocated scratch buffers for the compressor. */ -void compress_block( +bool compress_block( const astcenc_contexti& ctx, const image_block& blk, uint8_t pcb[16],