swr/rast: Fix primitive replication issue in tesselation PA.
[mesa.git] / src / gallium / auxiliary / vl / vl_csc.c
index d70ab14d323c0c14dbc9275362f4f0c0c8e2c318..861eda683a6aadec458f1111cf8976afbec66721 100644 (file)
@@ -131,6 +131,12 @@ static const vl_csc_matrix smpte240m =
    { 1.0f,  1.785f,  0.0f,   0.0f, }
 };
 
+static const vl_csc_matrix bt_709_rev  = {
+   { 0.183f,  0.614f,  0.062f, 0.0625f},
+   {-0.101f, -0.338f,  0.439f, 0.5f   },
+   { 0.439f, -0.399f, -0.040f, 0.5f   }
+};
+
 static const vl_csc_matrix identity =
 {
    { 1.0f, 0.0f, 0.0f, 0.0f, },
@@ -158,6 +164,7 @@ void vl_csc_get_matrix(enum VL_CSC_COLOR_STANDARD cs,
    float s = p->saturation;
    float b = p->brightness;
    float h = p->hue;
+   float x, y;
 
    const vl_csc_matrix *cstd;
 
@@ -167,6 +174,10 @@ void vl_csc_get_matrix(enum VL_CSC_COLOR_STANDARD cs,
       b -= c * 16.0f  / 255.0f; /* Adjust for the y bias */
    }
 
+   /* Parameter substitutions */
+   x = c * s * cosf(h);
+   y = c * s * sinf(h);
+
    assert(matrix);
 
    switch (cs) {
@@ -179,6 +190,9 @@ void vl_csc_get_matrix(enum VL_CSC_COLOR_STANDARD cs,
       case VL_CSC_COLOR_STANDARD_SMPTE_240M:
          cstd = &smpte240m;
          break;
+      case VL_CSC_COLOR_STANDARD_BT_709_REV:
+         memcpy(matrix, bt_709_rev, sizeof(vl_csc_matrix));
+         return;
       case VL_CSC_COLOR_STANDARD_IDENTITY:
       default:
          assert(cs == VL_CSC_COLOR_STANDARD_IDENTITY);
@@ -187,23 +201,23 @@ void vl_csc_get_matrix(enum VL_CSC_COLOR_STANDARD cs,
    }
 
    (*matrix)[0][0] = c * (*cstd)[0][0];
-   (*matrix)[0][1] = c * (*cstd)[0][1] * s * cosf(h) - c * (*cstd)[0][2] * s * sinf(h);
-   (*matrix)[0][2] = c * (*cstd)[0][2] * s * cosf(h) + c * (*cstd)[0][1] * s * sinf(h);
+   (*matrix)[0][1] = (*cstd)[0][1] * x - (*cstd)[0][2] * y;
+   (*matrix)[0][2] = (*cstd)[0][2] * x + (*cstd)[0][1] * y;
    (*matrix)[0][3] = (*cstd)[0][3] + (*cstd)[0][0] * b +
-                     (*cstd)[0][1] * (c * cbbias * s * cosf(h) + c * crbias * s * sinf(h)) +
-                     (*cstd)[0][2] * (c * crbias * s * cosf(h) - c * cbbias * s * sinf(h));
+                     (*cstd)[0][1] * (x * cbbias + y * crbias) +
+                     (*cstd)[0][2] * (x * crbias - y * cbbias);
 
    (*matrix)[1][0] = c * (*cstd)[1][0];
-   (*matrix)[1][1] = c * (*cstd)[1][1] * s * cosf(h) - c * (*cstd)[1][2] * s * sinf(h);
-   (*matrix)[1][2] = c * (*cstd)[1][2] * s * cosf(h) + c * (*cstd)[1][1] * s * sinf(h);
+   (*matrix)[1][1] = (*cstd)[1][1] * x - (*cstd)[1][2] * y;
+   (*matrix)[1][2] = (*cstd)[1][2] * x + (*cstd)[1][1] * y;
    (*matrix)[1][3] = (*cstd)[1][3] + (*cstd)[1][0] * b +
-                     (*cstd)[1][1] * (c * cbbias * s * cosf(h) + c * crbias * s * sinf(h)) +
-                     (*cstd)[1][2] * (c * crbias * s * cosf(h) - c * cbbias * s * sinf(h));
+                     (*cstd)[1][1] * (x * cbbias + y * crbias) +
+                     (*cstd)[1][2] * (x * crbias - y * cbbias);
 
    (*matrix)[2][0] = c * (*cstd)[2][0];
-   (*matrix)[2][1] = c * (*cstd)[2][1] * s * cosf(h) - c * (*cstd)[2][2] * s * sinf(h);
-   (*matrix)[2][2] = c * (*cstd)[2][2] * s * cosf(h) + c * (*cstd)[2][1] * s * sinf(h);
+   (*matrix)[2][1] = (*cstd)[2][1] * x - (*cstd)[2][2] * y;
+   (*matrix)[2][2] = (*cstd)[2][2] * x + (*cstd)[2][1] * y;
    (*matrix)[2][3] = (*cstd)[2][3] + (*cstd)[2][0] * b +
-                     (*cstd)[2][1] * (c * cbbias * s * cosf(h) + c * crbias * s * sinf(h)) +
-                     (*cstd)[2][2] * (c * crbias * s * cosf(h) - c * cbbias * s * sinf(h));
+                     (*cstd)[2][1] * (x * cbbias + y * crbias) +
+                     (*cstd)[2][2] * (x * crbias - y * cbbias);
 }