Beispiel #1
0
        /// <summary>
        /// See <see cref="BaseColorCache.OnGetColorPaletteIndex"/> for more details.
        /// </summary>
        protected override void OnGetColorPaletteIndex(Color color, out Int32 paletteIndex)
        {
            BucketInfo bucket     = GetBucket(color);
            Int32      colorCount = bucket.Colors.Count();

            paletteIndex = 0;

            if (colorCount == 1)
            {
                paletteIndex = bucket.Colors.First().Key;
            }
            else
            {
                Int32 index      = 0;
                Int32 colorIndex = ColorModelHelper.GetEuclideanDistance(color, ColorModel, bucket.Colors.Values.ToList());

                foreach (Int32 colorPaletteIndex in bucket.Colors.Keys)
                {
                    if (index == colorIndex)
                    {
                        paletteIndex = colorPaletteIndex;
                        break;
                    }

                    index++;
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// See <see cref="BaseColorCache.OnCachePalette"/> for more details.
        /// </summary>
        protected override void OnCachePalette(IList <Color> palette)
        {
            Int32 paletteIndex = 0;

            minBucketIndex = quality;
            maxBucketIndex = 0;

            foreach (Color color in palette)
            {
                Int64      bucketIndex = GetColorBucketIndex(color);
                BucketInfo bucket      = buckets[bucketIndex] ?? new BucketInfo();
                bucket.AddColor(paletteIndex++, color);
                buckets[bucketIndex] = bucket;

                if (bucketIndex < minBucketIndex)
                {
                    minBucketIndex = bucketIndex;
                }
                if (bucketIndex > maxBucketIndex)
                {
                    maxBucketIndex = bucketIndex;
                }
            }
        }