Layer (aka overlay, blend, merge) two clips of possibly different sizes, but with the same color format.
For pixel-wise transparency information, the alpha channel of an RGBA overlay_clip is used as a mask.
Before Avisynth+ 3.4.0 Layer was working only for RGB32 and YUY2. Filter "Overlay" was used primarily for YUV. Now Layer accepts practically all formats (also RGB24/48 since v3.5).
Note that some modes can be similar to Overlay, but the two filters are still different.
Overlay accepts mask clip, Layer would use existing A plane.
Overlay "blend" is Layer "add", Overlay "add" is different.
Lighten and darken is a bit different in Overlay.
Layer has "placement" parameter for proper mask positioning over chroma.
Layer( clip base_clip, clip overlay_clip [, string op, int level, int x, int y, int threshold, bool use_chroma ] )
- clip base_clip =
- clip overlay_clip =
- The clip which is merged onto clip. If RGB32 or other alpha-aware color space, the alpha channel is used as a mask.
- Color format must match base_clip.
- Non-alpha plane YUV/planar RGB color spaces act as having a fully transparent alpha channel (like the former YUY2 only working mode)
- string op = "add"
- The merge operation to be performed, which can be one of the following:
|add|| This is the default mode. Equivalent to Overlay(mode="blend").|
overlay_clip will be copied on top of the original, in proportion to level, and subject to the alpha channel.
The difference between base_clip and overlay_clip is multiplied with alpha and added to base_clip.
Formula used :
|subtract|| base_clip minus overlay_clip. The same as add, but overlay_clip is inverted before adding.|
If both clips are equal and level=128, a flat gray field is returned; compare to Subtract.
|lighten|| Copy overlay_clip over base_clip in areas where overlay_clip is lighter by threshold. |
Performs the same operation as add, but only when overlay_clip is BRIGHTER than base_clip. use_chroma must be true.
|darken|| Copy overlay_clip over base_clip in areas where overlay_clip is darker by threshold. |
The same as "lighten", but it is performed only when overlay_clip is DARKER than base_clip. use_chroma must be true.
|mul|| base_clip multiplied by overlay_clip. This will generally make the output darker.
See GIMP: Multiply
|fast||Like add, but without masking. use_chroma must be true; level and threshold are not used. The result is simply the average of base_clip and overlay_clip.|
- int level = (maximum)
- int x = 0
- int y = 0
- offset position of overlay_clip
- int threshold = 0
- bool use_chroma = true
- Use chroma of the overlay_clip. Default=true. When false, only luma is used.
- Must be true for op = "darken", "lighten", "add."
- float opacity = 1.0
- usable for all bit depths, replaces the previous level parameter. Similar to "opacity" in "Overlay"
- valid values are 0.0 to 1.0. Default value is 1.0 if level does not exist (full transparency)
- If level parameter is given then opacity is calculated as:
- for color spaces having alpha: opacity = level / ((1 << bits_per_pixel) + 1) which gives 1.0 for level=257 (@8bit) and 65537 (@16 bits)
- for color spaces not having alpha: opacity = level / ((1 << bits_per_pixel)) e.g. for YUY2 or other non-Alpha, gives 1.0 for level=256 (@8bit)
- Note: originally level was used in formula: (alpha*level + 1) / range_size, now level is calculated from opacity as: level = opacity * ((1 << bits_per_pixel) + 1)
- string placement = "mpeg2"
There are some differences in the behaviour and the allowed parameter depending on the color format and the operation; here are the details:
- There is no mask (alpha channel) in YUY2, so the alpha channel is assumed to be fully opaque (255d) everywhere.
- In RGB32 the overlay_clip alpha channel is multiplied with level, so the resulting alpha is
- (alpha * level + 1) / 256.
- This means for full strength of operation, alpha has to be 255d and level has to be 257.
- alpha * opacity
- This means for full strength of operation, alpha has to be 255d and opacity has to be 1.0.
Applies a defined alpha-mask to a clip, by converting RGB32-only mask_clip to greyscale and copying that greyscale information to the alpha channel of RGB32-only clip. In the alpha channel, "black" means transparent and "white" means opaque. For those of you who familiar with Photoshop masks, the concept is the same. In fact you can create a black and white photo in Photoshop, load it in your script and use it as a mask.
Mask(clip clip, clip mask_clip)
- clip clip =
- clip mask_clip =
- Alpha-mask source, as described above. Size and color format must match clip.
Suppose "ss.jpg" is a snapshot from a video clip, which served as a guideline to create the mask using Paint. We use ImageSource to load the image in the script and Mask to apply it.
Applies an opaque (white) alpha channel to a clip. The alpha channel of an RGB32 clip is not always well-defined, depending on the source (it may contain random data); this filter is a fast way to apply an all-white mask.
- clip clip =
Clears pixels in the alpha channel by comparing to a transparent color (default black).
Each pixel with a color differing less than (tolB,tolR,tolG) (default 10d) is set to transparent (black); otherwise it is left unchanged – note, it is NOT set to opaque (white). That's why you might need ResetMask before applying this filter. This behaviour allows an aggregate mask to be constructed with multiple calls to ColorKeyMask.
When tolR or tolG are not set, they get the value of tolB by default. Normally you start with a ResetMask, then chain a few calls to ColorKeyMask to cause transparent holes where each color of interest occurs. See Overlay for examples.
ColorKeyMask(clip clip, int color [, int tolB, int tolG, int tolR])
- int color = black
- Transparent color. Default black.
- int tolB = 10d
- int tolG = (tolB)
- int tolR = (tolB)
- Color tolerance. See description above.
|v2.58||ColorKeyMask: Added separate tolerance levels.|