Microsoft.Samples.Kinect.RecordAndPlaybackBasics.KinectDepthView.ProcessDepthFrameData C# (CSharp) Method

ProcessDepthFrameData() private method

Directly accesses the underlying image buffer of the DepthFrame to create a displayable bitmap. This function requires the /unsafe compiler option as we make use of direct access to the native memory pointed to by the depthFrameData pointer.
private ProcessDepthFrameData ( IntPtr depthFrameData, uint depthFrameDataSize, ushort minDepth, ushort maxDepth ) : void
depthFrameData System.IntPtr Pointer to the DepthFrame image data
depthFrameDataSize uint Size of the DepthFrame image data
minDepth ushort The minimum reliable depth value for the frame
maxDepth ushort The maximum reliable depth value for the frame
return void
        private unsafe void ProcessDepthFrameData(IntPtr depthFrameData, uint depthFrameDataSize, ushort minDepth, ushort maxDepth)
        {
            // depth frame data is a 16 bit value
            ushort* frameData = (ushort*)depthFrameData;

            // convert depth to a visual representation
            for (int i = 0; i < (int)(depthFrameDataSize / this.depthFrameDescription.BytesPerPixel); ++i)
            {
                // Get the depth for this pixel
                ushort depth = frameData[i];

                // To convert to a byte, we're mapping the depth value to the byte range.
                // Values outside the reliable depth range are mapped to 0 (black).
                this.depthPixels[i] = (byte)(depth >= minDepth && depth <= maxDepth ? (depth / MapDepthToByte) : 0);
            }
        }