mirror of
https://github.com/openharmony/developtools_global_resource_tool.git
synced 2026-07-19 11:31:44 -04:00
@@ -51,7 +51,7 @@ struct TranscodeResult {
|
||||
int32_t height;
|
||||
};
|
||||
|
||||
typedef TranscodeError (*ITranscodeImages) (const std::string &imagePath,
|
||||
typedef TranscodeError (*ITranscodeImages) (const std::string &imagePath, const bool extAppend,
|
||||
std::string &outputPath, TranscodeResult &result);
|
||||
typedef bool (*ISetTranscodeOptions) (const std::string &optionJson);
|
||||
|
||||
@@ -63,7 +63,7 @@ public:
|
||||
explicit CompressionParser(const std::string &filePath);
|
||||
virtual ~CompressionParser();
|
||||
uint32_t Init();
|
||||
bool CopyAndTranscode(const std::string &src, std::string &dst);
|
||||
bool CopyAndTranscode(const std::string &src, std::string &dst, const bool extAppend = false);
|
||||
bool GetMediaSwitch();
|
||||
std::string PrintTransMessage();
|
||||
bool GetDefaultCompress();
|
||||
@@ -73,7 +73,8 @@ private:
|
||||
bool ParseFilters(const cJSON *filtersNode);
|
||||
bool LoadImageTranscoder();
|
||||
bool SetTranscodeOptions(const std::string &optionJson);
|
||||
TranscodeError TranscodeImages(const std::string &imagePath, std::string &outputPath, TranscodeResult &result);
|
||||
TranscodeError TranscodeImages(const std::string &imagePath, const bool extAppend,
|
||||
std::string &outputPath, TranscodeResult &result);
|
||||
std::vector<std::string> ParsePath(const cJSON *pathNode);
|
||||
std::vector<std::string> ParseRules(const cJSON *rulesNode);
|
||||
std::string ParseJsonStr(const cJSON *node);
|
||||
@@ -86,7 +87,7 @@ private:
|
||||
TranscodeResult &result);
|
||||
std::string GetOptionsString(const std::shared_ptr<CompressFilter> &compressFilter, int type);
|
||||
bool CheckAndTranscode(const std::string &src, std::string &dst, std::string &output,
|
||||
const std::shared_ptr<CompressFilter> &compressFilter);
|
||||
const std::shared_ptr<CompressFilter> &compressFilter, const bool extAppend);
|
||||
bool IsDefaultCompress();
|
||||
std::string filePath_;
|
||||
std::string extensionPath_;
|
||||
|
||||
+19
-18
@@ -237,7 +237,7 @@ vector<string> CompressionParser::ParseRules(const cJSON *rulesNode)
|
||||
{
|
||||
vector<string> res;
|
||||
if (!rulesNode || !cJSON_IsObject(rulesNode)) {
|
||||
cerr << "Warning: rules is not exist." << endl;
|
||||
cout << "Warning: rules is not exist." << endl;
|
||||
return res;
|
||||
}
|
||||
for (cJSON *item = rulesNode->child; item; item = item->next) {
|
||||
@@ -254,7 +254,7 @@ vector<string> CompressionParser::ParsePath(const cJSON *pathNode)
|
||||
{
|
||||
vector<string> res;
|
||||
if (!pathNode || !cJSON_IsArray(pathNode)) {
|
||||
cerr << "Warning: path is not exist." << endl;
|
||||
cout << "Warning: path is not exist." << endl;
|
||||
return res;
|
||||
}
|
||||
for (cJSON *item = pathNode->child; item; item = item->next) {
|
||||
@@ -304,7 +304,7 @@ bool CompressionParser::LoadImageTranscoder()
|
||||
bool CompressionParser::SetTranscodeOptions(const string &optionJson)
|
||||
{
|
||||
if (!handle_) {
|
||||
cerr << "Warning: SetTranscodeOptions handle_ is nullptr." << endl;
|
||||
cout << "Warning: SetTranscodeOptions handle_ is nullptr." << endl;
|
||||
return false;
|
||||
}
|
||||
#ifdef __WIN32
|
||||
@@ -313,21 +313,22 @@ bool CompressionParser::SetTranscodeOptions(const string &optionJson)
|
||||
ISetTranscodeOptions iSetTranscodeOptions = (ISetTranscodeOptions)dlsym(handle_, "SetTranscodeOptions");
|
||||
#endif
|
||||
if (!iSetTranscodeOptions) {
|
||||
cerr << "Warning: Failed to get the 'SetTranscodeOptions'." << endl;
|
||||
cout << "Warning: Failed to get the 'SetTranscodeOptions'." << endl;
|
||||
return false;
|
||||
}
|
||||
bool ret = (*iSetTranscodeOptions)(optionJson);
|
||||
if (!ret) {
|
||||
cerr << "Warning: SetTranscodeOptions failed." << endl;
|
||||
cout << "Warning: SetTranscodeOptions failed." << endl;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
TranscodeError CompressionParser::TranscodeImages(const string &imagePath, string &outputPath, TranscodeResult &result)
|
||||
TranscodeError CompressionParser::TranscodeImages(const string &imagePath, const bool extAppend,
|
||||
string &outputPath, TranscodeResult &result)
|
||||
{
|
||||
if (!handle_) {
|
||||
cerr << "Warning: TranscodeImages handle_ is nullptr." << endl;
|
||||
cout << "Warning: TranscodeImages handle_ is nullptr." << endl;
|
||||
return TranscodeError::LOAD_COMPRESS_FAILED;
|
||||
}
|
||||
#ifdef __WIN32
|
||||
@@ -336,17 +337,17 @@ TranscodeError CompressionParser::TranscodeImages(const string &imagePath, strin
|
||||
ITranscodeImages iTranscodeImages = (ITranscodeImages)dlsym(handle_, "Transcode");
|
||||
#endif
|
||||
if (!iTranscodeImages) {
|
||||
cerr << "Warning: Failed to get the 'Transcode'." << endl;
|
||||
cout << "Warning: Failed to get the 'Transcode'." << endl;
|
||||
return TranscodeError::LOAD_COMPRESS_FAILED;
|
||||
}
|
||||
TranscodeError ret = (*iTranscodeImages)(imagePath, outputPath, result);
|
||||
TranscodeError ret = (*iTranscodeImages)(imagePath, extAppend, outputPath, result);
|
||||
if (ret != TranscodeError::SUCCESS) {
|
||||
auto iter = ERRORCODEMAP.find(ret);
|
||||
if (iter != ERRORCODEMAP.end()) {
|
||||
cerr << "Warning: TranscodeImages failed, error message: " << iter->second << ", file path = " <<
|
||||
cout << "Warning: TranscodeImages failed, error message: " << iter->second << ", file path = " <<
|
||||
imagePath << endl;
|
||||
} else {
|
||||
cerr << "Warning: TranscodeImages failed" << ", file path = " << imagePath << endl;
|
||||
cout << "Warning: TranscodeImages failed" << ", file path = " << imagePath << endl;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -457,7 +458,7 @@ bool CompressionParser::GetDefaultCompress()
|
||||
}
|
||||
|
||||
bool CompressionParser::CheckAndTranscode(const string &src, string &dst, string &output,
|
||||
const shared_ptr<CompressFilter> &compressFilter)
|
||||
const shared_ptr<CompressFilter> &compressFilter, const bool extAppend)
|
||||
{
|
||||
auto t1 = std::chrono::steady_clock::now();
|
||||
TranscodeResult result = {0, 0, 0, 0};
|
||||
@@ -465,7 +466,7 @@ bool CompressionParser::CheckAndTranscode(const string &src, string &dst, string
|
||||
if (!SetTranscodeOptions(GetOptionsString(compressFilter, OPT_TYPE_ONE))) {
|
||||
return false;
|
||||
}
|
||||
auto res = TranscodeImages(src, output, result);
|
||||
auto res = TranscodeImages(src, extAppend, output, result);
|
||||
CollectTimeAndSize(res, t1, result);
|
||||
if (res != TranscodeError::SUCCESS) {
|
||||
return false;
|
||||
@@ -480,7 +481,7 @@ bool CompressionParser::CheckAndTranscode(const string &src, string &dst, string
|
||||
if (!SetTranscodeOptions(GetOptionsString(compressFilter, OPT_TYPE_ONE))) {
|
||||
return false;
|
||||
}
|
||||
auto res = TranscodeImages(src, output, result);
|
||||
auto res = TranscodeImages(src, extAppend, output, result);
|
||||
CollectTimeAndSize(res, t1, result);
|
||||
if (res != TranscodeError::SUCCESS) {
|
||||
return false;
|
||||
@@ -489,7 +490,7 @@ bool CompressionParser::CheckAndTranscode(const string &src, string &dst, string
|
||||
return true;
|
||||
}
|
||||
if (SetTranscodeOptions(GetOptionsString(compressFilter, OPT_TYPE_THREE))) {
|
||||
auto res = TranscodeImages(src, output, result);
|
||||
auto res = TranscodeImages(src, extAppend, output, result);
|
||||
CollectTimeAndSize(res, t1, result);
|
||||
if (res == TranscodeError::SUCCESS) {
|
||||
dst = output;
|
||||
@@ -497,7 +498,7 @@ bool CompressionParser::CheckAndTranscode(const string &src, string &dst, string
|
||||
}
|
||||
}
|
||||
if (SetTranscodeOptions(GetOptionsString(compressFilter, OPT_TYPE_TWO))) {
|
||||
auto res = TranscodeImages(src, output, result);
|
||||
auto res = TranscodeImages(src, extAppend, output, result);
|
||||
CollectTimeAndSize(res, t1, result);
|
||||
if (res == TranscodeError::SUCCESS) {
|
||||
dst = output;
|
||||
@@ -507,7 +508,7 @@ bool CompressionParser::CheckAndTranscode(const string &src, string &dst, string
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CompressionParser::CopyAndTranscode(const string &src, string &dst)
|
||||
bool CompressionParser::CopyAndTranscode(const string &src, string &dst, const bool extAppend)
|
||||
{
|
||||
auto t0 = std::chrono::steady_clock::now();
|
||||
if (!mediaSwitch_) {
|
||||
@@ -523,7 +524,7 @@ bool CompressionParser::CopyAndTranscode(const string &src, string &dst)
|
||||
}
|
||||
string output = dst.substr(0, index);
|
||||
for (const auto &compressFilter : compressFilters_) {
|
||||
if (!CheckAndTranscode(src, dst, output, compressFilter)) {
|
||||
if (!CheckAndTranscode(src, dst, output, compressFilter, extAppend)) {
|
||||
continue;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -319,7 +319,7 @@ uint32_t ResourcePack::CopyRawFileOrResFileImpl(const string &src, const string
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (!CompressionParser::GetCompressionParser()->CopyAndTranscode(path, subPath)) {
|
||||
if (!CompressionParser::GetCompressionParser()->CopyAndTranscode(path, subPath, true)) {
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user