You should specify how the matrix is oriented (row-major, I guess, so pixel `(x,y)` is accessed as `res[x + 6 * y]`)