Fast undo/redo for bitmap editor when memory is limited?

前端 未结 2 472
故里飘歌
故里飘歌 2020-12-16 00:49

I\'m trying to write a bitmap editor for a mobile device (i.e. a limited version of Photoshop). The user\'s document consists of ~4 bitmaps around 1000x500 in size each.

相关标签:
2条回答
  • 2020-12-16 01:09

    One approach is to keep certain 'frames' as complete frames, and others as the the command necessary to create a frame from the previous one. You allude to this in your #2. It may be helpful to keep some frames in memory.

    A trick that may help to balance performance with the space/time available to hold complete frames is to discard a some fraction of the 'old' frames, so that at any given time you might have undo states from e.g. 1, 2, 4, 8, 16, 32, and 64 operations ago. Undoing one or two operations will require simply reading a frame. Undoing three will require reading a checkpoint and repeating one operation. Undoing five will require reading a checkpoint and repeating three operations. Undoing thirty-three will require reading a checkpoint and repeating 31 operations.

    To improve application smoothness, it may in some cases be helpful to recompute checkpoint frames in the background during an undo operation. For example, after having undone seventeen operations, one might in the background start working on computing the states for 48, 40, and 36 steps back from the starting point, so that if one wants to go back further one will have already done some of the work. Note that one may jettison the frames that were back 1, 2, 4, 8, or 16 operations, since one can recreate them by replaying commands forward from the current state.

    0 讨论(0)
  • 2020-12-16 01:26

    This following might be handy for layers and undo buffers using images:

    • Keep the latest image as an image
    • Previous versions are stored as an xor with the next version and then (assuming not everything changed or changed in the same manner) compressed using a simple compression algorithm (like run length encoding)

    This has the following advantages

    • previous versions could be easily merged (xor them together).

    This might not work well with:

    • color adjustments (hue, brightness etc)
    • coordinate transformations (crop, morphing, etc)
    0 讨论(0)
提交回复
热议问题