You are not resetting targetX
for each row, even though you are modifying it (targetX--
) in your loop. This would process the first row correctly, but not the remaining rows. You would need:
//loop from start to end of X
sourceX = x - sizer;
targetX = x + sizer; // <- reset targetX
for (sourceX = x - sizer; sourceX < targetX; sourceX++)
...
Note also that your initialization of sourceX
in the for
loop (as well as your initialization of it when it is declared at the start of your function) is redundant.