/* * Copyright (C) 2021 Christopher J. Howard * * This file is part of Antkeeper source code. * * Antkeeper source code is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Antkeeper source code is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Antkeeper source code. If not, see . */ #ifndef ANTKEEPER_COLOR_CCT_HPP #define ANTKEEPER_COLOR_CCT_HPP #include "math/math.hpp" #include "ucs.hpp" #include "xyy.hpp" namespace color { /// Functions which operate on correlated color temperature (CCT). namespace cct { /** * Calculates CIE 1960 UCS colorspace chromaticity coordinates given a correlated color temperature using Krystek's algorithm. * * @param t Correlated color temperature, in Kelvin. * @return CIE 1960 UCS colorspace chromaticity coordinates. * * @see Krystek, M. (1985), An algorithm to calculate correlated colour temperature. Color Res. Appl., 10: 38-40. */ template math::vector2 to_ucs(T t); /** * Calculates CIE xyY colorspace chromaticity coordinates given a correlated color temperature using Krystek's algorithm. * * @param t Correlated color temperature, in Kelvin. * @return CIE xyY color with `Y = 1`. */ template math::vector3 to_xyy(T t); /** * Calculates CIE XYZ colorspace chromaticity coordinates given a correlated color temperature using Krystek's algorithm. * * @param t Correlated color temperature, in Kelvin. * @return CIE XYZ color with `Y = 1`. */ template math::vector3 to_xyz(T t); template math::vector2 to_ucs(T t) { // Approximate the Planckian locus in CIE 1960 UCS colorspace (Krystek's algorithm) const T tt = t * t; return math::vector2 { (T(0.860117757) + T(1.54118254e-4) * t + T(1.28641212e-7) * tt) / (T(1.0) + T(8.42420235e-4) * t + T(7.08145163e-7) * tt), (T(0.317398726) + T(4.22806245e-5) * t + T(4.20481691e-8) * tt) / (T(1.0) - T(2.89741816e-5) * t + T(1.61456053e-7) * tt) }; } template math::vector3 to_xyy(T t) { return ucs::to_xyy(to_ucs(t), T(1.0)); } template math::vector3 to_xyz(T t) { return xyy::to_xyz(to_xyy(t)); } } // namespace cct } // namespace color #endif // ANTKEEPER_COLOR_CCT_HPP