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
59 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
b595f93
Add Android and iOS implementations (WIP)
BeMacized Dec 25, 2020
bdeed1d
Update platform interface for changes to autofocus methods
BeMacized Dec 25, 2020
e63b537
Merge branch 'feature/camera_focus_auto_platform_interface' into feat…
BeMacized Dec 25, 2020
4e405b0
WIP
BeMacized Dec 25, 2020
798d458
Revert "Update platform interface for changes to autofocus methods"
BeMacized Dec 25, 2020
7a6a21c
Merge branch 'feature/camera_focus_auto_platform_interface' into feat…
BeMacized Dec 25, 2020
68d3e74
Finish android implementation
BeMacized Dec 25, 2020
d830704
Fix iOS implementation
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
10f3d61
Merge branch 'feature/camera_focus_auto_platform_interface' into feat…
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
73f6798
Merge branch 'feature/camera_focus_auto_platform_interface' into feat…
BeMacized Dec 25, 2020
df1c09b
Updated changelog and pubspec.yaml
BeMacized Dec 25, 2020
ff45da4
Updated changelog and pubspec.yaml
BeMacized Dec 25, 2020
a6e47e8
Merge branch 'feature/camera_focus_auto_platform_interface' into feat…
BeMacized Dec 25, 2020
95b4795
Merge branch 'master' into feature/camera_focus_auto_platform_interface
BeMacized Dec 25, 2020
6d9f9ca
Merge branch 'feature/camera_focus_auto_platform_interface' into feat…
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
58d9411
Merge branch 'feature/camera_focus_auto_platform_interface' into feat…
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
0842f2c
Merge branch 'feature/camera_focus_auto_platform_interface' into feat…
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
6fb50d6
Merge branch 'feature/camera_focus_auto_platform_interface' into feat…
BeMacized Dec 30, 2020
930d901
Update camera pubspec
BeMacized Dec 30, 2020
5ebbca5
Merge branch 'feature/camera_focus_auto_platform_interface' into feat…
BeMacized Dec 30, 2020
60a1137
Update platform interface to prevent breaking changes with current ma…
BeMacized Dec 30, 2020
525d58c
Merge branch 'feature/camera_focus_auto_platform_interface' into feat…
BeMacized Dec 30, 2020
b0149e9
Update test to match platform interface updates
BeMacized Dec 30, 2020
e6367bd
Code format
BeMacized Dec 30, 2020
9473843
Merged with master
mvanbeusekom Jan 6, 2021
4ebae73
Merged with master
mvanbeusekom Jan 6, 2021
23fe0db
Merged with master
mvanbeusekom Jan 7, 2021
971b4e6
Fixed compilation error
mvanbeusekom Jan 7, 2021
6d174fb
Fix formatting
mvanbeusekom Jan 7, 2021
50dcdce
Update version number
mvanbeusekom Jan 7, 2021
5d8c235
Add missing license headers to java source files.
BeMacized Jan 11, 2021
9500a74
Merge branch 'master' into feature/camera_focus_auto
BeMacized Jan 11, 2021
0ba1c90
Update platform interface dependency
BeMacized Jan 11, 2021
bc97fb9
Merge branch 'feature/camera_focus_auto' of github.com:Baseflow/flutt…
BeMacized Jan 11, 2021
a6f4442
Change fps range determination
BeMacized Jan 11, 2021
1a0ced8
Update with master branch
mvanbeusekom Jan 11, 2021
bcacd4b
Fix analysis warnings
mvanbeusekom Jan 11, 2021
c11c46f
Update version number
mvanbeusekom Jan 11, 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
Merged with master
  • Loading branch information
mvanbeusekom committed Jan 6, 2021
commit 9473843d2794f45b65cfc47242439d80cd636cd0
17 changes: 17 additions & 0 deletions packages/camera/camera/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@

## 0.6.5

* Adds auto exposure support for Android and iOS implementations.

## 0.6.4+3

* Detect if selected camera supports auto focus and act accordingly on Android. This solves a problem where front facing cameras are not capturing the picture because auto focus is not supported.

## 0.6.4+2

* Set ImageStreamReader listener to null to prevent stale images when streaming images.

## 0.6.4+1

* Added closeCaptureSession() to stopVideoRecording in Camera.java to fix an Android 6 crash

## 0.6.4

