/* * Copyright (C) 2014 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.hardware.camera2.legacy; import android.graphics.Rect; import android.hardware.Camera; import android.hardware.Camera.Parameters; import android.hardware.camera2.CameraCharacteristics; import android.hardware.camera2.CaptureRequest; import android.hardware.camera2.params.MeteringRectangle; import android.hardware.camera2.utils.ListUtils; import android.hardware.camera2.utils.ParamsUtils; import android.location.Location; import android.util.Log; import android.util.Range; import android.util.Size; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Objects; import static android.hardware.camera2.CaptureRequest.*; /** * Provide legacy-specific implementations of camera2 CaptureRequest for legacy devices. */ @SuppressWarnings("deprecation") public class LegacyRequestMapper { private static final String TAG = "LegacyRequestMapper"; private static final boolean DEBUG = false; /** Default quality for android.jpeg.quality, android.jpeg.thumbnailQuality */ private static final byte DEFAULT_JPEG_QUALITY = 85; /** * Set the legacy parameters using the {@link LegacyRequest legacy request}. * *
The legacy request's parameters are changed as a side effect of calling this * method.
* * @param legacyRequest a non-{@code null} legacy request */ public static void convertRequestMetadata(LegacyRequest legacyRequest) { CameraCharacteristics characteristics = legacyRequest.characteristics; CaptureRequest request = legacyRequest.captureRequest; Size previewSize = legacyRequest.previewSize; Camera.Parameters params = legacyRequest.parameters; Rect activeArray = characteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE); /* * scaler.cropRegion */ ParameterUtils.ZoomData zoomData; { zoomData = ParameterUtils.convertScalerCropRegion(activeArray, request.get(SCALER_CROP_REGION), previewSize, params); if (params.isZoomSupported()) { params.setZoom(zoomData.zoomIndex); } else if (DEBUG) { Log.v(TAG, "convertRequestToMetadata - zoom is not supported"); } } /* * colorCorrection.* */ // colorCorrection.aberrationMode { int aberrationMode = ParamsUtils.getOrDefault(request, COLOR_CORRECTION_ABERRATION_MODE, /*defaultValue*/COLOR_CORRECTION_ABERRATION_MODE_FAST); if (aberrationMode != COLOR_CORRECTION_ABERRATION_MODE_FAST && aberrationMode != COLOR_CORRECTION_ABERRATION_MODE_HIGH_QUALITY) { Log.w(TAG, "convertRequestToMetadata - Ignoring unsupported " + "colorCorrection.aberrationMode = " + aberrationMode); } } /* * control.ae* */ // control.aeAntibandingMode { String legacyMode; Integer antiBandingMode = request.get(CONTROL_AE_ANTIBANDING_MODE); if (antiBandingMode != null) { legacyMode = convertAeAntiBandingModeToLegacy(antiBandingMode); } else { legacyMode = ListUtils.listSelectFirstFrom(params.getSupportedAntibanding(), new String[] { Parameters.ANTIBANDING_AUTO, Parameters.ANTIBANDING_OFF, Parameters.ANTIBANDING_50HZ, Parameters.ANTIBANDING_60HZ, }); } if (legacyMode != null) { params.setAntibanding(legacyMode); } } /* * control.aeRegions, afRegions */ { // aeRegions { // Use aeRegions if available, fall back to using awbRegions if present MeteringRectangle[] aeRegions = request.get(CONTROL_AE_REGIONS); if (request.get(CONTROL_AWB_REGIONS) != null) { Log.w(TAG, "convertRequestMetadata - control.awbRegions setting is not " + "supported, ignoring value"); } int maxNumMeteringAreas = params.getMaxNumMeteringAreas(); ListIf the fetched value in the request is equivalent to {@code allowedValue}, * then omit the warning (e.g. turning off AF lock on a camera * that always has the AF lock turned off is a silent no-op), but still return {@code null}.
* *Logs a warning to logcat if the key is not supported by api1 camera device. T getIfSupported(
CaptureRequest r, CaptureRequest.Key