/// <summary>
 /// Downsamples depth image using the row and column scaling steps
 /// </summary>
 /// <param name="depthCamState">Depth cam sensor state with original image buffer</param>
 /// <param name="targetDepthImage">Target buffer for downsampled image</param>
 /// <param name="columnStep">Column sampling interval</param>
 /// <param name="rowStep">Row sampling interval</param>
 public static void DownSampleDepthImage(
     DepthCamSensorState depthCamState,
     short[] targetDepthImage,
     int columnStep,
     int rowStep)
 {
     DownSampleDepthImageInternal(depthCamState, targetDepthImage, columnStep, rowStep);
 }
        /// <summary>
        /// Downsamples depth image using the row and column scaling steps
        /// </summary>
        /// <param name="depthCamState">Depth cam sensor state with original image buffer</param>
        /// <param name="targetDepthImage">Target buffer for downsampled image</param>
        /// <param name="columnStep">Column sampling interval</param>
        /// <param name="rowStep">Row sampling interval</param>
        private static unsafe void DownSampleDepthImageInternal(
            DepthCamSensorState depthCamState,
            short[] targetDepthImage,
            int columnStep,
            int rowStep)
        {
            int downSampledWidth = depthCamState.DepthImageSize.Width / columnStep;

            fixed(short *depthImagePointer = &depthCamState.DepthImage[0])
            {
                fixed(short *depthImageTargetPointer = &targetDepthImage[0])
                {
                    for (int y = 0; y < depthCamState.DepthImageSize.Height; y += rowStep)
                    {
                        for (int x = 0; x < depthCamState.DepthImageSize.Width; x += columnStep)
                        {
                            int targetOffset = ((y / rowStep) * downSampledWidth) + (x / columnStep);
                            int sourceOffset = (y * depthCamState.DepthImageSize.Width) + x;
                            depthImageTargetPointer[targetOffset] = depthImagePointer[sourceOffset];
                        }
                    }
                }
            }
        }