Expand description
Colour conversion between BGRA or RGBA pictures and I420.
Screen and camera pictures arrive as packed BGRA (the alpha byte is ignored); encoders take
I420. bgra_to_i420 scales and converts in one pass, fit and encode_size pick the
output size, and pack_rows removes row padding first. The opposite direction for display
is I420Frame::to_rgba.
Functions§
- bgra_
to_ i420 - Scales a packed BGRA picture (
src_w * 4bytes per row) into the box and converts it to I420 (BT.601 limited range). Luma is sampled per output pixel (nearest); chroma is the average of each 2×2 block of output pixels.Nonewhenfitdoes, or whensrcholds fewer thansrc_w * src_h * 4bytes. - encode_
size - Rounds a picture size down to what every encoder takes without padding: some hardware encoders (AMD AMF) pad widths to a multiple of 8 (a grey edge at the right), and I420 needs even sides. Pictures narrower than 8 pixels just get an even width (at least 2).
- fit
- Size that fits
srcinto the box with its aspect ratio kept, rounded down byencode_size. Never enlarges.Nonewhen a side ofsrcis 0 or a side of the box is below 2. - pack_
rows - Copies a BGRA picture with
stridebytes per row (rows may be padded) intooutas tight rows ofwidth * 4bytes, ready forbgra_to_i420.falsewhensrcis too short.