Using Parser Expressions
 
 
 

| Using Component Expressions | Using Mathematical Expressions

The Component Parser operator and the Pixel Parser operator parse expressions, and use the results to affect individual RGBA components or individual pixels respectively. This section lists valid expression types, arguments and variables, and gives examples of their use.

The Component Parser allows separate expressions to be applied to red, green, blue and alpha components.

The Pixel Parser process, in the Image Adjust effect category, has a single expression channel that allows an expression to be input in the form of pixel. This applies the given expression to each RGBA component equally; additionally, the Pixel Parser can take any valid expression in a single Component Parser channel.

Using Component Expressions

Syntax: value

where value can be:

Any floating point number (0 to1).

Any expression evaluating to a number.

An input component value (r, g, b, a, pixel).

Example: Solid green frame:

Component Parser

Red

0

 

Green

1

 

Blue

0

 

Alpha

0

Example: Solid red frame:

Component Parser

Red

1

 

Green

0

 

Blue

0

 

Alpha

0

Example: Solid blue frame:

Component Parser

Red

0

 

Green

0

 

Blue

1

 

Alpha

0

Example: Do nothing (output same as input):

Component Parser

Red

r

 

Green

g

 

Blue

b

 

Alpha

a

Pixel Parser

Pixel

pixel

Example: Swap Components:

Component Parser

Red

g

 

Green

r

 

Blue

b

 

Alpha

a

Example: Invert picture:

Component Parser

Red

1-r

 

Green

1-g

 

Blue

1-b

 

Alpha

1-a

Pixel Parser

Pixel

1-pixel

Example: Luma Extract:

Component Parser

Red

r+g+b

 

Green

r+g+b

 

Blue

r+g+b

 

Alpha

0

Pixel Parser

Pixel

r+g+b

Component Expressions at a Particular Location

Syntax: component(x,y)

where x = integer (0 -- picture width in pixels)

where y = integer (0 -- picture height in pixels)

If you are using the Pixel Probe to see pixels values at a particular location, view the image at Full Size.

Example: Do nothing (output same as input)

Component Parser

Red

r(x,y)

 

Green

g(x,y)

 

Blue

b(x,y)

 

Alpha

0

Pixel Parser

Pixel

pixel(x,y)

Example: Shift whole image 10 pixels to the right:

Component Parser

Red

r(x+10,y)

 

Green

g(x+10,y)

 

Blue

b(x+10,y)

 

Alpha

0

Pixel Parser

Pixel

pixel(x+10,y)

Example: Shift just the red component upwards:

Component Parser

Red

r(x,y-10)

 

Green

g(x,y)

 

Blue

b(x,y)

 

Alpha

0

Component Expressions using Another Input

Syntax: component[input](x,y)

input is an integer either 1, 2 or 3, corresponding to the three available inputs to the operator.

Example: Do nothing (output same as input):

Component Parser

Red

r[1](x,y)

 

Green

g[1](x,y)

 

Blue

b[1](x,y)

 

Alpha

0

Pixel Parser

Pixel

pixel[1](x,y)

Example: Use the red component of Input 2 in the output:

Component Parser

Red

r[2](x,y)

 

Green

g[1](x,y)

 

Blue

b[1](x,y)

 

Alpha

0

Using Variables with Component Expressions

Variables can be used in expressions. Select the Variables property page.

There are:

  • Three floating point numbers (0 to 30) a1, a2, and a3.

  • Three floating point numbers (0 to 1) b1, b2, and b3.

  • Three integer number (0,1,2,3,...,30) c1, c2, and c3.

  • The variables can be set at key frames in the animation.

Example: Fade black to white over 10 frames (Set b1=0.0 at frame 1, b1=1.0 at frame 10):

Component Parser

Red

b1

 

Green

b1

 

Blue

b1

 

Alpha

0

Pixel Parser

Pixel

b1

Example: Dissolve input2 to input1 over 10 frames (Set b1=0.0 at frame 1, b1=1.0 at frame 10):

Component Parser

Red

r[1](x,y)*b1 + r[2](x,y)*(1-b1)

 

Green

g[1](x,y)*b1 + g[2](x,y)*(1-b1)

 

