💿🐜 Antkeeper source code https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.3 KiB

  1. /*
  2. * Copyright (C) 2021 Christopher J. Howard
  3. *
  4. * This file is part of Antkeeper source code.
  5. *
  6. * Antkeeper source code is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Antkeeper source code is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef ANTKEEPER_COLOR_XYZ_HPP
  20. #define ANTKEEPER_COLOR_XYZ_HPP
  21. #include "math/math.hpp"
  22. namespace color {
  23. /// Functions which operate in the CIE XYZ colorspace.
  24. namespace xyz {
  25. /**
  26. * Returns the luminance of a CIE XYZ color.
  27. *
  28. * @param x CIE XYZ color.
  29. * @return return Luminance of @p x.
  30. */
  31. template <class T>
  32. T luminance(const math::vector3<T>& x);
  33. /**
  34. * Transforms a CIE XYZ color into the ACEScg colorspace.
  35. *
  36. * @param x CIE XYZ color.
  37. * @return ACEScg color.
  38. */
  39. template <class T>
  40. math::vector3<T> to_acescg(const math::vector3<T>& x);
  41. /**
  42. * Transforms a CIE XYZ color into the linear sRGB colorspace.
  43. *
  44. * @param x CIE XYZ color.
  45. * @return Linear sRGB color.
  46. */
  47. template <class T>
  48. math::vector3<T> to_srgb(const math::vector3<T>& x);
  49. template <class T>
  50. inline T luminance(const math::vector3<T>& x)
  51. {
  52. return x[1];
  53. }
  54. template <class T>
  55. math::vector3<T> to_acescg(const math::vector3<T>& x)
  56. {
  57. static const math::matrix3<T> xyz_to_acescg
  58. {{
  59. { 1.641023379694326 -0.663662858722983 0.011721894328375},
  60. {-0.324803294184790 1.615331591657338 -0.008284441996237},
  61. {-0.236424695237612, 0.016756347685530, 0.988394858539022}
  62. }};
  63. return xyz_to_acescg * x;
  64. }
  65. template <class T>
  66. math::vector3<T> to_srgb(const math::vector3<T>& x)
  67. {
  68. static const math::matrix3<T> xyz_to_srgb
  69. {{
  70. { 3.240969941904523, -0.969243636280880, 0.055630079696994},
  71. {-1.537383177570094, 1.875967501507721, -0.203976958888977},
  72. {-0.498610760293003, 0.041555057407176, 1.056971514242879}
  73. }};
  74. return xyz_to_srgb * x;
  75. }
  76. } // namespace xyz
  77. } // namespace color
  78. #endif // ANTKEEPER_COLOR_XYZ_HPP