Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 532b22f

Browse files
committed
Added platform interface methods for setting auto exposure.
1 parent c9f7e21 commit 532b22f

File tree

15 files changed

+529
-27
lines changed

15 files changed

+529
-27
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5490cb309144ac61a67edda5c46bb18b
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#
2+
# NOTE: This podspec is NOT to be published. It is only used as a local source!
3+
#
4+
5+
Pod::Spec.new do |s|
6+
s.name = 'Flutter'
7+
s.version = '1.0.0'
8+
s.summary = 'High-performance, high-fidelity mobile apps.'
9+
s.description = <<-DESC
10+
Flutter provides an easy and productive way to build and deploy high-performance mobile apps for Android and iOS.
11+
DESC
12+
s.homepage = 'https://flutter.io'
13+
s.license = { :type => 'MIT' }
14+
s.author = { 'Flutter Dev Team' => 'flutter-dev@googlegroups.com' }
15+
s.source = { :git => 'https://github.com/flutter/engine', :tag => s.version.to_s }
16+
s.ios.deployment_target = '8.0'
17+
s.vendored_frameworks = 'Flutter.framework'
18+
end
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

packages/camera/camera_platform_interface/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.0.5
2+
3+
- Added interface to support automatic exposure.
4+
15
## 1.0.4
26

37
- Added the torch option to the FlashMode enum, which when implemented indicates the flash light should be turned on continuously.

packages/camera/camera_platform_interface/lib/src/events/camera_event.dart

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import '../../camera_platform_interface.dart';
6+
57
/// Generic Event coming from the native side of Camera.
68
///
79
/// All [CameraEvent]s contain the `cameraId` that originated the event. This
@@ -45,6 +47,12 @@ class CameraInitializedEvent extends CameraEvent {
4547
/// The height of the preview in pixels.
4648
final double previewHeight;
4749

50+
/// The default exposure mode
51+
final ExposureMode exposureMode;
52+
53+
/// Whether setting exposure points is supported.
54+
final bool exposurePointSupported;
55+
4856
/// Build a CameraInitialized event triggered from the camera represented by
4957
/// `cameraId`.
5058
///
@@ -54,13 +62,17 @@ class CameraInitializedEvent extends CameraEvent {
5462
int cameraId,
5563
this.previewWidth,
5664
this.previewHeight,
65+
this.exposureMode,
66+
this.exposurePointSupported,
5767
) : super(cameraId);
5868

5969
/// Converts the supplied [Map] to an instance of the [CameraInitializedEvent]
6070
/// class.
6171
CameraInitializedEvent.fromJson(Map<String, dynamic> json)
6272
: previewWidth = json['previewWidth'],
6373
previewHeight = json['previewHeight'],
74+
exposureMode = deserializeExposureMode(json['exposureMode']),
75+
exposurePointSupported = json['exposurePointSupported'],
6476
super(json['cameraId']);
6577

6678
/// Converts the [CameraInitializedEvent] instance into a [Map] instance that
@@ -69,6 +81,8 @@ class CameraInitializedEvent extends CameraEvent {
6981
'cameraId': cameraId,
7082
'previewWidth': previewWidth,
7183
'previewHeight': previewHeight,
84+
'exposureMode': serializeExposureMode(exposureMode),
85+
'exposurePointSupported': exposurePointSupported,
7286
};
7387

7488
@override
@@ -78,11 +92,17 @@ class CameraInitializedEvent extends CameraEvent {
7892
other is CameraInitializedEvent &&
7993
runtimeType == other.runtimeType &&
8094
previewWidth == other.previewWidth &&
81-
previewHeight == other.previewHeight;
95+
previewHeight == other.previewHeight &&
96+
exposureMode == other.exposureMode &&
97+
exposurePointSupported == other.exposurePointSupported;
8298

8399
@override
84100
int get hashCode =>
85-
super.hashCode ^ previewWidth.hashCode ^ previewHeight.hashCode;
101+
super.hashCode ^
102+
previewWidth.hashCode ^
103+
previewHeight.hashCode ^
104+
exposureMode.hashCode ^
105+
exposurePointSupported.hashCode;
86106
}
87107

88108
/// An event fired when the resolution preset of the camera has changed.

packages/camera/camera_platform_interface/lib/src/method_channel/method_channel_camera.dart

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// found in the LICENSE file.
44

55
import 'dart:async';
6+
import 'dart:math';
67

78
import 'package:camera_platform_interface/camera_platform_interface.dart';
89
import 'package:camera_platform_interface/src/utils/utils.dart';
@@ -185,6 +186,62 @@ class MethodChannelCamera extends CameraPlatform {
185186
},
186187
);
187188