Blue

b[1](x,y)*b1 + b[2](x,y)*(1-b1)

 

Alpha

0

Pixel Parser

Pixel

pixel[1](x,y)*b1 + pixel[2](x,y)* (1-b1)

Using Variables with Conditional Expressions

Syntax: if (expression) then (expression) else (expression)

You must include an "else'"

Example: Horizontal Wipe over 10 frames (Set c1=0 at frame 1, c1= 720 at frame 10):

Component Parser

Red

if (x>c1) then r[1](x,y) else r[2](x,y)

 

Green

if (x>c1) then g[1](x,y) else g[2](x,y)

 

Blue

if (x>c1) then b[1](x,y) else b[2](x,y)

 

Alpha

0

Pixel Parser

Pixel

if (x>c1) then pixel[1](x,y) else pixel[2](x,y)

Using Mathematical Expressions

You can use a number of mathematical expressions in the component and pixel parsers. These include:

  • Plus: (+)

  • Minus: (-)

  • Multiplication: (*)

  • Division: (/)

  • Modulus: (%)

  • Natural Logarithm: (log) - log (float)

  • Square Root: (sqrt) - sqrt(float)

  • Exponential: (exp) - exp(float)

  • Absolute function: (abs) - abs(-1) = 1

  • Random number: (rand) - rand(N) N is any float, returns a float between 0 and N

Example: Color Correction:

Component Parser

Red

r + 0.5*b - 0.25*g

 

Green

g/2

 

Blue

b

 

Alpha

0

Example: Modulus - red and green stripey picture:

Component Parser

Red

if (y%2 = 0) then 1 else 0

 

Green

if (y%2 = 0) then 1 else 0

 

Blue

0

 

Alpha

0

Example: Add a lot of Noise to an image:

Component Parser

Red

r + rand(1)

 

Green

g + rand(1)

 

Blue

b + rand(1)

 

Alpha

0

Pixel Parser

Pixel

pixel + rand(1)

Example: Add a small amount of noise to an image:

Component Parser

Red

r + rand(0.1)

 

Green

g + rand(0.1)

 

Blue

b + rand(0.1)

 

Alpha

0

Pixel Parser

Pixel

pixel + rand(0.1)

Example: Scatter pixels around:

Component Parser

Red

r(x+rand(5),y+rand(5))

 

Green

g(x+rand(5),y+rand(5))

 

Blue

b(x+rand(5),y+rand(5))

 

Alpha

0

Pixel Parser

Pixel

pixel(x+rand(5),y+rand(5))

Trigonometric Expressions

Available trigonometric functions include:

  • Sine function (sin) - sin(float)

  • Cosine function (cos) - cos(float)

  • Tangent function (tan) - tan(float)

Example: Wave distortion:

Component Parser

Red

r(x+20*sin(x/ 20),y+20*sin(y/20))

 

Green

g(x+20*sin(x/ 20),y+20*sin(y/20))

 

Blue

b(x+20*sin(x/ 20),y+20*sin(y/20))

 

Alpha

a(x+20*sin(x/ 20),y+20*sin(y/20))

Pixel Parser

Pixel

pixel(x+20*sin(x/ 20),y+20*sin(y/20))

Logical Expressions

Available logical functions include:

  • Equality: (=)

  • Not equal: (<>)

  • Greater than: (>)

  • Less than: (<)

  • Greater than or equal: (>=)

  • Less than or equal: (<=)

  • Logical and: (and)

  • Logical or: (or)

  • Logical xor: (xor)

  • Logical not: (not)

  • Minimum of two numbers: (min)

  • Maximum of two numbers: (max)

Example: Logical composite:

Component Parser

Red

r[1](x,y) and r[2](x,y)

 

Green

g[1](x,y) and g[2](x,y)

 

Blue

b[1](x,y) and b[2](x,y)

 

Alpha

a[1](x,y) and a[2](x,y)

Pixel Parser

Pixel

pixel[1](x,y) and pixel[2](x,y)

Filter Attributes

Syntax: component.attribute(x,y)

where x and y are the pixel values at which the filter is applied.

