Exemple #1
0
            public Block(string Color, byte A, byte R, byte G, byte B)
            {
                this.Color = Color;

                this.A = A;
                this.R = R;
                this.G = G;
                this.B = B;

                this.ID = BlockID;
                BlockID++;

                CL = PixelArt.RGBtoLAB(R, G, B);
            }
Exemple #2
0
        private Bitmap ConvertColors(BackgroundWorker worker, DoWorkEventArgs e)
        {
            Blocks b1 = new Blocks();
            Bitmap OutputRecolored = new Bitmap(px1.OutImage.Width, px1.OutImage.Height);
            double minDelta = 1000, newDelta;

            PixelArt.CIELab TempCL;
            Blocks.Block    tempBlock = new Blocks.Block();
            Color           c1 = Color.Black;
            Color           c2 = Color.Transparent;
            int             PercentComplete = 0, ValueMaximum = px1.OutImage.Width * px1.OutImage.Height, n = 0, HighestPercentReached = 0;

            keyValuePairs.Clear();

            for (int y = 0; y < px1.OutImage.Height; y++)
            {
                for (int x = 0; x < px1.OutImage.Width; x++)
                {
                    if (worker.CancellationPending == true)
                    {
                        e.Cancel = true;
                        return(null);
                    }

                    if (px1.OutImage.GetPixel(x, y).ToArgb() == Color.Empty.ToArgb())
                    {
                        continue;
                    }
                    else if (c2 == px1.OutImage.GetPixel(x, y))
                    {
                        keyValuePairs[tempBlock]++;
                    }
                    else
                    {
                        TempCL = px1.RGBtoLAB(x, y);

                        if (checkBoxStandard.Checked)
                        {
                            foreach (Blocks.Block block in b1.Standard)
                            {
                                newDelta = px1.DeltaE(TempCL, block.CL);
                                if (newDelta < minDelta)
                                {
                                    minDelta  = newDelta;
                                    tempBlock = block;
                                }
                            }
                        }

                        if (checkBoxMetalic.Checked)
                        {
                            foreach (Blocks.Block block in b1.Metalic)
                            {
                                newDelta = px1.DeltaE(TempCL, block.CL);
                                if (newDelta < minDelta)
                                {
                                    minDelta  = newDelta;
                                    tempBlock = block;
                                }
                            }
                        }

                        if (checkBoxGlass.Checked)
                        {
                            foreach (Blocks.Block block in b1.Glass)
                            {
                                newDelta = px1.DeltaE(TempCL, block.CL);
                                if (newDelta < minDelta)
                                {
                                    minDelta  = newDelta;
                                    tempBlock = block;
                                }
                            }
                        }

                        if (checkBoxGlowing.Checked)
                        {
                            foreach (Blocks.Block block in b1.Glowing)
                            {
                                newDelta = px1.DeltaE(TempCL, block.CL);
                                if (newDelta < minDelta)
                                {
                                    minDelta  = newDelta;
                                    tempBlock = block;
                                }
                            }
                        }

                        if (checkBoxCustom.Checked)
                        {
                            foreach (Blocks.Block block in f3.Custom)
                            {
                                newDelta = px1.DeltaE(TempCL, block.CL);
                                if (newDelta < minDelta)
                                {
                                    minDelta  = newDelta;
                                    tempBlock = block;
                                }
                            }
                        }

                        if (!keyValuePairs.ContainsKey(tempBlock))
                        {
                            keyValuePairs.Add(tempBlock, 1);
                        }
                        else
                        {
                            keyValuePairs[tempBlock]++;
                        }

                        c1 = Color.FromArgb(tempBlock.A, tempBlock.R, tempBlock.G, tempBlock.B);
                        c2 = px1.OutImage.GetPixel(x, y);
                    }

                    OutputRecolored.SetPixel(x, y, c1);

                    minDelta = 1000;
                    n++;

                    DGVPixelArt[x, y] = tempBlock;

                    PercentComplete = (int)((float)n / (float)ValueMaximum * 100);
                    if (PercentComplete > HighestPercentReached)
                    {
                        HighestPercentReached = PercentComplete;
                        worker.ReportProgress(PercentComplete);
                    }
                }
            }

            return(OutputRecolored);
        }