Avisynth Levels: Difference between revisions

From wiki.selur.net
Jump to navigation Jump to search
Avisynth filter documentation (via create-page on MediaWiki MCP Server)
 
Avisynth filter documentation (via update-page on MediaWiki MCP Server)
 
Line 27: Line 27:
| Output low/high || output_low / output_high || 0–255 || 0 / 255 || Values the input black and white are mapped to.
| Output low/high || output_low / output_high || 0–255 || 0 / 255 || Values the input black and white are mapped to.
|-
|-
| Gamma || gamma || 0–10 || 1.00 || Nonlinearity of the mapping; > 1 brightens, < 1 darkens. Use values above 0.
| Gamma || gamma || 0.01–10 || 1.00 || Nonlinearity of the mapping; > 1 brightens, < 1 darkens.
|-
|-
| Coring || coring || on/off || on || On: YUV input is clamped to limited range (luma 16–235, chroma 16–240), scaled to full range for the calculation and back afterwards. Off: only the transfer function is applied. Ignored for RGB.
| Coring || coring || on/off || on || On: YUV input is clamped to limited range (luma 16–235, chroma 16–240), scaled to full range for the calculation and back afterwards. Off: only the transfer function is applied. Ignored for RGB.
Line 37: Line 37:
Expanding limited range to full range (''Input'' 16/235, ''Output'' 0/255, ''Coring'' off) on a 10-bit YUV 4:2:0 source:
Expanding limited range to full range (''Input'' 16/235, ''Output'' 0/255, ''Coring'' off) on a 10-bit YUV 4:2:0 source:
<pre>
<pre>
Levels(64,1.00,940,0,1020,coring=false)
Levels(64,1.00,940,0,1023,coring=false)
</pre>
</pre>


== How Hybrid calls it ==
== How Hybrid calls it ==
* The level values are always entered on the 8-bit scale. Hybrid shifts them to the bit depth of the clip at the filter's position (×4 at 10 bit, ×256 at 16 bit), so 16 becomes 64 and 255 becomes 1020 at 10 bit.
* The level values are always entered on the 8-bit scale. Hybrid scales them to the bit depth of the clip at the filter's position: 255 becomes the format's maximum, other values are shifted (16 becomes 64 and 255 becomes 1023 at 10 bit); for 32-bit float they are divided by 255.
* The five numbers are always written, in AviSynth's order input_low, gamma, input_high, output_low, output_high. ''Coring'' and ''Dither'' are only written when they differ from the defaults.
* The five numbers are always written, in AviSynth's order input_low, gamma, input_high, output_low, output_high. ''Coring'' and ''Dither'' are only written when they differ from the defaults.
* Levels works on all color spaces and bit depths, so Hybrid inserts no conversion.
* Levels works on all color spaces and bit depths, so Hybrid inserts no conversion.

Latest revision as of 18:45, 21 November 2026

Levels adjusts brightness, contrast and gamma by remapping an input value range to an output value range. It is a core filter of AviSynth+, no plugin is needed.

Filtering → Avisynth → Color → Levels

Levels controls in Hybrid
Levels controls in Hybrid

What it does

All values between Input low and Input high are stretched (or compressed) to the range between Output low and Output high. Gamma bends the curve in between: values above 1.0 brighten the mid tones, values below 1.0 darken them. The transfer function is

output = ((input − input_low) / (input_high − input_low))^(1/gamma) × (output_high − output_low) + output_low

Typical uses:

  • Input 16/235 → Output 0/255 with Coring off: expand limited (TV) range to full (PC) range.
  • Input 0/255 → Output 16/235 with Coring off: squeeze full range into limited range.
  • Input 0/255 → Output 255/0: invert the image.
  • Gamma around 1.3: brighten a dark clip without moving black and white.

In YUV, gamma only acts on luma, but the range mapping also changes the chroma planes. For pure brightness/contrast changes in YUV, Tweak or ColorYUV are often the better choice.

Settings

Control Parameter Range Hybrid default Meaning
Input low/high input_low / input_high 0–255 0 / 255 Values that are treated as black and white.
Output low/high output_low / output_high 0–255 0 / 255 Values the input black and white are mapped to.
Gamma gamma 0.01–10 1.00 Nonlinearity of the mapping; > 1 brightens, < 1 darkens.
Coring coring on/off on On: YUV input is clamped to limited range (luma 16–235, chroma 16–240), scaled to full range for the calculation and back afterwards. Off: only the transfer function is applied. Ignored for RGB.
Dither dither on/off off Ordered dithering, against banding from strong changes at 8 bit.

Example

Expanding limited range to full range (Input 16/235, Output 0/255, Coring off) on a 10-bit YUV 4:2:0 source:

Levels(64,1.00,940,0,1023,coring=false)

How Hybrid calls it

  • The level values are always entered on the 8-bit scale. Hybrid scales them to the bit depth of the clip at the filter's position: 255 becomes the format's maximum, other values are shifted (16 becomes 64 and 255 becomes 1023 at 10 bit); for 32-bit float they are divided by 255.
  • The five numbers are always written, in AviSynth's order input_low, gamma, input_high, output_low, output_high. Coring and Dither are only written when they differ from the defaults.
  • Levels works on all color spaces and bit depths, so Hybrid inserts no conversion.
  • Levels also offers the common options and can be added to the filter queue several times.

Background

  • AviSynth+ does not scale the Levels parameters automatically; in a hand-written script they have to match the bit depth (0–1023 at 10 bit, 0–65535 at 16 bit, 0–1.0 for float). Hybrid does this scaling for you.
  • coring defaults to true only for compatibility with old scripts. Levels(0, 1.6, 255, 0, 255, coring=true) gives the same result as Levels(16, 1.6, 235, 16, 235, coring=false), except that the latter does not clip the output.
  • For gamma-correct fades the documentation suggests: Levels with a gamma, the fade, then Levels with the inverse gamma, preferably at 10 bit or more to avoid banding.

See also: Vapoursynth Levels, Avisynth SmoothLevels

Sources