Plane.cs
10.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
using System;
using Unity.Collections;
namespace UnityEngine.XR.ARSubsystems
{
public partial struct XRCpuImage
{
/// <summary>
/// Information about the camera image planes. An image "plane" refers to an image channel used in video encoding.
/// </summary>
public struct Plane : IEquatable<Plane>
{
/// <summary>
/// Container for the metadata describing access to the raw camera image plane data.
/// </summary>
public struct Cinfo : IEquatable<Cinfo>
{
/// <summary>
/// The pointer to the raw native image data.
/// </summary>
/// <value>
/// The pointer to the raw native image data.
/// </value>
public IntPtr dataPtr => m_DataPtr;
IntPtr m_DataPtr;
/// <summary>
/// The length of the native image data.
/// </summary>
/// <value>
/// The length of the native image data.
/// </value>
public int dataLength => m_DataLength;
int m_DataLength;
/// <summary>
/// The stride for iterating through the rows of the native image data.
/// </summary>
/// <value>
/// The stride for iterating through the rows of the native image data.
/// </value>
public int rowStride => m_RowStride;
int m_RowStride;
/// <summary>
/// The stride for iterating through the pixels of the native image data.
/// </summary>
/// <value>
/// The stride for iterating through the pixels of the native image data.
/// </value>
public int pixelStride => m_PixelStride;
int m_PixelStride;
/// <summary>
/// Constructs the camera image plane cinfo.
/// </summary>
/// <param name="dataPtr">The pointer to the raw native image data.</param>
/// <param name="dataLength">The length of the native image data.</param>
/// <param name="rowStride">The stride for iterating through the rows of the native image data.</param>
/// <param name="pixelStride">The stride for iterating through the pixels of the native image data.</param>
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;
}
/// <summary>
/// Tests for equality.
/// </summary>
/// <param name="other">The other <see cref="Cinfo"/> to compare against.</param>
/// <returns>`True` if every field in <paramref name="other"/> is equal to this <see cref="Cinfo"/>, otherwise false.</returns>
public bool Equals(Cinfo other)
{
return (dataPtr.Equals(other.dataPtr) && dataLength.Equals(other.dataLength)
&& rowStride.Equals(other.rowStride) && pixelStride.Equals(other.pixelStride));
}
/// <summary>
/// Tests for equality.
/// </summary>
/// <param name="obj">The `object` to compare against.</param>
/// <returns>`True` if <paramref name="obj"/> is of type <see cref="Cinfo"/> and
/// <see cref="Equals(Cinfo)"/> also returns `true`; otherwise `false`.</returns>
public override bool Equals(System.Object obj) => obj is Cinfo other && Equals(other);
/// <summary>
/// Tests for equality. Same as <see cref="Equals(Cinfo)"/>.
/// </summary>
/// <param name="lhs">The left-hand side of the comparison.</param>
/// <param name="rhs">The right-hand side of the comparison.</param>
/// <returns>`True` if <paramref name="lhs"/> is equal to <paramref name="rhs"/>, otherwise `false`.</returns>
public static bool operator ==(Cinfo lhs, Cinfo rhs) => lhs.Equals(rhs);
/// <summary>
/// Tests for inequality. Same as `!`<see cref="Equals(Cinfo)"/>.
/// </summary>
/// <param name="lhs">The left-hand side of the comparison.</param>
/// <param name="rhs">The right-hand side of the comparison.</param>
/// <returns>`True` if <paramref name="lhs"/> is not equal to <paramref name="rhs"/>, otherwise `false`.</returns>
public static bool operator !=(Cinfo lhs, Cinfo rhs) => !(lhs == rhs);
/// <summary>
/// Generates a hash suitable for use with containers like `HashSet` and `Dictionary`.
/// </summary>
/// <returns>A hash code generated from this object's fields.</returns>
public override int GetHashCode() => HashCode.Combine(
dataPtr.GetHashCode(),
dataLength.GetHashCode(),
rowStride.GetHashCode(),
pixelStride.GetHashCode());
/// <summary>
/// Generates a string suitable for debugging.
/// </summary>
/// <returns>A string representation of this <see cref="Cinfo"/>.</returns>
public override string ToString()
=> $"dataPtr: 0x{dataPtr.ToInt64():x} length:{dataLength} rowStride:{rowStride} pixelStride:{pixelStride}";
}
/// <summary>
/// The number of bytes per row for this plane.
/// </summary>
/// <value>
/// The number of bytes per row for this plane.
/// </value>
public int rowStride { get; internal set; }
/// <summary>
/// The number of bytes per pixel for this plane.
/// </summary>
/// <value>
/// The number of bytes per pixel for this plane.
/// </value>
public int pixelStride { get; internal set; }
/// <summary>
/// A "view" into the platform-specific plane data. It is an error to access <c>data</c> after the owning
/// <see cref="XRCpuImage"/> has been disposed.
/// </summary>
/// <value>
/// The platform-specific plane data.
/// </value>
public NativeArray<byte> data { get; internal set; }
/// <summary>
/// Constructs an <see cref="Plane"/>.
/// </summary>
/// <param name="rowStride">The number of bytes per row for this plane.</param>
/// <param name="pixelStride">The number of bytes per pixel for this plane.</param>
/// <param name="data">The platform-specific plane data.</param>
public Plane(int rowStride, int pixelStride, NativeArray<byte> data)
{
this.rowStride = rowStride;
this.pixelStride = pixelStride;
this.data = data;
}
/// <summary>
/// Generates a hash suitable for use with containers like `HashSet` and `Dictionary`.
/// </summary>
/// <returns>A hash code generated from this object's fields.</returns>
public override int GetHashCode() => HashCode.Combine(
data.GetHashCode(),
rowStride.GetHashCode(),
pixelStride.GetHashCode());
/// <summary>
/// Tests for equality.
/// </summary>
/// <param name="obj">The `object` to compare against.</param>
/// <returns>`True` if <paramref name="obj"/> is of type <see cref="Plane"/> and
/// <see cref="Equals(Plane)"/> also returns `true`; otherwise `false`.</returns>
public override bool Equals(object obj) => obj is Plane other && Equals(other);
/// <summary>
/// Tests for equality.
/// </summary>
/// <param name="other">The other <see cref="Plane"/> to compare against.</param>
/// <returns>`True` if every field in <paramref name="other"/> is equal to this <see cref="Plane"/>, otherwise false.</returns>
public bool Equals(Plane other) =>
(data.Equals(other.data)) &&
(rowStride == other.rowStride) &&
(pixelStride == other.pixelStride);
/// <summary>
/// Tests for equality. Same as <see cref="Equals(Plane)"/>.
/// </summary>
/// <param name="lhs">The <see cref="Plane"/> to compare with <paramref name="rhs"/>.</param>
/// <param name="rhs">The <see cref="Plane"/> to compare with <paramref name="lhs"/>.</param>
/// <returns>`True` if <paramref name="lhs"/> is equal to <paramref name="rhs"/>, otherwise `false`.</returns>
public static bool operator ==(Plane lhs, Plane rhs) => lhs.Equals(rhs);
/// <summary>
/// Tests for inequality. Same as `!`<see cref="Equals(Plane)"/>.
/// </summary>
/// <param name="lhs">The <see cref="Plane"/> to compare with <paramref name="rhs"/>.</param>
/// <param name="rhs">The <see cref="Plane"/> to compare with <paramref name="lhs"/>.</param>
/// <returns>`True` if <paramref name="lhs"/> is not equal to <paramref name="rhs"/>, otherwise `false`.</returns>
public static bool operator !=(Plane lhs, Plane rhs) => !lhs.Equals(rhs);
/// <summary>
/// Generates a string representation of this <see cref="Plane"/>.
/// </summary>
/// <returns>A string representation of this <see cref="Plane"/>.</returns>
public override string ToString() => $"({data.Length} bytes, Row Stride: {rowStride}, Pixel Stride: {pixelStride})";
}
}
}