Home | History | Annotate | Download | only in tests
      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 
    114 static const vendor_tag_query_ops_t fakevendor_query_ops = {
    115     get_fakevendor_section_name,
    116     get_fakevendor_tag_name,
    117     get_fakevendor_tag_type
    118 };
    119 
    120 const char *get_fakevendor_section_name(const vendor_tag_query_ops_t *v,
    121         uint32_t tag) {
    122     if (v != &fakevendor_query_ops) return NULL;
    123     int tag_section = (tag >> 16) - VENDOR_SECTION;
    124     if (tag_section < 0 ||
    125             tag_section >= FAKEVENDOR_SECTION_COUNT) return NULL;
    126 
    127     return fakevendor_section_names[tag_section];
    128 }
    129 
    130 const char *get_fakevendor_tag_name(const vendor_tag_query_ops_t *v,
    131         uint32_t tag) {
    132     if (v != &fakevendor_query_ops) return NULL;
    133     int tag_section = (tag >> 16) - VENDOR_SECTION;
    134     if (tag_section < 0
    135             || tag_section >= FAKEVENDOR_SECTION_COUNT
    136             || tag >= fakevendor_section_bounds[tag_section][1]) return NULL;
    137     int tag_index = tag & 0xFFFF;
    138     return fakevendor_tag_info[tag_section][tag_index].tag_name;
    139 }
    140 
    141 int get_fakevendor_tag_type(const vendor_tag_query_ops_t *v,
    142         uint32_t tag) {
    143     if (v != &fakevendor_query_ops) return -1;
    144     int tag_section = (tag >> 16) - VENDOR_SECTION;
    145     if (tag_section < 0
    146             || tag_section >= FAKEVENDOR_SECTION_COUNT
    147             || tag >= fakevendor_section_bounds[tag_section][1]) return -1;
    148     int tag_index = tag & 0xFFFF;
    149     return fakevendor_tag_info[tag_section][tag_index].tag_type;
    150 }
    151 
    152 
    153 #endif
    154