AndroidCamera2Capabilities.java revision a97b7d1192e246a5f738991adca37cce282e1382
1a0842b40441db5332a5290f941021636b1182761Sol Boucher/* 2a0842b40441db5332a5290f941021636b1182761Sol Boucher * Copyright (C) 2014 The Android Open Source Project 3a0842b40441db5332a5290f941021636b1182761Sol Boucher * 4a0842b40441db5332a5290f941021636b1182761Sol Boucher * Licensed under the Apache License, Version 2.0 (the "License"); 5a0842b40441db5332a5290f941021636b1182761Sol Boucher * you may not use this file except in compliance with the License. 6a0842b40441db5332a5290f941021636b1182761Sol Boucher * You may obtain a copy of the License at 7a0842b40441db5332a5290f941021636b1182761Sol Boucher * 8a0842b40441db5332a5290f941021636b1182761Sol Boucher * http://www.apache.org/licenses/LICENSE-2.0 9a0842b40441db5332a5290f941021636b1182761Sol Boucher * 10a0842b40441db5332a5290f941021636b1182761Sol Boucher * Unless required by applicable law or agreed to in writing, software 11a0842b40441db5332a5290f941021636b1182761Sol Boucher * distributed under the License is distributed on an "AS IS" BASIS, 12a0842b40441db5332a5290f941021636b1182761Sol Boucher * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13a0842b40441db5332a5290f941021636b1182761Sol Boucher * See the License for the specific language governing permissions and 14a0842b40441db5332a5290f941021636b1182761Sol Boucher * limitations under the License. 15a0842b40441db5332a5290f941021636b1182761Sol Boucher */ 16a0842b40441db5332a5290f941021636b1182761Sol Boucher 17a0842b40441db5332a5290f941021636b1182761Sol Boucherpackage com.android.ex.camera2.portability; 18a0842b40441db5332a5290f941021636b1182761Sol Boucher 19a0842b40441db5332a5290f941021636b1182761Sol Boucherimport static android.hardware.camera2.CameraCharacteristics.*; 20a0842b40441db5332a5290f941021636b1182761Sol Boucher 21a0842b40441db5332a5290f941021636b1182761Sol Boucherimport android.graphics.Point; 22a0842b40441db5332a5290f941021636b1182761Sol Boucherimport android.hardware.camera2.CameraCharacteristics; 23a0842b40441db5332a5290f941021636b1182761Sol Boucherimport android.hardware.camera2.params.StreamConfigurationMap; 24a0842b40441db5332a5290f941021636b1182761Sol Boucherimport android.media.ImageReader; 25a0842b40441db5332a5290f941021636b1182761Sol Boucherimport android.media.MediaRecorder; 26a0842b40441db5332a5290f941021636b1182761Sol Boucherimport android.util.Range; 27a0842b40441db5332a5290f941021636b1182761Sol Boucherimport android.util.Rational; 28a0842b40441db5332a5290f941021636b1182761Sol Boucherimport android.view.SurfaceHolder; 29a0842b40441db5332a5290f941021636b1182761Sol Boucher 30a0842b40441db5332a5290f941021636b1182761Sol Boucherimport com.android.ex.camera2.portability.debug.Log; 31a0842b40441db5332a5290f941021636b1182761Sol Boucher 32a0842b40441db5332a5290f941021636b1182761Sol Boucherimport java.util.ArrayList; 33a0842b40441db5332a5290f941021636b1182761Sol Boucherimport java.util.Arrays; 34a0842b40441db5332a5290f941021636b1182761Sol Boucher 35a0842b40441db5332a5290f941021636b1182761Sol Boucher/** 36a0842b40441db5332a5290f941021636b1182761Sol Boucher * The subclass of {@link CameraCapabilities} for Android Camera 2 API. 37a0842b40441db5332a5290f941021636b1182761Sol Boucher */ 38a0842b40441db5332a5290f941021636b1182761Sol Boucherpublic class AndroidCamera2Capabilities extends CameraCapabilities { 39a0842b40441db5332a5290f941021636b1182761Sol Boucher private static Log.Tag TAG = new Log.Tag("AndCam2Capabs"); 40a0842b40441db5332a5290f941021636b1182761Sol Boucher 41a0842b40441db5332a5290f941021636b1182761Sol Boucher private IntegralStringifier mIntStringifier; 42a0842b40441db5332a5290f941021636b1182761Sol Boucher 43a0842b40441db5332a5290f941021636b1182761Sol Boucher AndroidCamera2Capabilities(CameraCharacteristics p) { 44a0842b40441db5332a5290f941021636b1182761Sol Boucher super(new IntegralStringifier()); 45a0842b40441db5332a5290f941021636b1182761Sol Boucher mIntStringifier = (IntegralStringifier) getStringifier(); 46a0842b40441db5332a5290f941021636b1182761Sol Boucher 47a0842b40441db5332a5290f941021636b1182761Sol Boucher StreamConfigurationMap s = p.get(SCALER_STREAM_CONFIGURATION_MAP); 48a0842b40441db5332a5290f941021636b1182761Sol Boucher 49a0842b40441db5332a5290f941021636b1182761Sol Boucher for (Range<Integer> fpsRange : p.get(CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES)) { 50a0842b40441db5332a5290f941021636b1182761Sol Boucher mSupportedPreviewFpsRange.add(new int[] { fpsRange.getLower(), fpsRange.getUpper() }); 51a0842b40441db5332a5290f941021636b1182761Sol Boucher } 52a0842b40441db5332a5290f941021636b1182761Sol Boucher 53a0842b40441db5332a5290f941021636b1182761Sol Boucher // TODO: We only support SurfaceView preview rendering 54a0842b40441db5332a5290f941021636b1182761Sol Boucher mSupportedPreviewSizes.addAll(Size.buildListFromAndroidSizes(Arrays.asList( 55a0842b40441db5332a5290f941021636b1182761Sol Boucher s.getOutputSizes(SurfaceHolder.class)))); 56a0842b40441db5332a5290f941021636b1182761Sol Boucher for (int format : s.getOutputFormats()) { 57a0842b40441db5332a5290f941021636b1182761Sol Boucher mSupportedPreviewFormats.add(format); 58a0842b40441db5332a5290f941021636b1182761Sol Boucher } 59a0842b40441db5332a5290f941021636b1182761Sol Boucher 60a0842b40441db5332a5290f941021636b1182761Sol Boucher // TODO: We only support MediaRecorder videos capture 61a0842b40441db5332a5290f941021636b1182761Sol Boucher mSupportedVideoSizes.addAll(Size.buildListFromAndroidSizes(Arrays.asList( 62a0842b40441db5332a5290f941021636b1182761Sol Boucher s.getOutputSizes(MediaRecorder.class)))); 63a0842b40441db5332a5290f941021636b1182761Sol Boucher 64a0842b40441db5332a5290f941021636b1182761Sol Boucher // TODO: We only support ImageReader image capture 65a0842b40441db5332a5290f941021636b1182761Sol Boucher mSupportedPhotoSizes.addAll(Size.buildListFromAndroidSizes(Arrays.asList( 66a0842b40441db5332a5290f941021636b1182761Sol Boucher s.getOutputSizes(ImageReader.class)))); 67a0842b40441db5332a5290f941021636b1182761Sol Boucher mSupportedPhotoFormats.addAll(mSupportedPreviewFormats); 68a0842b40441db5332a5290f941021636b1182761Sol Boucher 69a0842b40441db5332a5290f941021636b1182761Sol Boucher buildSceneModes(p); 70a0842b40441db5332a5290f941021636b1182761Sol Boucher buildFlashModes(p); 71a0842b40441db5332a5290f941021636b1182761Sol Boucher buildFocusModes(p); 72a0842b40441db5332a5290f941021636b1182761Sol Boucher buildWhiteBalances(p); 73a0842b40441db5332a5290f941021636b1182761Sol Boucher // TODO: Populate mSupportedFeatures 74a0842b40441db5332a5290f941021636b1182761Sol Boucher 75a0842b40441db5332a5290f941021636b1182761Sol Boucher // TODO: Populate mPreferredPreviewSizeForVideo 76a0842b40441db5332a5290f941021636b1182761Sol Boucher 77a0842b40441db5332a5290f941021636b1182761Sol Boucher Range<Integer> ecRange = p.get(CONTROL_AE_COMPENSATION_RANGE); 78a0842b40441db5332a5290f941021636b1182761Sol Boucher mMinExposureCompensation = ecRange.getLower(); 79a0842b40441db5332a5290f941021636b1182761Sol Boucher mMaxExposureCompensation = ecRange.getUpper(); 80a0842b40441db5332a5290f941021636b1182761Sol Boucher 81a0842b40441db5332a5290f941021636b1182761Sol Boucher Rational ecStep = p.get(CONTROL_AE_COMPENSATION_STEP); 82a0842b40441db5332a5290f941021636b1182761Sol Boucher mExposureCompensationStep = (float) ecStep.getNumerator() / ecStep.getDenominator(); 83a0842b40441db5332a5290f941021636b1182761Sol Boucher 84a0842b40441db5332a5290f941021636b1182761Sol Boucher mMaxNumOfFacesSupported = p.get(STATISTICS_INFO_MAX_FACE_COUNT); 85a0842b40441db5332a5290f941021636b1182761Sol Boucher mMaxNumOfMeteringArea = p.get(CONTROL_MAX_REGIONS_AE); 86a0842b40441db5332a5290f941021636b1182761Sol Boucher 87a0842b40441db5332a5290f941021636b1182761Sol Boucher // TODO: Populate mMaxZoomRatio 88a0842b40441db5332a5290f941021636b1182761Sol Boucher // TODO: Populate mHorizontalViewAngle 89a0842b40441db5332a5290f941021636b1182761Sol Boucher // TODO: Populate mVerticalViewAngle 90a0842b40441db5332a5290f941021636b1182761Sol Boucher // TODO: Populate mZoomRatioList 91a0842b40441db5332a5290f941021636b1182761Sol Boucher // TODO: Populate mMaxZoomIndex 92a97b7d1192e246a5f738991adca37cce282e1382Sol Boucher 93a97b7d1192e246a5f738991adca37cce282e1382Sol Boucher if (supports(FocusMode.AUTO)) { 94a97b7d1192e246a5f738991adca37cce282e1382Sol Boucher mMaxNumOfFocusAreas = p.get(CONTROL_MAX_REGIONS_AF); 95a97b7d1192e246a5f738991adca37cce282e1382Sol Boucher if (mMaxNumOfFocusAreas > 0) { 96a97b7d1192e246a5f738991adca37cce282e1382Sol Boucher mSupportedFeatures.add(Feature.FOCUS_AREA); 97a97b7d1192e246a5f738991adca37cce282e1382Sol Boucher } 98a97b7d1192e246a5f738991adca37cce282e1382Sol Boucher } 99a97b7d1192e246a5f738991adca37cce282e1382Sol Boucher if (mMaxNumOfMeteringArea > 0) { 100a97b7d1192e246a5f738991adca37cce282e1382Sol Boucher mSupportedFeatures.add(Feature.METERING_AREA); 101a97b7d1192e246a5f738991adca37cce282e1382Sol Boucher } 102a0842b40441db5332a5290f941021636b1182761Sol Boucher } 103a0842b40441db5332a5290f941021636b1182761Sol Boucher 104a0842b40441db5332a5290f941021636b1182761Sol Boucher public IntegralStringifier getIntegralStringifier() { 105a0842b40441db5332a5290f941021636b1182761Sol Boucher return mIntStringifier; 106a0842b40441db5332a5290f941021636b1182761Sol Boucher } 107a0842b40441db5332a5290f941021636b1182761Sol Boucher 108a0842b40441db5332a5290f941021636b1182761Sol Boucher private void buildSceneModes(CameraCharacteristics p) { 109a0842b40441db5332a5290f941021636b1182761Sol Boucher for (int scene : p.get(CONTROL_AVAILABLE_SCENE_MODES)) { 110a0842b40441db5332a5290f941021636b1182761Sol Boucher SceneMode equiv = mIntStringifier.sceneModeFromInt(scene); 111a0842b40441db5332a5290f941021636b1182761Sol Boucher if (equiv != SceneMode.NO_SCENE_MODE) { 112a0842b40441db5332a5290f941021636b1182761Sol Boucher // equiv isn't a default generated because we couldn't handle this mode, so add it 113a0842b40441db5332a5290f941021636b1182761Sol Boucher mSupportedSceneModes.add(equiv); 114a0842b40441db5332a5290f941021636b1182761Sol Boucher } 115a0842b40441db5332a5290f941021636b1182761Sol Boucher } 116a0842b40441db5332a5290f941021636b1182761Sol Boucher } 117a0842b40441db5332a5290f941021636b1182761Sol Boucher 118a0842b40441db5332a5290f941021636b1182761Sol Boucher private void buildFlashModes(CameraCharacteristics p) { 119a0842b40441db5332a5290f941021636b1182761Sol Boucher mSupportedFlashModes.add(FlashMode.OFF); 120a0842b40441db5332a5290f941021636b1182761Sol Boucher if (p.get(FLASH_INFO_AVAILABLE)) { 121a0842b40441db5332a5290f941021636b1182761Sol Boucher mSupportedFlashModes.add(FlashMode.ON); 122a0842b40441db5332a5290f941021636b1182761Sol Boucher mSupportedFlashModes.add(FlashMode.TORCH); 123a0842b40441db5332a5290f941021636b1182761Sol Boucher // TODO: New modes aren't represented here 124a0842b40441db5332a5290f941021636b1182761Sol Boucher } 125a0842b40441db5332a5290f941021636b1182761Sol Boucher } 126a0842b40441db5332a5290f941021636b1182761Sol Boucher 127a0842b40441db5332a5290f941021636b1182761Sol Boucher private void buildFocusModes(CameraCharacteristics p) { 128a0842b40441db5332a5290f941021636b1182761Sol Boucher for (int focus : p.get(CONTROL_AF_AVAILABLE_MODES)) { 129a0842b40441db5332a5290f941021636b1182761Sol Boucher FocusMode equiv = mIntStringifier.focusModeFromInt(focus); 130a0842b40441db5332a5290f941021636b1182761Sol Boucher if (equiv != FocusMode.AUTO || focus == CONTROL_AF_MODE_AUTO) { 131a0842b40441db5332a5290f941021636b1182761Sol Boucher // equiv isn't a default generated because we couldn't handle this mode, so add it 132a0842b40441db5332a5290f941021636b1182761Sol Boucher mSupportedFocusModes.add(equiv); 133a0842b40441db5332a5290f941021636b1182761Sol Boucher } 134a0842b40441db5332a5290f941021636b1182761Sol Boucher } 135a0842b40441db5332a5290f941021636b1182761Sol Boucher } 136a0842b40441db5332a5290f941021636b1182761Sol Boucher 137a0842b40441db5332a5290f941021636b1182761Sol Boucher private void buildWhiteBalances(CameraCharacteristics p) { 138a0842b40441db5332a5290f941021636b1182761Sol Boucher for (int bal : p.get(CONTROL_AWB_AVAILABLE_MODES)) { 139a0842b40441db5332a5290f941021636b1182761Sol Boucher WhiteBalance equiv = mIntStringifier.whiteBalanceFromInt(bal); 140a0842b40441db5332a5290f941021636b1182761Sol Boucher if (equiv != WhiteBalance.AUTO || bal == CONTROL_AWB_MODE_AUTO) { 141a0842b40441db5332a5290f941021636b1182761Sol Boucher // equiv isn't a default generated because we couldn't handle this mode, so add it 142a0842b40441db5332a5290f941021636b1182761Sol Boucher mSupportedWhiteBalances.add(equiv); 143a0842b40441db5332a5290f941021636b1182761Sol Boucher } 144a0842b40441db5332a5290f941021636b1182761Sol Boucher } 145a0842b40441db5332a5290f941021636b1182761Sol Boucher } 146a0842b40441db5332a5290f941021636b1182761Sol Boucher 147a0842b40441db5332a5290f941021636b1182761Sol Boucher public static class IntegralStringifier extends Stringifier { 148a0842b40441db5332a5290f941021636b1182761Sol Boucher /** 149a0842b40441db5332a5290f941021636b1182761Sol Boucher * Converts the focus mode to API-related integer representation. 150a0842b40441db5332a5290f941021636b1182761Sol Boucher * 151a0842b40441db5332a5290f941021636b1182761Sol Boucher * @param fm The focus mode to convert. 152a0842b40441db5332a5290f941021636b1182761Sol Boucher * @return The corresponding {@code int} used by the camera framework 153a0842b40441db5332a5290f941021636b1182761Sol Boucher * API, or {@link CONTROL_AF_MODE_AUTO} if that fails. 154a0842b40441db5332a5290f941021636b1182761Sol Boucher */ 155a0842b40441db5332a5290f941021636b1182761Sol Boucher public int intify(FocusMode fm) { 156a0842b40441db5332a5290f941021636b1182761Sol Boucher switch (fm) { 157a0842b40441db5332a5290f941021636b1182761Sol Boucher case AUTO: 158a0842b40441db5332a5290f941021636b1182761Sol Boucher return CONTROL_AF_MODE_AUTO; 159a0842b40441db5332a5290f941021636b1182761Sol Boucher case CONTINUOUS_PICTURE: 160a0842b40441db5332a5290f941021636b1182761Sol Boucher return CONTROL_AF_MODE_CONTINUOUS_PICTURE; 161a0842b40441db5332a5290f941021636b1182761Sol Boucher case CONTINUOUS_VIDEO: 162a0842b40441db5332a5290f941021636b1182761Sol Boucher return CONTROL_AF_MODE_CONTINUOUS_VIDEO; 163a0842b40441db5332a5290f941021636b1182761Sol Boucher case EXTENDED_DOF: 164a0842b40441db5332a5290f941021636b1182761Sol Boucher return CONTROL_AF_MODE_EDOF; 165a0842b40441db5332a5290f941021636b1182761Sol Boucher case FIXED: 166a0842b40441db5332a5290f941021636b1182761Sol Boucher return CONTROL_AF_MODE_OFF; 167a0842b40441db5332a5290f941021636b1182761Sol Boucher case MACRO: 168a0842b40441db5332a5290f941021636b1182761Sol Boucher return CONTROL_AF_MODE_MACRO; 169a0842b40441db5332a5290f941021636b1182761Sol Boucher // TODO: New modes aren't represented here 170a0842b40441db5332a5290f941021636b1182761Sol Boucher } 171a0842b40441db5332a5290f941021636b1182761Sol Boucher return CONTROL_AF_MODE_AUTO; 172a0842b40441db5332a5290f941021636b1182761Sol Boucher } 173a0842b40441db5332a5290f941021636b1182761Sol Boucher 174a0842b40441db5332a5290f941021636b1182761Sol Boucher /** 175a0842b40441db5332a5290f941021636b1182761Sol Boucher * Converts the API-related integer representation of the focus mode to 176a0842b40441db5332a5290f941021636b1182761Sol Boucher * the abstract representation. 177a0842b40441db5332a5290f941021636b1182761Sol Boucher * 178a0842b40441db5332a5290f941021636b1182761Sol Boucher * @param val The integral representation. 179a0842b40441db5332a5290f941021636b1182761Sol Boucher * @return The mode represented by the input integer, or the focus mode 180a0842b40441db5332a5290f941021636b1182761Sol Boucher * with the lowest ordinal if it cannot be converted. 181a0842b40441db5332a5290f941021636b1182761Sol Boucher */ 182a0842b40441db5332a5290f941021636b1182761Sol Boucher public FocusMode focusModeFromInt(int fm) { 183a0842b40441db5332a5290f941021636b1182761Sol Boucher switch (fm) { 184a0842b40441db5332a5290f941021636b1182761Sol Boucher case CONTROL_AF_MODE_AUTO: 185a0842b40441db5332a5290f941021636b1182761Sol Boucher return FocusMode.AUTO; 186a0842b40441db5332a5290f941021636b1182761Sol Boucher case CONTROL_AF_MODE_CONTINUOUS_PICTURE: 187a0842b40441db5332a5290f941021636b1182761Sol Boucher return FocusMode.CONTINUOUS_PICTURE; 188a0842b40441db5332a5290f941021636b1182761Sol Boucher case CONTROL_AF_MODE_CONTINUOUS_VIDEO: 189a0842b40441db5332a5290f941021636b1182761Sol Boucher return FocusMode.CONTINUOUS_VIDEO; 190a0842b40441db5332a5290f941021636b1182761Sol Boucher case CONTROL_AF_MODE_EDOF: 191a0842b40441db5332a5290f941021636b1182761Sol Boucher return FocusMode.EXTENDED_DOF; 192a0842b40441db5332a5290f941021636b1182761Sol Boucher case CONTROL_AF_MODE_OFF: 193a0842b40441db5332a5290f941021636b1182761Sol Boucher return FocusMode.FIXED; 194a0842b40441db5332a5290f941021636b1182761Sol Boucher case CONTROL_AF_MODE_MACRO: 195a0842b40441db5332a5290f941021636b1182761Sol Boucher return FocusMode.MACRO; 196a0842b40441db5332a5290f941021636b1182761Sol Boucher // TODO: New modes aren't represented here 197a0842b40441db5332a5290f941021636b1182761Sol Boucher } 198a0842b40441db5332a5290f941021636b1182761Sol Boucher return FocusMode.values()[0]; 199a0842b40441db5332a5290f941021636b1182761Sol Boucher } 200a0842b40441db5332a5290f941021636b1182761Sol Boucher 201a0842b40441db5332a5290f941021636b1182761Sol Boucher /** 202a0842b40441db5332a5290f941021636b1182761Sol Boucher * Converts the flash mode to API-related integer representation. 203a0842b40441db5332a5290f941021636b1182761Sol Boucher * 204a0842b40441db5332a5290f941021636b1182761Sol Boucher * @param fm The flash mode to convert. 205a0842b40441db5332a5290f941021636b1182761Sol Boucher * @return The corresponding {@code int} used by the camera framework 206a0842b40441db5332a5290f941021636b1182761Sol Boucher * API, or {@link CONTROL_AF_MODE_AUTO} if that fails. 207a0842b40441db5332a5290f941021636b1182761Sol Boucher */ 208a0842b40441db5332a5290f941021636b1182761Sol Boucher public int intify(FlashMode flm) { 209a0842b40441db5332a5290f941021636b1182761Sol Boucher switch (flm) { 210a0842b40441db5332a5290f941021636b1182761Sol Boucher case OFF: 211a0842b40441db5332a5290f941021636b1182761Sol Boucher return FLASH_MODE_OFF; 212a0842b40441db5332a5290f941021636b1182761Sol Boucher case ON: 213a0842b40441db5332a5290f941021636b1182761Sol Boucher return FLASH_MODE_SINGLE; 214a0842b40441db5332a5290f941021636b1182761Sol Boucher case TORCH: 215a0842b40441db5332a5290f941021636b1182761Sol Boucher return FLASH_MODE_TORCH; 216a0842b40441db5332a5290f941021636b1182761Sol Boucher // TODO: New modes aren't represented here 217a0842b40441db5332a5290f941021636b1182761Sol Boucher } 218a0842b40441db5332a5290f941021636b1182761Sol Boucher return FLASH_MODE_OFF; 219a0842b40441db5332a5290f941021636b1182761Sol Boucher } 220a0842b40441db5332a5290f941021636b1182761Sol Boucher 221a0842b40441db5332a5290f941021636b1182761Sol Boucher /** 222a0842b40441db5332a5290f941021636b1182761Sol Boucher * Converts the API-related integer representation of the flash mode to 223a0842b40441db5332a5290f941021636b1182761Sol Boucher * the abstract representation. 224a0842b40441db5332a5290f941021636b1182761Sol Boucher * 225a0842b40441db5332a5290f941021636b1182761Sol Boucher * @param flm The integral representation. 226a0842b40441db5332a5290f941021636b1182761Sol Boucher * @return The mode represented by the input integer, or the flash mode 227a0842b40441db5332a5290f941021636b1182761Sol Boucher * with the lowest ordinal if it cannot be converted. 228a0842b40441db5332a5290f941021636b1182761Sol Boucher */ 229a0842b40441db5332a5290f941021636b1182761Sol Boucher public FlashMode flashModeFromInt(int flm) { 230a0842b40441db5332a5290f941021636b1182761Sol Boucher switch (flm) { 231a0842b40441db5332a5290f941021636b1182761Sol Boucher case FLASH_MODE_OFF: 232a0842b40441db5332a5290f941021636b1182761Sol Boucher return FlashMode.OFF; 233a0842b40441db5332a5290f941021636b1182761Sol Boucher case FLASH_MODE_SINGLE: 234a0842b40441db5332a5290f941021636b1182761Sol Boucher return FlashMode.ON; 235a0842b40441db5332a5290f941021636b1182761Sol Boucher case FLASH_MODE_TORCH: 236a0842b40441db5332a5290f941021636b1182761Sol Boucher return FlashMode.TORCH; 237a0842b40441db5332a5290f941021636b1182761Sol Boucher // TODO: New modes aren't represented here 238a0842b40441db5332a5290f941021636b1182761Sol Boucher } 239a0842b40441db5332a5290f941021636b1182761Sol Boucher return FlashMode.values()[0]; 240a0842b40441db5332a5290f941021636b1182761Sol Boucher } 241a0842b40441db5332a5290f941021636b1182761Sol Boucher 242a0842b40441db5332a5290f941021636b1182761Sol Boucher /** 243a0842b40441db5332a5290f941021636b1182761Sol Boucher * Converts the scene mode to API-related integer representation. 244a0842b40441db5332a5290f941021636b1182761Sol Boucher * 245a0842b40441db5332a5290f941021636b1182761Sol Boucher * @param fm The scene mode to convert. 246a0842b40441db5332a5290f941021636b1182761Sol Boucher * @return The corresponding {@code int} used by the camera framework 247a0842b40441db5332a5290f941021636b1182761Sol Boucher * API, or {@link CONTROL_SCENE_MODE_DISABLED} if that fails. 248a0842b40441db5332a5290f941021636b1182761Sol Boucher */ 249a0842b40441db5332a5290f941021636b1182761Sol Boucher public int intify(SceneMode sm) { 250a0842b40441db5332a5290f941021636b1182761Sol Boucher switch (sm) { 251a0842b40441db5332a5290f941021636b1182761Sol Boucher case AUTO: 252a0842b40441db5332a5290f941021636b1182761Sol Boucher return CONTROL_SCENE_MODE_DISABLED; 253a0842b40441db5332a5290f941021636b1182761Sol Boucher case ACTION: 254a0842b40441db5332a5290f941021636b1182761Sol Boucher return CONTROL_SCENE_MODE_ACTION; 255a0842b40441db5332a5290f941021636b1182761Sol Boucher case BARCODE: 256a0842b40441db5332a5290f941021636b1182761Sol Boucher return CONTROL_SCENE_MODE_BARCODE; 257a0842b40441db5332a5290f941021636b1182761Sol Boucher case BEACH: 258a0842b40441db5332a5290f941021636b1182761Sol Boucher return CONTROL_SCENE_MODE_BEACH; 259a0842b40441db5332a5290f941021636b1182761Sol Boucher case CANDLELIGHT: 260a0842b40441db5332a5290f941021636b1182761Sol Boucher return CONTROL_SCENE_MODE_CANDLELIGHT; 261a0842b40441db5332a5290f941021636b1182761Sol Boucher case FIREWORKS: 262a0842b40441db5332a5290f941021636b1182761Sol Boucher return CONTROL_SCENE_MODE_FIREWORKS; 263a0842b40441db5332a5290f941021636b1182761Sol Boucher case LANDSCAPE: 264a0842b40441db5332a5290f941021636b1182761Sol Boucher return CONTROL_SCENE_MODE_LANDSCAPE; 265a0842b40441db5332a5290f941021636b1182761Sol Boucher case NIGHT: 266a0842b40441db5332a5290f941021636b1182761Sol Boucher return CONTROL_SCENE_MODE_NIGHT; 267a0842b40441db5332a5290f941021636b1182761Sol Boucher case PARTY: 268a0842b40441db5332a5290f941021636b1182761Sol Boucher return CONTROL_SCENE_MODE_PARTY; 269a0842b40441db5332a5290f941021636b1182761Sol Boucher case PORTRAIT: 270a0842b40441db5332a5290f941021636b1182761Sol Boucher return CONTROL_SCENE_MODE_PORTRAIT; 271a0842b40441db5332a5290f941021636b1182761Sol Boucher case SNOW: 272a0842b40441db5332a5290f941021636b1182761Sol Boucher return CONTROL_SCENE_MODE_SNOW; 273a0842b40441db5332a5290f941021636b1182761Sol Boucher case SPORTS: 274a0842b40441db5332a5290f941021636b1182761Sol Boucher return CONTROL_SCENE_MODE_SPORTS; 275a0842b40441db5332a5290f941021636b1182761Sol Boucher case STEADYPHOTO: 276a0842b40441db5332a5290f941021636b1182761Sol Boucher return CONTROL_SCENE_MODE_STEADYPHOTO; 277a0842b40441db5332a5290f941021636b1182761Sol Boucher case SUNSET: 278a0842b40441db5332a5290f941021636b1182761Sol Boucher return CONTROL_SCENE_MODE_SUNSET; 279a0842b40441db5332a5290f941021636b1182761Sol Boucher case THEATRE: 280a0842b40441db5332a5290f941021636b1182761Sol Boucher return CONTROL_SCENE_MODE_THEATRE; 281a0842b40441db5332a5290f941021636b1182761Sol Boucher // TODO: New modes aren't represented here 282a0842b40441db5332a5290f941021636b1182761Sol Boucher } 283a0842b40441db5332a5290f941021636b1182761Sol Boucher return CONTROL_SCENE_MODE_DISABLED; 284a0842b40441db5332a5290f941021636b1182761Sol Boucher } 285a0842b40441db5332a5290f941021636b1182761Sol Boucher 286a0842b40441db5332a5290f941021636b1182761Sol Boucher /** 287a0842b40441db5332a5290f941021636b1182761Sol Boucher * Converts the API-related integer representation of the scene mode to 288a0842b40441db5332a5290f941021636b1182761Sol Boucher * the abstract representation. 289a0842b40441db5332a5290f941021636b1182761Sol Boucher * 290a0842b40441db5332a5290f941021636b1182761Sol Boucher * @param sm The integral representation. 291a0842b40441db5332a5290f941021636b1182761Sol Boucher * @return The mode represented by the input integer, or the scene mode 292a0842b40441db5332a5290f941021636b1182761Sol Boucher * with the lowest ordinal if it cannot be converted. 293a0842b40441db5332a5290f941021636b1182761Sol Boucher */ 294a0842b40441db5332a5290f941021636b1182761Sol Boucher public SceneMode sceneModeFromInt(int sm) { 295a0842b40441db5332a5290f941021636b1182761Sol Boucher switch (sm) { 296a0842b40441db5332a5290f941021636b1182761Sol Boucher case CONTROL_SCENE_MODE_DISABLED: 297a0842b40441db5332a5290f941021636b1182761Sol Boucher return SceneMode.AUTO; 298a0842b40441db5332a5290f941021636b1182761Sol Boucher case CONTROL_SCENE_MODE_ACTION: 299a0842b40441db5332a5290f941021636b1182761Sol Boucher return SceneMode.ACTION; 300a0842b40441db5332a5290f941021636b1182761Sol Boucher case CONTROL_SCENE_MODE_BARCODE: 301a0842b40441db5332a5290f941021636b1182761Sol Boucher return SceneMode.BARCODE; 302a0842b40441db5332a5290f941021636b1182761Sol Boucher case CONTROL_SCENE_MODE_BEACH: 303a0842b40441db5332a5290f941021636b1182761Sol Boucher return SceneMode.BEACH; 304a0842b40441db5332a5290f941021636b1182761Sol Boucher case CONTROL_SCENE_MODE_CANDLELIGHT: 305a0842b40441db5332a5290f941021636b1182761Sol Boucher return SceneMode.CANDLELIGHT; 306a0842b40441db5332a5290f941021636b1182761Sol Boucher case CONTROL_SCENE_MODE_FIREWORKS: 307a0842b40441db5332a5290f941021636b1182761Sol Boucher return SceneMode.FIREWORKS; 308a0842b40441db5332a5290f941021636b1182761Sol Boucher case CONTROL_SCENE_MODE_LANDSCAPE: 309a0842b40441db5332a5290f941021636b1182761Sol Boucher return SceneMode.LANDSCAPE; 310a0842b40441db5332a5290f941021636b1182761Sol Boucher case CONTROL_SCENE_MODE_NIGHT: 311a0842b40441db5332a5290f941021636b1182761Sol Boucher return SceneMode.NIGHT; 312a0842b40441db5332a5290f941021636b1182761Sol Boucher case CONTROL_SCENE_MODE_PARTY: 313a0842b40441db5332a5290f941021636b1182761Sol Boucher return SceneMode.PARTY; 314a0842b40441db5332a5290f941021636b1182761Sol Boucher case CONTROL_SCENE_MODE_PORTRAIT: 315a0842b40441db5332a5290f941021636b1182761Sol Boucher return SceneMode.PORTRAIT; 316a0842b40441db5332a5290f941021636b1182761Sol Boucher case CONTROL_SCENE_MODE_SNOW: 317a0842b40441db5332a5290f941021636b1182761Sol Boucher return SceneMode.SNOW; 318a0842b40441db5332a5290f941021636b1182761Sol Boucher case CONTROL_SCENE_MODE_SPORTS: 319a0842b40441db5332a5290f941021636b1182761Sol Boucher return SceneMode.SPORTS; 320a0842b40441db5332a5290f941021636b1182761Sol Boucher case CONTROL_SCENE_MODE_STEADYPHOTO: 321a0842b40441db5332a5290f941021636b1182761Sol Boucher return SceneMode.STEADYPHOTO; 322a0842b40441db5332a5290f941021636b1182761Sol Boucher case CONTROL_SCENE_MODE_SUNSET: 323a0842b40441db5332a5290f941021636b1182761Sol Boucher return SceneMode.SUNSET; 324a0842b40441db5332a5290f941021636b1182761Sol Boucher case CONTROL_SCENE_MODE_THEATRE: 325a0842b40441db5332a5290f941021636b1182761Sol Boucher return SceneMode.THEATRE; 326a0842b40441db5332a5290f941021636b1182761Sol Boucher // TODO: New modes aren't represented here 327a0842b40441db5332a5290f941021636b1182761Sol Boucher } 328a0842b40441db5332a5290f941021636b1182761Sol Boucher return SceneMode.values()[0]; 329a0842b40441db5332a5290f941021636b1182761Sol Boucher } 330a0842b40441db5332a5290f941021636b1182761Sol Boucher 331a0842b40441db5332a5290f941021636b1182761Sol Boucher /** 332a0842b40441db5332a5290f941021636b1182761Sol Boucher * Converts the white balance to API-related integer representation. 333a0842b40441db5332a5290f941021636b1182761Sol Boucher * 334a0842b40441db5332a5290f941021636b1182761Sol Boucher * @param fm The white balance to convert. 335a0842b40441db5332a5290f941021636b1182761Sol Boucher * @return The corresponding {@code int} used by the camera framework 336a0842b40441db5332a5290f941021636b1182761Sol Boucher * API, or {@link CONTROL_SCENE_MODE_DISABLED} if that fails. 337a0842b40441db5332a5290f941021636b1182761Sol Boucher */ 338a0842b40441db5332a5290f941021636b1182761Sol Boucher public int intify(WhiteBalance wb) { 339a0842b40441db5332a5290f941021636b1182761Sol Boucher switch (wb) { 340a0842b40441db5332a5290f941021636b1182761Sol Boucher case AUTO: 341a0842b40441db5332a5290f941021636b1182761Sol Boucher return CONTROL_AWB_MODE_AUTO; 342a0842b40441db5332a5290f941021636b1182761Sol Boucher case CLOUDY_DAYLIGHT: 343a0842b40441db5332a5290f941021636b1182761Sol Boucher return CONTROL_AWB_MODE_CLOUDY_DAYLIGHT; 344a0842b40441db5332a5290f941021636b1182761Sol Boucher case DAYLIGHT: 345a0842b40441db5332a5290f941021636b1182761Sol Boucher return CONTROL_AWB_MODE_DAYLIGHT; 346a0842b40441db5332a5290f941021636b1182761Sol Boucher case FLUORESCENT: 347a0842b40441db5332a5290f941021636b1182761Sol Boucher return CONTROL_AWB_MODE_FLUORESCENT; 348a0842b40441db5332a5290f941021636b1182761Sol Boucher case INCANDESCENT: 349a0842b40441db5332a5290f941021636b1182761Sol Boucher return CONTROL_AWB_MODE_INCANDESCENT; 350a0842b40441db5332a5290f941021636b1182761Sol Boucher case SHADE: 351a0842b40441db5332a5290f941021636b1182761Sol Boucher return CONTROL_AWB_MODE_SHADE; 352a0842b40441db5332a5290f941021636b1182761Sol Boucher case TWILIGHT: 353a0842b40441db5332a5290f941021636b1182761Sol Boucher return CONTROL_AWB_MODE_TWILIGHT; 354a0842b40441db5332a5290f941021636b1182761Sol Boucher case WARM_FLUORESCENT: 355a0842b40441db5332a5290f941021636b1182761Sol Boucher return CONTROL_AWB_MODE_WARM_FLUORESCENT; 356a0842b40441db5332a5290f941021636b1182761Sol Boucher // TODO: New modes aren't represented here 357a0842b40441db5332a5290f941021636b1182761Sol Boucher } 358a0842b40441db5332a5290f941021636b1182761Sol Boucher return CONTROL_AWB_MODE_AUTO; 359a0842b40441db5332a5290f941021636b1182761Sol Boucher } 360a0842b40441db5332a5290f941021636b1182761Sol Boucher 361a0842b40441db5332a5290f941021636b1182761Sol Boucher /** 362a0842b40441db5332a5290f941021636b1182761Sol Boucher * Converts the API-related integer representation of the white balance 363a0842b40441db5332a5290f941021636b1182761Sol Boucher * to the abstract representation. 364a0842b40441db5332a5290f941021636b1182761Sol Boucher * 365a0842b40441db5332a5290f941021636b1182761Sol Boucher * @param wb The integral representation. 366a0842b40441db5332a5290f941021636b1182761Sol Boucher * @return The balance represented by the input integer, or the white 367a0842b40441db5332a5290f941021636b1182761Sol Boucher * balance with the lowest ordinal if it cannot be converted. 368a0842b40441db5332a5290f941021636b1182761Sol Boucher */ 369a0842b40441db5332a5290f941021636b1182761Sol Boucher public WhiteBalance whiteBalanceFromInt(int wb) { 370a0842b40441db5332a5290f941021636b1182761Sol Boucher switch (wb) { 371a0842b40441db5332a5290f941021636b1182761Sol Boucher case CONTROL_AWB_MODE_AUTO: 372a0842b40441db5332a5290f941021636b1182761Sol Boucher return WhiteBalance.AUTO; 373a0842b40441db5332a5290f941021636b1182761Sol Boucher case CONTROL_AWB_MODE_CLOUDY_DAYLIGHT: 374a0842b40441db5332a5290f941021636b1182761Sol Boucher return WhiteBalance.CLOUDY_DAYLIGHT; 375a0842b40441db5332a5290f941021636b1182761Sol Boucher case CONTROL_AWB_MODE_DAYLIGHT: 376a0842b40441db5332a5290f941021636b1182761Sol Boucher return WhiteBalance.DAYLIGHT; 377a0842b40441db5332a5290f941021636b1182761Sol Boucher case CONTROL_AWB_MODE_FLUORESCENT: 378a0842b40441db5332a5290f941021636b1182761Sol Boucher return WhiteBalance.FLUORESCENT; 379a0842b40441db5332a5290f941021636b1182761Sol Boucher case CONTROL_AWB_MODE_INCANDESCENT: 380a0842b40441db5332a5290f941021636b1182761Sol Boucher return WhiteBalance.INCANDESCENT; 381a0842b40441db5332a5290f941021636b1182761Sol Boucher case CONTROL_AWB_MODE_SHADE: 382a0842b40441db5332a5290f941021636b1182761Sol Boucher return WhiteBalance.SHADE; 383a0842b40441db5332a5290f941021636b1182761Sol Boucher case CONTROL_AWB_MODE_TWILIGHT: 384a0842b40441db5332a5290f941021636b1182761Sol Boucher return WhiteBalance.TWILIGHT; 385a0842b40441db5332a5290f941021636b1182761Sol Boucher case CONTROL_AWB_MODE_WARM_FLUORESCENT: 386a0842b40441db5332a5290f941021636b1182761Sol Boucher return WhiteBalance.WARM_FLUORESCENT; 387a0842b40441db5332a5290f941021636b1182761Sol Boucher // TODO: New modes aren't represented here 388a0842b40441db5332a5290f941021636b1182761Sol Boucher } 389a0842b40441db5332a5290f941021636b1182761Sol Boucher return WhiteBalance.values()[0]; 390a0842b40441db5332a5290f941021636b1182761Sol Boucher } 391a0842b40441db5332a5290f941021636b1182761Sol Boucher } 392a0842b40441db5332a5290f941021636b1182761Sol Boucher} 393