コード例 #1
0
ファイル: Lab.cs プロジェクト: jonathanruisi/Utility.NET
        protected override void FromRgb(Rgb color)
        {
            var xyz = color.ToColorSpace <Xyz>();
            var x   = xyz.X / Xyz.WhiteReference[0];
            var y   = xyz.Y / Xyz.WhiteReference[1];
            var z   = xyz.Z / Xyz.WhiteReference[2];

            x = x > Xyz.Epsilon ? CubicRoot(x) : (Xyz.Kappa * x + 16) / 116;
            y = y > Xyz.Epsilon ? CubicRoot(y) : (Xyz.Kappa * y + 16) / 116;
            z = z > Xyz.Epsilon ? CubicRoot(z) : (Xyz.Kappa * z + 16) / 116;

            L = System.Math.Max(0, 116 * y - 16);
            A = 500 * (x - y);
            B = 200 * (y - z);
        }
コード例 #2
0
        protected override void FromRgb(Rgb color)
        {
            var r = color.R / 255.0;
            var g = color.G / 255.0;
            var b = color.B / 255.0;

            r = (r > 0.04045 ? System.Math.Pow((r + 0.055) / 1.055, 2.4) : r / 12.92) * 100.0;
            g = (g > 0.04045 ? System.Math.Pow((g + 0.055) / 1.055, 2.4) : g / 12.92) * 100.0;
            b = (b > 0.04045 ? System.Math.Pow((b + 0.055) / 1.055, 2.4) : b / 12.92) * 100.0;

            // TODO: Hard-coded to use sRGB. Update to allow multiple working spaces
            X = r * RgbXyzMatrix.SRgb[0, 0] + g * RgbXyzMatrix.SRgb[0, 1] + b * RgbXyzMatrix.SRgb[0, 2];
            Y = r * RgbXyzMatrix.SRgb[1, 0] + g * RgbXyzMatrix.SRgb[1, 1] + b * RgbXyzMatrix.SRgb[1, 2];
            Z = r * RgbXyzMatrix.SRgb[2, 0] + g * RgbXyzMatrix.SRgb[2, 1] + b * RgbXyzMatrix.SRgb[2, 2];
        }
コード例 #3
0
        protected override void FromRgb(Rgb color)
        {
            var xyz = color.ToColorSpace <Xyz>();
            var y   = xyz.Y / Xyz.WhiteReference[1];

            L = y > Xyz.Epsilon ? 116.0 * System.Math.Pow(y, 1.0 / 3.0) - 16.0 : Xyz.Kappa * y;

            var targetDenominator    = xyz.X + 15.0 * xyz.Y + 3.0 * xyz.Z;
            var referenceDenominator = Xyz.WhiteReference[0] + 15.0 * Xyz.WhiteReference[1] + 3.0 * Xyz.WhiteReference[2];
            var xTarget = targetDenominator.Equals(0)
                                ? 0
                                : 4.0 * xyz.X / targetDenominator - 4.0 * Xyz.WhiteReference[0] / referenceDenominator;
            var yTarget = targetDenominator.Equals(0)
                                ? 0
                                : 9.0 * xyz.Y / targetDenominator - 9.0 * Xyz.WhiteReference[1] / referenceDenominator;

            U = 13.0 * L * xTarget;
            V = 13.0 * L * yTarget;
        }
コード例 #4
0
ファイル: Yxy.cs プロジェクト: jonathanruisi/Utility.NET
 public Yxy(Rgb color)
 {
     FromRgb(color);
 }
コード例 #5
0
 public Luv(Rgb color)
 {
     FromRgb(color);
 }
コード例 #6
0
 public Cmy(Rgb color)
 {
     FromRgb(color);
 }
コード例 #7
0
 protected override void FromRgb(Rgb color)
 {
     C = 1 - color.R / 255.0;
     M = 1 - color.G / 255.0;
     Y = 1 - color.B / 255.0;
 }
コード例 #8
0
 public HunterLab(Rgb color)
 {
     FromRgb(color);
 }
コード例 #9
0
 public Hsv(Rgb color)
 {
     FromRgb(color);
 }
コード例 #10
0
        public static ColorSpace FromXElement(XElement element)
        {
            if (element.Name != "ColorSpace")
            {
                throw new XmlException("XElement name must be \"ColorSpace\"");
            }

            switch (element.Attribute("Type").Value)
            {
            case "CMY":
            {
                var result = new Cmy();
                result.FromXNode(element);
                return(result);
            }

            case "CMYK":
            {
                var result = new Cmyk();
                result.FromXNode(element);
                return(result);
            }

            case "HSL":
            {
                var result = new Hsl();
                result.FromXNode(element);
                return(result);
            }

            case "HSV":
            {
                var result = new Hsv();
                result.FromXNode(element);
                return(result);
            }

            case "HunterLAB":
            {
                var result = new HunterLab();
                result.FromXNode(element);
                return(result);
            }

            case "LAB":
            {
                var result = new Lab();
                result.FromXNode(element);
                return(result);
            }

            case "LCH":
            {
                var result = new Lch();
                result.FromXNode(element);
                return(result);
            }

            case "LUV":
            {
                var result = new Luv();
                result.FromXNode(element);
                return(result);
            }

            case "RGB":
            {
                var result = new Rgb();
                result.FromXNode(element);
                return(result);
            }

            case "RGBA":
            {
                var result = new Rgba();
                result.FromXNode(element);
                return(result);
            }

            case "XYZ":
            {
                var result = new Xyz();
                result.FromXNode(element);
                return(result);
            }

            case "YXY":
            {
                var result = new Yxy();
                result.FromXNode(element);
                return(result);
            }

            default:
                throw new ArgumentException("Unrecognized ColorSpace type");
            }
        }
コード例 #11
0
 protected abstract void FromRgb(Rgb color);
コード例 #12
0
ファイル: Lch.cs プロジェクト: jonathanruisi/Utility.NET
 public Lch(Rgb color)
 {
     FromRgb(color);
 }
コード例 #13
0
ファイル: Lab.cs プロジェクト: jonathanruisi/Utility.NET
 public Lab(Rgb color)
 {
     FromRgb(color);
 }
コード例 #14
0
 protected override void FromRgb(Rgb color)
 {
     R = color.R;
     G = color.G;
     B = color.B;
 }