LibGfx: Implement YUV->RGBA color conversion for CPU painting

Using the Rust yuv crate, eagerly convert from YUV to RGBA on the CPU
when a GPU context is unavailable.

Time spent converting an 8-bit YUV frame with this crate is better than
libyuv on ARM by about 20%, and on x86 with AVX2, it achieves similar
numbers to libyuv.
This commit is contained in:
Zaggy1024
2026-04-16 20:43:09 -05:00
committed by Gregory Bertilson
parent f434b56ffa
commit 3cfe1f7542
Notes: github-actions[bot] 2026-04-18 06:25:55 +00:00
11 changed files with 477 additions and 2 deletions

View File

@@ -208,8 +208,10 @@ ErrorOr<NonnullRefPtr<ImmutableBitmap>> ImmutableBitmap::create_from_yuv(Nonnull
auto context = SkiaBackendContext::the();
auto* gr_context = context ? context->sk_context() : nullptr;
if (!gr_context)
return Error::from_string_literal("GPU context is unavailable");
if (!gr_context) {
auto bitmap = TRY(yuv_data->to_bitmap());
return create(move(bitmap), move(color_space));
}
if (yuv_data->bit_depth() > 8)
yuv_data->expand_samples_to_full_16_bit_range();