Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
c3f703e
Start of Android side of byte stream passing
bparrishMines Oct 24, 2018
f310580
dart side of byte streaming
bparrishMines Oct 25, 2018
87fdb60
Fix android streaming
bparrishMines Oct 25, 2018
673b003
Merge branch 'master' of github.com:flutter/plugins into camera_android
bparrishMines Nov 14, 2018
8d353ad
Add ios byte streaming
bparrishMines Nov 15, 2018
0291a29
Convert buffer to uiimage to pass over
bparrishMines Nov 16, 2018
31f746a
formatting
bparrishMines Nov 18, 2018
5fcfeb2
Stream yuv bytes instead
bparrishMines Nov 28, 2018
040d1ae
Make video format a constant
bparrishMines Nov 29, 2018
16d1d32
Pass back metadata for ios image
bparrishMines Nov 29, 2018
8e88978
Pass back metadata for android image
bparrishMines Nov 29, 2018
67f8304
Dart code now parses camera image buffer
bparrishMines Nov 30, 2018
646283a
YUV image to bgra
bparrishMines Nov 30, 2018
7e99691
Add documentation
bparrishMines Dec 6, 2018
4cbfab9
Only pass available data on Android
bparrishMines Dec 6, 2018
aa0e263
Merge branch 'master' of github.com:bparrishMines/plugins into camera…
bparrishMines Dec 6, 2018
9b2ae22
Merge branch 'master' of github.com:flutter/plugins into camera_andro…
bparrishMines Dec 6, 2018
297fe7a
Bump version
bparrishMines Dec 6, 2018
bdd9007
Formatting
bparrishMines Dec 6, 2018
ccc057b
create imageformat error
bparrishMines Dec 7, 2018
989edf6
Don't return from null
bparrishMines Dec 7, 2018
22ce601
Merge branch 'master' of github.com:bparrishMines/plugins into camera…
bparrishMines Dec 10, 2018
b1d7b89
Init buffers in constructor
bparrishMines Dec 10, 2018
aa3db0c
Add yuv ios format
bparrishMines Dec 11, 2018
0349ae2
Used presets with defined resolution. Sometimes resolution would come…
bparrishMines Dec 11, 2018
2633c49
Formatting
bparrishMines Dec 13, 2018
6377c64
Move CameraImage classes to separate file
bparrishMines Dec 13, 2018
6660a68
Move camera.dart to src folder
bparrishMines Dec 13, 2018
a4d278e
Create camera library
bparrishMines Dec 13, 2018
045dd53
Better name and comments
bparrishMines Dec 19, 2018
01520fe
Change from library camera file
bparrishMines Dec 19, 2018
6155620
bytestream -> imagestream
bparrishMines Dec 19, 2018
5898b4c
Comments and names
bparrishMines Dec 20, 2018
7617bb9
Formatting
bparrishMines Dec 20, 2018
f18db98
Added resolution and fps todo
bparrishMines Dec 20, 2018
0bf466a
Unmodify file
bparrishMines Dec 20, 2018
a53222b
Empty commit to rerun tests
bparrishMines Dec 20, 2018
fe965d1
Remove TODO from documentation
bparrishMines Dec 20, 2018
7c0228f
Merge branch 'master' of github.com:flutter/plugins into camera_andro…
bparrishMines Jan 3, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move CameraImage classes to separate file
  • Loading branch information
bparrishMines committed Dec 13, 2018
commit 6377c641a59cc7b9fccabd1fad57fceb0a408ac6
119 changes: 0 additions & 119 deletions packages/camera/lib/camera.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,125 +13,6 @@ enum ResolutionPreset { low, medium, high }

typedef void OnLatestImageAvailable(CameraImage image);

/// A single color plane of image data.
///
/// The number and meaning of the planes in an image are determined by the
/// format of the Image.
class Plane {
Plane._fromPlatformData(dynamic data)
: bytes = data['bytes'],
bytesPerPixel = data['bytesPerPixel'],
bytesPerRow = data['bytesPerRow'],
height = data['height'],
width = data['width'];

/// Bytes representing this plane.
final Uint8List bytes;

/// The distance between adjacent pixel samples on Android, in bytes.
///
/// Will be `null` on iOS.
final int bytesPerPixel;

/// The row stride for this color plane, in bytes.
final int bytesPerRow;

/// Height of the pixel buffer on iOS.
///
/// Will be `null` on Android
final int height;

/// Width of the pixel buffer on iOS.
///
/// Will be `null` on Android.
final int width;
}

/// 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,
}

/// Describes how pixels are represented in an image.
class ImageFormat {
ImageFormat._fromPlatformData(this.raw) : group = _asImageFormatGroup(raw);

/// Describes the format group the raw image format falls into.
final ImageFormatGroup group;

/// Raw version of the format from the Android or iOS platform.
///
/// On Android, this is an `int` from class `android.graphics.ImageFormat`. See
/// https://developer.android.com/reference/android/graphics/ImageFormat
///
/// On iOS, this is a `FourCharCode` constant from Pixel Format Identifiers.
/// See https://developer.apple.com/documentation/corevideo/1563591-pixel_format_identifiers?language=objc
final dynamic raw;
}

