using System; using Unity.Collections; namespace UnityEngine.XR.ARSubsystems { public partial struct XRCpuImage { /// /// Information about the camera image planes. An image plane refers to an image channel used in video encoding. /// public struct Plane : IEquatable { /// /// Container for the metadata that describes access to the raw camera image plane data. /// public struct Cinfo : IEquatable { /// /// The pointer to the raw native image data. /// /// /// The pointer to the raw native image data. /// public IntPtr dataPtr => m_DataPtr; IntPtr m_DataPtr; /// /// The length of the native image data. /// /// /// The length of the native image data. /// public int dataLength => m_DataLength; int m_DataLength; /// /// The stride for iterating through the rows of the native image data. /// /// /// The stride for iterating through the rows of the native image data. /// public int rowStride => m_RowStride; int m_RowStride; /// /// The stride for iterating through the pixels of the native image data. /// /// /// The stride for iterating through the pixels of the native image data. /// public int pixelStride => m_PixelStride; int m_PixelStride; /// /// Constructs the camera image plane cinfo. /// /// The pointer to the raw native image data. /// The length of the native image data. /// The stride for iterating through the rows of the native image data. /// The stride for iterating through the pixels of the native image data. public Cinfo(IntPtr dataPtr, int dataLength, int rowStride, int pixelStride) { this.m_DataPtr = dataPtr; this.m_DataLength = dataLength; this.m_RowStride = rowStride; this.m_PixelStride = pixelStride; } /// /// Tests for equality. /// /// The other to compare against. /// `True` if every field in is equal to this , otherwise false. public bool Equals(Cinfo other) { return (dataPtr.Equals(other.dataPtr) && dataLength.Equals(other.dataLength) && rowStride.Equals(other.rowStride) && pixelStride.Equals(other.pixelStride)); } /// /// Tests for equality. /// /// The `object` to compare against. /// `True` if is of type and /// also returns `true`; otherwise `false`. public override bool Equals(System.Object obj) => obj is Cinfo other && Equals(other); /// /// Tests for equality. Same as . /// /// The left-hand side of the comparison. /// The right-hand side of the comparison. /// `True` if is equal to , otherwise `false`. public static bool operator ==(Cinfo lhs, Cinfo rhs) => lhs.Equals(rhs); /// /// Tests for inequality. Same as `!`. /// /// The left-hand side of the comparison. /// The right-hand side of the comparison. /// `True` if is not equal to , otherwise `false`. public static bool operator !=(Cinfo lhs, Cinfo rhs) => !(lhs == rhs); /// /// Generates a hash suitable for use with containers like `HashSet` and `Dictionary`. /// /// A hash code generated from this object's fields. public override int GetHashCode() => HashCodeUtil.Combine( dataPtr.GetHashCode(), dataLength.GetHashCode(), rowStride.GetHashCode(), pixelStride.GetHashCode()); /// /// Generates a string suitable for debugging. /// /// A string representation of this . public override string ToString() => $"dataPtr: 0x{dataPtr.ToInt64():x} length:{dataLength} rowStride:{rowStride} pixelStride:{pixelStride}"; } /// /// The number of bytes per row for this plane. /// /// /// The number of bytes per row for this plane. /// public int rowStride { get; internal set; } /// /// The number of bytes per pixel for this plane. /// /// /// The number of bytes per pixel for this plane. /// public int pixelStride { get; internal set; } /// /// A view into the platform-specific plane data. It is an error to access data after the owning /// has been disposed. /// /// /// The platform-specific plane data. /// public NativeArray data { get; internal set; } /// /// Constructs an . /// /// The number of bytes per row for this plane. /// The number of bytes per pixel for this plane. /// The platform-specific plane data. public Plane(int rowStride, int pixelStride, NativeArray data) { this.rowStride = rowStride; this.pixelStride = pixelStride; this.data = data; } /// /// Generates a hash suitable for use with containers like `HashSet` and `Dictionary`. /// /// A hash code generated from this object's fields. public override int GetHashCode() => HashCodeUtil.Combine( data.GetHashCode(), rowStride.GetHashCode(), pixelStride.GetHashCode()); /// /// Tests for equality. /// /// The `object` to compare against. /// `True` if is of type and /// also returns `true`; otherwise `false`. public override bool Equals(object obj) => obj is Plane other && Equals(other); /// /// Tests for equality. /// /// The other to compare against. /// `True` if every field in is equal to this , otherwise false. public bool Equals(Plane other) => (data.Equals(other.data)) && (rowStride == other.rowStride) && (pixelStride == other.pixelStride); /// /// Tests for equality. Same as . /// /// The to compare with . /// The to compare with . /// `True` if is equal to , otherwise `false`. public static bool operator ==(Plane lhs, Plane rhs) => lhs.Equals(rhs); /// /// Tests for inequality. Same as `!`. /// /// The to compare with . /// The to compare with . /// `True` if is not equal to , otherwise `false`. public static bool operator !=(Plane lhs, Plane rhs) => !lhs.Equals(rhs); /// /// Generates a string representation of this . /// /// A string representation of this . public override string ToString() => $"({data.Length} bytes, Row Stride: {rowStride}, Pixel Stride: {pixelStride})"; } } }