CrossStitchCreator.ImagingTool.ReduceColourDepth C# (CSharp) Method

ReduceColourDepth() public method

public ReduceColourDepth ( object o, BackgroundWorker w, DoWorkEventArgs e ) : object
o object
w System.ComponentModel.BackgroundWorker
e System.ComponentModel.DoWorkEventArgs
return object
        public object ReduceColourDepth(object o, BackgroundWorker w, DoWorkEventArgs e)
        {
            Console.WriteLine("Worker thread: " + this + ","+TargetColours+","+ColourMap +","+ColourMap.Count);
            // This case we're removing colours one at a time, replacing them with closest colours
            if (TargetColours > 0)
            {
                Console.WriteLine("ReduceColourDepth: initial nColours = " + ColourMap.Count + ", Target: " + TargetColours);
                int toRemove = ColourMap.Count - TargetColours;

                for (int i = 0; i < toRemove; i++)
                {
                    if (w.CancellationPending)
                    {
                        e.Cancel = true;
                        return this;
                    }
                    IColourInfo least = ColourMap.GetLeastCommonColourInfo(true);
                    RemoveFromPalette(least);
                    UpdateColourMapFromImage();
                    w.ReportProgress(i * 100 / toRemove);
                }
                Console.WriteLine("ReduceColourDepth: final number of colours = " + ColourMap.Count);
            }
            else // This case we have no idea how many colours, we just want to fit the colour map.
            {
                Bitmap orig = mOutput;
                Bitmap b = new Bitmap(orig.Width, orig.Height, PixelFormat.Format24bppRgb);

                Console.WriteLine("ReduceColourDepth: initial nColours = " + ColourMap.Count);
                int i = 0;
                for (int x = 0; x < b.Width; x++)
                    for (int y = 0; y < b.Height; y++)
                    {
                        if (w.CancellationPending)
                        {
                            e.Cancel = true;
                            return this;
                        }
                        Color c = orig.GetPixel(x, y);
                        Color newC = ColourMap.GetNearestColour(c);
                        b.SetPixel(x, y, newC);
                        w.ReportProgress((i++) * 100 / (b.Width*b.Height));
                    }
                mOutput = b;
            }
            return this;
        }

Same methods

ImagingTool::ReduceColourDepth ( ) : void
ImagingTool::ReduceColourDepth ( IColourMap cmap ) : void
ImagingTool::ReduceColourDepth ( int maxColours ) : void

Usage Example

コード例 #1
0
        public void RecolourImage(bool startAgain)
        {
            this.Cursor = Cursors.WaitCursor;
            ImagingTool tool;

            if (mRecolouredImage == null || startAgain)
            {
                CreateNewColourMap();
                tool = new ImagingTool(mResizedImage, ColourMap);
                //tool.ReduceColourDepth();
                tool.ReduceColourDepth(ColourMap);
                mRecolouredImage = tool.OutputImage;
            }
            else
            {
                tool = new ImagingTool(mRecolouredImage, ColourMap);
                tool.ReduceColourDepth((int)maxColoursUpDown.Value);
                mRecolouredImage = tool.OutputImage;
            }
            //UpdateColourMap();
            this.Cursor = Cursors.Default;
            RedrawTab2Images();
        }
All Usage Examples Of CrossStitchCreator.ImagingTool::ReduceColourDepth