ImageFormatGroup _asImageFormatGroup(dynamic rawFormat) {
if (rawFormat == 35 || rawFormat == 875704438) {
return ImageFormatGroup.yuv420;
} else {
return ImageFormatGroup.unknown;
}
}

/// A single complete image buffer from the platform camera.
///
/// This class allows for direct application access to the pixel data of an
/// Image through one or more [Uint8List]. Each buffer is encapsulated in a
/// [Plane] that describes the layout of the pixel data in that plane. The
/// [CameraImage] is not directly usable as a UI resource.
///
/// Although not all image formats are planar on iOS, we treat 1-dimensional
/// images as single planar images.
class CameraImage {
CameraImage._fromPlatformData(dynamic data)
: format = ImageFormat._fromPlatformData(data['format']),
height = data['height'],
width = data['width'],
planes = List<Plane>.unmodifiable(data['planes']
.map((dynamic planeData) => Plane._fromPlatformData(planeData)));

/// Format of the image provided.
///
/// Determines the number of planes needed to represent the image, and
/// the general layout of the pixel data in each [Uint8List].
final ImageFormat format;

/// Height of the image in pixels.
///
/// For formats where some color channels are subsampled, this is the height
/// of the largest-resolution plane.
final int height;

/// Width of the image in pixels.
///
/// For formats where some color channels are subsampled, this is the width
/// of the largest-resolution plane.
final int width;

/// The pixels planes for this image.
///
/// The number of planes is determined by the format of the image.
final List<Plane> planes;
}

/// Returns the resolution preset as a String.
String serializeResolutionPreset(ResolutionPreset resolutionPreset) {
switch (resolutionPreset) {
Expand Down
122 changes: 122 additions & 0 deletions packages/camera/lib/src/camera_image.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/// A single color plane of image data.
///
/// The number and meaning of the planes in an image are determined by the
/// format of the Image.
class Plane {
Plane._fromPlatformData(dynamic data)
: bytes = data['bytes'],
bytesPerPixel = data['bytesPerPixel'],
bytesPerRow = data['bytesPerRow'],
height = data['height'],
width = data['width'];

/// Bytes representing this plane.
final Uint8List bytes;

/// The distance between adjacent pixel samples on Android, in bytes.
///
/// Will be `null` on iOS.
final int bytesPerPixel;

/// The row stride for this color plane, in bytes.
final int bytesPerRow;

/// Height of the pixel buffer on iOS.
///
/// Will be `null` on Android
final int height;

/// Width of the pixel buffer on iOS.
///
/// Will be `null` on Android.
final int width;
}

/// 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,
}

/// Describes how pixels are represented in an image.
class ImageFormat {
ImageFormat._fromPlatformData(this.raw) : group = _asImageFormatGroup(raw);

/// Describes the format group the raw image format falls into.
final ImageFormatGroup group;

/// Raw version of the format from the Android or iOS platform.
///
/// On Android, this is an `int` from class `android.graphics.ImageFormat`. See
/// https://developer.android.com/reference/android/graphics/ImageFormat
///
/// On iOS, this is a `FourCharCode` constant from Pixel Format Identifiers.
/// See https://developer.apple.com/documentation/corevideo/1563591-pixel_format_identifiers?language=objc
final dynamic raw;
}

ImageFormatGroup _asImageFormatGroup(dynamic rawFormat) {
if (rawFormat == 35 || rawFormat == 875704438) {
return ImageFormatGroup.yuv420;
} else {
return ImageFormatGroup.unknown;
}
}

/// A single complete image buffer from the platform camera.
///
/// This class allows for direct application access to the pixel data of an
/// Image through one or more [Uint8List]. Each buffer is encapsulated in a
/// [Plane] that describes the layout of the pixel data in that plane. The
/// [CameraImage] is not directly usable as a UI resource.
///
/// Although not all image formats are planar on iOS, we treat 1-dimensional
/// images as single planar images.
class CameraImage {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps add a helper to make it easy to turn this into a https://docs.flutter.io/flutter/painting/ImageProvider-class.html

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current implementation doesn't include a compatible image format with 'ImageProvider'. This impl uses yuv420.

I also include in CameraImage comments that The [CameraImage] is not directly usable as a UI resource.

CameraImage._fromPlatformData(dynamic data)
: format = ImageFormat._fromPlatformData(data['format']),
height = data['height'],
width = data['width'],
planes = List<Plane>.unmodifiable(data['planes']
.map((dynamic planeData) => Plane._fromPlatformData(planeData)));

/// Format of the image provided.
///
/// Determines the number of planes needed to represent the image, and
/// the general layout of the pixel data in each [Uint8List].
final ImageFormat format;

/// Height of the image in pixels.
///
/// For formats where some color channels are subsampled, this is the height
/// of the largest-resolution plane.
final int height;

/// Width of the image in pixels.
///
/// For formats where some color channels are subsampled, this is the width
/// of the largest-resolution plane.
final int width;

/// The pixels planes for this image.
///
/// The number of planes is determined by the format of the image.
final List<Plane> planes;
}