e.clientX,
            y = e.y || e.clientY,
            bbox = canvas.getBoundingClientRect();

        return { x: x - bbox.left * (canvas.width  / bbox.width),
            y: y - bbox.top  * (canvas.height / bbox.height)
        };
    }

    // Save and restore drawing surface..............................

    function saveDrawingSurface() {
        drawingSurfaceImageData = context.getImageData(0, 0,
            canvas.width,
            canvas.height);
    }

    function restoreDrawingSurface() {
  