Image warping - how to proceed
ImageMagick does that sort of thing, and it's open source.  Look at the source code in magick/distort.c of the current ImageMagick distribution, which you can get from imagemagick.org.  This assumes you have already selected the four control points and passed them in as an option.

The particular distortion method you described is called "binlinear forward" distortion in ImageMagick.  See http://www.imagemagick.org/Usage/distorts/#bilinear_forward