/* Calculate the inverse of a 3x3 matrix http://en.wikipedia.org/wiki/Invertible_matrix */ void x3f_3x3_inverse(double *a, double *ainv) { double A, B, C, D, E, F, G, H, I; double det; A = +(M11(a)*M22(a)-M12(a)*M21(a)); B = -(M10(a)*M22(a)-M12(a)*M20(a)); C = +(M10(a)*M21(a)-M11(a)*M20(a)); D = -(M01(a)*M22(a)-M02(a)*M21(a)); E = +(M00(a)*M22(a)-M02(a)*M20(a)); F = -(M00(a)*M21(a)-M01(a)*M20(a)); G = +(M01(a)*M12(a)-M02(a)*M11(a)); H = -(M00(a)*M12(a)-M02(a)*M10(a)); I = +(M00(a)*M11(a)-M01(a)*M10(a)); det = M00(a)*A + M01(a)*B + M02(a)*C; M00(ainv) = A/det; M01(ainv) = D/det; M02(ainv) = G/det; M10(ainv) = B/det; M11(ainv) = E/det; M12(ainv) = H/det; M20(ainv) = C/det; M21(ainv) = F/det; M22(ainv) = I/det; }
void DOMMatrixReadOnly::Stringify(nsAString& aResult) { nsAutoString matrixStr; if (mMatrix3D) { matrixStr.AppendPrintf("matrix3d(%g, %g, %g, %g, %g, %g, %g, %g, %g, %g, %g, %g, %g, %g, %g, %g)", M11(), M12(), M13(), M14(), M21(), M22(), M23(), M24(), M31(), M32(), M33(), M34(), M41(), M42(), M43(), M44()); } else { matrixStr.AppendPrintf("matrix(%g, %g, %g, %g, %g, %g)", A(), B(), C(), D(), E(), F()); } aResult = matrixStr; }
/* Multiply a 3x3 matrix with a 3x3 matrix, giving a 3x3 matrix */ void x3f_3x3_3x3_mul(double *a, double *b, double *c) { M00(c) = M00(a)*M00(b) + M01(a)*M10(b) + M02(a)*M20(b); M01(c) = M00(a)*M01(b) + M01(a)*M11(b) + M02(a)*M21(b); M02(c) = M00(a)*M02(b) + M01(a)*M12(b) + M02(a)*M22(b); M10(c) = M10(a)*M00(b) + M11(a)*M10(b) + M12(a)*M20(b); M11(c) = M10(a)*M01(b) + M11(a)*M11(b) + M12(a)*M21(b); M12(c) = M10(a)*M02(b) + M11(a)*M12(b) + M12(a)*M22(b); M20(c) = M20(a)*M00(b) + M21(a)*M10(b) + M22(a)*M20(b); M21(c) = M20(a)*M01(b) + M21(a)*M11(b) + M22(a)*M21(b); M22(c) = M20(a)*M02(b) + M21(a)*M12(b) + M22(a)*M22(b); }
void DOMMatrixReadOnly::Stringify(nsAString& aResult) { nsAutoString matrixStr; if (mMatrix3D) { // We can't use AppendPrintf here, because it does locale-specific // formatting of floating-point values. matrixStr.AssignLiteral("matrix3d("); AppendFloat(matrixStr, M11()); matrixStr.AppendLiteral(", "); AppendFloat(matrixStr, M12()); matrixStr.AppendLiteral(", "); AppendFloat(matrixStr, M13()); matrixStr.AppendLiteral(", "); AppendFloat(matrixStr, M14()); matrixStr.AppendLiteral(", "); AppendFloat(matrixStr, M21()); matrixStr.AppendLiteral(", "); AppendFloat(matrixStr, M22()); matrixStr.AppendLiteral(", "); AppendFloat(matrixStr, M23()); matrixStr.AppendLiteral(", "); AppendFloat(matrixStr, M24()); matrixStr.AppendLiteral(", "); AppendFloat(matrixStr, M31()); matrixStr.AppendLiteral(", "); AppendFloat(matrixStr, M32()); matrixStr.AppendLiteral(", "); AppendFloat(matrixStr, M33()); matrixStr.AppendLiteral(", "); AppendFloat(matrixStr, M34()); matrixStr.AppendLiteral(", "); AppendFloat(matrixStr, M41()); matrixStr.AppendLiteral(", "); AppendFloat(matrixStr, M42()); matrixStr.AppendLiteral(", "); AppendFloat(matrixStr, M43()); matrixStr.AppendLiteral(", "); AppendFloat(matrixStr, M44()); matrixStr.AppendLiteral(")"); } else { // We can't use AppendPrintf here, because it does locale-specific // formatting of floating-point values. matrixStr.AssignLiteral("matrix("); AppendFloat(matrixStr, A()); matrixStr.AppendLiteral(", "); AppendFloat(matrixStr, B()); matrixStr.AppendLiteral(", "); AppendFloat(matrixStr, C()); matrixStr.AppendLiteral(", "); AppendFloat(matrixStr, D()); matrixStr.AppendLiteral(", "); AppendFloat(matrixStr, E()); matrixStr.AppendLiteral(", "); AppendFloat(matrixStr, F()); matrixStr.AppendLiteral(")"); } aResult = matrixStr; }
/* Multiply a scalar with a 3x3 matrix, giving a 3x3 matrix */ void x3f_scalar_3x3_mul(double a, double *b, double *c) { M00(c) = a*M00(b); M01(c) = a*M01(b); M02(c) = a*M02(b); M10(c) = a*M10(b); M11(c) = a*M11(b); M12(c) = a*M12(b); M20(c) = a*M20(b); M21(c) = a*M21(b); M22(c) = a*M22(b); }
void x3f_Bradford_D65_to_D50(double *a) { M00(a) = +1.0478112 ; M01(a) = +0.0228866; M02(a) = -0.0501270; M10(a) = +0.0295424 ; M11(a) = +0.9904844; M12(a) = -0.0170491; M20(a) = -0.0092345 ; M21(a) = +0.0150436; M22(a) = +0.7521316; }
/* http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html */ void x3f_Bradford_D50_to_D65(double *a) { M00(a) = +0.9555766 ; M01(a) = -0.0230393; M02(a) = +0.0631636; M10(a) = -0.0282895 ; M11(a) = +1.0099416; M12(a) = +0.0210077; M20(a) = +0.0122982 ; M21(a) = -0.0204830; M22(a) = +1.3299098; }
/* http://en.wikipedia.org/wiki/CIE_1931_color_space */ void x3f_CIERGB_to_XYZ(double *a) { M00(a) = 0.49 ; M01(a) = 0.31 ; M02(a) = 0.20 ; M10(a) = 0.17697 ; M11(a) = 0.81240 ; M12(a) = 0.01063 ; M20(a) = 0.00 ; M21(a) = 0.01 ; M22(a) = 0.99 ; }
void x3f_3x3_identity(double *a) { M00(a) = 1.0; M01(a) = 0.0; M02(a) = 0.0; M10(a) = 0.0; M11(a) = 1.0; M12(a) = 0.0; M20(a) = 0.0; M21(a) = 0.0; M22(a) = 1.0; }
/* http://en.wikipedia.org/wiki/SRGB */ void x3f_XYZ_to_sRGB(double *a) { M00(a) = +3.2406; M01(a) = -1.5372; M02(a) = -0.4986; M10(a) = -0.9689; M11(a) = +1.8758; M12(a) = +0.0415; M20(a) = +0.0557; M21(a) = -0.2040; M22(a) = +1.0570; }
void x3f_AdobeRGB_to_XYZ(double *a) { M00(a) = 0.57667; M01(a) = 0.18556; M02(a) = 0.18823; M10(a) = 0.29737; M11(a) = 0.62736; M12(a) = 0.07529; M20(a) = 0.02703; M21(a) = 0.07069; M22(a) = 0.99134; }
/* http://www.adobe.com/digitalimag/pdfs/AdobeRGB1998.pdf */ void x3f_XYZ_to_AdobeRGB(double *a) { M00(a) = +2.04159; M01(a) = -0.56501; M02(a) = -0.34473; M10(a) = -0.96924; M11(a) = +1.87597; M12(a) = +0.04156; M20(a) = +0.01344; M21(a) = -0.11836; M22(a) = +1.01517; }
void x3f_ProPhotoRGB_to_XYZ(double *a) { M00(a) = 0.7977; M01(a) = 0.1352; M02(a) = 0.0313; M10(a) = 0.2880; M11(a) = 0.7119; M12(a) = 0.0001; M20(a) = 0.0000; M21(a) = 0.0000; M22(a) = 0.8249; }
/* http://en.wikipedia.org/wiki/ProPhoto_RGB_color_space */ void x3f_XYZ_to_ProPhotoRGB(double *a) { M00(a) = +1.3460; M01(a) = -0.2556; M02(a) = -0.0511; M10(a) = -0.5446; M11(a) = +1.5082; M12(a) = +0.0205; M20(a) = +0.0000; M21(a) = +0.0000; M22(a) = +1.2123; }
/* Print a 3x3 matrix */ void x3f_3x3_print(x3f_verbosity_t level, double *a) { x3f_printf(level, "%10g %10g %10g\n", M00(a), M01(a), M02(a)); x3f_printf(level, "%10g %10g %10g\n", M10(a), M11(a), M12(a)); x3f_printf(level, "%10g %10g %10g\n", M20(a), M21(a), M22(a)); }
void x3f_3x3_ones(double *a) { M00(a) = 1.0; M01(a) = 1.0; M02(a) = 1.0; M10(a) = 1.0; M11(a) = 1.0; M12(a) = 1.0; M20(a) = 1.0; M21(a) = 1.0; M22(a) = 1.0; }
void x3f_sRGB_to_XYZ(double *a) { M00(a) = 0.4124; M01(a) = 0.3576; M02(a) = 0.1805; M10(a) = 0.2126; M11(a) = 0.7152; M12(a) = 0.0722; M20(a) = 0.0193; M21(a) = 0.1192; M22(a) = 0.9505; }
/* Convert a 3x1 matrix to a 3x3 diagonal matrix */ void x3f_3x3_diag(double *a, double *b) { M00(b) = M0(a); M01(b) = 0.0; M02(b) = 0.0; M10(b) = 0.0; M11(b) = M1(a); M12(b) = 0.0; M20(b) = 0.0; M21(b) = 0.0; M22(b) = M2(a); }