All filters are based on a 3*3 convolution.

  • Gradient filter: (grad)

  • Blur filter: (blur)

  • Min filter: (minimum)

  • Max filter: (maximum)

  • Median filter: (median)

Example: Simple Blur:

Component Parser

Red

r.blur(x,y)

 

Green

g.blur(x,y)

 

Blue

b.blur(x,y)

 

Alpha

0

Pixel Parser

Pixel

pixel.blur(x,y)

Example: Edge Sharpen:

Component Parser

Red

r+r.grad(x,y)

 

Green

g+g.grad(x,y)

 

Blue

b+b.grad(x,y)

 

Alpha

0

Pixel Parser

Pixel

pixel+pixel.grad(x,y)

Shape Attributes

Syntax: shape(x,y,size)

where x, y and size are values in pixels and shape can be circle or square.

Circle: (circle)

Square: (square)

Example: Picture in picture:

Component Parser

Red

if square(100,200,50) then r[1](x,y) else r[2](x,y)

 

Green

if square(100,200,50) then g[1](x,y) else g[2](x,y)

 

Blue

if square(100,200,50) then b[1](x,y) else b[2](x,y)

 

Alpha

0

Pixel Parser

Pixel

if square(100,200,50) then pixel[1](x,y) else pixel[2](x,y)

Example: Picture in circle:

Component Parser

Red

if circle(100,200,50) then r[1](x,y) else r[2](x,y)

 

Green

if circle(100,200,50) then g[1](x,y) else g[2](x,y)

 

Blue

if circle(100,200,50) then b[1](x,y) else b[2](x,y)

 

Alpha

0

Pixel Parser

Pixel

if circle(100,200,50) then pixel[1](x,y) else pixel[2](x,y)

Image Attributes

Syntax: component.attribute(argument(s))

The image attribute category modifies the current pixel's component value. Attributes include:

  • Quantization (quantize) - component.quantize(x)

  • Contrast enhancement (contrast) - component.contrast(x1,x2)

  • Gamma correction (gamma) - component.gamma(x)

  • Sawtooth function (sawtooth) - component.sawtooth(x)

  • Smooth Step function (smoothstep) - component.smoothstep(x1,x2)

  • Step function (step) - component.step(x1,x2,x3)

Example: Component Quantization to 4 levels:

Component Parser

Red

r.quantize(4)

 

Green

g.quantize(4)

 

Blue

b.quantize(4)

 

Alpha

0

Pixel Parser

Pixel

 

pixel.quantize(4)

As quantization takes place on each component separately, this gives 43 = 64 levels.

Example: Contrast:

Component Parser

Red

r.contrast(0.25,0.75)

 

Green

g.contrast(0.25,0.75)

 

Blue

b.contrast(0.25,0.75)

 

Alpha

0

Pixel Parser

Pixel

pixel.contrast(0.25,0.75)

Example: Gamma:

Component Parser

Red

r.gamma(0.7)

 

Green

g.gamma(0.7)

 

Blue

b.gamma(0.7)

 

Alpha

0

Pixel Parser

Pixel

pixel.gamma(0.7)

Example: Sawtooth:

Component Parser

Red

r.sawtooth(4)

 

Green

g.sawtooth(4)

 

Blue

b.sawtooth(4)

 

Alpha

0

Pixel Parser

Pixel

pixel.sawtooth(4)

Example: Smoothstep:

Component Parser

Red

r.smoothstep(0.25,0.75)

 

Green

g.smoothstep(0.25,0.75)

 

Blue

b.smoothstep(0.25,0.75)

 

Alpha

0

Pixel Parser

Pixel

pixel.smoothstep(0.25,0.75)

Example: Step:

Component Parser

Red

r.step(0.25,0.75,0.75)

 

Green

g.step(0.25,0.75,0.75)

 

Blue

b.step(0.25,0.75,0.75)

 

Alpha

0

Pixel Parser

Pixel

pixel.step(0.25,0.75,0.75)

Time

Variables can be accessed at any point in time.

Syntax: variable(frame number)

The variable time represents the current frame number.

Example:

Component Parser

Red

r*c1(6)

 

Green

g*c1(time-1)

 

Blue

b

 

Alpha

0