Before this patch the `rgb` pointer was incremented by the "inner" for loop but never reset to the start of the buffer by the "outer" while loop. This bug was introduced by the refactoring in 6158aeb30a.
6158aeb30a
Use calloc(3) & free(3) instead of c99 VLA.