There is a third common way to cancel processing. That is, store the differences between the two states in the Undo object. You can make it like real differences (that is, which pixels have changed and what they have changed), but it is probably almost as wasteful as storing a bitmap at each stage.
Alternatively, you can use the command template approach, but instead of restarting the commands when canceling, you save the inversion of the command - that is, if the user increased the red value by ten, the cancel command should decrease by ten. To cancel, you simply execute the reverse command. It is difficult for some teams to find an inversion, for example, "convert to black and white", but by mixing the base bitmap with several filters that are turned on or off by the command, you can do this.
As another suggestion, use the above command approach, but save the bitmap for the previous step. When the user cancels the immediate display of the cached bitmap from the previous (n-1) step, then start calculating the bitmap for n-2 so that you are ready when it depresses the cancel again.
Djclayworth
source share