コード例 #1
0
        public List <Color32> GetColors(int numColors)
        {
            while (buckets.Count < numColors)
            {
                buckets.Sort((ColorBucket x, ColorBucket y) => (int)Mathf.Sign(y.BiggestVariance - x.BiggestVariance));
                ColorBucket bucket = buckets[0];
                buckets.RemoveAt(0);
                List <ColorBucket> splitResult = bucket.MedianCut();
                buckets.AddRange(splitResult);

                if (splitResult.Count < 2)
                {
                    break;
                }
            }

            List <Color32> colors = new List <Color32>();

            foreach (ColorBucket bucket in buckets)
            {
                colors.Add(bucket.averageColor);
            }

            // Sort by approx luminance (grayscale value)
            colors.Sort((Color32 x, Color32 y) => (int)Mathf.Sign(((Color)x).grayscale - ((Color)y).grayscale));

            return(colors);
        }
コード例 #2
0
        public PaletteTree(ColorBucket bucket, int level, int maxLevels)
        {
            this.bucket = bucket;
            this.level  = level;

            if (level < maxLevels)
            {
                children = new List <PaletteTree>();
                List <ColorBucket> childBuckets = bucket.MedianCut();

                foreach (ColorBucket child in childBuckets)
                {
                    children.Add(new PaletteTree(child, level + 1, maxLevels));
                }
            }
        }
コード例 #3
0
        public PaletteExtractor(Texture2D texture)
        {
            ColorBucket bucket = new ColorBucket(texture.GetPixels32());

            buckets.Add(bucket);
        }
コード例 #4
0
        public PaletteExtractor(Texture2D texture)
        {
            ColorBucket bucket = new ColorBucket(texture.GetPixels32());

            paletteTree = new PaletteTree(bucket, 0, 8);
        }