示例#1
0
        /// <summary>
        /// Get an image "plane". A "plane" in this context refers to a channel in the raw video format, not a physical
        /// surface.
        /// </summary>
        /// <param name="planeIndex">The index of the plane to get.</param>
        /// <returns>A <see cref="XRCameraImagePlane"/> describing the plane.</returns>
        /// <exception cref="System.ArgumentOutOfRangeException">Thrown if <paramref name="planeIndex"/> is not within
        /// the range [0, <see cref="planeCount"/>).</exception>
        /// <exception cref="System.InvalidOperationException">Thrown if the requested plane is not valid.</exception>
        public unsafe XRCameraImagePlane GetPlane(int planeIndex)
        {
            ValidateNativeHandleAndThrow();
            if (planeIndex < 0 || planeIndex >= planeCount)
            {
                throw new ArgumentOutOfRangeException("planeIndex",
                                                      string.Format("planeIndex must be in the range 0 to {0}", planeCount - 1));
            }

            XRCameraSubsystem.CameraImagePlaneCinfo imagePlaneCinfo;
            if (!m_CameraSubsystem.TryGetPlane(m_NativeHandle, planeIndex, out imagePlaneCinfo))
            {
                throw new InvalidOperationException("The requested plane is not valid for this XRCameraImage.");
            }

            var data = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <byte>(
                (void *)imagePlaneCinfo.dataPtr, imagePlaneCinfo.dataLength, Allocator.None);

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            NativeArrayUnsafeUtility.SetAtomicSafetyHandle(ref data, m_SafetyHandle);
#endif

            return(new XRCameraImagePlane
            {
                rowStride = imagePlaneCinfo.rowStride,
                pixelStride = imagePlaneCinfo.pixelStride,
                data = data
            });
        }