use super::{
ChromaSitingChanged,
GeometryOverflow,
HsvFrameMut,
InsufficientBuffer,
MixedSinker,
MixedSinkerError,
NativeRouteChanged,
RowIndexOutOfRange,
RowShapeMismatch,
RowSlice,
WidthAlignment,
check_dimensions_match,
check_frozen_alpha_mode,
chroma_420_bottom_sited_v,
chroma_420_center_sited_h,
chroma_420_top_sited_v,
deinterleave_y_high_bit_masked,
packed_yuva444_filter_resample,
packed_yuva444_resample,
planar_8bit::{
YUV422P_CENTERED_H_PHASE, reserve_420_chroma_full, reserve_420_chroma_prev,
stage_420_chroma_prev, upsample_420_chroma_sited, yuva420p_process_native,
},
reset_high_bit_yuva_streams,
rgb_row_buf_or_scratch,
rgba_plane_row_slice,
rgba_u16_plane_row_slice,
subsampled_4_2_0_high_bit::{
reserve_420_chroma_prev_u16, stage_420_chroma_prev_u16, upsample_420_chroma_sited_u16,
},
};
use crate::{
PixelSink,
resample::{
AveragingDomain, InsertionContext, InsertionPoint, PlanGeometry, ResampleError,
select_insertion_point,
},
row::*,
source::*,
};
const YUVA420P_STRAIGHT_NATIVE_ELIGIBLE: bool = true;
fn reserve_420_chroma_full_u16(
chroma_full: &mut std::vec::Vec<u16>,
width: usize,
height: usize,
) -> Result<(), MixedSinkerError> {
#[cfg(all(test, feature = "std", feature = "yuv-planar"))]
if super::FORCE_CHROMA_FULL_ALLOC_FAILURE.with(|f| f.take()) {
return Err(MixedSinkerError::Resample(ResampleError::AllocationFailed(
PlanGeometry::new(width, height, width, height),
)));
}
let needed = width
.checked_mul(2)
.ok_or(MixedSinkerError::GeometryOverflow(GeometryOverflow::new(
width, height, 2,
)))?;
if chroma_full.len() < needed {
chroma_full
.try_reserve_exact(needed - chroma_full.len())
.map_err(|_| {
MixedSinkerError::Resample(ResampleError::AllocationFailed(PlanGeometry::new(
width, height, width, height,
)))
})?;
chroma_full.resize(needed, 0);
}
Ok(())
}
fn reserve_420_chroma_top_u16(
buf: &mut std::vec::Vec<u16>,
width: usize,
height: usize,
) -> Result<(), MixedSinkerError> {
if buf.len() < width {
buf.try_reserve_exact(width - buf.len()).map_err(|_| {
MixedSinkerError::Resample(ResampleError::AllocationFailed(PlanGeometry::new(
width, height, width, height,
)))
})?;
buf.resize(width, 0);
}
Ok(())
}
fn reserve_420_chroma_top_u8(
buf: &mut std::vec::Vec<u8>,
width: usize,
height: usize,
) -> Result<(), MixedSinkerError> {
if buf.len() < width {
buf.try_reserve_exact(width - buf.len()).map_err(|_| {
MixedSinkerError::Resample(ResampleError::AllocationFailed(PlanGeometry::new(
width, height, width, height,
)))
})?;
buf.resize(width, 0);
}
Ok(())
}
#[allow(clippy::too_many_arguments, clippy::type_complexity)]
fn yuva444p_high_bit_top_identity_color_row<const BITS: u32, const BE: bool>(
rgb: &mut Option<&mut [u8]>,
rgba: &mut Option<&mut [u8]>,
rgb_u16: &mut Option<&mut [u16]>,
rgba_u16: &mut Option<&mut [u16]>,
hsv: &mut Option<HsvFrameMut<'_>>,
rgb_scratch: &mut std::vec::Vec<u8>,
y: &[u16],
a: &[u16],
u_full: &[u16],
v_full: &[u16],
one_plane_start: usize,
one_plane_end: usize,
w: usize,
h: usize,
matrix: crate::KernelMatrix,
full_range: bool,
use_simd: bool,
rgb_444_dispatch: fn(
&[u16],
&[u16],
&[u16],
&mut [u8],
usize,
crate::KernelMatrix,
bool,
bool,
bool,
),
rgb_u16_444_dispatch: fn(
&[u16],
&[u16],
&[u16],
&mut [u16],
usize,
crate::KernelMatrix,
bool,
bool,
bool,
),
rgba_444_dispatch: fn(
&[u16],
&[u16],
&[u16],
&[u16],
&mut [u8],
usize,
crate::KernelMatrix,
bool,
bool,
bool,
),
hsv_444_dispatch: fn(
&[u16],
&[u16],
&[u16],
&mut [u8],
&mut [u8],
&mut [u8],
usize,
crate::KernelMatrix,
bool,
bool,
bool,
),
rgba_u16_444_dispatch: fn(
&[u16],
&[u16],
&[u16],
&[u16],
&mut [u16],
usize,
crate::KernelMatrix,
bool,
bool,
bool,
),
) -> Result<(), MixedSinkerError> {
let want_rgb = rgb.is_some();
let want_rgba = rgba.is_some();
let want_hsv = hsv.is_some();
let want_rgb_u16 = rgb_u16.is_some();
let want_rgba_u16 = rgba_u16.is_some();
if want_rgb_u16 {
let buf = rgb_u16.as_deref_mut().unwrap();
let rgb_plane_end = one_plane_end
.checked_mul(3)
.ok_or(MixedSinkerError::GeometryOverflow(GeometryOverflow::new(
w, h, 3,
)))?;
let rgb_plane_start = one_plane_start * 3;
let rgb_u16_row = &mut buf[rgb_plane_start..rgb_plane_end];
rgb_u16_444_dispatch(
y,
u_full,
v_full,
rgb_u16_row,
w,
matrix,
full_range,
use_simd,
BE,
);
if want_rgba_u16 {
let rgba_buf = rgba_u16.as_deref_mut().unwrap();
let rgba_u16_row = rgba_u16_plane_row_slice(rgba_buf, one_plane_start, one_plane_end, w, h)?;
expand_rgb_u16_to_rgba_u16_row::<BITS>(rgb_u16_row, rgba_u16_row, w);
crate::row::alpha_extract::copy_alpha_plane_u16::<BITS, BE>(a, rgba_u16_row, w, use_simd);
}
} else if want_rgba_u16 {
let rgba_buf = rgba_u16.as_deref_mut().unwrap();
let rgba_u16_row = rgba_u16_plane_row_slice(rgba_buf, one_plane_start, one_plane_end, w, h)?;
rgba_u16_444_dispatch(
y,
u_full,
v_full,
a,
rgba_u16_row,
w,
matrix,
full_range,
use_simd,
BE,
);
}
let want_hsv_direct = want_hsv && !want_rgb && !want_rgba;
let need_rgb_kernel = want_rgb || (want_hsv && want_rgba);
if want_hsv_direct {
let hsv = hsv.as_mut().expect("want_hsv_direct implies hsv attached");
let (hh, ss, vv) = hsv.hsv();
hsv_444_dispatch(
y,
u_full,
v_full,
&mut hh[one_plane_start..one_plane_end],
&mut ss[one_plane_start..one_plane_end],
&mut vv[one_plane_start..one_plane_end],
w,
matrix,
full_range,
use_simd,
BE,
);
return Ok(());
}
if want_rgba && !need_rgb_kernel {
let rgba_buf = rgba.as_deref_mut().unwrap();
let rgba_row = rgba_plane_row_slice(rgba_buf, one_plane_start, one_plane_end, w, h)?;
rgba_444_dispatch(
y, u_full, v_full, a, rgba_row, w, matrix, full_range, use_simd, BE,
);
return Ok(());
}
if !need_rgb_kernel {
return Ok(());
}
let rgb_row = rgb_row_buf_or_scratch(
rgb.as_deref_mut(),
rgb_scratch,
one_plane_start,
one_plane_end,
w,
h,
)?;
rgb_444_dispatch(
y, u_full, v_full, rgb_row, w, matrix, full_range, use_simd, BE,
);
if let Some(hsv) = hsv.as_mut() {
let (hh, ss, vv) = hsv.hsv();
rgb_to_hsv_row(
rgb_row,
&mut hh[one_plane_start..one_plane_end],
&mut ss[one_plane_start..one_plane_end],
&mut vv[one_plane_start..one_plane_end],
w,
use_simd,
);
}
if want_rgba {
let rgba_buf = rgba.as_deref_mut().unwrap();
let rgba_row = rgba_plane_row_slice(rgba_buf, one_plane_start, one_plane_end, w, h)?;
expand_rgb_to_rgba_row(rgb_row, rgba_row, w);
crate::row::alpha_extract::copy_alpha_plane_u16_to_u8::<BITS, BE>(a, rgba_row, w, use_simd);
}
Ok(())
}
#[allow(clippy::too_many_arguments)]
fn yuva444_top_identity_color_row(
rgb: &mut Option<&mut [u8]>,
rgba: &mut Option<&mut [u8]>,
hsv: &mut Option<HsvFrameMut<'_>>,
rgb_scratch: &mut std::vec::Vec<u8>,
y: &[u8],
a: &[u8],
u_full: &[u8],
v_full: &[u8],
one_plane_start: usize,
one_plane_end: usize,
w: usize,
h: usize,
matrix: crate::KernelMatrix,
full_range: bool,
use_simd: bool,
) -> Result<(), MixedSinkerError> {
let want_rgb = rgb.is_some();
let want_rgba = rgba.is_some();
let want_hsv = hsv.is_some();
let want_hsv_direct = want_hsv && !want_rgb && !want_rgba;
let need_rgb_kernel = want_rgb || (want_hsv && want_rgba);
if want_hsv_direct {
let hsv = hsv.as_mut().expect("want_hsv_direct implies hsv attached");
let (hh, ss, vv) = hsv.hsv();
yuv_444_to_hsv_row(
y,
u_full,
v_full,
&mut hh[one_plane_start..one_plane_end],
&mut ss[one_plane_start..one_plane_end],
&mut vv[one_plane_start..one_plane_end],
w,
matrix,
full_range,
use_simd,
);
return Ok(());
}
if want_rgba && !need_rgb_kernel {
let rgba_buf = rgba.as_deref_mut().unwrap();
let rgba_row = rgba_plane_row_slice(rgba_buf, one_plane_start, one_plane_end, w, h)?;
yuva444p_to_rgba_row(
y, u_full, v_full, a, rgba_row, w, matrix, full_range, use_simd,
);
return Ok(());
}
if !need_rgb_kernel {
return Ok(());
}
let rgb_row = rgb_row_buf_or_scratch(
rgb.as_deref_mut(),
rgb_scratch,
one_plane_start,
one_plane_end,
w,
h,
)?;
yuv_444_to_rgb_row(y, u_full, v_full, rgb_row, w, matrix, full_range, use_simd);
if let Some(hsv) = hsv.as_mut() {
let (hh, ss, vv) = hsv.hsv();
rgb_to_hsv_row(
rgb_row,
&mut hh[one_plane_start..one_plane_end],
&mut ss[one_plane_start..one_plane_end],
&mut vv[one_plane_start..one_plane_end],
w,
use_simd,
);
}
if want_rgba {
let rgba_buf = rgba.as_deref_mut().unwrap();
let rgba_row = rgba_plane_row_slice(rgba_buf, one_plane_start, one_plane_end, w, h)?;
expand_rgb_to_rgba_row(rgb_row, rgba_row, w);
crate::row::alpha_extract::copy_alpha_plane_u8(a, rgba_row, w, use_simd);
}
Ok(())
}
impl<'a, R> MixedSinker<'a, Yuva420p, R> {
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn with_rgba(mut self, buf: &'a mut [u8]) -> Result<Self, MixedSinkerError> {
self.set_rgba(buf)?;
Ok(self)
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn set_rgba(&mut self, buf: &'a mut [u8]) -> Result<&mut Self, MixedSinkerError> {
let expected = self.frame_elems(4)?;
if buf.len() < expected {
return Err(MixedSinkerError::InsufficientRgbaBuffer(
InsufficientBuffer::new(expected, buf.len()),
));
}
self.rgba = Some(buf);
Ok(self)
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn with_luma_u16(mut self, buf: &'a mut [u16]) -> Result<Self, MixedSinkerError> {
self.set_luma_u16(buf)?;
Ok(self)
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn set_luma_u16(&mut self, buf: &'a mut [u16]) -> Result<&mut Self, MixedSinkerError> {
let expected = self.frame_pixels()?;
if buf.len() < expected {
return Err(MixedSinkerError::InsufficientLumaU16Buffer(
InsufficientBuffer::new(expected, buf.len()),
));
}
self.luma_u16 = Some(buf);
Ok(self)
}
}
impl<R> Yuva420pSink for MixedSinker<'_, Yuva420p, R> {}
impl<R> PixelSink for MixedSinker<'_, Yuva420p, R> {
type Input<'r> = Yuva420pRow<'r>;
type Error = MixedSinkerError;
#[cfg_attr(not(tarpaulin), inline(always))]
fn kernel_matrix(&self) -> crate::KernelMatrix {
self.kernel_matrix
}
fn begin_frame(&mut self, width: u32, height: u32) -> Result<(), Self::Error> {
if self.width & 1 != 0 {
return Err(MixedSinkerError::WidthAlignment(WidthAlignment::odd(
self.width,
)));
}
check_dimensions_match(self.width, self.height, width, height)?;
if let Some(stream) = self.rgba_stream.as_mut() {
stream.reset();
}
if let Some(stream) = self.luma_stream_u16.as_mut() {
stream.reset();
}
if let Some(stream) = self.rgba_filter_stream.as_mut() {
stream.reset();
}
if let Some(stream) = self.luma_filter_stream.as_mut() {
stream.reset();
}
if let Some(native) = self.native_yuva_420.as_mut() {
native.reset();
}
self.frozen_native_route = None;
self.resample_outputs = None;
self.frozen_chroma_centered = None;
self.frozen_chroma_bottom_v = None;
self.chroma_prev_row = None;
self.frozen_chroma_top_v = None;
self.chroma_top_pending = None;
self.frozen_alpha_mode = Some(self.alpha_mode);
Ok(())
}
fn process(&mut self, row: Yuva420pRow<'_>) -> Result<(), Self::Error> {
let w = self.width;
let h = self.height;
let idx = row.row();
let use_simd = self.simd;
let chroma_location = self.chroma_location.clone();
if w & 1 != 0 {
return Err(MixedSinkerError::WidthAlignment(WidthAlignment::odd(w)));
}
if row.y().len() != w {
return Err(MixedSinkerError::RowShapeMismatch(RowShapeMismatch::new(
RowSlice::Y,
idx,
w,
row.y().len(),
)));
}
if row.u_half().len() != w / 2 {
return Err(MixedSinkerError::RowShapeMismatch(RowShapeMismatch::new(
RowSlice::UHalf,
idx,
w / 2,
row.u_half().len(),
)));
}
if row.v_half().len() != w / 2 {
return Err(MixedSinkerError::RowShapeMismatch(RowShapeMismatch::new(
RowSlice::VHalf,
idx,
w / 2,
row.v_half().len(),
)));
}
if row.a().len() != w {
return Err(MixedSinkerError::RowShapeMismatch(RowShapeMismatch::new(
RowSlice::AFull,
idx,
w,
row.a().len(),
)));
}
if idx >= self.height {
return Err(MixedSinkerError::RowIndexOutOfRange(
RowIndexOutOfRange::new(idx, self.height),
));
}
if self.plan.is_some() {
let alpha_mode = self.alpha_mode;
let matrix = row.matrix();
let full_range = row.full_range();
let y = row.y();
let u_half = row.u_half();
let v_half = row.v_half();
let a = row.a();
let Self {
rgb,
rgba,
rgb_u16,
rgba_u16,
luma,
luma_u16,
hsv,
rgba_scratch,
rgb_scratch,
rgba_scratch_u16,
rgba_color_scratch_u16,
luma_scratch_u16,
chroma_full,
plan,
rgba_stream,
rgba_stream_u16,
luma_stream_u16,
rgba_filter_stream,
rgba_filter_stream_u16,
luma_filter_stream,
luma_filter_stream_u16,
resample_outputs,
frozen_alpha_mode,
native,
native_yuva_420,
frozen_native_route,
frozen_chroma_centered,
frozen_chroma_bottom_v,
frozen_chroma_top_v,
chroma_prev,
chroma_prev_row,
chroma_top_pending,
chroma_top_y,
chroma_top_a,
..
} = self;
let plan = plan.as_ref().expect("plan.is_some() checked above");
check_frozen_alpha_mode(*frozen_alpha_mode, alpha_mode, idx)?;
let center_sited = chroma_420_center_sited_h(&chroma_location);
let bottom_v = chroma_420_bottom_sited_v(&chroma_location);
let top_v = chroma_420_top_sited_v(&chroma_location);
let chroma_h_phase = if center_sited {
YUV422P_CENTERED_H_PHASE
} else {
0.0
};
let chroma_v_phase = if bottom_v { 1.0 } else { 0.0 };
let need_output =
rgb.is_some() || rgba.is_some() || hsv.is_some() || luma.is_some() || luma_u16.is_some();
let want_color = rgb.is_some() || rgba.is_some() || hsv.is_some();
if need_output
&& let Some(frozen) = *frozen_chroma_centered
&& (frozen != center_sited
|| *frozen_chroma_bottom_v != Some(bottom_v)
|| *frozen_chroma_top_v != Some(top_v))
{
return Err(MixedSinkerError::ChromaSitingChanged(
ChromaSitingChanged::new(idx),
));
}
return match plan.kind() {
crate::resample::SpanKind::Area => {
let insertion = select_insertion_point(
AveragingDomain::Encoded,
InsertionContext {
native_eligible: YUVA420P_STRAIGHT_NATIVE_ELIGIBLE && !alpha_mode.is_premultiplied(),
with_native: *native,
area_plan: true,
},
);
let take_native = matches!(insertion, InsertionPoint::NativeCodes);
if need_output
&& let Some(frozen) = *frozen_native_route
&& frozen != take_native
{
return Err(MixedSinkerError::NativeRouteChanged(
NativeRouteChanged::new(idx),
));
}
match insertion {
InsertionPoint::NativeCodes => {
let stale_native = idx == 0
&& native_yuva_420.as_ref().is_some_and(|join| {
join.has_chroma()
&& (join.chroma_centered() != center_sited
|| join.chroma_bottom() != bottom_v
|| join.chroma_top() != top_v)
&& join.next_y() == 0
});
let prev_native = if stale_native {
native_yuva_420.take()
} else {
None
};
let native_result = yuva420p_process_native(
plan,
native_yuva_420,
resample_outputs,
rgb,
rgba,
luma,
luma_u16,
hsv,
rgb_scratch,
y,
u_half,
v_half,
a,
matrix,
full_range,
idx,
w,
h,
chroma_h_phase,
chroma_v_phase,
top_v,
use_simd,
);
if stale_native && native_result.is_err() {
*native_yuva_420 = prev_native;
}
native_result?;
if frozen_native_route.is_none() && need_output {
*frozen_native_route = Some(true);
}
if frozen_chroma_centered.is_none() && need_output {
*frozen_chroma_centered = Some(center_sited);
*frozen_chroma_bottom_v = Some(bottom_v);
*frozen_chroma_top_v = Some(top_v);
}
Ok(())
}
InsertionPoint::EncodedOutput => {
if top_v && want_color {
let cursor = rgba_stream.as_ref().map_or(0, |s| s.next_y());
let expected_source = cursor + usize::from(chroma_top_pending.is_some());
if let core::ops::ControlFlow::Break(()) = super::resample_preflight_check_only(
resample_outputs,
luma,
luma_u16,
rgb,
rgba,
&None,
&None,
&None,
&None,
&None,
&None,
&None,
hsv,
&None,
Some(expected_source),
idx,
)? {
return Ok(());
}
reserve_420_chroma_full(chroma_full, w, h)?;
reserve_420_chroma_prev(chroma_prev, w, h)?;
reserve_420_chroma_top_u8(chroma_top_y, w, h)?;
reserve_420_chroma_top_u8(chroma_top_a, w, h)?;
let is_last = idx + 1 == h;
if idx & 1 == 0 {
if let Some((p_idx, p_matrix, p_full_range)) = chroma_top_pending.take() {
let (u_full, v_full) = upsample_420_chroma_sited(
chroma_full,
chroma_prev,
chroma_prev_row,
u_half,
v_half,
idx,
true,
center_sited,
false,
w,
use_simd,
);
let held_y: &[u8] = &chroma_top_y[..w];
let held_a: &[u8] = &chroma_top_a[..w];
packed_yuva444_resample::<8>(
rgba_stream,
rgba_stream_u16,
luma_stream_u16,
resample_outputs,
rgb,
rgba,
rgb_u16,
rgba_u16,
luma,
luma_u16,
hsv,
rgba_scratch,
rgb_scratch,
rgba_scratch_u16,
rgba_color_scratch_u16,
luma_scratch_u16,
w,
plan,
p_idx,
use_simd,
alpha_mode,
|dst| {
yuva444p_to_rgba_row(
held_y,
u_full,
v_full,
held_a,
dst,
w,
p_matrix,
p_full_range,
use_simd,
)
},
|_dst: &mut [u16]| {},
|dst| {
for (d, &s) in dst.iter_mut().zip(held_y) {
*d = s as u16;
}
},
)?;
}
let (u_full, v_full) = upsample_420_chroma_sited(
chroma_full,
chroma_prev,
chroma_prev_row,
u_half,
v_half,
idx,
false,
center_sited,
false,
w,
use_simd,
);
packed_yuva444_resample::<8>(
rgba_stream,
rgba_stream_u16,
luma_stream_u16,
resample_outputs,
rgb,
rgba,
rgb_u16,
rgba_u16,
luma,
luma_u16,
hsv,
rgba_scratch,
rgb_scratch,
rgba_scratch_u16,
rgba_color_scratch_u16,
luma_scratch_u16,
w,
plan,
idx,
use_simd,
alpha_mode,
|dst| {
yuva444p_to_rgba_row(
y, u_full, v_full, a, dst, w, matrix, full_range, use_simd,
)
},
|_dst: &mut [u16]| {},
|dst| {
for (d, &s) in dst.iter_mut().zip(y) {
*d = s as u16;
}
},
)?;
} else if !is_last {
chroma_top_y[..w].copy_from_slice(&y[..w]);
chroma_top_a[..w].copy_from_slice(&a[..w]);
*chroma_top_pending = Some((idx, matrix, full_range));
} else {
let (u_full, v_full) = upsample_420_chroma_sited(
chroma_full,
chroma_prev,
chroma_prev_row,
u_half,
v_half,
idx,
false,
center_sited,
false,
w,
use_simd,
);
packed_yuva444_resample::<8>(
rgba_stream,
rgba_stream_u16,
luma_stream_u16,
resample_outputs,
rgb,
rgba,
rgb_u16,
rgba_u16,
luma,
luma_u16,
hsv,
rgba_scratch,
rgb_scratch,
rgba_scratch_u16,
rgba_color_scratch_u16,
luma_scratch_u16,
w,
plan,
idx,
use_simd,
alpha_mode,
|dst| {
yuva444p_to_rgba_row(
y, u_full, v_full, a, dst, w, matrix, full_range, use_simd,
)
},
|_dst: &mut [u16]| {},
|dst| {
for (d, &s) in dst.iter_mut().zip(y) {
*d = s as u16;
}
},
)?;
}
stage_420_chroma_prev(chroma_prev, chroma_prev_row, u_half, v_half, idx, w);
} else if (center_sited || bottom_v) && want_color {
let expected = rgba_stream.as_ref().map_or(0, |s| s.next_y());
if let core::ops::ControlFlow::Break(()) = super::resample_preflight_check_only(
resample_outputs,
luma,
luma_u16,
rgb,
rgba,
&None,
&None,
&None,
&None,
&None,
&None,
&None,
hsv,
&None,
Some(expected),
idx,
)? {
return Ok(());
}
reserve_420_chroma_full(chroma_full, w, h)?;
if bottom_v {
reserve_420_chroma_prev(chroma_prev, w, h)?;
}
let (u_full, v_full) = upsample_420_chroma_sited(
chroma_full,
chroma_prev,
chroma_prev_row,
u_half,
v_half,
idx,
bottom_v,
center_sited,
false,
w,
use_simd,
);
packed_yuva444_resample::<8>(
rgba_stream,
rgba_stream_u16,
luma_stream_u16,
resample_outputs,
rgb,
rgba,
rgb_u16,
rgba_u16,
luma,
luma_u16,
hsv,
rgba_scratch,
rgb_scratch,
rgba_scratch_u16,
rgba_color_scratch_u16,
luma_scratch_u16,
w,
plan,
idx,
use_simd,
alpha_mode,
|dst| {
yuva444p_to_rgba_row(y, u_full, v_full, a, dst, w, matrix, full_range, use_simd)
},
|_dst: &mut [u16]| {},
|dst| {
for (d, &s) in dst.iter_mut().zip(y) {
*d = s as u16;
}
},
)?;
if bottom_v {
stage_420_chroma_prev(chroma_prev, chroma_prev_row, u_half, v_half, idx, w);
}
} else {
packed_yuva444_resample::<8>(
rgba_stream,
rgba_stream_u16,
luma_stream_u16,
resample_outputs,
rgb,
rgba,
rgb_u16,
rgba_u16,
luma,
luma_u16,
hsv,
rgba_scratch,
rgb_scratch,
rgba_scratch_u16,
rgba_color_scratch_u16,
luma_scratch_u16,
w,
plan,
idx,
use_simd,
alpha_mode,
|dst| {
yuva420p_to_rgba_row(y, u_half, v_half, a, dst, w, matrix, full_range, use_simd)
},
|_dst: &mut [u16]| {},
|dst| {
for (d, &s) in dst.iter_mut().zip(y) {
*d = s as u16;
}
},
)?;
}
if frozen_native_route.is_none() && need_output {
*frozen_native_route = Some(false);
}
if frozen_chroma_centered.is_none() && need_output {
*frozen_chroma_centered = Some(center_sited);
*frozen_chroma_bottom_v = Some(bottom_v);
*frozen_chroma_top_v = Some(top_v);
}
Ok(())
}
InsertionPoint::LinearLight => {
unreachable!("Yuva420p area downscale never selects the linear-light splice")
}
}
}
crate::resample::SpanKind::Filter if alpha_mode.is_premultiplied() => {
packed_yuva444_resample::<8>(
rgba_stream,
rgba_stream_u16,
luma_stream_u16,
resample_outputs,
rgb,
rgba,
rgb_u16,
rgba_u16,
luma,
luma_u16,
hsv,
rgba_scratch,
rgb_scratch,
rgba_scratch_u16,
rgba_color_scratch_u16,
luma_scratch_u16,
w,
plan,
idx,
use_simd,
alpha_mode,
|dst| yuva420p_to_rgba_row(y, u_half, v_half, a, dst, w, matrix, full_range, use_simd),
|_dst: &mut [u16]| {},
|dst| {
for (d, &s) in dst.iter_mut().zip(y) {
*d = s as u16;
}
},
)
}
crate::resample::SpanKind::Filter => {
plan.ensure_single_kernel_filter()?;
if top_v && want_color {
let cursor = rgba_filter_stream.as_ref().map_or(0, |s| s.next_y());
let expected_source = cursor + usize::from(chroma_top_pending.is_some());
if let core::ops::ControlFlow::Break(()) = super::resample_preflight_check_only(
resample_outputs,
luma,
luma_u16,
rgb,
rgba,
&None,
&None,
&None,
&None,
&None,
&None,
&None,
hsv,
&None,
Some(expected_source),
idx,
)? {
return Ok(());
}
reserve_420_chroma_full(chroma_full, w, h)?;
reserve_420_chroma_prev(chroma_prev, w, h)?;
reserve_420_chroma_top_u8(chroma_top_y, w, h)?;
reserve_420_chroma_top_u8(chroma_top_a, w, h)?;
let is_last = idx + 1 == h;
if idx & 1 == 0 {
if let Some((p_idx, p_matrix, p_full_range)) = chroma_top_pending.take() {
let (u_full, v_full) = upsample_420_chroma_sited(
chroma_full,
chroma_prev,
chroma_prev_row,
u_half,
v_half,
idx,
true,
center_sited,
false,
w,
use_simd,
);
let held_y: &[u8] = &chroma_top_y[..w];
let held_a: &[u8] = &chroma_top_a[..w];
packed_yuva444_filter_resample::<8, true, false>(
rgba_filter_stream,
rgba_filter_stream_u16,
luma_filter_stream,
luma_filter_stream_u16,
resample_outputs,
rgb,
rgba,
rgb_u16,
rgba_u16,
luma,
luma_u16,
hsv,
rgba_scratch,
rgb_scratch,
rgba_scratch_u16,
rgba_color_scratch_u16,
luma_scratch_u16,
w,
plan,
p_idx,
use_simd,
held_y,
None,
|dst| {
yuva444p_to_rgba_row(
held_y,
u_full,
v_full,
held_a,
dst,
w,
p_matrix,
p_full_range,
use_simd,
)
},
|_dst: &mut [u16]| {},
|_dst: &mut [u16]| {},
|_dst: &mut [u8]| {},
)?;
}
let (u_full, v_full) = upsample_420_chroma_sited(
chroma_full,
chroma_prev,
chroma_prev_row,
u_half,
v_half,
idx,
false,
center_sited,
false,
w,
use_simd,
);
packed_yuva444_filter_resample::<8, true, false>(
rgba_filter_stream,
rgba_filter_stream_u16,
luma_filter_stream,
luma_filter_stream_u16,
resample_outputs,
rgb,
rgba,
rgb_u16,
rgba_u16,
luma,
luma_u16,
hsv,
rgba_scratch,
rgb_scratch,
rgba_scratch_u16,
rgba_color_scratch_u16,
luma_scratch_u16,
w,
plan,
idx,
use_simd,
y,
None,
|dst| {
yuva444p_to_rgba_row(y, u_full, v_full, a, dst, w, matrix, full_range, use_simd)
},
|_dst: &mut [u16]| {},
|_dst: &mut [u16]| {},
|_dst: &mut [u8]| {},
)?;
} else if !is_last {
chroma_top_y[..w].copy_from_slice(&y[..w]);
chroma_top_a[..w].copy_from_slice(&a[..w]);
*chroma_top_pending = Some((idx, matrix, full_range));
} else {
let (u_full, v_full) = upsample_420_chroma_sited(
chroma_full,
chroma_prev,
chroma_prev_row,
u_half,
v_half,
idx,
false,
center_sited,
false,
w,
use_simd,
);
packed_yuva444_filter_resample::<8, true, false>(
rgba_filter_stream,
rgba_filter_stream_u16,
luma_filter_stream,
luma_filter_stream_u16,
resample_outputs,
rgb,
rgba,
rgb_u16,
rgba_u16,
luma,
luma_u16,
hsv,
rgba_scratch,
rgb_scratch,
rgba_scratch_u16,
rgba_color_scratch_u16,
luma_scratch_u16,
w,
plan,
idx,
use_simd,
y,
None,
|dst| {
yuva444p_to_rgba_row(y, u_full, v_full, a, dst, w, matrix, full_range, use_simd)
},
|_dst: &mut [u16]| {},
|_dst: &mut [u16]| {},
|_dst: &mut [u8]| {},
)?;
}
stage_420_chroma_prev(chroma_prev, chroma_prev_row, u_half, v_half, idx, w);
if need_output && frozen_chroma_centered.is_none() {
*frozen_chroma_centered = Some(center_sited);
*frozen_chroma_bottom_v = Some(bottom_v);
*frozen_chroma_top_v = Some(top_v);
}
return Ok(());
}
let r = if (center_sited || bottom_v) && want_color {
let expected = rgba_filter_stream.as_ref().map_or(0, |s| s.next_y());
if let core::ops::ControlFlow::Break(()) = super::resample_preflight_check_only(
resample_outputs,
luma,
luma_u16,
rgb,
rgba,
&None,
&None,
&None,
&None,
&None,
&None,
&None,
hsv,
&None,
Some(expected),
idx,
)? {
return Ok(());
}
reserve_420_chroma_full(chroma_full, w, h)?;
if bottom_v {
reserve_420_chroma_prev(chroma_prev, w, h)?;
}
let (u_full, v_full) = upsample_420_chroma_sited(
chroma_full,
chroma_prev,
chroma_prev_row,
u_half,
v_half,
idx,
bottom_v,
center_sited,
false,
w,
use_simd,
);
packed_yuva444_filter_resample::<8, true, false>(
rgba_filter_stream,
rgba_filter_stream_u16,
luma_filter_stream,
luma_filter_stream_u16,
resample_outputs,
rgb,
rgba,
rgb_u16,
rgba_u16,
luma,
luma_u16,
hsv,
rgba_scratch,
rgb_scratch,
rgba_scratch_u16,
rgba_color_scratch_u16,
luma_scratch_u16,
w,
plan,
idx,
use_simd,
y,
None,
|dst| {
yuva444p_to_rgba_row(y, u_full, v_full, a, dst, w, matrix, full_range, use_simd)
},
|_dst: &mut [u16]| {},
|_dst: &mut [u16]| {},
|_dst: &mut [u8]| {},
)
} else {
packed_yuva444_filter_resample::<8, true, false>(
rgba_filter_stream,
rgba_filter_stream_u16,
luma_filter_stream,
luma_filter_stream_u16,
resample_outputs,
rgb,
rgba,
rgb_u16,
rgba_u16,
luma,
luma_u16,
hsv,
rgba_scratch,
rgb_scratch,
rgba_scratch_u16,
rgba_color_scratch_u16,
luma_scratch_u16,
w,
plan,
idx,
use_simd,
y,
None,
|dst| {
yuva420p_to_rgba_row(y, u_half, v_half, a, dst, w, matrix, full_range, use_simd)
},
|_dst: &mut [u16]| {},
|_dst: &mut [u16]| {},
|_dst: &mut [u8]| {},
)
};
if r.is_ok() && bottom_v && want_color {
stage_420_chroma_prev(chroma_prev, chroma_prev_row, u_half, v_half, idx, w);
}
if r.is_ok() && need_output && frozen_chroma_centered.is_none() {
*frozen_chroma_centered = Some(center_sited);
*frozen_chroma_bottom_v = Some(bottom_v);
*frozen_chroma_top_v = Some(top_v);
}
r
}
};
}
let Self {
rgb,
rgba,
luma,
luma_u16,
hsv,
rgb_scratch,
chroma_full,
chroma_prev,
chroma_prev_row,
frozen_chroma_centered,
frozen_chroma_bottom_v,
frozen_chroma_top_v,
chroma_top_pending,
chroma_top_y,
chroma_top_a,
..
} = self;
let want_rgb = rgb.is_some();
let want_rgba = rgba.is_some();
let want_hsv = hsv.is_some();
let want_color = want_rgb || want_rgba || want_hsv;
let need_output = want_color || luma.is_some() || luma_u16.is_some();
if !need_output {
return Ok(());
}
let one_plane_start = idx * w;
let one_plane_end = one_plane_start + w;
let center_sited = chroma_420_center_sited_h(&chroma_location);
let bottom_v = chroma_420_bottom_sited_v(&chroma_location);
let top_v = chroma_420_top_sited_v(&chroma_location);
if need_output
&& let Some(frozen) = *frozen_chroma_centered
&& (frozen != center_sited
|| *frozen_chroma_bottom_v != Some(bottom_v)
|| *frozen_chroma_top_v != Some(top_v))
{
return Err(MixedSinkerError::ChromaSitingChanged(
ChromaSitingChanged::new(idx),
));
}
let want_hsv_direct = want_hsv && !want_rgb && !want_rgba;
let need_rgb_kernel = want_rgb || (want_hsv && want_rgba);
let matrix = row.matrix();
let full_range = row.full_range();
let need_centered_chroma = (center_sited || bottom_v) && want_color && !top_v;
if need_centered_chroma || (top_v && want_color) {
reserve_420_chroma_full(chroma_full, w, h)?;
}
if bottom_v || top_v {
reserve_420_chroma_prev(chroma_prev, w, h)?;
}
if top_v && want_color {
reserve_420_chroma_top_u8(chroma_top_y, w, h)?;
reserve_420_chroma_top_u8(chroma_top_a, w, h)?;
}
if want_hsv && want_rgba && !want_rgb {
rgb_row_buf_or_scratch(
rgb.as_deref_mut(),
rgb_scratch,
one_plane_start,
one_plane_end,
w,
h,
)?;
}
if (bottom_v || top_v) && !want_color {
stage_420_chroma_prev(
chroma_prev,
chroma_prev_row,
row.u_half(),
row.v_half(),
idx,
w,
);
}
if need_output && frozen_chroma_centered.is_none() {
*frozen_chroma_centered = Some(center_sited);
*frozen_chroma_bottom_v = Some(bottom_v);
*frozen_chroma_top_v = Some(top_v);
}
if let Some(luma) = luma.as_deref_mut() {
luma[one_plane_start..one_plane_end].copy_from_slice(&row.y()[..w]);
}
if let Some(luma_u16) = luma_u16.as_deref_mut() {
for (d, &s) in luma_u16[one_plane_start..one_plane_end]
.iter_mut()
.zip(&row.y()[..w])
{
*d = s as u16;
}
}
if top_v && want_color {
let is_last = idx + 1 == h;
if idx & 1 == 0 {
if let Some((p_idx, p_matrix, p_full_range)) = chroma_top_pending.take() {
let (u_full, v_full) = upsample_420_chroma_sited(
chroma_full,
chroma_prev,
chroma_prev_row,
row.u_half(),
row.v_half(),
idx,
true,
center_sited,
false,
w,
use_simd,
);
yuva444_top_identity_color_row(
rgb,
rgba,
hsv,
rgb_scratch,
&chroma_top_y[..w],
&chroma_top_a[..w],
u_full,
v_full,
p_idx * w,
p_idx * w + w,
w,
h,
p_matrix,
p_full_range,
use_simd,
)?;
}
let (u_full, v_full) = upsample_420_chroma_sited(
chroma_full,
chroma_prev,
chroma_prev_row,
row.u_half(),
row.v_half(),
idx,
false,
center_sited,
false,
w,
use_simd,
);
yuva444_top_identity_color_row(
rgb,
rgba,
hsv,
rgb_scratch,
row.y(),
row.a(),
u_full,
v_full,
one_plane_start,
one_plane_end,
w,
h,
matrix,
full_range,
use_simd,
)?;
} else if !is_last {
chroma_top_y[..w].copy_from_slice(&row.y()[..w]);
chroma_top_a[..w].copy_from_slice(&row.a()[..w]);
*chroma_top_pending = Some((idx, matrix, full_range));
} else {
let (u_full, v_full) = upsample_420_chroma_sited(
chroma_full,
chroma_prev,
chroma_prev_row,
row.u_half(),
row.v_half(),
idx,
false,
center_sited,
false,
w,
use_simd,
);
yuva444_top_identity_color_row(
rgb,
rgba,
hsv,
rgb_scratch,
row.y(),
row.a(),
u_full,
v_full,
one_plane_start,
one_plane_end,
w,
h,
matrix,
full_range,
use_simd,
)?;
}
stage_420_chroma_prev(
chroma_prev,
chroma_prev_row,
row.u_half(),
row.v_half(),
idx,
w,
);
return Ok(());
}
let rgb_row = if need_rgb_kernel {
Some(rgb_row_buf_or_scratch(
rgb.as_deref_mut(),
rgb_scratch,
one_plane_start,
one_plane_end,
w,
h,
)?)
} else {
None
};
let centered = if need_centered_chroma {
Some(upsample_420_chroma_sited(
chroma_full,
chroma_prev,
chroma_prev_row,
row.u_half(),
row.v_half(),
idx,
bottom_v,
center_sited,
true,
w,
use_simd,
))
} else {
None
};
if want_hsv_direct {
let hsv = hsv.as_mut().expect("want_hsv_direct implies hsv attached");
let (h, s, v) = hsv.hsv();
if let Some((u_full, v_full)) = centered {
yuv_444_to_hsv_row(
row.y(),
u_full,
v_full,
&mut h[one_plane_start..one_plane_end],
&mut s[one_plane_start..one_plane_end],
&mut v[one_plane_start..one_plane_end],
w,
row.matrix(),
row.full_range(),
use_simd,
);
} else {
yuv_420_to_hsv_row(
row.y(),
row.u_half(),
row.v_half(),
&mut h[one_plane_start..one_plane_end],
&mut s[one_plane_start..one_plane_end],
&mut v[one_plane_start..one_plane_end],
w,
row.matrix(),
row.full_range(),
use_simd,
);
}
return Ok(());
}
if want_rgba && !need_rgb_kernel {
let rgba_buf = rgba.as_deref_mut().unwrap();
let rgba_row = rgba_plane_row_slice(rgba_buf, one_plane_start, one_plane_end, w, h)?;
if let Some((u_full, v_full)) = centered {
yuva444p_to_rgba_row(
row.y(),
u_full,
v_full,
row.a(),
rgba_row,
w,
row.matrix(),
row.full_range(),
use_simd,
);
} else {
yuva420p_to_rgba_row(
row.y(),
row.u_half(),
row.v_half(),
row.a(),
rgba_row,
w,
row.matrix(),
row.full_range(),
use_simd,
);
}
return Ok(());
}
let Some(rgb_row) = rgb_row else {
return Ok(());
};
if let Some((u_full, v_full)) = centered {
yuv_444_to_rgb_row(
row.y(),
u_full,
v_full,
rgb_row,
w,
row.matrix(),
row.full_range(),
use_simd,
);
} else {
yuv_420_to_rgb_row(
row.y(),
row.u_half(),
row.v_half(),
rgb_row,
w,
row.matrix(),
row.full_range(),
use_simd,
);
}
if let Some(hsv) = hsv.as_mut() {
let (h, s, v) = hsv.hsv();
rgb_to_hsv_row(
rgb_row,
&mut h[one_plane_start..one_plane_end],
&mut s[one_plane_start..one_plane_end],
&mut v[one_plane_start..one_plane_end],
w,
use_simd,
);
}
if want_rgba {
let rgba_buf = rgba.as_deref_mut().unwrap();
let rgba_row = rgba_plane_row_slice(rgba_buf, one_plane_start, one_plane_end, w, h)?;
expand_rgb_to_rgba_row(rgb_row, rgba_row, w);
crate::row::alpha_extract::copy_alpha_plane_u8(row.a(), rgba_row, w, use_simd);
}
Ok(())
}
}
impl<'a, R, const BE: bool> MixedSinker<'a, Yuva420p9<BE>, R> {
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn with_rgba(mut self, buf: &'a mut [u8]) -> Result<Self, MixedSinkerError> {
self.set_rgba(buf)?;
Ok(self)
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn set_rgba(&mut self, buf: &'a mut [u8]) -> Result<&mut Self, MixedSinkerError> {
let expected = self.frame_elems(4)?;
if buf.len() < expected {
return Err(MixedSinkerError::InsufficientRgbaBuffer(
InsufficientBuffer::new(expected, buf.len()),
));
}
self.rgba = Some(buf);
Ok(self)
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn with_rgba_u16(mut self, buf: &'a mut [u16]) -> Result<Self, MixedSinkerError> {
self.set_rgba_u16(buf)?;
Ok(self)
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn set_rgba_u16(&mut self, buf: &'a mut [u16]) -> Result<&mut Self, MixedSinkerError> {
let expected = self.frame_elems(4)?;
if buf.len() < expected {
return Err(MixedSinkerError::InsufficientRgbaU16Buffer(
InsufficientBuffer::new(expected, buf.len()),
));
}
self.rgba_u16 = Some(buf);
Ok(self)
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn with_rgb_u16(mut self, buf: &'a mut [u16]) -> Result<Self, MixedSinkerError> {
self.set_rgb_u16(buf)?;
Ok(self)
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn set_rgb_u16(&mut self, buf: &'a mut [u16]) -> Result<&mut Self, MixedSinkerError> {
let expected = self.frame_elems(3)?;
if buf.len() < expected {
return Err(MixedSinkerError::InsufficientRgbU16Buffer(
InsufficientBuffer::new(expected, buf.len()),
));
}
self.rgb_u16 = Some(buf);
Ok(self)
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn with_luma_u16(mut self, buf: &'a mut [u16]) -> Result<Self, MixedSinkerError> {
self.set_luma_u16(buf)?;
Ok(self)
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn set_luma_u16(&mut self, buf: &'a mut [u16]) -> Result<&mut Self, MixedSinkerError> {
let expected = self.frame_pixels()?;
if buf.len() < expected {
return Err(MixedSinkerError::InsufficientLumaU16Buffer(
InsufficientBuffer::new(expected, buf.len()),
));
}
self.luma_u16 = Some(buf);
Ok(self)
}
}
impl<R, const BE: bool> Yuva420p9Sink<BE> for MixedSinker<'_, Yuva420p9<BE>, R> {}
impl<R, const BE: bool> PixelSink for MixedSinker<'_, Yuva420p9<BE>, R> {
type Input<'r> = Yuva420p9Row<'r>;
type Error = MixedSinkerError;
#[cfg_attr(not(tarpaulin), inline(always))]
fn kernel_matrix(&self) -> crate::KernelMatrix {
self.kernel_matrix
}
fn begin_frame(&mut self, width: u32, height: u32) -> Result<(), Self::Error> {
if self.width & 1 != 0 {
return Err(MixedSinkerError::WidthAlignment(WidthAlignment::odd(
self.width,
)));
}
check_dimensions_match(self.width, self.height, width, height)?;
reset_high_bit_yuva_streams(self);
Ok(())
}
fn process(&mut self, row: Yuva420p9Row<'_>) -> Result<(), Self::Error> {
if self.plan.is_some() {
return yuva420p_high_bit_resample::<9, BE>(
self,
row.row(),
row.y(),
row.u_half(),
row.v_half(),
row.a(),
row.matrix(),
row.full_range(),
RowSlice::Y9,
RowSlice::UHalf9,
RowSlice::VHalf9,
RowSlice::AFull9,
yuva420p9_to_rgba_row_endian,
yuva420p9_to_rgba_u16_row_endian,
yuva444p9_to_rgba_row_endian,
yuva444p9_to_rgba_u16_row_endian,
);
}
yuva420p_high_bit_process::<9, BE, _, _>(
self,
row.row(),
row.y(),
row.u_half(),
row.v_half(),
row.a(),
row.matrix(),
row.full_range(),
RowSlice::Y9,
RowSlice::UHalf9,
RowSlice::VHalf9,
RowSlice::AFull9,
yuv420p9_to_rgb_row_endian,
yuv420p9_to_rgb_u16_row_endian,
yuva420p9_to_rgba_row_endian,
yuv420p9_to_hsv_row_endian,
yuva420p9_to_rgba_u16_row_endian,
yuv444p9_to_rgb_row_endian,
yuv444p9_to_rgb_u16_row_endian,
yuva444p9_to_rgba_row_endian,
yuv444p9_to_hsv_row_endian,
yuva444p9_to_rgba_u16_row_endian,
)
}
}
impl<'a, R, const BE: bool> MixedSinker<'a, Yuva420p10<BE>, R> {
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn with_rgba(mut self, buf: &'a mut [u8]) -> Result<Self, MixedSinkerError> {
self.set_rgba(buf)?;
Ok(self)
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn set_rgba(&mut self, buf: &'a mut [u8]) -> Result<&mut Self, MixedSinkerError> {
let expected = self.frame_elems(4)?;
if buf.len() < expected {
return Err(MixedSinkerError::InsufficientRgbaBuffer(
InsufficientBuffer::new(expected, buf.len()),
));
}
self.rgba = Some(buf);
Ok(self)
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn with_rgba_u16(mut self, buf: &'a mut [u16]) -> Result<Self, MixedSinkerError> {
self.set_rgba_u16(buf)?;
Ok(self)
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn set_rgba_u16(&mut self, buf: &'a mut [u16]) -> Result<&mut Self, MixedSinkerError> {
let expected = self.frame_elems(4)?;
if buf.len() < expected {
return Err(MixedSinkerError::InsufficientRgbaU16Buffer(
InsufficientBuffer::new(expected, buf.len()),
));
}
self.rgba_u16 = Some(buf);
Ok(self)
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn with_rgb_u16(mut self, buf: &'a mut [u16]) -> Result<Self, MixedSinkerError> {
self.set_rgb_u16(buf)?;
Ok(self)
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn set_rgb_u16(&mut self, buf: &'a mut [u16]) -> Result<&mut Self, MixedSinkerError> {
let expected = self.frame_elems(3)?;
if buf.len() < expected {
return Err(MixedSinkerError::InsufficientRgbU16Buffer(
InsufficientBuffer::new(expected, buf.len()),
));
}
self.rgb_u16 = Some(buf);
Ok(self)
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn with_luma_u16(mut self, buf: &'a mut [u16]) -> Result<Self, MixedSinkerError> {
self.set_luma_u16(buf)?;
Ok(self)
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn set_luma_u16(&mut self, buf: &'a mut [u16]) -> Result<&mut Self, MixedSinkerError> {
let expected = self.frame_pixels()?;
if buf.len() < expected {
return Err(MixedSinkerError::InsufficientLumaU16Buffer(
InsufficientBuffer::new(expected, buf.len()),
));
}
self.luma_u16 = Some(buf);
Ok(self)
}
}
impl<R, const BE: bool> Yuva420p10Sink<BE> for MixedSinker<'_, Yuva420p10<BE>, R> {}
impl<R, const BE: bool> PixelSink for MixedSinker<'_, Yuva420p10<BE>, R> {
type Input<'r> = Yuva420p10Row<'r>;
type Error = MixedSinkerError;
#[cfg_attr(not(tarpaulin), inline(always))]
fn kernel_matrix(&self) -> crate::KernelMatrix {
self.kernel_matrix
}
fn begin_frame(&mut self, width: u32, height: u32) -> Result<(), Self::Error> {
if self.width & 1 != 0 {
return Err(MixedSinkerError::WidthAlignment(WidthAlignment::odd(
self.width,
)));
}
check_dimensions_match(self.width, self.height, width, height)?;
reset_high_bit_yuva_streams(self);
Ok(())
}
fn process(&mut self, row: Yuva420p10Row<'_>) -> Result<(), Self::Error> {
if self.plan.is_some() {
return yuva420p_high_bit_resample::<10, BE>(
self,
row.row(),
row.y(),
row.u_half(),
row.v_half(),
row.a(),
row.matrix(),
row.full_range(),
RowSlice::Y10,
RowSlice::UHalf10,
RowSlice::VHalf10,
RowSlice::AFull10,
yuva420p10_to_rgba_row_endian,
yuva420p10_to_rgba_u16_row_endian,
yuva444p10_to_rgba_row_endian,
yuva444p10_to_rgba_u16_row_endian,
);
}
yuva420p_high_bit_process::<10, BE, _, _>(
self,
row.row(),
row.y(),
row.u_half(),
row.v_half(),
row.a(),
row.matrix(),
row.full_range(),
RowSlice::Y10,
RowSlice::UHalf10,
RowSlice::VHalf10,
RowSlice::AFull10,
yuv420p10_to_rgb_row_endian,
yuv420p10_to_rgb_u16_row_endian,
yuva420p10_to_rgba_row_endian,
yuv420p10_to_hsv_row_endian,
yuva420p10_to_rgba_u16_row_endian,
yuv444p10_to_rgb_row_endian,
yuv444p10_to_rgb_u16_row_endian,
yuva444p10_to_rgba_row_endian,
yuv444p10_to_hsv_row_endian,
yuva444p10_to_rgba_u16_row_endian,
)
}
}
impl<'a, R, const BE: bool> MixedSinker<'a, Yuva420p12<BE>, R> {
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn with_rgba(mut self, buf: &'a mut [u8]) -> Result<Self, MixedSinkerError> {
self.set_rgba(buf)?;
Ok(self)
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn set_rgba(&mut self, buf: &'a mut [u8]) -> Result<&mut Self, MixedSinkerError> {
let expected = self.frame_elems(4)?;
if buf.len() < expected {
return Err(MixedSinkerError::InsufficientRgbaBuffer(
InsufficientBuffer::new(expected, buf.len()),
));
}
self.rgba = Some(buf);
Ok(self)
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn with_rgba_u16(mut self, buf: &'a mut [u16]) -> Result<Self, MixedSinkerError> {
self.set_rgba_u16(buf)?;
Ok(self)
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn set_rgba_u16(&mut self, buf: &'a mut [u16]) -> Result<&mut Self, MixedSinkerError> {
let expected = self.frame_elems(4)?;
if buf.len() < expected {
return Err(MixedSinkerError::InsufficientRgbaU16Buffer(
InsufficientBuffer::new(expected, buf.len()),
));
}
self.rgba_u16 = Some(buf);
Ok(self)
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn with_rgb_u16(mut self, buf: &'a mut [u16]) -> Result<Self, MixedSinkerError> {
self.set_rgb_u16(buf)?;
Ok(self)
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn set_rgb_u16(&mut self, buf: &'a mut [u16]) -> Result<&mut Self, MixedSinkerError> {
let expected = self.frame_elems(3)?;
if buf.len() < expected {
return Err(MixedSinkerError::InsufficientRgbU16Buffer(
InsufficientBuffer::new(expected, buf.len()),
));
}
self.rgb_u16 = Some(buf);
Ok(self)
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn with_luma_u16(mut self, buf: &'a mut [u16]) -> Result<Self, MixedSinkerError> {
self.set_luma_u16(buf)?;
Ok(self)
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn set_luma_u16(&mut self, buf: &'a mut [u16]) -> Result<&mut Self, MixedSinkerError> {
let expected = self.frame_pixels()?;
if buf.len() < expected {
return Err(MixedSinkerError::InsufficientLumaU16Buffer(
InsufficientBuffer::new(expected, buf.len()),
));
}
self.luma_u16 = Some(buf);
Ok(self)
}
}
impl<R, const BE: bool> Yuva420p12Sink<BE> for MixedSinker<'_, Yuva420p12<BE>, R> {}
impl<R, const BE: bool> PixelSink for MixedSinker<'_, Yuva420p12<BE>, R> {
type Input<'r> = Yuva420p12Row<'r>;
type Error = MixedSinkerError;
#[cfg_attr(not(tarpaulin), inline(always))]
fn kernel_matrix(&self) -> crate::KernelMatrix {
self.kernel_matrix
}
fn begin_frame(&mut self, width: u32, height: u32) -> Result<(), Self::Error> {
if self.width & 1 != 0 {
return Err(MixedSinkerError::WidthAlignment(WidthAlignment::odd(
self.width,
)));
}
check_dimensions_match(self.width, self.height, width, height)?;
reset_high_bit_yuva_streams(self);
Ok(())
}
fn process(&mut self, row: Yuva420p12Row<'_>) -> Result<(), Self::Error> {
if self.plan.is_some() {
return yuva420p_high_bit_resample::<12, BE>(
self,
row.row(),
row.y(),
row.u_half(),
row.v_half(),
row.a(),
row.matrix(),
row.full_range(),
RowSlice::Y12,
RowSlice::UHalf12,
RowSlice::VHalf12,
RowSlice::AFull12,
yuva420p12_to_rgba_row_endian,
yuva420p12_to_rgba_u16_row_endian,
yuva444p12_to_rgba_row_endian,
yuva444p12_to_rgba_u16_row_endian,
);
}
yuva420p_high_bit_process::<12, BE, _, _>(
self,
row.row(),
row.y(),
row.u_half(),
row.v_half(),
row.a(),
row.matrix(),
row.full_range(),
RowSlice::Y12,
RowSlice::UHalf12,
RowSlice::VHalf12,
RowSlice::AFull12,
yuv420p12_to_rgb_row_endian,
yuv420p12_to_rgb_u16_row_endian,
yuva420p12_to_rgba_row_endian,
yuv420p12_to_hsv_row_endian,
yuva420p12_to_rgba_u16_row_endian,
yuv444p12_to_rgb_row_endian,
yuv444p12_to_rgb_u16_row_endian,
yuva444p12_to_rgba_row_endian,
yuv444p12_to_hsv_row_endian,
yuva444p12_to_rgba_u16_row_endian,
)
}
}
impl<'a, R, const BE: bool> MixedSinker<'a, Yuva420p16<BE>, R> {
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn with_rgba(mut self, buf: &'a mut [u8]) -> Result<Self, MixedSinkerError> {
self.set_rgba(buf)?;
Ok(self)
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn set_rgba(&mut self, buf: &'a mut [u8]) -> Result<&mut Self, MixedSinkerError> {
let expected = self.frame_elems(4)?;
if buf.len() < expected {
return Err(MixedSinkerError::InsufficientRgbaBuffer(
InsufficientBuffer::new(expected, buf.len()),
));
}
self.rgba = Some(buf);
Ok(self)
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn with_rgba_u16(mut self, buf: &'a mut [u16]) -> Result<Self, MixedSinkerError> {
self.set_rgba_u16(buf)?;
Ok(self)
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn set_rgba_u16(&mut self, buf: &'a mut [u16]) -> Result<&mut Self, MixedSinkerError> {
let expected = self.frame_elems(4)?;
if buf.len() < expected {
return Err(MixedSinkerError::InsufficientRgbaU16Buffer(
InsufficientBuffer::new(expected, buf.len()),
));
}
self.rgba_u16 = Some(buf);
Ok(self)
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn with_rgb_u16(mut self, buf: &'a mut [u16]) -> Result<Self, MixedSinkerError> {
self.set_rgb_u16(buf)?;
Ok(self)
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn set_rgb_u16(&mut self, buf: &'a mut [u16]) -> Result<&mut Self, MixedSinkerError> {
let expected = self.frame_elems(3)?;
if buf.len() < expected {
return Err(MixedSinkerError::InsufficientRgbU16Buffer(
InsufficientBuffer::new(expected, buf.len()),
));
}
self.rgb_u16 = Some(buf);
Ok(self)
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn with_luma_u16(mut self, buf: &'a mut [u16]) -> Result<Self, MixedSinkerError> {
self.set_luma_u16(buf)?;
Ok(self)
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn set_luma_u16(&mut self, buf: &'a mut [u16]) -> Result<&mut Self, MixedSinkerError> {
let expected = self.frame_pixels()?;
if buf.len() < expected {
return Err(MixedSinkerError::InsufficientLumaU16Buffer(
InsufficientBuffer::new(expected, buf.len()),
));
}
self.luma_u16 = Some(buf);
Ok(self)
}
}
impl<R, const BE: bool> Yuva420p16Sink<BE> for MixedSinker<'_, Yuva420p16<BE>, R> {}
impl<R, const BE: bool> PixelSink for MixedSinker<'_, Yuva420p16<BE>, R> {
type Input<'r> = Yuva420p16Row<'r>;
type Error = MixedSinkerError;
#[cfg_attr(not(tarpaulin), inline(always))]
fn kernel_matrix(&self) -> crate::KernelMatrix {
self.kernel_matrix
}
fn begin_frame(&mut self, width: u32, height: u32) -> Result<(), Self::Error> {
if self.width & 1 != 0 {
return Err(MixedSinkerError::WidthAlignment(WidthAlignment::odd(
self.width,
)));
}
check_dimensions_match(self.width, self.height, width, height)?;
reset_high_bit_yuva_streams(self);
Ok(())
}
fn process(&mut self, row: Yuva420p16Row<'_>) -> Result<(), Self::Error> {
if self.plan.is_some() {
return yuva420p_high_bit_resample::<16, BE>(
self,
row.row(),
row.y(),
row.u_half(),
row.v_half(),
row.a(),
row.matrix(),
row.full_range(),
RowSlice::Y16,
RowSlice::UHalf16,
RowSlice::VHalf16,
RowSlice::AFull16,
yuva420p16_to_rgba_row_endian,
yuva420p16_to_rgba_u16_row_endian,
yuva444p16_to_rgba_row_endian,
yuva444p16_to_rgba_u16_row_endian,
);
}
yuva420p_high_bit_process::<16, BE, _, _>(
self,
row.row(),
row.y(),
row.u_half(),
row.v_half(),
row.a(),
row.matrix(),
row.full_range(),
RowSlice::Y16,
RowSlice::UHalf16,
RowSlice::VHalf16,
RowSlice::AFull16,
yuv420p16_to_rgb_row_endian,
yuv420p16_to_rgb_u16_row_endian,
yuva420p16_to_rgba_row_endian,
yuv420p16_to_hsv_row_endian,
yuva420p16_to_rgba_u16_row_endian,
yuv444p16_to_rgb_row_endian,
yuv444p16_to_rgb_u16_row_endian,
yuva444p16_to_rgba_row_endian,
yuv444p16_to_hsv_row_endian,
yuva444p16_to_rgba_u16_row_endian,
)
}
}
#[allow(clippy::too_many_arguments, clippy::type_complexity)]
#[cfg_attr(not(tarpaulin), inline(always))]
fn yuva420p_high_bit_process<const BITS: u32, const BE: bool, F: crate::SourceFormat, R>(
sinker: &mut MixedSinker<'_, F, R>,
idx: usize,
y_row: &[u16],
u_half_row: &[u16],
v_half_row: &[u16],
a_row: &[u16],
matrix: crate::KernelMatrix,
full_range: bool,
y_slice: RowSlice,
u_slice: RowSlice,
v_slice: RowSlice,
a_slice: RowSlice,
rgb_dispatch: fn(&[u16], &[u16], &[u16], &mut [u8], usize, crate::KernelMatrix, bool, bool, bool),
rgb_u16_dispatch: fn(
&[u16],
&[u16],
&[u16],
&mut [u16],
usize,
crate::KernelMatrix,
bool,
bool,
bool,
),
rgba_dispatch: fn(
&[u16],
&[u16],
&[u16],
&[u16],
&mut [u8],
usize,
crate::KernelMatrix,
bool,
bool,
bool,
),
hsv_dispatch: fn(
&[u16],
&[u16],
&[u16],
&mut [u8],
&mut [u8],
&mut [u8],
usize,
crate::KernelMatrix,
bool,
bool,
bool,
),
rgba_u16_dispatch: fn(
&[u16],
&[u16],
&[u16],
&[u16],
&mut [u16],
usize,
crate::KernelMatrix,
bool,
bool,
bool,
),
rgb_444_dispatch: fn(
&[u16],
&[u16],
&[u16],
&mut [u8],
usize,
crate::KernelMatrix,
bool,
bool,
bool,
),
rgb_u16_444_dispatch: fn(
&[u16],
&[u16],
&[u16],
&mut [u16],
usize,
crate::KernelMatrix,
bool,
bool,
bool,
),
rgba_444_dispatch: fn(
&[u16],
&[u16],
&[u16],
&[u16],
&mut [u8],
usize,
crate::KernelMatrix,
bool,
bool,
bool,
),
hsv_444_dispatch: fn(
&[u16],
&[u16],
&[u16],
&mut [u8],
&mut [u8],
&mut [u8],
usize,
crate::KernelMatrix,
bool,
bool,
bool,
),
rgba_u16_444_dispatch: fn(
&[u16],
&[u16],
&[u16],
&[u16],
&mut [u16],
usize,
crate::KernelMatrix,
bool,
bool,
bool,
),
) -> Result<(), MixedSinkerError> {
let w = sinker.width;
let h = sinker.height;
let use_simd = sinker.simd;
let chroma_location = sinker.chroma_location.clone();
if w & 1 != 0 {
return Err(MixedSinkerError::WidthAlignment(WidthAlignment::odd(w)));
}
if y_row.len() != w {
return Err(MixedSinkerError::RowShapeMismatch(RowShapeMismatch::new(
y_slice,
idx,
w,
y_row.len(),
)));
}
if u_half_row.len() != w / 2 {
return Err(MixedSinkerError::RowShapeMismatch(RowShapeMismatch::new(
u_slice,
idx,
w / 2,
u_half_row.len(),
)));
}
if v_half_row.len() != w / 2 {
return Err(MixedSinkerError::RowShapeMismatch(RowShapeMismatch::new(
v_slice,
idx,
w / 2,
v_half_row.len(),
)));
}
if a_row.len() != w {
return Err(MixedSinkerError::RowShapeMismatch(RowShapeMismatch::new(
a_slice,
idx,
w,
a_row.len(),
)));
}
if idx >= sinker.height {
return Err(MixedSinkerError::RowIndexOutOfRange(
RowIndexOutOfRange::new(idx, sinker.height),
));
}
let MixedSinker {
rgb,
rgb_u16,
rgba,
rgba_u16,
luma,
luma_u16,
hsv,
rgb_scratch,
chroma_full_u16,
chroma_prev_u16,
chroma_prev_row,
frozen_chroma_centered,
frozen_chroma_bottom_v,
frozen_chroma_top_v,
chroma_top_pending,
chroma_top_y_u16,
chroma_top_a_u16,
..
} = sinker;
let want_rgb = rgb.is_some();
let want_rgba = rgba.is_some();
let want_hsv = hsv.is_some();
let want_rgb_u16 = rgb_u16.is_some();
let want_rgba_u16 = rgba_u16.is_some();
let want_color = want_rgb || want_rgba || want_hsv || want_rgb_u16 || want_rgba_u16;
let need_output = want_color || luma.is_some() || luma_u16.is_some();
if !need_output {
return Ok(());
}
let one_plane_start = idx * w;
let one_plane_end = one_plane_start + w;
let center_sited = chroma_420_center_sited_h(&chroma_location);
let bottom_v = chroma_420_bottom_sited_v(&chroma_location);
let top_v = chroma_420_top_sited_v(&chroma_location);
if need_output
&& let Some(frozen) = *frozen_chroma_centered
&& (frozen != center_sited
|| *frozen_chroma_bottom_v != Some(bottom_v)
|| *frozen_chroma_top_v != Some(top_v))
{
return Err(MixedSinkerError::ChromaSitingChanged(
ChromaSitingChanged::new(idx),
));
}
let want_hsv_direct = want_hsv && !want_rgb && !want_rgba;
let need_rgb_kernel = want_rgb || (want_hsv && want_rgba);
let need_centered_chroma = (center_sited || bottom_v) && want_color && !top_v;
if need_centered_chroma || (top_v && want_color) {
reserve_420_chroma_full_u16(chroma_full_u16, w, h)?;
}
if bottom_v || top_v {
reserve_420_chroma_prev_u16(chroma_prev_u16, w, h)?;
}
if top_v && want_color {
reserve_420_chroma_top_u16(chroma_top_y_u16, w, h)?;
reserve_420_chroma_top_u16(chroma_top_a_u16, w, h)?;
}
if want_hsv && want_rgba && !want_rgb {
rgb_row_buf_or_scratch(
rgb.as_deref_mut(),
rgb_scratch,
one_plane_start,
one_plane_end,
w,
h,
)?;
}
if (bottom_v || top_v) && !want_color {
stage_420_chroma_prev_u16(
chroma_prev_u16,
chroma_prev_row,
u_half_row,
v_half_row,
idx,
w,
);
}
if need_output && frozen_chroma_centered.is_none() {
*frozen_chroma_centered = Some(center_sited);
*frozen_chroma_bottom_v = Some(bottom_v);
*frozen_chroma_top_v = Some(top_v);
}
if luma.is_some() || luma_u16.is_some() {
let luma_dst = luma.as_deref_mut();
let luma_u16_dst = luma_u16.as_deref_mut();
let mut luma_row = luma_dst.map(|b| &mut b[one_plane_start..one_plane_end]);
let mut luma_u16_row = luma_u16_dst.map(|b| &mut b[one_plane_start..one_plane_end]);
let sample_mask = ((1u32 << BITS) - 1) as u16;
for (i, &s) in y_row.iter().enumerate().take(w) {
let logical = (if BE { u16::from_be(s) } else { u16::from_le(s) }) & sample_mask;
if let Some(row) = luma_row.as_deref_mut() {
row[i] = (logical >> (BITS - 8)) as u8;
}
if let Some(row) = luma_u16_row.as_deref_mut() {
row[i] = logical;
}
}
}
if top_v && want_color {
let is_last = idx + 1 == h;
if idx & 1 == 0 {
if let Some((p_idx, p_matrix, p_full_range)) = chroma_top_pending.take() {
let (u_full, v_full) = upsample_420_chroma_sited_u16::<BITS>(
chroma_full_u16,
chroma_prev_u16,
chroma_prev_row,
u_half_row,
v_half_row,
idx,
true,
center_sited,
false,
w,
BE,
use_simd,
);
yuva444p_high_bit_top_identity_color_row::<BITS, BE>(
rgb,
rgba,
rgb_u16,
rgba_u16,
hsv,
rgb_scratch,
&chroma_top_y_u16[..w],
&chroma_top_a_u16[..w],
u_full,
v_full,
p_idx * w,
p_idx * w + w,
w,
h,
p_matrix,
p_full_range,
use_simd,
rgb_444_dispatch,
rgb_u16_444_dispatch,
rgba_444_dispatch,
hsv_444_dispatch,
rgba_u16_444_dispatch,
)?;
}
let (u_full, v_full) = upsample_420_chroma_sited_u16::<BITS>(
chroma_full_u16,
chroma_prev_u16,
chroma_prev_row,
u_half_row,
v_half_row,
idx,
false,
center_sited,
false,
w,
BE,
use_simd,
);
yuva444p_high_bit_top_identity_color_row::<BITS, BE>(
rgb,
rgba,
rgb_u16,
rgba_u16,
hsv,
rgb_scratch,
y_row,
a_row,
u_full,
v_full,
one_plane_start,
one_plane_end,
w,
h,
matrix,
full_range,
use_simd,
rgb_444_dispatch,
rgb_u16_444_dispatch,
rgba_444_dispatch,
hsv_444_dispatch,
rgba_u16_444_dispatch,
)?;
} else if !is_last {
chroma_top_y_u16[..w].copy_from_slice(&y_row[..w]);
chroma_top_a_u16[..w].copy_from_slice(&a_row[..w]);
*chroma_top_pending = Some((idx, matrix, full_range));
} else {
let (u_full, v_full) = upsample_420_chroma_sited_u16::<BITS>(
chroma_full_u16,
chroma_prev_u16,
chroma_prev_row,
u_half_row,
v_half_row,
idx,
false,
center_sited,
false,
w,
BE,
use_simd,
);
yuva444p_high_bit_top_identity_color_row::<BITS, BE>(
rgb,
rgba,
rgb_u16,
rgba_u16,
hsv,
rgb_scratch,
y_row,
a_row,
u_full,
v_full,
one_plane_start,
one_plane_end,
w,
h,
matrix,
full_range,
use_simd,
rgb_444_dispatch,
rgb_u16_444_dispatch,
rgba_444_dispatch,
hsv_444_dispatch,
rgba_u16_444_dispatch,
)?;
}
stage_420_chroma_prev_u16(
chroma_prev_u16,
chroma_prev_row,
u_half_row,
v_half_row,
idx,
w,
);
return Ok(());
}
let rgb_row = if need_rgb_kernel {
Some(rgb_row_buf_or_scratch(
rgb.as_deref_mut(),
rgb_scratch,
one_plane_start,
one_plane_end,
w,
h,
)?)
} else {
None
};
let centered = if need_centered_chroma {
Some(upsample_420_chroma_sited_u16::<BITS>(
chroma_full_u16,
chroma_prev_u16,
chroma_prev_row,
u_half_row,
v_half_row,
idx,
bottom_v,
center_sited,
true,
w,
BE,
use_simd,
))
} else {
None
};
if want_rgb_u16 {
let buf = rgb_u16.as_deref_mut().unwrap();
let rgb_plane_end = one_plane_end
.checked_mul(3)
.ok_or(MixedSinkerError::GeometryOverflow(GeometryOverflow::new(
w, h, 3,
)))?;
let rgb_plane_start = one_plane_start * 3;
let rgb_u16_row = &mut buf[rgb_plane_start..rgb_plane_end];
if let Some((u_full, v_full)) = centered {
rgb_u16_444_dispatch(
y_row,
u_full,
v_full,
rgb_u16_row,
w,
matrix,
full_range,
use_simd,
BE,
);
} else {
rgb_u16_dispatch(
y_row,
u_half_row,
v_half_row,
rgb_u16_row,
w,
matrix,
full_range,
use_simd,
BE,
);
}
if want_rgba_u16 {
let rgba_buf = rgba_u16.as_deref_mut().unwrap();
let rgba_u16_row = rgba_u16_plane_row_slice(rgba_buf, one_plane_start, one_plane_end, w, h)?;
expand_rgb_u16_to_rgba_u16_row::<BITS>(rgb_u16_row, rgba_u16_row, w);
crate::row::alpha_extract::copy_alpha_plane_u16::<BITS, BE>(a_row, rgba_u16_row, w, use_simd);
}
} else if want_rgba_u16 {
let rgba_buf = rgba_u16.as_deref_mut().unwrap();
let rgba_u16_row = rgba_u16_plane_row_slice(rgba_buf, one_plane_start, one_plane_end, w, h)?;
if let Some((u_full, v_full)) = centered {
rgba_u16_444_dispatch(
y_row,
u_full,
v_full,
a_row,
rgba_u16_row,
w,
matrix,
full_range,
use_simd,
BE,
);
} else {
rgba_u16_dispatch(
y_row,
u_half_row,
v_half_row,
a_row,
rgba_u16_row,
w,
matrix,
full_range,
use_simd,
BE,
);
}
}
if want_hsv_direct {
let hsv = hsv.as_mut().expect("want_hsv_direct implies hsv attached");
let (h, s, v) = hsv.hsv();
if let Some((u_full, v_full)) = centered {
hsv_444_dispatch(
y_row,
u_full,
v_full,
&mut h[one_plane_start..one_plane_end],
&mut s[one_plane_start..one_plane_end],
&mut v[one_plane_start..one_plane_end],
w,
matrix,
full_range,
use_simd,
BE,
);
} else {
hsv_dispatch(
y_row,
u_half_row,
v_half_row,
&mut h[one_plane_start..one_plane_end],
&mut s[one_plane_start..one_plane_end],
&mut v[one_plane_start..one_plane_end],
w,
matrix,
full_range,
use_simd,
BE,
);
}
return Ok(());
}
if want_rgba && !need_rgb_kernel {
let rgba_buf = rgba.as_deref_mut().unwrap();
let rgba_row = rgba_plane_row_slice(rgba_buf, one_plane_start, one_plane_end, w, h)?;
if let Some((u_full, v_full)) = centered {
rgba_444_dispatch(
y_row, u_full, v_full, a_row, rgba_row, w, matrix, full_range, use_simd, BE,
);
} else {
rgba_dispatch(
y_row, u_half_row, v_half_row, a_row, rgba_row, w, matrix, full_range, use_simd, BE,
);
}
return Ok(());
}
let Some(rgb_row) = rgb_row else {
return Ok(());
};
if let Some((u_full, v_full)) = centered {
rgb_444_dispatch(
y_row, u_full, v_full, rgb_row, w, matrix, full_range, use_simd, BE,
);
} else {
rgb_dispatch(
y_row, u_half_row, v_half_row, rgb_row, w, matrix, full_range, use_simd, BE,
);
}
if let Some(hsv) = hsv.as_mut() {
let (h, s, v) = hsv.hsv();
rgb_to_hsv_row(
rgb_row,
&mut h[one_plane_start..one_plane_end],
&mut s[one_plane_start..one_plane_end],
&mut v[one_plane_start..one_plane_end],
w,
use_simd,
);
}
if want_rgba {
let rgba_buf = rgba.as_deref_mut().unwrap();
let rgba_row = rgba_plane_row_slice(rgba_buf, one_plane_start, one_plane_end, w, h)?;
expand_rgb_to_rgba_row(rgb_row, rgba_row, w);
crate::row::alpha_extract::copy_alpha_plane_u16_to_u8::<BITS, BE>(a_row, rgba_row, w, use_simd);
}
Ok(())
}
#[allow(clippy::too_many_arguments, clippy::type_complexity)]
#[cfg_attr(not(tarpaulin), inline(always))]
fn yuva420p_high_bit_resample<const BITS: u32, const BE: bool>(
sinker: &mut MixedSinker<'_, impl crate::SourceFormat, impl Sized>,
idx: usize,
y_row: &[u16],
u_half_row: &[u16],
v_half_row: &[u16],
a_row: &[u16],
matrix: crate::KernelMatrix,
full_range: bool,
y_slice: RowSlice,
u_slice: RowSlice,
v_slice: RowSlice,
a_slice: RowSlice,
rgba_dispatch: fn(
&[u16],
&[u16],
&[u16],
&[u16],
&mut [u8],
usize,
crate::KernelMatrix,
bool,
bool,
bool,
),
rgba_u16_dispatch: fn(
&[u16],
&[u16],
&[u16],
&[u16],
&mut [u16],
usize,
crate::KernelMatrix,
bool,
bool,
bool,
),
rgba_444_dispatch: fn(
&[u16],
&[u16],
&[u16],
&[u16],
&mut [u8],
usize,
crate::KernelMatrix,
bool,
bool,
bool,
),
rgba_u16_444_dispatch: fn(
&[u16],
&[u16],
&[u16],
&[u16],
&mut [u16],
usize,
crate::KernelMatrix,
bool,
bool,
bool,
),
) -> Result<(), MixedSinkerError> {
let w = sinker.width;
let h = sinker.height;
let use_simd = sinker.simd;
let chroma_location = sinker.chroma_location.clone();
if w & 1 != 0 {
return Err(MixedSinkerError::WidthAlignment(WidthAlignment::odd(w)));
}
if y_row.len() != w {
return Err(MixedSinkerError::RowShapeMismatch(RowShapeMismatch::new(
y_slice,
idx,
w,
y_row.len(),
)));
}
if u_half_row.len() != w / 2 {
return Err(MixedSinkerError::RowShapeMismatch(RowShapeMismatch::new(
u_slice,
idx,
w / 2,
u_half_row.len(),
)));
}
if v_half_row.len() != w / 2 {
return Err(MixedSinkerError::RowShapeMismatch(RowShapeMismatch::new(
v_slice,
idx,
w / 2,
v_half_row.len(),
)));
}
if a_row.len() != w {
return Err(MixedSinkerError::RowShapeMismatch(RowShapeMismatch::new(
a_slice,
idx,
w,
a_row.len(),
)));
}
if idx >= sinker.height {
return Err(MixedSinkerError::RowIndexOutOfRange(
RowIndexOutOfRange::new(idx, sinker.height),
));
}
let alpha_mode = sinker.alpha_mode;
let MixedSinker {
rgb,
rgba,
rgb_u16,
rgba_u16,
luma,
luma_u16,
hsv,
rgba_scratch,
rgb_scratch,
rgba_scratch_u16,
rgba_color_scratch_u16,
luma_scratch_u16,
chroma_full_u16,
plan,
rgba_stream,
rgba_stream_u16,
luma_stream_u16,
rgba_filter_stream,
rgba_filter_stream_u16,
luma_filter_stream_u16,
resample_outputs,
frozen_alpha_mode,
frozen_chroma_centered,
frozen_chroma_bottom_v,
frozen_chroma_top_v,
chroma_prev_u16,
chroma_prev_row,
chroma_top_pending,
chroma_top_y_u16,
chroma_top_a_u16,
..
} = sinker;
let plan = plan.as_ref().expect("plan.is_some() checked by the caller");
check_frozen_alpha_mode(*frozen_alpha_mode, alpha_mode, idx)?;
let center_sited = chroma_420_center_sited_h(&chroma_location);
let bottom_v = chroma_420_bottom_sited_v(&chroma_location);
let top_v = chroma_420_top_sited_v(&chroma_location);
let want_color =
rgb.is_some() || rgba.is_some() || hsv.is_some() || rgb_u16.is_some() || rgba_u16.is_some();
let need_output = want_color || luma.is_some() || luma_u16.is_some();
if need_output
&& let Some(frozen) = *frozen_chroma_centered
&& (frozen != center_sited
|| *frozen_chroma_bottom_v != Some(bottom_v)
|| *frozen_chroma_top_v != Some(top_v))
{
return Err(MixedSinkerError::ChromaSitingChanged(
ChromaSitingChanged::new(idx),
));
}
if top_v && want_color && !(plan.kind().is_filter() && alpha_mode.is_premultiplied()) {
match plan.kind() {
crate::resample::SpanKind::Area => {
let cursor = if rgb.is_some() || rgba.is_some() || hsv.is_some() {
rgba_stream.as_ref().map_or(0, |s| s.next_y())
} else {
rgba_stream_u16.as_ref().map_or(0, |s| s.next_y())
};
let expected_source = cursor + usize::from(chroma_top_pending.is_some());
if let core::ops::ControlFlow::Break(()) = super::resample_preflight_check_only(
resample_outputs,
luma,
luma_u16,
rgb,
rgba,
rgb_u16,
rgba_u16,
&None,
&None,
&None,
&None,
&None,
hsv,
&None,
Some(expected_source),
idx,
)? {
return Ok(());
}
reserve_420_chroma_full_u16(chroma_full_u16, w, h)?;
reserve_420_chroma_prev_u16(chroma_prev_u16, w, h)?;
reserve_420_chroma_top_u16(chroma_top_y_u16, w, h)?;
reserve_420_chroma_top_u16(chroma_top_a_u16, w, h)?;
let is_last = idx + 1 == h;
if idx & 1 == 0 {
if let Some((p_idx, p_matrix, p_full_range)) = chroma_top_pending.take() {
let (u_full, v_full) = upsample_420_chroma_sited_u16::<BITS>(
chroma_full_u16,
chroma_prev_u16,
chroma_prev_row,
u_half_row,
v_half_row,
idx,
true,
center_sited,
false,
w,
BE,
use_simd,
);
let held_y: &[u16] = &chroma_top_y_u16[..w];
let held_a: &[u16] = &chroma_top_a_u16[..w];
packed_yuva444_resample::<BITS>(
rgba_stream,
rgba_stream_u16,
luma_stream_u16,
resample_outputs,
rgb,
rgba,
rgb_u16,
rgba_u16,
luma,
luma_u16,
hsv,
rgba_scratch,
rgb_scratch,
rgba_scratch_u16,
rgba_color_scratch_u16,
luma_scratch_u16,
w,
plan,
p_idx,
use_simd,
alpha_mode,
|dst| {
rgba_444_dispatch(
held_y,
u_full,
v_full,
held_a,
dst,
w,
p_matrix,
p_full_range,
use_simd,
BE,
)
},
|dst| {
rgba_u16_444_dispatch(
held_y,
u_full,
v_full,
held_a,
dst,
w,
p_matrix,
p_full_range,
use_simd,
BE,
)
},
|dst| deinterleave_y_high_bit_masked::<BITS, BE>(held_y, dst, w),
)?;
}
let (u_full, v_full) = upsample_420_chroma_sited_u16::<BITS>(
chroma_full_u16,
chroma_prev_u16,
chroma_prev_row,
u_half_row,
v_half_row,
idx,
false,
center_sited,
false,
w,
BE,
use_simd,
);
packed_yuva444_resample::<BITS>(
rgba_stream,
rgba_stream_u16,
luma_stream_u16,
resample_outputs,
rgb,
rgba,
rgb_u16,
rgba_u16,
luma,
luma_u16,
hsv,
rgba_scratch,
rgb_scratch,
rgba_scratch_u16,
rgba_color_scratch_u16,
luma_scratch_u16,
w,
plan,
idx,
use_simd,
alpha_mode,
|dst| {
rgba_444_dispatch(
y_row, u_full, v_full, a_row, dst, w, matrix, full_range, use_simd, BE,
)
},
|dst| {
rgba_u16_444_dispatch(
y_row, u_full, v_full, a_row, dst, w, matrix, full_range, use_simd, BE,
)
},
|dst| deinterleave_y_high_bit_masked::<BITS, BE>(y_row, dst, w),
)?;
} else if !is_last {
chroma_top_y_u16[..w].copy_from_slice(&y_row[..w]);
chroma_top_a_u16[..w].copy_from_slice(&a_row[..w]);
*chroma_top_pending = Some((idx, matrix, full_range));
} else {
let (u_full, v_full) = upsample_420_chroma_sited_u16::<BITS>(
chroma_full_u16,
chroma_prev_u16,
chroma_prev_row,
u_half_row,
v_half_row,
idx,
false,
center_sited,
false,
w,
BE,
use_simd,
);
packed_yuva444_resample::<BITS>(
rgba_stream,
rgba_stream_u16,
luma_stream_u16,
resample_outputs,
rgb,
rgba,
rgb_u16,
rgba_u16,
luma,
luma_u16,
hsv,
rgba_scratch,
rgb_scratch,
rgba_scratch_u16,
rgba_color_scratch_u16,
luma_scratch_u16,
w,
plan,
idx,
use_simd,
alpha_mode,
|dst| {
rgba_444_dispatch(
y_row, u_full, v_full, a_row, dst, w, matrix, full_range, use_simd, BE,
)
},
|dst| {
rgba_u16_444_dispatch(
y_row, u_full, v_full, a_row, dst, w, matrix, full_range, use_simd, BE,
)
},
|dst| deinterleave_y_high_bit_masked::<BITS, BE>(y_row, dst, w),
)?;
}
stage_420_chroma_prev_u16(
chroma_prev_u16,
chroma_prev_row,
u_half_row,
v_half_row,
idx,
w,
);
}
crate::resample::SpanKind::Filter => {
plan.ensure_single_kernel_filter()?;
let cursor = if rgb.is_some() || rgba.is_some() || hsv.is_some() {
rgba_filter_stream.as_ref().map_or(0, |s| s.next_y())
} else {
rgba_filter_stream_u16.as_ref().map_or(0, |s| s.next_y())
};
let expected_source = cursor + usize::from(chroma_top_pending.is_some());
if let core::ops::ControlFlow::Break(()) = super::resample_preflight_check_only(
resample_outputs,
luma,
luma_u16,
rgb,
rgba,
rgb_u16,
rgba_u16,
&None,
&None,
&None,
&None,
&None,
hsv,
&None,
Some(expected_source),
idx,
)? {
return Ok(());
}
reserve_420_chroma_full_u16(chroma_full_u16, w, h)?;
reserve_420_chroma_prev_u16(chroma_prev_u16, w, h)?;
reserve_420_chroma_top_u16(chroma_top_y_u16, w, h)?;
reserve_420_chroma_top_u16(chroma_top_a_u16, w, h)?;
let is_last = idx + 1 == h;
if idx & 1 == 0 {
if let Some((p_idx, p_matrix, p_full_range)) = chroma_top_pending.take() {
let (u_full, v_full) = upsample_420_chroma_sited_u16::<BITS>(
chroma_full_u16,
chroma_prev_u16,
chroma_prev_row,
u_half_row,
v_half_row,
idx,
true,
center_sited,
false,
w,
BE,
use_simd,
);
let held_y: &[u16] = &chroma_top_y_u16[..w];
let held_a: &[u16] = &chroma_top_a_u16[..w];
packed_yuva444_filter_resample::<BITS, false, false>(
rgba_filter_stream,
rgba_filter_stream_u16,
&mut None,
luma_filter_stream_u16,
resample_outputs,
rgb,
rgba,
rgb_u16,
rgba_u16,
luma,
luma_u16,
hsv,
rgba_scratch,
rgb_scratch,
rgba_scratch_u16,
rgba_color_scratch_u16,
luma_scratch_u16,
w,
plan,
p_idx,
use_simd,
&[],
None,
|dst| {
rgba_444_dispatch(
held_y,
u_full,
v_full,
held_a,
dst,
w,
p_matrix,
p_full_range,
use_simd,
BE,
)
},
|dst| {
rgba_u16_444_dispatch(
held_y,
u_full,
v_full,
held_a,
dst,
w,
p_matrix,
p_full_range,
use_simd,
BE,
)
},
|dst| deinterleave_y_high_bit_masked::<BITS, BE>(held_y, dst, w),
|_dst: &mut [u8]| {},
)?;
}
let (u_full, v_full) = upsample_420_chroma_sited_u16::<BITS>(
chroma_full_u16,
chroma_prev_u16,
chroma_prev_row,
u_half_row,
v_half_row,
idx,
false,
center_sited,
false,
w,
BE,
use_simd,
);
packed_yuva444_filter_resample::<BITS, false, false>(
rgba_filter_stream,
rgba_filter_stream_u16,
&mut None,
luma_filter_stream_u16,
resample_outputs,
rgb,
rgba,
rgb_u16,
rgba_u16,
luma,
luma_u16,
hsv,
rgba_scratch,
rgb_scratch,
rgba_scratch_u16,
rgba_color_scratch_u16,
luma_scratch_u16,
w,
plan,
idx,
use_simd,
&[],
None,
|dst| {
rgba_444_dispatch(
y_row, u_full, v_full, a_row, dst, w, matrix, full_range, use_simd, BE,
)
},
|dst| {
rgba_u16_444_dispatch(
y_row, u_full, v_full, a_row, dst, w, matrix, full_range, use_simd, BE,
)
},
|dst| deinterleave_y_high_bit_masked::<BITS, BE>(y_row, dst, w),
|_dst: &mut [u8]| {},
)?;
} else if !is_last {
chroma_top_y_u16[..w].copy_from_slice(&y_row[..w]);
chroma_top_a_u16[..w].copy_from_slice(&a_row[..w]);
*chroma_top_pending = Some((idx, matrix, full_range));
} else {
let (u_full, v_full) = upsample_420_chroma_sited_u16::<BITS>(
chroma_full_u16,
chroma_prev_u16,
chroma_prev_row,
u_half_row,
v_half_row,
idx,
false,
center_sited,
false,
w,
BE,
use_simd,
);
packed_yuva444_filter_resample::<BITS, false, false>(
rgba_filter_stream,
rgba_filter_stream_u16,
&mut None,
luma_filter_stream_u16,
resample_outputs,
rgb,
rgba,
rgb_u16,
rgba_u16,
luma,
luma_u16,
hsv,
rgba_scratch,
rgb_scratch,
rgba_scratch_u16,
rgba_color_scratch_u16,
luma_scratch_u16,
w,
plan,
idx,
use_simd,
&[],
None,
|dst| {
rgba_444_dispatch(
y_row, u_full, v_full, a_row, dst, w, matrix, full_range, use_simd, BE,
)
},
|dst| {
rgba_u16_444_dispatch(
y_row, u_full, v_full, a_row, dst, w, matrix, full_range, use_simd, BE,
)
},
|dst| deinterleave_y_high_bit_masked::<BITS, BE>(y_row, dst, w),
|_dst: &mut [u8]| {},
)?;
}
stage_420_chroma_prev_u16(
chroma_prev_u16,
chroma_prev_row,
u_half_row,
v_half_row,
idx,
w,
);
}
}
if need_output && frozen_chroma_centered.is_none() {
*frozen_chroma_centered = Some(center_sited);
*frozen_chroma_bottom_v = Some(bottom_v);
*frozen_chroma_top_v = Some(top_v);
}
return Ok(());
}
let r = match plan.kind() {
crate::resample::SpanKind::Area => {
if (center_sited || bottom_v) && want_color {
let expected = if rgb.is_some() || rgba.is_some() || hsv.is_some() {
rgba_stream.as_ref().map_or(0, |s| s.next_y())
} else {
rgba_stream_u16.as_ref().map_or(0, |s| s.next_y())
};
match super::resample_preflight_check_only(
resample_outputs,
luma,
luma_u16,
rgb,
rgba,
rgb_u16,
rgba_u16,
&None,
&None,
&None,
&None,
&None,
hsv,
&None,
Some(expected),
idx,
)? {
core::ops::ControlFlow::Break(()) => Ok(()),
core::ops::ControlFlow::Continue(()) => {
reserve_420_chroma_full_u16(chroma_full_u16, w, h)?;
if bottom_v {
reserve_420_chroma_prev_u16(chroma_prev_u16, w, h)?;
}
let (u_full, v_full) = upsample_420_chroma_sited_u16::<BITS>(
chroma_full_u16,
chroma_prev_u16,
chroma_prev_row,
u_half_row,
v_half_row,
idx,
bottom_v,
center_sited,
false,
w,
BE,
use_simd,
);
let r = packed_yuva444_resample::<BITS>(
rgba_stream,
rgba_stream_u16,
luma_stream_u16,
resample_outputs,
rgb,
rgba,
rgb_u16,
rgba_u16,
luma,
luma_u16,
hsv,
rgba_scratch,
rgb_scratch,
rgba_scratch_u16,
rgba_color_scratch_u16,
luma_scratch_u16,
w,
plan,
idx,
use_simd,
alpha_mode,
|dst| {
rgba_444_dispatch(
y_row, u_full, v_full, a_row, dst, w, matrix, full_range, use_simd, BE,
)
},
|dst| {
rgba_u16_444_dispatch(
y_row, u_full, v_full, a_row, dst, w, matrix, full_range, use_simd, BE,
)
},
|dst| deinterleave_y_high_bit_masked::<BITS, BE>(y_row, dst, w),
);
if r.is_ok() && bottom_v {
stage_420_chroma_prev_u16(
chroma_prev_u16,
chroma_prev_row,
u_half_row,
v_half_row,
idx,
w,
);
}
r
}
}
} else {
packed_yuva444_resample::<BITS>(
rgba_stream,
rgba_stream_u16,
luma_stream_u16,
resample_outputs,
rgb,
rgba,
rgb_u16,
rgba_u16,
luma,
luma_u16,
hsv,
rgba_scratch,
rgb_scratch,
rgba_scratch_u16,
rgba_color_scratch_u16,
luma_scratch_u16,
w,
plan,
idx,
use_simd,
alpha_mode,
|dst| {
rgba_dispatch(
y_row, u_half_row, v_half_row, a_row, dst, w, matrix, full_range, use_simd, BE,
)
},
|dst| {
rgba_u16_dispatch(
y_row, u_half_row, v_half_row, a_row, dst, w, matrix, full_range, use_simd, BE,
)
},
|dst| deinterleave_y_high_bit_masked::<BITS, BE>(y_row, dst, w),
)
}
}
crate::resample::SpanKind::Filter if alpha_mode.is_premultiplied() => {
packed_yuva444_resample::<BITS>(
rgba_stream,
rgba_stream_u16,
luma_stream_u16,
resample_outputs,
rgb,
rgba,
rgb_u16,
rgba_u16,
luma,
luma_u16,
hsv,
rgba_scratch,
rgb_scratch,
rgba_scratch_u16,
rgba_color_scratch_u16,
luma_scratch_u16,
w,
plan,
idx,
use_simd,
alpha_mode,
|dst| {
rgba_dispatch(
y_row, u_half_row, v_half_row, a_row, dst, w, matrix, full_range, use_simd, BE,
)
},
|dst| {
rgba_u16_dispatch(
y_row, u_half_row, v_half_row, a_row, dst, w, matrix, full_range, use_simd, BE,
)
},
|dst| deinterleave_y_high_bit_masked::<BITS, BE>(y_row, dst, w),
)
}
crate::resample::SpanKind::Filter => {
plan.ensure_single_kernel_filter()?;
if (center_sited || bottom_v) && want_color {
let expected = if rgb.is_some() || rgba.is_some() || hsv.is_some() {
rgba_filter_stream.as_ref().map_or(0, |s| s.next_y())
} else {
rgba_filter_stream_u16.as_ref().map_or(0, |s| s.next_y())
};
match super::resample_preflight_check_only(
resample_outputs,
luma,
luma_u16,
rgb,
rgba,
rgb_u16,
rgba_u16,
&None,
&None,
&None,
&None,
&None,
hsv,
&None,
Some(expected),
idx,
)? {
core::ops::ControlFlow::Break(()) => Ok(()),
core::ops::ControlFlow::Continue(()) => {
reserve_420_chroma_full_u16(chroma_full_u16, w, h)?;
if bottom_v {
reserve_420_chroma_prev_u16(chroma_prev_u16, w, h)?;
}
let (u_full, v_full) = upsample_420_chroma_sited_u16::<BITS>(
chroma_full_u16,
chroma_prev_u16,
chroma_prev_row,
u_half_row,
v_half_row,
idx,
bottom_v,
center_sited,
false,
w,
BE,
use_simd,
);
let r = packed_yuva444_filter_resample::<BITS, false, false>(
rgba_filter_stream,
rgba_filter_stream_u16,
&mut None,
luma_filter_stream_u16,
resample_outputs,
rgb,
rgba,
rgb_u16,
rgba_u16,
luma,
luma_u16,
hsv,
rgba_scratch,
rgb_scratch,
rgba_scratch_u16,
rgba_color_scratch_u16,
luma_scratch_u16,
w,
plan,
idx,
use_simd,
&[],
None,
|dst| {
rgba_444_dispatch(
y_row, u_full, v_full, a_row, dst, w, matrix, full_range, use_simd, BE,
)
},
|dst| {
rgba_u16_444_dispatch(
y_row, u_full, v_full, a_row, dst, w, matrix, full_range, use_simd, BE,
)
},
|dst| deinterleave_y_high_bit_masked::<BITS, BE>(y_row, dst, w),
|_dst: &mut [u8]| {},
);
if r.is_ok() && bottom_v {
stage_420_chroma_prev_u16(
chroma_prev_u16,
chroma_prev_row,
u_half_row,
v_half_row,
idx,
w,
);
}
r
}
}
} else {
packed_yuva444_filter_resample::<BITS, false, false>(
rgba_filter_stream,
rgba_filter_stream_u16,
&mut None,
luma_filter_stream_u16,
resample_outputs,
rgb,
rgba,
rgb_u16,
rgba_u16,
luma,
luma_u16,
hsv,
rgba_scratch,
rgb_scratch,
rgba_scratch_u16,
rgba_color_scratch_u16,
luma_scratch_u16,
w,
plan,
idx,
use_simd,
&[],
None,
|dst| {
rgba_dispatch(
y_row, u_half_row, v_half_row, a_row, dst, w, matrix, full_range, use_simd, BE,
)
},
|dst| {
rgba_u16_dispatch(
y_row, u_half_row, v_half_row, a_row, dst, w, matrix, full_range, use_simd, BE,
)
},
|dst| deinterleave_y_high_bit_masked::<BITS, BE>(y_row, dst, w),
|_dst: &mut [u8]| {},
)
}
}
};
if r.is_ok() && need_output && frozen_chroma_centered.is_none() {
*frozen_chroma_centered = Some(center_sited);
*frozen_chroma_bottom_v = Some(bottom_v);
*frozen_chroma_top_v = Some(top_v);
}
r
}