private void UpdateCameraTexture(TrackedImage image)
        {
            IntPtr camDataPtr = image.GetDataPtr();

            switch (image.GetFormat())
            {
            case ColorFormat.RGBA8888:
                if (rgbaTexture != null)
                {
                    rgbaTexture.LoadRawTextureData(camDataPtr, image.GetWidth() * image.GetHeight() * 4);
                    rgbaTexture.Apply();
                }
                break;

            case ColorFormat.RGB888:
                if (rgbTexture != null)
                {
                    rgbTexture.LoadRawTextureData(camDataPtr, image.GetWidth() * image.GetHeight() * 3);
                    rgbTexture.Apply();
                }
                break;

            case ColorFormat.YUV420sp:
                if (uvTexture != null)                         // It means that RG16 texture format is supported
                {
                    IntPtr yPtr  = IntPtr.Zero;
                    IntPtr uvPtr = IntPtr.Zero;
                    image.GetYuv420spYUVPtr(out yPtr, out uvPtr);
                    yTexture.LoadRawTextureData(yPtr, image.GetWidth() * image.GetHeight());
                    yTexture.Apply();
                    uvTexture.LoadRawTextureData(uvPtr, image.GetWidth() * image.GetHeight() / 2);
                    uvTexture.Apply();
                }
                else if (yTexture != null && uTexture != null && vTexture != null)
                {
                    IntPtr yPtr = IntPtr.Zero;
                    IntPtr uPtr = IntPtr.Zero;
                    IntPtr vPtr = IntPtr.Zero;
                    image.GetYuv420spYUVPtr(out yPtr, out uPtr, out vPtr);
                    int uvSize = image.GetWidth() * image.GetHeight() / 2;
                    yTexture.LoadRawTextureData(camDataPtr, image.GetWidth() * image.GetHeight());
                    yTexture.Apply();

                    uTexture.LoadRawTextureData(uPtr, uvSize / 2);
                    uTexture.Apply();

                    vTexture.LoadRawTextureData(vPtr, uvSize / 2);
                    vTexture.Apply();
                }
                break;

            case ColorFormat.YUV420_888:
                if (u16bitTexture != null)                          // It means that RG16 texture format is supported
                {
                    IntPtr yPtr = IntPtr.Zero;
                    IntPtr uPtr = IntPtr.Zero;
                    IntPtr vPtr = IntPtr.Zero;
                    image.GetYuv420_888YUVPtr(out yPtr, out uPtr, out vPtr, true);
                    yTexture.LoadRawTextureData(yPtr, image.GetWidth() * image.GetHeight());
                    yTexture.Apply();

                    u16bitTexture.LoadRawTextureData(uPtr, image.GetWidth() * image.GetHeight() / 2);
                    u16bitTexture.Apply();

                    v16bitTexture.LoadRawTextureData(vPtr, image.GetWidth() * image.GetHeight() / 2);
                    v16bitTexture.Apply();
                }
                else if (yTexture != null && uTexture != null && vTexture != null)
                {
                    IntPtr yPtr = IntPtr.Zero;
                    IntPtr uPtr = IntPtr.Zero;
                    IntPtr vPtr = IntPtr.Zero;
                    image.GetYuv420_888YUVPtr(out yPtr, out uPtr, out vPtr, false);

                    int uSize = image.GetWidth() * image.GetHeight() / 2;

                    yTexture.LoadRawTextureData(yPtr, image.GetWidth() * image.GetHeight());
                    yTexture.Apply();

                    uTexture.LoadRawTextureData(uPtr, uSize / 2);
                    uTexture.Apply();

                    vTexture.LoadRawTextureData(vPtr, uSize / 2);
                    vTexture.Apply();
                }
                break;
            }
        }
