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.
CodePudding user response:
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 finds just the subset of layers which are visible at that point, provided 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.