private void UpdatePositionDecrease(int index, int minimalIndex) { IndexedColor swap = null; while (index - 1 >= minimalIndex && _colorsSorted[index].PixelsCount < _colorsSorted[index - 1].PixelsCount) { swap = _colorsSorted[index]; _colorsSorted[index] = _colorsSorted[index - 1]; _colorsSorted[index - 1] = swap; index--; } }
private void UpdatePositionIncrease(int index) { IndexedColor swap = null; while (index + 1 < _colorsSorted.Length && _colorsSorted[index].PixelsCount > _colorsSorted[index + 1].PixelsCount) { int iSwap = _colorsSorted[index].Index; _colorsSorted[index].Index = _colorsSorted[index + 1].Index; _colorsSorted[index + 1].Index = iSwap; swap = _colorsSorted[index]; _colorsSorted[index] = _colorsSorted[index + 1]; _colorsSorted[index + 1] = swap; index++; } }
private void DeleteColor(int index) { IndexedColor cl = _colorsSorted[index]; int replacment = GetClosestColor(cl); cl.ReplaceColorRoot(_image, _colorsBook[replacment].Color); _colorsBook[replacment].AddReplacment(cl); //_colorsBook[replacment].UpdatePixelsCount(); //FlushRemoval(index, _colorsBook[replacment].Color); _deletedColors.Add(replacment); _deletedColorReplacments.Push(replacment); UpdatePositionIncrease(replacment); //for(int i = 0; i < _colorsSorted.Length; i++) //Array.Sort(_colorsSorted, _deletedColors.Count, _colorsSorted.Length - _deletedColors.Count, IndexedColor.AlternativeComparer); }
/// <summary> /// Handles the Click event of SelectInPaletteButton object. /// </summary> private void selectInPaletteButton_Click(object sender, EventArgs e) { // create pallete viewer form using (PaletteForm paletteDlg = new PaletteForm()) { paletteDlg.PaletteViewer.CanChangePalette = false; IndexedColor indColor = ((IndexedColor)_selectedColor); paletteDlg.PaletteViewer.Palette = indColor.Palette; paletteDlg.PaletteViewer.SelectedColorIndex = indColor.Index; if (paletteDlg.ShowDialog() == DialogResult.OK) { // set new color to pixel indexNumericUpDown.Value = (int)paletteDlg.PaletteViewer.SelectedColorIndex; ShowSelectedPixelColor(_selectedColorX, _selectedColorY, new IndexedColor(paletteDlg.PaletteViewer.Palette, paletteDlg.PaletteViewer.SelectedColorIndex)); SetColorOfSelectedPixel(); } } }
private int GetClosestColor(IndexedColor cl) { //Color minColor = _colorsSorted[_colorsSorted.Length - 1].Key.color; //var min = ColorAndImageFactory.GetColorRangeQ(cl, minColor); //for(int i = _colorsSorted.Length - 2; i > _deletedColors.Count; i--) { // var diff = ColorAndImageFactory.GetColorRangeQ(cl, _colorsSorted[i].Key); // if(diff < min) { // minColor = _colorsSorted[i].Key; // min = diff; // } //} //return minColor; //throw new NotImplementedException(); int id = cl.Index; int diff = 0; int iteration = 1; do { if (diff > 0) { diff -= iteration; if (id + diff < 0) { continue; } } else { diff += iteration; if (id + diff > _colorsBook.Length - 1) { continue; } } iteration++; } while(_deletedColors.Contains(id + diff)); //Trace.WriteLine(string.Format("{0} -> {1}, {2} -> {3}", id, id + diff, _colorsBook[id].Index, _colorsBook[id + diff].Index)); return(id + diff); }
public void UpdateColors() { _progress.OperationsDone = 0; _progress.OperationsTotal = _image.Width; Dictionary <Color, IndexedColor> colors = new Dictionary <Color, IndexedColor>(); for (int i = 0; i < _image.Width; i++) { for (int j = 0; j < _image.Height; j++) { var col = _image.GetPixel(i, j); if (colors.ContainsKey(col)) { colors[col].Pixels.Add(new Pixel(col, i, j)); } else { var indexedColor = new IndexedColor(col); indexedColor.Pixels.Add(new Pixel(col, i, j)); colors[col] = indexedColor; } } _progress.OperationsDone = i; } _colorsSorted = colors.Values.ToArray(); _colorsBook = new IndexedColor[_colorsSorted.Length]; Array.Copy(_colorsSorted, _colorsBook, _colorsSorted.Length); Array.Sort(_colorsBook); for (int i = 0; i < _colorsBook.Length; i++) { _colorsBook[i].Index = i; } for (int i = 0; i < _colorsSorted.Length; i++) { _colorsSorted[i].UpdatePixelsCount(); } Array.Sort(_colorsSorted, (IndexedColor a, IndexedColor b) => a.PixelsCount.CompareTo(b.PixelsCount)); _progress.OperationsDone = _progress.OperationsTotal; }
/// <summary> /// Updates the information about selected pixel. /// </summary> /// <param name="x">Selected pixel x coordinate.</param> /// <param name="y">Selected pixel y coordinate.</param> /// <param name="pixelColor">Selected pixel color.</param> private void ShowSelectedPixelColor(int x, int y, ColorBase pixelColor) { VintasoftImage image = _viewer.Image; _selectedColorX = x; _selectedColorY = y; _selectedColor = pixelColor; selectedPixelLabel.Text = string.Format("Selected Pixel: X={0},Y={1}; ColorType={2}", x, y, pixelColor.GetType().Name); _pixelSelect = true; if (pixelColor is Rgb24Color) { Rgb24Color rgbColor = (Rgb24Color)pixelColor; argbPanel.Visible = true; indexedPanel.Visible = false; gray16Panel.Visible = false; redNumericUpDown.Maximum = 255; redNumericUpDown.Value = rgbColor.Red; greenNumericUpDown.Maximum = 255; greenNumericUpDown.Value = rgbColor.Green; blueNumericUpDown.Maximum = 255; blueNumericUpDown.Value = rgbColor.Blue; if (pixelColor is Argb32Color) { alphaNumericUpDown.Maximum = 255; alphaNumericUpDown.Value = ((Argb32Color)pixelColor).Alpha; alphaNumericUpDown.Visible = true; rgbColorTypeLabel.Text = "ARGB32 ="; } else { alphaNumericUpDown.Visible = false; rgbColorTypeLabel.Text = "RGB (24bpp) ="; } } else if (pixelColor is Rgb48Color) { Rgb48Color rgb48Color = (Rgb48Color)pixelColor; argbPanel.Visible = true; indexedPanel.Visible = false; gray16Panel.Visible = false; redNumericUpDown.Maximum = 65535; redNumericUpDown.Value = rgb48Color.Red; greenNumericUpDown.Maximum = 65535; greenNumericUpDown.Value = rgb48Color.Green; blueNumericUpDown.Maximum = 65535; blueNumericUpDown.Value = rgb48Color.Blue; if (pixelColor is Argb64Color) { alphaNumericUpDown.Maximum = 65535; alphaNumericUpDown.Value = ((Argb64Color)pixelColor).Alpha; alphaNumericUpDown.Visible = true; rgbColorTypeLabel.Text = "ARGB64 ="; } else { alphaNumericUpDown.Visible = false; rgbColorTypeLabel.Text = "RGB (48bpp) ="; } } else if (pixelColor is Rgb16ColorBase) { Rgb16ColorBase rgb16Color = (Rgb16ColorBase)pixelColor; argbPanel.Visible = true; indexedPanel.Visible = false; gray16Panel.Visible = false; redNumericUpDown.Maximum = 31; redNumericUpDown.Value = rgb16Color.Red; blueNumericUpDown.Maximum = 31; blueNumericUpDown.Value = rgb16Color.Blue; alphaNumericUpDown.Visible = false; if (pixelColor is Rgb16Color555) { greenNumericUpDown.Maximum = 31; rgbColorTypeLabel.Text = "RGB16 (5-5-5) ="; } else { greenNumericUpDown.Maximum = 63; rgbColorTypeLabel.Text = "RGB16 (5-6-5) ="; } greenNumericUpDown.Value = rgb16Color.Green; } else if (pixelColor is IndexedColor) { IndexedColor indexedColor = (IndexedColor)pixelColor; argbPanel.Visible = false; indexedPanel.Visible = true; gray16Panel.Visible = false; indexNumericUpDown.Maximum = indexedColor.Palette.ColorCount - 1; indexNumericUpDown.Value = indexedColor.Index; } else if (pixelColor is Gray16Color) { Gray16Color gray16 = (Gray16Color)pixelColor; argbPanel.Visible = false; indexedPanel.Visible = false; gray16Panel.Visible = true; gray16LumNumericUpDown.Value = gray16.Luminance; } selectedPixelColorPanel.BackColor = pixelColor.ToColor(); _pixelSelect = false; pixelsGroupBox.Refresh(); }