Skip to main content

Module yuv

Module yuv 

Source
Expand description

BT.601 YUV-to-BGRA conversion.

Fixed-point integer math matching the C# IthmbCodecPlugin.YuvUtils implementation bit-exactly.

§Math (BT.601-7)

R = Y + (Cr - 128) ×  359 ÷ 256
G = Y - (Cb - 128) ×   88 ÷ 256 - (Cr - 128) × 183 ÷ 256
B = Y + (Cb - 128) ×  454 ÷ 256

Division uses arithmetic right-shift (>> 8) to match C# semantics exactly: negative intermediates round toward negative infinity, not toward zero.

Constants§

B_COEF
Cb → B coefficient: 1.772 × 256 = 454 (truncated).
G_COEF_CB
Cb → G coefficient: −0.344 × 256 = −88 (truncated magnitude, sign handled in the expression as - ((cb_s * G_COEF_CB) >> 8) per the C# source).
G_COEF_CR
Cr → G coefficient: −0.714 × 256 = −183 (truncated magnitude).
R_COEF
Cr → R coefficient: 1.402 × 256 = 359 (truncated).

Functions§

clamp
Clamp an i32 to the inclusive [0, 255] range.
yuv_to_bgra
Convert a single BT.601 Y′CbCr triad to BGRA 8-bit.