Tint

From Avisynth wiki
Jump to: navigation, search

by actionman133

Tint () is designed to be a useful colour filter to be implemented for colour grading or correction in AVISynth. If you apply this function at full strengh (255) to a greyscale clip, you can create interesting colorizing effects.

Function Tint (clip Last, int color, int "strength") {

strength = Default (strength, 128)
hue = BlankClip (last, color = color, pixel_type = "YV12")

# get chroma on new tint
uhue = hue.UtoY ()
vhue = hue.VtoY ()

u = UtoY ()
v = VtoY ()

#set up mask. Assumes 0-255 RGB and 16-235 YUV.
mask = GreyScale ()
mask = mask.isYUV () ? mask.ColorYUV (levels = "tv->pc") : mask

# mask 1 reduces chroma impact in shadows
# mask 2 reduces chroma in highlights
mask1 = mask.Levels (0, 1, 127, 0, 255, false)
mask2 = mask.Levels (128, 1, 255, 255, 0, false)
maskmask = mask.Levels (127, 1, 128, 0, 255, false)
mask = Overlay (mask1, mask2, mask = maskmask).Levels (0, 1, 255, 0, strength, false)
mask =	isYUY2 () ? mask.BilinearResize (Width/2, Height) : \
	isYV12 () ? mask.BilinearResize (Width/2, Height/2) : mask
# mask combines the two masks and resizes to match chroma

# apply tints to the chroma channels
u1 = Overlay (u, uhue, mode = "luma", mask = mask)
v1 = Overlay (v, vhue, mode = "luma", mask = mask)

# mix new chroma into
YtoUV (u1, v1, last)

}

[edit] Example:

Tint ($FF7F00, 64) # warm tint for a late afternoon look.

[edit] Notes:

Due to Overlay's unpredictable behavior in RGB, this filter will only work with YUY2 and YV12 content. For RGB colour correction or grading, use RGBAdjust()

The color is expressed in hexadecimal. Check the colors_rgb.avsi file in the plugins folder for some common colours.

Personal tools