1 /*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 /**
18 * Fake vendor extensions for testing
19 */
20
21 #ifndef TESTING_CAMERA_METADATA_FAKEVENDOR_H
22 #define TESTING_CAMERA_METADATA_FAKEVENDOR_H
23
24 #include <stdint.h>
25
26 #include <system/camera_metadata.h>
27 #include <system/camera_vendor_tags.h>
28
29 enum vendor_extension_section {
30 FAKEVENDOR_SENSOR = VENDOR_SECTION,
31 FAKEVENDOR_SENSOR_INFO,
32 FAKEVENDOR_COLORCORRECTION,
33 FAKEVENDOR_SCALER,
34 FAKEVENDOR_SECTION_END
35 };
36
37 const int FAKEVENDOR_SECTION_COUNT = FAKEVENDOR_SECTION_END - VENDOR_SECTION;
38
39 enum vendor_extension_section_ranges {
40 FAKEVENDOR_SENSOR_START = FAKEVENDOR_SENSOR << 16,
41 FAKEVENDOR_SENSOR_I_START = FAKEVENDOR_SENSOR_INFO << 16,
42 FAKEVENDOR_COLORCORRECTION_START = FAKEVENDOR_COLORCORRECTION << 16,
43 FAKEVENDOR_SCALER_START = FAKEVENDOR_SCALER << 16
44 };
45
46 enum vendor_extension_tags {
47 FAKEVENDOR_SENSOR_SUPERMODE = FAKEVENDOR_SENSOR_START,
48 FAKEVENDOR_SENSOR_DOUBLE_EXPOSURE,
49 FAKEVENDOR_SENSOR_END,
50
51 FAKEVENDOR_SENSOR_AVAILABLE_SUPERMODES = FAKEVENDOR_SENSOR_I_START,
52 FAKEVENDOR_SENSOR_I_END,
53
54 FAKEVENDOR_COLORCORRECTION_3DLUT_MODE = FAKEVENDOR_COLORCORRECTION_START,
55 FAKEVENDOR_COLORCORRECTION_3DLUT_TABLES,
56 FAKEVENDOR_COLORCORRECTION_END,
57
58 FAKEVENDOR_SCALER_DOWNSCALE_MODE = FAKEVENDOR_SCALER_START,
59 FAKEVENDOR_SCALER_DOWNSCALE_COEFF,
60 FAKEVENDOR_SCALER_END
61 };
62
63 typedef struct vendor_tag_info {
64 const char *tag_name;
65 uint8_t tag_type;
66 } vendor_tag_info_t;
67
68 const char *fakevendor_section_names[FAKEVENDOR_SECTION_COUNT] = {
69 "com.fakevendor.sensor",
70 "com.fakevendor.sensor.info",
71 "com.fakevendor.colorCorrection",
72 "com.fakevendor.scaler"
73 };
74
75 uint32_t fakevendor_section_bounds[FAKEVENDOR_SECTION_COUNT][2] = {
76 { (uint32_t) FAKEVENDOR_SENSOR_START, (uint32_t) FAKEVENDOR_SENSOR_END },
77 { (uint32_t) FAKEVENDOR_SENSOR_I_START, (uint32_t) FAKEVENDOR_SENSOR_I_END },
78 { (uint32_t) FAKEVENDOR_COLORCORRECTION_START, (uint32_t) FAKEVENDOR_COLORCORRECTION_END },
79 { (uint32_t) FAKEVENDOR_SCALER_START, (uint32_t) FAKEVENDOR_SCALER_END}
80 };
81
82 vendor_tag_info_t fakevendor_sensor[FAKEVENDOR_SENSOR_END -
83 FAKEVENDOR_SENSOR_START] = {
84 { "superMode", TYPE_BYTE },
85 { "doubleExposure", TYPE_INT64 }
86 };
87
88 vendor_tag_info_t fakevendor_sensor_info[FAKEVENDOR_SENSOR_I_END -
89 FAKEVENDOR_SENSOR_I_START] = {
90 { "availableSuperModes", TYPE_BYTE }
91 };
92
93 vendor_tag_info_t fakevendor_color_correction[FAKEVENDOR_COLORCORRECTION_END -
94 FAKEVENDOR_COLORCORRECTION_START] = {
95 { "3dLutMode", TYPE_BYTE },
96 { "3dLutTables", TYPE_FLOAT }
97 };
98
99 vendor_tag_info_t fakevendor_scaler[FAKEVENDOR_SCALER_END -
100 FAKEVENDOR_SCALER_START] = {
101 { "downscaleMode", TYPE_BYTE },
102 { "downscaleCoefficients", TYPE_FLOAT }
103 };
104
105 vendor_tag_info_t *fakevendor_tag_info[FAKEVENDOR_SECTION_COUNT] = {
106 fakevendor_sensor,
107 fakevendor_sensor_info,
108 fakevendor_color_correction,
109 fakevendor_scaler
110 };
111
112 const char *get_fakevendor_section_name(const vendor_tag_ops_t *v,
113 uint32_t tag);
114 const char *get_fakevendor_tag_name(const vendor_tag_ops_t *v,
115 uint32_t tag);
116 int get_fakevendor_tag_type(const vendor_tag_ops_t *v,
117 uint32_t tag);
118 int get_fakevendor_tag_count(const vendor_tag_ops_t *v);
119 void get_fakevendor_tags(const vendor_tag_ops_t *v, uint32_t *tag_array);
120
121 static const vendor_tag_ops_t fakevendor_ops = {
122 get_fakevendor_tag_count,
123 get_fakevendor_tags,
124 get_fakevendor_section_name,
125 get_fakevendor_tag_name,
126 get_fakevendor_tag_type
127 };
128
get_fakevendor_section_name(const vendor_tag_ops_t * v,uint32_t tag)129 const char *get_fakevendor_section_name(const vendor_tag_ops_t *v,
130 uint32_t tag) {
131 if (v != &fakevendor_ops) return NULL;
132 int tag_section = (tag >> 16) - VENDOR_SECTION;
133 if (tag_section < 0 ||
134 tag_section >= FAKEVENDOR_SECTION_COUNT) return NULL;
135
136 return fakevendor_section_names[tag_section];
137 }
138
get_fakevendor_tag_name(const vendor_tag_ops_t * v,uint32_t tag)139 const char *get_fakevendor_tag_name(const vendor_tag_ops_t *v,
140 uint32_t tag) {
141 if (v != &fakevendor_ops) return NULL;
142 int tag_section = (tag >> 16) - VENDOR_SECTION;
143 if (tag_section < 0
144 || tag_section >= FAKEVENDOR_SECTION_COUNT
145 || tag >= fakevendor_section_bounds[tag_section][1]) return NULL;
146 int tag_index = tag & 0xFFFF;
147 return fakevendor_tag_info[tag_section][tag_index].tag_name;
148 }
149
get_fakevendor_tag_type(const vendor_tag_ops_t * v,uint32_t tag)150 int get_fakevendor_tag_type(const vendor_tag_ops_t *v,
151 uint32_t tag) {
152 if (v != &fakevendor_ops) return -1;
153 int tag_section = (tag >> 16) - VENDOR_SECTION;
154 if (tag_section < 0
155 || tag_section >= FAKEVENDOR_SECTION_COUNT
156 || tag >= fakevendor_section_bounds[tag_section][1]) return -1;
157 int tag_index = tag & 0xFFFF;
158 return fakevendor_tag_info[tag_section][tag_index].tag_type;
159 }
160
get_fakevendor_tag_count(const vendor_tag_ops_t * v)161 int get_fakevendor_tag_count(const vendor_tag_ops_t *v) {
162 int section;
163 unsigned int start, end;
164 int count = 0;
165
166 if (v != &fakevendor_ops) return -1;
167 for (section = 0; section < FAKEVENDOR_SECTION_COUNT; section++) {
168 start = fakevendor_section_bounds[section][0];
169 end = fakevendor_section_bounds[section][1];
170 count += end - start;
171 }
172 return count;
173 }
174
get_fakevendor_tags(const vendor_tag_ops_t * v,uint32_t * tag_array)175 void get_fakevendor_tags(const vendor_tag_ops_t *v, uint32_t *tag_array) {
176 int section;
177 unsigned int start, end, tag;
178
179 if (v != &fakevendor_ops || tag_array == NULL) return;
180 for (section = 0; section < FAKEVENDOR_SECTION_COUNT; section++) {
181 start = fakevendor_section_bounds[section][0];
182 end = fakevendor_section_bounds[section][1];
183 for (tag = start; tag < end; tag++) {
184 *tag_array++ = tag;
185 }
186 }
187 }
188
189 #endif
190