Don McCurdy пре 2 година
родитељ
комит
0936708173
1 измењених фајлова са 19 додато и 34 уклоњено
  1. 19 34
      src/math/ColorManagement.js

+ 19 - 34
src/math/ColorManagement.js

@@ -16,43 +16,28 @@ export function LinearToSRGB( c ) {
 
 
 
 
 /**
 /**
- * Matrices for sRGB and Display P3, based on the W3C specifications
- * for sRGB and Display P3, and the ICC specification for the D50
- * connection space.
+ * Matrices converting P3 <-> Rec. 709 primaries, without gamut mapping
+ * or clipping. Based on W3C specifications for sRGB and Display P3,
+ * and ICC specifications for the D50 connection space. Values in/out
+ * are _linear_ sRGB and _linear_ Display P3.
+ *
+ * Note that both sRGB and Display P3 use the sRGB transfer functions.
  *
  *
  * Reference:
  * Reference:
  * - http://www.russellcottrell.com/photo/matrixCalculator.htm
  * - http://www.russellcottrell.com/photo/matrixCalculator.htm
  */
  */
 
 
-const SRGB_TO_DISPLAY_P3 = new Matrix3().multiplyMatrices(
-	// XYZ to Display P3
-	new Matrix3().set(
-		2.4039840, - 0.9899069, - 0.3976415,
-		- 0.8422229, 1.7988437, 0.0160354,
-		0.0482059, - 0.0974068, 1.2740049,
-	),
-	// sRGB to XYZ
-	new Matrix3().set(
-		0.4360413, 0.3851129, 0.1430458,
-		0.2224845, 0.7169051, 0.0606104,
-		0.0139202, 0.0970672, 0.7139126,
-	),
-);
-
-const DISPLAY_P3_TO_SRGB = new Matrix3().multiplyMatrices(
-	// XYZ to sRGB
-	new Matrix3().set(
-		3.1341864, - 1.6172090, - 0.4906941,
-		- 0.9787485, 1.9161301, 0.0334334,
-		0.0719639, - 0.2289939, 1.4057537,
-	),
-	// Display P3 to XYZ
-	new Matrix3().set(
-		0.5151187, 0.2919778, 0.1571035,
-		0.2411892, 0.6922441, 0.0665668,
-		- 0.0010505, 0.0418791, 0.7840713,
-	),
-);
+const LINEAR_SRGB_TO_LINEAR_DISPLAY_P3 = new Matrix3().fromArray( [
+	0.8224621, 0.0331941, 0.0170827,
+	0.1775380, 0.9668058, 0.0723974,
+	- 0.0000001, 0.0000001, 0.9105199
+] );
+
+const LINEAR_DISPLAY_P3_TO_LINEAR_SRGB = new Matrix3().fromArray( [
+	1.2249401, - 0.0420569, - 0.0196376,
+	- 0.2249404, 1.0420571, - 0.0786361,
+	0.0000001, 0.0000000, 1.0982735
+] );
 
 
 const _vector = new Vector3();
 const _vector = new Vector3();
 
 
@@ -60,7 +45,7 @@ function DisplayP3ToLinearSRGB( color ) {
 
 
 	color.convertSRGBToLinear();
 	color.convertSRGBToLinear();
 
 
-	_vector.set( color.r, color.g, color.b ).applyMatrix3( DISPLAY_P3_TO_SRGB );
+	_vector.set( color.r, color.g, color.b ).applyMatrix3( LINEAR_DISPLAY_P3_TO_LINEAR_SRGB );
 
 
 	return color.setRGB( _vector.x, _vector.y, _vector.z );
 	return color.setRGB( _vector.x, _vector.y, _vector.z );
 
 
@@ -68,7 +53,7 @@ function DisplayP3ToLinearSRGB( color ) {
 
 
 function LinearSRGBToDisplayP3( color ) {
 function LinearSRGBToDisplayP3( color ) {
 
 
-	_vector.set( color.r, color.g, color.b ).applyMatrix3( SRGB_TO_DISPLAY_P3 );
+	_vector.set( color.r, color.g, color.b ).applyMatrix3( LINEAR_SRGB_TO_LINEAR_DISPLAY_P3 );
 
 
 	return color.setRGB( _vector.x, _vector.y, _vector.z ).convertLinearToSRGB();
 	return color.setRGB( _vector.x, _vector.y, _vector.z ).convertLinearToSRGB();