189+
@override
190+
Future<void> setExposureMode(int cameraId, ExposureMode mode) =>
191+
_channel.invokeMethod<void>(
192+
'setExposureMode',
193+
<String, dynamic>{
194+
'cameraId': cameraId,
195+
'mode': serializeExposureMode(mode),
196+
},
197+
);
198+
199+
@override
200+
Future<void> setExposurePoint(int cameraId, Point<double> point) {
201+
assert(point == null || point.x >= 0 && point.x <= 1);
202+
assert(point == null || point.y >= 0 && point.y <= 1);
203+
return _channel.invokeMethod<void>(
204+
'setExposurePoint',
205+
<String, dynamic>{
206+
'cameraId': cameraId,
207+
'reset': point == null,
208+
'x': point?.x,
209+
'y': point?.y,
210+
},
211+
);
212+
}
213+
214+
@override
215+
Future<double> getMinExposureOffset(int cameraId) =>
216+
_channel.invokeMethod<double>(
217+
'getMinExposureOffset',
218+
<String, dynamic>{'cameraId': cameraId},
219+
);
220+
221+
@override
222+
Future<double> getMaxExposureOffset(int cameraId) =>
223+
_channel.invokeMethod<double>(
224+
'getMaxExposureOffset',
225+
<String, dynamic>{'cameraId': cameraId},
226+
);
227+
228+
@override
229+
Future<double> getExposureOffsetStepSize(int cameraId) =>
230+
_channel.invokeMethod<double>(
231+
'getExposureOffsetStepSize',
232+
<String, dynamic>{'cameraId': cameraId},
233+
);
234+
235+
@override
236+
Future<double> setExposureOffset(int cameraId, double offset) =>
237+
_channel.invokeMethod<double>(
238+
'setExposureOffset',
239+
<String, dynamic>{
240+
'cameraId': cameraId,
241+
'offset': offset,
242+
},
243+
);
244+
188245
@override
189246
Future<double> getMaxZoomLevel(int cameraId) => _channel.invokeMethod<double>(
190247
'getMaxZoomLevel',
@@ -265,6 +322,8 @@ class MethodChannelCamera extends CameraPlatform {
265322
cameraId,
266323
call.arguments['previewWidth'],
267324
call.arguments['previewHeight'],
325+
deserializeExposureMode(call.arguments['exposureMode']),
326+
call.arguments['exposurePointSupported'],
268327
));
269328
break;
270329
case 'resolution_changed':

packages/camera/camera_platform_interface/lib/src/platform_interface/camera_platform.dart

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
// found in the LICENSE file.
44

55
import 'dart:async';
6+
import 'dart:math';
67

78
import 'package:camera_platform_interface/camera_platform_interface.dart';
89
import 'package:camera_platform_interface/src/method_channel/method_channel_camera.dart';
10+
import 'package:camera_platform_interface/src/types/exposure_mode.dart';
911
import 'package:cross_file/cross_file.dart';
1012
import 'package:flutter/widgets.dart';
1113
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
@@ -113,6 +115,48 @@ abstract class CameraPlatform extends PlatformInterface {
113115
throw UnimplementedError('setFlashMode() is not implemented.');
114116
}
115117

