ColorSpaces.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { LinearTransfer, Matrix3, SRGBTransfer } from 'three';
  2. // Reference: http://www.russellcottrell.com/photo/matrixCalculator.htm
  3. const P3_PRIMARIES = [ 0.680, 0.320, 0.265, 0.690, 0.150, 0.060 ];
  4. const P3_LUMINANCE_COEFFICIENTS = [ 0.2289, 0.6917, 0.0793 ];
  5. const REC2020_PRIMARIES = [ 0.708, 0.292, 0.170, 0.797, 0.131, 0.046 ];
  6. const REC2020_LUMINANCE_COEFFICIENTS = [ 0.2627, 0.6780, 0.0593 ];
  7. const D65 = [ 0.3127, 0.3290 ];
  8. /******************************************************************************
  9. * Display P3 definitions
  10. */
  11. const LINEAR_DISPLAY_P3_TO_XYZ = /*@__PURE__*/ new Matrix3().set(
  12. 0.4865709, 0.2656677, 0.1982173,
  13. 0.2289746, 0.6917385, 0.0792869,
  14. 0.0000000, 0.0451134, 1.0439444
  15. );
  16. const XYZ_TO_LINEAR_DISPLAY_P3 = /*@__PURE__*/ new Matrix3().set(
  17. 2.4934969, - 0.9313836, - 0.4027108,
  18. - 0.8294890, 1.7626641, 0.0236247,
  19. 0.0358458, - 0.0761724, 0.9568845
  20. );
  21. export const DisplayP3ColorSpace = 'display-p3';
  22. export const LinearDisplayP3ColorSpace = 'display-p3-linear';
  23. export const DisplayP3ColorSpaceImpl = {
  24. primaries: P3_PRIMARIES,
  25. whitePoint: D65,
  26. transfer: SRGBTransfer,
  27. toXYZ: LINEAR_DISPLAY_P3_TO_XYZ,
  28. fromXYZ: XYZ_TO_LINEAR_DISPLAY_P3,
  29. luminanceCoefficients: P3_LUMINANCE_COEFFICIENTS,
  30. outputColorSpaceConfig: { drawingBufferColorSpace: DisplayP3ColorSpace }
  31. };
  32. export const LinearDisplayP3ColorSpaceImpl = {
  33. primaries: P3_PRIMARIES,
  34. whitePoint: D65,
  35. transfer: LinearTransfer,
  36. toXYZ: LINEAR_DISPLAY_P3_TO_XYZ,
  37. fromXYZ: XYZ_TO_LINEAR_DISPLAY_P3,
  38. luminanceCoefficients: P3_LUMINANCE_COEFFICIENTS,
  39. workingColorSpaceConfig: { unpackColorSpace: DisplayP3ColorSpace },
  40. outputColorSpaceConfig: { drawingBufferColorSpace: DisplayP3ColorSpace }
  41. };
  42. /******************************************************************************
  43. * Rec. 2020 definitions
  44. */
  45. const LINEAR_REC2020_TO_XYZ = /*@__PURE__*/ new Matrix3().set(
  46. 0.6369580, 0.1446169, 0.1688810,
  47. 0.2627002, 0.6779981, 0.0593017,
  48. 0.0000000, 0.0280727, 1.0609851
  49. );
  50. const XYZ_TO_LINEAR_REC2020 = /*@__PURE__*/ new Matrix3().set(
  51. 1.7166512, - 0.3556708, - 0.2533663,
  52. - 0.6666844, 1.6164812, 0.0157685,
  53. 0.0176399, - 0.0427706, 0.9421031
  54. );
  55. export const LinearRec2020ColorSpace = 'rec2020-linear';
  56. export const LinearRec2020ColorSpaceImpl = {
  57. primaries: REC2020_PRIMARIES,
  58. whitePoint: D65,
  59. transfer: LinearTransfer,
  60. toXYZ: LINEAR_REC2020_TO_XYZ,
  61. fromXYZ: XYZ_TO_LINEAR_REC2020,
  62. luminanceCoefficients: REC2020_LUMINANCE_COEFFICIENTS,
  63. };
粤ICP备19079148号