govips中多个图像的并行叠加

huangapple go评论82阅读模式
英文:

Parallel overlaying of multiple images in govips

问题

Govips中,是否有一种功能可以在基础图像上并行叠加多个图像?
有一个名为compositeMulti的函数,它接受一个图像列表,但它是否并行渲染这些图像?此外,它是否具有识别哪个像素来自哪个图像并在图像上进行渲染的能力,而不是逐个遍历所有图像并逐个渲染的能力?

英文:

In Govips, is there a functionality to overlay multiple images on a base image parallelly?
There is a function - compositeMulti which takes a list of images but does it render it parallelly? Also, does it have a capability to identify which pixel of which image has to be rendered on the image , instead of iteratively going through all the images and rendering one by one.

答案1

得分: 1

libvips(govips背后的图像处理库)是按需驱动和水平线程化的。计算的图像处理流水线被表示为一个图形,您的计算机上的每个线程选择输出图像中的一个瓦片(通常为128 x 128像素),并且线程独立地从末尾向开始遍历图形以计算像素。

composite运算符(compositeMulti调用的内容)计算使用PDF样式混合模式叠加一组图层的结果。对于每个瓦片,它选择在该点可见的图层子集。只有在所选的混合模式是“可跳过”的情况下,它才能执行此操作,即将黑色(空像素)叠加在基础图像上不会产生任何效果。

您可以在此处查看可跳过性的测试:

https://github.com/libvips/libvips/blob/master/libvips/conversion/composite.cpp#L1273-L1296

图层剪裁循环在此处:

https://github.com/libvips/libvips/blob/master/libvips/conversion/composite.cpp#L443-L460

最后,使用矢量运算(如果可能)合成所选的图层。它将RGBA像素表示为四个浮点数的向量,并同时计算它们。

简而言之,libvips的合成操作是线程化、矢量化的,并且(如果可能)进行瓦片级别的可见性剪裁。

英文:

libvips (the image processing library behind govips) is demand-driven and horizontally-threaded. The image processing pipeline being computed is represented as a graph, each thread on your PC picks a tile in the output image (usually 128 x 128 pixels), and threads independently walk the graph from end to start computing pixels.

The composite operator (the thing that compositeMulti calls) computes the result of overlaying a set of layers with PDF-style blend modes. For each tile, it selects the subset of layers which are visible at that point. It can only do this if the selected blending modes are 'skippable', ie. compositing black (the empty pixel) over the base image will have no effect.

You can see the test for skippability here:

https://github.com/libvips/libvips/blob/master/libvips/conversion/composite.cpp#L1273-L1296

And the layer culling loop is here:

https://github.com/libvips/libvips/blob/master/libvips/conversion/composite.cpp#L443-L460

Finally, the selected layers are composited, using vector arithmetic if possible. It represents an RGBA pixel as a vector of four floats and computes all of them together.

tldr: libvips composite is threaded, vectorized, and (if possible) does tile-wise visibility culling.

huangapple
  • 本文由 发表于 2022年4月13日 21:47:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/71858613.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定