Go back to Efl.Gfx.Filter.
The color curve function is based on the classic curve image filtering operation. It works by remapping one or more color channels (R, G, B, A, or RGB together) by applying a function over the range [0-255]. A table can also be passed in, containing a series of key points to be interpolated.
curve ({ points, interpolation = 'linear', channel = 'rgb', src = input, dst = output })
points | The color curve to apply. See below for the syntax. |
interpolation | How to interpolate between points. One of linear (y = ax + b) or none (y = Yk). |
channel | Target channel for the color modification. One of R(ed), G(reen), B(lue), A(lpha), RGB and RGBA. If src is an alpha buffer, this parameter will be ignored. |
src | Source buffer. |
dst | Destination buffer, must be of same dimensions and color space as src . |
The points
argument is a function or table taking input values from 0 to 255 and mapping those to the same range 0 to 255. The old string-based syntax is still supported but not recommended.
The easiest way to specify a curve is to create a sparse table with keys and values from 0 to 255 (yes, the table starts at 0 and not 1 as is usual in Lua):
-- color invert p = {} p[0] = 255 p[255] = 0 curve ({ points = p })
This can of course be inlined:
curve ({ points = { [0] = 255, [255] = 0 } })
Another solution is to pass in a function f(x)
that will output values in the 0-255 range. For example:
p = function(x) return 255 * math.sin(x / 255 * math.pi) end curve ({ points = p })
a = buffer ('alpha') b = buffer ('alpha') blur { 6, dst = a } c = {} c[0] = 0 c[50] = 255 c[100] = 0 c[150] = 255 c[200] = 0 c[255] = 255 curve { src = a, points = c, dst = b } blend {src = b }
Color curves can thus be used to draw contours of text characters:
a = buffer ('alpha') blur ({ 4, dst = a }) p = {} p[0] = 0 p[20] = 0 p[60] = 255 p[160] = 255 p[200] = 0 p[255] = 0 curve ({ points = p, src = a, dst = a }) blend ({ src = a, color = 'white' })