You need For x = 0 To w - 1, and For y = 0 to h - 1.
There is nothing wrong with the Until Conard has used - it does the same thing.
You are going to kick yourself, but I think the actual problem you have is simply from you writing the parameters in the wrong order for WritePixel (from the docs): ;-)
WritePixel( pixmap:TPixmap,x,y,argb )
You have put the pixel before the coordinates in your line, therefore, it should be changed to:
WritePixel(pm2, x * _sx + x2, y * _sy + y2, pm.ReadPixel(x,y))