I'm looking for an algorithm here, independent of specific programming language.
The problem:
We have a 2-dimensional display area (think simple buffer of pixels). Periodically, some of the pixels are changed. We need to find a set of rectangles that encapsulate all changed pixels.
It would be trivial, but undesirable, to compute a single, potentially large, rectangle that encapsulates all changed pixels. We would rather have multiple, smaller, tight-fitting rectangles down to a specified minimum size (that is a variable which can be changed).
For example, suppose that within the entire display area, a few pixels in the upper left corner changed and a few pixels in the lower right corner changed. We do NOT want to compute a single dirty rectangle of the entire area - we instead want two dirty rectangles: a small one in the upper left and a small one in the lower right.
Performance is critical, hence this question.
This problem crops up all of the time, definitely in video codecs and remote desktop compression areas, I presume. In my case, it is a recurring problem during graphical image manipulations that involve multiple users simultaneously drawing in a shared area.
Does anyone know of published algorithms for this or know of a solution you have used in the past?
Thanks!
My idea, with two decision options:
I wrote it in some kind of pseudocode ..
Basically for the first option you decide on a percentage that your area's must comply to meet minimum dirty pixels count.
And for the second option, you decide if the difference in this factor or dirty pixels per area changes too much if you expand to include this pixel.