Exemple #1
0
        public void SetImageSource(ImageSources source, string filename)
        {
            imageSourceType = source;

            if (imageSourceType == ImageSources.File)
            {
                using (var tempImage = new Bitmap(filename))
                {
                    using (var g = System.Drawing.Graphics.FromImage(scaledImage))
                    {
                        var ratio      = Math.Min(tempImage.Width / (float)camSensorWidth, tempImage.Height / (float)camSensorHeight);
                        var srcWidth   = (int)(camSensorWidth * ratio);
                        var srcHeight  = (int)(camSensorHeight * ratio);
                        var srcX       = (tempImage.Width - srcWidth) / 2;
                        var srcY       = (tempImage.Height - srcHeight) / 2;
                        var scaledRect = new Rectangle(0, 0, camSensorWidth, camSensorHeight);

                        g.FillRectangle(Brushes.White, scaledRect);
                        g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
                        g.DrawImage(tempImage, scaledRect, new Rectangle(srcX, srcY, srcWidth, srcHeight), GraphicsUnit.Pixel);
                    }
                }

                for (var x = 0; x < camSensorWidth; x++)
                {
                    for (var y = 0; y < camSensorHeight; y++)
                    {
                        webcamOutput[x, y] = (int)(scaledImage.GetPixel(x, y).GetBrightness() * 255);
                    }
                }
            }
        }
        public void FastBitmapModificationsAreApplied()
        {
            List <string> files = new List <string>
            {
                ImageSources.GetFilePathByName("format-Penguins.jpg"),
                ImageSources.GetFilePathByName("format-Penguins.png"),
            };

            foreach (string file in files)
            {
                Bitmap bmp      = new Bitmap(file);
                Bitmap original = (Bitmap)bmp.Clone();

                using (FastBitmap fbmp = new FastBitmap(bmp))
                {
                    // draw a pink diagonal line
                    for (int i = 0; i < 10; i++)
                    {
                        fbmp.SetPixel(i, i, Color.Pink);
                    }
                }

                AssertionHelpers.AssertImagesAreDifferent(original, bmp, "because modifying the fast bitmap should have modified the original bitmap");
            }
        }
Exemple #3
0
 private void ValidateImageSources()
 {
     foreach (var classEnum in _guide.GetListOfClasses().Concat(new[] { ClassEnum.All }))
     {
         if (!ImageSources.ContainsKey(classEnum) || !File.Exists(ImageSources[classEnum]))
         {
             ImageSources[classEnum] = Guide.MissingImageUrl;
         }
     }
 }
        public void BitmapIsRead()
        {
            List <string> files = new List <string>
            {
                ImageSources.GetFilePathByName("format-Penguins.jpg"),
                ImageSources.GetFilePathByName("format-Penguins.png"),
            };

            foreach (string file in files)
            {
                Bitmap bmp = new Bitmap(file);

                using (FastBitmap fbmp = new FastBitmap(bmp))
                {
                    fbmp.Width.Should().Be(bmp.Width, "because the bitmap should have been read");
                    fbmp.Height.Should().Be(bmp.Height, "because the bitmap should have been read");
                }
            }
        }
