• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 enum vendor_extension_section {
25     FAKEVENDOR_SENSOR = VENDOR_SECTION,
26     FAKEVENDOR_SENSOR_INFO,
27     FAKEVENDOR_COLORCORRECTION,
28     FAKEVENDOR_SCALER,
29     FAKEVENDOR_SECTION_END
30 };
31 
32 const int FAKEVENDOR_SECTION_COUNT = FAKEVENDOR_SECTION_END - VENDOR_SECTION;
33 
34 enum vendor_extension_section_ranges {
35     FAKEVENDOR_SENSOR_START          = FAKEVENDOR_SENSOR << 16,
36     FAKEVENDOR_SENSOR_I_START        = FAKEVENDOR_SENSOR_INFO << 16,
37     FAKEVENDOR_COLORCORRECTION_START = FAKEVENDOR_COLORCORRECTION << 16,
38     FAKEVENDOR_SCALER_START          = FAKEVENDOR_SCALER << 16
39 };
40 
41 enum vendor_extension_tags {
42     FAKEVENDOR_SENSOR_SUPERMODE = FAKEVENDOR_SENSOR_START,
43     FAKEVENDOR_SENSOR_DOUBLE_EXPOSURE,
44     FAKEVENDOR_SENSOR_END,
45 
46     FAKEVENDOR_SENSOR_AVAILABLE_SUPERMODES = FAKEVENDOR_SENSOR_I_START,
47     FAKEVENDOR_SENSOR_I_END,
48 
49     FAKEVENDOR_COLORCORRECTION_3DLUT_MODE = FAKEVENDOR_COLORCORRECTION_START,
50     FAKEVENDOR_COLORCORRECTION_3DLUT_TABLES,
51     FAKEVENDOR_COLORCORRECTION_END,
52 
53     FAKEVENDOR_SCALER_DOWNSCALE_MODE = FAKEVENDOR_SCALER_START,
54     FAKEVENDOR_SCALER_DOWNSCALE_COEFF,
55     FAKEVENDOR_SCALER_END
56 };
57 
58 typedef struct vendor_tag_info {
59     const char *tag_name;
60     uint8_t     tag_type;
61 } vendor_tag_info_t;
62 
63 const char *fakevendor_section_names[FAKEVENDOR_SECTION_COUNT] = {
64     "com.fakevendor.sensor",
65     "com.fakevendor.sensor.info",
66     "com.fakevendor.colorCorrection",
67     "com.fakevendor.scaler"
68 };
69 
70 unsigned int fakevendor_section_bounds[FAKEVENDOR_SECTION_COUNT][2] = {
71     { FAKEVENDOR_SENSOR_START,          FAKEVENDOR_SENSOR_END },
72     { FAKEVENDOR_SENSOR_I_START,        FAKEVENDOR_SENSOR_I_END },
73     { FAKEVENDOR_COLORCORRECTION_START, FAKEVENDOR_COLORCORRECTION_END },
74     { FAKEVENDOR_SCALER_START,          FAKEVENDOR_SCALER_END}
75 };
76 
77 vendor_tag_info_t fakevendor_sensor[FAKEVENDOR_SENSOR_END -
78         FAKEVENDOR_SENSOR_START] = {
79     { "superMode",       TYPE_BYTE },
80     { "doubleExposure",  TYPE_INT64 }
81 };
82 
83 vendor_tag_info_t fakevendor_sensor_info[FAKEVENDOR_SENSOR_I_END -
84         FAKEVENDOR_SENSOR_I_START] = {
85     { "availableSuperModes",   TYPE_BYTE }
86 };
87 
88 vendor_tag_info_t fakevendor_color_correction[FAKEVENDOR_COLORCORRECTION_END -
89         FAKEVENDOR_COLORCORRECTION_START] = {
90     { "3dLutMode",   TYPE_BYTE },
91     { "3dLutTables", TYPE_FLOAT }
92 };
93 
94 vendor_tag_info_t fakevendor_scaler[FAKEVENDOR_SCALER_END -
95         FAKEVENDOR_SCALER_START] = {
96     { "downscaleMode",  TYPE_BYTE },
97     { "downscaleCoefficients", TYPE_FLOAT }
98 };
99 
100 vendor_tag_info_t *fakevendor_tag_info[FAKEVENDOR_SECTION_COUNT] = {
101     fakevendor_sensor,
102     fakevendor_sensor_info,
103     fakevendor_color_correction,
104     fakevendor_scaler
105 };
106 
107 const char *get_fakevendor_section_name(const vendor_tag_query_ops_t *v,
108         uint32_t tag);
109 const char *get_fakevendor_tag_name(const vendor_tag_query_ops_t *v,
110         uint32_t tag);
111 int get_fakevendor_tag_type(const vendor_tag_query_ops_t *v,
112         uint32_t tag);
113 int get_fakevendor_tag_count(const vendor_tag_query_ops_t *v);
114 void get_fakevendor_tags(const vendor_tag_query_ops_t *v, uint32_t *tag_array);
115 
116 static const vendor_tag_query_ops_t fakevendor_query_ops = {
117     get_fakevendor_section_name,
118     get_fakevendor_tag_name,
119     get_fakevendor_tag_type,
120     get_fakevendor_tag_count,
121     get_fakevendor_tags
122 };
123 
get_fakevendor_section_name(const vendor_tag_query_ops_t * v,uint32_t tag)124 const char *get_fakevendor_section_name(const vendor_tag_query_ops_t *v,
125         uint32_t tag) {
126     if (v != &fakevendor_query_ops) return NULL;
127     int tag_section = (tag >> 16) - VENDOR_SECTION;
128     if (tag_section < 0 ||
129             tag_section >= FAKEVENDOR_SECTION_COUNT) return NULL;
130 
131     return fakevendor_section_names[tag_section];
132 }
133 
get_fakevendor_tag_name(const vendor_tag_query_ops_t * v,uint32_t tag)134 const char *get_fakevendor_tag_name(const vendor_tag_query_ops_t *v,
135         uint32_t tag) {
136     if (v != &fakevendor_query_ops) return NULL;
137     int tag_section = (tag >> 16) - VENDOR_SECTION;
138     if (tag_section < 0
139             || tag_section >= FAKEVENDOR_SECTION_COUNT
140             || tag >= fakevendor_section_bounds[tag_section][1]) return NULL;
141     int tag_index = tag & 0xFFFF;
142     return fakevendor_tag_info[tag_section][tag_index].tag_name;
143 }
144 
get_fakevendor_tag_type(const vendor_tag_query_ops_t * v,uint32_t tag)145 int get_fakevendor_tag_type(const vendor_tag_query_ops_t *v,
146         uint32_t tag) {
147     if (v != &fakevendor_query_ops) return -1;
148     int tag_section = (tag >> 16) - VENDOR_SECTION;
149     if (tag_section < 0
150             || tag_section >= FAKEVENDOR_SECTION_COUNT
151             || tag >= fakevendor_section_bounds[tag_section][1]) return -1;
152     int tag_index = tag & 0xFFFF;
153     return fakevendor_tag_info[tag_section][tag_index].tag_type;
154 }
155 
get_fakevendor_tag_count(const vendor_tag_query_ops_t * v)156 int get_fakevendor_tag_count(const vendor_tag_query_ops_t *v) {
157     int section;
158     unsigned int start, end;
159     int count = 0;
160 
161     if (v != &fakevendor_query_ops) return -1;
162     for (section = 0; section < FAKEVENDOR_SECTION_COUNT; section++) {
163         start = fakevendor_section_bounds[section][0];
164         end = fakevendor_section_bounds[section][1];
165         count += end - start;
166     }
167     return count;
168 }
169 
get_fakevendor_tags(const vendor_tag_query_ops_t * v,uint32_t * tag_array)170 void get_fakevendor_tags(const vendor_tag_query_ops_t *v, uint32_t *tag_array) {
171     int section;
172     unsigned int start, end, tag;
173 
174     if (v != &fakevendor_query_ops || tag_array == NULL) return;
175     for (section = 0; section < FAKEVENDOR_SECTION_COUNT; section++) {
176         start = fakevendor_section_bounds[section][0];
177         end = fakevendor_section_bounds[section][1];
178         for (tag = start; tag < end; tag++) {
179             *tag_array++ = tag;
180         }
181     }
182 }
183 
184 #endif
185