💿🐜 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.4 KiB

  1. /*
  2. * Copyright (C) 2023 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_ACES_HPP
  20. #define ANTKEEPER_COLOR_ACES_HPP
  21. #include "color/rgb.hpp"
  22. #include "math/matrix.hpp"
  23. #include "math/vector.hpp"
  24. namespace color {
  25. /// ACES color spaces.
  26. namespace aces {
  27. /// CIE xy chromaticity coordinates of the ACES white point (~D60).
  28. template <class T>
  29. constexpr math::vector2<T> white_point = {T{0.32168}, T{0.33767}};
  30. /// ACES AP0 color space.
  31. template <class T>
  32. constexpr rgb::color_space<T> ap0
  33. (
  34. {T{0.7347}, T{ 0.2653}},
  35. {T{0.0000}, T{ 1.0000}},
  36. {T{0.0001}, T{-0.0770}},
  37. aces::white_point<T>,
  38. nullptr,
  39. nullptr
  40. );
  41. /// ACES AP1 color space.
  42. template <class T>
  43. constexpr rgb::color_space<T> ap1
  44. (
  45. {T{0.713}, T{0.293}},
  46. {T{0.165}, T{0.830}},
  47. {T{0.128}, T{0.044}},
  48. aces::white_point<T>,
  49. nullptr,
  50. nullptr
  51. );
  52. /**
  53. * Constructs a saturation adjustment matrix.
  54. *
  55. * @param s Saturation adjustment factor.
  56. * @param to_y Color space to CIE XYZ luminance vector.
  57. *
  58. * @return Saturation adjustment matrix.
  59. */
  60. template <class T>
  61. constexpr math::matrix<T, 3, 3> adjust_saturation(T s, const math::vector3<T>& to_y)
  62. {
  63. const math::vector3<T> v = to_y * (T{1} - s);
  64. return math::matrix<T, 3, 3>
  65. {
  66. v[0] + s, v[0], v[0],
  67. v[1], v[1] + s, v[1],
  68. v[2], v[2], v[2] + s
  69. };
  70. }
  71. /// ACES AP1 RRT saturation adjustment matrix.
  72. template <class T>
  73. constexpr math::matrix<T, 3, 3> ap1_rrt_sat = aces::adjust_saturation(T{0.96}, ap1<T>.to_y);
  74. /// ACES AP1 ODT saturation adjustment matrix.
  75. template <class T>
  76. constexpr math::matrix<T, 3, 3> ap1_odt_sat = aces::adjust_saturation(T{0.93}, ap1<T>.to_y);
  77. } // namespace aces
  78. } // namespace color
  79. #endif // ANTKEEPER_COLOR_ACES_HPP