Exemple #1
0
        public override void Execute(Action onCompleted, Action <Exception> onError)
        {
            // create graph with renderers
            _graph = new RenderGraph {
                Destinations  = GetRenderers(_options),
                RenderAsGray4 = _options.RenderAsGray4
            };

            // instantiate transformation processor
            var transformationProcessor = new TransformationProcessor {
                FlipVertically   = _options.FlipVertically,
                FlipHorizontally = _options.FlipHorizontally
            };

            // setup source and additional processors
            switch (_options.Source)
            {
            case SourceType.PinballFX2: {
                if (_options.GridSize.Length != 2)
                {
                    throw new InvalidOptionException("Argument --grid-size must have two values: \"<Width> <Height>\".");
                }
                if (_options.DmdCrop.Length != 4)
                {
                    throw new InvalidOptionException("Argument --dmd-crop must have four values: \"<Left> <Top> <Right> <Bottom>\".");
                }
                _graph.Source = new PBFX2Grabber {
                    FramesPerSecond = _options.FramesPerSecond,
                    CropLeft        = _options.DmdCrop[0],
                    CropTop         = _options.DmdCrop[1],
                    CropRight       = _options.DmdCrop[2],
                    CropBottom      = _options.DmdCrop[3]
                };
                var gridProcessor = new GridProcessor {
                    Spacing = _options.GridSpacing,
                    Width   = _options.GridSize[0],
                    Height  = _options.GridSize[1]
                };
                var shadeProcessor = new ShadeProcessor {
                    Enabled    = !_options.DisableShading,
                    NumShades  = _options.NumShades,
                    Intensity  = _options.ShadeIntensity,
                    Brightness = _options.ShadeBrightness
                };
                _graph.Processors = new List <AbstractProcessor> {
                    gridProcessor,
                    transformationProcessor,
                    shadeProcessor
                };
                break;
            }

            case SourceType.PinballArcade: {
                _graph.Source = new TPAGrabber {
                    FramesPerSecond = _options.FramesPerSecond
                };
                var shadeProcessor = new ShadeProcessor {
                    Enabled    = !_options.DisableShading,
                    NumShades  = 4,
                    Shades     = new[] { 0d, 0.22, 0.35, 0.55 },
                    Intensity  = 1.9,
                    Brightness = 0
                };
                _graph.Processors = new List <AbstractProcessor>()
                {
                    transformationProcessor,
                    shadeProcessor
                };
                break;
            }

            case SourceType.Screen:
                if (_options.Position.Length != 4)
                {
                    throw new InvalidOptionException("Argument --position must have four values: \"<Left> <Top> <Width> <Height>\".");
                }
                _graph.Source = new ScreenGrabber {
                    FramesPerSecond = _options.FramesPerSecond,
                    Left            = _options.Position[0],
                    Top             = _options.Position[1],
                    Width           = _options.Position[2],
                    Height          = _options.Position[3]
                };
                _graph.Processors = new List <AbstractProcessor>()
                {
                    transformationProcessor
                };
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            // TODO add as option
            var monochromeProcessor = new MonochromeProcessor {
                Tint = Color.FromRgb(255, 155, 0)
            };

            // always transform to correct dimensions
            _renderer = _graph.StartRendering(onCompleted, onError);
        }
Exemple #2
0
        public MainWindow()
        {
            InitializeComponent();
            Closing += OnWindowClosing;

            var title   = (AssemblyTitleAttribute)Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false).FirstOrDefault();
            var version = (AssemblyInformationalVersionAttribute)Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false).FirstOrDefault();

            Title = $"{title?.Title} v{version?.InformationalVersion}";


            // define renderers
            var renderers = new List <IFrameDestination> {
                VirtualDmd
            };

            Console.AppendText("Added VirtualDMD renderer.\n");

            try {
                var pinDmd = PinDmd3.GetInstance();
                if (pinDmd.IsAvailable)
                {
                    renderers.Add(pinDmd);
                    Console.AppendText($"Added PinDMDv3 renderer.\n");
                    Console.AppendText($"PinDMDv3 detected at {pinDmd.Width}x{pinDmd.Height}\n");
                    Console.AppendText($"Firmware: {pinDmd.Firmware}\n");
                }
                else
                {
                    Console.AppendText("PinDMDv3 not connected.\n");
                }
                var pin2Dmd = Pin2Dmd.GetInstance();
                if (pin2Dmd.IsAvailable)
                {
                    renderers.Add(pin2Dmd);
                    Console.AppendText($"Added PIN2DMD renderer.\n");
                }
                else
                {
                    Console.AppendText("PIN2DMD not connected.\n");
                }
                var pinDmd2 = PinDmd2.GetInstance();
                if (pinDmd2.IsAvailable)
                {
                    renderers.Add(pinDmd2);
                    Console.AppendText($"Added PinDMDv2 renderer.\n");
                }
                else
                {
                    Console.AppendText("PinDMDv2 not connected.\n");
                }
                var pinDmd1 = PinDmd1.GetInstance();
                if (pinDmd1.IsAvailable)
                {
                    renderers.Add(pinDmd1);
                    Console.AppendText($"Added PinDMDv1 renderer.\n");
                }
                else
                {
                    Console.AppendText("PinDMDv1 not connected.\n");
                }
            } catch (DllNotFoundException e) {
                Console.AppendText("A DLL was not found. It's possible that Windows blocked it.\n");
                Console.AppendText("Go look for it in the installation folder. If it's there, right-click, \"Properties\" and \"unblock\".\n");
                Console.AppendText("Then restart the app.\n");
                Console.AppendText("Message: " + e.Message + "\n");
            }

            // define sources
            var grabber = new ScreenGrabber {
                FramesPerSecond = 15
            };

            _pbfxGrabber = new PBFX2Grabber {
                FramesPerSecond = 25
            };
            _tpaGrabber = new TPAGrabber {
                FramesPerSecond = 15
            };

            // define processors
            _pbfxGridProcessor = new GridProcessor {
                Enabled = true, Spacing = 1
            };
            _tpaGridProcessor = new GridProcessor {
                Enabled = true, Spacing = 0, CropRight = 0, CropBottom = 1
            };
            var transformationProcessor = new TransformationProcessor {
                Enabled = true, FlipVertically = false, FlipHorizontally = false
            };
            var monochromeProcessor = new MonochromeProcessor {
                Enabled     = true,
                PixelFormat = PixelFormats.Gray16,
                Tint        = System.Windows.Media.Color.FromRgb(255, 155, 0)
            };

            _pbfxShadeProcessor = new ShadeProcessor {
                NumShades = 4, Intensity = 2.5, Brightness = 0
            };
            _tpaShadeProcessor = new ShadeProcessor {
                NumShades  = 4,
                Intensity  = 1.9,
                Brightness = 0,
                Shades     = new[] { 0d, 0.22, 0.35, 0.55 }
            };

            // chain them up
            _screenGraph = new RenderGraph {
                Source       = grabber,
                Destinations = renderers,
                Processors   = new List <AbstractProcessor> {
                    transformationProcessor, monochromeProcessor
                }
            };
            _pbfxGraph = new RenderGraph {
                Source       = _pbfxGrabber,
                Destinations = renderers,
                Processors   = new List <AbstractProcessor> {
                    _pbfxGridProcessor, transformationProcessor, _pbfxShadeProcessor
                }
            };
            _tpaGraph = new RenderGraph {
                Source       = _tpaGrabber,
                Destinations = renderers,
                Processors   = new List <AbstractProcessor> {
                    transformationProcessor, _tpaShadeProcessor
                }
            };

            // init grabber window and link it to grabber
            _grabberWindow = new GrabberWindow()
            {
                Left   = Properties.Settings.Default.GrabLeft,
                Top    = Properties.Settings.Default.GrabTop,
                Width  = Properties.Settings.Default.GrabWidth,
                Height = Properties.Settings.Default.GrabHeight,
            };
            _grabberWindow.WhenPositionChanges.Subscribe(rect => {
                grabber.Move(rect);
                Properties.Settings.Default.GrabLeft   = rect.X;
                Properties.Settings.Default.GrabTop    = rect.Y;
                Properties.Settings.Default.GrabWidth  = rect.Width;
                Properties.Settings.Default.GrabHeight = rect.Height;
                Properties.Settings.Default.Save();
            });

            PreviewKeyDown += _grabberWindow.HotKey;
            PreviewKeyUp   += _grabberWindow.HotKey;
            PreviewKeyDown += HotKey;

            // grid preview images
            _pbfxGridProcessor.WhenProcessed.Subscribe(bmp => {
                ProcessedGrid.Dispatcher.Invoke(() => {
                    ProcessedGrid.Source = bmp;
                });
            });
            transformationProcessor.WhenProcessed.Subscribe(bmp => {
                ProcessedGrid.Dispatcher.Invoke(() => {
                    ProcessedGrid.Source = bmp;
                });
            });
        }