Documentation
¶
Overview ¶
Package loopfilter implements the VP9 deblocking loop filter (spec §8.8). All filter kernels operate on byte slices addressed via a step parameter, which allows the same code to handle both horizontal and vertical edges:
- horizontal edge: step = 1 (consecutive bytes in a row)
- vertical edge: step = stride (bytes to the next row)
The four filter widths:
filter4 – 4-tap narrow (inner 4×4 sub-block edges) filter8 – 8-tap wide (TX-block edges, luma/chroma) filter16 – 14-tap (super-block / large TX edges)
Index ¶
- Variables
- func FilterEdge4(buf []byte, q0, step, width int, p Params)
- func FilterEdge4_16(buf []uint16, q0, step, width int, p Params)
- func FilterFrame(buf []byte, stride, w4, h4, sbN4, sharpness int, ...)
- func FilterFrame16(buf []uint16, stride, w4, h4, sbN4, sharpness int, ...)
- func FilterPlane(buf []byte, stride, width, height, bsLog2 int, p Params)
- func FilterPlaneWithLevels(buf []byte, stride, width, height, bsLog2 int, ...)
- func LevelForBlock(baseLevel int, segLFActive bool, segLFDelta int16, deltaEnabled bool, ...) int
- func SetBitDepth16(bd int)
- type Params
Constants ¶
This section is empty.
Variables ¶
var ( DumpW io.Writer DumpPlane int )
DumpW/DumpPlane: debug edge-trace hook. When DumpW != nil, FilterFrame writes one line per filtered edge ("<plane> <V|H> <y> <x> <width>") to compare the edge-selection against libvpx's instrumented loop filter.
Functions ¶
func FilterEdge4 ¶
FilterEdge4 filters a single 4-sample edge in buf at position q0 (index of the first sample on the "right/below" side of the edge). step is the address step between consecutive samples (1 for horizontal, stride for vertical). Requires buf[q0-4*step..q0+3*step] to be valid. width (flat filter) and wide (flat2 filter) select the kernel:
width=4: 4-tap narrow only width=8: 8-tap if flat, else 4-tap narrow width=16: 14-tap if flat2, 8-tap if flat, else 4-tap narrow
func FilterEdge4_16 ¶ added in v0.2.0
FilterEdge4_16 is FilterEdge4 for the high-bit-depth uint16 path.
func FilterFrame ¶ added in v0.2.0
func FilterFrame(buf []byte, stride, w4, h4, sbN4, sharpness int, infoAt func(r4, c4 int) (level int, txSize uint8, skipLF, predH, predV bool))
FilterFrame applies the VP9 loop filter to one plane in libvpx's order: superblock by superblock (raster), and within each SB ALL vertical edges then ALL horizontal edges. sbN4 is the superblock size in 4×4 units for this plane (16 for luma 64-px SBs, 8 for 4:2:0 chroma). This matters at SB boundaries, where a later SB's vertical edge reads the previous SB's already horizontally-filtered pixels. infoAt(r4,c4) returns the block's loop-filter level and transform size (for this plane) covering 4×4 (r4,c4).
An edge at the left/top of (r4,c4) is on a transform boundary iff the coordinate is a multiple of the block's TX size in 4×4 units (that subsumes prediction-block boundaries).
func FilterFrame16 ¶ added in v0.2.0
func FilterPlane ¶
FilterPlane applies the VP9 loop filter to one luma or chroma plane.
Each 4x4 block's edge is filtered with the given Params. For simplicity this API takes a uniform Params for the whole plane; a full implementation would supply per-block params derived from filter_level, ref_delta, etc.
The filter visits:
- All vertical edges (column boundaries at multiples of 4, left to right).
- All horizontal edges (row boundaries at multiples of 4, top to bottom).
For each 4-pixel column/row along an edge the EdgeWidth function determines which kernel to apply (4, 8, or 16 wide) based on the block size at that edge (bsLog2: 1=8px, 2=16px, 3=32/64px boundary).
buf – plane pixel data, row-major. stride – row stride in bytes (may be > width). width, height – plane dimensions in pixels. bsLog2 – log2 of the superblock size in pixels (2=4px blocks, 3=8px…).
Controls whether the wider 8/14-tap filters are engaged. Pass 2 for chroma or for simple filter mode.
func FilterPlaneWithLevels ¶
func FilterPlaneWithLevels(buf []byte, stride, width, height, bsLog2 int, paramsAt func(row4, col4 int) Params)
FilterPlaneWithLevels applies the VP9 loop filter with per-4×4-block level lookup. paramsAt(row4, col4) returns the Params for the block at that 4×4 grid position. Blocks with level=0 produce Params{} from paramsAt; FilterEdge4 no-ops when BLimit=0.
func LevelForBlock ¶
func LevelForBlock( baseLevel int, segLFActive bool, segLFDelta int16, deltaEnabled bool, refFrame int, isInter bool, isZeroMV bool, refDeltas [4]int, modeDeltas [2]int, ) int
LevelForBlock computes the per-block loop filter level (spec §8.8.1 / libvpx vp9_loop_filter.c).
segLFActive: SEG_LVL_ALT_LF is enabled for this block's segment. segLFDelta: the segment's LF delta (always additive, never absolute). deltaEnabled: frame-level mode_ref_delta_enabled flag. refFrame: 0=INTRA, 1=LAST, 2=GOLDEN, 3=ALTREF. isZeroMV: inter block with zero MV (uses modeDeltas[0], else modeDeltas[1]).
func SetBitDepth16 ¶ added in v0.2.0
func SetBitDepth16(bd int)
SetBitDepth16 configures the highbd loop-filter parameters for bit depth bd.
Types ¶
type Params ¶
type Params struct {
Limit uint8 // interior flatness threshold (lim_lut)
BLimit uint8 // block-edge threshold (2*limit + level)
Thresh uint8 // HEV threshold (thresh_lut)
}
Params holds the per-edge filter thresholds derived from a filter level.
func ParamsForLevel ¶
ParamsForLevel returns filter thresholds for level ∈ [0,63] and sharpness ∈ [0,7] (spec §8.8.3).