Joe Maller: FXScript Reference: Joe's Default Composite ControlsStep by step explanation of the compositing controls used in my FXScript filters for Final Cut Pro. |
|
|
Visit the New FXScript Reference and Joe's Filters sites. These pages will be phased out soon and may already be out of date. This page describes how I built the set of composite controls which appear in almost all of my filters. There are two versions of the composite controls set, the simple one, and one for YUVaware filters. Composite FoundationI've been working with Photoshop since 1992, maybe even earlier. When I started building my filters for Final Cut Pro and the time came to add compositing modes, the basic Photoshop set was a no-brainer.
Add and Subtract are not standard Photoshop composite modes, but back before the dawn of layers, we had to composite using Photoshop's Calculate command where Add and Subtract were options. They are also available in After Effects and common in most other image manipulation applications. Most of these modes were already supported in FXScript and work as expected. However a few modes required extra tweaking to preserve the source clip's alpha channel. Missing from the list are Soft Light and Hard Light. These modes are not supported by FXScript, but I'm looking into other ways of implementing them. Basic SetBelow is the code for the basic set of compositing controls. My filters place each if statement on it's own line, the statements are expanded here for clarity. In the Definition section of the script, add the following two inputs:
The In the following statements, the image buffer
There are two important things to note. First, Second is the extra code in My Difference hack implements opacity by first placing the straight 100% difference composite into I had to take the additional step of copying the alpha channel back into dest because Dealing with YUVSeveral of the built in composite modes do not cooperate with YUV information. Sending YUV data into Add, Subtract or Difference results in a disturbing mess of dark greens or bright pinks. These modes seem to operate on all the channels even though the result might push the image data beyond normal YUV amounts. The solution is simpler than it looks. The images need to be converted to RGB before processing, as discussed on the RGB and YUV page and the FXScript behind Joe's Color Glow, each conversion is wrapped in an if statement, which makes this look a lot worse than it really is. The first six composite modes are not affected by YUV image data, so only the last three need changing. In the following examples there are two additional image buffers, The code for the YUVaware Add composite mode works like this:
Add is the seventh item in the ApplyAs menu.
The above statement checks the format of the source image buffer. If that format is not RGB219, xbuffer2 is temporarily transferred to dest. Then the temporary contents of dest are converted back into xbuffer2 as RGB219. The following statement performs the same operation on the contents of xbuffer.
Now that both source image buffers are set to RGB219 and can be safely composited with Add, Subtract or Difference, the target image buffer needs to be formatted correctly. Because the target has nothing in it, it's format can be declared in one simple statement:
Finishing up the conversion requires a bit more buffer juggling. The filter will screw up if it ends with anything other than YUV219 (this is a DV bias). Since the data is now RGB219, the composite can end with a conversion where the result ends up in dest. To prepare for this, the script first transfers xbuffer2 back into dest.
Next, dest and xbuffer are added and the result is placed into xbuffer2.
Finally, the Add() composite is converted back to YUV219 and placed into the dest image buffer concluding the composite operation. All that's left is to close the original if statement.
Here is the code for Subtract in one code block. It is exactly the same except for the final compositing function.
Difference mode is also the same, except that it incorporates the alpha channel juggling mentioned at the end of the basic set of compositing controls.
ConclusionThese compositing controls appear in the majority of Joe's Filters. It might seem like a lot to think about, but in most instances everything on this page fits in a dozen lines of code. Repetition is not complexity, they only look alike from a distance. The unlocked set of Joe's Filters include the complete FXScript source code so you can see the composite controls in use. |
The FXScript ReferenceFXScripting Joe's FiltersJoe's Filters for Final Cut Pro Building Joe's Minimum Maximum Joe's FXScript ExplorersJoe's Debug and Explore Filters Joe's 3x3 Convolve Matrix Tester Joe's 3x3 Matrix Values Tester Other FCP Stuff
Film & VideoRecording the sound of PhotographyProjectsFinal Cut ProDesignWRITINGSite Notes Archive (weblog) Web ResourcesAbout Joe MallerPast Home Pages Etc.Search joemaller.comContact Me
|