예제 #1
0
        public Mapping()
        {
            this.InitializeComponent();

            frameRenderer = new FrameRenderer(this.depthPreviewImage);
            frameRenderer.renderFramesInUI = true;
        }
예제 #2
0
 public void Dispose()
 {
     if (_mainCanvas != null)
     {
         if (_popMenuOverlayRenderer != null)
         {
             _popMenuOverlayRenderer.PointerPressed  -= menuOverlayRenderer_PointerPressed;
             _popMenuOverlayRenderer.PointerMoved    -= menuOverlayRenderer_PointerMoved;
             _popMenuOverlayRenderer.PointerReleased -= menuOverlayRenderer_PointerReleased;
             _popMenuOverlayRenderer.PointerExited   -= menuOverlayRenderer_PointerReleased;
             _mainCanvas.Children.Remove(_popMenuOverlayRenderer);
         }
         if (_backgroundOverlay != null)
         {
             _backgroundOverlay.Tapped -= _backgroundOverlay_Tapped;
             _mainCanvas.Children.Remove(_backgroundOverlay);
         }
         if (_popupRenderer != null)
         {
             _mainCanvas.Children.Remove(_popupRenderer);
         }
         _mainCanvas.SizeChanged -= mainCanvas_SizeChanged;
     }
     _mainCanvas             = null;
     _popMenuOverlayRenderer = null;
     _backgroundOverlay      = null;
     _popupRenderer          = null;
 }
예제 #3
0
 void HideBackgroundForPopup()
 {
     _currentPopup = null;
     if (_popupRenderer != null)
     {
         _mainCanvas.Children.Remove(_popupRenderer);
         _popupRenderer = null;
     }
     if (_backgroundOverlay != null)
     {
         _mainCanvas.Children.Remove(_backgroundOverlay);
         _backgroundOverlay = null;
     }
 }
예제 #4
0
        public MainPage()
        {
            this.InitializeComponent();

            puzzleSolver   = new PuzzleSolver();
            PanelParser    = new Parser();
            BrightnessCalc = new BrightnessCalculator();

            stylusDriver = new StylusDriver(phoneConfig);

            _SourceRenderer      = new FrameRenderer(PreviewImage);
            _ColorFilterRenderer = new FrameRenderer(ColotFilterImage);
            _ClippedRenderer     = new FrameRenderer(ClippedImage);

            _cvhelper = new OpenCVHelper();

            _FPSTimer = new DispatcherTimer()
            {
                Interval = TimeSpan.FromSeconds(1)
            };
            _FPSTimer.Tick += UpdateFPS;

            _MessageTimer = new DispatcherTimer()
            {
                Interval = TimeSpan.FromMilliseconds(100)
            };
            _MessageTimer.Tick += MessageTimer_Tick;
            MessageSB           = new StringBuilder();

            webcam = new Webcam(100);
            webcam.OnReceiveFrame += Webcam_OnReceiveFrame;

            StartPoint = new Point(phoneConfig.PadPanelLocation.Left, phoneConfig.PadPanelLocation.Top);
            EndPoint   = new Point(phoneConfig.PadPanelLocation.Right, phoneConfig.PadPanelLocation.Bottom);
            TargetScoreTextbox.Text = TargetRouteScore.ToString();

            FastModeCheckButton.IsChecked = FastMode;
            AutoModeCheckButton.IsChecked = AutoMode;
        }
예제 #5
0
        private bool _canPlayNext = true; //used for playing one frame at a time

        public FrameComparer(VideoDecoder decoder, FrameRenderer renderer)
        {
            Decoder  = decoder;
            Renderer = renderer;
        }
예제 #6
0
        private void LayoutPopup()
        {
            if (!CheckPageAndPopup())
            {
                return;
            }
            _popupBasePage.ShowPopupAction = (key) =>
            {
                if (!string.IsNullOrEmpty(_currentPopup))
                {
                    return;
                }
                SlidePopupView popup = null;
                if (!_popupBasePage.PopupViews.ContainsKey(key))
                {
                    if (string.IsNullOrEmpty(key) && _popupBasePage.PopupViews.Count == 1)
                    {
                        popup = _popupBasePage.PopupViews.Values.GetEnumerator().Current;
                    }
                    if (popup == null)
                    {
                        return;
                    }
                }

                _currentPopup = key;
                popup         = _popupBasePage.PopupViews[_currentPopup] as SlidePopupView;
                var renderer = popup.GetOrCreateRenderer();
                _popupRenderer = renderer as FrameRenderer;

                if (_popupRenderer != null)
                {
                    if (!PopupLayout())
                    {
                        return;
                    }
                    _mainCanvas.Children.Add(_popupRenderer);
                    Canvas.SetZIndex(_popupRenderer, 254);
                    _popupRenderer.Visibility = Visibility.Visible;

                    ShowBackgroundForPopup(popup.BackgroundViewColor);
                    popup.IsShown = true;
                }

                popup.HideMySelf = () =>
                {
                    HideBackgroundForPopup();
                    popup.IsShown = false;
                };
            };

            _popupBasePage.HidePopupAction = () =>
            {
                HideBackgroundForPopup();
                var popup = _popupBasePage.PopupViews.Values.Where(o => o.IsShown).FirstOrDefault();
                if (popup != null)
                {
                    popup.IsShown = false;
                }
            };
        }
