private BitmapSource GetColorBitmapSource(MultiFrame multiFrame)
        {
            BitmapSource bmpSrcColor;

            if (Context.ProcessColorResize)
            {
                if (Context.ProcessColorMapping)
                {
                    bmpSrcColor = Utils.ToBitmapSource(multiFrame.ColorResizedData, Context.ColorResizedWidth, Context.ColorResizedHeight * 2, PixelFormats.Bgr32);
                }
                else
                {
                    bmpSrcColor = Utils.ToBitmapSource(multiFrame.ColorResizedData, Context.ColorResizedWidth, Context.ColorResizedHeight, PixelFormats.Bgr32);
                }
            }
            else
            {
                if (Context.ProcessColorMapping)
                {
                    int    colorByteSize = Context.ColorWidth * Context.ColorHeight * 4;
                    byte[] colorBytes    = new byte[colorByteSize * 2];
                    Array.Copy(multiFrame.ColorData, colorBytes, colorByteSize);
                    Array.Copy(multiFrame.ColorMappedBytes, 0, colorBytes, colorByteSize, colorByteSize);
                    bmpSrcColor = Utils.ToBitmapSource(colorBytes, Context.ColorWidth, Context.ColorHeight * 2, PixelFormats.Bgr32);
                }
                else
                {
                    bmpSrcColor = Utils.ToBitmapSource(multiFrame.ColorData, Context.ColorWidth, Context.ColorHeight, PixelFormats.Bgr32);
                }
            }
            return(bmpSrcColor);
        }
 private BitmapSource GetDepthBitmapSource(MultiFrame multiFrame)
 {
     if (Context.ProcessDepthMapping)
     {
         return(Utils.ToBitmapSource(multiFrame.DepthBytes, Context.DepthWidth, Context.DepthHeight * 2, PixelFormats.Bgr32));
     }
     else
     {
         return(Utils.ToBitmapSource(multiFrame.DepthBytes, Context.DepthWidth, Context.DepthHeight, PixelFormats.Bgr32));
     }
 }
        // --- display bitmaps
        public void DisplayBitmaps(MultiFrame multiFrame)
        {
            if (bmpNbAbsolute++ % Context.DisplayEveryNthFrame != 0)
            {
                return;
            }

            BitmapSource bmpSrcColor  = null;
            BitmapSource bmpSrcDepth  = null;
            BitmapSource bmpSrcPS3Eye = null;

            // TODO: freeze?

            if (Context.DisplayColor)
            {
                long ticksColor = DateTime.Now.Ticks;
                bmpSrcColor = GetColorBitmapSource(multiFrame);
                if (bmpSrcColor != null)
                {
                    bmpSrcColor.Freeze();
                }
                Utils.UpdateTimer("DisplayColor", ticksColor);
            }

            if (Context.ProcessDepthData && Context.DisplayDepth)           // TODO: do not check processdepth?
            {
                long ticksDepth = DateTime.Now.Ticks;
                bmpSrcDepth = GetDepthBitmapSource(multiFrame);
                if (bmpSrcDepth != null)
                {
                    bmpSrcDepth.Freeze();
                }
                Utils.UpdateTimer("DisplayDepth", ticksDepth);
            }

            if (Context.DisplayPS3Eye)
            {
                long ticksDepth = DateTime.Now.Ticks;
                bmpSrcPS3Eye = Utils.ToBitmapSource(multiFrame.PS3EyeData, Context.PsWidth, Context.PsHeight * 2, PixelFormats.Bgr32);
                if (bmpSrcPS3Eye != null)
                {
                    bmpSrcPS3Eye.Freeze();
                }
                Utils.UpdateTimer("DisplayPS3Eye", ticksDepth);
            }

            Dispatcher.BeginInvoke(new Action(() =>
            {
                imgColor.Source  = bmpSrcColor;
                imgDepth.Source  = bmpSrcDepth;
                imgPS3Eye.Source = bmpSrcPS3Eye;
            }));
        }