+ // Create a matrix to convert from source space -> XYZ,
+ // another matrix to convert from XYZ -> destination space,
+ // and then concatenate the two.
+ //
+ // Since we right-multiply the RGB column vector, the matrix
+ // concatenation order needs to be the opposite of the operation order.
+ Matrix3x3 m;
+
+ Matrix3x3 source_space_to_xyz;
+ Matrix3x3 destination_space_to_xyz;
+ Matrix3x3 xyz_to_destination_space;
+
+ get_xyz_matrix(source_space, source_space_to_xyz);
+ get_xyz_matrix(destination_space, destination_space_to_xyz);
+ invert_3x3_matrix(destination_space_to_xyz, xyz_to_destination_space);
+
+ multiply_3x3_matrices(xyz_to_destination_space, source_space_to_xyz, m);
+
+ char buf[1024];
+ sprintf(buf,
+ "const mat3 PREFIX(conversion_matrix) = mat3(\n"
+ " %.8f, %.8f, %.8f,\n"
+ " %.8f, %.8f, %.8f,\n"
+ " %.8f, %.8f, %.8f);\n\n",
+ m[0], m[3], m[6],
+ m[1], m[4], m[7],
+ m[2], m[5], m[8]);
+ return buf + read_file("colorspace_conversion_effect.glsl");