wai-rs: jpegai_pipeline::yuv_to_rgb / rgb_to_yuv — BT.709 colour combine #12

Merged
dcharlot merged 1 commit from feat/jpegai-color into main 2026-07-14 10:45:17 -04:00
Owner

The final pixel transform before the output image: BT.709 full-range YUV<->RGB (planes in [0,1], chroma +0.5 offset).

r = y + 1.5748·(v-½) ; b = y + 1.8556·(u-½)
g = y - (Kb·Kby/Kg)·(u-½) - (Kr·Kry/Kg)·(v-½)

rgb_to_yuv is the exact inverse. Validated vs a BT.709-formula golden (max|Δ|=1e-7) plus unit tests: greyscale (u=v=½→r=g=b=y) and rgb→yuv→rgb round-trip identity.

The final pixel transform before the output image: BT.709 full-range YUV<->RGB (planes in [0,1], chroma +0.5 offset). ``` r = y + 1.5748·(v-½) ; b = y + 1.8556·(u-½) g = y - (Kb·Kby/Kg)·(u-½) - (Kr·Kry/Kg)·(v-½) ``` rgb_to_yuv is the exact inverse. **Validated vs a BT.709-formula golden (max|Δ|=1e-7)** plus unit tests: greyscale (u=v=½→r=g=b=y) and rgb→yuv→rgb round-trip identity.
The final pixel transform before the output image: BT.709 full-range YUV↔RGB, planes
normalised to [0,1], chroma carrying the +0.5 offset.

  r = y + Kry·(v-½) ; b = y + Kby·(u-½)
  g = y - (Kb·Kby/Kg)·(u-½) - (Kr·Kry/Kg)·(v-½)
  (Kr,Kg,Kb,Kby,Kry = 0.2126, 0.7152, 0.0722, 1.8556, 1.5748)

rgb_to_yuv is the exact inverse (for round-trip / re-encode). Validated against a
BT.709-formula golden (max|Δ| = 1e-7) plus unit tests: greyscale (u=v=½ → r=g=b=y) and
rgb→yuv→rgb round-trip identity to float precision.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Transaction-Science/open-standards!12
No description provided.