Ejemplo n.º 1
0
        private static Color[] ShiftHue(Color[] c, Color target, int count, bool zora, bool grad, bool fd)
        {
            Color[] s = new Color[count];
            Color   a;

            if (zora && !grad)
            {
                a = GetAverageColour(c, 16);
            }
            else
            {
                a = GetAverageColour(c, count);
            }
            float rot  = target.GetHue() - a.GetHue();
            float avgb = a.GetBrightness();
            float avgs = a.GetSaturation();

            for (int i = 0; i < count; i++)
            {
                if ((i == 12) && (count == 14))
                {
                    s[i] = c[i];
                    continue;
                }
                float h   = c[i].GetHue();
                float b   = c[i].GetBrightness();
                float sat = c[i].GetSaturation();
                b   -= avgb;
                sat -= avgs;
                b   += target.GetBrightness();
                sat += target.GetSaturation();
                h   += rot;
                if (fd)
                {
                    sat = target.GetSaturation();
                    h   = target.GetHue();
                }
                if (zora && grad)
                {
                    if (i > 351)
                    {
                        float x0 = c[352].GetBrightness();
                        float x1 = c[511].GetBrightness();
                        float x  = c[i].GetBrightness();
                        h   = target.GetHue();
                        sat = target.GetSaturation();
                        b   = Interpolate(target.GetBrightness(), c[511].GetBrightness(), x0, x1, x);
                    }
                }
                h %= 360f;
                if (h < 0f)
                {
                    h += 360f;
                }
                if (b < 0.0f)
                {
                    b = 0.0f;
                }
                if (b > 1.0f)
                {
                    b = 1.0f;
                }
                if (sat < 0.0f)
                {
                    sat = 0.0f;
                }
                if (sat > 1.0f)
                {
                    sat = 1.0f;
                }
                s[i] = ColorUtils.FromAHSB(c[i].A, h, sat, b);
                //this code is a mess
                if (zora && grad)
                {
                    if (i < 96)
                    {
                        s[i] = c[i];
                    }
                    else if (i < 352)
                    {
                        float x0 = c[95].GetBrightness();
                        float x1 = c[352].GetBrightness();
                        float x  = c[i].GetBrightness();
                        int   rr = (int)Interpolate(c[95].R, target.R, x0, x1, x);
                        int   gg = (int)Interpolate(c[95].G, target.G, x0, x1, x);
                        int   bb = (int)Interpolate(c[95].B, target.B, x0, x1, x);
                        if (rr < 0)
                        {
                            rr = 0;
                        }
                        if (rr > 255)
                        {
                            rr = 255;
                        }
                        if (gg < 0)
                        {
                            gg = 0;
                        }
                        if (gg > 255)
                        {
                            gg = 255;
                        }
                        if (bb < 0)
                        {
                            bb = 0;
                        }
                        if (bb > 255)
                        {
                            bb = 255;
                        }
                        s[i] = Color.FromArgb(rr, gg, bb);
                    }
                }
                else if (zora)
                {
                    if (i > 15)
                    {
                        float x0 = c[14].GetBrightness();
                        float x1 = c[31].GetBrightness();
                        float x  = c[i].GetBrightness();
                        int   rr = (int)Interpolate(s[14].R, c[31].R, x0, x1, x);
                        int   gg = (int)Interpolate(s[14].G, c[31].G, x0, x1, x);
                        int   bb = (int)Interpolate(s[14].B, c[31].B, x0, x1, x);
                        if (rr < 0)
                        {
                            rr = 0;
                        }
                        if (rr > 255)
                        {
                            rr = 255;
                        }
                        if (gg < 0)
                        {
                            gg = 0;
                        }
                        if (gg > 255)
                        {
                            gg = 255;
                        }
                        if (bb < 0)
                        {
                            bb = 0;
                        }
                        if (bb > 255)
                        {
                            bb = 255;
                        }
                        s[i] = Color.FromArgb(rr, gg, bb);
                    }
                }
            }
            return(s);
        }