Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c9f7e21
Added platform interface methods for setting auto exposure.
BeMacized Dec 24, 2020
532b22f
Added platform interface methods for setting auto exposure.
BeMacized Dec 24, 2020
1844b24
Remove workspace files
BeMacized Dec 24, 2020
fd8dd40
Added auto exposure implementations for Android and iOS
BeMacized Dec 24, 2020
92966de
Added platform interface methods for managing auto focus.
BeMacized Dec 25, 2020
deea6a0
Formatted code
BeMacized Dec 25, 2020
42a4517
Export focus mode
BeMacized Dec 25, 2020
bdeed1d
Update platform interface for changes to autofocus methods
BeMacized Dec 25, 2020
798d458
Revert "Update platform interface for changes to autofocus methods"
BeMacized Dec 25, 2020
2b98bdd
iOS fix for setting the exposure point
BeMacized Dec 25, 2020
b886e55
Merge branch 'feature/camera_exposure_auto' into feature/camera_focus…
BeMacized Dec 25, 2020
06f436f
Removed unnecessary check
BeMacized Dec 25, 2020
e19c2a5
Merge branch 'feature/camera_exposure_auto' into feature/camera_focus…
BeMacized Dec 25, 2020
df1c09b
Updated changelog and pubspec.yaml
BeMacized Dec 25, 2020
95b4795
Merge branch 'master' into feature/camera_focus_auto_platform_interface
BeMacized Dec 25, 2020
70804a0
Merge branch 'master' into feature/camera_exposure_auto
BeMacized Dec 29, 2020
5f1a730
Merge branch 'feature/camera_exposure_auto' into feature/camera_focus…
BeMacized Dec 29, 2020
7b4445d
Merge branch 'master' into feature/camera_exposure_auto
BeMacized Dec 29, 2020
67b37f2
Merge branch 'feature/camera_exposure_auto' into feature/camera_focus…
BeMacized Dec 29, 2020
14c6ab6
Update platform interface dependency
BeMacized Dec 29, 2020
a52f690
Implement PR feedback
BeMacized Dec 29, 2020
1e6ed87
Merge branch 'master' into feature/camera_exposure_auto
BeMacized Dec 29, 2020
9a88bca
Restore test
BeMacized Dec 29, 2020
0b748ef
Merge branch 'feature/camera_exposure_auto' into feature/camera_focus…
BeMacized Dec 30, 2020
171fe0b
Revert test change
BeMacized Dec 30, 2020
930d901
Update camera pubspec
BeMacized Dec 30, 2020
60a1137
Update platform interface to prevent breaking changes with current ma…
BeMacized Dec 30, 2020
07c4339
Merged with master
mvanbeusekom Jan 6, 2021
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
Prev Previous commit
Next Next commit
Added auto exposure implementations for Android and iOS
  • Loading branch information
BeMacized committed Dec 24, 2020
commit fd8dd401ec7a4c477be53352fcfa0ad4ff35df54
8 changes: 8 additions & 0 deletions packages/camera/camera/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 0.6.4

* Adds auto exposure support for Android and iOS implementations.

## 0.6.3+1

* Fixes flash & torch modes not working on some Android devices.

## 0.6.3

* Adds torch mode as a flash mode for Android and iOS implementations.
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import androidx.annotation.Nullable;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugins.camera.types.ExposureMode;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -20,13 +21,23 @@ enum EventType {
channel = new MethodChannel(messenger, "flutter.io/cameraPlugin/camera" + cameraId);
}

