示例#1
0
        /// <summary>
        /// Writes the image to be drawn to the back buffer.
        /// </summary>
        /// <param name="message">The TickRenderedMessage received, which contains the frame to be drawn</param>
        public override void Handle(TickRenderedMessage message)
        {
            base.Handle(message);
            var frame = message[OutputModel];

            if (frame == null)
            {
                return;
            }

            int width  = frame.Size.Width;
            int height = frame.Size.Height;

            if (width == 0 || height == 0)
            {
                return;
            }

            if (SourceImage == null || width != SourceImage.Width || height != SourceImage.Height)
            {
                SourceImage = new WriteableBitmap(width, height, 96, 96, PixelFormats.Bgr32, null);
                NotifyOfPropertyChange(() => SourceImage);
            }

            SourceImage.Lock();

            unsafe {
                int *backBuffer = (int *)SourceImage.BackBuffer;

                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        // Compute colors in pixel format. That is sRGB:
                        // MSDN: Bgr32 is a sRGB format with 32 bits per pixel (BPP).
                        // Each color channel (blue, green, and red) is allocated 8 bits per pixel (BPP).
                        int bgr = ((frame[x, y].R << 16) |
                                   (frame[x, y].G << 8) |
                                   (frame[x, y].B));

                        // Set the pixel at the current position to the BGR of the frame
                        *backBuffer++ = bgr;
                    }
                }
            }

            SourceImage.AddDirtyRect(new Int32Rect(0, 0, width, height));
            SourceImage.Unlock();
        }
示例#2
0
        public override void Handle(TickRenderedMessage message)
        {
            base.Handle(message);
            if (NodeModel.Data == null)
            {
                return;
            }

            int width  = NodeModel.Data.Size.Width;
            int height = NodeModel.Data.Size.Height;

            if (width == 0 || height == 0)
            {
                return;
            }

            if (RenderedImage == null || width != widthOld || height != heightOld)
            {
                RenderedImage = new WriteableBitmap(width, height, 96, 96, PixelFormats.Bgr32, null);
                widthOld      = width;
                heightOld     = height;
                NotifyOfPropertyChange(() => RenderedImage);
            }
            RenderedImage.Lock();

            unsafe {
                int *backBuffer = (int *)RenderedImage.BackBuffer;

                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        // Compute colors in pixel format. That is sRGB:
                        // MSDN: Bgr32 is a sRGB format with 32 bits per pixel (BPP).
                        // Each color channel (blue, green, and red) is allocated 8 bits per pixel (BPP).
                        int rgb = ((NodeModel.Data[x, y].R << 16) |
                                   (NodeModel.Data[x, y].G << 8) |
                                   (NodeModel.Data[x, y].B));

                        // Set the pixel at the current position to the BGR of the frame
                        *backBuffer++ = rgb;
                    }
                }
            }
            RenderedImage.AddDirtyRect(new Int32Rect(0, 0, width, height));
            RenderedImage.Unlock();
        }