public SortSettingsForm(Bitmap image) : base() { InitializeComponent(); //Initialize the form's comboboxes with their respective enum values sortByComboBox.DataSource = SortSettings.GetEnumAsDataSource(typeof(SortSettings.SortBy)); sortDirectionComboBox.DataSource = SortSettings.GetEnumAsDataSource(typeof(SortSettings.SortDirection)); intervalTypeComboBox.DataSource = SortSettings.GetEnumAsDataSource(typeof(SortSettings.IntervalType)); previewPictureBox.Image = image; intervalUpDown.Maximum = Math.Max(image.Width, image.Height); // Change to hypotemus for angles }
private void startButton_Click(object sender, EventArgs e) { Settings = new SortSettings { ImageOriginal = (Bitmap)previewPictureBox.Image, SortBySelection = (SortSettings.SortBy)sortByComboBox.SelectedIndex, SortDirectionSelection = (SortSettings.SortDirection)sortDirectionComboBox.SelectedIndex, IntervalTypeSelection = (SortSettings.IntervalType)intervalTypeComboBox.SelectedIndex, Angle = (int)angleUpDown.Value, Interval = (int)intervalUpDown.Value, IsRandomInterval = randomIntervalCheckBox.Checked }; DialogResult = DialogResult.OK; Close(); }
private List <Color> PixelSort(SortSettings settings, List <Color> colors) { switch (settings.IntervalTypeSelection) { case SortSettings.IntervalType.Disabled: Sort(settings, colors); break; case SortSettings.IntervalType.FromPixel: case SortSettings.IntervalType.WholeImage: SortInterval(settings, colors); break; } return(colors); }
private List <Color> SortInterval(SortSettings settings, List <Color> colors) { switch (settings.IntervalTypeSelection) { case SortSettings.IntervalType.FromPixel: break; case SortSettings.IntervalType.WholeImage: double subArrayLength = settings.ImageOriginal.Width / settings.Interval; for (int i = 0; i < settings.ImageOriginal.Width; i += settings.Interval) { int length = i + settings.Interval > settings.ImageOriginal.Width ? settings.ImageOriginal.Width - i : settings.Interval; Sort(settings, colors.GetRange(i, length)); } break; } return(colors); }
public PixelSorterForm(SortSettings settings) { InitializeComponent(); this.settings = settings; stop = false; Bitmap image = settings.ImageOriginal; settings.ImageSorted = (Bitmap)image.Clone(); int value = settings.SortDirectionSelection == SortSettings.SortDirection.Horizontal ? image.Height : image.Width; progressBar.Maximum = value; for (int index = 0; index < value; index++) { ThreadInfo threadInfo = new ThreadInfo(); threadInfo.Image = (Bitmap)image.Clone(); threadInfo.Index = index; threadInfo.Settings = (SortSettings)settings.Clone(); ThreadPool.QueueUserWorkItem(new WaitCallback(Process), threadInfo); } }
private List <Color> Sort(SortSettings settings, List <Color> colors) { switch (settings.SortBySelection) { case SortSettings.SortBy.Brightness: colors.Sort(delegate(Color color1, Color color2) { return(color1.GetBrightness().CompareTo(color2.GetBrightness())); }); break; case SortSettings.SortBy.Luminance: colors.Sort(delegate(Color color1, Color color2) { return(GetRelativeLuminance(color1).CompareTo(GetRelativeLuminance(color2))); }); break; case SortSettings.SortBy.Hue: colors.Sort(delegate(Color color1, Color color2) { return(color1.GetHue().CompareTo(color2.GetHue())); }); break; case SortSettings.SortBy.Saturation: colors.Sort(delegate(Color color1, Color color2) { return(color1.GetSaturation().CompareTo(color2.GetSaturation())); }); break; } return(colors); }