Skip to content

Commit

Permalink
[camera_platform_interface] Adds support for setting the image file f…
Browse files Browse the repository at this point in the history
…ormat (#5593)

Part of  #4586
  • Loading branch information
Mairramer committed Dec 14, 2023
1 parent 9186a1f commit 942f1bd
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/camera/camera_platform_interface/AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ Aleksandr Yurkovskiy <sanekyy@gmail.com>
Anton Borries <mail@antonborri.es>
Alex Li <google@alexv525.com>
Rahul Raj <64.rahulraj@gmail.com>
Mairramer <mairramer.dasilva28@hotmail.com>
3 changes: 2 additions & 1 deletion packages/camera/camera_platform_interface/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NEXT
## 2.7.0

* Adds support for setting the image file format. See `CameraPlatform.setImageFileFormat`.
* Updates minimum supported SDK version to Flutter 3.10/Dart 3.0.

## 2.6.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,17 @@ class MethodChannelCamera extends CameraPlatform {
);
}

@override
Future<void> setImageFileFormat(int cameraId, ImageFileFormat format) {
return _channel.invokeMethod<void>(
'setImageFileFormat',
<String, dynamic>{
'cameraId': cameraId,
'fileFormat': format.name,
},
);
}

@override
Widget buildPreview(int cameraId) {
return Texture(textureId: cameraId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,4 +298,12 @@ abstract class CameraPlatform extends PlatformInterface {
Future<void> dispose(int cameraId) {
throw UnimplementedError('dispose() is not implemented.');
}

/// Sets the output image file format for the selected camera.
///
// TODO(bmparr): This is only supported on iOS. See
// https://github.com/flutter/flutter/issues/139588
Future<void> setImageFileFormat(int cameraId, ImageFileFormat format) {
throw UnimplementedError('setImageFileFormat() is not implemented.');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/// The format in which images should be returned from the camera.
enum ImageFileFormat {
/// The JPEG format.
jpeg,

/// The HEIF format.
///
/// HEIF is a file format name that refers to High Efficiency Image Format
/// (HEIF). For iOS, this is only supported on versions 11+.
heif,
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export 'camera_image_data.dart';
export 'exposure_mode.dart';
export 'flash_mode.dart';
export 'focus_mode.dart';
export 'image_file_format.dart';
export 'image_format_group.dart';
export 'media_settings.dart';
export 'resolution_preset.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 @@ -4,7 +4,7 @@ repository: https://github.com/flutter/packages/tree/main/packages/camera/camera
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
# 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: 2.6.0
version: 2.7.0

environment:
sdk: ">=3.0.0 <4.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void main() {
'exposureMode': 'auto',
'exposurePointSupported': true,
'focusMode': 'auto',
'focusPointSupported': true
'focusPointSupported': true,
});

expect(event.cameraId, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,46 @@ void main() {
isMethodCall('stopImageStream', arguments: null),
]);
});

test('Should set the ImageFileFormat to heif', () async {
// Arrange
final MethodChannelMock channel = MethodChannelMock(
channelName: 'plugins.flutter.io/camera',
methods: <String, dynamic>{'setImageFileFormat': 'heif'},
);

// Act
await camera.setImageFileFormat(cameraId, ImageFileFormat.heif);

// Assert
expect(channel.log, <Matcher>[
isMethodCall('setImageFileFormat', arguments: <String, Object?>{
'cameraId': cameraId,
'fileFormat': 'heif',
}),
]);
});

test('Should set the ImageFileFormat to jpeg', () async {
// Arrange
final MethodChannelMock channel = MethodChannelMock(
channelName: 'plugins.flutter.io/camera',
methods: <String, dynamic>{
'setImageFileFormat': 'jpeg',
},
);

// Act
await camera.setImageFileFormat(cameraId, ImageFileFormat.jpeg);

// Assert
expect(channel.log, <Matcher>[
isMethodCall('setImageFileFormat', arguments: <String, Object?>{
'cameraId': cameraId,
'fileFormat': 'jpeg',
}),
]);
});
});
});
}

0 comments on commit 942f1bd

Please sign in to comment.