Ejemplo n.º 1
0
        private static ColorResult ConvertCMYK(ColorSpace resultSpace, ColorSource source)
        {
            ColorResult color;

            double c = source.component0;
            double m = source.component1;
            double y = source.component2;
            double k = source.component3;

            switch (resultSpace)
            {
            case ColorSpace.RGBSpace:
                RGB rgb = ColorConverter.CMYKtoRGB(c, m, y, k);
                color = new ColorResult(rgb.Red, rgb.Green, rgb.Blue);
                break;

            case ColorSpace.HSBSpace:
                HSB hsb = ColorConverter.CMYKtoHSB(c, m, y, k);
                color = new ColorResult(hsb.Hue, hsb.Saturation, hsb.Brightness);
                break;

            case ColorSpace.HSLSpace:
                HSL hsl = ColorConverter.CMYKtoHSL(c, m, y, k);
                color = new ColorResult(hsl.Hue, hsl.Saturation, hsl.Luminance);
                break;

            case ColorSpace.LabSpace:
                Lab lab = ColorConverter.CMYKtoLab(c, m, y, k);
                color = ScaleCIELabOutputRange(lab);
                break;

            case ColorSpace.XYZSpace:
                XYZ xyz = ColorConverter.CMYKtoXYZ(c, m, y, k);
                color = new ColorResult(xyz.X, xyz.Y, xyz.Z);
                break;

            case ColorSpace.GraySpace:
                color = new ColorResult(ColorConverter.CMYKtoRGB(c, m, y, k).GetIntensity(source.maxChannelValue));
                break;

            default:
                throw new InvalidEnumArgumentException("Unsupported color space conversion", (int)resultSpace, typeof(ColorSpace));
            }

            return(color);
        }