AndroidCameraSettings.java revision 9d8668449376fa47bc6528c7a61b04d6a0f691b3
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        } else {
45            setZoomRatio(CameraCapabilities.ZOOM_RATIO_UNZOOMED);
46        }
47        setExposureCompensationIndex(params.getExposureCompensation());
48        setFlashMode(stringifier.flashModeFromString(params.getFlashMode()));
49        setFocusMode(stringifier.focusModeFromString(params.getFocusMode()));
50        setSceneMode(stringifier.sceneModeFromString(params.getSceneMode()));
51
52        // Video capture.
53        if (capabilities.supports(CameraCapabilities.Feature.VIDEO_STABILIZATION)) {
54            setVideoStabilization(isVideoStabilizationEnabled());
55        }
56        setRecordingHintEnabled(TRUE.equals(params.get(RECORDING_HINT)));
57
58        // Output: Photo size, compression quality
59        setPhotoJpegCompressionQuality(params.getJpegQuality());
60        Camera.Size paramPictureSize = params.getPictureSize();
61        setPhotoSize(new Size(paramPictureSize.width, paramPictureSize.height));
62        setPhotoFormat(params.getPictureFormat());
63    }
64
65    public AndroidCameraSettings(AndroidCameraSettings other) {
66        super(other);
67    }
68
69    @Override
70    public CameraSettings copy() {
71        return new AndroidCameraSettings(this);
72    }
73}
74