Skip to content

Commit

Permalink
feat: Support more image formats on Android (#634)
Browse files Browse the repository at this point in the history
* Support more image formats on Android
* Use meta data
* Changelog + Version increase + Docs
  • Loading branch information
ueman authored May 30, 2024
1 parent 7d64419 commit e8338de
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
5 changes: 5 additions & 0 deletions packages/google_mlkit_commons/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.7.2

* Widened image format support for Android
* Improve documentation for image formats

## 0.7.1

* Update README.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static InputImage getInputImageFromData(Map<String, Object> imageData,
(int) (double) metaData.get("width"),
(int) (double) metaData.get("height"),
(int) metaData.get("rotation"),
InputImage.IMAGE_FORMAT_NV21);
(int) metaData.get("image_format"));
return inputImage;
} else {
result.error("InputImageConverterError", "Invalid Input Image", null);
Expand Down
19 changes: 18 additions & 1 deletion packages/google_mlkit_commons/lib/src/input_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,15 @@ class InputImageMetadata {

/// Format of the input image.
///
/// Not used on Android.
/// Android supports
/// - [InputImageFormat.nv21]
/// - [InputImageFormat.yuv_420_888]
/// - [InputImageFormat.yv12]
/// as described in [here](https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage.ImageFormat).
///
/// iOS supports
/// - [InputImageFormat.yuv420]
/// - [InputImageFormat.bgra8888]
final InputImageFormat format;

/// The row stride for color plane, in bytes.
Expand Down Expand Up @@ -122,10 +130,19 @@ extension InputImageRotationValue on InputImageRotation {

/// To indicate the format of image while creating input image from bytes
enum InputImageFormat {
/// Android only: https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage#IMAGE_FORMAT_NV21
nv21,

/// Android only: https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage#public-static-final-int-image_format_yv12
yv12,

/// Android only: https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage#public-static-final-int-image_format_yuv_420_888
yuv_420_888,

/// iOS only: https://developer.apple.com/documentation/corevideo/kCVPixelFormatType_420YpCbCr8BiPlanarFullRange
yuv420,

/// iOS only: https://developer.apple.com/documentation/corevideo/kcvpixelformattype_32bgra
bgra8888,
}

Expand Down
2 changes: 1 addition & 1 deletion packages/google_mlkit_commons/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: google_mlkit_commons
description: A Flutter plugin with commons files to implement google's standalone ml kit made for mobile platform.
version: 0.7.1
version: 0.7.2
homepage: https://github.com/flutter-ml/google_ml_kit_flutter

environment:
Expand Down

0 comments on commit e8338de

Please sign in to comment.