Basically, you have the original image and the grid. The grid begins as a grid with perfect squares, but is deformed. Algorithm
For Each section of the mesh
For Each pixel of the section
(x, y) = Location in original photo for this pixel // (floating point)
color = ColorFromOriginal(x, y) // this needs to blend neighboring pixels if fractional
setColor(color)
Finding out (x, y) - simple geometry - match the center of the deformed square to the center of the original, then determine which triangle you are (N, S, E, W) and the deformed triangle to the original.
+---------+
|\ /|
| \ N / |
| \ / |
| \ / |
| W X E |
| / \ |
| / \ |
| / S \ |
|/ \|
+---------+
(x, y) , , , pt. .
+----+----+----+
| | | |
| | | |
+----+----+----+
| | | |
| | | |
+----+----+----+
| | | |
| | | |
+----+----+----+
pt. ,
+----+----+----+
| | | |
| x|xx | |
+----+----+----+
| x|xx | |
| | | |
+----+----+----+
| | | |
| | | |
+----+----+----+
- , .
(resample). , , , .