1 /*
2  * Copyright (c) 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 
16 #include "camera_example_vendor_tags.h"
17 
18 namespace OHOS::Camera {
19 const uint32_t EXAMPLE_VENDOR_SECTION_BOUNDS[EXAMPLE_SECTION_COUNT][2] = {
20     {(uint32_t)EXAMPLE_VENDOR_SENSOR_START, (uint32_t)EXAMPLE_VENDOR_SENSOR_END}
21 };
22 
23 const vendorTag_t VENDOR_SENSOR[EXAMPLE_VENDOR_SENSOR_END -
24         EXAMPLE_VENDOR_SENSOR_START] = {
25     {EXAMPLE_VENDOR_SENSOR_MODE, "sensorMode", META_TYPE_BYTE},
26     {EXAMPLE_VENDOR_SENSOR_EXPOSURE, "sensorExposure", META_TYPE_INT64}
27 };
28 
29 const vendorTag_t* EXAMPLE_VENDOR_TAG_INFO[EXAMPLE_SECTION_COUNT] = {
30     VENDOR_SENSOR
31 };
32 
GetVendorTagCount()33 uint32_t CameraVendorTagExample::GetVendorTagCount()
34 {
35     uint32_t count = 0;
36 
37     for (int32_t section = 0; section < EXAMPLE_SECTION_COUNT; section++) {
38         uint32_t start = EXAMPLE_VENDOR_SECTION_BOUNDS[section][0];
39         uint32_t end = EXAMPLE_VENDOR_SECTION_BOUNDS[section][1];
40         count += end - start;
41     }
42     return count;
43 }
44 
GetVendorTagName(const uint32_t tag)45 const char* CameraVendorTagExample::GetVendorTagName(const uint32_t tag)
46 {
47     int32_t tag_section = (tag >> 16) - OHOS_VENDOR_SECTION;
48     if (tag_section < 0
49             || tag_section >= EXAMPLE_SECTION_COUNT
50             || tag >= EXAMPLE_VENDOR_SECTION_BOUNDS[tag_section][1]) return nullptr;
51     int32_t tag_index = tag & 0xFFFF;
52     return EXAMPLE_VENDOR_TAG_INFO[tag_section][tag_index].tagName;
53 }
54 
GetVendorTagType(const uint32_t tag)55 int32_t CameraVendorTagExample::GetVendorTagType(const uint32_t tag)
56 {
57     int32_t tag_section = (tag >> 16) - OHOS_VENDOR_SECTION;
58     if (tag_section < 0
59             || tag_section >= EXAMPLE_SECTION_COUNT
60             || tag >= EXAMPLE_VENDOR_SECTION_BOUNDS[tag_section][1]) return -1;
61     int32_t tag_index = tag & 0xFFFF;
62     return EXAMPLE_VENDOR_TAG_INFO[tag_section][tag_index].tagType;
63 }
64 
GetAllVendorTags(std::vector<vendorTag_t> & tagVec)65 void CameraVendorTagExample::GetAllVendorTags(std::vector<vendorTag_t>& tagVec)
66 {
67     for (int32_t section = 0; section < EXAMPLE_SECTION_COUNT; section++) {
68         uint32_t start = EXAMPLE_VENDOR_SECTION_BOUNDS[section][0];
69         uint32_t end = EXAMPLE_VENDOR_SECTION_BOUNDS[section][1];
70         for (uint32_t tag = start; tag < end; tag++) {
71             vendorTag_t info {};
72             info.tagId = tag;
73             info.tagName = GetVendorTagName(tag);
74             info.tagType = GetVendorTagType(tag);
75             tagVec.push_back(info);
76         }
77     }
78 }
79 }
80