Allocate memory for both pixels and rows in the same way to make the code easier understandable. (cherry picked from commit b7ae59e9)