1e9297d28Sopenharmony_ci/* 2e9297d28Sopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd. 3e9297d28Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4e9297d28Sopenharmony_ci * you may not use this file except in compliance with the License. 5e9297d28Sopenharmony_ci * You may obtain a copy of the License at 6e9297d28Sopenharmony_ci * 7e9297d28Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8e9297d28Sopenharmony_ci * 9e9297d28Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10e9297d28Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11e9297d28Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12e9297d28Sopenharmony_ci * See the License for the specific language governing permissions and 13e9297d28Sopenharmony_ci * limitations under the License. 14e9297d28Sopenharmony_ci */ 15e9297d28Sopenharmony_ci 16e9297d28Sopenharmony_ci#include "util.h" 17e9297d28Sopenharmony_ci 18e9297d28Sopenharmony_ci#include <event_handler.h> 19e9297d28Sopenharmony_ci#include <fstream> 20e9297d28Sopenharmony_ci#include <securec.h> 21e9297d28Sopenharmony_ci#include <sstream> 22e9297d28Sopenharmony_ci 23e9297d28Sopenharmony_cinamespace OHOS { 24e9297d28Sopenharmony_ciconstexpr const float HALF = 2.0; 25e9297d28Sopenharmony_ciconstexpr const float RADIO = 360.0; 26e9297d28Sopenharmony_ci 27e9297d28Sopenharmony_civoid PostTask(std::function<void()> func, uint32_t delayTime) 28e9297d28Sopenharmony_ci{ 29e9297d28Sopenharmony_ci auto handler = AppExecFwk::EventHandler::Current(); 30e9297d28Sopenharmony_ci if (handler) { 31e9297d28Sopenharmony_ci handler->PostTask(func, delayTime); 32e9297d28Sopenharmony_ci } 33e9297d28Sopenharmony_ci} 34e9297d28Sopenharmony_ci 35e9297d28Sopenharmony_cibool IsFileExisted(const std::string& filePath) 36e9297d28Sopenharmony_ci{ 37e9297d28Sopenharmony_ci if (filePath.empty()) { 38e9297d28Sopenharmony_ci LOGE("check filepath is empty"); 39e9297d28Sopenharmony_ci return false; 40e9297d28Sopenharmony_ci } 41e9297d28Sopenharmony_ci char newpath[PATH_MAX + 1] = { 0x00 }; 42e9297d28Sopenharmony_ci if (strlen(filePath.c_str()) > PATH_MAX || realpath(filePath.c_str(), newpath) == nullptr) { 43e9297d28Sopenharmony_ci LOGE("check filepath fail! %{public}s %{public}d %{public}s", filePath.c_str(), errno, ::strerror(errno)); 44e9297d28Sopenharmony_ci return false; 45e9297d28Sopenharmony_ci } 46e9297d28Sopenharmony_ci struct stat info = {0}; 47e9297d28Sopenharmony_ci if (stat(newpath, &info) != 0) { 48e9297d28Sopenharmony_ci LOGE("stat filepath fail! %{public}s %{public}d %{public}s", filePath.c_str(), errno, ::strerror(errno)); 49e9297d28Sopenharmony_ci return false; 50e9297d28Sopenharmony_ci } 51e9297d28Sopenharmony_ci return true; 52e9297d28Sopenharmony_ci} 53e9297d28Sopenharmony_ci 54e9297d28Sopenharmony_cibool ParseBootConfig(const std::string& path, int32_t& duration, bool& isCompatible, bool& isMultiDisplay, 55e9297d28Sopenharmony_ci std::vector<BootAnimationConfig>& configs) 56e9297d28Sopenharmony_ci{ 57e9297d28Sopenharmony_ci char newpath[PATH_MAX + 1] = { 0x00 }; 58e9297d28Sopenharmony_ci if (strlen(path.c_str()) > PATH_MAX || realpath(path.c_str(), newpath) == nullptr) { 59e9297d28Sopenharmony_ci LOGE("check config path fail! %{public}s %{public}d %{public}s", path.c_str(), errno, ::strerror(errno)); 60e9297d28Sopenharmony_ci return false; 61e9297d28Sopenharmony_ci } 62e9297d28Sopenharmony_ci 63e9297d28Sopenharmony_ci std::ifstream configFile; 64e9297d28Sopenharmony_ci configFile.open(newpath); 65e9297d28Sopenharmony_ci std::stringstream JFilterParamsStream; 66e9297d28Sopenharmony_ci JFilterParamsStream << configFile.rdbuf(); 67e9297d28Sopenharmony_ci configFile.close(); 68e9297d28Sopenharmony_ci std::string JParamsString = JFilterParamsStream.str(); 69e9297d28Sopenharmony_ci 70e9297d28Sopenharmony_ci cJSON* overallData = cJSON_Parse(JParamsString.c_str()); 71e9297d28Sopenharmony_ci if (overallData == nullptr) { 72e9297d28Sopenharmony_ci LOGE("can not parse config to json"); 73e9297d28Sopenharmony_ci return false; 74e9297d28Sopenharmony_ci } 75e9297d28Sopenharmony_ci cJSON_bool isNewConfig = cJSON_HasObjectItem(overallData, "screen_config"); 76e9297d28Sopenharmony_ci if (!isNewConfig) { 77e9297d28Sopenharmony_ci isCompatible = true; 78e9297d28Sopenharmony_ci ParseOldConfigFile(overallData, configs); 79e9297d28Sopenharmony_ci } else { 80e9297d28Sopenharmony_ci ParseNewConfigFile(overallData, isMultiDisplay, configs); 81e9297d28Sopenharmony_ci } 82e9297d28Sopenharmony_ci ParseBootDuration(overallData, duration); 83e9297d28Sopenharmony_ci cJSON_Delete(overallData); 84e9297d28Sopenharmony_ci return true; 85e9297d28Sopenharmony_ci} 86e9297d28Sopenharmony_ci 87e9297d28Sopenharmony_civoid ParseOldConfigFile(cJSON* data, std::vector<BootAnimationConfig>& configs) 88e9297d28Sopenharmony_ci{ 89e9297d28Sopenharmony_ci LOGD("ParseOldConfigFile"); 90e9297d28Sopenharmony_ci BootAnimationConfig config; 91e9297d28Sopenharmony_ci cJSON* custPicPath = cJSON_GetObjectItem(data, "cust.bootanimation.pics"); 92e9297d28Sopenharmony_ci if (custPicPath != nullptr && cJSON_IsString(custPicPath)) { 93e9297d28Sopenharmony_ci config.picZipPath = custPicPath->valuestring; 94e9297d28Sopenharmony_ci LOGI("cust piczip path: %{public}s", config.picZipPath.c_str()); 95e9297d28Sopenharmony_ci } 96e9297d28Sopenharmony_ci cJSON* custSoundPath = cJSON_GetObjectItem(data, "cust.bootanimation.sounds"); 97e9297d28Sopenharmony_ci if (custSoundPath != nullptr && cJSON_IsString(custSoundPath)) { 98e9297d28Sopenharmony_ci config.soundPath = custSoundPath->valuestring; 99e9297d28Sopenharmony_ci LOGI("cust sound path: %{public}s", config.soundPath.c_str()); 100e9297d28Sopenharmony_ci } 101e9297d28Sopenharmony_ci cJSON* custVideoDefaultPath = cJSON_GetObjectItem(data, "cust.bootanimation.video"); 102e9297d28Sopenharmony_ci if (custVideoDefaultPath != nullptr && cJSON_IsString(custVideoDefaultPath)) { 103e9297d28Sopenharmony_ci config.videoDefaultPath = custVideoDefaultPath->valuestring; 104e9297d28Sopenharmony_ci LOGI("cust video path: %{public}s", config.videoDefaultPath.c_str()); 105e9297d28Sopenharmony_ci } 106e9297d28Sopenharmony_ci cJSON* custVideoExtraPath = cJSON_GetObjectItem(data, "cust.bootanimation.video.extra"); 107e9297d28Sopenharmony_ci if (custVideoExtraPath != nullptr && cJSON_IsString(custVideoExtraPath)) { 108e9297d28Sopenharmony_ci config.videoExtraPath = custVideoExtraPath->valuestring; 109e9297d28Sopenharmony_ci LOGI("cust extra video path: %{public}s", config.videoExtraPath.c_str()); 110e9297d28Sopenharmony_ci } 111e9297d28Sopenharmony_ci cJSON* rotateScreenJson = cJSON_GetObjectItem(data, "cust.bootanimation.rotate.screenid"); 112e9297d28Sopenharmony_ci if (rotateScreenJson != nullptr && cJSON_IsString(rotateScreenJson)) { 113e9297d28Sopenharmony_ci config.rotateScreenId = std::atoi(rotateScreenJson->valuestring); 114e9297d28Sopenharmony_ci LOGI("cust rotateScreenId: %{public}d", config.rotateScreenId); 115e9297d28Sopenharmony_ci } 116e9297d28Sopenharmony_ci cJSON* rotateDegreeJson = cJSON_GetObjectItem(data, "cust.bootanimation.rotate.degree"); 117e9297d28Sopenharmony_ci if (rotateDegreeJson != nullptr && cJSON_IsString(rotateDegreeJson)) { 118e9297d28Sopenharmony_ci config.rotateDegree = std::atoi(rotateDegreeJson->valuestring); 119e9297d28Sopenharmony_ci LOGI("cust rotateDegree: %{public}d", config.rotateDegree); 120e9297d28Sopenharmony_ci } 121e9297d28Sopenharmony_ci configs.emplace_back(config); 122e9297d28Sopenharmony_ci} 123e9297d28Sopenharmony_ci 124e9297d28Sopenharmony_civoid ParseNewConfigFile(cJSON* data, bool& isMultiDisplay, std::vector<BootAnimationConfig>& configs) 125e9297d28Sopenharmony_ci{ 126e9297d28Sopenharmony_ci LOGD("ParseNewConfigFile"); 127e9297d28Sopenharmony_ci cJSON* isSupport = cJSON_GetObjectItem(data, "cust.bootanimation.multi_display"); 128e9297d28Sopenharmony_ci if (isSupport != nullptr && cJSON_IsBool(isSupport)) { 129e9297d28Sopenharmony_ci if (cJSON_IsTrue(isSupport)) { 130e9297d28Sopenharmony_ci isMultiDisplay = true; 131e9297d28Sopenharmony_ci } 132e9297d28Sopenharmony_ci } 133e9297d28Sopenharmony_ci LOGI("isMultiDisplay: %{public}d", isMultiDisplay); 134e9297d28Sopenharmony_ci 135e9297d28Sopenharmony_ci cJSON* screens = cJSON_GetObjectItem(data, "screen_config"); 136e9297d28Sopenharmony_ci if (screens != nullptr) { 137e9297d28Sopenharmony_ci BootAnimationConfig config; 138e9297d28Sopenharmony_ci cJSON* item = screens->child; 139e9297d28Sopenharmony_ci while (item != nullptr) { 140e9297d28Sopenharmony_ci cJSON* screenIdJson = cJSON_GetObjectItem(item, "cust.bootanimation.screen_id"); 141e9297d28Sopenharmony_ci if (screenIdJson != nullptr && cJSON_IsString(screenIdJson)) { 142e9297d28Sopenharmony_ci config.screenId = std::strtoul(screenIdJson->valuestring, nullptr, 0); 143e9297d28Sopenharmony_ci LOGI("screenId: " BPUBU64 "", config.screenId); 144e9297d28Sopenharmony_ci } 145e9297d28Sopenharmony_ci cJSON* custPicPath = cJSON_GetObjectItem(item, "cust.bootanimation.pics"); 146e9297d28Sopenharmony_ci if (custPicPath != nullptr && cJSON_IsString(custPicPath)) { 147e9297d28Sopenharmony_ci config.picZipPath = custPicPath->valuestring; 148e9297d28Sopenharmony_ci LOGI("cust piczip path: %{public}s", config.picZipPath.c_str()); 149e9297d28Sopenharmony_ci } 150e9297d28Sopenharmony_ci cJSON* custSoundPath = cJSON_GetObjectItem(item, "cust.bootanimation.sounds"); 151e9297d28Sopenharmony_ci if (custSoundPath != nullptr && cJSON_IsString(custSoundPath)) { 152e9297d28Sopenharmony_ci config.soundPath = custSoundPath->valuestring; 153e9297d28Sopenharmony_ci LOGI("cust sound path: %{public}s", config.soundPath.c_str()); 154e9297d28Sopenharmony_ci } 155e9297d28Sopenharmony_ci cJSON* custVideoDefaultPath = cJSON_GetObjectItem(item, "cust.bootanimation.video_default"); 156e9297d28Sopenharmony_ci if (custVideoDefaultPath != nullptr && cJSON_IsString(custVideoDefaultPath)) { 157e9297d28Sopenharmony_ci config.videoDefaultPath = custVideoDefaultPath->valuestring; 158e9297d28Sopenharmony_ci LOGI("cust default video path: %{public}s", config.videoDefaultPath.c_str()); 159e9297d28Sopenharmony_ci } 160e9297d28Sopenharmony_ci cJSON* rotateDegreeJson = cJSON_GetObjectItem(item, "cust.bootanimation.rotate_degree"); 161e9297d28Sopenharmony_ci if (rotateDegreeJson != nullptr && cJSON_IsString(rotateDegreeJson)) { 162e9297d28Sopenharmony_ci config.rotateDegree = std::atoi(rotateDegreeJson->valuestring); 163e9297d28Sopenharmony_ci LOGI("cust rotateDegree: %{public}d", config.rotateDegree); 164e9297d28Sopenharmony_ci } 165e9297d28Sopenharmony_ci cJSON* extraVideoPath = cJSON_GetObjectItem(item, "cust.bootanimation.video_extensions"); 166e9297d28Sopenharmony_ci if (extraVideoPath != nullptr && cJSON_IsArray(extraVideoPath)) { 167e9297d28Sopenharmony_ci ParseVideoExtraPath(extraVideoPath, config); 168e9297d28Sopenharmony_ci } 169e9297d28Sopenharmony_ci configs.emplace_back(config); 170e9297d28Sopenharmony_ci item = item->next; 171e9297d28Sopenharmony_ci } 172e9297d28Sopenharmony_ci } 173e9297d28Sopenharmony_ci} 174e9297d28Sopenharmony_ci 175e9297d28Sopenharmony_civoid ParseVideoExtraPath(cJSON* data, BootAnimationConfig& config) 176e9297d28Sopenharmony_ci{ 177e9297d28Sopenharmony_ci int size = cJSON_GetArraySize(data); 178e9297d28Sopenharmony_ci for (int index = 0; index < size; index++) { 179e9297d28Sopenharmony_ci cJSON* extraPath = cJSON_GetArrayItem(data, index); 180e9297d28Sopenharmony_ci if (extraPath != nullptr && cJSON_IsString(extraPath)) { 181e9297d28Sopenharmony_ci config.videoExtPath.emplace_back(extraPath->valuestring); 182e9297d28Sopenharmony_ci } 183e9297d28Sopenharmony_ci } 184e9297d28Sopenharmony_ci} 185e9297d28Sopenharmony_ci 186e9297d28Sopenharmony_civoid ParseBootDuration(cJSON* data, int32_t& duration) 187e9297d28Sopenharmony_ci{ 188e9297d28Sopenharmony_ci cJSON* durationJson = cJSON_GetObjectItem(data, "cust.bootanimation.duration"); 189e9297d28Sopenharmony_ci if (durationJson != nullptr && cJSON_IsString(durationJson)) { 190e9297d28Sopenharmony_ci duration = std::atoi(durationJson->valuestring); 191e9297d28Sopenharmony_ci LOGI("cust duration: %{public}d", duration); 192e9297d28Sopenharmony_ci } 193e9297d28Sopenharmony_ci} 194e9297d28Sopenharmony_ci 195e9297d28Sopenharmony_cibool ReadZipFile(const std::string& srcFilePath, ImageStructVec& imgVec, FrameRateConfig& frameConfig) 196e9297d28Sopenharmony_ci{ 197e9297d28Sopenharmony_ci unzFile zipFile = unzOpen2(srcFilePath.c_str(), nullptr); 198e9297d28Sopenharmony_ci if (zipFile == nullptr) { 199e9297d28Sopenharmony_ci LOGE("Open zipFile fail: %{public}s", srcFilePath.c_str()); 200e9297d28Sopenharmony_ci return false; 201e9297d28Sopenharmony_ci } 202e9297d28Sopenharmony_ci 203e9297d28Sopenharmony_ci unz_global_info globalInfo; 204e9297d28Sopenharmony_ci if (unzGetGlobalInfo(zipFile, &globalInfo) != UNZ_OK) { 205e9297d28Sopenharmony_ci LOGE("Get ZipGlobalInfo fail"); 206e9297d28Sopenharmony_ci return CloseZipFile(zipFile, false); 207e9297d28Sopenharmony_ci } 208e9297d28Sopenharmony_ci 209e9297d28Sopenharmony_ci LOGD("read zip file num: %{public}ld", globalInfo.number_entry); 210e9297d28Sopenharmony_ci for (unsigned long i = 0; i < globalInfo.number_entry; ++i) { 211e9297d28Sopenharmony_ci unz_file_info fileInfo; 212e9297d28Sopenharmony_ci char filename[MAX_FILE_NAME] = {0}; 213e9297d28Sopenharmony_ci if (unzGetCurrentFileInfo(zipFile, &fileInfo, filename, MAX_FILE_NAME, nullptr, 0, nullptr, 0) != UNZ_OK) { 214e9297d28Sopenharmony_ci return CloseZipFile(zipFile, false); 215e9297d28Sopenharmony_ci } 216e9297d28Sopenharmony_ci size_t length = strlen(filename); 217e9297d28Sopenharmony_ci if (length > MAX_FILE_NAME || length == 0) { 218e9297d28Sopenharmony_ci return CloseZipFile(zipFile, false); 219e9297d28Sopenharmony_ci } 220e9297d28Sopenharmony_ci if (filename[length - 1] != '/') { 221e9297d28Sopenharmony_ci if (unzOpenCurrentFile(zipFile) != UNZ_OK) { 222e9297d28Sopenharmony_ci return CloseZipFile(zipFile, false); 223e9297d28Sopenharmony_ci } 224e9297d28Sopenharmony_ci std::string name = std::string(filename); 225e9297d28Sopenharmony_ci size_t npos = name.find_last_of("//"); 226e9297d28Sopenharmony_ci if (npos != std::string::npos) { 227e9297d28Sopenharmony_ci name = name.substr(npos + 1, name.length()); 228e9297d28Sopenharmony_ci } 229e9297d28Sopenharmony_ci if (!ReadImageFile(zipFile, name, imgVec, frameConfig, fileInfo.uncompressed_size)) { 230e9297d28Sopenharmony_ci LOGE("read zip deal single file failed"); 231e9297d28Sopenharmony_ci unzCloseCurrentFile(zipFile); 232e9297d28Sopenharmony_ci return CloseZipFile(zipFile, false); 233e9297d28Sopenharmony_ci } 234e9297d28Sopenharmony_ci unzCloseCurrentFile(zipFile); 235e9297d28Sopenharmony_ci } 236e9297d28Sopenharmony_ci if (i < (globalInfo.number_entry - 1)) { 237e9297d28Sopenharmony_ci if (unzGoToNextFile(zipFile) != UNZ_OK) { 238e9297d28Sopenharmony_ci return CloseZipFile(zipFile, false); 239e9297d28Sopenharmony_ci } 240e9297d28Sopenharmony_ci } 241e9297d28Sopenharmony_ci } 242e9297d28Sopenharmony_ci return CloseZipFile(zipFile, true); 243e9297d28Sopenharmony_ci} 244e9297d28Sopenharmony_ci 245e9297d28Sopenharmony_cibool CloseZipFile(const unzFile zipFile, bool ret) 246e9297d28Sopenharmony_ci{ 247e9297d28Sopenharmony_ci unzClose(zipFile); 248e9297d28Sopenharmony_ci return ret; 249e9297d28Sopenharmony_ci} 250e9297d28Sopenharmony_ci 251e9297d28Sopenharmony_civoid SortZipFile(ImageStructVec& imgVec) 252e9297d28Sopenharmony_ci{ 253e9297d28Sopenharmony_ci if (imgVec.size() == 0) { 254e9297d28Sopenharmony_ci return; 255e9297d28Sopenharmony_ci } 256e9297d28Sopenharmony_ci 257e9297d28Sopenharmony_ci sort(imgVec.begin(), imgVec.end(), [](std::shared_ptr<ImageStruct> image1, 258e9297d28Sopenharmony_ci std::shared_ptr<ImageStruct> image2) 259e9297d28Sopenharmony_ci -> bool {return image1->fileName < image2->fileName;}); 260e9297d28Sopenharmony_ci} 261e9297d28Sopenharmony_ci 262e9297d28Sopenharmony_cibool ReadImageFile(const unzFile zipFile, const std::string& fileName, ImageStructVec& imgVec, 263e9297d28Sopenharmony_ci FrameRateConfig& frameConfig, unsigned long fileSize) 264e9297d28Sopenharmony_ci{ 265e9297d28Sopenharmony_ci if (zipFile == nullptr) { 266e9297d28Sopenharmony_ci LOGE("ReadImageFile failed, zip is null"); 267e9297d28Sopenharmony_ci return false; 268e9297d28Sopenharmony_ci } 269e9297d28Sopenharmony_ci int readLen = UNZ_OK; 270e9297d28Sopenharmony_ci int totalLen = 0; 271e9297d28Sopenharmony_ci int size = static_cast<int>(fileSize); 272e9297d28Sopenharmony_ci char readBuffer[READ_SIZE] = {0}; 273e9297d28Sopenharmony_ci std::shared_ptr<ImageStruct> imageStruct = std::make_shared<ImageStruct>(); 274e9297d28Sopenharmony_ci imageStruct->memPtr.SetBufferSize(fileSize); 275e9297d28Sopenharmony_ci do { 276e9297d28Sopenharmony_ci readLen = unzReadCurrentFile(zipFile, readBuffer, READ_SIZE); 277e9297d28Sopenharmony_ci if (readLen < 0) { 278e9297d28Sopenharmony_ci LOGE("unzReadCurrentFile length error"); 279e9297d28Sopenharmony_ci return false; 280e9297d28Sopenharmony_ci } 281e9297d28Sopenharmony_ci if (imageStruct->memPtr.memBuffer == nullptr) { 282e9297d28Sopenharmony_ci LOGE("ReadImageFile memPtr is null"); 283e9297d28Sopenharmony_ci return false; 284e9297d28Sopenharmony_ci } 285e9297d28Sopenharmony_ci if (memcpy_s(imageStruct->memPtr.memBuffer + totalLen, size - totalLen, \ 286e9297d28Sopenharmony_ci readBuffer, readLen) == EOK) { 287e9297d28Sopenharmony_ci totalLen += readLen; 288e9297d28Sopenharmony_ci } 289e9297d28Sopenharmony_ci } while (readLen > 0); 290e9297d28Sopenharmony_ci 291e9297d28Sopenharmony_ci if (totalLen > 0) { 292e9297d28Sopenharmony_ci LOGD("fileName: %{public}s, fileSize: %{public}d, totalLen: %{public}d", fileName.c_str(), size, totalLen); 293e9297d28Sopenharmony_ci if (strstr(fileName.c_str(), BOOT_PIC_CONFIG_FILE.c_str()) != nullptr) { 294e9297d28Sopenharmony_ci ParseImageConfig(imageStruct->memPtr.memBuffer, totalLen, frameConfig); 295e9297d28Sopenharmony_ci } else { 296e9297d28Sopenharmony_ci CheckImageData(fileName, imageStruct, totalLen, imgVec); 297e9297d28Sopenharmony_ci } 298e9297d28Sopenharmony_ci } 299e9297d28Sopenharmony_ci return true; 300e9297d28Sopenharmony_ci} 301e9297d28Sopenharmony_ci 302e9297d28Sopenharmony_cibool ParseImageConfig(const char* fileBuffer, int totalsize, FrameRateConfig& frameConfig) 303e9297d28Sopenharmony_ci{ 304e9297d28Sopenharmony_ci std::string JParamsString; 305e9297d28Sopenharmony_ci JParamsString.assign(fileBuffer, totalsize); 306e9297d28Sopenharmony_ci cJSON* overallData = cJSON_Parse(JParamsString.c_str()); 307e9297d28Sopenharmony_ci if (overallData == nullptr) { 308e9297d28Sopenharmony_ci LOGE("parse image config failed"); 309e9297d28Sopenharmony_ci return false; 310e9297d28Sopenharmony_ci } 311e9297d28Sopenharmony_ci cJSON* frameRate = cJSON_GetObjectItem(overallData, "FrameRate"); 312e9297d28Sopenharmony_ci if (frameRate != nullptr && cJSON_IsNumber(frameRate)) { 313e9297d28Sopenharmony_ci frameConfig.frameRate = frameRate->valueint; 314e9297d28Sopenharmony_ci LOGI("freq: %{public}d", frameConfig.frameRate); 315e9297d28Sopenharmony_ci } 316e9297d28Sopenharmony_ci cJSON_Delete(overallData); 317e9297d28Sopenharmony_ci return true; 318e9297d28Sopenharmony_ci} 319e9297d28Sopenharmony_ci 320e9297d28Sopenharmony_cibool CheckImageData(const std::string& fileName, std::shared_ptr<ImageStruct> imageStruct, 321e9297d28Sopenharmony_ci int32_t bufferLen, ImageStructVec& imgVec) 322e9297d28Sopenharmony_ci{ 323e9297d28Sopenharmony_ci if (imageStruct->memPtr.memBuffer == nullptr) { 324e9297d28Sopenharmony_ci LOGE("json file buffer is null"); 325e9297d28Sopenharmony_ci return false; 326e9297d28Sopenharmony_ci } 327e9297d28Sopenharmony_ci auto data = std::make_shared<Rosen::Drawing::Data>(); 328e9297d28Sopenharmony_ci data->BuildFromMalloc(imageStruct->memPtr.memBuffer, bufferLen); 329e9297d28Sopenharmony_ci if (data->GetData() == nullptr) { 330e9297d28Sopenharmony_ci LOGE("data memory data is null. update data failed"); 331e9297d28Sopenharmony_ci return false; 332e9297d28Sopenharmony_ci } 333e9297d28Sopenharmony_ci imageStruct->memPtr.setOwnerShip(data); 334e9297d28Sopenharmony_ci imageStruct->fileName = fileName; 335e9297d28Sopenharmony_ci imageStruct->imageData = std::make_shared<Rosen::Drawing::Image>(); 336e9297d28Sopenharmony_ci imageStruct->imageData->MakeFromEncoded(data); 337e9297d28Sopenharmony_ci imgVec.push_back(imageStruct); 338e9297d28Sopenharmony_ci return true; 339e9297d28Sopenharmony_ci} 340e9297d28Sopenharmony_ci 341e9297d28Sopenharmony_ci/** 342e9297d28Sopenharmony_ci * Transate vp to pixel. 343e9297d28Sopenharmony_ci * 344e9297d28Sopenharmony_ci * @param sideLen The short side length of screen. 345e9297d28Sopenharmony_ci * @param vp vp value. 346e9297d28Sopenharmony_ci * @return Returns the font size. 347e9297d28Sopenharmony_ci */ 348e9297d28Sopenharmony_ciint32_t TransalteVp2Pixel(const int32_t sideLen, const int32_t vp) 349e9297d28Sopenharmony_ci{ 350e9297d28Sopenharmony_ci return static_cast<int32_t>(std::ceil(sideLen * HALF / RADIO) / HALF * vp); 351e9297d28Sopenharmony_ci} 352e9297d28Sopenharmony_ci} // namespace OHOS 353