示例#1
0
        public RgbColor ToRgb(RgbType type = RgbType.Normalized)
        {
            RgbColor color;

            if (type == RgbType.Normalized)
            {
                color = this;
                switch (Type)
                {
                case RgbType.Percent:
                    color   = new RgbColor(type);
                    color.r = r / 100f;
                    color.g = g / 100f;
                    color.b = b / 100f;
                    break;

                case RgbType.Byte:
                    color   = new RgbColor(type);
                    color.r = r / 255f;
                    color.g = g / 255f;
                    color.b = b / 255f;
                    break;
                }
            }
            else
            {
                if (Type == RgbType.Normalized)
                {
                    color = this;
                    switch (type)
                    {
                    case RgbType.Byte:
                        color   = new RgbColor(type);
                        color.r = (int)(r * 255);
                        color.g = (int)(g * 255);
                        color.b = (int)(b * 255);
                        break;

                    case RgbType.Percent:
                        color   = new RgbColor(type);
                        color.r = r * 100f;
                        color.g = g * 100f;
                        color.b = b * 100f;
                        break;
                    }
                }
                else
                {
                    color = ToRgb().ToRgb(type);
                }
            }
            return(color);
        }
示例#2
0
        public RgbColor ToRgb(RgbType type = RgbType.Normalized)
        {
            float[] colors    = { x, y, z };
            var     converted = new RgbColor();

            for (int i = 0; i < 3; i++)
            {
                converted.R += rgbmatconv[0, i] * colors[i];
                converted.G += rgbmatconv[1, i] * colors[i];
                converted.B += rgbmatconv[2, i] * colors[i];
            }
            return(converted.ToRgb(type));
        }
示例#3
0
        public RgbColor ToRgb(RgbType type = RgbType.Normalized)
        {
            float[] colors    = { y, i, q };
            var     converted = new RgbColor();

            for (int j = 0; j < 3; j++)
            {
                converted.R += rgbmatconv[0, j] * colors[j];
                converted.G += rgbmatconv[1, j] * colors[j];
                converted.B += rgbmatconv[2, j] * colors[j];
            }
            return(converted.ToRgb(type));
        }
示例#4
0
        public RgbColor ToRgb(RgbType type = RgbType.Normalized)
        {
            float    hh, p, q, t, ff;
            long     i;
            RgbColor res = new RgbColor();

            if (this.s <= 0.0)
            {       // < is bogus, just shuts up warnthisgs
                res.R = this.v;
                res.G = this.v;
                res.B = this.v;
                return(res);
            }
            hh = this.h;
            if (hh >= 360.0)
            {
                hh = 0.0F;
            }
            hh /= 60.0F;
            i   = (long)hh;
            ff  = hh - i;
            p   = this.v * (1.0F - this.s);
            q   = this.v * (1.0F - (this.s * ff));
            t   = this.v * (1.0F - (this.s * (1.0F - ff)));

            switch (i)
            {
            case 0:
                res.R = this.v;
                res.G = t;
                res.B = p;
                break;

            case 1:
                res.R = q;
                res.G = this.v;
                res.B = p;
                break;

            case 2:
                res.R = p;
                res.G = this.v;
                res.B = t;
                break;

            case 3:
                res.R = p;
                res.G = q;
                res.B = this.v;
                break;

            case 4:
                res.R = t;
                res.G = p;
                res.B = this.v;
                break;

            case 5:
            default:
                res.R = this.v;
                res.G = p;
                res.B = q;
                break;
            }
            return(res.ToRgb(type));
        }