TColorMask

From Avisynth wiki
Revision as of 17:24, 12 June 2022 by VoodooZX (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Abstract
Author tp7, Asd-g
Version v1.2.2
Download tcolormask-x86.zip // tcolormask-x64.zip
Category Masking
License GPLv2
Discussion

Contents

Description

TColorMask This is a port of the great tophf's script t_colormask. It masks colors but unlike the old ColorKeyMask it works on YV12. The main reason for this plugin is performance. The API and output are not identical, please refer to the Difference section for details.



Requirements


Syntax and Parameters

tcolormask(clip, string "colors, int "tolerance", bool "bt601", bool "gray", int "lutthr", bool "mt", bool "onlyY", int "opt")


clip   =
A clip to process.
Must be in YUV420/422/444 8/16-bit planar format.


string  colors = ""
String of colors. Line and block comments are allowed.


int  tolerance = 10(8-bit) / 2570(16-bit)
Pixel value will pass if its absolute difference with color is less than tolerance (luma) or half the tolerance (chroma).
It must be between 0 and 255/65535.


bool  bt601 = false
Use bt601 matrix for conversion of colors.


bool  gray = false
Set chroma of output clip to 128/32896.


int  lutthr = 9
If specified more than lutthr colors, LUT will be used instead of direct SIMD computations.


bool  mt = false
Enable multithreading. It actually uses only two threads as any more threading doesn't seem to be useful.


bool  onlyY = false
The returned clip format is Y.


int  opt = -1
-1: Auto-detect.
0: Use C++ code.
1: Use SSE2 code.
2: Use AVX2 code.
3: Use AVX512 code.


Difference

Unlike the old script, this plugin uses a single string to specify all colors and doesn't do any blurring. Wrapper functions are provided for convenience in the bin/tcolormask_wrappers.avs script.

Also since we process chroma and luma together to avoid having to merge planes later, output is not identical. Basically it appears a bit less blurred and doesn't contain any non-binary values produced by chroma resizing. This will not be fixed and there's no workaround. You'll most likely be blurring the output clip anyway.

Performance

This plugin uses direct SIMD computations to do its dirty work. SIMD appears to be faster than LUT for the most common cases, but unfortunately its speed depends on the number of specified colors and at some point it does get slower than LUT. That's why the alternative is also provided. If specified more than lutthr (9 by default) colors, the plugin will use the LUT routine to avoid performance degradation.

See performance table on GitHub.

Examples

tcolormask with default values, except colors:

AviSource("bah.avi")
tcolormask("$E0C0AB", tolerance=10, bt601=false, gray=false, lutthr=9, mt=true)


Changelog

Version      Date            Changes
v1.2.2 2022/06/11 - grayscale and 'onlyY' cannot be true in the same time. (Asd-g) - Added AVX512 code. (Asd-g) v1.2.1 2022/06/10 - Registered as MT_NICE_FILTER. (tp7) - Disabled internal 'MT' by default. (tp7) - Fixed YV12 processing. (tp7) - Added support for frame properties passthrough. (Asd-g) - Fixed the right side when width is not mod16. (Asd-g) - Non-mod2 chroma height for YV12 and mt=true are not allowed. (Asd-g) - Added C and AVX2 code. (Asd-g) - Added 'opt' parameter. (Asd-g) - Added support for 16-bit clips. (Asd-g) - Added 'onlyY' parameter. (Asd-g) - Added binary version. (Asd-g) v1.2 2013/11/30 - x64 build added. - Function from tcolormask_wrappers will not work with x64 build of AviSynth+. v1.1 2013/07/26 - This plugin now only works with AviSynth 2.6 alpha 4. If you need support for older versions, download v1.0.1. - Also, YV16 colorspace is now supported. v1.0 2013/07/08 - Actually working now.


External Links

  • GitHub - Source code repository by tp7.
  • GitHub - Source code repository by Asd-g.




Back to External Filters

Personal tools