Skip to content
Open
1 change: 1 addition & 0 deletions packages/camera/camera_android/lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ PlatformMediaSettings mediaSettingsToPlatform(MediaSettings? settings) => Platfo
/// [ImageFormatGroup.unknown] and [ImageFormatGroup.bgra8888] default to
/// [PlatformImageFormatGroup.yuv420], which is the default on Android.
PlatformImageFormatGroup imageFormatGroupToPlatform(ImageFormatGroup format) {
// ignore: non_exhaustive_switch_statement
switch (format) {
case ImageFormatGroup.unknown:
return PlatformImageFormatGroup.yuv420;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ class AVFoundationCamera extends CameraPlatform {

/// Returns an [ImageFormatGroup]'s Pigeon representation.
PlatformImageFormatGroup _pigeonImageFormat(ImageFormatGroup format) {
// ignore: non_exhaustive_switch_statement
switch (format) {
// "unknown" is used to indicate the default.
case ImageFormatGroup.unknown:
Expand Down
4 changes: 4 additions & 0 deletions packages/camera/camera_platform_interface/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.14.0

* Adds `rgba8888` to `ImageFormatGroup` enum.

## 2.13.1

* Changes the default implementation of `setJpegImageQuality` to a no-op so that
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ ImageFormatGroup _imageFormatGroupFromPlatformData(dynamic data) {
return ImageFormatGroup.yuv420;
case 256: // android.graphics.ImageFormat.JPEG
return ImageFormatGroup.jpeg;
case 1: // android.graphics.PixelFormat.RGBA_8888
return ImageFormatGroup.rgba8888;
Comment thread
Mairramer marked this conversation as resolved.
}
}

Expand All @@ -46,6 +48,9 @@ ImageFormatGroup _imageFormatGroupFromPlatformData(dynamic data) {

case 1111970369: // kCVPixelFormatType_32BGRA
return ImageFormatGroup.bgra8888;

case 1380401729: // kCVPixelFormatType_32RGBA
return ImageFormatGroup.rgba8888;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ enum ImageFormatGroup {
/// On Android, this is `android.graphics.ImageFormat.NV21`. See
/// https://developer.android.com/reference/android/graphics/ImageFormat#NV21
nv21,

/// 32-bit RGBA.
///
/// On Android, this is `android.graphics.PixelFormat.RGBA_8888`. See
/// https://developer.android.com/reference/android/graphics/PixelFormat#RGBA_8888
///
/// On iOS, this is `kCVPixelFormatType_32RGBA`. See
/// https://developer.apple.com/documentation/corevideo/1563591-pixel_format_identifiers/kcvpixelformattype_32rgba?language=objc
rgba8888,
}

/// Extension on [ImageFormatGroup] to stringify the enum
Expand All @@ -54,6 +63,8 @@ extension ImageFormatGroupName on ImageFormatGroup {
return 'jpeg';
case ImageFormatGroup.nv21:
return 'nv21';
case ImageFormatGroup.rgba8888:
return 'rgba8888';
case ImageFormatGroup.unknown:
return 'unknown';
}
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.13.1
version: 2.14.0

environment:
sdk: ^3.10.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,54 @@ void main() {
});
expect(cameraImage.format.group, ImageFormatGroup.yuv420);
});

test('$CameraImageData has ImageFormatGroup.rgba8888 for Android', () {
debugDefaultTargetPlatformOverride = TargetPlatform.android;

final CameraImageData cameraImage = cameraImageFromPlatformData(
<dynamic, dynamic>{
'format': 1,
'height': 1,
'width': 4,
'lensAperture': 1.8,
'sensorExposureTime': 9991324,
'sensorSensitivity': 92.0,
'planes': <dynamic>[
<dynamic, dynamic>{
'bytes': Uint8List.fromList(<int>[1, 2, 3, 4]),
'bytesPerPixel': 1,
'bytesPerRow': 4,
'height': 1,
'width': 4,
},
],
},
);
expect(cameraImage.format.group, ImageFormatGroup.rgba8888);
});

test('$CameraImageData has ImageFormatGroup.rgba8888 for iOS', () {
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;

final CameraImageData cameraImage = cameraImageFromPlatformData(
<dynamic, dynamic>{
'format': 1380401729,
'height': 1,
'width': 4,
'lensAperture': 1.8,
'sensorExposureTime': 9991324,
'sensorSensitivity': 92.0,
'planes': <dynamic>[
<dynamic, dynamic>{
'bytes': Uint8List.fromList(<int>[1, 2, 3, 4]),
'bytesPerPixel': 1,
'bytesPerRow': 4,
'height': 1,
'width': 4,
},
],
},
);
expect(cameraImage.format.group, ImageFormatGroup.rgba8888);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ void main() {
expect(ImageFormatGroup.yuv420.name(), 'yuv420');
expect(ImageFormatGroup.jpeg.name(), 'jpeg');
expect(ImageFormatGroup.nv21.name(), 'nv21');
expect(ImageFormatGroup.rgba8888.name(), 'rgba8888');
expect(ImageFormatGroup.unknown.name(), 'unknown');
});
});
Expand Down