* Adds auto exposure support for Android and iOS implementations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import android.os.Build.VERSION_CODES;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.util.Range;
import android.util.Rational;
import android.util.Size;
Expand Down Expand Up @@ -95,6 +96,8 @@ public class Camera {
private PictureCaptureRequest pictureCaptureRequest;
private CameraRegions cameraRegions;
private int exposureOffset;
private boolean useAutoFocus;
private Range<Integer> fpsRange;

public Camera(
final Activity activity,
Expand Down Expand Up @@ -939,132 +942,6 @@ private void updateFlash(FlashMode mode) {
// Get flash
flashMode = mode;

public void setExposureMode(@NonNull final Result result, ExposureMode mode)
throws CameraAccessException {
this.exposureMode = mode;
initPreviewCaptureBuilder();
cameraCaptureSession.setRepeatingRequest(captureRequestBuilder.build(), null, null);
result.success(null);
}

public void setExposurePoint(@NonNull final Result result, Double x, Double y)
throws CameraAccessException {
// Check if exposure point functionality is available.
if (!isExposurePointSupported()) {
result.error(
"setExposurePointFailed", "Device does not have exposure point capabilities", null);
return;
}
// Check if we are doing a reset or not
if (x == null || y == null) {
x = 0.5;
y = 0.5;
}
// Get the current region boundaries.
Size maxBoundaries = getRegionBoundaries();
if (maxBoundaries == null) {
result.error("setExposurePointFailed", "Could not determine max region boundaries", null);
return;
}
// Set the metering rectangle
cameraRegions.setAutoExposureMeteringRectangleFromPoint(x, y);
// Apply it
initPreviewCaptureBuilder();
this.cameraCaptureSession.setRepeatingRequest(
captureRequestBuilder.build(), pictureCaptureCallback, null);
result.success(null);
}

@TargetApi(VERSION_CODES.P)
private boolean supportsDistortionCorrection() throws CameraAccessException {
int[] availableDistortionCorrectionModes =
cameraManager
.getCameraCharacteristics(cameraDevice.getId())
.get(CameraCharacteristics.DISTORTION_CORRECTION_AVAILABLE_MODES);
if (availableDistortionCorrectionModes == null) availableDistortionCorrectionModes = new int[0];
long nonOffModesSupported =
Arrays.stream(availableDistortionCorrectionModes)
.filter((value) -> value != CaptureRequest.DISTORTION_CORRECTION_MODE_OFF)
.count();
return nonOffModesSupported > 0;
}

private Size getRegionBoundaries() throws CameraAccessException {
// No distortion correction support
if (android.os.Build.VERSION.SDK_INT < VERSION_CODES.P || !supportsDistortionCorrection()) {
return cameraManager
.getCameraCharacteristics(cameraDevice.getId())
.get(CameraCharacteristics.SENSOR_INFO_PIXEL_ARRAY_SIZE);
}
// Get the current distortion correction mode
Integer distortionCorrectionMode =
captureRequestBuilder.get(CaptureRequest.DISTORTION_CORRECTION_MODE);
// Return the correct boundaries depending on the mode
android.graphics.Rect rect;
if (distortionCorrectionMode == null
|| distortionCorrectionMode == CaptureRequest.DISTORTION_CORRECTION_MODE_OFF) {
rect =
cameraManager
.getCameraCharacteristics(cameraDevice.getId())
.get(CameraCharacteristics.SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE);
} else {
rect =
cameraManager
.getCameraCharacteristics(cameraDevice.getId())
.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE);
}
return rect == null ? null : new Size(rect.width(), rect.height());
}

private boolean isExposurePointSupported() throws CameraAccessException {
Integer supportedRegions =
cameraManager
.getCameraCharacteristics(cameraDevice.getId())
.get(CameraCharacteristics.CONTROL_MAX_REGIONS_AE);
return supportedRegions != null && supportedRegions > 0;
}

public double getMinExposureOffset() throws CameraAccessException {
Range<Integer> range =
cameraManager
.getCameraCharacteristics(cameraDevice.getId())
.get(CameraCharacteristics.CONTROL_AE_COMPENSATION_RANGE);
double minStepped = range == null ? 0 : range.getLower();
double stepSize = getExposureOffsetStepSize();
return minStepped * stepSize;
}

public double getMaxExposureOffset() throws CameraAccessException {
Range<Integer> range =
cameraManager
.getCameraCharacteristics(cameraDevice.getId())
.get(CameraCharacteristics.CONTROL_AE_COMPENSATION_RANGE);
double maxStepped = range == null ? 0 : range.getUpper();
double stepSize = getExposureOffsetStepSize();
return maxStepped * stepSize;
}

public double getExposureOffsetStepSize() throws CameraAccessException {
Rational stepSize =
cameraManager
.getCameraCharacteristics(cameraDevice.getId())
.get(CameraCharacteristics.CONTROL_AE_COMPENSATION_STEP);
return stepSize == null ? 0.0 : stepSize.doubleValue();
}

public void setExposureOffset(@NonNull final Result result, double offset)
throws CameraAccessException {
// Set the exposure offset
double stepSize = getExposureOffsetStepSize();
exposureOffset = (int) (offset / stepSize);
// Apply it
initPreviewCaptureBuilder();
this.cameraCaptureSession.setRepeatingRequest(captureRequestBuilder.build(), null, null);
result.success(offset);
}

private void initPreviewCaptureBuilder() {
captureRequestBuilder.set(CaptureRequest.CONTROL_MODE, CaptureRequest.CONTROL_MODE_AUTO);
// Applying flash modes
switch (flashMode) {
case off:
Expand All @@ -1089,24 +966,6 @@ private void initPreviewCaptureBuilder() {
captureRequestBuilder.set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_TORCH);
break;
}
// Applying auto exposure
MeteringRectangle aeRect = cameraRegions.getAEMeteringRectangle();
captureRequestBuilder.set(
CaptureRequest.CONTROL_AE_REGIONS,
new MeteringRectangle[] {cameraRegions.getAEMeteringRectangle()});
switch (exposureMode) {
case locked:
captureRequestBuilder.set(CaptureRequest.CONTROL_AE_LOCK, true);
break;
case auto:
default:
captureRequestBuilder.set(CaptureRequest.CONTROL_AE_LOCK, false);
break;
}
captureRequestBuilder.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, exposureOffset);
// Applying auto focus
captureRequestBuilder.set(
CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
}

public void startPreview() throws CameraAccessException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ public final class CameraRegions {
private Size maxBoundaries;

public CameraRegions(Size maxBoundaries) {
assert (maxBoundaries != null);
assert (maxBoundaries.getWidth() > 0);
assert (maxBoundaries.getHeight() > 0);
assert (maxBoundaries == null || maxBoundaries.getWidth() > 0);
assert (maxBoundaries == null || maxBoundaries.getHeight() > 0);
this.maxBoundaries = maxBoundaries;
setAutoExposureMeteringRectangleFromPoint(0.5, 0.5);
}

public MeteringRectangle getAEMeteringRectangle() {
Expand All @@ -23,14 +21,20 @@ public Size getMaxBoundaries() {
return this.maxBoundaries;
}

public void resetAutoExposureMeteringRectangle() {
this.aeMeteringRectangle = null;
}

public void setAutoExposureMeteringRectangleFromPoint(double x, double y) {
this.aeMeteringRectangle = getMeteringRectangleForPoint(maxBoundaries, x, y);
}

public MeteringRectangle getMeteringRectangleForPoint(Size maxBoundaries, double x, double y) {
assert (x >= 0 && x <= 1);
assert (y >= 0 && y <= 1);
assert (maxBoundaries != null);
if (maxBoundaries == null)
throw new IllegalStateException(
"Functionality for managing metering rectangles is unavailable as this CameraRegions instance was initialized with null boundaries.");

// Interpolate the target coordinate
int targetX = (int) Math.round(x * ((double) (maxBoundaries.getWidth() - 1)));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.flutter.plugins.camera;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

import android.hardware.camera2.params.MeteringRectangle;
import android.util.Size;
Expand Down Expand Up @@ -39,7 +41,7 @@ public void getMeteringRectangleForPoint_should_throw_for_y_lower_bound() {
cameraRegions.getMeteringRectangleForPoint(new Size(10, 10), 0, -0.5);
}

@Test(expected = AssertionError.class)
@Test(expected = IllegalStateException.class)
public void getMeteringRectangleForPoint_should_throw_for_null_boundaries() {
cameraRegions.getMeteringRectangleForPoint(null, 0, -0);
}
Expand Down Expand Up @@ -68,11 +70,6 @@ public void getMeteringRectangleForPoint_should_return_valid_MeteringRectangle()
assertEquals(new MeteringRectangle(89, 0, 10, 5, 1), r);
}

@Test(expected = AssertionError.class)
public void constructor_should_throw_for_null_boundaries() {
new CameraRegions(null);
}

@Test(expected = AssertionError.class)
public void constructor_should_throw_for_0_width_boundary() {
new CameraRegions(new Size(0, 50));
Expand All @@ -87,13 +84,22 @@ public void constructor_should_throw_for_0_height_boundary() {
public void constructor_should_initialize() {
CameraRegions cr = new CameraRegions(new Size(100, 50));
assertEquals(new Size(100, 50), cr.getMaxBoundaries());
assertEquals(new MeteringRectangle(45, 23, 10, 5, 1), cr.getAEMeteringRectangle());
assertNull(cr.getAEMeteringRectangle());
}

@Test
public void setAutoExposureMeteringRectangleFromPoin_should_set_aeMeteringRectangle_for_point() {
public void setAutoExposureMeteringRectangleFromPoint_should_set_aeMeteringRectangle_for_point() {
CameraRegions cr = new CameraRegions(new Size(100, 50));
cr.setAutoExposureMeteringRectangleFromPoint(0, 0);
assertEquals(new MeteringRectangle(0, 0, 10, 5, 1), cr.getAEMeteringRectangle());
}

@Test
public void resetAutoExposureMeteringRectangle_should_reset_aeMeteringRectangle() {
CameraRegions cr = new CameraRegions(new Size(100, 50));
cr.setAutoExposureMeteringRectangleFromPoint(0, 0);
assertNotNull(cr.getAEMeteringRectangle());
cr.resetAutoExposureMeteringRectangle();
assertNull(cr.getAEMeteringRectangle());
}
}
4 changes: 2 additions & 2 deletions packages/camera/camera/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ name: camera
description: A Flutter plugin for getting information about and controlling the
camera on Android and iOS. Supports previewing the camera feed, capturing images, capturing video,
and streaming image buffers to dart.
version: 0.6.4
version: 0.6.5
homepage: https://github.com/flutter/plugins/tree/master/packages/camera/camera

dependencies:
flutter:
sdk: flutter
camera_platform_interface: '>=1.0.4 <1.3.0'
camera_platform_interface: ^1.2.0
pedantic: ^1.8.0

dev_dependencies:
Expand Down
2 changes: 1 addition & 1 deletion packages/camera/camera/test/camera_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ get mockAvailableCameras => [
get mockInitializeCamera => 13;

get mockOnCameraInitializedEvent =>
CameraInitializedEvent(13, 75, 75, ExposureMode.auto, false);
CameraInitializedEvent(13, 75, 75, ExposureMode.auto, true);

get mockOnCameraClosingEvent => null;

Expand Down
6 changes: 5 additions & 1 deletion packages/camera/camera_platform_interface/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
## 1.3.0
## 1.4.0

- Added interface methods to support auto focus.

## 1.3.0

- Introduces an option to set the image format when initializing.

## 1.2.0

- Added interface to support automatic exposure.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'dart:math';

import 'package:camera_platform_interface/camera_platform_interface.dart';
import 'package:camera_platform_interface/src/types/focus_mode.dart';
import 'package:camera_platform_interface/src/types/image_format_group.dart';
import 'package:camera_platform_interface/src/utils/utils.dart';
import 'package:cross_file/cross_file.dart';
import 'package:flutter/services.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:camera_platform_interface/camera_platform_interface.dart';
import 'package:camera_platform_interface/src/method_channel/method_channel_camera.dart';
import 'package:camera_platform_interface/src/types/exposure_mode.dart';
import 'package:camera_platform_interface/src/types/focus_mode.dart';
import 'package:camera_platform_interface/src/types/image_format_group.dart';
import 'package:cross_file/cross_file.dart';
import 'package:flutter/widgets.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
Expand Down
2 changes: 1 addition & 1 deletion packages/camera/camera_platform_interface/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: A common platform interface for the camera plugin.
homepage: https://github.com/flutter/plugins/tree/master/packages/camera/camera_platform_interface
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
version: 1.3.0
version: 1.4.0

dependencies:
flutter:
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.