Go back to Efl.Gfx.Filter.

Displacement mapping

Apply a displacement map on a buffer. This has the effect of moving the input pixels based on the values of the corresponding pixels in the displacement buffer.

Syntax
displace ({ map, intensity = 10, flags = 0, src = input, dst = output, fillmode = 'repeat' })
Parameters
map An RGBA buffer containing a displacement map. See below for more details.
intensity Maximum distance for the displacement. The value 255 in the displacement map will then represent a displacement of intensity pixels.
flags This defines how pixels should be treated when going out of the source image bounds.
Must be one of “default”, “nearest”, “smooth”, “nearest_stretch” or “smooth_stretch”. “default” is equivalent to “smooth_stretch”.
src Source buffer.
dst Destination buffer. Must be of same color format and size as src.
fillmode Defines how to handle cases where the map has a different size from src and dst. It should be a combination of stretch or repeat: none is not supported. See Fill modes.

The map buffer is an RGBA image containing displacement and alpha values. Its size can be different from src or dst.

  • The red channel is used for X displacements while the green channel is used for Y displacements. All subpixel values are in the range 0..255. A value of 128 means 0 displacement, lower means displace to the top/left and higher than 128 displace to the bottom/right.
  • The alpha channel is used as an alpha multiplier for blending.
  • The blue channel is ignored.

Considering I(x, y) represents the pixel at position (x, y) in the image I, then here is how the displacement is applied to dst:

D = map (x, y)
dst (x, y) = D.alpha / 255 * src (x + (D.red - 128) * intensity / 128,
                                  y + (D.green - 128) * intensity / 128)
           + (255 - D.alpha) / 255 * dst (x, y)

Of course, the real algorithm takes into account interpolation between pixels as well.

Example
a = buffer { 'alpha' }
displace { 'image1', intensity = 20, fillmode = 'stretch', dst = a }
blend { a }
Displacement map Output