/// <summary>
        /// Converts a <see cref="CieXyz"/> into a <see cref="CieLab"/>
        /// </summary>
        /// <param name="color">The color to convert.</param>
        /// <returns>The <see cref="CieLab"/></returns>
        public CieLab ToCieLab(CieXyz color)
        {
            // Adaptation
            CieXyz adapted = !this.WhitePoint.Equals(this.TargetLabWhitePoint) && this.IsChromaticAdaptationPerformed
                ? this.ChromaticAdaptation.Transform(color, this.WhitePoint, this.TargetLabWhitePoint)
                : color;

            // Conversion
            var converter = new CieXyzToCieLabConverter(this.TargetLabWhitePoint);

            return(converter.Convert(adapted));
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ColorSpaceConverter"/> class.
        /// </summary>
        /// <param name="options">The configuration options.</param>
        public ColorSpaceConverter(ColorSpaceConverterOptions options)
        {
            Guard.NotNull(options, nameof(options));
            this.whitePoint                 = options.WhitePoint;
            this.targetLuvWhitePoint        = options.TargetLuvWhitePoint;
            this.targetLabWhitePoint        = options.TargetLabWhitePoint;
            this.targetHunterLabWhitePoint  = options.TargetHunterLabWhitePoint;
            this.targetRgbWorkingSpace      = options.TargetRgbWorkingSpace;
            this.chromaticAdaptation        = options.ChromaticAdaptation;
            this.performChromaticAdaptation = this.chromaticAdaptation != null;
            this.lmsAdaptationMatrix        = options.LmsAdaptationMatrix;

            this.cieXyzAndLmsConverter      = new CieXyzAndLmsConverter(this.lmsAdaptationMatrix);
            this.cieXyzToCieLabConverter    = new CieXyzToCieLabConverter(this.targetLabWhitePoint);
            this.cieXyzToCieLuvConverter    = new CieXyzToCieLuvConverter(this.targetLuvWhitePoint);
            this.cieXyzToHunterLabConverter = new CieXyzToHunterLabConverter(this.targetHunterLabWhitePoint);
            this.cieXyzToLinearRgbConverter = new CieXyzToLinearRgbConverter(this.targetRgbWorkingSpace);
        }