async void HandleFrameArrivedAsync(PerceptionInfraredFrameReader sender,
                                    PerceptionInfraredFrameArrivedEventArgs args)
 {
     // We move the whole thing to the dispatcher thread for now because we need to
     // get back to the writeable bitmap and that's got affinity. We could probably
     // do a lot better here.
     await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High,
                                    () => {
         this.HandleFrameArrivedDispatcherThread(args);
     }
                                    );
 }
        unsafe void HandleFrameArrivedDispatcherThread(PerceptionInfraredFrameArrivedEventArgs args)
        {
            using (var frame = args.TryOpenFrame())
            {
                if (frame != null)
                {
                    unsafe
                    {
                        using (var bufferSource = frame.VideoFrame.SoftwareBitmap.LockBuffer(BitmapBufferAccessMode.Read))
                            using (var sourceReference = bufferSource.CreateReference())
                            {
                                var  sourceByteAccess = sourceReference as IMemoryBufferByteAccess;
                                var  pSourceBits      = (byte *)null;
                                uint capacity         = 0;
                                sourceByteAccess.GetBuffer(out pSourceBits, out capacity);

                                var destByteAccess = bitmap_bg.PixelBuffer as IBufferByteAccess;
                                var pDestBits      = (byte *)null;
                                destByteAccess.Buffer(out pDestBits);

                                var bufferStart = pSourceBits;

                                for (int i = 0; i < (capacity); i++)
                                {
                                    byte val = (byte)(*pSourceBits);

                                    *pDestBits++ = val;
                                    *pDestBits++ = val;
                                    *pDestBits++ = val;
                                    *pDestBits++ = 0xFF;

                                    pSourceBits += 1;           // sizeof(Uint16)
                                }
                            }
                    }

                    bitmap_bg.Invalidate();

                    if (bitmap_bg == bitmap1)
                    {
                        bitmap_bg = bitmap2;
                        bitmap_fg = bitmap1;
                    }
                    else
                    {
                        bitmap_bg = bitmap1;
                        bitmap_fg = bitmap2;
                    }
                }
            }
        }
Example #3
0
        private void ProcessInfraredFrame(/*PerceptionInfraredFrameReader sender, */ PerceptionInfraredFrameArrivedEventArgs args)
        {
            using (var frame = args.TryOpenFrame())
            {
                if (frame != null)
                {
                    using (var videoFrame = frame.VideoFrame)
                    {
                        if (videoFrame != null)
                        {
                            var IsGetIllumination = videoFrame.ExtendedProperties.TryGetValue(KnownPerceptionInfraredFrameSourceProperties.ActiveIlluminationEnabled, out illuminationEnabled);

                            ProcessVideoFrame(videoFrame, Convert.ToBoolean(illuminationEnabled));
                        }
                    }
                }
            }
        }
        unsafe void HandleFrameArrivedDispatcherThread(PerceptionInfraredFrameArrivedEventArgs args)
        {
            using (var frame = args.TryOpenFrame()) {
                if (frame != null)
                {
                    unsafe
                    {
                        using (var bufferSource = frame.VideoFrame.SoftwareBitmap.LockBuffer(BitmapBufferAccessMode.Read))
                            using (var sourceReference = bufferSource.CreateReference()) {
                                var  sourceByteAccess = sourceReference as IMemoryBufferByteAccess;
                                var  pSourceBits      = (byte *)null;
                                uint capacity         = 0;
                                sourceByteAccess.GetBuffer(out pSourceBits, out capacity);

                                var destByteAccess = bitmap.PixelBuffer as IBufferByteAccess;
                                var pDestBits      = (byte *)null;
                                destByteAccess.Buffer(out pDestBits);

                                var bufferStart = pSourceBits;

                                for (int i = 0; i < (capacity / 2); i++)
                                {
                                    // scaling RGB value of 0...Uint16.Max into 0...byte.MaxValue which
                                    // probably isn't the best idea but it's a start.
                                    float pct = (float)(*(UInt16 *)pSourceBits / (float)UInt16.MaxValue);
                                    byte  val = (byte)(pct * byte.MaxValue);

                                    *pDestBits++ = val;
                                    *pDestBits++ = val;
                                    *pDestBits++ = val;
                                    *pDestBits++ = 0xFF;

                                    pSourceBits += 2; //sizeof(Uint16)
                                }
                            }
                    }
                    this.bitmap.Invalidate();
                }
            }
        }
Example #5
0
 private void InfraredReader_FrameArrived(PerceptionInfraredFrameReader sender, PerceptionInfraredFrameArrivedEventArgs args)
 {
     ProcessInfraredFrame(/*sender,*/ args);
 }