RHS/LHS right-hand side and left-hand side
W% in the code was indeed the width of the image. Clever of you to work that out in absence of the bulk of the code.
Although Steve hasn't given us the full tutorial on accessing the _MEM pixel data of an image, I took a chance that the data are in column then row order, so to get the next row you index down a complete width's worth.