This repository has been archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[camera_platform_interface] Added imageFormatGroup to initialize (#3364)
* Added imageFormatGroup to initialize * Apply suggestions from code review Co-authored-by: Maurits van Beusekom <maurits@vnbskm.nl> * Added period to sentence * Moved ImageFormatGroup to platform_interface; Added extension to convert ImageFormatGroup to name; Changed int to ImageFormatGroup for initializeCamera * Fixed test * Separated Android and iOS in name extension * Clarified returns on name extension * Export image_format_group.dart in types.dart * Changed enum values to lowercase * Added ImageFormatGroup test * Fixed formatting * Removed target platform switch. * Fixed formatting Co-authored-by: Maurits van Beusekom <maurits@vnbskm.nl>
- Loading branch information
1 parent
cfa7098
commit 16f37e9
Showing
8 changed files
with
90 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
packages/camera/camera_platform_interface/lib/src/types/image_format_group.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/// Group of image formats that are comparable across Android and iOS platforms. | ||
enum ImageFormatGroup { | ||
/// The image format does not fit into any specific group. | ||
unknown, | ||
|
||
/// Multi-plane YUV 420 format. | ||
/// | ||
/// This format is a generic YCbCr format, capable of describing any 4:2:0 | ||
/// chroma-subsampled planar or semiplanar buffer (but not fully interleaved), | ||
/// with 8 bits per color sample. | ||
/// | ||
/// On Android, this is `android.graphics.ImageFormat.YUV_420_888`. See | ||
/// https://developer.android.com/reference/android/graphics/ImageFormat.html#YUV_420_888 | ||
/// | ||
/// On iOS, this is `kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange`. See | ||
/// https://developer.apple.com/documentation/corevideo/1563591-pixel_format_identifiers/kcvpixelformattype_420ypcbcr8biplanarvideorange?language=objc | ||
yuv420, | ||
|
||
/// 32-bit BGRA. | ||
/// | ||
/// On iOS, this is `kCVPixelFormatType_32BGRA`. See | ||
/// https://developer.apple.com/documentation/corevideo/1563591-pixel_format_identifiers/kcvpixelformattype_32bgra?language=objc | ||
bgra8888, | ||
|
||
/// 32-big RGB image encoded into JPEG bytes. | ||
/// | ||
/// On Android, this is `android.graphics.ImageFormat.JPEG`. See | ||
/// https://developer.android.com/reference/android/graphics/ImageFormat#JPEG | ||
jpeg, | ||
} | ||
|
||
/// Extension on [ImageFormatGroup] to stringify the enum | ||
extension ImageFormatGroupName on ImageFormatGroup { | ||
/// returns a String value for [ImageFormatGroup] | ||
/// returns 'unknown' if platform is not supported | ||
/// or if [ImageFormatGroup] is not supported for the platform | ||
String name() { | ||
switch (this) { | ||
case ImageFormatGroup.bgra8888: | ||
return 'bgra8888'; | ||
case ImageFormatGroup.yuv420: | ||
return 'yuv420'; | ||
case ImageFormatGroup.jpeg: | ||
return 'jpeg'; | ||
case ImageFormatGroup.unknown: | ||
default: | ||
return 'unknown'; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
packages/camera/camera_platform_interface/test/types/image_group_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import 'package:camera_platform_interface/src/types/types.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
group('$ImageFormatGroup tests', () { | ||
test('ImageFormatGroupName extension returns correct values', () { | ||
expect(ImageFormatGroup.bgra8888.name(), 'bgra8888'); | ||
expect(ImageFormatGroup.yuv420.name(), 'yuv420'); | ||
expect(ImageFormatGroup.jpeg.name(), 'jpeg'); | ||
expect(ImageFormatGroup.unknown.name(), 'unknown'); | ||
}); | ||
}); | ||
} |