Yeah I figured you did something like that, I did the same once until i realized what the problem was ;) The mapping of coordinates is trickier. The trick, which I consider a bit cheating, is doing reverse mapping along iterating the pixels, which can be shown in the code I posted earlier. That's why I have 4, or was it 3 loops instead of 2. The proper way to do it is find the perspective correct texture coordinate from the current pixel, which you can find here for instance:
http://www.flipcode.com/articles/dem..._issue14.shtml