void sendCameraInitializedEvent(Integer previewWidth, Integer previewHeight) {
void sendCameraInitializedEvent(
Integer previewWidth,
Integer previewHeight,
ExposureMode exposureMode,
Boolean exposurePointSupported) {
assert (previewWidth != null);
assert (previewHeight != null);
assert (exposureMode != null);
assert (exposurePointSupported != null);
this.send(
EventType.INITIALIZED,
new HashMap<String, Object>() {
{
if (previewWidth != null) put("previewWidth", previewWidth.doubleValue());
if (previewHeight != null) put("previewHeight", previewHeight.doubleValue());
put("previewWidth", previewWidth.doubleValue());
put("previewHeight", previewHeight.doubleValue());
put("exposureMode", exposureMode.toString());
put("exposurePointSupported", exposurePointSupported);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugins.camera.CameraPermissions.PermissionsRegistry;
import io.flutter.plugins.camera.types.ExposureMode;
import io.flutter.plugins.camera.types.FlashMode;
import io.flutter.view.TextureRegistry;
import java.util.HashMap;
Expand Down Expand Up @@ -138,6 +139,73 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull final Result result)
}
break;
}
case "setExposureMode":
{
String modeStr = call.argument("mode");
ExposureMode mode = ExposureMode.getValueForString(modeStr);
if (mode == null) {
result.error("setExposureModeFailed", "Unknown exposure mode " + modeStr, null);
return;
}
try {
camera.setExposureMode(result, mode);
} catch (Exception e) {
handleException(e, result);
}
break;
}
case "setExposurePoint":
{
Boolean reset = call.argument("reset");
Double x = null;
Double y = null;
if (reset == null || !reset) {
x = call.argument("x");
y = call.argument("y");
}
try {
camera.setExposurePoint(result, x, y);
} catch (Exception e) {
handleException(e, result);
}
break;
}
case "getMinExposureOffset":
{
try {
result.success(camera.getMinExposureOffset());
} catch (Exception e) {
handleException(e, result);
}
break;
}
case "getMaxExposureOffset":
{
try {
result.success(camera.getMaxExposureOffset());
} catch (Exception e) {
handleException(e, result);
}
break;
}
case "getExposureOffsetStepSize":
{
try {
result.success(camera.getExposureOffsetStepSize());
} catch (Exception e) {
handleException(e, result);
}
break;
}
case "setExposureOffset":
{
try {
camera.setExposureOffset(result, call.argument("offset"));
} catch (Exception e) {
handleException(e, result);
}
break;
}
case "startImageStream":
{
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ class PictureCaptureRequest {

enum State {
idle,
awaitingPreCapture,
focusing,
preCapture,
waitingPreCaptureReady,
capturing,
finished,
error,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.flutter.plugins.camera.types;

// Mirrors exposure_mode.dart
public enum ExposureMode {
auto("auto"),
locked("locked");

private final String strValue;

ExposureMode(String strValue) {
this.strValue = strValue;
}

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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,26 @@

// Mirrors flash_mode.dart
public enum FlashMode {
off,
auto,
always,
torch;
off("off"),
auto("auto"),
always("always"),
torch("torch");

private final String strValue;

FlashMode(String strValue) {
this.strValue = strValue;
}

public static FlashMode getValueForString(String modeStr) {
try {
return valueOf(modeStr);
} catch (IllegalArgumentException | NullPointerException e) {
return null;
for (FlashMode value : values()) {
if (value.strValue.equals(modeStr)) return value;
}
return null;
}

@Override
public String toString() {
return strValue;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,16 @@ public void sendCameraErrorEvent_includesErrorDescriptions() {

@Test
public void sendCameraInitializedEvent_includesPreviewSize() {
dartMessenger.sendCameraInitializedEvent(0, 0);
dartMessenger.sendCameraInitializedEvent(0, 0, ExposureMode.auto, true);

List<ByteBuffer> sentMessages = fakeBinaryMessenger.getMessages();
assertEquals(1, sentMessages.size());
MethodCall call = decodeSentMessage(sentMessages.get(0));
assertEquals("initialized", call.method);
assertEquals(0, (double) call.argument("previewWidth"), 0);
assertEquals(0, (double) call.argument("previewHeight"), 0);
assertEquals("ExposureMode auto", call.argument("exposureMode"), "auto");
assertEquals("exposurePointSupported", call.argument("exposurePointSupported"), true);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@ public void state_is_idle_by_default() {
@Test
public void setState_sets_state() {
PictureCaptureRequest req = new PictureCaptureRequest(null);
req.setState(PictureCaptureRequest.State.awaitingPreCapture);
req.setState(PictureCaptureRequest.State.focusing);
assertEquals("State is focusing", req.getState(), PictureCaptureRequest.State.focusing);
req.setState(PictureCaptureRequest.State.preCapture);
assertEquals("State is preCapture", req.getState(), PictureCaptureRequest.State.preCapture);
req.setState(PictureCaptureRequest.State.waitingPreCaptureReady);
assertEquals(
"State is awaitingPreCapture",
"State is waitingPreCaptureReady",
req.getState(),
PictureCaptureRequest.State.awaitingPreCapture);
PictureCaptureRequest.State.waitingPreCaptureReady);
req.setState(PictureCaptureRequest.State.capturing);
assertEquals(
"State is awaitingPreCapture", req.getState(), PictureCaptureRequest.State.capturing);
Expand All @@ -49,7 +53,7 @@ public void isFinished_is_true_When_state_is_finished_or_error() {
// Test false states
req.setState(PictureCaptureRequest.State.idle);
assertFalse(req.isFinished());
req.setState(PictureCaptureRequest.State.awaitingPreCapture);
req.setState(PictureCaptureRequest.State.preCapture);
assertFalse(req.isFinished());
req.setState(PictureCaptureRequest.State.capturing);
assertFalse(req.isFinished());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package io.flutter.plugins.camera.types;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

public class ExposureModeTest {

@Test
public void getValueForString_returns_correct_values() {
assertEquals(
"Returns ExposureMode.auto for 'auto'",
ExposureMode.getValueForString("auto"),
ExposureMode.auto);
assertEquals(
"Returns ExposureMode.locked for 'locked'",
ExposureMode.getValueForString("locked"),
ExposureMode.locked);
}

@Test
public void getValueForString_returns_null_for_nonexistant_value() {
assertEquals(
"Returns null for 'nonexistant'", ExposureMode.getValueForString("nonexistant"), null);
}

@Test
public void toString_returns_correct_value() {
assertEquals("Returns 'auto' for ExposureMode.auto", ExposureMode.auto.toString(), "auto");
assertEquals(
"Returns 'locked' for ExposureMode.locked", ExposureMode.locked.toString(), "locked");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,12 @@ public void getValueForString_returns_null_for_nonexistant_value() {
assertEquals(
"Returns null for 'nonexistant'", FlashMode.getValueForString("nonexistant"), null);
}

@Test
public void toString_returns_correct_value() {
assertEquals("Returns 'off' for FlashMode.off", FlashMode.off.toString(), "off");
assertEquals("Returns 'auto' for FlashMode.auto", FlashMode.auto.toString(), "auto");
assertEquals("Returns 'always' for FlashMode.always", FlashMode.always.toString(), "always");
assertEquals("Returns 'torch' for FlashMode.torch", FlashMode.torch.toString(), "torch");
}
}
Loading