Skip to content
dnjulek edited this page Jul 7, 2026 · 1 revision

Bit-depth conversion with dithering — a port of fmtconv's fmtc.bitdepth plus the depth-dither modes from zimg (the engine behind resize.Point).

Converts a clip to another bit depth and/or sample type, applying a chosen dither pattern when reducing precision.

Usage

vszip.Dither(vnode clip, int bitdepth[, int dither_type=2, int sample_type, bint fulls, bint fulld])

Parameters

  • clip:
    Clip to process. 8-16 bit integer or 16/32-bit float, any planar/gray color family.

  • bitdepth:
    Target bit depth. Integer output: 8-16. Float output: 16 or 32.

  • sample_type: (Default: 1 (float) when bitdepth == 32, else 0 (integer))
    Output sample type: 0 = integer, 1 = float. A float output is only valid with bitdepth 16 or 32.

  • dither_type: (Default: 2)
    Dither pattern:

    # Mode Source
    0 Round (no dither) zimg/fmtc
    1 Ordered (Bayer) zimg
    2 Random (blue noise) zimg
    3 Error diffusion (Floyd-Steinberg) zimg
    4 Ordered (Bayer) fmtc
    5 FilterLite error diffusion fmtc
    6 Stucki error diffusion fmtc
    7 Atkinson error diffusion fmtc
    8 Floyd-Steinberg error diffusion fmtc
    9 Ostromoukhov error diffusion fmtc
    10 Void-and-cluster fmtc
    11 Quasirandom fmtc
  • fulls: (Default: True for RGB, else False)
    Treat the source as full range. When neither fulls nor fulld is set the source's range prop passes through unchanged.

  • fulld: (Default: same as fulls)
    Produce full-range output. If either fulls or fulld is given explicitly, the output's _ColorRange prop is stamped accordingly; otherwise the source prop is kept.

Notes

  • An identity conversion (same depth, sample type and range) is a pure passthrough for every mode — following zimg, dithering to the same depth only adds noise, so it is skipped.
  • Upconverting between limited-range integer depths is a pure bit-shift (no dither); dithering only kicks in when precision is actually reduced.

Examples

out = core.vszip.Dither(src, bitdepth=8)                       # 16 -> 8 bit, zimg random / blue noise (default)
out = core.vszip.Dither(src, bitdepth=8, dither_type=3)        # zimg error diffusion
out = core.vszip.Dither(src, bitdepth=10, dither_type=8)       # fmtc Floyd-Steinberg to 10 bit
out = core.vszip.Dither(src, bitdepth=32)                      # convert to 32-bit float
out = core.vszip.Dither(src, bitdepth=8, fulls=1, fulld=0)     # full -> limited range conversion

Clone this wiki locally