|
| 1 | +// Copyright 2013 The Flutter Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +import 'dart:typed_data'; |
| 6 | + |
| 7 | +import 'package:flutter/foundation.dart'; |
| 8 | + |
| 9 | +import '../../camera_platform_interface.dart'; |
| 10 | + |
| 11 | +/// Options for configuring camera streaming. |
| 12 | +/// |
| 13 | +/// Currently unused; this exists for future-proofing of the platform interface |
| 14 | +/// API. |
| 15 | +@immutable |
| 16 | +class CameraImageStreamOptions {} |
| 17 | + |
| 18 | +/// A single color plane of image data. |
| 19 | +/// |
| 20 | +/// The number and meaning of the planes in an image are determined by its |
| 21 | +/// format. |
| 22 | +@immutable |
| 23 | +class CameraImagePlane { |
| 24 | + /// Creates a new instance with the given bytes and optional metadata. |
| 25 | + const CameraImagePlane({ |
| 26 | + required this.bytes, |
| 27 | + required this.bytesPerRow, |
| 28 | + this.bytesPerPixel, |
| 29 | + this.height, |
| 30 | + this.width, |
| 31 | + }); |
| 32 | + |
| 33 | + /// Bytes representing this plane. |
| 34 | + final Uint8List bytes; |
| 35 | + |
| 36 | + /// The row stride for this color plane, in bytes. |
| 37 | + final int bytesPerRow; |
| 38 | + |
| 39 | + /// The distance between adjacent pixel samples in bytes, when available. |
| 40 | + final int? bytesPerPixel; |
| 41 | + |
| 42 | + /// Height of the pixel buffer, when available. |
| 43 | + final int? height; |
| 44 | + |
| 45 | + /// Width of the pixel buffer, when available. |
| 46 | + final int? width; |
| 47 | +} |
| 48 | + |
| 49 | +/// Describes how pixels are represented in an image. |
| 50 | +@immutable |
| 51 | +class CameraImageFormat { |
| 52 | + /// Create a new format with the given cross-platform group and raw underyling |
| 53 | + /// platform identifier. |
| 54 | + const CameraImageFormat(this.group, {required this.raw}); |
| 55 | + |
| 56 | + /// Describes the format group the raw image format falls into. |
| 57 | + final ImageFormatGroup group; |
| 58 | + |
| 59 | + /// Raw version of the format from the underlying platform. |
| 60 | + /// |
| 61 | + /// On Android, this should be an `int` from class |
| 62 | + /// `android.graphics.ImageFormat`. See |
| 63 | + /// https://developer.android.com/reference/android/graphics/ImageFormat |
| 64 | + /// |
| 65 | + /// On iOS, this should be a `FourCharCode` constant from Pixel Format |
| 66 | + /// Identifiers. See |
| 67 | + /// https://developer.apple.com/documentation/corevideo/1563591-pixel_format_identifiers |
| 68 | + final dynamic raw; |
| 69 | +} |
| 70 | + |
| 71 | +/// A single complete image buffer from the platform camera. |
| 72 | +/// |
| 73 | +/// This class allows for direct application access to the pixel data of an |
| 74 | +/// Image through one or more [Uint8List]. Each buffer is encapsulated in a |
| 75 | +/// [CameraImagePlane] that describes the layout of the pixel data in that |
| 76 | +/// plane. [CameraImageData] is not directly usable as a UI resource. |
| 77 | +/// |
| 78 | +/// Although not all image formats are planar on all platforms, this class |
| 79 | +/// treats 1-dimensional images as single planar images. |
| 80 | +@immutable |
| 81 | +class CameraImageData { |
| 82 | + /// Creates a new instance with the given format, planes, and metadata. |
| 83 | + const CameraImageData({ |
| 84 | + required this.format, |
| 85 | + required this.planes, |
| 86 | + required this.height, |
| 87 | + required this.width, |
| 88 | + this.lensAperture, |
| 89 | + this.sensorExposureTime, |
| 90 | + this.sensorSensitivity, |
| 91 | + }); |
| 92 | + |
| 93 | + /// Format of the image provided. |
| 94 | + /// |
| 95 | + /// Determines the number of planes needed to represent the image, and |
| 96 | + /// the general layout of the pixel data in each [Uint8List]. |
| 97 | + final CameraImageFormat format; |
| 98 | + |
| 99 | + /// Height of the image in pixels. |
| 100 | + /// |
| 101 | + /// For formats where some color channels are subsampled, this is the height |
| 102 | + /// of the largest-resolution plane. |
| 103 | + final int height; |
| 104 | + |
| 105 | + /// Width of the image in pixels. |
| 106 | + /// |
| 107 | + /// For formats where some color channels are subsampled, this is the width |
| 108 | + /// of the largest-resolution plane. |
| 109 | + final int width; |
| 110 | + |
| 111 | + /// The pixels planes for this image. |
| 112 | + /// |
| 113 | + /// The number of planes is determined by the format of the image. |
| 114 | + final List<CameraImagePlane> planes; |
| 115 | + |
| 116 | + /// The aperture settings for this image. |
| 117 | + /// |
| 118 | + /// Represented as an f-stop value. |
| 119 | + final double? lensAperture; |
| 120 | + |
| 121 | + /// The sensor exposure time for this image in nanoseconds. |
| 122 | + final int? sensorExposureTime; |
| 123 | + |
| 124 | + /// The sensor sensitivity in standard ISO arithmetic units. |
| 125 | + final double? sensorSensitivity; |
| 126 | +} |
0 commit comments