예제 #7
0
            void renderItemList(Blitter b, List<Menu> items, int selIndex, bool selActive, int width)
            {
                int indent = 10;

                //indent the list
                b.OffsetWindow(indent, 0);

                int overallWidth = width + SelectionOverhang;

                //the tie
                FrameRenderer fr = new FrameRenderer(cabedge.img_ui, new Chunk[]{
                    new Chunk(75, 82, 4, 3),
                    new Chunk(75, 86, 4, 42),
                    new Chunk(75, 129, 4, 3),
                    new Chunk(80, 131, 1, 1),
                    Chunk.empty,
                    Chunk.empty,
                    Chunk.empty,
                    new Chunk(80, 82, 1, 1)});

                //the bar
                FrameRenderer fr_gray = new FrameRenderer(cabedge.img_ui, new Chunk[]{
                    new Chunk(94, 83, 5, 6),
                    new Chunk(94, 90, 5, 1),
                    new Chunk(94, 92, 5, 6),
                    new Chunk(100, 92, 1, 6),
                    new Chunk(102, 92, 5, 6),
                    new Chunk(102, 90, 5, 1),
                    new Chunk(102, 83, 5, 6),
                    new Chunk(100, 83, 1, 6)});

                FrameRenderer fr_sel = fr_gray.offset(0, 17);

                //the selActive renderer is same as green but with an endcap
                FrameRenderer fr_selActive = fr_sel.clone();
                fr_selActive.NE = new Chunk(108, 100, 5, 5);
                fr_selActive.E = new Chunk(108, 106, 5, 3);
                fr_selActive.SE = new Chunk(108, 110, 5, 5);

                //render the tie (the left,top,and bottom border)
                int tie_height = 16*items.Count+2;
                fr.render(b,new Rectangle(0,0,width,tie_height));

                //render items
                for(int i=0;i<items.Count;i++) {
                    int x = 4;
                    int y = i*16+1;
                    int w = width-4;
                    int h = 16;

                    //(render fill first so the green endcap can overlap)
                    if(i == selIndex) {
                        b.Color = MakeColor(225, 255, 208);
                        if(selActive) {
                            b.RectFill(x+5, y+6, w-10+SelectionOverhang, h-12);
                            fr_selActive.render(b, new Rectangle(x, y, w + SelectionOverhang, h));
                        } else {
                            b.RectFill(x+5, y+6, w-10, h-12);
                            fr_sel.render(b, new Rectangle(x, y, w, h));
                        }
                    } else {
                        b.Color = MakeColor(232, 232, 232);
                        b.RectFill(x+5, y+6, w-10, h-12);
                        fr_gray.render(b, new Rectangle(x, y, w, h));
                    }

                    if(items[i].label != null) {
                        int textOffset = 5;
                        //offset for aesthetics and/or icon
                        textOffset += 8;
                        cabedge.font_v3_1_black.Render(b, x+textOffset, y+5, items[i].label);
                    }
                }
            }
