1 /* 2 * Copyright (c) 2023-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef EFFECT_SUGGESTION_INFO_PARSE_H 16 #define EFFECT_SUGGESTION_INFO_PARSE_H 17 18 #include <queue> 19 #include <vector> 20 #include <iostream> 21 #include <cstdint> 22 23 namespace OHOS { 24 namespace CameraStandard { 25 using namespace std; 26 27 typedef struct EffectSuggestionModeInfo { 28 int32_t modeType; 29 std::vector<int32_t> effectSuggestionList; 30 } EffectSuggestionModeInfo; 31 32 typedef struct EffectSuggestionInfo { 33 uint32_t modeCount; 34 std::vector<EffectSuggestionModeInfo> modeInfo; 35 } EffectSuggestionInfo; 36 37 class EffectSuggestionInfoParse { 38 public: GetEffectSuggestionInfo(int32_t * originInfo,uint32_t count,EffectSuggestionInfo & effectSuggestionInfo)39 void GetEffectSuggestionInfo(int32_t* originInfo, uint32_t count, EffectSuggestionInfo& effectSuggestionInfo) 40 { 41 if (count <= 0 || originInfo == nullptr) { 42 return; 43 } 44 ResizeModeInfo(originInfo, count, effectSuggestionInfo); 45 ResizeEffectSuggestionList(originInfo, effectSuggestionInfo); 46 } 47 private: ResizeModeInfo(int32_t * originInfo,uint32_t count,EffectSuggestionInfo & effectSuggestionInfo)48 void ResizeModeInfo(int32_t* originInfo, uint32_t count, EffectSuggestionInfo& effectSuggestionInfo) 49 { 50 int32_t MODE_END = -1; 51 uint32_t i = 0; 52 uint32_t j = i + 1; 53 while (j < count) { 54 if (originInfo[j] == MODE_END) { 55 std::pair<uint32_t, uint32_t> indexPair(i, j - 1); 56 modeInfoIndexRange_.push_back(indexPair); 57 effectSuggestionInfo.modeCount++; 58 i = j + 1; 59 j = i + 1; 60 } else { 61 j++; 62 } 63 } 64 effectSuggestionInfo.modeInfo.resize(effectSuggestionInfo.modeCount); 65 } 66 ResizeEffectSuggestionList(int32_t * originInfo,EffectSuggestionInfo & effectSuggestionInfo)67 void ResizeEffectSuggestionList(int32_t* originInfo, EffectSuggestionInfo& effectSuggestionInfo) 68 { 69 for (auto it = modeInfoIndexRange_.begin(); it != modeInfoIndexRange_.end(); ++it) { 70 uint32_t start = it->first; 71 int modeInfoIndex = std::distance(modeInfoIndexRange_.begin(), it); 72 EffectSuggestionModeInfo &modeInfo = effectSuggestionInfo.modeInfo[modeInfoIndex]; 73 int32_t mode = originInfo[start]; 74 int32_t typeNum = originInfo[start + 1]; 75 modeInfo.modeType = mode; 76 modeInfo.effectSuggestionList.resize(typeNum); 77 uint32_t effectStartIndex = start + 2; 78 for (int i = 0; i < typeNum; i++) { 79 modeInfo.effectSuggestionList[i] = originInfo[effectStartIndex + static_cast<uint32_t>(i)]; 80 } 81 } 82 } 83 std::vector<std::pair<uint32_t, uint32_t>> modeInfoIndexRange_; 84 }; 85 } // namespace CameraStandard 86 } // namespace OHOS 87 #endif // EFFECT_SUGGESTION_INFO_PARSE_H