FXNodes

libavg can apply a variety of GPU-based image postprocessing effects to nodes using FXNodes. Currently available are:

  • BlurFXNode: Blurs the node it is applied to.
  • ChromaKeyFXNode: Applies a high-quality realtime chroma key (greenscreen or bluescreen) effect.
  • HueSatFXNode: Color-correction filter based on the photoshop hue/saturation image adjustment.
  • InvertFXNode: Inverts the brightness values of all pixels in the node.
  • NullFXNode: Has no effect and is mainly used for debugging purposes.
  • ShadowFXNode: Adds a shadow behind the node.

Usage

To use this feature, attach an appropriate FXNode to a base node and set the effect parameters:

1image = avg.ImageNode(parent=rootNode, href='hsl.png', 
2        size=(640,640))
3fxNode = avg.HueSatFXNode(0, 0)
4image.setEffect(fxNode)

The above code simply desaturates the image displayed.

Effect parameters can be changed at runtime:

1fxNode.saturation -= 1

This works with any RasterNode, so you can add effects to VideoNodes and WordsNodes as well. To add an effect to a DivNode, render the DivNode to a canvas, use the canvas as input for an ImageNode and attach the effect to the ImageNode.

Performance

Some effects - blurs with a large radius, for example - can take a bit of time to execute. This depends in large part on the graphics card being used. In any case, libavg is smart enough to only regenerate effects when it has to. For instance, in a static text with a shadow effect, the effect will only be regenerated when either the text or the effect parameters change.