Effects » User » Broadcast » Safe area and crosshatch

Safe area and crosshatch
Release date: Sept. 26, 2018
Creation date: Jan. 23, 2016
License: unknown

Lightworks user effect Crosshatch.fx

This safe area and cross hatch generator is entirely original work. It has been
generously commented so that anyone who wishes to do so may modify it as required.
All "magic numbers" are defined immediately following the sampler declarations for
easy access and adjustment.

Modified 6 April 2018 jwrl.
Added authorship and description information for GitHub, and reformatted the original
code to be consistent with other Lightworks user effects.

Modified by LW user jwrl 26 September 2018.
Added notes to header.
Definitions and declarations
Subtract value used by showIt and showSafeArea
Difference value used by showIt and showSafeArea
Disabled value used by showIt
Minimum number of horizontal crosshatch lines
Default number of horizontal crosshatch lines
Maximum number of horizontal crosshatch lines
These two give an action safe area of 93.5%,
consistent with EBU R 95
These two give an action safe area of 93%,
consistent with SMPTE RP 218, 2007-2008
These two give a title/action safe area of
90%, RP 218 - EBU R 95/legacy RP 218
These two give a title safe area of 80%,
consistent with legacy SMPTE RP 218
The next group of definitions only used to produce the 4x3 equivalents
EBU R 95 action
SMPTE RP 218 action
Legacy action/SMPTE RP 218 title/EBU R 95 title
Legacy title
These define the the edges of the 4:3
area on a 16:9 frame
Boundary of centre cross - 15% of screen height
Centre point
Line weight scale factor - this has been arbitrarily chosen
16x9 rounded down to give minimum identification
16x9 rounded up to give maximum ID
Pixel Shaders
Quit if the opacity is zero or we don't need to show the crosshatch pattern
Calculate the horizontal and vertical line weights
Get the integer value of the number of lines
Calculate the percentage increment to achieve that
Use this to offset lines so they stay centred
We set up this boolean here so we don't calculate it inside the loop
The loop executes a fixed amount to resolve a Windows compatibility issue.
The alternative would have been to build a unique Windows-specific version.
If there are an odd number of lines offset them by half the line spacing
This is really the first part of a compare operation
If we fall inside the line width turn the pixel on
To get the y value we must allow for the aspect ratio. This is a little complex because any scaling must be centred.
Repeat our line width boundary calculation from above.
Quit if the opacity is zero or the background is disabled
Set this next test up here so that we don't need to repeatedly do it
Skip this block if we don't need to show the centre 4x3 safe area
Left line outer edge
Left line inner edge
Right line inner edge
Right line outer edge
Safe line upper end
Safe line lower end
We show the 4x3 safe area as cyan. Because it's done here this also
puts the 4x3 area behind the standard 16x9 display.
Now we calculate the inner and outer rectangles for the real safe area.
After this i.x holds the leftmost inner edge, i.y the right, i.z the top,
and i.w the bottom. The o parameter holds the outer edge equivalents.
Work out what to display. The line width is obtained by excluding the
i (inner) area from the o (outer) area.
This is a duplicate of the routine used to show action safe, above.
These two aren't done as a function for reasons of speed of execution.
Now check to see if we show the centre cross
Calculate the horizontal size
Calculate the horizontal component
Calculate the vertical component
Finally show the 4x3 frame boundary if needed. This goes on top in red.
Left line outer edge
Left line inner edge
Right line inner edge
Right line outer edge
If the foreground is disabled we either show the background video or we show black.
If the background is disabled we show black or white, depending on the crosshatch polarity
Otherwise we get the background video and set the opacity values.
Now we calculate the crosshatch overlay. Only do this if opacity isn't zero and crosshatch isn't disabled.
Recover the crosshatch pattern
The level setting is applied at this point
This produces the actual crosshatch submaster, whether add, subtract or difference
This is the safe area display routine. Only do it if the safe area opacity isn't zero.
Recover the safe area display
Ensure that the alpha channel isn't zero