コード例 #1
0
        /*public void UpdateTexture(int textureName)
         * {
         *      GL.BindTexture(TextureTarget.Texture2D, textureName);
         *      PixelBufferImpl.CVPixelBufferLockBaseAddress(_handle, CVPixelBufferLockFlags.kCVPixelBufferLock_ReadOnly);
         *      GL.TexImage2D(
         *              TextureTarget.Texture2D,
         *              0,
         *              PixelInternalFormat.Rgba,
         *              Width,
         *              Height,
         *              0,
         *              PixelFormat.Bgra,
         *              PixelType.UnsignedByte,
         *              PixelBufferImpl.CVPixelBufferGetBaseAddress(_handle));
         *      PixelBufferImpl.CVPixelBufferUnlockBaseAddress(_handle, CVPixelBufferLockFlags.kCVPixelBufferLock_ReadOnly);
         * }*/

        public void UpdateTexture(int textureName, VideoHandle handle)
        {
            var width             = Width;
            var height            = Height;
            var bytesPerRow       = BytesPerRow;
            var actualBytesPerRow = width * 4;

            PixelBufferImpl.CVPixelBufferLockBaseAddress(_handle, CVPixelBufferLockFlags.kCVPixelBufferLock_ReadOnly);

            var baseAddress   = PixelBufferImpl.CVPixelBufferGetBaseAddress(_handle);
            var sourceAddress = baseAddress;
            var sourceOffset  = 0;
            var destOffset    = 0;

            for (int y = 0; y < height; y++)
            {
                sourceOffset  = y * bytesPerRow;
                destOffset    = y * actualBytesPerRow;
                sourceAddress = new IntPtr(baseAddress.ToInt64() + (Int64)sourceOffset);
                Marshal.Copy(sourceAddress, handle.Pixels, destOffset, actualBytesPerRow);
            }

            PixelBufferImpl.CVPixelBufferUnlockBaseAddress(_handle, CVPixelBufferLockFlags.kCVPixelBufferLock_ReadOnly);

            var pinnedArray = GCHandle.Alloc(handle.Pixels, GCHandleType.Pinned);

            GL.BindTexture(TextureTarget.Texture2D, textureName);
            if (width != handle.WidthCache || height != handle.HeightCache)
            {
                handle.WidthCache  = width;
                handle.HeightCache = height;
                GL.TexImage2D(
                    TextureTarget.Texture2D,
                    0,
                    PixelInternalFormat.Rgba,
                    width,
                    height,
                    0,
                    PixelFormat.Bgra,
                    PixelType.UnsignedByte,
                    pinnedArray.AddrOfPinnedObject());
            }
            else
            {
                GL.TexSubImage2D(
                    TextureTarget.Texture2D,
                    0,
                    0,
                    0,
                    width,
                    height,
                    PixelFormat.Bgra,
                    PixelType.UnsignedByte,
                    pinnedArray.AddrOfPinnedObject());
            }

            pinnedArray.Free();
        }
コード例 #2
0
        public void CopyPixels(byte[] pixels)
        {
            var size = PixelBufferImpl.CVPixelBufferGetBytesPerRow(_handle).ToInt32() * Height;

            if (size == 0)
            {
                return;
            }

            if (pixels.Length != size)
            {
                throw new ArgumentOutOfRangeException("pixel buffer invalide size");
            }

            PixelBufferImpl.CVPixelBufferLockBaseAddress(_handle, CVPixelBufferLockFlags.kCVPixelBufferLock_ReadOnly);

            Marshal.Copy(
                PixelBufferImpl.CVPixelBufferGetBaseAddress(_handle),
                pixels,
                0,
                size);

            PixelBufferImpl.CVPixelBufferUnlockBaseAddress(_handle, CVPixelBufferLockFlags.kCVPixelBufferLock_ReadOnly);
        }
コード例 #3
0
 public void Dispose()
 {
     PixelBufferImpl.CVBufferRelease(_handle);
 }