• 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 #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     {NULL}
128 };
129 
get_fakevendor_section_name(const vendor_tag_ops_t * v,uint32_t tag)130 const char *get_fakevendor_section_name(const vendor_tag_ops_t *v,
131         uint32_t tag) {
132     if (v != &fakevendor_ops) return NULL;
133     int tag_section = (tag >> 16) - VENDOR_SECTION;
134     if (tag_section < 0 ||
135             tag_section >= FAKEVENDOR_SECTION_COUNT) return NULL;
136 
137     return fakevendor_section_names[tag_section];
138 }
139 
get_fakevendor_tag_name(const vendor_tag_ops_t * v,uint32_t tag)140 const char *get_fakevendor_tag_name(const vendor_tag_ops_t *v,
141         uint32_t tag) {
142     if (v != &fakevendor_ops) return NULL;
143     int tag_section = (tag >> 16) - VENDOR_SECTION;
144     if (tag_section < 0
145             || tag_section >= FAKEVENDOR_SECTION_COUNT
146             || tag >= fakevendor_section_bounds[tag_section][1]) return NULL;
147     int tag_index = tag & 0xFFFF;
148     return fakevendor_tag_info[tag_section][tag_index].tag_name;
149 }
150 
get_fakevendor_tag_type(const vendor_tag_ops_t * v,uint32_t tag)151 int get_fakevendor_tag_type(const vendor_tag_ops_t *v,
152         uint32_t tag) {
153     if (v != &fakevendor_ops) return -1;
154     int tag_section = (tag >> 16) - VENDOR_SECTION;
155     if (tag_section < 0
156             || tag_section >= FAKEVENDOR_SECTION_COUNT
157             || tag >= fakevendor_section_bounds[tag_section][1]) return -1;
158     int tag_index = tag & 0xFFFF;
159     return fakevendor_tag_info[tag_section][tag_index].tag_type;
160 }
161 
get_fakevendor_tag_count(const vendor_tag_ops_t * v)162 int get_fakevendor_tag_count(const vendor_tag_ops_t *v) {
163     int section;
164     unsigned int start, end;
165     int count = 0;
166 
167     if (v != &fakevendor_ops) return -1;
168     for (section = 0; section < FAKEVENDOR_SECTION_COUNT; section++) {
169         start = fakevendor_section_bounds[section][0];
170         end = fakevendor_section_bounds[section][1];
171         count += end - start;
172     }
173     return count;
174 }
175 
get_fakevendor_tags(const vendor_tag_ops_t * v,uint32_t * tag_array)176 void get_fakevendor_tags(const vendor_tag_ops_t *v, uint32_t *tag_array) {
177     int section;
178     unsigned int start, end, tag;
179 
180     if (v != &fakevendor_ops || tag_array == NULL) return;
181     for (section = 0; section < FAKEVENDOR_SECTION_COUNT; section++) {
182         start = fakevendor_section_bounds[section][0];
183         end = fakevendor_section_bounds[section][1];
184         for (tag = start; tag < end; tag++) {
185             *tag_array++ = tag;
186         }
187     }
188 }
189 
190 #endif
191