Skip to main content

Module convert

Module convert 

Source
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 * 4 bytes 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. None when fit does, or when src holds fewer than src_w * src_h * 4 bytes.
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 src into the box with its aspect ratio kept, rounded down by encode_size. Never enlarges. None when a side of src is 0 or a side of the box is below 2.
pack_rows
Copies a BGRA picture with stride bytes per row (rows may be padded) into out as tight rows of width * 4 bytes, ready for bgra_to_i420. false when src is too short.