예제 #2
0
        void UpdateInternal(TrackedImage image)
        {
            IntPtr cameraFramePtr = image.GetDataPtr();

            switch (image.GetFormat())
            {
            case ColorFormat.RGB888:
                if (rgbTexture != null)
                {
                    rgbTexture.LoadRawTextureData(cameraFramePtr, image.GetWidth() * image.GetHeight() * 3);
                    rgbTexture.Apply();
                }
                break;

            case ColorFormat.YUV420sp:
                if (uvTexture != null)                         // It means that RG16 texture format is supported
                {
                    IntPtr yPtr;
                    IntPtr uvPtr;
                    unsafe
                    {
                        byte *pointer = (byte *)cameraFramePtr.ToPointer();
                        yPtr     = (IntPtr)pointer;
                        pointer += image.GetWidth() * image.GetHeight();
                        uvPtr    = (IntPtr)pointer;
                    }

                    yTexture.LoadRawTextureData(yPtr, image.GetWidth() * image.GetHeight());
                    yTexture.Apply();
                    uvTexture.LoadRawTextureData(uvPtr, image.GetWidth() * image.GetHeight() / 2);
                    uvTexture.Apply();
                }
                else if (yTexture != null && uTexture != null && vTexture != null)
                {
                    IntPtr yPtr;
                    IntPtr uPtr;
                    IntPtr vPtr;

                    int uvSize = image.GetWidth() * image.GetHeight() / 2;

                    unsafe
                    {
                        byte *pointer = (byte *)cameraFramePtr.ToPointer();
                        yPtr     = (IntPtr)pointer;
                        pointer += image.GetWidth() * image.GetHeight();
                        uPtr     = (IntPtr)pointer;
                        pointer += uvSize / 2;
                        vPtr     = (IntPtr)pointer;
                    }

                    yTexture.LoadRawTextureData(yPtr, image.GetWidth() * image.GetHeight());
                    yTexture.Apply();

                    uTexture.LoadRawTextureData(uPtr, uvSize / 2);
                    uTexture.Apply();

                    vTexture.LoadRawTextureData(vPtr, uvSize / 2);
                    vTexture.Apply();
                }
                break;

            case ColorFormat.YUV420_888:
                if (u16bitTexture != null)                          // It means that RG16 texture format is supported
                {
                    IntPtr yPtr;
                    IntPtr uPtr;
                    IntPtr vPtr;
                    unsafe
                    {
                        byte *pointer = (byte *)cameraFramePtr.ToPointer();
                        yPtr     = (IntPtr)pointer;
                        pointer += image.GetWidth() * image.GetHeight();
                        uPtr     = (IntPtr)pointer;
                        pointer += image.GetWidth() * image.GetHeight() / 2;
                        vPtr     = (IntPtr)pointer;
                    }

                    yTexture.LoadRawTextureData(yPtr, image.GetWidth() * image.GetHeight());
                    yTexture.Apply();

                    u16bitTexture.LoadRawTextureData(uPtr, image.GetWidth() * image.GetHeight() / 2);
                    u16bitTexture.Apply();

                    v16bitTexture.LoadRawTextureData(vPtr, image.GetWidth() * image.GetHeight() / 2);
                    v16bitTexture.Apply();
                }
                else if (yTexture != null && uTexture != null && vTexture != null)
                {
                    IntPtr yPtr;
                    IntPtr uPtr;
                    IntPtr vPtr;

                    int uSize = image.GetWidth() * image.GetHeight() / 2;

                    unsafe
                    {
                        byte *pointer = (byte *)cameraFramePtr.ToPointer();
                        yPtr     = (IntPtr)pointer;
                        pointer += image.GetWidth() * image.GetHeight();
                        uPtr     = (IntPtr)pointer;
                        pointer += uSize;
                        vPtr     = (IntPtr)pointer;
                    }

                    yTexture.LoadRawTextureData(yPtr, image.GetWidth() * image.GetHeight());
                    yTexture.Apply();

                    uTexture.LoadRawTextureData(uPtr, uSize / 2);
                    uTexture.Apply();

                    vTexture.LoadRawTextureData(vPtr, uSize / 2);
                    vTexture.Apply();
                }
                break;
            }
        }