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 
17 package com.android.camera.one;
18 
19 import android.hardware.camera2.params.MeteringRectangle;
20 
21 /**
22  * Contains 3A parameters common to all camera flavors. TODO: Move to
23  * GservicesHelper.
24  */
25 public class Settings3A {
26 
27     /**
28      * Width of touch AF region in [0,1] relative to shorter edge of the current
29      * crop region. Multiply this number by the number of pixels along the
30      * shorter edge of the current crop region's width to get a value in pixels.
31      * <p>
32      * This value has been tested on Nexus 5 and Shamu, but will need to be
33      * tuned per device depending on how its ISP interprets the metering box and
34      * weight.
35      *
36      * <pre>
37      * Values prior to L release:
38      * Normal mode: 0.125 * longest edge
39      * Gcam: Fixed at 300px x 300px.
40      */
41     private static final float AF_REGION_BOX = 0.2f;
42 
43     /**
44      * Width of touch metering region in [0,1] relative to shorter edge of the
45      * current crop region. Multiply this number by the number of pixels along
46      * shorter edge of the current crop region's width to get a value in pixels.
47      * <p>
48      * This value has been tested on Nexus 5 and Shamu, but will need to be
49      * tuned per device depending on how its ISP interprets the metering box and
50      * weight.
51      *
52      * <pre>
53      * Values prior to L release:
54      * Normal mode: 0.1875 * longest edge
55      * Gcam: Fixed  ffat 300px x 300px.
56      */
57     private static final float AE_REGION_BOX = 0.3f;
58 
59     /**
60      * Metering region weight between 0 and 1.
61      * <p>
62      * This value has been tested on Nexus 5 and Shamu, but will need to be
63      * tuned per device depending on how its ISP interprets the metering box and
64      * weight.
65      * </p>
66      */
67     private static final float REGION_WEIGHT = 0.022f;
68 
69     /** Duration to hold after manual tap to focus. */
70     private static final int FOCUS_HOLD_MILLIS = 3000;
71 
72     /**
73      * The number of milliseconds to hold tap-to-expose/metering after the last
74      * payload frame is received before returning to continuous 3A.
75      */
76     private static final int GCAM_POST_SHOT_FOCUS_HOLD_MILLIS = 1000;
77 
78     /**
79      * Width of touch metering region in [0,1] relative to shorter edge of the
80      * current crop region. Multiply this number by the number of pixels along
81      * shorter edge of the current crop region's width to get a value in pixels.
82      * <p>
83      * This value has been tested on Nexus 5 and Shamu, but will need to be
84      * tuned per device depending on how its ISP interprets the metering box and
85      * weight.
86      * </p>
87      * <p>
88      * Was fixed at 300px x 300px prior to L release.
89      * </p>
90      */
91     private static final float GCAM_METERING_REGION_FRACTION = 0.1225f;
92 
93     /**
94      * Weight of a touch metering region, in [0, \inf).
95      * <p>
96      * This value has been tested on Nexus 5 and Shamu, but will need to be
97      * tuned per device.
98      * </p>
99      * <p>
100      * Was fixed at 15.0f prior to L release.
101      * </p>
102      */
103     private static final float GCAM_METERING_REGION_WEIGHT = 45.0f;
104 
105     /**
106      * @Return The weight to use for {@link MeteringRectangle}s for 3A.
107      */
getMeteringWeight()108     public int getMeteringWeight() {
109         // TODO Determine the optimal metering region for non-HDR photos.
110         int weightMin = MeteringRectangle.METERING_WEIGHT_MIN;
111         int weightRange = MeteringRectangle.METERING_WEIGHT_MAX
112                 - MeteringRectangle.METERING_WEIGHT_MIN;
113         return (int) (weightMin + GCAM_METERING_REGION_FRACTION * weightRange);
114     }
115 
116     /**
117      * @return The size of (square) metering regions, normalized with respect to
118      *         the smallest dimension of the current crop-region.
119      */
getMeteringRegionFraction()120     public float getMeteringRegionFraction() {
121         // TODO Determine the optimal metering weight for non-HDR photos.
122         return GCAM_METERING_REGION_FRACTION;
123     }
124 
125     @Deprecated
getAutoFocusRegionWidth()126     public static float getAutoFocusRegionWidth() {
127         return AF_REGION_BOX;
128     }
129 
130     @Deprecated
getMeteringRegionWidth()131     public static float getMeteringRegionWidth() {
132         return AE_REGION_BOX;
133     }
134 
135     @Deprecated
getMeteringRegionWeight()136     public static float getMeteringRegionWeight() {
137         return REGION_WEIGHT;
138     }
139 
140     @Deprecated
getGcamMeteringRegionFraction()141     public static float getGcamMeteringRegionFraction() {
142         return GCAM_METERING_REGION_FRACTION;
143     }
144 
145     @Deprecated
getGcamMeteringRegionWeight()146     public static float getGcamMeteringRegionWeight() {
147         return GCAM_METERING_REGION_WEIGHT;
148     }
149 
150     @Deprecated
getFocusHoldMillis()151     public static int getFocusHoldMillis() {
152         return FOCUS_HOLD_MILLIS;
153     }
154 
155     @Deprecated
getGcamPostShotFocusHoldMillis()156     public static int getGcamPostShotFocusHoldMillis() {
157         return GCAM_POST_SHOT_FOCUS_HOLD_MILLIS;
158     }
159 }
160