AndroidCameraSettings.java revision 01e7c02174ef268b6d6daaa5a5bb4f752d55964c
1/* 2 * Copyright (C) 2014 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 17package com.android.ex.camera2.portability; 18 19import android.hardware.Camera; 20 21/** 22 * The subclass of {@link CameraSettings} for Android Camera 1 API. 23 */ 24public class AndroidCameraSettings extends CameraSettings { 25 private static final String TRUE = "true"; 26 private static final String RECORDING_HINT = "recording-hint"; 27 28 public AndroidCameraSettings(CameraCapabilities capabilities, Camera.Parameters params) { 29 CameraCapabilities.Stringifier stringifier = capabilities.getStringifier(); 30 31 // Preview 32 Camera.Size paramPreviewSize = params.getPreviewSize(); 33 setPreviewSize(new Size(paramPreviewSize.width, paramPreviewSize.height)); 34 setPreviewFrameRate(params.getPreviewFrameRate()); 35 int[] previewFpsRange = new int[2]; 36 params.getPreviewFpsRange(previewFpsRange); 37 setPreviewFpsRange(previewFpsRange[Camera.Parameters.PREVIEW_FPS_MIN_INDEX], 38 previewFpsRange[Camera.Parameters.PREVIEW_FPS_MAX_INDEX]); 39 setPreviewFormat(params.getPreviewFormat()); 40 41 // Capture: Focus, flash, zoom, exposure, scene mode. 42 if (capabilities.supports(CameraCapabilities.Feature.ZOOM)) { 43 setZoomRatio(params.getZoomRatios().get(params.getZoom()) / 100f); 44 setZoomIndex(params.getZoom()); 45 } else { 46 setZoomRatio(1.0f); 47 setZoomIndex(0); 48 } 49 setExposureCompensationIndex(params.getExposureCompensation()); 50 setFlashMode(stringifier.flashModeFromString(params.getFlashMode())); 51 setFocusMode(stringifier.focusModeFromString(params.getFocusMode())); 52 setSceneMode(stringifier.sceneModeFromString(params.getSceneMode())); 53 54 // Video capture. 55 if (capabilities.supports(CameraCapabilities.Feature.VIDEO_STABILIZATION)) { 56 setVideoStabilization(isVideoStabilizationEnabled()); 57 } 58 setRecordingHintEnabled(TRUE.equals(params.get(RECORDING_HINT))); 59 60 // Output: Photo size, compression quality, rotation. 61 setPhotoRotationDegrees(0f); 62 setPhotoJpegCompressionQuality(params.getJpegQuality()); 63 Camera.Size paramPictureSize = params.getPictureSize(); 64 setPhotoSize(new Size(paramPictureSize.width, paramPictureSize.height)); 65 setPhotoFormat(params.getPictureFormat()); 66 } 67} 68