Struct XRCpuImage
Represents a single, raw image from a device camera. Provides access to the raw image plane data, as well as conversion methods to convert to color and grayscale formats. See Convert(ConversionParams, IntPtr, int) and ConvertAsync(ConversionParams). Use TryAcquireLatestCpuImage(out XRCpuImage) to get a XRCpuImage.
Inherited Members
Namespace: UnityEngine.XR.ARSubsystems
Assembly: Unity.XR.ARSubsystems.dll
Syntax
public struct XRCpuImage : IDisposable, IEquatable<XRCpuImage>
Remarks
Each XRCpuImage must be explicitly disposed. Failing to do so will leak resources and could prevent future camera image access.
Constructors
XRCpuImage(Api, Cinfo)
Construct the XRCpuImage
with the given native image information.
Declaration
public XRCpuImage(XRCpuImage.Api api, XRCpuImage.Cinfo cinfo)
Parameters
Type | Name | Description |
---|---|---|
XRCpuImage.Api | api | The camera subsystem to use for interacting with the native image. |
XRCpuImage.Cinfo | cinfo | Construction information. See XRCpuImage.Cinfo. |
Properties
dimensions
The dimensions (width and height) of the image.
Declaration
public readonly Vector2Int dimensions { get; }
Property Value
Type | Description |
---|---|
Vector2Int | The dimensions (width and height) of the image. |
format
The format used by the image planes. You will only need this if you plan to interpret the raw plane data.
Declaration
public readonly XRCpuImage.Format format { get; }
Property Value
Type | Description |
---|---|
XRCpuImage.Format | The format used by the image planes. |
height
The image height.
Declaration
public int height { get; }
Property Value
Type | Description |
---|---|
int | The image height. |
planeCount
The number of image planes. A plane in this context refers to a channel in the raw video format, not a physical surface.
Declaration
public readonly int planeCount { get; }
Property Value
Type | Description |
---|---|
int | The number of image planes. |
timestamp
The timestamp, in seconds, associated with this camera image
Declaration
public readonly double timestamp { get; }
Property Value
Type | Description |
---|---|
double | The timestamp, in seconds, associated with this camera image |
valid
Whether this XRCpuImage
represents a valid image (that is, it has not been Disposed).
Declaration
public bool valid { get; }
Property Value
Type | Description |
---|---|
bool |
|
width
The image width.
Declaration
public int width { get; }
Property Value
Type | Description |
---|---|
int | The image width. |
Methods
Convert(ConversionParams, IntPtr, int)
Convert the XRCpuImage
to one of the supported formats using the specified
conversionParams
.
Declaration
public void Convert(XRCpuImage.ConversionParams conversionParams, IntPtr destinationBuffer, int bufferLength)
Parameters
Type | Name | Description |
---|---|---|
XRCpuImage.ConversionParams | conversionParams | The parameters for the image conversion. |
IntPtr | destinationBuffer | A pointer to memory to which to write the converted image. |
int | bufferLength | The number of bytes pointed to by |
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown if the |
InvalidOperationException | Thrown if the conversion failed. |
See Also
Convert(ConversionParams, NativeSlice<byte>)
Convert the XRCpuImage
to one of the supported formats using the specified
conversionParams
.
Declaration
public void Convert(XRCpuImage.ConversionParams conversionParams, NativeSlice<byte> destinationBuffer)
Parameters
Type | Name | Description |
---|---|---|
XRCpuImage.ConversionParams | conversionParams | The parameters for the image conversion. |
NativeSlice<byte> | destinationBuffer | The destination buffer for the converted data. The buffer must be large enough to hold the converted data, that is, at least as large as the value returned by GetConvertedDataSize(ConversionParams). |
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown if the |
InvalidOperationException | Thrown if the conversion failed. |
See Also
ConvertAsync(ConversionParams)
Convert the XRCpuImage
to one of the supported formats using the specified
conversionParams
. The conversion is performed asynchronously. Use the returned
XRCpuImage.AsyncConversion to check for the status of the conversion, and retrieve the data
when complete.
Declaration
public XRCpuImage.AsyncConversion ConvertAsync(XRCpuImage.ConversionParams conversionParams)
Parameters
Type | Name | Description |
---|---|---|
XRCpuImage.ConversionParams | conversionParams | The parameters to use for the conversion. |
Returns
Type | Description |
---|---|
XRCpuImage.AsyncConversion | A XRCpuImage.AsyncConversion which can be used to check the status of the conversion operation and get the resulting data. |
Remarks
It is safe to Dispose
the XRCpuImage
before the asynchronous operation has completed.
See Also
ConvertAsync(ConversionParams, Action<AsyncConversionStatus, ConversionParams, NativeArray<byte>>)
Convert the XRCpuImage
to one of the supported formats using the specified
conversionParams
. The conversion is performed asynchronously, and
onComplete
is invoked when the conversion is complete, whether successful or not.
The NativeArray
provided in the onComplete
delegate is only valid during
the invocation and is disposed immediately upon return.
Declaration
public void ConvertAsync(XRCpuImage.ConversionParams conversionParams, Action<XRCpuImage.AsyncConversionStatus, XRCpuImage.ConversionParams, NativeArray<byte>> onComplete)
Parameters
Type | Name | Description |
---|---|---|
XRCpuImage.ConversionParams | conversionParams | The parameters to use for the conversion. |
Action<XRCpuImage.AsyncConversionStatus, XRCpuImage.ConversionParams, NativeArray<byte>> | onComplete | A delegate to invoke when the conversion operation completes. The delegate is always invoked, regardless of whether the conversion succeeded. |
See Also
Dispose()
Dispose native resources associated with this request, including the raw image data. Any
XRCpuImage.Planes returned by GetPlane(int) are invalidated immediately after
calling Dispose
.
Declaration
public void Dispose()
Equals(object)
Tests for equality.
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
object | obj | The |
Returns
Type | Description |
---|---|
bool |
|
Overrides
Equals(XRCpuImage)
Tests for equality.
Declaration
public bool Equals(XRCpuImage other)
Parameters
Type | Name | Description |
---|---|---|
XRCpuImage | other | The other XRCpuImage to compare against. |
Returns
Type | Description |
---|---|
bool |
|
FormatSupported(TextureFormat)
Determines whether the given TextureFormat is supported for conversion.
Declaration
public bool FormatSupported(TextureFormat format)
Parameters
Type | Name | Description |
---|---|---|
TextureFormat | format | A TextureFormat to test. |
Returns
Type | Description |
---|---|
bool | Returns |
GetConvertedDataSize(Vector2Int, TextureFormat)
Get the number of bytes required to store a converted image with the given parameters.
Declaration
public int GetConvertedDataSize(Vector2Int dimensions, TextureFormat format)
Parameters
Type | Name | Description |
---|---|---|
Vector2Int | dimensions | The desired dimensions of the converted image. |
TextureFormat | format | The desired |
Returns
Type | Description |
---|---|
int | The number of bytes required to store the converted image. |
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown if the desired |
ArgumentOutOfRangeException | Thrown if the desired |
InvalidOperationException | Thrown if the image is invalid. |
See Also
GetConvertedDataSize(ConversionParams)
Get the number of bytes required to store a converted image with the given parameters.
Declaration
public int GetConvertedDataSize(XRCpuImage.ConversionParams conversionParams)
Parameters
Type | Name | Description |
---|---|---|
XRCpuImage.ConversionParams | conversionParams | The desired conversion parameters. |
Returns
Type | Description |
---|---|
int | The number of bytes required to store the converted image. |
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown if the desired format is not supported. |
ArgumentOutOfRangeException | Thrown if the desired dimensions exceed the native image dimensions. |
InvalidOperationException | Thrown if the image is invalid. |
See Also
GetHashCode()
Generates a hash suitable for use with containers like HashSet
and Dictionary
.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
int | A hash code generated from this object's fields. |
Overrides
GetPlane(int)
Get an image plane. A plane in this context refers to a channel in the raw video format, not a physical surface.
Declaration
public XRCpuImage.Plane GetPlane(int planeIndex)
Parameters
Type | Name | Description |
---|---|---|
int | planeIndex | The index of the plane to get. |
Returns
Type | Description |
---|---|
XRCpuImage.Plane | A XRCpuImage.Plane describing the plane. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | Thrown if |
InvalidOperationException | Thrown if the requested plane is not valid. |
ToString()
Generates a string representation of this XRCpuImage.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
string | A string representation of this XRCpuImage. |
Overrides
Operators
operator ==(XRCpuImage, XRCpuImage)
Tests for equality. Same as Equals(XRCpuImage).
Declaration
public static bool operator ==(XRCpuImage lhs, XRCpuImage rhs)
Parameters
Type | Name | Description |
---|---|---|
XRCpuImage | lhs | The XRCpuImage to compare with |
XRCpuImage | rhs | The XRCpuImage to compare with |
Returns
Type | Description |
---|---|
bool |
|
operator !=(XRCpuImage, XRCpuImage)
Tests for inequality. Same as !
Equals(XRCpuImage).
Declaration
public static bool operator !=(XRCpuImage lhs, XRCpuImage rhs)
Parameters
Type | Name | Description |
---|---|---|
XRCpuImage | lhs | The XRCpuImage to compare with |
XRCpuImage | rhs | The XRCpuImage to compare with |
Returns
Type | Description |
---|---|
bool |
|