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