예제 #8
0
        /// <summary>
        /// Switches to the next camera source and starts reading frames.
        /// </summary>
        private async Task PickNextMediaSourceWorkerAsync()
        {
            await CleanupMediaCaptureAsync();

            var allGroups = await MediaFrameSourceGroup.FindAllAsync();

            if (allGroups.Count == 0)
            {
                _logger.Log("No source groups found.");
                return;
            }

            // Pick next group in the array after each time the Next button is clicked.
            _groupSelectionIndex = (_groupSelectionIndex + 1) % allGroups.Count;
            var selectedGroup = allGroups[1];

            // _logger.Log($"Found {allGroups.Count} groups and selecting index [{_groupSelectionIndex}]: {selectedGroup.DisplayName}");

            try
            {
                // Initialize MediaCapture with selected group.
                // This can raise an exception if the source no longer exists,
                // or if the source could not be initialized.
                await InitializeMediaCaptureAsync(selectedGroup);
            }
            catch (Exception exception)
            {
                _logger.Log($"MediaCapture initialization error: {exception.Message}");
                await CleanupMediaCaptureAsync();

                return;
            }

            // Set up frame readers, register event handlers and start streaming.
            var startedKinds = new HashSet <MediaFrameSourceKind>();

            foreach (MediaFrameSource source in _mediaCapture.FrameSources.Values)
            {
                MediaFrameSourceKind kind = source.Info.SourceKind;

                // Ignore this source if we already have a source of this kind.
                if (startedKinds.Contains(kind))
                {
                    continue;
                }

                // Look for a format which the FrameRenderer can render.
                string requestedSubtype = null;
                foreach (MediaFrameFormat format in source.SupportedFormats)
                {
                    requestedSubtype = FrameRenderer.GetSubtypeForFrameReader(kind, format);
                    if (requestedSubtype != null)
                    {
                        // Tell the source to use the format we can render.
                        await source.SetFormatAsync(format);

                        break;
                    }
                }
                if (requestedSubtype == null)
                {
                    // No acceptable format was found. Ignore this source.
                    continue;
                }

                MediaFrameReader frameReader = await _mediaCapture.CreateFrameReaderAsync(source, requestedSubtype);

                frameReader.FrameArrived += FrameReader_FrameArrived;
                _sourceReaders.Add(frameReader);

                MediaFrameReaderStartStatus status = await frameReader.StartAsync();

                if (status == MediaFrameReaderStartStatus.Success)
                {
                    //  _logger.Log($"Started {kind} reader.");
                    startedKinds.Add(kind);
                }
                else
                {
                    _logger.Log($"Unable to start {kind} reader. Error: {status}");
                }
            }

            if (startedKinds.Count == 0)
            {
                _logger.Log($"No eligible sources in {selectedGroup.DisplayName}.");
            }
        }
예제 #9
0
        public SolarSystemScene(GameWindow gw, PlanetParameters planetParams, ContentManager contentManager)
        {
            this.contentManager = contentManager;
            this.hoursPerSecond = 1;
            this.defaultShader  = contentManager.GetShader("default");
            this.sunShader      = contentManager.GetShader("sunShader");
            this.lineShader     = contentManager.GetShader("lineShader");
            this.earthShader    = contentManager.GetShader("earth");

            this.buffer = new Framebuffer(gw.Width, gw.Height);
            buffer.AttachColorBuffer(internalFormat: PixelInternalFormat.Rgba16f, type: PixelType.Float);
            buffer.AttachColorBuffer(internalFormat: PixelInternalFormat.Rgba16f, type: PixelType.Float);
            buffer.AttachDepthStencilBuffer();

            blur = new GaussianBlur((int)gw.Size.Width / 1, (int)gw.Size.Height / 1);

            frame = FrameRenderer.Instance;

            finalShader            = contentManager.LoadShader("final");
            finalShader.Initialize = () =>
            {
                finalShader.Bind();
                finalShader.SetUniform("frame", 0);
                finalShader.SetUniform("bloom", 1);
            };
            finalShader.Init();

            cam            = new Camera(60);
            cam.MaxDepth   = 600;
            cam.LightPos   = new Vector3(0, 0, 0);
            cam.Projection = Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(70), gw.Width / (float)gw.Height, .1f, 100000f);

            this.loadContent(planetParams, contentManager);

            cam.SetFocus(earth);

            #region Gui
            guiManager = new GuiManager(gw);
            panel      = new Panel()
            {
                Size            = new System.Drawing.Size(200, gw.Height),
                BackgroundColor = new Vector4(36f / 255, 36f / 255, 36f / 255, 1),
                BorderColor     = new Vector4(1, 1, 1, 1),
                Location        = new System.Drawing.Point(-201, 0),
            };

            var titleLabel = new Label()
            {
                Size      = new System.Drawing.Size(200, 50),
                Location  = new System.Drawing.Point(0, 10),
                Font      = new System.Drawing.Font("Arial", 20, System.Drawing.FontStyle.Underline),
                TextColor = new Vector4(1, 1, 1, 1),
                Text      = "Options"
            };

            int y     = 70;
            var label = new Label()
            {
                Size      = new System.Drawing.Size(120, 25),
                Location  = new System.Drawing.Point(10, y),
                TextColor = new Vector4(1, 1, 1, 1),
                Text      = "Axial Tilt"
            };
            var @switch = new Switch()
            {
                Location = new System.Drawing.Point(130, y), On = true
            };
            @switch.OnToggle += (o, e) =>
            {
                this.setAxialTiltDraw(((Switch)o).On);
            };
            panel.Controls.Add(titleLabel, label, @switch);

            y    += 30;
            label = new Label()
            {
                Size      = new System.Drawing.Size(120, 25),
                Location  = new System.Drawing.Point(10, y),
                TextColor = new Vector4(1, 1, 1, 1),
                Text      = "Orbits"
            };
            @switch = new Switch()
            {
                Location = new System.Drawing.Point(130, y), On = true
            };
            @switch.OnToggle += (o, e) =>
            {
                this.setOrbitDraw(((Switch)o).On);
            };
            panel.Controls.Add(label, @switch);

            y    += 30;
            label = new Label()
            {
                Size      = new System.Drawing.Size(120, 25),
                Location  = new System.Drawing.Point(10, y),
                TextColor = new Vector4(1, 1, 1, 1),
                Text      = "Bloom Buffer"
            };
            @switch = new Switch()
            {
                Location = new System.Drawing.Point(130, y)
            };
            @switch.OnToggle += (o, e) =>
            {
                this.showBloomBuffer = ((Switch)o).On;
            };
            panel.Controls.Add(label, @switch);

            y    += 30;
            label = new Label()
            {
                Size      = new System.Drawing.Size(120, 25),
                Location  = new System.Drawing.Point(10, y),
                TextColor = new Vector4(1, 1, 1, 1),
                Text      = "Bloom"
            };
            @switch = new Switch()
            {
                Location = new System.Drawing.Point(130, y), On = true
            };
            @switch.OnToggle += (o, e) =>
            {
                this.bloom = ((Switch)o).On;
            };
            panel.Controls.Add(label, @switch);

            guiManager.Controls.Add(panel);
            #endregion
        }
 public Move()
 {
     this.InitializeComponent();
     frameRenderer            = new FrameRenderer(this.colorPreviewImage);
     this.FrameRendererStatus = true;
 }
