Normally a color matrix is a 5x5 matrix. Here are 5x5 color matrix as a example:
Brightness Matrix Contrast Matrix
R G B A W R G B A W
R [1 0 0 0 b] R [c 0 0 0 t]
G [0 1 0 0 b] G [0 c 0 0 t]
B [0 0 1 0 b] B [0 0 c 0 t]
A [0 0 0 1 0] A [0 0 0 1 0]
W [0 0 0 0 1] W [0 0 0 0 1]
b = brightness c = contrast
t = (1.0 - c) / 2.0
This is the formula when color matrix transforms a RGBA color vector:
The last color vector W [0 0 0 0 1] does not matter, so it could be ignored in the formula.