Exemplo n.º 1
0
        public int getClosestColorWithAlpha(Color c, Color[] pal)
        {
            int   bestInd = 0;
            float bestDif = ImageIndexer.colorDifference(pal[0], c);

            for (int i = 0; i < pal.Length; i++)
            {
                float d = ImageIndexer.colorDifference(pal[i], c);
                if (d < bestDif)
                {
                    bestDif = d;
                    bestInd = i;
                }
            }

            return(bestInd);
        }
Exemplo n.º 2
0
        public float palDifUni(Color[] a, Color[] b)
        {
            bool aTransp = a[3] == Color.Transparent;
            bool bTransp = b[3] == Color.Transparent;

            if (aTransp != bTransp)
            {
                return(float.PositiveInfinity);
            }

            float dif = 0;
            int   len = aTransp ? 3 : 4;

            bool[] sel = new bool[len];

            for (int i = 0; i < len; i++)
            {
                Color c    = a[i];
                float diff = float.PositiveInfinity;
                int   i2   = -1;
                for (int j = 0; j < len; j++)
                {
                    if (sel[j])
                    {
                        continue;
                    }
                    float diff2 = ImageIndexer.colorDifference(c, b[j]);
                    if (diff2 < diff || i2 == -1)
                    {
                        i2   = j;
                        diff = diff2;
                    }
                }
                sel[i2] = true;
                dif    += diff;
            }

            return(dif);
        }