118+
/// Sets the exposure mode for taking pictures.
119+
Future<void> setExposureMode(int cameraId, ExposureMode mode) {
120+
throw UnimplementedError('setExposureMode() is not implemented.');
121+
}
122+
123+
/// Sets the exposure point for automatically determining the exposure value.
124+
Future<void> setExposurePoint(int cameraId, Point<double> point) {
125+
throw UnimplementedError('setExposurePoint() is not implemented.');
126+
}
127+
128+
/// Gets the minimum supported exposure offset for the selected camera in EV units.
129+
Future<double> getMinExposureOffset(int cameraId) {
130+
throw UnimplementedError('getMinExposureOffset() is not implemented.');
131+
}
132+
133+
/// Gets the maximum supported exposure offset for the selected camera in EV units.
134+
Future<double> getMaxExposureOffset(int cameraId) {
135+
throw UnimplementedError('getMaxExposureOffset() is not implemented.');
136+
}
137+
138+
/// Gets the supported step size for exposure offset for the selected camera in EV units.
139+
///
140+
/// Returns 0 when the camera supports using a free value without stepping.
141+
Future<double> getExposureOffsetStepSize(int cameraId) {
142+
throw UnimplementedError('getMinExposureOffset() is not implemented.');
143+
}
144+
145+
/// Sets the exposure offset for the selected camera.
146+
///
147+
/// The supplied [offset] value should be in EV units. 1 EV unit represents a
148+
/// doubling in brightness. It should be between the minimum and maximum offsets
149+
/// obtained through `getMinExposureOffset` and `getMaxExposureOffset` respectively.
150+
/// Throws a `CameraException` when an illegal offset is supplied.
151+
///
152+
/// When the supplied [offset] value does not align with the step size obtained
153+
/// through `getExposureStepSize`, it will automatically be rounded to the nearest step.
154+
///
155+
/// Returns the (rounded) offset value that was set.
156+
Future<double> setExposureOffset(int cameraId, double offset) {
157+
throw UnimplementedError('setExposureOffset() is not implemented.');
158+
}
159+
116160
/// Gets the maximum supported zoom level for the selected camera.
117161
Future<double> getMaxZoomLevel(int cameraId) {
118162
throw UnimplementedError('getMaxZoomLevel() is not implemented.');
@@ -126,7 +170,7 @@ abstract class CameraPlatform extends PlatformInterface {
126170
/// Set the zoom level for the selected camera.
127171
///
128172
/// The supplied [zoom] value should be between 1.0 and the maximum supported
129-
/// zoom level returned by the `getMaxZoomLevel`. Throws an `CameraException`
173+
/// zoom level returned by the `getMaxZoomLevel`. Throws a `CameraException`
130174
/// when an illegal zoom level is supplied.
131175
Future<void> setZoomLevel(int cameraId, double zoom) {
132176
throw UnimplementedError('setZoomLevel() is not implemented.');
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2019 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
/// The possible exposure modes that can be set for a camera.
6+
enum ExposureMode {
7+
/// Automatically determine exposure settings.
8+
auto,
9+
10+
/// Lock the currently determined exposure settings.
11+
locked,
12+
}
13+
14+
/// Returns the exposure mode as a String.
15+
String serializeExposureMode(ExposureMode exposureMode) {
16+
switch (exposureMode) {
17+
case ExposureMode.locked:
18+
return 'locked';
19+
case ExposureMode.auto:
20+
return 'auto';
21+
default:
22+
throw ArgumentError('Unknown ExposureMode value');
23+
}
24+
}
25+
26+
/// Returns the exposure mode for a given String.
27+
ExposureMode deserializeExposureMode(String str) {
28+
switch (str) {
29+
case "locked":
30+
return ExposureMode.locked;
31+
case "auto":
32+
return ExposureMode.auto;
33+
default:
34+
throw ArgumentError('"$str" is not a valid ExposureMode value');
35+
}
36+
}

packages/camera/camera_platform_interface/lib/src/types/types.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ export 'camera_description.dart';
66
export 'resolution_preset.dart';
77
export 'camera_exception.dart';
88
export 'flash_mode.dart';
9+
export 'exposure_mode.dart';

0 commit comments

Comments
 (0)