Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
[camera] Provides a default exposure point if null
  • Loading branch information
Mairramer committed Apr 16, 2023
commit c59aad8f1023e318687e70fb33a790486e6aafd4
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
import io.flutter.plugins.camera.features.CameraFeature;
import io.flutter.plugins.camera.features.Point;
import io.flutter.plugins.camera.features.sensororientation.SensorOrientationFeature;
import java.util.Arrays;

/** Exposure point controls where in the frame exposure metering will come from. */
public class ExposurePointFeature extends CameraFeature<Point> {

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

Expand Down Expand Up @@ -72,9 +74,14 @@ public void updateBuilder(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 @@ -96,4 +103,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 @@ -10,6 +10,7 @@
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
Expand All @@ -29,12 +30,15 @@
import org.junit.Test;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import java.util.Arrays;

public class ExposurePointFeatureTest {

Size mockCameraBoundaries;
SensorOrientationFeature mockSensorOrientationFeature;
DeviceOrientationManager mockDeviceOrientationManager;
MeteringRectangle[] mockDefaultExposureRectangle;
MeteringRectangle mockExposureRectangle;

@Before
public void setUp() {
Expand Down Expand Up @@ -290,7 +294,7 @@ public void updateBuilder_shouldNotSetMeteringRectangleWhenNoValidBoundariesAreS

exposurePointFeature.updateBuilder(mockCaptureRequestBuilder);

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

@Test
Expand All @@ -308,6 +312,23 @@ public void updateBuilder_shouldNotSetMeteringRectangleWhenNoValidCoordsAreSuppl
exposurePointFeature.updateBuilder(mockCaptureRequestBuilder);
exposurePointFeature.setValue(new Point(null, 0d));
exposurePointFeature.updateBuilder(mockCaptureRequestBuilder);
verify(mockCaptureRequestBuilder, times(3)).set(any(), isNull());

verify(mockCaptureRequestBuilder, never()).set(any(), any());
}

@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));
}
}
}