ImfChromaticities.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. //
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. // Copyright (c) Contributors to the OpenEXR Project.
  4. //
  5. #ifndef INCLUDED_IMF_CHROMATICITIES_H
  6. #define INCLUDED_IMF_CHROMATICITIES_H
  7. //-----------------------------------------------------------------------------
  8. //
  9. // CIE (x,y) chromaticities, and conversions between
  10. // RGB tiples and CIE XYZ tristimulus values.
  11. //
  12. //-----------------------------------------------------------------------------
  13. #include "ImfExport.h"
  14. #include "ImfNamespace.h"
  15. #include "ImathMatrix.h"
  16. #include "ImathVec.h"
  17. OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
  18. struct IMF_EXPORT_TYPE Chromaticities
  19. {
  20. //-----------------------------------------------
  21. // The CIE x and y coordinates of the RGB triples
  22. // (1,0,0), (0,1,0), (0,0,1) and (1,1,1).
  23. //-----------------------------------------------
  24. IMATH_NAMESPACE::V2f red;
  25. IMATH_NAMESPACE::V2f green;
  26. IMATH_NAMESPACE::V2f blue;
  27. IMATH_NAMESPACE::V2f white;
  28. //--------------------------------------------
  29. // Default constructor produces chromaticities
  30. // according to Rec. ITU-R BT.709-3
  31. //--------------------------------------------
  32. IMF_EXPORT
  33. Chromaticities (const IMATH_NAMESPACE::V2f &red = IMATH_NAMESPACE::V2f (0.6400f, 0.3300f),
  34. const IMATH_NAMESPACE::V2f &green = IMATH_NAMESPACE::V2f (0.3000f, 0.6000f),
  35. const IMATH_NAMESPACE::V2f &blue = IMATH_NAMESPACE::V2f (0.1500f, 0.0600f),
  36. const IMATH_NAMESPACE::V2f &white = IMATH_NAMESPACE::V2f (0.3127f, 0.3290f));
  37. //---------
  38. // Equality
  39. //---------
  40. IMF_EXPORT
  41. bool operator == (const Chromaticities &v) const;
  42. IMF_EXPORT
  43. bool operator != (const Chromaticities &v) const;
  44. };
  45. //
  46. // Conversions between RGB and CIE XYZ
  47. //
  48. // RGB to XYZ:
  49. //
  50. // Given a set of chromaticities, c, and the luminance, Y, of the RGB
  51. // triple (1,1,1), or "white", RGBtoXYZ(c,Y) computes a matrix, M, so
  52. // that multiplying an RGB value, v, with M produces an equivalent
  53. // XYZ value, w. (w == v * M)
  54. //
  55. // If we define that
  56. //
  57. // (Xr, Yr, Zr) == (1, 0, 0) * M
  58. // (Xg, Yg, Zg) == (0, 1, 0) * M
  59. // (Xb, Yb, Zb) == (0, 0, 1) * M
  60. // (Xw, Yw, Zw) == (1, 1, 1) * M,
  61. //
  62. // then the following statements are true:
  63. //
  64. // Xr / (Xr + Yr + Zr) == c.red.x
  65. // Yr / (Xr + Yr + Zr) == c.red.y
  66. //
  67. // Xg / (Xg + Yg + Zg) == c.green.x
  68. // Yg / (Xg + Yg + Zg) == c.green.y
  69. //
  70. // Xb / (Xb + Yb + Zb) == c.blue.x
  71. // Yb / (Xb + Yb + Zb) == c.blue.y
  72. //
  73. // Xw / (Xw + Yw + Zw) == c.white.x
  74. // Yw / (Xw + Yw + Zw) == c.white.y
  75. //
  76. // Yw == Y.
  77. //
  78. // XYZ to RGB:
  79. //
  80. // XYZtoRGB(c,Y) returns RGBtoXYZ(c,Y).inverse().
  81. //
  82. IMF_EXPORT IMATH_NAMESPACE::M44f RGBtoXYZ (const Chromaticities &chroma, float Y);
  83. IMF_EXPORT IMATH_NAMESPACE::M44f XYZtoRGB (const Chromaticities &chroma, float Y);
  84. OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
  85. #endif