示例#1
0
        private static (List <System.Drawing.Color> colors, Dictionary <System.Drawing.Color, int> lookup) MedianCut(List <System.Drawing.Color> allColors, int stages)
        {
            MedianCutNode        node           = MedianCutInternal(allColors, stages);
            List <List <Color> > bucketedColors = new List <List <Color> >();

            node.GetColors(bucketedColors);

            List <System.Drawing.Color> colors = new List <System.Drawing.Color>();

            foreach (List <Color> cs in bucketedColors)
            {
                colors.Add(cs[0]);                 // TODO: use average instead
            }

            Dictionary <System.Drawing.Color, int> colorLookupTable = new Dictionary <System.Drawing.Color, int>();

            for (int ci = 0; ci < bucketedColors.Count; ++ci)
            {
                foreach (Color c in bucketedColors[ci])
                {
                    colorLookupTable.Add(c, ci);
                }
            }

            return(colors, colorLookupTable);
        }
示例#2
0
 public void GetColors(List <List <Color> > colors)
 {
     if (LeftChild != null)
     {
         LeftChild.GetColors(colors);
     }
     if (RightChild != null)
     {
         RightChild.GetColors(colors);
     }
     if (LeftColors != null && LeftColors.Count > 0)
     {
         colors.Add(LeftColors);
     }
     if (RightColors != null && RightColors.Count > 0)
     {
         colors.Add(RightColors);
     }
 }