• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 COLOR_SPACE_INFO_PARSE_H
16 #define COLOR_SPACE_INFO_PARSE_H
17 
18 #include <queue>
19 #include <vector>
20 #include <iostream>
21 #include <limits.h>
22 
23 namespace OHOS {
24 namespace CameraStandard {
25 using namespace std;
26 
27 typedef struct ColorSpaceStreamInfo {
28     int32_t streamType;
29     uint32_t colorSpaceCount;
30     std::vector<int32_t> colorSpaces;
31 } ColorSpaceStreamInfo;
32 
33 typedef struct ColorSpaceModeInfo {
34     int32_t modeType;
35     uint32_t streamTypeCount;
36     std::vector<ColorSpaceStreamInfo> streamInfo;
37 } ColorSpaceModeInfo;
38 
39 typedef struct ColorSpaceInfo {
40     uint32_t modeCount;
41     std::vector<ColorSpaceModeInfo> modeInfo;
42 } ColorSpaceInfo;
43 
44 constexpr static int32_t MODE_FINISH_IDENTIFIER = -1;
45 constexpr static int32_t STREAM_FINISH_IDENTIFIER = -1;
46 constexpr static int32_t LOOP_ONE_STEP = 1;
47 constexpr static int32_t COMMON_STREAM_WITHOUT_TYPE = -1;
48 
49 class ColorSpaceInfoParse {
50 public:
getColorSpaceInfo(int32_t * originInfo,uint32_t count,ColorSpaceInfo & transferedInfo)51     void getColorSpaceInfo(int32_t* originInfo, uint32_t count, ColorSpaceInfo& transferedInfo)
52     {
53         modeStartIndex_.push_back(0);
54         // 处理mode层级的信息,记录mode数量及每个mode开始和结束的下标
55         for (uint32_t i = LOOP_ONE_STEP; i < count; i++) {
56             // 连续两个-1代表当前模式的色彩空间信息上报结束
57             if (originInfo[i - LOOP_ONE_STEP] == STREAM_FINISH_IDENTIFIER && originInfo[i] == MODE_FINISH_IDENTIFIER) {
58                 modeEndIndex_.push_back(i);
59                 if (i + LOOP_ONE_STEP < count) {
60                     modeStartIndex_.push_back(i + LOOP_ONE_STEP);
61                 }
62                 transferedInfo.modeCount++;
63             }
64         }
65         transferedInfo.modeInfo.resize(transferedInfo.modeCount);
66 
67         getColorSpaceStreamCount(originInfo, transferedInfo);
68         for (uint32_t i = 0; i < transferedInfo.modeCount; i++) {
69             transferedInfo.modeInfo[i].modeType = originInfo[modeStartIndex_[i]];
70             getColorSpaceStreamInfo(originInfo, transferedInfo.modeInfo[i]);
71         }
72     }
73 
getColorSpaceInfoforConcurrent(double * originInfo,uint32_t count,ColorSpaceInfo & transferedInfo)74     void getColorSpaceInfoforConcurrent(double* originInfo, uint32_t count, ColorSpaceInfo& transferedInfo)
75     {
76         modeStartIndex_.push_back(0);
77         // 处理mode层级的信息,记录mode数量及每个mode开始和结束的下标
78         for (uint32_t i = LOOP_ONE_STEP; i < count; i++) {
79             // 连续两个-1代表当前模式的色彩空间信息上报结束
80             if (static_cast<int32_t>(originInfo[i - LOOP_ONE_STEP]) == INT_MAX &&
81                 static_cast<int32_t>(originInfo[i]) == INT_MAX) {
82                 modeEndIndex_.push_back(i);
83                 if (i + LOOP_ONE_STEP < count) {
84                     modeStartIndex_.push_back(i + LOOP_ONE_STEP);
85                 }
86                 transferedInfo.modeCount++;
87             }
88         }
89         transferedInfo.modeInfo.resize(transferedInfo.modeCount);
90 
91         getColorSpaceStreamCountforConcurrent(originInfo, transferedInfo);
92         for (uint32_t i = 0; i < transferedInfo.modeCount; i++) {
93             transferedInfo.modeInfo[i].modeType = static_cast<int32_t>(originInfo[modeStartIndex_[i]]);
94             getColorSpaceStreamInfoforConcurrent(originInfo, transferedInfo.modeInfo[i]);
95         }
96     }
97 private:
getColorSpaceStreamCount(int32_t * originInfo,ColorSpaceInfo & transferedInfo)98     void getColorSpaceStreamCount(int32_t* originInfo, ColorSpaceInfo& transferedInfo)
99     {
100         for (uint32_t i = 0; i < transferedInfo.modeCount; i++) {
101             for (uint32_t j = modeStartIndex_[i]; j < modeEndIndex_[i]; j++) {
102                 if (j == modeStartIndex_[i]) {
103                     streamStartIndex_.push(modeStartIndex_[i] + LOOP_ONE_STEP);
104                 }
105                 if (originInfo[j] == STREAM_FINISH_IDENTIFIER) {
106                     streamEndIndex_.push(j);
107                     transferedInfo.modeInfo[i].streamTypeCount++;
108                 }
109                 if ((originInfo[j] == STREAM_FINISH_IDENTIFIER) && ((j + LOOP_ONE_STEP) < modeEndIndex_[i])) {
110                     streamStartIndex_.push(j + LOOP_ONE_STEP);
111                 }
112             }
113         }
114         modeStartIndex_.clear();
115         modeEndIndex_.clear();
116     }
117 
getColorSpaceStreamInfo(int32_t * originInfo,ColorSpaceModeInfo & modeInfo)118     void getColorSpaceStreamInfo(int32_t* originInfo, ColorSpaceModeInfo& modeInfo)
119     {
120         modeInfo.streamInfo.resize(modeInfo.streamTypeCount);
121         for (uint32_t i = 0; i < modeInfo.streamTypeCount; i++) {
122             uint32_t loopStart;
123             // 第一套色彩空间能力集为common能力,不报streamType
124             if (i == 0) {
125                 modeInfo.streamInfo[i].streamType = COMMON_STREAM_WITHOUT_TYPE;
126                 loopStart = streamStartIndex_.front();
127             } else {
128                 // 除第一套外,其余色彩空间能力集的第一个int值表示streamType
129                 modeInfo.streamInfo[i].streamType = originInfo[streamStartIndex_.front()];
130                 loopStart = streamStartIndex_.front() + LOOP_ONE_STEP;
131             }
132 
133             modeInfo.streamInfo[i].colorSpaceCount = streamEndIndex_.front() - loopStart;
134             modeInfo.streamInfo[i].colorSpaces.resize(modeInfo.streamInfo[i].colorSpaceCount);
135             int j = 0;
136             for (uint32_t k = loopStart; k < streamEndIndex_.front(); k++) {
137                 modeInfo.streamInfo[i].colorSpaces[j] = originInfo[k];
138                 j++;
139             }
140 
141             streamStartIndex_.pop();
142             streamEndIndex_.pop();
143         }
144     }
145 
getColorSpaceStreamCountforConcurrent(double * originInfo,ColorSpaceInfo & transferedInfo)146     void getColorSpaceStreamCountforConcurrent(double* originInfo, ColorSpaceInfo& transferedInfo)
147     {
148         for (uint32_t i = 0; i < transferedInfo.modeCount; i++) {
149             for (uint32_t j = modeStartIndex_[i]; j < modeEndIndex_[i]; j++) {
150                 if (j == modeStartIndex_[i]) {
151                     streamStartIndex_.push(modeStartIndex_[i] + LOOP_ONE_STEP);
152                 }
153                 if (static_cast<int32_t>(originInfo[j]) == INT_MAX) {
154                     streamEndIndex_.push(j);
155                     transferedInfo.modeInfo[i].streamTypeCount++;
156                 }
157                 if ((static_cast<int32_t>(originInfo[j]) == INT_MAX) &&
158                     ((j + LOOP_ONE_STEP) < modeEndIndex_[i])) {
159                     streamStartIndex_.push(j + LOOP_ONE_STEP);
160                 }
161             }
162         }
163         modeStartIndex_.clear();
164         modeEndIndex_.clear();
165     }
166 
getColorSpaceStreamInfoforConcurrent(double * originInfo,ColorSpaceModeInfo & modeInfo)167     void getColorSpaceStreamInfoforConcurrent(double* originInfo, ColorSpaceModeInfo& modeInfo)
168     {
169         modeInfo.streamInfo.resize(modeInfo.streamTypeCount);
170         for (uint32_t i = 0; i < modeInfo.streamTypeCount; i++) {
171             uint32_t loopStart;
172             // 第一套色彩空间能力集为common能力,不报streamType
173             if (i == 0) {
174                 modeInfo.streamInfo[i].streamType = COMMON_STREAM_WITHOUT_TYPE;
175                 loopStart = streamStartIndex_.front();
176             } else {
177                 // 除第一套外,其余色彩空间能力集的第一个int值表示streamType
178                 modeInfo.streamInfo[i].streamType = static_cast<int32_t>(originInfo[streamStartIndex_.front()]);
179                 loopStart = streamStartIndex_.front() + LOOP_ONE_STEP;
180             }
181 
182             modeInfo.streamInfo[i].colorSpaceCount = streamEndIndex_.front() - loopStart;
183             modeInfo.streamInfo[i].colorSpaces.resize(modeInfo.streamInfo[i].colorSpaceCount);
184             int j = 0;
185             for (uint32_t k = loopStart; k < streamEndIndex_.front(); k++) {
186                 modeInfo.streamInfo[i].colorSpaces[j] = static_cast<int32_t>(originInfo[k]);
187                 j++;
188             }
189 
190             streamStartIndex_.pop();
191             streamEndIndex_.pop();
192         }
193     }
194 
195     std::vector<uint32_t> modeStartIndex_ = {};
196     std::vector<uint32_t> modeEndIndex_ = {};
197     std::queue<uint32_t> streamStartIndex_;
198     std::queue<uint32_t> streamEndIndex_;
199 };
200 } // namespace CameraStandard
201 } // namespace OHOS
202 #endif // COLOR_SPACE_INFO_PARSE_H