color_encoding.inl 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /// @ref gtx_color_encoding
  2. namespace glm
  3. {
  4. template<typename T, qualifier Q>
  5. GLM_FUNC_QUALIFIER vec<3, T, Q> convertLinearSRGBToD65XYZ(vec<3, T, Q> const& ColorLinearSRGB)
  6. {
  7. vec<3, T, Q> const M(0.490f, 0.17697f, 0.2f);
  8. vec<3, T, Q> const N(0.31f, 0.8124f, 0.01063f);
  9. vec<3, T, Q> const O(0.490f, 0.01f, 0.99f);
  10. return (M * ColorLinearSRGB + N * ColorLinearSRGB + O * ColorLinearSRGB) * static_cast<T>(5.650675255693055f);
  11. }
  12. template<typename T, qualifier Q>
  13. GLM_FUNC_QUALIFIER vec<3, T, Q> convertLinearSRGBToD50XYZ(vec<3, T, Q> const& ColorLinearSRGB)
  14. {
  15. vec<3, T, Q> const M(0.436030342570117f, 0.222438466210245f, 0.013897440074263f);
  16. vec<3, T, Q> const N(0.385101860087134f, 0.716942745571917f, 0.097076381494207f);
  17. vec<3, T, Q> const O(0.143067806654203f, 0.060618777416563f, 0.713926257896652f);
  18. return M * ColorLinearSRGB + N * ColorLinearSRGB + O * ColorLinearSRGB;
  19. }
  20. template<typename T, qualifier Q>
  21. GLM_FUNC_QUALIFIER vec<3, T, Q> convertD65XYZToLinearSRGB(vec<3, T, Q> const& ColorD65XYZ)
  22. {
  23. vec<3, T, Q> const M(0.41847f, -0.091169f, 0.0009209f);
  24. vec<3, T, Q> const N(-0.15866f, 0.25243f, 0.015708f);
  25. vec<3, T, Q> const O(0.0009209f, -0.0025498f, 0.1786f);
  26. return M * ColorD65XYZ + N * ColorD65XYZ + O * ColorD65XYZ;
  27. }
  28. template<typename T, qualifier Q>
  29. GLM_FUNC_QUALIFIER vec<3, T, Q> convertD65XYZToD50XYZ(vec<3, T, Q> const& ColorD65XYZ)
  30. {
  31. vec<3, T, Q> const M(+1.047844353856414f, +0.029549007606644f, -0.009250984365223f);
  32. vec<3, T, Q> const N(+0.022898981050086f, +0.990508028941971f, +0.015072338237051f);
  33. vec<3, T, Q> const O(-0.050206647741605f, -0.017074711360960f, +0.751717835079977f);
  34. return M * ColorD65XYZ + N * ColorD65XYZ + O * ColorD65XYZ;
  35. }
  36. }//namespace glm