Exemple #5
0
        public GBCameraCartridge(int romSize, int ramSize)
        {
            imageSourceType = ImageSources.Noise;
            scaledImage     = new Bitmap(camSensorWidth, camSensorHeight);

            webcamOutput    = new int[camSensorWidth, camSensorHeight];
            camRetinaOutput = new int[camSensorWidth, camSensorHeight];
            tileBuffer      = new byte[14, 16, 16];

            romData = new byte[romSize];
            ramData = new byte[ramSize];

            romBank = 1;
            ramBank = 0;

            ramEnable = false;

            camRegisters = new byte[0x80];              // 0x36 used
            camSelected  = false;

            hasBattery = false;
        }
        public MainWindowViewModel()
        {
            #region ChangeNumberOfCubesCommand
            ChangeNumberOfCubesCommand = new RelayCommand<EventArgs>(e =>
                {
                    Status = "Changing number of cubes";
                    var args = e as RoutedPropertyChangedEventArgs<double>;
                    if (args != null)
                    {
                        var numToChange = Math.Abs(Convert.ToInt32(CubeViewModels.Count - args.NewValue));
                        if (args.NewValue < CubeViewModels.Count) // removing cubes
                        {
                            for (var i = 0; i < numToChange; i++)
                            {
                                CubeViewModels.RemoveAt(CubeViewModels.Count - 1);
                            }
                            NeighborCalculator.CalculateNeighbors(CubeViewModels);
                        }
                        else if (args.NewValue > CubeViewModels.Count) // adding cubes
                        {
                            AddNewCubes(numToChange);
                            Status = ReadyStatus;
                            SnapToGridCommand.Execute(null);
                            if (AppRunner.IsRunning)
                            {
                                AppRunner.App.AssociateCubes(CubeSet);
                            }
                        }
                    }
                    Status = ReadyStatus;
                });
            #endregion
            #region SnapToGridCommand
            SnapToGridCommand = new RelayCommand(() =>
                {
                    Status = "Snapping to grid";
                    for (var i = 0; i < Math.Ceiling(CubeViewModels.Count / 4.0); i++)
                    {
                        for (var j = 0; j < 4; j++)
                        {
                            if ((i * 4) + j > CubeViewModels.Count - 1)
                            {
                                NeighborCalculator.CalculateNeighbors(CubeViewModels);
                                Status = ReadyStatus;
                                return;
                            }
                            CubeViewModels[(i * 4) + j].PositionX = 200 * j;
                            CubeViewModels[(i * 4) + j].PositionY = 200 * i;
                        }
                    }
                    NeighborCalculator.CalculateNeighbors(CubeViewModels);
                    Status = ReadyStatus;
                });
            #endregion
            #region LoadAFileCommand
            LoadAFileCommand = new RelayCommand(() =>
                {
                    if (AppRunner.IsRunning)
                    {
                        AppRunner.StopExecution();
                    }

                    Status = "Select the application to run.";

                    var openFileDialog = new OpenFileDialog
                                             {
                                                 Filter = "C# Library (*.dll)|*.dll|All Files (*.*)|*.*",
                                                 FilterIndex = 1,
                                                 Multiselect = false
                                             };
                    if (openFileDialog.ShowDialog() == true)
                    {
                        Status = "Loading application...";
                        using (var fileStream = openFileDialog.File.OpenRead())
                        {
                            try
                            {
                                AppRunner.LoadApplication(fileStream);
                            }
                            catch (TypeLoadException e)
                            {
                                Status = String.Format("Unable to load application: {0}", e.Message);
                            }
                        }
                        if (AppRunner.IsLoaded)
                        {
                            Status = "Loading image resources...";
                            if (openFileDialog.File.Directory != null)
                            {
                                _imageSources =
                                    new ImageSources(openFileDialog.File.Directory.FullName + "/assets/images");
                                SoundSources =
                                    new SoundSources(openFileDialog.File.Directory.FullName + "/assets/sounds");

                                SoundSources.NotifyNewSound += sound =>
                                    SoundSources.InitializeSound(sound, ActiveSounds, InactiveSounds);
                                Sound.NotifyPauseAllSounds += () => SoundSources.PauseAllSounds(ActiveSounds, InactiveSounds);
                                Sound.NotifyResumeAllSounds += () => SoundSources.ResumeAllSounds(ActiveSounds, InactiveSounds);
                                Sound.NotifyStopAllSounds += () => SoundSources.StopAllSounds(ActiveSounds, InactiveSounds);

                                AppRunner.App.Images = _imageSources.GetImageSet();

                                foreach (var cubeViewModel in CubeViewModels)
                                {
                                    cubeViewModel.ImageSources = _imageSources;
                                }

                                Status = openFileDialog.File.Name + " was loaded.";
                                AppRunner.StartExecution(CubeSet, Application.Current.MainWindow.Dispatcher,
                                                            SoundSources.SoundSet);
                                AppRunner.NotifyApplicationException += DisplayException;
                                NotifyPropertyChanged("PauseOrResumeText");
                                NotifyPropertyChanged("CanPauseOrResume");
                            }
                            else
                            {
                                Status = "Application loading failed.";
                            }
                        }
                    }
                    else
                    {
                        Status = "Program loader was closed.";
                    }
                });
            #endregion
            #region PauseOrResumeCommand

            PauseOrResumeCommand = new RelayCommand(() =>
            {
                if (AppRunner.IsRunning)
                {
                    AppRunner.PauseExecution();
                    SoundSources.PauseAllSounds(ActiveSounds, InactiveSounds);
                } else
                {
                    AppRunner.ResumeExecution();
                    SoundSources.ResumeAllSounds(ActiveSounds, InactiveSounds);
                }
                NotifyPropertyChanged("PauseOrResumeText");
            });
            #endregion
            #region ChangeBackgroundCommand
            ChangeBackgroundCommand = new RelayCommand(() =>
            {
                Status = "Changing Background";
                if (BgColor == "SkyBlue")
                {
                    BgColor = "Red";
                }
                else
                {
                    BgColor = "SkyBlue";
                }

                Status = ReadyStatus;
            });
            #endregion

            AppRunner = AppRunner.GetInstance();

            CubeViewModels = new ObservableCollection<CubeViewModel>();
            AddNewCubes(NumInitialCubes);
            SnapToGridCommand.Execute(null);
            ActiveSounds = new ObservableCollection<SoundViewModel>();
            InactiveSounds = new Collection<SoundViewModel>();
            Status = ReadyStatus;
        }
Exemple #7
0
 public ContentSecurityPolicyBuilder AddImageSource(string value)
 {
     ImageSources.Add(value);
     return(this);
 }