ColorSpaces.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import { LinearTransfer, Matrix3, SRGBTransfer } from 'three';
  2. /** @module ColorSpaces */
  3. // Reference: http://www.russellcottrell.com/photo/matrixCalculator.htm
  4. const P3_PRIMARIES = [ 0.680, 0.320, 0.265, 0.690, 0.150, 0.060 ];
  5. const P3_LUMINANCE_COEFFICIENTS = [ 0.2289, 0.6917, 0.0793 ];
  6. const REC2020_PRIMARIES = [ 0.708, 0.292, 0.170, 0.797, 0.131, 0.046 ];
  7. const REC2020_LUMINANCE_COEFFICIENTS = [ 0.2627, 0.6780, 0.0593 ];
  8. const D65 = [ 0.3127, 0.3290 ];
  9. /******************************************************************************
  10. * Display P3 definitions
  11. */
  12. const LINEAR_DISPLAY_P3_TO_XYZ = /*@__PURE__*/ new Matrix3().set(
  13. 0.4865709, 0.2656677, 0.1982173,
  14. 0.2289746, 0.6917385, 0.0792869,
  15. 0.0000000, 0.0451134, 1.0439444
  16. );
  17. const XYZ_TO_LINEAR_DISPLAY_P3 = /*@__PURE__*/ new Matrix3().set(
  18. 2.4934969, - 0.9313836, - 0.4027108,
  19. - 0.8294890, 1.7626641, 0.0236247,
  20. 0.0358458, - 0.0761724, 0.9568845
  21. );
  22. /**
  23. * Display-P3 color space.
  24. *
  25. * @type {string}
  26. * @constant
  27. */
  28. export const DisplayP3ColorSpace = 'display-p3';
  29. /**
  30. * Display-P3-Linear color space.
  31. *
  32. * @type {string}
  33. * @constant
  34. */
  35. export const LinearDisplayP3ColorSpace = 'display-p3-linear';
  36. /**
  37. * Implementation object for the Display-P3 color space.
  38. *
  39. * @type {module:ColorSpaces~ColorSpaceImpl}
  40. * @constant
  41. */
  42. export const DisplayP3ColorSpaceImpl = {
  43. primaries: P3_PRIMARIES,
  44. whitePoint: D65,
  45. transfer: SRGBTransfer,
  46. toXYZ: LINEAR_DISPLAY_P3_TO_XYZ,
  47. fromXYZ: XYZ_TO_LINEAR_DISPLAY_P3,
  48. luminanceCoefficients: P3_LUMINANCE_COEFFICIENTS,
  49. outputColorSpaceConfig: { drawingBufferColorSpace: DisplayP3ColorSpace }
  50. };
  51. /**
  52. * Implementation object for the Display-P3-Linear color space.
  53. *
  54. * @type {module:ColorSpaces~ColorSpaceImpl}
  55. * @constant
  56. */
  57. export const LinearDisplayP3ColorSpaceImpl = {
  58. primaries: P3_PRIMARIES,
  59. whitePoint: D65,
  60. transfer: LinearTransfer,
  61. toXYZ: LINEAR_DISPLAY_P3_TO_XYZ,
  62. fromXYZ: XYZ_TO_LINEAR_DISPLAY_P3,
  63. luminanceCoefficients: P3_LUMINANCE_COEFFICIENTS,
  64. workingColorSpaceConfig: { unpackColorSpace: DisplayP3ColorSpace },
  65. outputColorSpaceConfig: { drawingBufferColorSpace: DisplayP3ColorSpace }
  66. };
  67. /******************************************************************************
  68. * Rec. 2020 definitions
  69. */
  70. const LINEAR_REC2020_TO_XYZ = /*@__PURE__*/ new Matrix3().set(
  71. 0.6369580, 0.1446169, 0.1688810,
  72. 0.2627002, 0.6779981, 0.0593017,
  73. 0.0000000, 0.0280727, 1.0609851
  74. );
  75. const XYZ_TO_LINEAR_REC2020 = /*@__PURE__*/ new Matrix3().set(
  76. 1.7166512, - 0.3556708, - 0.2533663,
  77. - 0.6666844, 1.6164812, 0.0157685,
  78. 0.0176399, - 0.0427706, 0.9421031
  79. );
  80. /**
  81. * Rec2020-Linear color space.
  82. *
  83. * @type {string}
  84. * @constant
  85. */
  86. export const LinearRec2020ColorSpace = 'rec2020-linear';
  87. /**
  88. * Implementation object for the Rec2020-Linear color space.
  89. *
  90. * @type {module:ColorSpaces~ColorSpaceImpl}
  91. * @constant
  92. */
  93. export const LinearRec2020ColorSpaceImpl = {
  94. primaries: REC2020_PRIMARIES,
  95. whitePoint: D65,
  96. transfer: LinearTransfer,
  97. toXYZ: LINEAR_REC2020_TO_XYZ,
  98. fromXYZ: XYZ_TO_LINEAR_REC2020,
  99. luminanceCoefficients: REC2020_LUMINANCE_COEFFICIENTS,
  100. };
  101. /**
  102. * An object holding the color space implementation.
  103. *
  104. * @typedef {Object} module:ColorSpaces~ColorSpaceImpl
  105. * @property {Array<number>} primaries - The primaries.
  106. * @property {Array<number>} whitePoint - The white point.
  107. * @property {Matrix3} toXYZ - A color space conversion matrix, converting to CIE XYZ.
  108. * @property {Matrix3} fromXYZ - A color space conversion matrix, converting from CIE XYZ.
  109. * @property {Array<number>} luminanceCoefficients - The luminance coefficients.
  110. * @property {{unpackColorSpace:string}} [workingColorSpaceConfig] - The working color space config.
  111. * @property {{drawingBufferColorSpace:string}} [outputColorSpaceConfig] - The drawing buffer color space config.
  112. **/
粤ICP备19079148号