AndroidCameraSettings.java revision 2569329d6cff25bfe9941df539df14a0aeb4c4f4
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        setSizesLocked(false);
32
33        // Preview
34        Camera.Size paramPreviewSize = params.getPreviewSize();
35        setPreviewSize(new Size(paramPreviewSize.width, paramPreviewSize.height));
36        setPreviewFrameRate(params.getPreviewFrameRate());
37        int[] previewFpsRange = new int[2];
38        params.getPreviewFpsRange(previewFpsRange);
39        setPreviewFpsRange(previewFpsRange[Camera.Parameters.PREVIEW_FPS_MIN_INDEX],
40                previewFpsRange[Camera.Parameters.PREVIEW_FPS_MAX_INDEX]);
41        setPreviewFormat(params.getPreviewFormat());
42
43        // Capture: Focus, flash, zoom, exposure, scene mode.
44        if (capabilities.supports(CameraCapabilities.Feature.ZOOM)) {
45            setZoomRatio(params.getZoomRatios().get(params.getZoom()) / 100f);
46        } else {
47            setZoomRatio(CameraCapabilities.ZOOM_RATIO_UNZOOMED);
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
61        setPhotoJpegCompressionQuality(params.getJpegQuality());
62        Camera.Size paramPictureSize = params.getPictureSize();
63        setPhotoSize(new Size(paramPictureSize.width, paramPictureSize.height));
64        setPhotoFormat(params.getPictureFormat());
65    }
66
67    public AndroidCameraSettings(AndroidCameraSettings other) {
68        super(other);
69    }
70
71    @Override
72    public CameraSettings copy() {
73        return new AndroidCameraSettings(this);
74    }
75}
76