Exemple #1
0
        static private void RefineMinMax(ARGB_Rev[] Colors, ref ARGB_Rev Min, ref ARGB_Rev Max)
        {
            int MinListCount = 0;
            int MaxListCount = 0;
            var MinAccum     = default(RGBA32);
            var MaxAccum     = default(RGBA32);

            foreach (var color in Colors)
            {
                int DistanceMin = ARGB_Rev.DistanceRGB(color, Min);
                int DistanceMax = ARGB_Rev.DistanceRGB(color, Max);

                if (DistanceMin <= DistanceMax)
                {
                    MinAccum += color;
                    MinListCount++;
                }

                if (DistanceMax <= DistanceMin)
                {
                    MaxAccum += color;
                    MaxListCount++;
                }
            }

            Min   = MinAccum / MinListCount;
            Max   = MaxAccum / MaxListCount;
            Min.A = 0xFF;
            Max.A = 0xFF;
        }
Exemple #2
0
        static public int ColorToIndexed(ARGB_Rev[] Colors, ARGB_Rev[] Palette, byte[] Indices)
        {
            int TotalDistance = 0;

            for (int n = 0; n < 16; n++)
            {
                var Color       = Colors[n];
                int MinDistance = int.MaxValue;
                int BestIndex   = 0;
                for (int m = 0; m < 4; m++)
                {
                    var Distance = ARGB_Rev.DistanceRGB(Color, Palette[m]);
                    if (Distance < MinDistance)
                    {
                        BestIndex   = m;
                        MinDistance = Distance;
                    }
                }
                TotalDistance += MinDistance;
                Indices[n]     = (byte)BestIndex;
            }
            return(TotalDistance);
        }