I'm not sure how Photoshop implements undo, but the Paint node within Apple's Shake compositing application is pretty easy to explain:
- Each stoke is stored as a series of points, along with some information like stroke-colour, brush-size etc.
- When you draw a stoke, the changes are made on the current image
- Every
x
strokes (10 I think) the current image is cached into memory
- When you undo, it redraws the last ~9 stokes on the previous cached image.
There are two problems with this:
- When you undo more than 10 times, it has to recalculate the whole image. With thousands of strokes this can cause a several second pause
- With Shake, you save the setup file, containing the stroke information - not the actual pixel values.. Then means you have to recalculate the whole image whenever you reopen the Paint node, or render the image (not nearly as big a problem as the undo thing, however)
Well, there is a third problem, that being Shake is horribly buggy and poorly implemented in many areas, the Paint node beign one of them - so I'm not sure how good an implementation this is, but I can't imagine Photoshop being too dissimilar (albeit far better optimised)