예제 #11
0
        public static IAsyncAction RenderFrameAsync_out(FrameRenderer frameRenderer, VideoFrame inputVideoFrame)
        {
            return(AsyncInfo.Run(async(token) =>
            {
                bool useDX = inputVideoFrame.SoftwareBitmap == null;
                if (frameRenderer == null)
                {
                    throw (new InvalidOperationException("FrameRenderer is null"));
                }

                SoftwareBitmap softwareBitmap = null;
                if (useDX)
                {
                    softwareBitmap = await SoftwareBitmap.CreateCopyFromSurfaceAsync(inputVideoFrame.Direct3DSurface);
                    softwareBitmap = SoftwareBitmap.Convert(softwareBitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied);
                }
                else
                {
                    softwareBitmap = inputVideoFrame.SoftwareBitmap;

                    int a = 1;

                    if (a == 1)
                    {
                        using (BitmapBuffer buffer = softwareBitmap.LockBuffer(BitmapBufferAccessMode.Write))
                        {
                            using (var reference = buffer.CreateReference())
                            {
                                unsafe
                                {
                                    byte *dataInBytes;
                                    uint capacity;

                                    ((IMemoryBufferByteAccess)reference).GetBuffer(out dataInBytes, out capacity);

                                    // Fill-in the BGRA plane
                                    BitmapPlaneDescription bufferLayout = buffer.GetPlaneDescription(0);
                                    // In BGRA8 format, each pixel is defined by 4 bytes
                                    const int BYTES_PER_PIXEL = 4;

                                    for (int i = 0; i < bufferLayout.Height; i++)
                                    {
                                        for (int j = 0; j < bufferLayout.Width; j++)
                                        {
                                            var currPixel = bufferLayout.StartIndex + bufferLayout.Stride * i + BYTES_PER_PIXEL * j;
                                            // Read the current pixel information into b,g,r channels (leave out alpha channel)
                                            var b = dataInBytes[currPixel + 0]; // Blue
                                            var g = dataInBytes[currPixel + 1]; // Green
                                            var r = dataInBytes[currPixel + 2]; // Red
                                                                                // Boost the green channel, leave the other two untouched
                                            dataInBytes[currPixel + 0] = r;
                                            dataInBytes[currPixel + 1] = g;
                                            dataInBytes[currPixel + 2] = b;
                                        }
                                    }
                                }
                            }
                        }
                    }



                    // Scale image to appropriate size
                    //BitmapTransform transform = new BitmapTransform()
                    //{
                    //    ScaledWidth = Convert.ToUInt32(WriteableBitmap.PixelWidthProperty),
                    //    ScaledHeight = Convert.ToUInt32(WriteableBitmap.PixelHeightProperty)
                    //};
                    //softwareBitmap = new SoftwareBitmap(
                    //    BitmapPixelFormat.Bgra8,
                    //    inputVideoFrame.SoftwareBitmap.PixelWidth,
                    //    inputVideoFrame.SoftwareBitmap.PixelHeight,
                    //    inputVideoFrame.SoftwareBitmap.BitmapAlphaMode);
                    //inputVideoFrame.SoftwareBitmap.CopyTo(softwareBitmap);
                }

                frameRenderer.RenderFrame(softwareBitmap);
            }));
        }
 public void RegisterFrameRenderer(FrameRenderer renderer, String id)
 {
     Renderers.Add(id, renderer);
 }