Esempio n. 1
0
        public static byte findACPaletteIndexMostLike(Color c)
        {
            if (ACPaletteColors == null)
            {
                populateACPaletteColors();
            }

            byte targInd = 0;

            double championDistance = double.MaxValue;

            for (byte i = 0; i < ACPaletteColors.Count; i++)
            {
                double dist = RGBOctree.EuclideanRGB(c, ACPaletteColors[i]);
                if (dist < championDistance)
                {
                    championDistance = dist;
                    targInd          = i;
                }
            }

            return(targInd);
        }
Esempio n. 2
0
        public static NewLeafBitmap NLBfromBitmap(Bitmap src)
        {
            NewLeafBitmap tortimer = new NewLeafBitmap();

            double wid = 32; double hig = 32;
            Bitmap scaled = new Bitmap((int)wid, (int)hig);

            using (Graphics graphics = Graphics.FromImage(scaled))
            {
                graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;

                graphics.DrawImage(src, new Rectangle(0, 0, scaled.Width, scaled.Height));
            }

            RGBOctree tree = new RGBOctree((Bitmap)scaled, 15);

            //  MessageBox.Show("Reduced to " + tree.lastQuantizedPalette.Count + "  colors.");

            tree.QuantizeOnLastPalette((Bitmap)scaled);

            byte i = 0;

            tortimer.filepal = new byte[15];

            for (byte o = 0; o < tree.lastQuantizedPalette.Count; o++)
            {
                Color me = tree.lastQuantizedPalette[o].color;

                Button newb = new Button();

                newb.Left  = 20 * o;
                newb.Top   = 20;
                newb.Width = 15;

                newb.BackColor = me;
                Form1.grp.Controls.Add(newb);
            }

            foreach (RGBOctree.RGBOctreeNode rgbon in tree.lastQuantizedPalette)
            {
                byte mostlike = findACPaletteIndexMostLike(rgbon.color);
                tortimer.filepal[transtosilly(i)] = mostlike;

                // MessageBox.Show("Color " + rgbon.color.ToArgb() + " is most like " + tortimer.filepal[transtosilly(i)]);


                for (int j = 0; j < 32; j++)
                {
                    for (int k = 0; k < 32; k++)
                    {
                        if (scaled.GetPixel(j, k) == rgbon.color)
                        {
                            tortimer.falseColor.SetPixel(j, k, Color.FromArgb(i));
                        }
                    }
                }

                i++;
            }


            return(tortimer);
        }