This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[camera] android-rework part 3: Android exposure related features #3797
Merged
stuartmorgan-g
merged 13 commits into
flutter:master
from
Baseflow:camera-android/exposure_features
May 27, 2021
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2b7aa9b
Base classes to support Android camera features
mvanbeusekom f780742
Fixed formatting
mvanbeusekom 76bc5bd
Applied feedback from PR
mvanbeusekom 461309a
Added Android exposure related features
mvanbeusekom 058805b
Merge remote-tracking branch 'upstream/master' into camera-android/ex…
mvanbeusekom 7052b45
Added partial feedback from PR
mvanbeusekom 8985a9c
Merge remote-tracking branch 'upstream/master' into camera-android/ex…
mvanbeusekom 7a0b41e
Updated feedback from PR
mvanbeusekom 6a50e99
Fix formatting
mvanbeusekom a3a4ee1
Merge remote-tracking branch 'upstream/master' into camera-android/ex…
mvanbeusekom 989ecfa
Apply feedback from PR
mvanbeusekom ebae3de
Correct documentation of min and max exposure offset
mvanbeusekom 81dafb3
Fix formatting
mvanbeusekom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/Point.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package io.flutter.plugins.camera.features; | ||
|
||
/** Represents a point on an x/y axis. */ | ||
public class Point { | ||
public final Double x; | ||
public final Double y; | ||
|
||
public Point(Double x, Double y) { | ||
this.x = x; | ||
this.y = y; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...id/src/main/java/io/flutter/plugins/camera/features/exposurelock/ExposureLockFeature.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package io.flutter.plugins.camera.features.exposurelock; | ||
|
||
import android.hardware.camera2.CaptureRequest; | ||
import io.flutter.plugins.camera.CameraProperties; | ||
import io.flutter.plugins.camera.features.CameraFeature; | ||
|
||
/** Controls whether or not the exposure mode is currently locked or automatically metering. */ | ||
public class ExposureLockFeature extends CameraFeature<ExposureMode> { | ||
|
||
private ExposureMode currentSetting = ExposureMode.auto; | ||
|
||
/** | ||
* Creates a new instance of the {@see ExposureLockFeature}. | ||
* | ||
* @param cameraProperties Collection of the characteristics for the current camera device. | ||
*/ | ||
public ExposureLockFeature(CameraProperties cameraProperties) { | ||
super(cameraProperties); | ||
} | ||
|
||
@Override | ||
public String getDebugName() { | ||
return "ExposureLockFeature"; | ||
} | ||
|
||
@Override | ||
public ExposureMode getValue() { | ||
return currentSetting; | ||
} | ||
|
||
@Override | ||
public void setValue(ExposureMode value) { | ||
this.currentSetting = value; | ||
} | ||
|
||
// Available on all devices. | ||
@Override | ||
public boolean checkIsSupported() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public void updateBuilder(CaptureRequest.Builder requestBuilder) { | ||
if (!checkIsSupported()) { | ||
return; | ||
} | ||
|
||
requestBuilder.set(CaptureRequest.CONTROL_AE_LOCK, currentSetting == ExposureMode.locked); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...a/android/src/main/java/io/flutter/plugins/camera/features/exposurelock/ExposureMode.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package io.flutter.plugins.camera.features.exposurelock; | ||
|
||
// Mirrors exposure_mode.dart | ||
public enum ExposureMode { | ||
auto("auto"), | ||
locked("locked"); | ||
|
||
private final String strValue; | ||
|
||
ExposureMode(String strValue) { | ||
this.strValue = strValue; | ||
} | ||
|
||
/** | ||
* Tries to convert the supplied string into an {@see ExposureMode} enum value. | ||
* | ||
* <p>When the supplied string doesn't match a valid {@see ExposureMode} enum value, null is | ||
* returned. | ||
* | ||
* @param modeStr String value to convert into an {@see ExposureMode} enum value. | ||
* @return Matching {@see ExposureMode} enum value, or null if no match is found. | ||
*/ | ||
public static ExposureMode getValueForString(String modeStr) { | ||
for (ExposureMode value : values()) { | ||
if (value.strValue.equals(modeStr)) { | ||
return value; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return strValue; | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
...rc/main/java/io/flutter/plugins/camera/features/exposureoffset/ExposureOffsetFeature.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package io.flutter.plugins.camera.features.exposureoffset; | ||
|
||
import android.hardware.camera2.CaptureRequest; | ||
import android.util.Range; | ||
import androidx.annotation.NonNull; | ||
import io.flutter.plugins.camera.CameraProperties; | ||
import io.flutter.plugins.camera.features.CameraFeature; | ||
|
||
/** Controls the exposure offset making the resulting image brighter or darker. */ | ||
public class ExposureOffsetFeature extends CameraFeature<Double> { | ||
|
||
private double currentSetting = 0; | ||
|
||
/** | ||
* Creates a new instance of the {@link ExposureOffsetFeature}. | ||
* | ||
* @param cameraProperties Collection of the characteristics for the current camera device. | ||
*/ | ||
public ExposureOffsetFeature(CameraProperties cameraProperties) { | ||
super(cameraProperties); | ||
} | ||
|
||
@Override | ||
public String getDebugName() { | ||
return "ExposureOffsetFeature"; | ||
} | ||
|
||
@Override | ||
public Double getValue() { | ||
return currentSetting; | ||
} | ||
|
||
@Override | ||
public void setValue(@NonNull Double value) { | ||
double stepSize = getExposureOffsetStepSize(); | ||
this.currentSetting = value / stepSize; | ||
} | ||
|
||
// Available on all devices. | ||
@Override | ||
public boolean checkIsSupported() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public void updateBuilder(CaptureRequest.Builder requestBuilder) { | ||
if (!checkIsSupported()) { | ||
return; | ||
} | ||
|
||
requestBuilder.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, (int) currentSetting); | ||
} | ||
|
||
/** | ||
* Returns the minimum exposure offset. | ||
* | ||
* @return double Minimum exposure offset. | ||
*/ | ||
public double getMinExposureOffset() { | ||
Range<Integer> range = cameraProperties.getControlAutoExposureCompensationRange(); | ||
double minStepped = range == null ? 0 : range.getLower(); | ||
double stepSize = getExposureOffsetStepSize(); | ||
return minStepped * stepSize; | ||
} | ||
|
||
/** | ||
* Returns the maximum exposure offset. | ||
* | ||
* @return double Maximum exposure offset. | ||
*/ | ||
public double getMaxExposureOffset() { | ||
Range<Integer> range = cameraProperties.getControlAutoExposureCompensationRange(); | ||
double maxStepped = range == null ? 0 : range.getUpper(); | ||
double stepSize = getExposureOffsetStepSize(); | ||
return maxStepped * stepSize; | ||
} | ||
|
||
/** | ||
* Returns the smallest step by which the exposure compensation can be changed. | ||
* | ||
* <p>Example: if this has a value of 0.5, then an aeExposureCompensation setting of -2 means that | ||
* the actual AE offset is -1. More details can be found in the official Android documentation: | ||
* https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics.html#CONTROL_AE_COMPENSATION_STEP | ||
* | ||
* @return double Smallest step by which the exposure compensation can be changed. | ||
*/ | ||
public double getExposureOffsetStepSize() { | ||
return cameraProperties.getControlAutoExposureCompensationStep(); | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
.../src/main/java/io/flutter/plugins/camera/features/exposurepoint/ExposurePointFeature.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package io.flutter.plugins.camera.features.exposurepoint; | ||
|
||
import android.hardware.camera2.CaptureRequest; | ||
import android.hardware.camera2.params.MeteringRectangle; | ||
import android.util.Log; | ||
import androidx.annotation.NonNull; | ||
import io.flutter.plugins.camera.CameraProperties; | ||
import io.flutter.plugins.camera.features.CameraFeature; | ||
import io.flutter.plugins.camera.features.Point; | ||
import io.flutter.plugins.camera.types.CameraRegions; | ||
|
||
/** Exposure point controls where in the frame exposure metering will come from. */ | ||
public class ExposurePointFeature extends CameraFeature<Point> { | ||
|
||
private final CameraRegions cameraRegions; | ||
private Point currentSetting = new Point(0.0, 0.0); | ||
|
||
/** | ||
* Creates a new instance of the {@link ExposurePointFeature}. | ||
* | ||
* @param cameraProperties Collection of the characteristics for the current camera device. | ||
* @param cameraRegions Utility class to assist in calculating exposure boundaries. | ||
*/ | ||
public ExposurePointFeature(CameraProperties cameraProperties, CameraRegions cameraRegions) { | ||
super(cameraProperties); | ||
this.cameraRegions = cameraRegions; | ||
} | ||
|
||
@Override | ||
public String getDebugName() { | ||
return "ExposurePointFeature"; | ||
} | ||
|
||
@Override | ||
public Point getValue() { | ||
return currentSetting; | ||
} | ||
|
||
@Override | ||
public void setValue(@NonNull Point value) { | ||
this.currentSetting = value; | ||
|
||
if (value.x == null || value.y == null) { | ||
cameraRegions.resetAutoExposureMeteringRectangle(); | ||
} else { | ||
cameraRegions.setAutoExposureMeteringRectangleFromPoint(value.x, value.y); | ||
} | ||
} | ||
|
||
// Whether or not this camera can set the exposure point. | ||
@Override | ||
public boolean checkIsSupported() { | ||
Integer supportedRegions = cameraProperties.getControlMaxRegionsAutoExposure(); | ||
return supportedRegions != null && supportedRegions > 0; | ||
} | ||
|
||
@Override | ||
public void updateBuilder(CaptureRequest.Builder requestBuilder) { | ||
if (!checkIsSupported()) { | ||
return; | ||
} | ||
|
||
MeteringRectangle aeRect = null; | ||
try { | ||
aeRect = cameraRegions.getAEMeteringRectangle(); | ||
} catch (Exception e) { | ||
Log.w("Camera", "Unable to retrieve the Auto Exposure metering rectangle.", e); | ||
} | ||
|
||
requestBuilder.set( | ||
CaptureRequest.CONTROL_AE_REGIONS, | ||
aeRect == null ? null : new MeteringRectangle[] {aeRect}); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.