Skip to content

[camera_android] Provides a default exposure point if null #3718

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/camera/camera_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.10.8

* Provides a default exposure point if null.

## 0.10.7

* Adds support for NV21 as a new streaming format in Android which includes correct handling of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class ExposurePointFeature extends CameraFeature<Point> {

private Size cameraBoundaries;
@Nullable private Point exposurePoint;
private Point exposurePoint;
private MeteringRectangle[] defaultExposureRectangle;
private MeteringRectangle exposureRectangle;
@NonNull private final SensorOrientationFeature sensorOrientationFeature;

Expand Down Expand Up @@ -78,9 +80,15 @@ public void updateBuilder(@NonNull CaptureRequest.Builder requestBuilder) {
if (!checkIsSupported()) {
return;
}
requestBuilder.set(
CaptureRequest.CONTROL_AE_REGIONS,
exposureRectangle == null ? null : new MeteringRectangle[] {exposureRectangle});
if (defaultExposureRectangle == null) {
defaultExposureRectangle = requestBuilder.get(CaptureRequest.CONTROL_AE_REGIONS);
}
if (exposureRectangle != null) {
requestBuilder.set(
CaptureRequest.CONTROL_AE_REGIONS, new MeteringRectangle[] {exposureRectangle});
} else if (shouldReset(requestBuilder)) {
requestBuilder.set(CaptureRequest.CONTROL_AE_REGIONS, defaultExposureRectangle);
}
}

private void buildExposureRectangle() {
Expand All @@ -102,4 +110,9 @@ private void buildExposureRectangle() {
this.cameraBoundaries, this.exposurePoint.x, this.exposurePoint.y, orientation);
}
}

public boolean shouldReset(CaptureRequest.Builder requestBuilder) {
MeteringRectangle[] currentRectangles = requestBuilder.get(CaptureRequest.CONTROL_AE_REGIONS);
return currentRectangles == null || currentRectangles.length == 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class ExposurePointFeatureTest {
Size mockCameraBoundaries;
SensorOrientationFeature mockSensorOrientationFeature;
DeviceOrientationManager mockDeviceOrientationManager;
MeteringRectangle[] mockDefaultExposureRectangle;
MeteringRectangle mockExposureRectangle;

@Before
public void setUp() {
Expand Down Expand Up @@ -308,6 +310,24 @@ public void updateBuilder_shouldNotSetMeteringRectangleWhenNoValidCoordsAreSuppl
exposurePointFeature.updateBuilder(mockCaptureRequestBuilder);
exposurePointFeature.setValue(new Point(null, 0d));
exposurePointFeature.updateBuilder(mockCaptureRequestBuilder);

verify(mockCaptureRequestBuilder, times(3)).set(any(), isNull());
}

@Test
public void testShouldResetReturnsFalse() {
CaptureRequest.Builder mockCaptureRequestBuilder = mock(CaptureRequest.Builder.class);
MeteringRectangle[] defaultRectangles = new MeteringRectangle[1];
defaultRectangles[0] = mock(MeteringRectangle.class);
when(mockCaptureRequestBuilder.get(CaptureRequest.CONTROL_AE_REGIONS))
.thenReturn(defaultRectangles);
mockCaptureRequestBuilder.set(CaptureRequest.CONTROL_AE_REGIONS, defaultRectangles);

ExposurePointFeature exposurePointFeature = mock(ExposurePointFeature.class);
exposurePointFeature.setCameraBoundaries(this.mockCameraBoundaries);
exposurePointFeature.setValue(new Point(0.5, 0.5));
exposurePointFeature.updateBuilder(mockCaptureRequestBuilder);

assertFalse(exposurePointFeature.shouldReset(mockCaptureRequestBuilder));
}
}
3 changes: 2 additions & 1 deletion packages/camera/camera_android/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ name: camera_android
description: Android implementation of the camera plugin.
repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_android
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
version: 0.10.7

version: 0.10.8

environment:
sdk: ">=2.17.0 <4.0.0"
Expand Down