Home | History | Annotate | Download | only in camera
      1 /*
      2 **
      3 ** Copyright 2008, The Android Open Source Project
      4 **
      5 ** Licensed under the Apache License, Version 2.0 (the "License");
      6 ** you may not use this file except in compliance with the License.
      7 ** You may obtain a copy of the License at
      8 **
      9 **     http://www.apache.org/licenses/LICENSE-2.0
     10 **
     11 ** Unless required by applicable law or agreed to in writing, software
     12 ** distributed under the License is distributed on an "AS IS" BASIS,
     13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14 ** See the License for the specific language governing permissions and
     15 ** limitations under the License.
     16 */
     17 
     18 #define LOG_TAG "QCameraParams"
     19 #include <utils/Log.h>
     20 #include <string.h>
     21 #include <stdlib.h>
     22 #include "QCameraParameters.h"
     23 
     24 namespace android {
     25 // Parameter keys to communicate between camera application and driver.
     26 const char QCameraParameters::KEY_SUPPORTED_HFR_SIZES[] = "hfr-size-values";
     27 const char QCameraParameters::KEY_PREVIEW_FRAME_RATE_MODE[] = "preview-frame-rate-mode";
     28 const char QCameraParameters::KEY_SUPPORTED_PREVIEW_FRAME_RATE_MODES[] = "preview-frame-rate-modes";
     29 const char QCameraParameters::KEY_PREVIEW_FRAME_RATE_AUTO_MODE[] = "frame-rate-auto";
     30 const char QCameraParameters::KEY_PREVIEW_FRAME_RATE_FIXED_MODE[] = "frame-rate-fixed";
     31 const char QCameraParameters::KEY_TOUCH_AF_AEC[] = "touch-af-aec";
     32 const char QCameraParameters::KEY_SUPPORTED_TOUCH_AF_AEC[] = "touch-af-aec-values";
     33 const char QCameraParameters::KEY_TOUCH_INDEX_AEC[] = "touch-index-aec";
     34 const char QCameraParameters::KEY_TOUCH_INDEX_AF[] = "touch-index-af";
     35 const char QCameraParameters::KEY_SCENE_DETECT[] = "scene-detect";
     36 const char QCameraParameters::KEY_SUPPORTED_SCENE_DETECT[] = "scene-detect-values";
     37 const char QCameraParameters::KEY_ISO_MODE[] = "iso";
     38 const char QCameraParameters::KEY_SUPPORTED_ISO_MODES[] = "iso-values";
     39 const char QCameraParameters::KEY_LENSSHADE[] = "lensshade";
     40 const char QCameraParameters::KEY_SUPPORTED_LENSSHADE_MODES[] = "lensshade-values";
     41 const char QCameraParameters::KEY_AUTO_EXPOSURE[] = "auto-exposure";
     42 const char QCameraParameters::KEY_SUPPORTED_AUTO_EXPOSURE[] = "auto-exposure-values";
     43 const char QCameraParameters::KEY_DENOISE[] = "denoise";
     44 const char QCameraParameters::KEY_SUPPORTED_DENOISE[] = "denoise-values";
     45 const char QCameraParameters::KEY_SELECTABLE_ZONE_AF[] = "selectable-zone-af";
     46 const char QCameraParameters::KEY_SUPPORTED_SELECTABLE_ZONE_AF[] = "selectable-zone-af-values";
     47 const char QCameraParameters::KEY_FACE_DETECTION[] = "face-detection";
     48 const char QCameraParameters::KEY_SUPPORTED_FACE_DETECTION[] = "face-detection-values";
     49 const char QCameraParameters::KEY_MEMORY_COLOR_ENHANCEMENT[] = "mce";
     50 const char QCameraParameters::KEY_SUPPORTED_MEM_COLOR_ENHANCE_MODES[] = "mce-values";
     51 const char QCameraParameters::KEY_VIDEO_HIGH_FRAME_RATE[] = "video-hfr";
     52 const char QCameraParameters::KEY_SUPPORTED_VIDEO_HIGH_FRAME_RATE_MODES[] = "video-hfr-values";
     53 const char QCameraParameters::KEY_REDEYE_REDUCTION[] = "redeye-reduction";
     54 const char QCameraParameters::KEY_SUPPORTED_REDEYE_REDUCTION[] = "redeye-reduction-values";
     55 const char QCameraParameters::KEY_HIGH_DYNAMIC_RANGE_IMAGING[] = "hdr";
     56 const char QCameraParameters::KEY_SUPPORTED_HDR_IMAGING_MODES[] = "hdr-values";
     57 const char QCameraParameters::KEY_POWER_MODE_SUPPORTED[] = "power-mode-supported";
     58 const char QCameraParameters::KEY_ZSL[] = "zsl";
     59 const char QCameraParameters::KEY_SUPPORTED_ZSL_MODES[] = "zsl-values";
     60 const char QCameraParameters::KEY_CAMERA_MODE[] = "camera-mode";
     61 const char QCameraParameters::KEY_AE_BRACKET_HDR[] = "ae-bracket-hdr";
     62 const char QCameraParameters::KEY_POWER_MODE[] = "power-mode";
     63 /*only effective when KEY_AE_BRACKET_HDR set to ae_bracketing*/
     64 //const char QCameraParameters::KEY_AE_BRACKET_SETTING_KEY[] = "ae-bracket-setting";
     65 
     66 // Values for effect settings.
     67 const char QCameraParameters::EFFECT_EMBOSS[] = "emboss";
     68 const char QCameraParameters::EFFECT_SKETCH[] = "sketch";
     69 const char QCameraParameters::EFFECT_NEON[] = "neon";
     70 
     71 // Values for auto exposure settings.
     72 const char QCameraParameters::TOUCH_AF_AEC_OFF[] = "touch-off";
     73 const char QCameraParameters::TOUCH_AF_AEC_ON[] = "touch-on";
     74 
     75 // Values for scene mode settings.
     76 const char QCameraParameters::SCENE_MODE_ASD[] = "asd";   // corresponds to CAMERA_BESTSHOT_AUTO in HAL
     77 const char QCameraParameters::SCENE_MODE_BACKLIGHT[] = "backlight";
     78 const char QCameraParameters::SCENE_MODE_FLOWERS[] = "flowers";
     79 const char QCameraParameters::SCENE_MODE_AR[] = "AR";
     80 const char QCameraParameters::SCENE_MODE_HDR[] = "hdr";
     81 
     82 // Values for auto scene detection settings.
     83 const char QCameraParameters::SCENE_DETECT_OFF[] = "off";
     84 const char QCameraParameters::SCENE_DETECT_ON[] = "on";
     85 
     86 // Formats for setPreviewFormat and setPictureFormat.
     87 const char QCameraParameters::PIXEL_FORMAT_YUV420SP_ADRENO[] = "yuv420sp-adreno";
     88 const char QCameraParameters::PIXEL_FORMAT_RAW[] = "raw";
     89 const char QCameraParameters::PIXEL_FORMAT_YV12[] = "yuv420p";
     90 const char QCameraParameters::PIXEL_FORMAT_NV12[] = "nv12";
     91 
     92 // Values for focus mode settings.
     93 const char QCameraParameters::FOCUS_MODE_NORMAL[] = "normal";
     94 const char QCameraParameters::KEY_SKIN_TONE_ENHANCEMENT[] = "skinToneEnhancement";
     95 const char QCameraParameters::KEY_SUPPORTED_SKIN_TONE_ENHANCEMENT_MODES[] = "skinToneEnhancement-values";
     96 
     97 // Values for ISO Settings
     98 const char QCameraParameters::ISO_AUTO[] = "auto";
     99 const char QCameraParameters::ISO_HJR[] = "ISO_HJR";
    100 const char QCameraParameters::ISO_100[] = "ISO100";
    101 const char QCameraParameters::ISO_200[] = "ISO200";
    102 const char QCameraParameters::ISO_400[] = "ISO400";
    103 const char QCameraParameters::ISO_800[] = "ISO800";
    104 const char QCameraParameters::ISO_1600[] = "ISO1600";
    105 
    106  //Values for Lens Shading
    107 const char QCameraParameters::LENSSHADE_ENABLE[] = "enable";
    108 const char QCameraParameters::LENSSHADE_DISABLE[] = "disable";
    109 
    110 // Values for auto exposure settings.
    111 const char QCameraParameters::AUTO_EXPOSURE_FRAME_AVG[] = "frame-average";
    112 const char QCameraParameters::AUTO_EXPOSURE_CENTER_WEIGHTED[] = "center-weighted";
    113 const char QCameraParameters::AUTO_EXPOSURE_SPOT_METERING[] = "spot-metering";
    114 
    115 const char QCameraParameters::KEY_GPS_LATITUDE_REF[] = "gps-latitude-ref";
    116 const char QCameraParameters::KEY_GPS_LONGITUDE_REF[] = "gps-longitude-ref";
    117 const char QCameraParameters::KEY_GPS_ALTITUDE_REF[] = "gps-altitude-ref";
    118 const char QCameraParameters::KEY_GPS_STATUS[] = "gps-status";
    119 const char QCameraParameters::KEY_EXIF_DATETIME[] = "exif-datetime";
    120 
    121 const char QCameraParameters::KEY_HISTOGRAM[] = "histogram";
    122 const char QCameraParameters::KEY_SUPPORTED_HISTOGRAM_MODES[] = "histogram-values";
    123 
    124 //Values for Histogram Shading
    125 const char QCameraParameters::HISTOGRAM_ENABLE[] = "enable";
    126 const char QCameraParameters::HISTOGRAM_DISABLE[] = "disable";
    127 
    128 //Values for Skin Tone Enhancement Modes
    129 const char QCameraParameters::SKIN_TONE_ENHANCEMENT_ENABLE[] = "enable";
    130 const char QCameraParameters::SKIN_TONE_ENHANCEMENT_DISABLE[] = "disable";
    131 
    132 const char QCameraParameters::KEY_SHARPNESS[] = "sharpness";
    133 const char QCameraParameters::KEY_MAX_SHARPNESS[] = "max-sharpness";
    134 const char QCameraParameters::KEY_CONTRAST[] = "contrast";
    135 const char QCameraParameters::KEY_MAX_CONTRAST[] = "max-contrast";
    136 const char QCameraParameters::KEY_SATURATION[] = "saturation";
    137 const char QCameraParameters::KEY_MAX_SATURATION[] = "max-saturation";
    138 
    139 const char QCameraParameters::KEY_SINGLE_ISP_OUTPUT_ENABLED[] = "single-isp-output-enabled";
    140 const char QCameraParameters::KEY_SUPPORTED_CAMERA_FEATURES[] = "qc-camera-features";
    141 const char QCameraParameters::KEY_MAX_NUM_REQUESTED_FACES[] = "qc-max-num-requested-faces";
    142 
    143 //Values for DENOISE
    144 const char QCameraParameters::DENOISE_OFF[] = "denoise-off";
    145 const char QCameraParameters::DENOISE_ON[] = "denoise-on";
    146 
    147 // Values for selectable zone af Settings
    148 const char QCameraParameters::SELECTABLE_ZONE_AF_AUTO[] = "auto";
    149 const char QCameraParameters::SELECTABLE_ZONE_AF_SPOT_METERING[] = "spot-metering";
    150 const char QCameraParameters::SELECTABLE_ZONE_AF_CENTER_WEIGHTED[] = "center-weighted";
    151 const char QCameraParameters::SELECTABLE_ZONE_AF_FRAME_AVERAGE[] = "frame-average";
    152 
    153 // Values for Face Detection settings.
    154 const char QCameraParameters::FACE_DETECTION_OFF[] = "off";
    155 const char QCameraParameters::FACE_DETECTION_ON[] = "on";
    156 
    157 // Values for MCE settings.
    158 const char QCameraParameters::MCE_ENABLE[] = "enable";
    159 const char QCameraParameters::MCE_DISABLE[] = "disable";
    160 
    161 // Values for HFR settings.
    162 const char QCameraParameters::VIDEO_HFR_OFF[] = "off";
    163 const char QCameraParameters::VIDEO_HFR_2X[] = "60";
    164 const char QCameraParameters::VIDEO_HFR_3X[] = "90";
    165 const char QCameraParameters::VIDEO_HFR_4X[] = "120";
    166 
    167 // Values for Redeye Reduction settings.
    168 const char QCameraParameters::REDEYE_REDUCTION_ENABLE[] = "enable";
    169 const char QCameraParameters::REDEYE_REDUCTION_DISABLE[] = "disable";
    170 
    171 // Values for HDR settings.
    172 const char QCameraParameters::HDR_ENABLE[] = "enable";
    173 const char QCameraParameters::HDR_DISABLE[] = "disable";
    174 
    175 // Values for ZSL settings.
    176 const char QCameraParameters::ZSL_OFF[] = "off";
    177 const char QCameraParameters::ZSL_ON[] = "on";
    178 
    179 // Values for HDR Bracketing settings.
    180 const char QCameraParameters::AE_BRACKET_HDR_OFF[] = "Off";
    181 const char QCameraParameters::AE_BRACKET_HDR[] = "HDR";
    182 const char QCameraParameters::AE_BRACKET[] = "AE-Bracket";
    183 
    184 const char QCameraParameters::LOW_POWER[] = "Low_Power";
    185 const char QCameraParameters::NORMAL_POWER[] = "Normal_Power";
    186 
    187 static const char* portrait = "portrait";
    188 static const char* landscape = "landscape";
    189 
    190 //QCameraParameters::QCameraParameters()
    191 //                : mMap()
    192 //{
    193 //}
    194 
    195 QCameraParameters::~QCameraParameters()
    196 {
    197 }
    198 
    199 int QCameraParameters::getOrientation() const
    200 {
    201     const char* orientation = get("orientation");
    202     if (orientation && !strcmp(orientation, portrait))
    203         return CAMERA_ORIENTATION_PORTRAIT;
    204     return CAMERA_ORIENTATION_LANDSCAPE;
    205 }
    206 void QCameraParameters::setOrientation(int orientation)
    207 {
    208     if (orientation == CAMERA_ORIENTATION_PORTRAIT) {
    209         set("orientation", portrait);
    210     } else {
    211          set("orientation", landscape);
    212     }
    213 }
    214 
    215         //XXX ALOGE("Key \"%s\"contains invalid character (= or ;)", key);
    216         //XXX ALOGE("Value \"%s\"contains invalid character (= or ;)", value);
    217     //snprintf(str, sizeof(str), "%d", value);
    218         //ALOGE("Cannot find delimeter (%c) in str=%s", delim, str);
    219 
    220 
    221 // Parse string like "(1, 2, 3, 4, ..., N)"
    222 // num is pointer to an allocated array of size N
    223 static int parseNDimVector(const char *str, int *num, int N, char delim = ',')
    224 {
    225     char *start, *end;
    226     if(num == NULL) {
    227         ALOGE("Invalid output array (num == NULL)");
    228         return -1;
    229     }
    230     //check if string starts and ends with parantheses
    231     if(str[0] != '(' || str[strlen(str)-1] != ')') {
    232         ALOGE("Invalid format of string %s, valid format is (n1, n2, n3, n4 ...)", str);
    233         return -1;
    234     }
    235     start = (char*) str;
    236     start++;
    237     for(int i=0; i<N; i++) {
    238         *(num+i) = (int) strtol(start, &end, 10);
    239         if(*end != delim && i < N-1) {
    240             ALOGE("Cannot find delimeter '%c' in string \"%s\". end = %c", delim, str, *end);
    241             return -1;
    242         }
    243         start = end+1;
    244     }
    245     return 0;
    246 }
    247 
    248 
    249             //ALOGE("Picture sizes string \"%s\" contains invalid character.", sizesStr);
    250     //snprintf(str, sizeof(str), "%dx%d", width, height);
    251 
    252 
    253 
    254 // Parse string like "640x480" or "10000,20000"
    255 static int parse_pair(const char *str, int *first, int *second, char delim,
    256                       char **endptr = NULL)
    257 {
    258     // Find the first integer.
    259     char *end;
    260     int w = (int)strtol(str, &end, 10);
    261     // If a delimeter does not immediately follow, give up.
    262     if (*end != delim) {
    263         ALOGE("Cannot find delimeter (%c) in str=%s", delim, str);
    264         return -1;
    265     }
    266 
    267     // Find the second integer, immediately after the delimeter.
    268     int h = (int)strtol(end+1, &end, 10);
    269 
    270     *first = w;
    271     *second = h;
    272 
    273     if (endptr) {
    274         *endptr = end;
    275     }
    276 
    277     return 0;
    278 }
    279 
    280 static void parseSizesList(const char *sizesStr, Vector<Size> &sizes)
    281 {
    282     if (sizesStr == 0) {
    283         return;
    284     }
    285 
    286     char *sizeStartPtr = (char *)sizesStr;
    287 
    288     while (true) {
    289         int width, height;
    290         int success = parse_pair(sizeStartPtr, &width, &height, 'x',
    291                                  &sizeStartPtr);
    292         if (success == -1 || (*sizeStartPtr != ',' && *sizeStartPtr != '\0')) {
    293             ALOGE("Picture sizes string \"%s\" contains invalid character.", sizesStr);
    294             return;
    295         }
    296         sizes.push(Size(width, height));
    297 
    298         if (*sizeStartPtr == '\0') {
    299             return;
    300         }
    301         sizeStartPtr++;
    302     }
    303 }
    304 
    305 
    306 void QCameraParameters::getSupportedHfrSizes(Vector<Size> &sizes) const
    307 {
    308     const char *hfrSizesStr = get(KEY_SUPPORTED_HFR_SIZES);
    309     parseSizesList(hfrSizesStr, sizes);
    310 }
    311 
    312 void QCameraParameters::setPreviewFpsRange(int minFPS, int maxFPS)
    313 {
    314     char str[32];
    315     snprintf(str, sizeof(str), "%d,%d",minFPS,maxFPS);
    316     set(KEY_PREVIEW_FPS_RANGE,str);
    317 }
    318 
    319 void QCameraParameters::setPreviewFrameRateMode(const char *mode)
    320 {
    321     set(KEY_PREVIEW_FRAME_RATE_MODE, mode);
    322 }
    323 
    324 const char *QCameraParameters::getPreviewFrameRateMode() const
    325 {
    326     return get(KEY_PREVIEW_FRAME_RATE_MODE);
    327 }
    328 
    329 
    330     //ALOGD("dump: mMap.size = %d", mMap.size());
    331         //ALOGD("%s: %s\n", k.string(), v.string());
    332 
    333 
    334 
    335 void QCameraParameters::setTouchIndexAec(int x, int y)
    336 {
    337     char str[32];
    338     snprintf(str, sizeof(str), "%dx%d", x, y);
    339     set(KEY_TOUCH_INDEX_AEC, str);
    340 }
    341 
    342 void QCameraParameters::getTouchIndexAec(int *x, int *y) const
    343 {
    344     *x = -1;
    345     *y = -1;
    346 
    347     // Get the current string, if it doesn't exist, leave the -1x-1
    348     const char *p = get(KEY_TOUCH_INDEX_AEC);
    349     if (p == 0)
    350         return;
    351 
    352     int tempX, tempY;
    353     if (parse_pair(p, &tempX, &tempY, 'x') == 0) {
    354         *x = tempX;
    355         *y = tempY;
    356     }
    357 }
    358 
    359 void QCameraParameters::setTouchIndexAf(int x, int y)
    360 {
    361     char str[32];
    362     snprintf(str, sizeof(str), "%dx%d", x, y);
    363     set(KEY_TOUCH_INDEX_AF, str);
    364 }
    365 
    366 void QCameraParameters::getTouchIndexAf(int *x, int *y) const
    367 {
    368     *x = -1;
    369     *y = -1;
    370 
    371     // Get the current string, if it doesn't exist, leave the -1x-1
    372     const char *p = get(KEY_TOUCH_INDEX_AF);
    373     if (p == 0)
    374         return;
    375 
    376     int tempX, tempY;
    377     if (parse_pair(p, &tempX, &tempY, 'x') == 0) {
    378         *x = tempX;
    379         *y = tempY;
    380 	}
    381 }
    382 
    383 void QCameraParameters::getMeteringAreaCenter(int *x, int *y) const
    384 {
    385     //Default invalid values
    386     *x = -2000;
    387     *y = -2000;
    388 
    389     const char *p = get(KEY_METERING_AREAS);
    390     if(p != NULL) {
    391         int arr[5] = {-2000, -2000, -2000, -2000, 0};
    392         parseNDimVector(p, arr, 5); //p = "(x1, y1, x2, y2, weight)"
    393         *x = (arr[0] + arr[2])/2; //center_x = (x1+x2)/2
    394         *y = (arr[1] + arr[3])/2; //center_y = (y1+y2)/2
    395     }
    396 }
    397 
    398 
    399 }; // namespace android
    400 
    401