The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | ** |
| 3 | ** Copyright 2008, The Android Open Source Project |
| 4 | ** |
Wu-cheng Li | 8de57d8 | 2009-09-23 14:37:52 -0700 | [diff] [blame] | 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 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8 | ** |
Wu-cheng Li | 8de57d8 | 2009-09-23 14:37:52 -0700 | [diff] [blame] | 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10 | ** |
Wu-cheng Li | 8de57d8 | 2009-09-23 14:37:52 -0700 | [diff] [blame] | 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 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #define LOG_TAG "CameraParams" |
| 19 | #include <utils/Log.h> |
| 20 | |
| 21 | #include <string.h> |
| 22 | #include <stdlib.h> |
Mathias Agopian | 000479f | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 23 | #include <camera/CameraParameters.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | |
| 25 | namespace android { |
Wu-cheng Li | 8de57d8 | 2009-09-23 14:37:52 -0700 | [diff] [blame] | 26 | // Parameter keys to communicate between camera application and driver. |
| 27 | const char CameraParameters::KEY_PREVIEW_SIZE[] = "preview-size"; |
| 28 | const char CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES[] = "preview-size-values"; |
| 29 | const char CameraParameters::KEY_PREVIEW_FORMAT[] = "preview-format"; |
| 30 | const char CameraParameters::KEY_SUPPORTED_PREVIEW_FORMATS[] = "preview-format-values"; |
| 31 | const char CameraParameters::KEY_PREVIEW_FRAME_RATE[] = "preview-frame-rate"; |
| 32 | const char CameraParameters::KEY_SUPPORTED_PREVIEW_FRAME_RATES[] = "preview-frame-rate-values"; |
| 33 | const char CameraParameters::KEY_PICTURE_SIZE[] = "picture-size"; |
| 34 | const char CameraParameters::KEY_SUPPORTED_PICTURE_SIZES[] = "picture-size-values"; |
| 35 | const char CameraParameters::KEY_PICTURE_FORMAT[] = "picture-format"; |
| 36 | const char CameraParameters::KEY_SUPPORTED_PICTURE_FORMATS[] = "picture-format-values"; |
| 37 | const char CameraParameters::KEY_JPEG_THUMBNAIL_WIDTH[] = "jpeg-thumbnail-width"; |
| 38 | const char CameraParameters::KEY_JPEG_THUMBNAIL_HEIGHT[] = "jpeg-thumbnail-height"; |
Wu-cheng Li | acf7703 | 2010-01-25 15:18:18 +0800 | [diff] [blame] | 39 | const char CameraParameters::KEY_SUPPORTED_JPEG_THUMBNAIL_SIZES[] = "jpeg-thumbnail-size-values"; |
Wu-cheng Li | 8de57d8 | 2009-09-23 14:37:52 -0700 | [diff] [blame] | 40 | const char CameraParameters::KEY_JPEG_THUMBNAIL_QUALITY[] = "jpeg-thumbnail-quality"; |
| 41 | const char CameraParameters::KEY_JPEG_QUALITY[] = "jpeg-quality"; |
| 42 | const char CameraParameters::KEY_ROTATION[] = "rotation"; |
| 43 | const char CameraParameters::KEY_GPS_LATITUDE[] = "gps-latitude"; |
| 44 | const char CameraParameters::KEY_GPS_LONGITUDE[] = "gps-longitude"; |
| 45 | const char CameraParameters::KEY_GPS_ALTITUDE[] = "gps-altitude"; |
| 46 | const char CameraParameters::KEY_GPS_TIMESTAMP[] = "gps-timestamp"; |
Ray Chen | 055c986 | 2010-02-23 10:45:42 +0800 | [diff] [blame] | 47 | const char CameraParameters::KEY_GPS_PROCESSING_METHOD[] = "gps-processing-method"; |
Wu-cheng Li | 8de57d8 | 2009-09-23 14:37:52 -0700 | [diff] [blame] | 48 | const char CameraParameters::KEY_WHITE_BALANCE[] = "whitebalance"; |
| 49 | const char CameraParameters::KEY_SUPPORTED_WHITE_BALANCE[] = "whitebalance-values"; |
| 50 | const char CameraParameters::KEY_EFFECT[] = "effect"; |
| 51 | const char CameraParameters::KEY_SUPPORTED_EFFECTS[] = "effect-values"; |
| 52 | const char CameraParameters::KEY_ANTIBANDING[] = "antibanding"; |
| 53 | const char CameraParameters::KEY_SUPPORTED_ANTIBANDING[] = "antibanding-values"; |
| 54 | const char CameraParameters::KEY_SCENE_MODE[] = "scene-mode"; |
| 55 | const char CameraParameters::KEY_SUPPORTED_SCENE_MODES[] = "scene-mode-values"; |
| 56 | const char CameraParameters::KEY_FLASH_MODE[] = "flash-mode"; |
| 57 | const char CameraParameters::KEY_SUPPORTED_FLASH_MODES[] = "flash-mode-values"; |
| 58 | const char CameraParameters::KEY_FOCUS_MODE[] = "focus-mode"; |
| 59 | const char CameraParameters::KEY_SUPPORTED_FOCUS_MODES[] = "focus-mode-values"; |
Wu-cheng Li | 6c8d276 | 2010-01-27 22:55:14 +0800 | [diff] [blame] | 60 | const char CameraParameters::KEY_FOCAL_LENGTH[] = "focal-length"; |
| 61 | const char CameraParameters::KEY_HORIZONTAL_VIEW_ANGLE[] = "horizontal-view-angle"; |
| 62 | const char CameraParameters::KEY_VERTICAL_VIEW_ANGLE[] = "vertical-view-angle"; |
Wu-cheng Li | ff723b6 | 2010-02-09 13:38:19 +0800 | [diff] [blame] | 63 | const char CameraParameters::KEY_EXPOSURE_COMPENSATION[] = "exposure-compensation"; |
Wu-cheng Li | 24b326a | 2010-02-20 17:47:04 +0800 | [diff] [blame] | 64 | const char CameraParameters::KEY_MAX_EXPOSURE_COMPENSATION[] = "max-exposure-compensation"; |
| 65 | const char CameraParameters::KEY_MIN_EXPOSURE_COMPENSATION[] = "min-exposure-compensation"; |
| 66 | const char CameraParameters::KEY_EXPOSURE_COMPENSATION_STEP[] = "exposure-compensation-step"; |
Wu-cheng Li | 8cbb8f5 | 2010-02-28 23:19:55 -0800 | [diff] [blame] | 67 | const char CameraParameters::KEY_ZOOM[] = "zoom"; |
| 68 | const char CameraParameters::KEY_MAX_ZOOM[] = "max-zoom"; |
| 69 | const char CameraParameters::KEY_ZOOM_RATIOS[] = "zoom-ratios"; |
| 70 | const char CameraParameters::KEY_ZOOM_SUPPORTED[] = "zoom-supported"; |
| 71 | const char CameraParameters::KEY_SMOOTH_ZOOM_SUPPORTED[] = "smooth-zoom-supported"; |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame^] | 72 | const char CameraParameters::KEY_FOCUS_DISTANCES[] = "focus-distances"; |
Wu-cheng Li | 8de57d8 | 2009-09-23 14:37:52 -0700 | [diff] [blame] | 73 | |
Wu-cheng Li | d9ef5d7 | 2010-03-08 15:28:48 -0800 | [diff] [blame] | 74 | const char CameraParameters::TRUE[] = "true"; |
Wu-cheng Li | e339c5e | 2010-05-13 19:31:02 +0800 | [diff] [blame^] | 75 | const char CameraParameters::INFINITY[] = "Infinity"; |
Wu-cheng Li | d9ef5d7 | 2010-03-08 15:28:48 -0800 | [diff] [blame] | 76 | |
Wu-cheng Li | 8de57d8 | 2009-09-23 14:37:52 -0700 | [diff] [blame] | 77 | // Values for white balance settings. |
| 78 | const char CameraParameters::WHITE_BALANCE_AUTO[] = "auto"; |
| 79 | const char CameraParameters::WHITE_BALANCE_INCANDESCENT[] = "incandescent"; |
| 80 | const char CameraParameters::WHITE_BALANCE_FLUORESCENT[] = "fluorescent"; |
| 81 | const char CameraParameters::WHITE_BALANCE_WARM_FLUORESCENT[] = "warm-fluorescent"; |
| 82 | const char CameraParameters::WHITE_BALANCE_DAYLIGHT[] = "daylight"; |
| 83 | const char CameraParameters::WHITE_BALANCE_CLOUDY_DAYLIGHT[] = "cloudy-daylight"; |
| 84 | const char CameraParameters::WHITE_BALANCE_TWILIGHT[] = "twilight"; |
| 85 | const char CameraParameters::WHITE_BALANCE_SHADE[] = "shade"; |
| 86 | |
| 87 | // Values for effect settings. |
| 88 | const char CameraParameters::EFFECT_NONE[] = "none"; |
| 89 | const char CameraParameters::EFFECT_MONO[] = "mono"; |
| 90 | const char CameraParameters::EFFECT_NEGATIVE[] = "negative"; |
| 91 | const char CameraParameters::EFFECT_SOLARIZE[] = "solarize"; |
| 92 | const char CameraParameters::EFFECT_SEPIA[] = "sepia"; |
| 93 | const char CameraParameters::EFFECT_POSTERIZE[] = "posterize"; |
| 94 | const char CameraParameters::EFFECT_WHITEBOARD[] = "whiteboard"; |
| 95 | const char CameraParameters::EFFECT_BLACKBOARD[] = "blackboard"; |
| 96 | const char CameraParameters::EFFECT_AQUA[] = "aqua"; |
| 97 | |
| 98 | // Values for antibanding settings. |
| 99 | const char CameraParameters::ANTIBANDING_AUTO[] = "auto"; |
| 100 | const char CameraParameters::ANTIBANDING_50HZ[] = "50hz"; |
| 101 | const char CameraParameters::ANTIBANDING_60HZ[] = "60hz"; |
| 102 | const char CameraParameters::ANTIBANDING_OFF[] = "off"; |
| 103 | |
| 104 | // Values for flash mode settings. |
| 105 | const char CameraParameters::FLASH_MODE_OFF[] = "off"; |
| 106 | const char CameraParameters::FLASH_MODE_AUTO[] = "auto"; |
| 107 | const char CameraParameters::FLASH_MODE_ON[] = "on"; |
| 108 | const char CameraParameters::FLASH_MODE_RED_EYE[] = "red-eye"; |
Wu-cheng Li | fe1a86d | 2009-09-28 13:51:12 -0700 | [diff] [blame] | 109 | const char CameraParameters::FLASH_MODE_TORCH[] = "torch"; |
Wu-cheng Li | 8de57d8 | 2009-09-23 14:37:52 -0700 | [diff] [blame] | 110 | |
| 111 | // Values for scene mode settings. |
| 112 | const char CameraParameters::SCENE_MODE_AUTO[] = "auto"; |
| 113 | const char CameraParameters::SCENE_MODE_ACTION[] = "action"; |
| 114 | const char CameraParameters::SCENE_MODE_PORTRAIT[] = "portrait"; |
| 115 | const char CameraParameters::SCENE_MODE_LANDSCAPE[] = "landscape"; |
| 116 | const char CameraParameters::SCENE_MODE_NIGHT[] = "night"; |
| 117 | const char CameraParameters::SCENE_MODE_NIGHT_PORTRAIT[] = "night-portrait"; |
| 118 | const char CameraParameters::SCENE_MODE_THEATRE[] = "theatre"; |
| 119 | const char CameraParameters::SCENE_MODE_BEACH[] = "beach"; |
| 120 | const char CameraParameters::SCENE_MODE_SNOW[] = "snow"; |
| 121 | const char CameraParameters::SCENE_MODE_SUNSET[] = "sunset"; |
| 122 | const char CameraParameters::SCENE_MODE_STEADYPHOTO[] = "steadyphoto"; |
| 123 | const char CameraParameters::SCENE_MODE_FIREWORKS[] = "fireworks"; |
| 124 | const char CameraParameters::SCENE_MODE_SPORTS[] = "sports"; |
| 125 | const char CameraParameters::SCENE_MODE_PARTY[] = "party"; |
| 126 | const char CameraParameters::SCENE_MODE_CANDLELIGHT[] = "candlelight"; |
Wu-cheng Li | c58b423 | 2010-03-29 17:21:28 +0800 | [diff] [blame] | 127 | const char CameraParameters::SCENE_MODE_BARCODE[] = "barcode"; |
Wu-cheng Li | 8de57d8 | 2009-09-23 14:37:52 -0700 | [diff] [blame] | 128 | |
| 129 | // Formats for setPreviewFormat and setPictureFormat. |
| 130 | const char CameraParameters::PIXEL_FORMAT_YUV422SP[] = "yuv422sp"; |
| 131 | const char CameraParameters::PIXEL_FORMAT_YUV420SP[] = "yuv420sp"; |
| 132 | const char CameraParameters::PIXEL_FORMAT_YUV422I[] = "yuv422i-yuyv"; |
| 133 | const char CameraParameters::PIXEL_FORMAT_RGB565[] = "rgb565"; |
| 134 | const char CameraParameters::PIXEL_FORMAT_JPEG[] = "jpeg"; |
| 135 | |
| 136 | // Values for focus mode settings. |
| 137 | const char CameraParameters::FOCUS_MODE_AUTO[] = "auto"; |
| 138 | const char CameraParameters::FOCUS_MODE_INFINITY[] = "infinity"; |
| 139 | const char CameraParameters::FOCUS_MODE_MACRO[] = "macro"; |
| 140 | const char CameraParameters::FOCUS_MODE_FIXED[] = "fixed"; |
Wu-cheng Li | c58b423 | 2010-03-29 17:21:28 +0800 | [diff] [blame] | 141 | const char CameraParameters::FOCUS_MODE_EDOF[] = "edof"; |
Wu-cheng Li | ca09961 | 2010-05-06 16:47:30 +0800 | [diff] [blame] | 142 | const char CameraParameters::FOCUS_MODE_CONTINUOUS[] = "continuous"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 143 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 144 | CameraParameters::CameraParameters() |
| 145 | : mMap() |
| 146 | { |
| 147 | } |
| 148 | |
| 149 | CameraParameters::~CameraParameters() |
| 150 | { |
| 151 | } |
| 152 | |
| 153 | String8 CameraParameters::flatten() const |
| 154 | { |
| 155 | String8 flattened(""); |
| 156 | size_t size = mMap.size(); |
| 157 | |
| 158 | for (size_t i = 0; i < size; i++) { |
| 159 | String8 k, v; |
| 160 | k = mMap.keyAt(i); |
| 161 | v = mMap.valueAt(i); |
| 162 | |
| 163 | flattened += k; |
| 164 | flattened += "="; |
| 165 | flattened += v; |
| 166 | if (i != size-1) |
| 167 | flattened += ";"; |
| 168 | } |
| 169 | |
| 170 | return flattened; |
| 171 | } |
| 172 | |
| 173 | void CameraParameters::unflatten(const String8 ¶ms) |
| 174 | { |
| 175 | const char *a = params.string(); |
| 176 | const char *b; |
| 177 | |
| 178 | mMap.clear(); |
| 179 | |
| 180 | for (;;) { |
| 181 | // Find the bounds of the key name. |
| 182 | b = strchr(a, '='); |
| 183 | if (b == 0) |
| 184 | break; |
| 185 | |
| 186 | // Create the key string. |
| 187 | String8 k(a, (size_t)(b-a)); |
| 188 | |
| 189 | // Find the value. |
| 190 | a = b+1; |
| 191 | b = strchr(a, ';'); |
| 192 | if (b == 0) { |
| 193 | // If there's no semicolon, this is the last item. |
| 194 | String8 v(a); |
| 195 | mMap.add(k, v); |
| 196 | break; |
| 197 | } |
| 198 | |
| 199 | String8 v(a, (size_t)(b-a)); |
| 200 | mMap.add(k, v); |
| 201 | a = b+1; |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | |
| 206 | void CameraParameters::set(const char *key, const char *value) |
| 207 | { |
Wu-cheng Li | 8de57d8 | 2009-09-23 14:37:52 -0700 | [diff] [blame] | 208 | // XXX i think i can do this with strspn() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 209 | if (strchr(key, '=') || strchr(key, ';')) { |
| 210 | //XXX LOGE("Key \"%s\"contains invalid character (= or ;)", key); |
| 211 | return; |
| 212 | } |
| 213 | |
| 214 | if (strchr(value, '=') || strchr(key, ';')) { |
| 215 | //XXX LOGE("Value \"%s\"contains invalid character (= or ;)", value); |
| 216 | return; |
| 217 | } |
| 218 | |
| 219 | mMap.replaceValueFor(String8(key), String8(value)); |
| 220 | } |
| 221 | |
| 222 | void CameraParameters::set(const char *key, int value) |
| 223 | { |
| 224 | char str[16]; |
| 225 | sprintf(str, "%d", value); |
| 226 | set(key, str); |
| 227 | } |
| 228 | |
Wu-cheng Li | 7eae31c | 2010-01-31 14:19:38 +0800 | [diff] [blame] | 229 | void CameraParameters::setFloat(const char *key, float value) |
| 230 | { |
| 231 | char str[16]; // 14 should be enough. We overestimate to be safe. |
| 232 | snprintf(str, sizeof(str), "%g", value); |
| 233 | set(key, str); |
| 234 | } |
| 235 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 236 | const char *CameraParameters::get(const char *key) const |
| 237 | { |
| 238 | String8 v = mMap.valueFor(String8(key)); |
| 239 | if (v.length() == 0) |
| 240 | return 0; |
| 241 | return v.string(); |
| 242 | } |
| 243 | |
| 244 | int CameraParameters::getInt(const char *key) const |
| 245 | { |
| 246 | const char *v = get(key); |
| 247 | if (v == 0) |
| 248 | return -1; |
| 249 | return strtol(v, 0, 0); |
| 250 | } |
| 251 | |
Wu-cheng Li | 7eae31c | 2010-01-31 14:19:38 +0800 | [diff] [blame] | 252 | float CameraParameters::getFloat(const char *key) const |
| 253 | { |
| 254 | const char *v = get(key); |
| 255 | if (v == 0) return -1; |
| 256 | return strtof(v, 0); |
| 257 | } |
| 258 | |
Wu-cheng Li | 78624e4 | 2010-05-11 12:11:56 +0800 | [diff] [blame] | 259 | void CameraParameters::remove(const char *key) |
| 260 | { |
| 261 | mMap.removeItem(String8(key)); |
| 262 | } |
| 263 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 264 | static int parse_size(const char *str, int &width, int &height) |
| 265 | { |
| 266 | // Find the width. |
| 267 | char *end; |
| 268 | int w = (int)strtol(str, &end, 10); |
| 269 | // If an 'x' does not immediately follow, give up. |
| 270 | if (*end != 'x') |
| 271 | return -1; |
| 272 | |
| 273 | // Find the height, immediately after the 'x'. |
| 274 | int h = (int)strtol(end+1, 0, 10); |
| 275 | |
| 276 | width = w; |
| 277 | height = h; |
| 278 | |
| 279 | return 0; |
| 280 | } |
| 281 | |
| 282 | void CameraParameters::setPreviewSize(int width, int height) |
| 283 | { |
| 284 | char str[32]; |
| 285 | sprintf(str, "%dx%d", width, height); |
Wu-cheng Li | 8de57d8 | 2009-09-23 14:37:52 -0700 | [diff] [blame] | 286 | set(KEY_PREVIEW_SIZE, str); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | void CameraParameters::getPreviewSize(int *width, int *height) const |
| 290 | { |
| 291 | *width = -1; |
| 292 | *height = -1; |
| 293 | |
| 294 | // Get the current string, if it doesn't exist, leave the -1x-1 |
Wu-cheng Li | 8de57d8 | 2009-09-23 14:37:52 -0700 | [diff] [blame] | 295 | const char *p = get(KEY_PREVIEW_SIZE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 296 | if (p == 0) |
| 297 | return; |
| 298 | |
| 299 | int w, h; |
| 300 | if (parse_size(p, w, h) == 0) { |
| 301 | *width = w; |
| 302 | *height = h; |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | void CameraParameters::setPreviewFrameRate(int fps) |
| 307 | { |
Wu-cheng Li | 8de57d8 | 2009-09-23 14:37:52 -0700 | [diff] [blame] | 308 | set(KEY_PREVIEW_FRAME_RATE, fps); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | int CameraParameters::getPreviewFrameRate() const |
| 312 | { |
Wu-cheng Li | 8de57d8 | 2009-09-23 14:37:52 -0700 | [diff] [blame] | 313 | return getInt(KEY_PREVIEW_FRAME_RATE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | void CameraParameters::setPreviewFormat(const char *format) |
| 317 | { |
Wu-cheng Li | 8de57d8 | 2009-09-23 14:37:52 -0700 | [diff] [blame] | 318 | set(KEY_PREVIEW_FORMAT, format); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 319 | } |
| 320 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 321 | const char *CameraParameters::getPreviewFormat() const |
| 322 | { |
Wu-cheng Li | 8de57d8 | 2009-09-23 14:37:52 -0700 | [diff] [blame] | 323 | return get(KEY_PREVIEW_FORMAT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | void CameraParameters::setPictureSize(int width, int height) |
| 327 | { |
| 328 | char str[32]; |
| 329 | sprintf(str, "%dx%d", width, height); |
Wu-cheng Li | 8de57d8 | 2009-09-23 14:37:52 -0700 | [diff] [blame] | 330 | set(KEY_PICTURE_SIZE, str); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | void CameraParameters::getPictureSize(int *width, int *height) const |
| 334 | { |
| 335 | *width = -1; |
| 336 | *height = -1; |
| 337 | |
| 338 | // Get the current string, if it doesn't exist, leave the -1x-1 |
Wu-cheng Li | 8de57d8 | 2009-09-23 14:37:52 -0700 | [diff] [blame] | 339 | const char *p = get(KEY_PICTURE_SIZE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 340 | if (p == 0) |
| 341 | return; |
| 342 | |
| 343 | int w, h; |
| 344 | if (parse_size(p, w, h) == 0) { |
| 345 | *width = w; |
| 346 | *height = h; |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | void CameraParameters::setPictureFormat(const char *format) |
| 351 | { |
Wu-cheng Li | 8de57d8 | 2009-09-23 14:37:52 -0700 | [diff] [blame] | 352 | set(KEY_PICTURE_FORMAT, format); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | const char *CameraParameters::getPictureFormat() const |
| 356 | { |
Wu-cheng Li | 8de57d8 | 2009-09-23 14:37:52 -0700 | [diff] [blame] | 357 | return get(KEY_PICTURE_FORMAT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | void CameraParameters::dump() const |
| 361 | { |
| 362 | LOGD("dump: mMap.size = %d", mMap.size()); |
| 363 | for (size_t i = 0; i < mMap.size(); i++) { |
| 364 | String8 k, v; |
| 365 | k = mMap.keyAt(i); |
| 366 | v = mMap.valueAt(i); |
| 367 | LOGD("%s: %s\n", k.string(), v.string()); |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | status_t CameraParameters::dump(int fd, const Vector<String16>& args) const |
| 372 | { |
| 373 | const size_t SIZE = 256; |
| 374 | char buffer[SIZE]; |
| 375 | String8 result; |
| 376 | snprintf(buffer, 255, "CameraParameters::dump: mMap.size = %d\n", mMap.size()); |
| 377 | result.append(buffer); |
| 378 | for (size_t i = 0; i < mMap.size(); i++) { |
| 379 | String8 k, v; |
| 380 | k = mMap.keyAt(i); |
| 381 | v = mMap.valueAt(i); |
| 382 | snprintf(buffer, 255, "\t%s: %s\n", k.string(), v.string()); |
| 383 | result.append(buffer); |
| 384 | } |
| 385 | write(fd, result.string(), result.size()); |
| 386 | return NO_ERROR; |
| 387 | } |
| 388 | |
| 389 | }; // namespace android |