Ejemplo n.º 1
0
        public static void GetPlaneData(out byte[] pixels, XRCameraImage image)
        {
            XRCameraImagePlane plane = image.GetPlane(0);             // use the Y plane
            int width = image.width, height = image.height;

            pixels = new byte[width * height];

            if (width == plane.rowStride)
            {
                plane.data.CopyTo(pixels);
            }
            else
            {
                unsafe
                {
                    ulong handle;
                    byte *srcPtr = (byte *)NativeArrayUnsafeUtility.GetUnsafePtr(plane.data);
                    byte *dstPtr = (byte *)UnsafeUtility.PinGCArrayAndGetDataAddress(pixels, out handle);
                    if (width > 0 && height > 0)
                    {
                        UnsafeUtility.MemCpyStride(dstPtr, width, srcPtr, plane.rowStride, width, height);
                    }
                    UnsafeUtility.ReleaseGCObject(handle);
                }
            }
        }
        private static object[] extractYUVFromImage(XRCameraImage image)
        {
            // Consider each image plane
            XRCameraImagePlane plane = image.GetPlane(0);
            var yRowStride           = plane.rowStride;
            var y = plane.data;

            XRCameraImagePlane plane2 = image.GetPlane(1);
            var uvRowStride           = plane2.rowStride;
            var uvPixelStride         = plane2.pixelStride;
            var u = plane2.data;

            XRCameraImagePlane plane3 = image.GetPlane(2);
            var v = plane3.data;

            byte[] yDst = new byte[y.Length];
            byte[] uDst = new byte[u.Length];
            byte[] vDst = new byte[v.Length];

            object[] objParams = new object[8];
            NativeArray <byte> .Copy(y, yDst);

            NativeArray <byte> .Copy(u, uDst);

            NativeArray <byte> .Copy(v, vDst);

            objParams[0] = yDst;
            objParams[1] = uDst;
            objParams[2] = vDst;
            objParams[3] = yRowStride;
            objParams[4] = uvRowStride;
            objParams[5] = uvPixelStride;
            objParams[6] = image.width;
            objParams[7] = image.height;

            return(objParams);
        }
Ejemplo n.º 3
0
 public static void GetPlaneDataFast(ref IntPtr pixels, XRCameraImage image)
 {
     XRCameraImagePlane plane = image.GetPlane(0);               // use the Y plane
Ejemplo n.º 4
0
 public static void GetPlaneData(out byte[] pixels, XRCameraImage image)
 {
     XRCameraImagePlane plane = image.GetPlane(0);               // use the Y plane