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 ÷ 256Division 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
i32to the inclusive[0, 255]range. - yuv_
to_ bgra - Convert a single BT.601 Y′CbCr triad to BGRA 8-bit.