Ejemplo n.º 1
0
        private static void GetMinMaxChroma(
            float c1, float c2, float c3,
            out float min, out float max, out float chroma, out Color3MaxComponents maxComponent)
        {
            min    = MathUtils.Min(c1, c2, c3);
            max    = MathUtils.Max(c1, c2, c3);
            chroma = max - min;

            if (chroma == 0)
            {
                maxComponent = Color3MaxComponents.Achromatic;
            }
            else if (max == c1)
            {
                maxComponent = Color3MaxComponents.c1;
            }
            else if (max == c2)
            {
                maxComponent = Color3MaxComponents.c2;
            }
            else
            {
                maxComponent = Color3MaxComponents.c3;
            }
        }
Ejemplo n.º 2
0
        private static float CalculateHue(float c1, float c2, float c3, float chroma, Color3MaxComponents maxComponent)
        {
            var chroma6 = chroma * 6.0f;

            switch (maxComponent)
            {
            case Color3MaxComponents.c1:
                return((c2 - c3) / chroma6 + (c2 < c3 ? 1 : 0));

            case Color3MaxComponents.c2:
                return((c3 - c1) / chroma6 + (1.0f / 3.0f));

            case Color3MaxComponents.c3:
                return((c1 - c2) / chroma6 + (2.0f / 3.0f));

            default:
                throw new InternalException("Invalid color component");
            }
        }