Example #1
0
        /// <inheritdoc/>
        public override void FromColor(Color color)
        {
            var cieXyz = new CieXyz();

            cieXyz.FromColor(color);
            var y = CieLab.PivotXyz(cieXyz.Y / CieXyz.WhiteReference.Y);

            this.L = Math.Max(0, 116 * y - 16);
            this.a = 500 * (CieLab.PivotXyz(cieXyz.X / CieXyz.WhiteReference.X) - y);
            this.b = 200 * (y - CieLab.PivotXyz(cieXyz.Z / CieXyz.WhiteReference.Z));
        }
Example #2
0
        /// <inheritdoc/>
        public override void FromColor(Color color)
        {
            var cieXyz = new CieXyz();

            cieXyz.FromColor(color);
            var white = CieXyz.WhiteReference;
            var y     = cieXyz.Y / CieXyz.WhiteReference.Y;

            this.L = y > CieXyz.T0 ? 116 * Math.Pow(y, 1d / 3) - 16 : CieLuv.Kappa *y;
            var targetDenominator    = CieLuv.GetDenominator(cieXyz);
            var referenceDenominator = CieLuv.WhiteDenominator;
            // ReSharper disable CompareOfFloatsByEqualityOperator
            var xTarget = targetDenominator == 0 ? 0 : 4 * cieXyz.X / targetDenominator - 4 * white.X / referenceDenominator;
            var yTarget = targetDenominator == 0 ? 0 : 9 * cieXyz.Y / targetDenominator - 9 * white.Y / referenceDenominator;

            // ReSharper restore CompareOfFloatsByEqualityOperator
            this.u = 13 * this.L * xTarget;
            this.v = 13 * this.L * yTarget;
        }