Linear-Light Matte Compositing and Chroma Subsampling for AVIF to JPEG
Eliminating Gamma-Darkened Seams When Flattening Transparency
Baseline baseline JFIF/JPEG bitstreams do not carry an alpha channel. Whenever a product cutout, sticker, or UI screenshot stored as RGBA AVIF is exported to JPG, transparent and semi-transparent pixels must be blended over a solid background color. Performing alpha interpolation directly on gamma-encoded sRGB bytes darkens mid-opacity transitions because sRGB follows a non-linear 2.4 power curve rather than physical photon intensity.
This workflow converts both foreground straight-alpha RGB and your chosen hex backdrop (#ffffff white by default) into linear light via an exact IEC 61966-2-1 lookup table, blends C_lin = C_fg * alpha + C_matte * (1 - alpha), and re-encodes sRGB bytes prior to MozJPEG compression. At quality 90 and above, chroma subsampling automatically switches from 4:2:0 to full-resolution 4:4:4 so saturated red or teal typography edges remain razor-sharp.
- Supports any 3-digit or 6-digit hex matte color alongside an A/B toggle between linear-light and direct sRGB blending.
- Automatic 4:4:4 YCbCr chroma retention at quality >= 90 prevents colored blockiness on synthetic edges.
- Outputs clean baseline/progressive JFIF segments with SOI (0xFFD8) and EOI (0xFFD9) markers free of private EXIF leaks.