最优脏矩形集
我在这里寻找一种独立于特定编程语言的算法。
问题:
我们有一个二维显示区域 (想想简单的像素缓冲区)。 周期性地,一些像素 改变了。我们需要找到一组 封装所有的矩形 改变了像素。
这虽然微不足道,但不可取, 计算一个潜在的 大的矩形,封装了所有 改变了像素。我们宁愿有 多个、较小、紧身 矩形缩小到指定的最小值 大小(这是一个变量,可以是 改变)。
例如,假设在 整个显示区域,其中的几个像素 左上角发生变化,并且 右下角有几个像素 改变了。我们不想计算 整个的单个脏矩形 区域 - 我们想要两个脏的 矩形:上面一个小矩形 左边,下面有一个小 对。
性能至关重要,因此提出了这个问题。
我认为这个问题一直都会出现,尤其是在视频编解码器和远程桌面压缩领域。就我而言,这是图形图像操作过程中反复出现的问题,涉及多个用户同时在共享区域中绘图。
有谁知道已发布的算法或知道您过去使用过的解决方案?
谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
屏幕视频/远程桌面编解码器通常将屏幕划分为图块,然后仅传输已更改图块的位图。然后,平铺图像通常会进行 ZLIB 压缩。
有多种方法可以对此进行改进,例如,
例如,Adobe Flash 在其“Screen Video 2”编解码器中结合使用了所有三种技术。
如果您不想使用压缩,则可以使用图块和图块的组合。边界框是一个很好的折衷方案。例如,如果您在对角处只有两个更改的像素,则只有这两个像素将被更新,但如果您有一个具有分散更改的区域(例如在文本编辑器中键入),则更改将组合成几个大矩形,这可能更有效而不是将其分成数百个小矩形。)
Screen video/remote desktop codecs generally divide the screen into tiles and then transmit bitmaps for the changed tiles only. The tile images are typically then ZLIB-compressed.
There are various ways to improve on this, e.g.
For example Adobe Flash uses a combination of all three techniques in its "Screen Video 2" codec.
If you don't want to use compression, a combination of tiles & bounding boxes is a good compromise. E.g. if you have just two changed pixels at opposite corners only those two pixels will be updated, but if you have a region with scattered changes (e.g. typing in a text editor) the changes are combined into a few large rectangles which is probably more efficient than breaking it into hundreds of small rectangles.)
查看 R-tree 和 四叉树 数据结构。
Look into R-tree and quadtree data structures.
我的想法有两个决策选项:
我用某种伪代码编写了它。
基本上,对于第一个选项,您决定您的区域必须遵守的百分比,以满足最小脏像素数。
对于第二个选项,您可以决定如果扩展以包含此像素,则此因子或每个区域的脏像素的差异是否会发生太大变化。
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.