Actually there is a following task: there is an image. It is necessary to deform the image so that the square was formed by a hemisphere. To implement this will be in JS+Canvas so... I Doubt that there is a ready-made solution (although you never know) so at least tell me the algorithm to implement this?
Wanted to explain algorithm on fingers, but came to the conclusion that it is easier to write an example: jsfiddle.net/CDKXm/
Look, if something is not clear in the PM. The algorithm is clumsy, no anti aliasing and optimizations.