diff --git a/Source/astcenc.h b/Source/astcenc.h index 4d8836d88c6a2246665de138fe829e68310dc345..f9ce19fb569db98855d2349b992d233bfa02f1bb 100644 --- a/Source/astcenc.h +++ b/Source/astcenc.h @@ -175,27 +175,10 @@ #define ASTCENC_NEON 0 #endif -#ifdef ASTC_CUSTOMIZED_ENABLE -#if defined(_WIN32) && !defined(__CYGWIN__) -#define NOMINMAX -#include -#include -#else -#include -#endif - -#include -#include -#include -#include -#endif - enum QualityProfile { HIGH_QUALITY_PROFILE = 0, // default profile HIGH_SPEED_PROFILE, -#ifdef ASTC_CUSTOMIZED_ENABLE CUSTOMIZED_PROFILE -#endif }; static const int HIGH_SPEED_PROFILE_BLOCK_MODE = 67; // keep openSource type, example @@ -913,160 +896,4 @@ ASTCENC_PUBLIC astcenc_error astcenc_get_block_info( ASTCENC_PUBLIC const char* astcenc_get_error_string( astcenc_error status); -#ifdef ASTC_CUSTOMIZED_ENABLE -#if defined(_WIN32) && !defined(__CYGWIN__) -const LPCSTR g_astcCustomizedSo = "libastcCustomizedEncode.dll"; -#elif defined(BUILD_HMOS_SDK) -const std::string g_astcCustomizedSo = "libastcCustomizedEncode.so"; -#else -const std::string g_astcCustomizedSo = "/system/lib64/module/hms/graphic/libastcCustomizedEncode.z.so"; -#endif -using IsCustomizedBlockMode = bool (*)(const int); -using CustomizedMaxPartitions = int (*)(); -using CustomizedBlockMode = int (*)(); - -class AstcCustomizedSoManager -{ -public: - AstcCustomizedSoManager() - { - astcCustomizedSoOpened_ = false; - astcCustomizedSoHandle_ = nullptr; - isCustomizedBlockModeFunc_ = nullptr; - customizedMaxPartitionsFunc_ = nullptr; - customizedBlockModeFunc_ = nullptr; - } - ~AstcCustomizedSoManager() - { - if (!astcCustomizedSoOpened_ || astcCustomizedSoHandle_ == nullptr) - { - printf("astcenc customized so is not be opened when dlclose!\n"); - return; - } -#if defined(_WIN32) && !defined(__CYGWIN__) - if (!FreeLibrary(astcCustomizedSoHandle_)) - { - printf("astc dll FreeLibrary failed: %s\n", g_astcCustomizedSo); - } -#else - if (dlclose(astcCustomizedSoHandle_) != 0) - { - printf("astcenc so dlclose failed: %s\n", g_astcCustomizedSo.c_str()); - } -#endif - } - IsCustomizedBlockMode isCustomizedBlockModeFunc_; - CustomizedMaxPartitions customizedMaxPartitionsFunc_; - CustomizedBlockMode customizedBlockModeFunc_; - bool LoadSutCustomizedSo() - { - if (!astcCustomizedSoOpened_) - { -#if defined(_WIN32) && !defined(__CYGWIN__) - if ((_access(g_astcCustomizedSo, 0) == -1)) - { - printf("astc customized dll(%s) is not found!\n", g_astcCustomizedSo); - return false; - } - astcCustomizedSoHandle_ = LoadLibrary(g_astcCustomizedSo); - if (astcCustomizedSoHandle_ == nullptr) - { - printf("astc libAstcCustomizedEnc LoadLibrary failed!\n"); - return false; - } - isCustomizedBlockModeFunc_ = - reinterpret_cast(GetProcAddress(astcCustomizedSoHandle_, - "IsCustomizedBlockMode")); - if (isCustomizedBlockModeFunc_ == nullptr) - { - printf("astc isCustomizedBlockModeFunc_ GetProcAddress failed!\n"); - if (!FreeLibrary(astcCustomizedSoHandle_)) - { - printf("astc isCustomizedBlockModeFunc_ FreeLibrary failed!\n"); - } - return false; - } - customizedMaxPartitionsFunc_ = - reinterpret_cast(GetProcAddress(astcCustomizedSoHandle_, - "CustomizedMaxPartitions")); - if (customizedMaxPartitionsFunc_ == nullptr) - { - printf("astc customizedMaxPartitionsFunc_ GetProcAddress failed!\n"); - if (!FreeLibrary(astcCustomizedSoHandle_)) - { - printf("astc customizedMaxPartitionsFunc_ FreeLibrary failed!\n"); - } - return false; - } - customizedBlockModeFunc_ = - reinterpret_cast(GetProcAddress(astcCustomizedSoHandle_, - "CustomizedBlockMode")); - if (customizedBlockModeFunc_ == nullptr) - { - printf("astc customizedBlockModeFunc_ GetProcAddress failed!\n"); - if (!FreeLibrary(astcCustomizedSoHandle_)) - { - printf("astc customizedBlockModeFunc_ FreeLibrary failed!\n"); - } - return false; - } - printf("astcenc customized dll load success: %s!\n", g_astcCustomizedSo); -#else - if (access(g_astcCustomizedSo.c_str(), F_OK) == -1) - { - printf("astc customized so(%s) is not found!\n", g_astcCustomizedSo.c_str()); - return false; - } - astcCustomizedSoHandle_ = dlopen(g_astcCustomizedSo.c_str(), 1); - if (astcCustomizedSoHandle_ == nullptr) - { - printf("astc libAstcCustomizedEnc dlopen failed!\n"); - return false; - } - isCustomizedBlockModeFunc_ = - reinterpret_cast(dlsym(astcCustomizedSoHandle_, - "IsCustomizedBlockMode")); - if (isCustomizedBlockModeFunc_ == nullptr) - { - printf("astc isCustomizedBlockModeFunc_ dlsym failed!\n"); - dlclose(astcCustomizedSoHandle_); - astcCustomizedSoHandle_ = nullptr; - return false; - } - customizedMaxPartitionsFunc_ = - reinterpret_cast(dlsym(astcCustomizedSoHandle_, - "CustomizedMaxPartitions")); - if (customizedMaxPartitionsFunc_ == nullptr) - { - printf("astc customizedMaxPartitionsFunc_ dlsym failed!\n"); - dlclose(astcCustomizedSoHandle_); - astcCustomizedSoHandle_ = nullptr; - return false; - } - customizedBlockModeFunc_ = - reinterpret_cast(dlsym(astcCustomizedSoHandle_, - "CustomizedBlockMode")); - if (customizedBlockModeFunc_ == nullptr) - { - printf("astc customizedBlockModeFunc_ dlsym failed!\n"); - dlclose(astcCustomizedSoHandle_); - astcCustomizedSoHandle_ = nullptr; - return false; - } - printf("astcenc customized so dlopen success: %s\n", g_astcCustomizedSo.c_str()); -#endif - astcCustomizedSoOpened_ = true; - } - return true; - } -private: - bool astcCustomizedSoOpened_; -#if defined(_WIN32) && !defined(__CYGWIN__) - HINSTANCE astcCustomizedSoHandle_; -#else - void *astcCustomizedSoHandle_; -#endif -}; -extern AstcCustomizedSoManager g_astcCustomizedSoManager; -#endif #endif diff --git a/Source/astcenc_entry.cpp b/Source/astcenc_entry.cpp index 5a1ad96a212224ce5f0ccba105ef38740cfc3aa3..81f8f6bf342c30a16251dc58fbe2b93f8e53afc5 100644 --- a/Source/astcenc_entry.cpp +++ b/Source/astcenc_entry.cpp @@ -681,6 +681,13 @@ astcenc_error astcenc_context_alloc( } #endif +#ifndef ASTC_CUSTOMIZED_ENABLE + if (config.privateProfile == CUSTOMIZED_PROFILE) + { + return ASTCENC_ERR_BAD_PARAM; + } +#endif + astcenc_context* ctxo = new astcenc_context; astcenc_contexti* ctx = &ctxo->context; ctx->thread_count = thread_count; diff --git a/Source/astcenc_internal.h b/Source/astcenc_internal.h index 03a0b72d1e9491c34e9f70c6eda3a8686ada9ff3..bad12479acc07ab8546ce2693cce4e7780c34d9e 100644 --- a/Source/astcenc_internal.h +++ b/Source/astcenc_internal.h @@ -31,6 +31,18 @@ #include #include +#ifdef ASTC_CUSTOMIZED_ENABLE +#include +#include +#if defined(_WIN32) && !defined(__CYGWIN__) +#define NOMINMAX +#include +#include +#else +#include +#endif +#endif + #include "astcenc.h" #include "astcenc_mathlib.h" #include "astcenc_vecmathlib.h" @@ -2238,4 +2250,165 @@ void aligned_free(T* ptr) #endif } +#ifdef ASTC_CUSTOMIZED_ENABLE +#ifdef BUILD_HMOS_SDK +#if defined(_WIN32) && !defined(__CYGWIN__) +const LPCSTR g_astcCustomizedSo = "../../hms/toolchains/lib/libastcCustomizedEncode.dll"; +#elif defined(__APPLE__) +const std::string g_astcCustomizedSo = "../../hms/toolchains/lib/libastcCustomizedEncode.dylib"; +#else +const std::string g_astcCustomizedSo = "../../hms/toolchains/lib/libastcCustomizedEncode.so"; +#endif +#else +const std::string g_astcCustomizedSo = "/system/lib64/module/hms/graphic/libastcCustomizedEncode.z.so"; +#endif +using IsCustomizedBlockMode = bool (*)(const int); +using CustomizedMaxPartitions = int (*)(); +using CustomizedBlockMode = int (*)(); + +class AstcCustomizedSoManager +{ +public: + AstcCustomizedSoManager() + { + astcCustomizedSoOpened_ = false; + astcCustomizedSoHandle_ = nullptr; + isCustomizedBlockModeFunc_ = nullptr; + customizedMaxPartitionsFunc_ = nullptr; + customizedBlockModeFunc_ = nullptr; + } + ~AstcCustomizedSoManager() + { + if (!astcCustomizedSoOpened_ || astcCustomizedSoHandle_ == nullptr) + { + printf("astcenc customized so is not be opened when dlclose!\n"); + return; + } +#if defined(_WIN32) && !defined(__CYGWIN__) + if (!FreeLibrary(astcCustomizedSoHandle_)) + { + printf("astc dll FreeLibrary failed: %s\n", g_astcCustomizedSo); + } +#else + if (dlclose(astcCustomizedSoHandle_) != 0) + { + printf("astcenc so dlclose failed: %s\n", g_astcCustomizedSo.c_str()); + } +#endif + } + IsCustomizedBlockMode isCustomizedBlockModeFunc_; + CustomizedMaxPartitions customizedMaxPartitionsFunc_; + CustomizedBlockMode customizedBlockModeFunc_; + bool LoadSutCustomizedSo() + { + if (!astcCustomizedSoOpened_) + { +#if defined(_WIN32) && !defined(__CYGWIN__) + if ((_access(g_astcCustomizedSo, 0) == -1)) + { + printf("astc customized dll(%s) is not found!\n", g_astcCustomizedSo); + return false; + } + astcCustomizedSoHandle_ = LoadLibrary(g_astcCustomizedSo); + if (astcCustomizedSoHandle_ == nullptr) + { + printf("astc libAstcCustomizedEnc LoadLibrary failed!\n"); + return false; + } + isCustomizedBlockModeFunc_ = + reinterpret_cast(GetProcAddress(astcCustomizedSoHandle_, + "IsCustomizedBlockMode")); + if (isCustomizedBlockModeFunc_ == nullptr) + { + printf("astc isCustomizedBlockModeFunc_ GetProcAddress failed!\n"); + if (!FreeLibrary(astcCustomizedSoHandle_)) + { + printf("astc isCustomizedBlockModeFunc_ FreeLibrary failed!\n"); + } + return false; + } + customizedMaxPartitionsFunc_ = + reinterpret_cast(GetProcAddress(astcCustomizedSoHandle_, + "CustomizedMaxPartitions")); + if (customizedMaxPartitionsFunc_ == nullptr) + { + printf("astc customizedMaxPartitionsFunc_ GetProcAddress failed!\n"); + if (!FreeLibrary(astcCustomizedSoHandle_)) + { + printf("astc customizedMaxPartitionsFunc_ FreeLibrary failed!\n"); + } + return false; + } + customizedBlockModeFunc_ = + reinterpret_cast(GetProcAddress(astcCustomizedSoHandle_, + "CustomizedBlockMode")); + if (customizedBlockModeFunc_ == nullptr) + { + printf("astc customizedBlockModeFunc_ GetProcAddress failed!\n"); + if (!FreeLibrary(astcCustomizedSoHandle_)) + { + printf("astc customizedBlockModeFunc_ FreeLibrary failed!\n"); + } + return false; + } + printf("astcenc customized dll load success: %s!\n", g_astcCustomizedSo); +#else + if (access(g_astcCustomizedSo.c_str(), F_OK) == -1) + { + printf("astc customized so(%s) is not found!\n", g_astcCustomizedSo.c_str()); + return false; + } + astcCustomizedSoHandle_ = dlopen(g_astcCustomizedSo.c_str(), 1); + if (astcCustomizedSoHandle_ == nullptr) + { + printf("astc libAstcCustomizedEnc dlopen failed!\n"); + return false; + } + isCustomizedBlockModeFunc_ = + reinterpret_cast(dlsym(astcCustomizedSoHandle_, + "IsCustomizedBlockMode")); + if (isCustomizedBlockModeFunc_ == nullptr) + { + printf("astc isCustomizedBlockModeFunc_ dlsym failed!\n"); + dlclose(astcCustomizedSoHandle_); + astcCustomizedSoHandle_ = nullptr; + return false; + } + customizedMaxPartitionsFunc_ = + reinterpret_cast(dlsym(astcCustomizedSoHandle_, + "CustomizedMaxPartitions")); + if (customizedMaxPartitionsFunc_ == nullptr) + { + printf("astc customizedMaxPartitionsFunc_ dlsym failed!\n"); + dlclose(astcCustomizedSoHandle_); + astcCustomizedSoHandle_ = nullptr; + return false; + } + customizedBlockModeFunc_ = + reinterpret_cast(dlsym(astcCustomizedSoHandle_, + "CustomizedBlockMode")); + if (customizedBlockModeFunc_ == nullptr) + { + printf("astc customizedBlockModeFunc_ dlsym failed!\n"); + dlclose(astcCustomizedSoHandle_); + astcCustomizedSoHandle_ = nullptr; + return false; + } + printf("astcenc customized so dlopen success: %s\n", g_astcCustomizedSo.c_str()); +#endif + astcCustomizedSoOpened_ = true; + } + return true; + } +private: + bool astcCustomizedSoOpened_; +#if defined(_WIN32) && !defined(__CYGWIN__) + HINSTANCE astcCustomizedSoHandle_; +#else + void *astcCustomizedSoHandle_; +#endif +}; +extern AstcCustomizedSoManager g_astcCustomizedSoManager; +#endif + #endif